hwc_utils.cpp revision 9e3d34120ce5f349322a8ffe41d9655a183a8202
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * Copyright (C) 2012-2013, The Linux Foundation All rights reserved. 4 * 5 * Not a Contribution, Apache license notifications and license are retained 6 * for attribution purposes only. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20#define HWC_UTILS_DEBUG 0 21#include <math.h> 22#include <sys/ioctl.h> 23#include <binder/IServiceManager.h> 24#include <EGL/egl.h> 25#include <cutils/properties.h> 26#include <gralloc_priv.h> 27#include <overlay.h> 28#include <overlayRotator.h> 29#include <overlayWriteback.h> 30#include "hwc_utils.h" 31#include "hwc_mdpcomp.h" 32#include "hwc_fbupdate.h" 33#include "hwc_ad.h" 34#include "mdp_version.h" 35#include "hwc_copybit.h" 36#include "external.h" 37#include "hwc_qclient.h" 38#include "QService.h" 39#include "comptype.h" 40 41using namespace qClient; 42using namespace qService; 43using namespace android; 44using namespace overlay; 45using namespace overlay::utils; 46namespace ovutils = overlay::utils; 47 48namespace qhwc { 49 50static int openFramebufferDevice(hwc_context_t *ctx) 51{ 52 struct fb_fix_screeninfo finfo; 53 struct fb_var_screeninfo info; 54 55 int fb_fd = openFb(HWC_DISPLAY_PRIMARY); 56 if(fb_fd < 0) { 57 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno)); 58 return -errno; 59 } 60 61 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) { 62 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__, 63 strerror(errno)); 64 close(fb_fd); 65 return -errno; 66 } 67 68 if (int(info.width) <= 0 || int(info.height) <= 0) { 69 // the driver doesn't return that information 70 // default to 160 dpi 71 info.width = ((info.xres * 25.4f)/160.0f + 0.5f); 72 info.height = ((info.yres * 25.4f)/160.0f + 0.5f); 73 } 74 75 float xdpi = (info.xres * 25.4f) / info.width; 76 float ydpi = (info.yres * 25.4f) / info.height; 77 78#ifdef MSMFB_METADATA_GET 79 struct msmfb_metadata metadata; 80 memset(&metadata, 0 , sizeof(metadata)); 81 metadata.op = metadata_op_frame_rate; 82 83 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) { 84 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__, 85 strerror(errno)); 86 close(fb_fd); 87 return -errno; 88 } 89 90 float fps = metadata.data.panel_frame_rate; 91#else 92 //XXX: Remove reserved field usage on all baselines 93 //The reserved[3] field is used to store FPS by the driver. 94 float fps = info.reserved[3] & 0xFF; 95#endif 96 97 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) { 98 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__, 99 strerror(errno)); 100 close(fb_fd); 101 return -errno; 102 } 103 104 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd; 105 //xres, yres may not be 32 aligned 106 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8); 107 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres; 108 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres; 109 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi; 110 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi; 111 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps; 112 113 //Unblank primary on first boot 114 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) { 115 ALOGE("%s: Failed to unblank display", __FUNCTION__); 116 return -errno; 117 } 118 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true; 119 120 return 0; 121} 122 123void initContext(hwc_context_t *ctx) 124{ 125 memset(&ctx->dpyAttr, 0, sizeof(ctx->dpyAttr)); 126 if(openFramebufferDevice(ctx) < 0) { 127 ALOGE("%s: failed to open framebuffer!!", __FUNCTION__); 128 } 129 130 overlay::Overlay::initOverlay(); 131 ctx->mOverlay = overlay::Overlay::getInstance(); 132 ctx->mRotMgr = new RotMgr(); 133 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); 134 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); 135 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); 136 const int rightSplit = qdutils::MDPVersion::getInstance().getRightSplit(); 137 overlay::Overlay::initOverlay(); 138 ctx->mOverlay = overlay::Overlay::getInstance(); 139 ctx->mRotMgr = new RotMgr(); 140 141 //Is created and destroyed only once for primary 142 //For external it could get created and destroyed multiple times depending 143 //on what external we connect to. 144 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] = 145 IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, 146 rightSplit, HWC_DISPLAY_PRIMARY); 147 148 // Check if the target supports copybit compostion (dyn/mdp/c2d) to 149 // decide if we need to open the copybit module. 150 int compositionType = 151 qdutils::QCCompositionType::getInstance().getCompositionType(); 152 153 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | 154 qdutils::COMPOSITION_TYPE_MDP | 155 qdutils::COMPOSITION_TYPE_C2D)) { 156 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(); 157 } 158 159 ctx->mExtDisplay = new ExternalDisplay(ctx); 160 161 for (uint32_t i = 0; i < MAX_DISPLAYS; i++) { 162 ctx->mLayerRotMap[i] = new LayerRotMap(); 163 } 164 165 ctx->mMDPComp[HWC_DISPLAY_PRIMARY] = 166 MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, 167 rightSplit, HWC_DISPLAY_PRIMARY); 168 169 MDPComp::init(ctx); 170 ctx->mAD = new AssertiveDisplay(); 171 172 ctx->vstate.enable = false; 173 ctx->vstate.fakevsync = false; 174 ctx->mBasePipeSetup = false; 175 176 //Right now hwc starts the service but anybody could do it, or it could be 177 //independent process as well. 178 QService::init(); 179 sp<IQClient> client = new QClient(ctx); 180 interface_cast<IQService>( 181 defaultServiceManager()->getService( 182 String16("display.qservice")))->connect(client); 183 184 ALOGI("Initializing Qualcomm Hardware Composer"); 185 ALOGI("MDP version: %d", ctx->mMDP.version); 186} 187 188void closeContext(hwc_context_t *ctx) 189{ 190 if(ctx->mOverlay) { 191 delete ctx->mOverlay; 192 ctx->mOverlay = NULL; 193 } 194 195 if(ctx->mRotMgr) { 196 delete ctx->mRotMgr; 197 ctx->mRotMgr = NULL; 198 } 199 200 for(int i = 0; i < MAX_DISPLAYS; i++) { 201 if(ctx->mCopyBit[i]) { 202 delete ctx->mCopyBit[i]; 203 ctx->mCopyBit[i] = NULL; 204 } 205 } 206 207 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) { 208 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); 209 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; 210 } 211 212 if(ctx->mExtDisplay) { 213 delete ctx->mExtDisplay; 214 ctx->mExtDisplay = NULL; 215 } 216 217 for(int i = 0; i < MAX_DISPLAYS; i++) { 218 if(ctx->mFBUpdate[i]) { 219 delete ctx->mFBUpdate[i]; 220 ctx->mFBUpdate[i] = NULL; 221 } 222 if(ctx->mMDPComp[i]) { 223 delete ctx->mMDPComp[i]; 224 ctx->mMDPComp[i] = NULL; 225 } 226 if(ctx->mLayerRotMap[i]) { 227 delete ctx->mLayerRotMap[i]; 228 ctx->mLayerRotMap[i] = NULL; 229 } 230 } 231 232 if(ctx->mAD) { 233 delete ctx->mAD; 234 ctx->mAD = NULL; 235 } 236} 237 238 239void dumpsys_log(android::String8& buf, const char* fmt, ...) 240{ 241 va_list varargs; 242 va_start(varargs, fmt); 243 buf.appendFormatV(fmt, varargs); 244 va_end(varargs); 245} 246 247/* Calculates the destination position based on the action safe rectangle */ 248void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x, 249 uint32_t& y, uint32_t& w, uint32_t& h) { 250 251 // if external supports underscan, do nothing 252 // it will be taken care in the driver 253 if(ctx->mExtDisplay->isCEUnderscanSupported()) 254 return; 255 256 char value[PROPERTY_VALUE_MAX]; 257 // Read action safe properties 258 property_get("persist.sys.actionsafe.width", value, "0"); 259 int asWidthRatio = atoi(value); 260 property_get("persist.sys.actionsafe.height", value, "0"); 261 int asHeightRatio = atoi(value); 262 263 if(!asWidthRatio && !asHeightRatio) { 264 //No action safe ratio set, return 265 return; 266 } 267 268 float wRatio = 1.0; 269 float hRatio = 1.0; 270 float xRatio = 1.0; 271 float yRatio = 1.0; 272 273 float fbWidth = ctx->dpyAttr[dpy].xres; 274 float fbHeight = ctx->dpyAttr[dpy].yres; 275 276 float asX = 0; 277 float asY = 0; 278 float asW = fbWidth; 279 float asH= fbHeight; 280 281 // based on the action safe ratio, get the Action safe rectangle 282 asW = fbWidth * (1.0f - asWidthRatio / 100.0f); 283 asH = fbHeight * (1.0f - asHeightRatio / 100.0f); 284 asX = (fbWidth - asW) / 2; 285 asY = (fbHeight - asH) / 2; 286 287 // calculate the position ratio 288 xRatio = (float)x/fbWidth; 289 yRatio = (float)y/fbHeight; 290 wRatio = (float)w/fbWidth; 291 hRatio = (float)h/fbHeight; 292 293 //Calculate the position... 294 x = (xRatio * asW) + asX; 295 y = (yRatio * asH) + asY; 296 w = (wRatio * asW); 297 h = (hRatio * asH); 298 299 return; 300} 301 302bool needsScaling(hwc_context_t* ctx, hwc_layer_1_t const* layer, 303 const int& dpy) { 304 int dst_w, dst_h, src_w, src_h; 305 306 hwc_rect_t displayFrame = layer->displayFrame; 307 hwc_rect_t sourceCrop = layer->sourceCrop; 308 trimLayer(ctx, dpy, layer->transform, sourceCrop, displayFrame); 309 310 dst_w = displayFrame.right - displayFrame.left; 311 dst_h = displayFrame.bottom - displayFrame.top; 312 src_w = sourceCrop.right - sourceCrop.left; 313 src_h = sourceCrop.bottom - sourceCrop.top; 314 315 if(((src_w != dst_w) || (src_h != dst_h))) 316 return true; 317 318 return false; 319} 320 321bool isAlphaScaled(hwc_context_t* ctx, hwc_layer_1_t const* layer, 322 const int& dpy) { 323 if(needsScaling(ctx, layer, dpy) && isAlphaPresent(layer)) { 324 return true; 325 } 326 return false; 327} 328 329bool isAlphaPresent(hwc_layer_1_t const* layer) { 330 private_handle_t *hnd = (private_handle_t *)layer->handle; 331 if(hnd) { 332 int format = hnd->format; 333 switch(format) { 334 case HAL_PIXEL_FORMAT_RGBA_8888: 335 case HAL_PIXEL_FORMAT_BGRA_8888: 336 // In any more formats with Alpha go here.. 337 return true; 338 default : return false; 339 } 340 } 341 return false; 342} 343 344// Let CABL know we have a YUV layer 345static void setYUVProp(int yuvCount) { 346 static char property[PROPERTY_VALUE_MAX]; 347 if(yuvCount > 0) { 348 if (property_get("hw.cabl.yuv", property, NULL) > 0) { 349 if (atoi(property) != 1) { 350 property_set("hw.cabl.yuv", "1"); 351 } 352 } 353 } else { 354 if (property_get("hw.cabl.yuv", property, NULL) > 0) { 355 if (atoi(property) != 0) { 356 property_set("hw.cabl.yuv", "0"); 357 } 358 } 359 } 360} 361 362void setListStats(hwc_context_t *ctx, 363 const hwc_display_contents_1_t *list, int dpy) { 364 const int prevYuvCount = ctx->listStats[dpy].yuvCount; 365 memset(&ctx->listStats[dpy], 0, sizeof(ListStats)); 366 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1; 367 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1; 368 ctx->listStats[dpy].skipCount = 0; 369 ctx->listStats[dpy].needsAlphaScale = false; 370 ctx->listStats[dpy].preMultipliedAlpha = false; 371 ctx->listStats[dpy].planeAlpha = false; 372 ctx->listStats[dpy].yuvCount = 0; 373 374 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) { 375 hwc_layer_1_t const* layer = &list->hwLayers[i]; 376 private_handle_t *hnd = (private_handle_t *)layer->handle; 377 378 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS 379 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) 380 continue; 381 382 //reset yuv indices 383 ctx->listStats[dpy].yuvIndices[i] = -1; 384 385 if (isSkipLayer(&list->hwLayers[i])) { 386 ctx->listStats[dpy].skipCount++; 387 } else if (UNLIKELY(isYuvBuffer(hnd))) { 388 int& yuvCount = ctx->listStats[dpy].yuvCount; 389 ctx->listStats[dpy].yuvIndices[yuvCount] = i; 390 yuvCount++; 391 392 if((layer->transform & HWC_TRANSFORM_ROT_90) && 393 canUseRotator(ctx)) { 394 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) { 395 ctx->isPaddingRound = true; 396 } 397 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE); 398 } 399 } 400 if(layer->blending == HWC_BLENDING_PREMULT) 401 ctx->listStats[dpy].preMultipliedAlpha = true; 402 if(layer->planeAlpha < 0xFF) 403 ctx->listStats[dpy].planeAlpha = true; 404 if(!ctx->listStats[dpy].needsAlphaScale) 405 ctx->listStats[dpy].needsAlphaScale = 406 isAlphaScaled(ctx, layer, dpy); 407 } 408 setYUVProp(ctx->listStats[dpy].yuvCount); 409 //The marking of video begin/end is useful on some targets where we need 410 //to have a padding round to be able to shift pipes across mixers. 411 if(prevYuvCount != ctx->listStats[dpy].yuvCount) { 412 ctx->mVideoTransFlag = true; 413 } 414 if(dpy == HWC_DISPLAY_PRIMARY) { 415 ctx->mAD->markDoable(ctx, list); 416 } 417} 418 419 420static void calc_cut(double& leftCutRatio, double& topCutRatio, 421 double& rightCutRatio, double& bottomCutRatio, int orient) { 422 if(orient & HAL_TRANSFORM_FLIP_H) { 423 swap(leftCutRatio, rightCutRatio); 424 } 425 if(orient & HAL_TRANSFORM_FLIP_V) { 426 swap(topCutRatio, bottomCutRatio); 427 } 428 if(orient & HAL_TRANSFORM_ROT_90) { 429 //Anti clock swapping 430 double tmpCutRatio = leftCutRatio; 431 leftCutRatio = topCutRatio; 432 topCutRatio = rightCutRatio; 433 rightCutRatio = bottomCutRatio; 434 bottomCutRatio = tmpCutRatio; 435 } 436} 437 438bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) { 439 if((ctx->mMDP.version < qdutils::MDSS_V5) && 440 (ctx->mMDP.version > qdutils::MDP_V3_0) && 441 ctx->mSecuring) { 442 return true; 443 } 444 // On A-Family, Secure policy is applied system wide and not on 445 // buffers. 446 if (isSecureModePolicy(ctx->mMDP.version)) { 447 private_handle_t *hnd = (private_handle_t *)layer->handle; 448 if(ctx->mSecureMode) { 449 if (! isSecureBuffer(hnd)) { 450 // This code path executes for the following usecase: 451 // Some Apps in which first few seconds, framework 452 // sends non-secure buffer and with out destroying 453 // surfaces, switches to secure buffer thereby exposing 454 // vulnerability on A-family devices. Catch this situation 455 // and handle it gracefully by allowing it to be composed by 456 // GPU. 457 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle non-secure video layer" 458 "during secure playback gracefully", __FUNCTION__); 459 return true; 460 } 461 } else { 462 if (isSecureBuffer(hnd)) { 463 // This code path executes for the following usecase: 464 // For some Apps, when User terminates playback, Framework 465 // doesnt destroy video surface and video surface still 466 // comes to Display HAL. This exposes vulnerability on 467 // A-family. Catch this situation and handle it gracefully 468 // by allowing it to be composed by GPU. 469 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle secure video layer" 470 "during non-secure playback gracefully", __FUNCTION__); 471 return true; 472 } 473 } 474 } 475 return false; 476} 477 478bool isSecureModePolicy(int mdpVersion) { 479 if (mdpVersion < qdutils::MDSS_V5) 480 return true; 481 else 482 return false; 483} 484 485int getBlending(int blending) { 486 switch(blending) { 487 case HWC_BLENDING_NONE: 488 return overlay::utils::OVERLAY_BLENDING_OPAQUE; 489 case HWC_BLENDING_PREMULT: 490 return overlay::utils::OVERLAY_BLENDING_PREMULT; 491 case HWC_BLENDING_COVERAGE : 492 default: 493 return overlay::utils::OVERLAY_BLENDING_COVERAGE; 494 } 495} 496 497//Crops source buffer against destination and FB boundaries 498void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, 499 const hwc_rect_t& scissor, int orient) { 500 501 int& crop_l = crop.left; 502 int& crop_t = crop.top; 503 int& crop_r = crop.right; 504 int& crop_b = crop.bottom; 505 int crop_w = crop.right - crop.left; 506 int crop_h = crop.bottom - crop.top; 507 508 int& dst_l = dst.left; 509 int& dst_t = dst.top; 510 int& dst_r = dst.right; 511 int& dst_b = dst.bottom; 512 int dst_w = abs(dst.right - dst.left); 513 int dst_h = abs(dst.bottom - dst.top); 514 515 const int& sci_l = scissor.left; 516 const int& sci_t = scissor.top; 517 const int& sci_r = scissor.right; 518 const int& sci_b = scissor.bottom; 519 int sci_w = abs(sci_r - sci_l); 520 int sci_h = abs(sci_b - sci_t); 521 522 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0, 523 bottomCutRatio = 0.0; 524 525 if(dst_l < sci_l) { 526 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w; 527 dst_l = sci_l; 528 } 529 530 if(dst_r > sci_r) { 531 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w; 532 dst_r = sci_r; 533 } 534 535 if(dst_t < sci_t) { 536 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h; 537 dst_t = sci_t; 538 } 539 540 if(dst_b > sci_b) { 541 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h; 542 dst_b = sci_b; 543 } 544 545 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); 546 crop_l += crop_w * leftCutRatio; 547 crop_t += crop_h * topCutRatio; 548 crop_r -= crop_w * rightCutRatio; 549 crop_b -= crop_h * bottomCutRatio; 550} 551 552void getNonWormholeRegion(hwc_display_contents_1_t* list, 553 hwc_rect_t& nwr) 554{ 555 uint32_t last = list->numHwLayers - 1; 556 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame; 557 //Initiliaze nwr to first frame 558 nwr.left = list->hwLayers[0].displayFrame.left; 559 nwr.top = list->hwLayers[0].displayFrame.top; 560 nwr.right = list->hwLayers[0].displayFrame.right; 561 nwr.bottom = list->hwLayers[0].displayFrame.bottom; 562 563 for (uint32_t i = 1; i < last; i++) { 564 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; 565 nwr.left = min(nwr.left, displayFrame.left); 566 nwr.top = min(nwr.top, displayFrame.top); 567 nwr.right = max(nwr.right, displayFrame.right); 568 nwr.bottom = max(nwr.bottom, displayFrame.bottom); 569 } 570 571 //Intersect with the framebuffer 572 nwr.left = max(nwr.left, fbDisplayFrame.left); 573 nwr.top = max(nwr.top, fbDisplayFrame.top); 574 nwr.right = min(nwr.right, fbDisplayFrame.right); 575 nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom); 576 577} 578 579bool isSecondaryConfiguring(hwc_context_t* ctx) { 580 return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring | 581 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring); 582} 583 584void closeAcquireFds(hwc_display_contents_1_t* list) { 585 if(LIKELY(list)) { 586 for(uint32_t i = 0; i < list->numHwLayers; i++) { 587 //Close the acquireFenceFds 588 //HWC_FRAMEBUFFER are -1 already by SF, rest we close. 589 if(list->hwLayers[i].acquireFenceFd >= 0) { 590 close(list->hwLayers[i].acquireFenceFd); 591 list->hwLayers[i].acquireFenceFd = -1; 592 } 593 } 594 } 595} 596 597int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy, 598 int fd) { 599 int ret = 0; 600 int acquireFd[MAX_NUM_APP_LAYERS]; 601 int count = 0; 602 int releaseFd = -1; 603 int fbFd = -1; 604 int rotFd = -1; 605 bool swapzero = false; 606 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); 607 608 struct mdp_buf_sync data; 609 memset(&data, 0, sizeof(data)); 610 //Until B-family supports sync for rotator 611 if(mdpVersion >= qdutils::MDSS_V5) { 612 data.flags = MDP_BUF_SYNC_FLAG_WAIT; 613 } 614 data.acq_fen_fd = acquireFd; 615 data.rel_fen_fd = &releaseFd; 616 617 char property[PROPERTY_VALUE_MAX]; 618 if(property_get("debug.egl.swapinterval", property, "1") > 0) { 619 if(atoi(property) == 0) 620 swapzero = true; 621 } 622 623#ifndef MDSS_TARGET 624 //Send acquireFenceFds to rotator 625 if(mdpVersion < qdutils::MDSS_V5) { 626 //A-family 627 int rotFd = ctx->mRotMgr->getRotDevFd(); 628 struct msm_rotator_buf_sync rotData; 629 630 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) { 631 memset(&rotData, 0, sizeof(rotData)); 632 int& acquireFenceFd = 633 ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd; 634 rotData.acq_fen_fd = acquireFenceFd; 635 rotData.session_id = ctx->mLayerRotMap[dpy]->getRot(i)->getSessId(); 636 ioctl(rotFd, MSM_ROTATOR_IOCTL_BUFFER_SYNC, &rotData); 637 close(acquireFenceFd); 638 //For MDP to wait on. 639 acquireFenceFd = dup(rotData.rel_fen_fd); 640 //A buffer is free to be used by producer as soon as its copied to 641 //rotator. 642 ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd = 643 rotData.rel_fen_fd; 644 } 645 } else { 646 //TODO B-family 647 } 648 649#endif 650 //Accumulate acquireFenceFds for MDP 651 for(uint32_t i = 0; i < list->numHwLayers; i++) { 652 if(list->hwLayers[i].compositionType == HWC_OVERLAY && 653 list->hwLayers[i].acquireFenceFd >= 0) { 654 if(UNLIKELY(swapzero)) 655 acquireFd[count++] = -1; 656 else 657 acquireFd[count++] = list->hwLayers[i].acquireFenceFd; 658 } 659 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { 660 if(UNLIKELY(swapzero)) 661 acquireFd[count++] = -1; 662 else if(fd >= 0) { 663 //set the acquireFD from fd - which is coming from c2d 664 acquireFd[count++] = fd; 665 // Buffer sync IOCTL should be async when using c2d fence is 666 // used 667 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; 668 } else if(list->hwLayers[i].acquireFenceFd >= 0) 669 acquireFd[count++] = list->hwLayers[i].acquireFenceFd; 670 } 671 } 672 673 data.acq_fen_fd_cnt = count; 674 fbFd = ctx->dpyAttr[dpy].fd; 675 676 //Waits for acquire fences, returns a release fence 677 if(LIKELY(!swapzero)) { 678 uint64_t start = systemTime(); 679 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); 680 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d", 681 __FUNCTION__, (size_t) ns2ms(systemTime() - start)); 682 } 683 684 if(ret < 0) { 685 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s", 686 __FUNCTION__, strerror(errno)); 687 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d", 688 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd, 689 dpy, list->numHwLayers); 690 } 691 692 for(uint32_t i = 0; i < list->numHwLayers; i++) { 693 if(list->hwLayers[i].compositionType == HWC_OVERLAY || 694 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { 695 //Populate releaseFenceFds. 696 if(UNLIKELY(swapzero)) { 697 list->hwLayers[i].releaseFenceFd = -1; 698 } else if(list->hwLayers[i].releaseFenceFd < 0) { 699 //If rotator has not already populated this field. 700 list->hwLayers[i].releaseFenceFd = dup(releaseFd); 701 } 702 } 703 } 704 705 if(fd >= 0) { 706 close(fd); 707 fd = -1; 708 } 709 710 if (ctx->mCopyBit[dpy]) 711 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd); 712 713 //A-family 714 if(mdpVersion < qdutils::MDSS_V5) { 715 //Signals when MDP finishes reading rotator buffers. 716 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd); 717 } 718 719 if(UNLIKELY(swapzero)){ 720 list->retireFenceFd = -1; 721 close(releaseFd); 722 } else { 723 list->retireFenceFd = releaseFd; 724 } 725 726 return ret; 727} 728 729void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform, 730 hwc_rect_t& crop, hwc_rect_t& dst) { 731 int hw_w = ctx->dpyAttr[dpy].xres; 732 int hw_h = ctx->dpyAttr[dpy].yres; 733 if(dst.left < 0 || dst.top < 0 || 734 dst.right > hw_w || dst.bottom > hw_h) { 735 hwc_rect_t scissor = {0, 0, hw_w, hw_h }; 736 qhwc::calculate_crop_rects(crop, dst, scissor, transform); 737 } 738} 739 740void setMdpFlags(hwc_layer_1_t *layer, 741 ovutils::eMdpFlags &mdpFlags, 742 int rotDownscale) { 743 private_handle_t *hnd = (private_handle_t *)layer->handle; 744 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; 745 const int& transform = layer->transform; 746 747 if(layer->blending == HWC_BLENDING_PREMULT) { 748 ovutils::setMdpFlags(mdpFlags, 749 ovutils::OV_MDP_BLEND_FG_PREMULT); 750 } 751 752 if(isYuvBuffer(hnd)) { 753 if(isSecureBuffer(hnd)) { 754 ovutils::setMdpFlags(mdpFlags, 755 ovutils::OV_MDP_SECURE_OVERLAY_SESSION); 756 } 757 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) && 758 metadata->interlaced) { 759 ovutils::setMdpFlags(mdpFlags, 760 ovutils::OV_MDP_DEINTERLACE); 761 } 762 //Pre-rotation will be used using rotator. 763 if(transform & HWC_TRANSFORM_ROT_90) { 764 ovutils::setMdpFlags(mdpFlags, 765 ovutils::OV_MDP_SOURCE_ROTATED_90); 766 } 767 } 768 769 //No 90 component and no rot-downscale then flips done by MDP 770 //If we use rot then it might as well do flips 771 if(!(layer->transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) { 772 if(layer->transform & HWC_TRANSFORM_FLIP_H) { 773 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H); 774 } 775 776 if(layer->transform & HWC_TRANSFORM_FLIP_V) { 777 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V); 778 } 779 } 780 781 if(metadata && 782 ((metadata->operation & PP_PARAM_HSIC) 783 || (metadata->operation & PP_PARAM_IGC) 784 || (metadata->operation & PP_PARAM_SHARP2))) { 785 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN); 786 } 787} 788 789int configRotator(Rotator *rot, const Whf& whf, 790 hwc_rect_t& crop, const eMdpFlags& mdpFlags, 791 const eTransform& orient, const int& downscale) { 792 rot->setSource(whf); 793 794 if (qdutils::MDPVersion::getInstance().getMDPVersion() >= 795 qdutils::MDSS_V5) { 796 uint32_t crop_w = (crop.right - crop.left); 797 uint32_t crop_h = (crop.bottom - crop.top); 798 if (ovutils::isYuv(whf.format)) { 799 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w); 800 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h); 801 // For interlaced, crop.h should be 4-aligned 802 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4)) 803 crop_h = ovutils::aligndown(crop_h, 4); 804 crop.right = crop.left + crop_w; 805 crop.bottom = crop.top + crop_h; 806 } 807 Dim rotCrop(crop.left, crop.top, crop_w, crop_h); 808 rot->setCrop(rotCrop); 809 } 810 811 rot->setFlags(mdpFlags); 812 rot->setTransform(orient); 813 rot->setDownscale(downscale); 814 if(!rot->commit()) return -1; 815 return 0; 816} 817 818/* 819 * Sets up BORDERFILL as default base pipe and detaches RGB0. 820 * Framebuffer is always updated using PLAY ioctl. 821 */ 822bool setupBasePipe(hwc_context_t *ctx) { 823 const int dpy = HWC_DISPLAY_PRIMARY; 824 int fb_stride = ctx->dpyAttr[dpy].stride; 825 int fb_width = ctx->dpyAttr[dpy].xres; 826 int fb_height = ctx->dpyAttr[dpy].yres; 827 int fb_fd = ctx->dpyAttr[dpy].fd; 828 829 mdp_overlay ovInfo; 830 msmfb_overlay_data ovData; 831 memset(&ovInfo, 0, sizeof(mdp_overlay)); 832 memset(&ovData, 0, sizeof(msmfb_overlay_data)); 833 834 ovInfo.src.format = MDP_RGB_BORDERFILL; 835 ovInfo.src.width = fb_width; 836 ovInfo.src.height = fb_height; 837 ovInfo.src_rect.w = fb_width; 838 ovInfo.src_rect.h = fb_height; 839 ovInfo.dst_rect.w = fb_width; 840 ovInfo.dst_rect.h = fb_height; 841 ovInfo.id = MSMFB_NEW_REQUEST; 842 843 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) { 844 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s", 845 strerror(errno)); 846 return false; 847 } 848 849 ovData.id = ovInfo.id; 850 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) { 851 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s", 852 strerror(errno)); 853 return false; 854 } 855 ctx->mBasePipeSetup = true; 856 return true; 857} 858 859int configMdp(Overlay *ov, const PipeArgs& parg, 860 const eTransform& orient, const hwc_rect_t& crop, 861 const hwc_rect_t& pos, const MetaData_t *metadata, 862 const eDest& dest) { 863 ov->setSource(parg, dest); 864 ov->setTransform(orient, dest); 865 866 int crop_w = crop.right - crop.left; 867 int crop_h = crop.bottom - crop.top; 868 Dim dcrop(crop.left, crop.top, crop_w, crop_h); 869 ov->setCrop(dcrop, dest); 870 871 int posW = pos.right - pos.left; 872 int posH = pos.bottom - pos.top; 873 Dim position(pos.left, pos.top, posW, posH); 874 ov->setPosition(position, dest); 875 876 if (metadata) 877 ov->setVisualParams(*metadata, dest); 878 879 if (!ov->commit(dest)) { 880 return -1; 881 } 882 return 0; 883} 884 885void updateSource(eTransform& orient, Whf& whf, 886 hwc_rect_t& crop) { 887 Dim srcCrop(crop.left, crop.top, 888 crop.right - crop.left, 889 crop.bottom - crop.top); 890 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient)); 891 preRotateSource(orient, whf, srcCrop); 892 if (qdutils::MDPVersion::getInstance().getMDPVersion() >= 893 qdutils::MDSS_V5) { 894 // Source for overlay will be the cropped (and rotated) 895 crop.left = 0; 896 crop.top = 0; 897 crop.right = srcCrop.w; 898 crop.bottom = srcCrop.h; 899 // Set width & height equal to sourceCrop w & h 900 whf.w = srcCrop.w; 901 whf.h = srcCrop.h; 902 } else { 903 crop.left = srcCrop.x; 904 crop.top = srcCrop.y; 905 crop.right = srcCrop.x + srcCrop.w; 906 crop.bottom = srcCrop.y + srcCrop.h; 907 } 908} 909 910int configureLowRes(hwc_context_t *ctx, hwc_layer_1_t *layer, 911 const int& dpy, eMdpFlags& mdpFlags, const eZorder& z, 912 const eIsFg& isFg, const eDest& dest, Rotator **rot) { 913 914 private_handle_t *hnd = (private_handle_t *)layer->handle; 915 if(!hnd) { 916 ALOGE("%s: layer handle is NULL", __FUNCTION__); 917 ctx->mLayerRotMap[dpy]->reset(); 918 return -1; 919 } 920 921 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; 922 923 hwc_rect_t crop = layer->sourceCrop; 924 hwc_rect_t dst = layer->displayFrame; 925 int transform = layer->transform; 926 eTransform orient = static_cast<eTransform>(transform); 927 int downscale = 0; 928 int rotFlags = ovutils::ROT_FLAGS_NONE; 929 Whf whf(hnd->width, hnd->height, 930 getMdpFormat(hnd->format), hnd->size); 931 932 uint32_t x = dst.left, y = dst.top; 933 uint32_t w = dst.right - dst.left; 934 uint32_t h = dst.bottom - dst.top; 935 936 if(dpy) { 937 // Calculate the actionsafe dimensions for External(dpy = 1 or 2) 938 getActionSafePosition(ctx, dpy, x, y, w, h); 939 // Convert position to hwc_rect_t 940 dst.left = x; 941 dst.top = y; 942 dst.right = w + dst.left; 943 dst.bottom = h + dst.top; 944 } 945 946 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 && 947 ctx->mMDP.version < qdutils::MDSS_V5) { 948 downscale = getDownscaleFactor( 949 crop.right - crop.left, 950 crop.bottom - crop.top, 951 dst.right - dst.left, 952 dst.bottom - dst.top); 953 if(downscale) { 954 rotFlags = ROT_DOWNSCALE_ENABLED; 955 } 956 } 957 958 setMdpFlags(layer, mdpFlags, downscale); 959 trimLayer(ctx, dpy, transform, crop, dst); 960 961 //Will do something only if feature enabled and conditions suitable 962 //hollow call otherwise 963 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) { 964 overlay::Writeback *wb = overlay::Writeback::getInstance(); 965 whf.format = wb->getOutputFormat(); 966 } 967 968 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot 969 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) { 970 *rot = ctx->mRotMgr->getNext(); 971 if(*rot == NULL) return -1; 972 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags); 973 //Configure rotator for pre-rotation 974 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) { 975 ALOGE("%s: configRotator failed!", __FUNCTION__); 976 ctx->mOverlay->clear(dpy); 977 return -1; 978 } 979 ctx->mLayerRotMap[dpy]->add(layer, *rot); 980 whf.format = (*rot)->getDstFormat(); 981 updateSource(orient, whf, crop); 982 rotFlags |= ovutils::ROT_PREROTATED; 983 } 984 985 //For the mdp, since either we are pre-rotating or MDP does flips 986 orient = OVERLAY_TRANSFORM_0; 987 transform = 0; 988 989 PipeArgs parg(mdpFlags, whf, z, isFg, 990 static_cast<eRotFlags>(rotFlags), layer->planeAlpha, 991 (ovutils::eBlending) getBlending(layer->blending)); 992 993 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) { 994 ALOGE("%s: commit failed for low res panel", __FUNCTION__); 995 ctx->mLayerRotMap[dpy]->reset(); 996 return -1; 997 } 998 return 0; 999} 1000 1001int configureHighRes(hwc_context_t *ctx, hwc_layer_1_t *layer, 1002 const int& dpy, eMdpFlags& mdpFlagsL, const eZorder& z, 1003 const eIsFg& isFg, const eDest& lDest, const eDest& rDest, 1004 Rotator **rot) { 1005 private_handle_t *hnd = (private_handle_t *)layer->handle; 1006 if(!hnd) { 1007 ALOGE("%s: layer handle is NULL", __FUNCTION__); 1008 return -1; 1009 } 1010 1011 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; 1012 1013 int hw_w = ctx->dpyAttr[dpy].xres; 1014 int hw_h = ctx->dpyAttr[dpy].yres; 1015 hwc_rect_t crop = layer->sourceCrop; 1016 hwc_rect_t dst = layer->displayFrame; 1017 int transform = layer->transform; 1018 eTransform orient = static_cast<eTransform>(transform); 1019 const int downscale = 0; 1020 int rotFlags = ROT_FLAGS_NONE; 1021 1022 Whf whf(hnd->width, hnd->height, 1023 getMdpFormat(hnd->format), hnd->size); 1024 1025 setMdpFlags(layer, mdpFlagsL, 0); 1026 trimLayer(ctx, dpy, transform, crop, dst); 1027 1028 //Will do something only if feature enabled and conditions suitable 1029 //hollow call otherwise 1030 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) { 1031 overlay::Writeback *wb = overlay::Writeback::getInstance(); 1032 whf.format = wb->getOutputFormat(); 1033 } 1034 1035 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) { 1036 (*rot) = ctx->mRotMgr->getNext(); 1037 if((*rot) == NULL) return -1; 1038 //Configure rotator for pre-rotation 1039 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { 1040 ALOGE("%s: configRotator failed!", __FUNCTION__); 1041 ctx->mOverlay->clear(dpy); 1042 return -1; 1043 } 1044 ctx->mLayerRotMap[dpy]->add(layer, *rot); 1045 whf.format = (*rot)->getDstFormat(); 1046 updateSource(orient, whf, crop); 1047 rotFlags |= ROT_PREROTATED; 1048 } 1049 1050 eMdpFlags mdpFlagsR = mdpFlagsL; 1051 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER); 1052 1053 hwc_rect_t tmp_cropL, tmp_dstL; 1054 hwc_rect_t tmp_cropR, tmp_dstR; 1055 1056 const int lSplit = getLeftSplit(ctx, dpy); 1057 1058 if(lDest != OV_INVALID) { 1059 tmp_cropL = crop; 1060 tmp_dstL = dst; 1061 hwc_rect_t scissor = {0, 0, lSplit, hw_h }; 1062 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); 1063 } 1064 if(rDest != OV_INVALID) { 1065 tmp_cropR = crop; 1066 tmp_dstR = dst; 1067 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h }; 1068 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); 1069 } 1070 1071 //When buffer is H-flipped, contents of mixer config also needs to swapped 1072 //Not needed if the layer is confined to one half of the screen. 1073 //If rotator has been used then it has also done the flips, so ignore them. 1074 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID 1075 && rDest != OV_INVALID && (*rot) == NULL) { 1076 hwc_rect_t new_cropR; 1077 new_cropR.left = tmp_cropL.left; 1078 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); 1079 1080 hwc_rect_t new_cropL; 1081 new_cropL.left = new_cropR.right; 1082 new_cropL.right = tmp_cropR.right; 1083 1084 tmp_cropL.left = new_cropL.left; 1085 tmp_cropL.right = new_cropL.right; 1086 1087 tmp_cropR.left = new_cropR.left; 1088 tmp_cropR.right = new_cropR.right; 1089 1090 } 1091 1092 //For the mdp, since either we are pre-rotating or MDP does flips 1093 orient = OVERLAY_TRANSFORM_0; 1094 transform = 0; 1095 1096 //configure left mixer 1097 if(lDest != OV_INVALID) { 1098 PipeArgs pargL(mdpFlagsL, whf, z, isFg, 1099 static_cast<eRotFlags>(rotFlags), layer->planeAlpha, 1100 (ovutils::eBlending) getBlending(layer->blending)); 1101 1102 if(configMdp(ctx->mOverlay, pargL, orient, 1103 tmp_cropL, tmp_dstL, metadata, lDest) < 0) { 1104 ALOGE("%s: commit failed for left mixer config", __FUNCTION__); 1105 return -1; 1106 } 1107 } 1108 1109 //configure right mixer 1110 if(rDest != OV_INVALID) { 1111 PipeArgs pargR(mdpFlagsR, whf, z, isFg, 1112 static_cast<eRotFlags>(rotFlags), layer->planeAlpha, 1113 (ovutils::eBlending) getBlending(layer->blending)); 1114 1115 tmp_dstR.right = tmp_dstR.right - lSplit; 1116 tmp_dstR.left = tmp_dstR.left - lSplit; 1117 if(configMdp(ctx->mOverlay, pargR, orient, 1118 tmp_cropR, tmp_dstR, metadata, rDest) < 0) { 1119 ALOGE("%s: commit failed for right mixer config", __FUNCTION__); 1120 return -1; 1121 } 1122 } 1123 1124 return 0; 1125} 1126 1127bool canUseRotator(hwc_context_t *ctx) { 1128 if(qdutils::MDPVersion::getInstance().is8x26() && 1129 ctx->mExtDisplay->isExternalConnected()) { 1130 return false; 1131 } 1132 if(ctx->mMDP.version == qdutils::MDP_V3_0_4) 1133 return false; 1134 return true; 1135} 1136 1137int getLeftSplit(hwc_context_t *ctx, const int& dpy) { 1138 //Default even split for all displays with high res 1139 int lSplit = ctx->dpyAttr[dpy].xres / 2; 1140 if(dpy == HWC_DISPLAY_PRIMARY && 1141 qdutils::MDPVersion::getInstance().getLeftSplit()) { 1142 //Override if split published by driver for primary 1143 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit(); 1144 } 1145 return lSplit; 1146} 1147 1148void setupSecondaryObjs(hwc_context_t *ctx, const int& dpy) { 1149 const int rSplit = 0; 1150 ctx->mFBUpdate[dpy] = 1151 IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, rSplit, dpy); 1152 ctx->mMDPComp[dpy] = MDPComp::getObject( 1153 ctx->dpyAttr[dpy].xres, rSplit, dpy); 1154 1155 int compositionType = 1156 qdutils::QCCompositionType::getInstance().getCompositionType(); 1157 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | 1158 qdutils::COMPOSITION_TYPE_MDP | 1159 qdutils::COMPOSITION_TYPE_C2D)) { 1160 ctx->mCopyBit[dpy] = new CopyBit(); 1161 } 1162} 1163 1164void clearSecondaryObjs(hwc_context_t *ctx, const int& dpy) { 1165 if(ctx->mFBUpdate[dpy]) { 1166 delete ctx->mFBUpdate[dpy]; 1167 ctx->mFBUpdate[dpy] = NULL; 1168 } 1169 if(ctx->mCopyBit[dpy]){ 1170 delete ctx->mCopyBit[dpy]; 1171 ctx->mCopyBit[dpy] = NULL; 1172 } 1173 if(ctx->mMDPComp[dpy]) { 1174 delete ctx->mMDPComp[dpy]; 1175 ctx->mMDPComp[dpy] = NULL; 1176 } 1177} 1178 1179void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop, 1180 const hwc_rect_t& dst, const int& transform, 1181 ovutils::eMdpFlags& mdpFlags) { 1182 //Target doesnt support Bwc 1183 if(!qdutils::MDPVersion::getInstance().supportsBWC()) { 1184 return; 1185 } 1186 //src width > MAX mixer supported dim 1187 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) { 1188 return; 1189 } 1190 //External connected 1191 if(ctx->mExtDisplay->isExternalConnected()) { 1192 return; 1193 } 1194 //Decimation necessary, cannot use BWC. H/W requirement. 1195 if(qdutils::MDPVersion::getInstance().supportsDecimation()) { 1196 int src_w = crop.right - crop.left; 1197 int src_h = crop.bottom - crop.top; 1198 int dst_w = dst.right - dst.left; 1199 int dst_h = dst.bottom - dst.top; 1200 if(transform & HAL_TRANSFORM_ROT_90) { 1201 swap(src_w, src_h); 1202 } 1203 float horDscale = 0.0f; 1204 float verDscale = 0.0f; 1205 int horzDeci = 0; 1206 int vertDeci = 0; 1207 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale, 1208 verDscale); 1209 //TODO Use log2f once math.h has it 1210 if((int)horDscale) 1211 horzDeci = (int)(log(horDscale) / log(2)); 1212 if((int)verDscale) 1213 vertDeci = (int)(log(verDscale) / log(2)); 1214 if(horzDeci || vertDeci) return; 1215 } 1216 //Property 1217 char value[PROPERTY_VALUE_MAX]; 1218 property_get("debug.disable.bwc", value, "0"); 1219 if(atoi(value)) return; 1220 1221 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN); 1222} 1223 1224void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) { 1225 if(mCount >= MAX_SESS) return; 1226 mLayer[mCount] = layer; 1227 mRot[mCount] = rot; 1228 mCount++; 1229} 1230 1231void LayerRotMap::reset() { 1232 for (int i = 0; i < MAX_SESS; i++) { 1233 mLayer[i] = 0; 1234 mRot[i] = 0; 1235 } 1236 mCount = 0; 1237} 1238 1239void LayerRotMap::setReleaseFd(const int& fence) { 1240 for(uint32_t i = 0; i < mCount; i++) { 1241 mRot[i]->setReleaseFd(dup(fence)); 1242 } 1243} 1244 1245};//namespace qhwc 1246