hwc_fbupdate.cpp revision 348ca172f707a14925ba1652e9bcb3d4c2a695f4
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved. 4 * 5 * Not a Contribution, Apache license notifications and license are 6 * retained 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 21#define DEBUG_FBUPDATE 0 22#include <cutils/properties.h> 23#include <gralloc_priv.h> 24#include <overlay.h> 25#include <overlayRotator.h> 26#include "hwc_fbupdate.h" 27#include "mdp_version.h" 28#include "external.h" 29#include "virtual.h" 30 31using namespace qdutils; 32using namespace overlay; 33using overlay::Rotator; 34using namespace overlay::utils; 35 36namespace qhwc { 37 38namespace ovutils = overlay::utils; 39 40IFBUpdate* IFBUpdate::getObject(hwc_context_t *ctx, const int& dpy) { 41 if(isDisplaySplit(ctx, dpy)) { 42 if(qdutils::MDPVersion::getInstance().isSrcSplit()) { 43 return new FBSrcSplit(ctx, dpy); 44 } 45 return new FBUpdateSplit(ctx, dpy); 46 } 47 return new FBUpdateNonSplit(ctx, dpy); 48} 49 50IFBUpdate::IFBUpdate(hwc_context_t *ctx, const int& dpy) : mDpy(dpy) { 51 size_t size = 0; 52 getBufferAttributes(ctx->dpyAttr[mDpy].xres, 53 ctx->dpyAttr[mDpy].yres, 54 HAL_PIXEL_FORMAT_RGBA_8888, 55 0, 56 mAlignedFBWidth, 57 mAlignedFBHeight, 58 mTileEnabled, size); 59} 60 61void IFBUpdate::reset() { 62 mModeOn = false; 63 mRot = NULL; 64} 65 66bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx, 67 hwc_display_contents_1 *list, int fbZorder) { 68 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; 69 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) && 70 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd); 71 return mModeOn; 72} 73 74//================= Low res==================================== 75FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy): 76 IFBUpdate(ctx, dpy) {} 77 78void FBUpdateNonSplit::reset() { 79 IFBUpdate::reset(); 80 mDest = ovutils::OV_INVALID; 81} 82 83bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx, 84 hwc_layer_1_t *layer, 85 ovutils::Whf &info, 86 hwc_rect_t& sourceCrop, 87 ovutils::eMdpFlags& mdpFlags, 88 int& rotFlags) 89{ 90 int extOrient = getExtOrientation(ctx); 91 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient); 92 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) { 93 mRot = ctx->mRotMgr->getNext(); 94 if(mRot == NULL) return false; 95 // Composed FB content will have black bars, if the viewFrame of the 96 // external is different from {0, 0, fbWidth, fbHeight}, so intersect 97 // viewFrame with sourceCrop to avoid those black bars 98 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]); 99 //Configure rotator for pre-rotation 100 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) { 101 ALOGE("%s: configRotator Failed!", __FUNCTION__); 102 mRot = NULL; 103 return false; 104 } 105 ctx->mLayerRotMap[mDpy]->add(layer, mRot); 106 info.format = (mRot)->getDstFormat(); 107 updateSource(orient, info, sourceCrop); 108 rotFlags |= ovutils::ROT_PREROTATED; 109 } 110 return true; 111} 112 113bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list, 114 hwc_rect_t fbUpdatingRect, int fbZorder) { 115 if(!ctx->mMDP.hasOverlay) { 116 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays", 117 __FUNCTION__); 118 return false; 119 } 120 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder); 121 return mModeOn; 122} 123 124// Configure 125bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list, 126 hwc_rect_t fbUpdatingRect, int fbZorder) { 127 bool ret = false; 128 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; 129 if (LIKELY(ctx->mOverlay)) { 130 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex; 131 // ext only layer present.. 132 if(extOnlyLayerIndex != -1) { 133 layer = &list->hwLayers[extOnlyLayerIndex]; 134 layer->compositionType = HWC_OVERLAY; 135 } 136 overlay::Overlay& ov = *(ctx->mOverlay); 137 138 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight, 139 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, 140 mTileEnabled)); 141 142 //Request a pipe 143 ovutils::eMdpPipeType type = ovutils::OV_MDP_PIPE_ANY; 144 if(qdutils::MDPVersion::getInstance().is8x26() && mDpy) { 145 //For 8x26 external always use DMA pipe 146 type = ovutils::OV_MDP_PIPE_DMA; 147 } 148 ovutils::eDest dest = ov.nextPipe(type, mDpy, Overlay::MIXER_DEFAULT); 149 if(dest == ovutils::OV_INVALID) { //None available 150 ALOGE("%s: No pipes available to configure fb for dpy %d", 151 __FUNCTION__, mDpy); 152 return false; 153 } 154 mDest = dest; 155 156 if((mDpy && ctx->deviceOrientation) && 157 ctx->listStats[mDpy].isDisplayAnimating) { 158 fbZorder = 0; 159 } 160 161 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT; 162 ovutils::eIsFg isFg = ovutils::IS_FG_OFF; 163 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder); 164 165 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); 166 hwc_rect_t displayFrame = layer->displayFrame; 167 168 // No FB update optimization on (1) Custom FB resolution, 169 // (2) External Mirror mode, (3) External orientation 170 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode 171 && !ctx->mExtOrientation) { 172 sourceCrop = fbUpdatingRect; 173 displayFrame = fbUpdatingRect; 174 } 175 176 int transform = layer->transform; 177 int rotFlags = ovutils::ROT_FLAGS_NONE; 178 179 ovutils::eTransform orient = 180 static_cast<ovutils::eTransform>(transform); 181 // use ext orientation if any 182 int extOrient = getExtOrientation(ctx); 183 184 // Do not use getNonWormholeRegion() function to calculate the 185 // sourceCrop during animation on external display and 186 // Dont do wormhole calculation when extorientation is set on External 187 // Dont do wormhole calculation when extDownscale is enabled on External 188 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) { 189 sourceCrop = layer->displayFrame; 190 } else if((!mDpy || 191 (mDpy && !extOrient 192 && !ctx->dpyAttr[mDpy].mDownScaleMode)) 193 && (extOnlyLayerIndex == -1)) { 194 if(!qdutils::MDPVersion::getInstance().is8x26() && 195 !ctx->dpyAttr[mDpy].customFBSize) { 196 getNonWormholeRegion(list, sourceCrop); 197 displayFrame = sourceCrop; 198 } 199 } 200 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame, 201 transform, orient); 202 //Store the displayFrame, will be used in getDisplayViewFrame 203 ctx->dpyAttr[mDpy].mDstRect = displayFrame; 204 setMdpFlags(layer, mdpFlags, 0, transform); 205 // For External use rotator if there is a rotation value set 206 ret = preRotateExtDisplay(ctx, layer, info, 207 sourceCrop, mdpFlags, rotFlags); 208 if(!ret) { 209 ALOGE("%s: preRotate for external Failed!", __FUNCTION__); 210 ctx->mOverlay->clear(mDpy); 211 ctx->mLayerRotMap[mDpy]->clear(); 212 return false; 213 } 214 //For the mdp, since either we are pre-rotating or MDP does flips 215 orient = ovutils::OVERLAY_TRANSFORM_0; 216 transform = 0; 217 ovutils::PipeArgs parg(mdpFlags, info, zOrder, isFg, 218 static_cast<ovutils::eRotFlags>(rotFlags), 219 ovutils::DEFAULT_PLANE_ALPHA, 220 (ovutils::eBlending) 221 getBlending(layer->blending)); 222 ret = true; 223 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame, 224 NULL, mDest) < 0) { 225 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy); 226 ctx->mLayerRotMap[mDpy]->clear(); 227 ret = false; 228 } 229 } 230 return ret; 231} 232 233bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd) 234{ 235 if(!mModeOn) { 236 return true; 237 } 238 bool ret = true; 239 overlay::Overlay& ov = *(ctx->mOverlay); 240 ovutils::eDest dest = mDest; 241 int fd = hnd->fd; 242 uint32_t offset = hnd->offset; 243 if(mRot) { 244 if(!mRot->queueBuffer(fd, offset)) 245 return false; 246 fd = mRot->getDstMemId(); 247 offset = mRot->getDstOffset(); 248 } 249 if (!ov.queueBuffer(fd, offset, dest)) { 250 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__); 251 ret = false; 252 } 253 return ret; 254} 255 256//================= High res==================================== 257FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy): 258 IFBUpdate(ctx, dpy) {} 259 260void FBUpdateSplit::reset() { 261 IFBUpdate::reset(); 262 mDestLeft = ovutils::OV_INVALID; 263 mDestRight = ovutils::OV_INVALID; 264 mRot = NULL; 265} 266 267bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list, 268 hwc_rect_t fbUpdatingRect, int fbZorder) { 269 if(!ctx->mMDP.hasOverlay) { 270 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays", 271 __FUNCTION__); 272 return false; 273 } 274 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn); 275 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder); 276 return mModeOn; 277} 278 279// Configure 280bool FBUpdateSplit::configure(hwc_context_t *ctx, 281 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) { 282 bool ret = false; 283 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; 284 if (LIKELY(ctx->mOverlay)) { 285 /* External only layer present */ 286 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex; 287 if(extOnlyLayerIndex != -1) { 288 layer = &list->hwLayers[extOnlyLayerIndex]; 289 layer->compositionType = HWC_OVERLAY; 290 } 291 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight, 292 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, 293 mTileEnabled)); 294 295 overlay::Overlay& ov = *(ctx->mOverlay); 296 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT; 297 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder); 298 ovutils::eTransform orient = 299 static_cast<ovutils::eTransform>(layer->transform); 300 const int hw_w = ctx->dpyAttr[mDpy].xres; 301 const int hw_h = ctx->dpyAttr[mDpy].yres; 302 const int lSplit = getLeftSplit(ctx, mDpy); 303 mDestLeft = ovutils::OV_INVALID; 304 mDestRight = ovutils::OV_INVALID; 305 306 hwc_rect_t sourceCrop = fbUpdatingRect; 307 hwc_rect_t displayFrame = fbUpdatingRect; 308 309 ret = true; 310 /* Configure left pipe */ 311 if(displayFrame.left < lSplit) { 312 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy, 313 Overlay::MIXER_LEFT); 314 if(destL == ovutils::OV_INVALID) { //None available 315 ALOGE("%s: No pipes available to configure fb for dpy %d's left" 316 " mixer", __FUNCTION__, mDpy); 317 return false; 318 } 319 320 mDestLeft = destL; 321 322 //XXX: FB layer plane alpha is currently sent as zero from 323 //surfaceflinger 324 ovutils::PipeArgs pargL(mdpFlags, 325 info, 326 zOrder, 327 ovutils::IS_FG_OFF, 328 ovutils::ROT_FLAGS_NONE, 329 ovutils::DEFAULT_PLANE_ALPHA, 330 (ovutils::eBlending) 331 getBlending(layer->blending)); 332 hwc_rect_t cropL = sourceCrop; 333 hwc_rect_t dstL = displayFrame; 334 hwc_rect_t scissorL = {0, 0, lSplit, hw_h }; 335 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0); 336 337 if (configMdp(ctx->mOverlay, pargL, orient, cropL, 338 dstL, NULL, destL)< 0) { 339 ALOGE("%s: configMdp fails for left FB", __FUNCTION__); 340 ret = false; 341 } 342 } 343 344 /* Configure right pipe */ 345 if(displayFrame.right > lSplit) { 346 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy, 347 Overlay::MIXER_RIGHT); 348 if(destR == ovutils::OV_INVALID) { //None available 349 ALOGE("%s: No pipes available to configure fb for dpy %d's" 350 " right mixer", __FUNCTION__, mDpy); 351 return false; 352 } 353 354 mDestRight = destR; 355 ovutils::eMdpFlags mdpFlagsR = mdpFlags; 356 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER); 357 358 //XXX: FB layer plane alpha is currently sent as zero from 359 //surfaceflinger 360 ovutils::PipeArgs pargR(mdpFlagsR, 361 info, 362 zOrder, 363 ovutils::IS_FG_OFF, 364 ovutils::ROT_FLAGS_NONE, 365 ovutils::DEFAULT_PLANE_ALPHA, 366 (ovutils::eBlending) 367 getBlending(layer->blending)); 368 369 hwc_rect_t cropR = sourceCrop; 370 hwc_rect_t dstR = displayFrame; 371 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h }; 372 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0); 373 374 dstR.left -= lSplit; 375 dstR.right -= lSplit; 376 377 if (configMdp(ctx->mOverlay, pargR, orient, cropR, 378 dstR, NULL, destR) < 0) { 379 ALOGE("%s: configMdp fails for right FB", __FUNCTION__); 380 ret = false; 381 } 382 } 383 384 if(ret == false) { 385 ctx->mLayerRotMap[mDpy]->clear(); 386 } 387 } 388 return ret; 389} 390 391bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd) 392{ 393 if(!mModeOn) { 394 return true; 395 } 396 bool ret = true; 397 overlay::Overlay& ov = *(ctx->mOverlay); 398 if(mDestLeft != ovutils::OV_INVALID) { 399 if (!ov.queueBuffer(hnd->fd, hnd->offset, mDestLeft)) { 400 ALOGE("%s: queue failed for left of dpy = %d", 401 __FUNCTION__, mDpy); 402 ret = false; 403 } 404 } 405 if(mDestRight != ovutils::OV_INVALID) { 406 if (!ov.queueBuffer(hnd->fd, hnd->offset, mDestRight)) { 407 ALOGE("%s: queue failed for right of dpy = %d", 408 __FUNCTION__, mDpy); 409 ret = false; 410 } 411 } 412 return ret; 413} 414 415//=================FBSrcSplit==================================== 416FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy): 417 FBUpdateSplit(ctx, dpy) {} 418 419bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list, 420 hwc_rect_t fbUpdatingRect, int fbZorder) { 421 bool ret = false; 422 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; 423 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex; 424 // ext only layer present.. 425 if(extOnlyLayerIndex != -1) { 426 layer = &list->hwLayers[extOnlyLayerIndex]; 427 layer->compositionType = HWC_OVERLAY; 428 } 429 430 overlay::Overlay& ov = *(ctx->mOverlay); 431 432 ovutils::Whf info(mAlignedFBWidth, 433 mAlignedFBHeight, 434 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, 435 mTileEnabled)); 436 437 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT; 438 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder); 439 440 ovutils::PipeArgs parg(mdpFlags, 441 info, 442 zOrder, 443 ovutils::IS_FG_OFF, 444 ovutils::ROT_FLAGS_NONE, 445 ovutils::DEFAULT_PLANE_ALPHA, 446 (ovutils::eBlending) 447 getBlending(layer->blending)); 448 449 int transform = layer->transform; 450 ovutils::eTransform orient = 451 static_cast<ovutils::eTransform>(transform); 452 453 hwc_rect_t cropL = fbUpdatingRect; 454 hwc_rect_t cropR = fbUpdatingRect; 455 456 //Request left pipe (or 1 by default) 457 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy, 458 Overlay::MIXER_DEFAULT); 459 if(destL == ovutils::OV_INVALID) { 460 ALOGE("%s: No pipes available to configure fb for dpy %d's left" 461 " mixer", __FUNCTION__, mDpy); 462 return false; 463 } 464 465 ovutils::eDest destR = ovutils::OV_INVALID; 466 467 //Request right pipe (2 pipes needed only if dim > 2048) 468 if((fbUpdatingRect.right - fbUpdatingRect.left) > 469 qdutils::MAX_DISPLAY_DIM) { 470 destR = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy, 471 Overlay::MIXER_DEFAULT); 472 if(destR == ovutils::OV_INVALID) { 473 ALOGE("%s: No pipes available to configure fb for dpy %d's right" 474 " mixer", __FUNCTION__, mDpy); 475 return false; 476 } 477 478 if(ctx->mOverlay->comparePipePriority(destL, destR) == -1) { 479 qhwc::swap(destL, destR); 480 } 481 482 //Split crop equally when using 2 pipes 483 cropL.right = (fbUpdatingRect.right + fbUpdatingRect.left) / 2; 484 cropR.left = cropL.right; 485 } 486 487 mDestLeft = destL; 488 mDestRight = destR; 489 490 if(destL != OV_INVALID) { 491 if(configMdp(ctx->mOverlay, parg, orient, 492 cropL, cropL, NULL /*metadata*/, destL) < 0) { 493 ALOGE("%s: commit failed for left mixer config", __FUNCTION__); 494 ctx->mLayerRotMap[mDpy]->clear(); 495 return false; 496 } 497 } 498 499 //configure right pipe 500 if(destR != OV_INVALID) { 501 if(configMdp(ctx->mOverlay, parg, orient, 502 cropR, cropR, NULL /*metadata*/, destR) < 0) { 503 ALOGE("%s: commit failed for right mixer config", __FUNCTION__); 504 ctx->mLayerRotMap[mDpy]->clear(); 505 return false; 506 } 507 } 508 509 return true; 510} 511 512//--------------------------------------------------------------------- 513}; //namespace qhwc 514