Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 3 | * Copyright (C) 2012-2015, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 4 | * |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 5 | * Not a Contribution. |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 20 | #define DEBUG_COPYBIT 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #include <copybit.h> |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 22 | #include <utils/Timers.h> |
Terence Hampson | 0124cc7 | 2013-04-18 23:45:56 -0700 | [diff] [blame] | 23 | #include <mdp_version.h> |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 24 | #include "hwc_copybit.h" |
| 25 | #include "comptype.h" |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 26 | #include "gr.h" |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 27 | #include "cb_utils.h" |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 28 | #include "cb_swap_rect.h" |
Ramakant Singh | 80f36f2 | 2014-02-25 14:11:35 +0530 | [diff] [blame] | 29 | #include "math.h" |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 30 | #include "sync/sync.h" |
| 31 | |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 32 | using namespace qdutils; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 33 | namespace qhwc { |
| 34 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 35 | struct range { |
| 36 | int current; |
| 37 | int end; |
| 38 | }; |
| 39 | struct region_iterator : public copybit_region_t { |
| 40 | |
| 41 | region_iterator(hwc_region_t region) { |
| 42 | mRegion = region; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 43 | r.end = (int)region.numRects; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 44 | r.current = 0; |
| 45 | this->next = iterate; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | static int iterate(copybit_region_t const * self, copybit_rect_t* rect){ |
| 50 | if (!self || !rect) { |
| 51 | ALOGE("iterate invalid parameters"); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | region_iterator const* me = |
| 56 | static_cast<region_iterator const*>(self); |
| 57 | if (me->r.current != me->r.end) { |
| 58 | rect->l = me->mRegion.rects[me->r.current].left; |
| 59 | rect->t = me->mRegion.rects[me->r.current].top; |
| 60 | rect->r = me->mRegion.rects[me->r.current].right; |
| 61 | rect->b = me->mRegion.rects[me->r.current].bottom; |
| 62 | me->r.current++; |
| 63 | return 1; |
| 64 | } |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | hwc_region_t mRegion; |
| 69 | mutable range r; |
| 70 | }; |
| 71 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 72 | void CopyBit::reset() { |
| 73 | mIsModeOn = false; |
| 74 | mCopyBitDraw = false; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 77 | bool CopyBit::canUseCopybitForYUV(hwc_context_t *ctx) { |
| 78 | // return true for non-overlay targets |
Terence Hampson | d0fd579 | 2013-05-29 11:56:52 -0400 | [diff] [blame] | 79 | if(ctx->mMDP.hasOverlay && ctx->mMDP.version >= qdutils::MDP_V4_0) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 80 | return false; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 81 | } |
| 82 | return true; |
| 83 | } |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 84 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 85 | bool CopyBit::canUseCopybitForRGB(hwc_context_t *ctx, |
| 86 | hwc_display_contents_1_t *list, |
| 87 | int dpy) { |
| 88 | int compositionType = qdutils::QCCompositionType:: |
| 89 | getInstance().getCompositionType(); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 90 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 91 | if (compositionType & qdutils::COMPOSITION_TYPE_DYN) { |
| 92 | // DYN Composition: |
Prabhanjan Kandula | 73030ba | 2013-03-15 22:33:39 +0530 | [diff] [blame] | 93 | // use copybit, if (TotalRGBRenderArea < threashold * FB Area) |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 94 | // this is done based on perf inputs in ICS |
| 95 | // TODO: Above condition needs to be re-evaluated in JB |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 96 | int fbWidth = ctx->dpyAttr[dpy].xres; |
| 97 | int fbHeight = ctx->dpyAttr[dpy].yres; |
| 98 | unsigned int fbArea = (fbWidth * fbHeight); |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame] | 99 | unsigned int renderArea = getRGBRenderingArea(ctx, list); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 100 | ALOGD_IF (DEBUG_COPYBIT, "%s:renderArea %u, fbArea %u", |
| 101 | __FUNCTION__, renderArea, fbArea); |
Prabhanjan Kandula | 73030ba | 2013-03-15 22:33:39 +0530 | [diff] [blame] | 102 | if (renderArea < (mDynThreshold * fbArea)) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | } else if ((compositionType & qdutils::COMPOSITION_TYPE_MDP)) { |
| 106 | // MDP composition, use COPYBIT always |
| 107 | return true; |
| 108 | } else if ((compositionType & qdutils::COMPOSITION_TYPE_C2D)) { |
| 109 | // C2D composition, use COPYBIT |
| 110 | return true; |
| 111 | } |
| 112 | return false; |
| 113 | } |
| 114 | |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame] | 115 | unsigned int CopyBit::getRGBRenderingArea (const hwc_context_t *ctx, |
| 116 | const hwc_display_contents_1_t *list) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 117 | //Calculates total rendering area for RGB layers |
| 118 | unsigned int renderArea = 0; |
| 119 | unsigned int w=0, h=0; |
Terence Hampson | ef379d4 | 2013-05-21 10:38:01 -0400 | [diff] [blame] | 120 | // Skipping last layer since FrameBuffer layer should not affect |
| 121 | // which composition to choose |
| 122 | for (unsigned int i=0; i<list->numHwLayers -1; i++) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 123 | private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle; |
| 124 | if (hnd) { |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame] | 125 | if (BUFFER_TYPE_UI == hnd->bufferType && !ctx->copybitDrop[i]) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 126 | getLayerResolution(&list->hwLayers[i], w, h); |
| 127 | renderArea += (w*h); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | return renderArea; |
| 132 | } |
| 133 | |
Dileep Kumar Reddi | 9dab73a | 2015-02-24 16:15:53 +0530 | [diff] [blame] | 134 | bool CopyBit::isLayerChanging(hwc_context_t *ctx, |
| 135 | hwc_display_contents_1_t *list, int k) { |
Dileep Kumar Reddi | aa48888 | 2014-12-16 11:19:45 +0530 | [diff] [blame] | 136 | if((mLayerCache.hnd[k] != list->hwLayers[k].handle) || |
Dileep Kumar Reddi | 9dab73a | 2015-02-24 16:15:53 +0530 | [diff] [blame] | 137 | (mLayerCache.drop[k] != ctx->copybitDrop[k]) || |
Dileep Kumar Reddi | aa48888 | 2014-12-16 11:19:45 +0530 | [diff] [blame] | 138 | (mLayerCache.displayFrame[k].left != |
| 139 | list->hwLayers[k].displayFrame.left) || |
| 140 | (mLayerCache.displayFrame[k].top != |
| 141 | list->hwLayers[k].displayFrame.top) || |
| 142 | (mLayerCache.displayFrame[k].right != |
| 143 | list->hwLayers[k].displayFrame.right) || |
| 144 | (mLayerCache.displayFrame[k].bottom != |
| 145 | list->hwLayers[k].displayFrame.bottom)) { |
| 146 | return 1; |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 151 | int CopyBit::getLayersChanging(hwc_context_t *ctx, |
| 152 | hwc_display_contents_1_t *list, |
| 153 | int dpy){ |
| 154 | |
| 155 | int changingLayerIndex = -1; |
| 156 | if(mLayerCache.layerCount != ctx->listStats[dpy].numAppLayers) { |
| 157 | mLayerCache.reset(); |
| 158 | mFbCache.reset(); |
| 159 | mLayerCache.updateCounts(ctx,list,dpy); |
| 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | int updatingLayerCount = 0; |
| 164 | for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){ |
| 165 | //swap rect will kick in only for single updating layer |
Dileep Kumar Reddi | 9dab73a | 2015-02-24 16:15:53 +0530 | [diff] [blame] | 166 | if(isLayerChanging(ctx, list, k)) { |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 167 | updatingLayerCount ++; |
| 168 | if(updatingLayerCount == 1) |
| 169 | changingLayerIndex = k; |
| 170 | } |
| 171 | } |
| 172 | //since we are using more than one framebuffers,we have to |
| 173 | //kick in swap rect only if we are getting continuous same |
| 174 | //dirty rect for same layer at least equal of number of |
| 175 | //framebuffers |
| 176 | |
| 177 | if ( updatingLayerCount == 1 ) { |
Saurabh Shah | 93c6905 | 2014-04-24 10:27:10 -0700 | [diff] [blame] | 178 | hwc_rect_t dirtyRect = list->hwLayers[changingLayerIndex].displayFrame; |
| 179 | #ifdef QCOM_BSP |
| 180 | dirtyRect = list->hwLayers[changingLayerIndex].dirtyRect; |
| 181 | #endif |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 182 | |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 183 | for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--) { |
| 184 | //disable swap rect in case of scaling and video . |
| 185 | private_handle_t *hnd =(private_handle_t *)list->hwLayers[k].handle; |
| 186 | if(needsScaling(&list->hwLayers[k])||( hnd && isYuvBuffer(hnd))) { |
| 187 | mFbCache.reset(); |
| 188 | return -1; |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 189 | } |
| 190 | } |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 191 | if(mFbCache.getUnchangedFbDRCount(dirtyRect) < |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 192 | NUM_RENDER_BUFFERS) { |
| 193 | mFbCache.insertAndUpdateFbCache(dirtyRect); |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 194 | changingLayerIndex = -1; |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 195 | } |
| 196 | } else { |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 197 | mFbCache.reset(); |
| 198 | changingLayerIndex = -1; |
| 199 | } |
| 200 | mLayerCache.updateCounts(ctx,list,dpy); |
| 201 | return changingLayerIndex; |
| 202 | } |
| 203 | |
| 204 | int CopyBit::checkDirtyRect(hwc_context_t *ctx, |
| 205 | hwc_display_contents_1_t *list, |
| 206 | int dpy) { |
| 207 | |
| 208 | //dirty rect will enable only if |
| 209 | //1.Only single layer is updating. |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 210 | //2.No scaling |
| 211 | //3.No video layer |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 212 | if(mSwapRectEnable == false) |
| 213 | return -1; |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 214 | return getLayersChanging(ctx, list, dpy); |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 215 | } |
| 216 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 217 | bool CopyBit::prepareOverlap(hwc_context_t *ctx, |
| 218 | hwc_display_contents_1_t *list) { |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 219 | |
| 220 | if (ctx->mMDP.version < qdutils::MDP_V4_0) { |
| 221 | ALOGE("%s: Invalid request", __FUNCTION__); |
| 222 | return false; |
| 223 | } |
| 224 | |
Saurabh Shah | 15455aa | 2015-01-28 13:54:48 -0800 | [diff] [blame] | 225 | if (mEngine == NULL) { |
| 226 | ALOGW("%s: Copybit HAL not enabled", __FUNCTION__); |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | if (!(validateParams(ctx, list))) { |
| 231 | ALOGE("%s: validateParams() failed", __FUNCTION__); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 232 | return false; |
| 233 | } |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 234 | PtorInfo* ptorInfo = &(ctx->mPtorInfo); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 235 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 236 | // Allocate render buffers if they're not allocated |
| 237 | int alignW = 0, alignH = 0; |
| 238 | int finalW = 0, finalH = 0; |
| 239 | for (int i = 0; i < ptorInfo->count; i++) { |
| 240 | int ovlapIndex = ptorInfo->layerIndex[i]; |
| 241 | hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame; |
| 242 | // render buffer width will be the max of two layers |
| 243 | // Align Widht and height to 32, Mdp would be configured |
| 244 | // with Aligned overlap w/h |
| 245 | finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32)); |
| 246 | finalH += ALIGN((overlap.bottom - overlap.top), 32); |
| 247 | if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) { |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 248 | // Calculate the dest top, left will always be zero |
| 249 | ptorInfo->displayFrame[i].top = (finalH - |
| 250 | (ALIGN((overlap.bottom - overlap.top), 32))); |
| 251 | } |
| 252 | // calculate the right and bottom values |
| 253 | ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left + |
| 254 | (overlap.right - overlap.left); |
| 255 | ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top + |
| 256 | (overlap.bottom - overlap.top); |
| 257 | } |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 258 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 259 | getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888, |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 260 | alignW, alignH); |
| 261 | |
| 262 | if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) { |
| 263 | // Overlap rect has changed, so free render buffers |
| 264 | freeRenderBuffers(); |
| 265 | } |
| 266 | |
| 267 | int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888); |
| 268 | |
| 269 | if (ret < 0) { |
| 270 | ALOGE("%s: Render buffer allocation failed", __FUNCTION__); |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | mAlignedWidth = alignW; |
| 275 | mAlignedHeight = alignH; |
| 276 | mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS; |
| 277 | return true; |
| 278 | } |
| 279 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 280 | bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 281 | int dpy) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 282 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 283 | if(mEngine == NULL) { |
| 284 | // No copybit device found - cannot use copybit |
| 285 | return false; |
| 286 | } |
Dileep Kumar Reddi | a25a918 | 2014-07-24 20:01:44 +0530 | [diff] [blame] | 287 | |
| 288 | if(ctx->mThermalBurstMode) { |
| 289 | ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed," |
| 290 | "Running in Thermal Burst mode",__FUNCTION__); |
| 291 | return false; |
| 292 | } |
| 293 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 294 | int compositionType = qdutils::QCCompositionType:: |
| 295 | getInstance().getCompositionType(); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 296 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 297 | if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) || |
| 298 | (compositionType == qdutils::COMPOSITION_TYPE_CPU)) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 299 | //GPU/CPU composition, don't change layer composition type |
| 300 | return true; |
| 301 | } |
| 302 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 303 | if(!(validateParams(ctx, list))) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 304 | ALOGE("%s:Invalid Params", __FUNCTION__); |
| 305 | return false; |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 308 | if(ctx->listStats[dpy].skipCount) { |
| 309 | //GPU will be anyways used |
| 310 | return false; |
| 311 | } |
| 312 | |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 313 | if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) { |
Sushil Chauhan | b00f59d | 2013-04-29 18:35:54 -0700 | [diff] [blame] | 314 | // Reached max layers supported by HWC. |
| 315 | return false; |
| 316 | } |
| 317 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 318 | bool useCopybitForYUV = canUseCopybitForYUV(ctx); |
| 319 | bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 320 | LayerProp *layerProp = ctx->layerProp[dpy]; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 321 | |
Radhika Ranjan Soni | 46cf4e9 | 2013-08-06 16:40:05 +0530 | [diff] [blame] | 322 | // Following are MDP3 limitations for which we |
| 323 | // need to fallback to GPU composition: |
Terence Hampson | b102193 | 2013-09-18 11:15:19 -0400 | [diff] [blame] | 324 | // 1. Plane alpha is not supported by MDP3. |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 325 | // 2. Scaling is within range |
Terence Hampson | c235bda | 2013-07-12 12:47:38 -0400 | [diff] [blame] | 326 | if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) { |
| 327 | for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) { |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 328 | int dst_h, dst_w, src_h, src_w; |
| 329 | float dx, dy; |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame] | 330 | if(ctx->copybitDrop[i]) { |
| 331 | continue; |
| 332 | } |
Terence Hampson | c235bda | 2013-07-12 12:47:38 -0400 | [diff] [blame] | 333 | hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i]; |
Radhika Ranjan Soni | 46cf4e9 | 2013-08-06 16:40:05 +0530 | [diff] [blame] | 334 | if (layer->planeAlpha != 0xFF) |
| 335 | return true; |
Ramakant Singh | f2b51e6 | 2013-11-28 12:07:51 +0530 | [diff] [blame] | 336 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 337 | |
Sushil Chauhan | fda00fc | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 338 | if (has90Transform(layer)) { |
Ramakant Singh | f2b51e6 | 2013-11-28 12:07:51 +0530 | [diff] [blame] | 339 | src_h = sourceCrop.right - sourceCrop.left; |
| 340 | src_w = sourceCrop.bottom - sourceCrop.top; |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 341 | } else { |
Ramakant Singh | f2b51e6 | 2013-11-28 12:07:51 +0530 | [diff] [blame] | 342 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 343 | src_w = sourceCrop.right - sourceCrop.left; |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 344 | } |
| 345 | dst_h = layer->displayFrame.bottom - layer->displayFrame.top; |
| 346 | dst_w = layer->displayFrame.right - layer->displayFrame.left; |
| 347 | |
Ramakant Singh | 0b35f2c | 2014-01-07 11:25:48 +0530 | [diff] [blame] | 348 | if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) { |
| 349 | ALOGE("%s: wrong params for display screen_w=%d \ |
| 350 | src_crop_width=%d screen_h=%d src_crop_height=%d", |
| 351 | __FUNCTION__, dst_w,src_w,dst_h,src_h); |
| 352 | return false; |
| 353 | } |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 354 | dx = (float)dst_w/(float)src_w; |
| 355 | dy = (float)dst_h/(float)src_h; |
Ramakant Singh | 0b35f2c | 2014-01-07 11:25:48 +0530 | [diff] [blame] | 356 | |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 357 | if (dx > MAX_SCALE_FACTOR || dx < MIN_SCALE_FACTOR) |
| 358 | return false; |
| 359 | |
| 360 | if (dy > MAX_SCALE_FACTOR || dy < MIN_SCALE_FACTOR) |
| 361 | return false; |
Terence Hampson | c235bda | 2013-07-12 12:47:38 -0400 | [diff] [blame] | 362 | } |
| 363 | } |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 364 | |
| 365 | //Allocate render buffers if they're not allocated |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 366 | if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 && |
| 367 | ctx->mMDP.version != qdutils::MDP_V3_0_5) && |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 368 | (useCopybitForYUV || useCopybitForRGB)) { |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 369 | int ret = allocRenderBuffers(mAlignedWidth, |
| 370 | mAlignedHeight, |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 371 | HAL_PIXEL_FORMAT_RGBA_8888); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 372 | if (ret < 0) { |
| 373 | return false; |
| 374 | } else { |
| 375 | mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % |
| 376 | NUM_RENDER_BUFFERS; |
| 377 | } |
| 378 | } |
| 379 | |
Terence Hampson | d0fd579 | 2013-05-29 11:56:52 -0400 | [diff] [blame] | 380 | // We cannot mix copybit layer with layers marked to be drawn on FB |
| 381 | if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount) |
| 382 | return true; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 383 | |
Radhika Ranjan Soni | 14f6c4b | 2013-08-28 17:04:49 +0530 | [diff] [blame] | 384 | mCopyBitDraw = false; |
| 385 | if (useCopybitForRGB && |
| 386 | (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) { |
| 387 | mCopyBitDraw = true; |
| 388 | // numAppLayers-1, as we iterate till 0th layer index |
| 389 | // Mark all layers to be drawn by copybit |
| 390 | for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 391 | layerProp[i].mFlags |= HWC_COPYBIT; |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 392 | #ifdef QCOM_BSP |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 393 | if (ctx->mMDP.version == qdutils::MDP_V3_0_4 || |
| 394 | ctx->mMDP.version == qdutils::MDP_V3_0_5) |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 395 | list->hwLayers[i].compositionType = HWC_BLIT; |
| 396 | else |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 397 | #endif |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 398 | list->hwLayers[i].compositionType = HWC_OVERLAY; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
Radhika Ranjan Soni | 14f6c4b | 2013-08-28 17:04:49 +0530 | [diff] [blame] | 401 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 405 | int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect) |
| 406 | { |
| 407 | int ret = 0; |
| 408 | copybit_rect_t clear_rect = {rect.left, rect.top, |
| 409 | rect.right, |
| 410 | rect.bottom}; |
| 411 | |
| 412 | copybit_image_t buf; |
Ramkumar Radhakrishnan | 92f3abe | 2013-06-05 13:52:40 -0700 | [diff] [blame] | 413 | buf.w = ALIGN(getWidth(hnd),32); |
| 414 | buf.h = getHeight(hnd); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 415 | buf.format = hnd->format; |
| 416 | buf.base = (void *)hnd->base; |
| 417 | buf.handle = (native_handle_t *)hnd; |
| 418 | |
| 419 | copybit_device_t *copybit = mEngine; |
| 420 | ret = copybit->clear(copybit, &buf, &clear_rect); |
| 421 | return ret; |
| 422 | } |
| 423 | |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 424 | bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx, |
| 425 | hwc_display_contents_1_t *list, |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 426 | int dpy, int *copybitFd) { |
| 427 | int layerCount = 0; |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 428 | uint32_t last = (uint32_t)list->numHwLayers - 1; |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 429 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 430 | private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle; |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 431 | |
| 432 | if(ctx->enableABC == false) |
| 433 | return false; |
| 434 | |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 435 | if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC ) |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 436 | return false; |
| 437 | |
| 438 | layerCount = ctx->listStats[dpy].numAppLayers; |
| 439 | //bottom most layer should |
| 440 | //equal to FB |
| 441 | hwc_layer_1_t *tmpLayer = &list->hwLayers[0]; |
| 442 | private_handle_t *hnd = (private_handle_t *)tmpLayer->handle; |
| 443 | if(hnd && fbhnd && (hnd->size == fbhnd->size) && |
| 444 | (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){ |
| 445 | if(tmpLayer->transform || |
| 446 | (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 || |
| 447 | hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) || |
| 448 | (needsScaling(tmpLayer) == true)) { |
| 449 | return false; |
| 450 | }else { |
| 451 | ctx->listStats[dpy].renderBufIndexforABC = 0; |
| 452 | } |
| 453 | } |
| 454 | |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 455 | if(ctx->listStats[dpy].renderBufIndexforABC == 0) { |
| 456 | if(layerCount == 1) |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 457 | return true; |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 458 | |
Ramakant Singh | cc32661 | 2014-06-19 14:19:18 +0530 | [diff] [blame] | 459 | if(layerCount == MAX_LAYERS_FOR_ABC) { |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 460 | int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC; |
Ramakant Singh | cc32661 | 2014-06-19 14:19:18 +0530 | [diff] [blame] | 461 | //enable ABC only for non intersecting layers. |
| 462 | hwc_rect_t displayFrame = |
| 463 | list->hwLayers[abcRenderBufIdx].displayFrame; |
| 464 | for (int i = abcRenderBufIdx + 1; i < layerCount; i++) { |
| 465 | hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame; |
| 466 | hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame); |
| 467 | if (isValidRect(result)) { |
| 468 | ctx->listStats[dpy].renderBufIndexforABC = -1; |
| 469 | return false; |
| 470 | } |
| 471 | } |
| 472 | // Pass the Acquire Fence FD to driver for base layer |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 473 | private_handle_t *renderBuffer = |
| 474 | (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle; |
| 475 | copybit_device_t *copybit = getCopyBitDevice(); |
| 476 | if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){ |
| 477 | copybit->set_sync(copybit, |
| 478 | list->hwLayers[abcRenderBufIdx].acquireFenceFd); |
| 479 | } |
Ramakant Singh | cc32661 | 2014-06-19 14:19:18 +0530 | [diff] [blame] | 480 | for(int i = abcRenderBufIdx + 1; i < layerCount; i++){ |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 481 | mDirtyLayerIndex = -1; |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 482 | int retVal = drawLayerUsingCopybit(ctx, |
| 483 | &(list->hwLayers[i]),renderBuffer, 0); |
| 484 | if(retVal < 0) { |
| 485 | ALOGE("%s : Copybit failed", __FUNCTION__); |
| 486 | } |
| 487 | } |
| 488 | // Get Release Fence FD of copybit for the App layer(s) |
| 489 | copybit->flush_get_fence(copybit, copybitFd); |
Ramakant Singh | 52e1c0c | 2014-12-18 23:35:33 +0530 | [diff] [blame] | 490 | close(list->hwLayers[last].acquireFenceFd); |
| 491 | list->hwLayers[last].acquireFenceFd = -1; |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 492 | return true; |
| 493 | } |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 494 | } |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 499 | int dpy, int32_t *fd) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 500 | // draw layers marked for COPYBIT |
| 501 | int retVal = true; |
| 502 | int copybitLayerCount = 0; |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 503 | uint32_t last = 0; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 504 | LayerProp *layerProp = ctx->layerProp[dpy]; |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 505 | private_handle_t *renderBuffer; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 506 | |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 507 | if(mCopyBitDraw == false){ |
| 508 | mFbCache.reset(); // there is no layer marked for copybit |
| 509 | return false ; |
| 510 | } |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 511 | |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 512 | if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) { |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 513 | return true; |
| 514 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 515 | //render buffer |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 516 | if (ctx->mMDP.version == qdutils::MDP_V3_0_4 || |
| 517 | ctx->mMDP.version == qdutils::MDP_V3_0_5) { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 518 | last = (uint32_t)list->numHwLayers - 1; |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 519 | renderBuffer = (private_handle_t *)list->hwLayers[last].handle; |
| 520 | } else { |
| 521 | renderBuffer = getCurrentRenderBuffer(); |
| 522 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 523 | if (!renderBuffer) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 524 | ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 525 | return false; |
| 526 | } |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 527 | |
Terence Hampson | 0124cc7 | 2013-04-18 23:45:56 -0700 | [diff] [blame] | 528 | if (ctx->mMDP.version >= qdutils::MDP_V4_0) { |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 529 | //Wait for the previous frame to complete before rendering onto it |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 530 | if(mRelFd[mCurRenderBufferIndex] >=0) { |
| 531 | sync_wait(mRelFd[mCurRenderBufferIndex], 1000); |
| 532 | close(mRelFd[mCurRenderBufferIndex]); |
| 533 | mRelFd[mCurRenderBufferIndex] = -1; |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 534 | } |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 535 | } else { |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 536 | if(list->hwLayers[last].acquireFenceFd >=0) { |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 537 | copybit_device_t *copybit = getCopyBitDevice(); |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 538 | copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd); |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 539 | } |
Terence Hampson | 0124cc7 | 2013-04-18 23:45:56 -0700 | [diff] [blame] | 540 | } |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 541 | |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 542 | mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy); |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 543 | ALOGD_IF (DEBUG_COPYBIT, "%s:Dirty Layer Index: %d", |
| 544 | __FUNCTION__, mDirtyLayerIndex); |
Ramakant Singh | 75b427c | 2014-12-08 17:09:31 +0530 | [diff] [blame] | 545 | hwc_rect_t clearRegion = {0,0,0,0}; |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 546 | mDirtyRect = list->hwLayers[last].displayFrame; |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 547 | |
Dileep Kumar Reddi | f4e2e0c | 2014-12-16 11:24:34 +0530 | [diff] [blame] | 548 | if (CBUtils::getuiClearRegion(list, clearRegion, layerProp, |
Ramakant Singh | 909bc2a | 2015-02-10 16:29:21 +0530 | [diff] [blame] | 549 | mDirtyLayerIndex)) { |
| 550 | int clear_w = clearRegion.right - clearRegion.left; |
| 551 | int clear_h = clearRegion.bottom - clearRegion.top; |
| 552 | //mdp can't handle solid fill for one line |
| 553 | //making solid fill as full in this case |
| 554 | //disable swap rect if presents |
| 555 | if ((clear_w == 1) || (clear_h ==1)) { |
| 556 | clear(renderBuffer, mDirtyRect); |
| 557 | mDirtyLayerIndex = -1; |
| 558 | }else |
| 559 | clear(renderBuffer, clearRegion); |
| 560 | } |
| 561 | if (mDirtyLayerIndex != -1) |
| 562 | mDirtyRect = list->hwLayers[mDirtyLayerIndex].displayFrame; |
| 563 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 564 | // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 565 | for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 566 | if(!(layerProp[i].mFlags & HWC_COPYBIT)) { |
| 567 | ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 568 | continue; |
| 569 | } |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame] | 570 | if(ctx->copybitDrop[i]) { |
| 571 | continue; |
| 572 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 573 | int ret = -1; |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 574 | if (list->hwLayers[i].acquireFenceFd != -1 |
| 575 | && ctx->mMDP.version >= qdutils::MDP_V4_0) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 576 | // Wait for acquire Fence on the App buffers. |
| 577 | ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000); |
| 578 | if(ret < 0) { |
| 579 | ALOGE("%s: sync_wait error!! error no = %d err str = %s", |
| 580 | __FUNCTION__, errno, strerror(errno)); |
| 581 | } |
| 582 | close(list->hwLayers[i].acquireFenceFd); |
| 583 | list->hwLayers[i].acquireFenceFd = -1; |
| 584 | } |
| 585 | retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]), |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 586 | renderBuffer, !i); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 587 | copybitLayerCount++; |
| 588 | if(retVal < 0) { |
| 589 | ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | if (copybitLayerCount) { |
| 594 | copybit_device_t *copybit = getCopyBitDevice(); |
| 595 | // Async mode |
| 596 | copybit->flush_get_fence(copybit, fd); |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 597 | if((ctx->mMDP.version == qdutils::MDP_V3_0_4 || |
| 598 | ctx->mMDP.version == qdutils::MDP_V3_0_5) && |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 599 | list->hwLayers[last].acquireFenceFd >= 0) { |
| 600 | close(list->hwLayers[last].acquireFenceFd); |
| 601 | list->hwLayers[last].acquireFenceFd = -1; |
Terence Hampson | 65fe452 | 2013-10-17 17:40:03 -0400 | [diff] [blame] | 602 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 603 | } |
| 604 | return true; |
| 605 | } |
| 606 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 607 | int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) { |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 608 | int fd = -1; |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 609 | PtorInfo* ptorInfo = &(ctx->mPtorInfo); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 610 | |
| 611 | if (ctx->mMDP.version < qdutils::MDP_V4_0) { |
| 612 | ALOGE("%s: Invalid request", __FUNCTION__); |
| 613 | return fd; |
| 614 | } |
| 615 | |
| 616 | private_handle_t *renderBuffer = getCurrentRenderBuffer(); |
| 617 | |
| 618 | if (!renderBuffer) { |
| 619 | ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__); |
| 620 | return fd; |
| 621 | } |
| 622 | |
Dileep Kumar Reddi | d1f08e4 | 2014-11-05 21:24:27 +0530 | [diff] [blame] | 623 | //Clear the transparent or left out region on the render buffer |
| 624 | hwc_rect_t clearRegion = {0,0,0,0}; |
| 625 | LayerProp *layerProp = ctx->layerProp[0]; |
| 626 | if(CBUtils::getuiClearRegion(list, clearRegion, layerProp)) |
| 627 | clear(renderBuffer, clearRegion); |
| 628 | |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 629 | int copybitLayerCount = 0; |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 630 | for(int j = 0; j < ptorInfo->count; j++) { |
| 631 | int ovlapIndex = ptorInfo->layerIndex[j]; |
| 632 | hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame; |
Prabhanjan Kandula | 9889a20 | 2014-09-04 21:50:35 +0530 | [diff] [blame] | 633 | if(j) { |
| 634 | /** |
| 635 | * It's possible that 2 PTOR layers might have overlapping. |
| 636 | * In such case, remove the intersection(again if peripheral) |
| 637 | * from the lower PTOR layer to avoid overlapping. |
| 638 | * If intersection is not on peripheral then compromise |
| 639 | * by reducing number of PTOR layers. |
| 640 | **/ |
| 641 | int prevOvlapIndex = ptorInfo->layerIndex[0]; |
| 642 | hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame; |
| 643 | hwc_rect_t commonRect = getIntersection(prevOvlap, overlap); |
| 644 | if(isValidRect(commonRect)) { |
| 645 | overlap = deductRect(overlap, commonRect); |
| 646 | } |
| 647 | } |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 648 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 649 | // Draw overlapped content of layers on render buffer |
| 650 | for (int i = 0; i <= ovlapIndex; i++) { |
| 651 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
| 652 | if(!isValidRect(getIntersection(layer->displayFrame, |
| 653 | overlap))) { |
| 654 | continue; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 655 | } |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 656 | if ((list->hwLayers[i].acquireFenceFd != -1)) { |
| 657 | // Wait for acquire fence on the App buffers. |
| 658 | if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) { |
| 659 | ALOGE("%s: sync_wait error!! error no = %d err str = %s", |
| 660 | __FUNCTION__, errno, strerror(errno)); |
| 661 | } |
| 662 | close(list->hwLayers[i].acquireFenceFd); |
| 663 | list->hwLayers[i].acquireFenceFd = -1; |
| 664 | } |
Dileep Kumar Reddi | 408fde5 | 2014-11-04 22:53:15 +0530 | [diff] [blame] | 665 | /* |
| 666 | * Find the intersection of layer display frame with PTOR layer |
| 667 | * with respect to screen co-ordinates |
| 668 | * |
| 669 | * Calculated the destination rect by transforming the overlapping |
| 670 | * region of layer display frame with respect to PTOR display frame |
| 671 | * |
| 672 | * Transform the destination rect on to render buffer |
| 673 | * */ |
| 674 | hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame); |
| 675 | destRect.left = destRect.left - overlap.left + |
| 676 | ptorInfo->displayFrame[j].left; |
| 677 | destRect.right = destRect.right- overlap.left + |
| 678 | ptorInfo->displayFrame[j].left; |
| 679 | destRect.top = destRect.top - overlap.top + |
| 680 | ptorInfo->displayFrame[j].top; |
| 681 | destRect.bottom = destRect.bottom - overlap.top + |
| 682 | ptorInfo->displayFrame[j].top; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 683 | |
Dileep Kumar Reddi | 408fde5 | 2014-11-04 22:53:15 +0530 | [diff] [blame] | 684 | int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer, |
| 685 | overlap, destRect); |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 686 | copybitLayerCount++; |
| 687 | if(retVal < 0) { |
| 688 | ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__); |
| 689 | copybitLayerCount = 0; |
| 690 | } |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | if (copybitLayerCount) { |
| 695 | copybit_device_t *copybit = getCopyBitDevice(); |
| 696 | copybit->flush_get_fence(copybit, &fd); |
| 697 | } |
| 698 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 699 | ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__, |
| 700 | copybitLayerCount); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 701 | return fd; |
| 702 | } |
| 703 | |
| 704 | int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 705 | private_handle_t *renderBuffer, hwc_rect_t overlap, |
| 706 | hwc_rect_t destRect) |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 707 | { |
| 708 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 709 | if (!ctx) { |
| 710 | ALOGE("%s: null context ", __FUNCTION__); |
| 711 | return -1; |
| 712 | } |
| 713 | |
| 714 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 715 | if (!hnd) { |
| 716 | ALOGE("%s: invalid handle", __FUNCTION__); |
| 717 | return -1; |
| 718 | } |
| 719 | |
| 720 | private_handle_t *dstHandle = (private_handle_t *)renderBuffer; |
| 721 | if (!dstHandle) { |
| 722 | ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__); |
| 723 | return -1; |
| 724 | } |
| 725 | |
| 726 | // Set the Copybit Source |
| 727 | copybit_image_t src; |
| 728 | src.handle = (native_handle_t *)layer->handle; |
| 729 | src.w = hnd->width; |
| 730 | src.h = hnd->height; |
| 731 | src.base = (void *)hnd->base; |
| 732 | src.format = hnd->format; |
| 733 | src.horiz_padding = 0; |
| 734 | src.vert_padding = 0; |
| 735 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 736 | |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 737 | hwc_rect_t dispFrame = layer->displayFrame; |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 738 | hwc_rect_t iRect = getIntersection(dispFrame, overlap); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 739 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 740 | qhwc::calculate_crop_rects(crop, dispFrame, iRect, |
| 741 | layer->transform); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 742 | |
| 743 | // Copybit source rect |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 744 | copybit_rect_t srcRect = {crop.left, crop.top, crop.right, |
| 745 | crop.bottom}; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 746 | |
| 747 | // Copybit destination rect |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 748 | copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right, |
| 749 | destRect.bottom}; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 750 | |
| 751 | // Copybit dst |
| 752 | copybit_image_t dst; |
| 753 | dst.handle = (native_handle_t *)dstHandle; |
| 754 | dst.w = ALIGN(dstHandle->width, 32); |
| 755 | dst.h = dstHandle->height; |
| 756 | dst.base = (void *)dstHandle->base; |
| 757 | dst.format = dstHandle->format; |
| 758 | |
| 759 | copybit_device_t *copybit = mEngine; |
| 760 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 761 | // Copybit region is the destRect |
| 762 | hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b}; |
| 763 | hwc_region_t region; |
| 764 | region.numRects = 1; |
| 765 | region.rects = ®Rect; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 766 | region_iterator copybitRegion(region); |
| 767 | int acquireFd = layer->acquireFenceFd; |
| 768 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 769 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH, |
| 770 | renderBuffer->width); |
| 771 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT, |
| 772 | renderBuffer->height); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 773 | copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform); |
| 774 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha); |
| 775 | copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending); |
| 776 | copybit->set_parameter(copybit, COPYBIT_DITHER, |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 777 | (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE : |
| 778 | COPYBIT_DISABLE); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 779 | copybit->set_sync(copybit, acquireFd); |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 780 | int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect, |
| 781 | ©bitRegion); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 782 | |
| 783 | if (err < 0) |
| 784 | ALOGE("%s: copybit stretch failed",__FUNCTION__); |
| 785 | |
| 786 | return err; |
| 787 | } |
| 788 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 789 | int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 790 | private_handle_t *renderBuffer, bool isFG) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 791 | { |
| 792 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 793 | int err = 0, acquireFd; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 794 | if(!ctx) { |
| 795 | ALOGE("%s: null context ", __FUNCTION__); |
| 796 | return -1; |
| 797 | } |
| 798 | |
| 799 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 800 | if(!hnd) { |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 801 | if (layer->flags & HWC_COLOR_FILL) { // Color layer |
| 802 | return fillColorUsingCopybit(layer, renderBuffer); |
| 803 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 804 | ALOGE("%s: invalid handle", __FUNCTION__); |
| 805 | return -1; |
| 806 | } |
| 807 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 808 | private_handle_t *fbHandle = (private_handle_t *)renderBuffer; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 809 | if(!fbHandle) { |
| 810 | ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 811 | return -1; |
| 812 | } |
| 813 | |
| 814 | // Set the copybit source: |
| 815 | copybit_image_t src; |
Ramkumar Radhakrishnan | 92f3abe | 2013-06-05 13:52:40 -0700 | [diff] [blame] | 816 | src.w = getWidth(hnd); |
| 817 | src.h = getHeight(hnd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 818 | src.format = hnd->format; |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 819 | |
| 820 | // Handle R/B swap |
| 821 | if ((layer->flags & HWC_FORMAT_RB_SWAP)) { |
| 822 | if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) { |
| 823 | src.format = HAL_PIXEL_FORMAT_BGRA_8888; |
| 824 | } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) { |
| 825 | src.format = HAL_PIXEL_FORMAT_BGRX_8888; |
| 826 | } |
| 827 | } |
| 828 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 829 | src.base = (void *)hnd->base; |
| 830 | src.handle = (native_handle_t *)layer->handle; |
Ramkumar Radhakrishnan | 92f3abe | 2013-06-05 13:52:40 -0700 | [diff] [blame] | 831 | src.horiz_padding = src.w - getWidth(hnd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 832 | // Initialize vertical padding to zero for now, |
| 833 | // this needs to change to accomodate vertical stride |
| 834 | // if needed in the future |
| 835 | src.vert_padding = 0; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 836 | |
shuoy | 7c101f9 | 2013-08-26 14:48:57 +0800 | [diff] [blame] | 837 | int layerTransform = layer->transform ; |
| 838 | // When flip and rotation(90) are present alter the flip, |
| 839 | // as GPU is doing the flip and rotation in opposite order |
| 840 | // to that of MDP3.0 |
| 841 | // For 270 degrees, we get 90 + (H+V) which is same as doing |
| 842 | // flip first and then rotation (H+V) + 90 |
| 843 | if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) { |
| 844 | if (((layer->transform& HAL_TRANSFORM_FLIP_H) || |
| 845 | (layer->transform & HAL_TRANSFORM_FLIP_V)) && |
| 846 | (layer->transform & HAL_TRANSFORM_ROT_90) && |
| 847 | !(layer->transform == HAL_TRANSFORM_ROT_270)){ |
| 848 | if(layer->transform & HAL_TRANSFORM_FLIP_H){ |
| 849 | layerTransform ^= HAL_TRANSFORM_FLIP_H; |
| 850 | layerTransform |= HAL_TRANSFORM_FLIP_V; |
| 851 | } |
| 852 | if(layer->transform & HAL_TRANSFORM_FLIP_V){ |
| 853 | layerTransform ^= HAL_TRANSFORM_FLIP_V; |
| 854 | layerTransform |= HAL_TRANSFORM_FLIP_H; |
| 855 | } |
| 856 | } |
| 857 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 858 | // Copybit source rect |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 859 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 860 | copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top, |
| 861 | sourceCrop.right, |
| 862 | sourceCrop.bottom}; |
| 863 | |
| 864 | // Copybit destination rect |
| 865 | hwc_rect_t displayFrame = layer->displayFrame; |
| 866 | copybit_rect_t dstRect = {displayFrame.left, displayFrame.top, |
| 867 | displayFrame.right, |
| 868 | displayFrame.bottom}; |
Saurabh Shah | 93c6905 | 2014-04-24 10:27:10 -0700 | [diff] [blame] | 869 | #ifdef QCOM_BSP |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 870 | //change src and dst with dirtyRect |
| 871 | if(mDirtyLayerIndex != -1) { |
Dileep Kumar Reddi | f7b7205 | 2014-12-16 11:25:11 +0530 | [diff] [blame] | 872 | hwc_rect_t result = getIntersection(displayFrame, mDirtyRect); |
| 873 | if(!isValidRect(result)) |
| 874 | return true; |
| 875 | dstRect.l = result.left; |
| 876 | dstRect.t = result.top; |
| 877 | dstRect.r = result.right; |
| 878 | dstRect.b = result.bottom; |
| 879 | |
| 880 | srcRect.l += (result.left - displayFrame.left); |
| 881 | srcRect.t += (result.top - displayFrame.top); |
| 882 | srcRect.r -= (displayFrame.right - result.right); |
| 883 | srcRect.b -= (displayFrame.bottom - result.bottom); |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 884 | } |
Saurabh Shah | 93c6905 | 2014-04-24 10:27:10 -0700 | [diff] [blame] | 885 | #endif |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 886 | // Copybit dst |
| 887 | copybit_image_t dst; |
| 888 | dst.w = ALIGN(fbHandle->width,32); |
| 889 | dst.h = fbHandle->height; |
| 890 | dst.format = fbHandle->format; |
| 891 | dst.base = (void *)fbHandle->base; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 892 | dst.handle = (native_handle_t *)fbHandle; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 893 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 894 | copybit_device_t *copybit = mEngine; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 895 | |
| 896 | int32_t screen_w = displayFrame.right - displayFrame.left; |
| 897 | int32_t screen_h = displayFrame.bottom - displayFrame.top; |
| 898 | int32_t src_crop_width = sourceCrop.right - sourceCrop.left; |
| 899 | int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top; |
| 900 | |
| 901 | // Copybit dst |
| 902 | float copybitsMaxScale = |
| 903 | (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT); |
| 904 | float copybitsMinScale = |
| 905 | (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT); |
| 906 | |
Sushil Chauhan | dffbf43 | 2013-12-09 15:33:57 -0800 | [diff] [blame] | 907 | if (layer->transform & HWC_TRANSFORM_ROT_90) { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 908 | //swap screen width and height |
| 909 | int tmp = screen_w; |
| 910 | screen_w = screen_h; |
| 911 | screen_h = tmp; |
| 912 | } |
| 913 | private_handle_t *tmpHnd = NULL; |
| 914 | |
| 915 | if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) { |
| 916 | ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \ |
Ramakant Singh | 0b35f2c | 2014-01-07 11:25:48 +0530 | [diff] [blame] | 917 | screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w, |
| 918 | src_crop_width,screen_h,src_crop_height); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 919 | return -1; |
| 920 | } |
| 921 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 922 | float dsdx = (float)screen_w/(float)src_crop_width; |
| 923 | float dtdy = (float)screen_h/(float)src_crop_height; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 924 | |
| 925 | float scaleLimitMax = copybitsMaxScale * copybitsMaxScale; |
| 926 | float scaleLimitMin = copybitsMinScale * copybitsMinScale; |
| 927 | if(dsdx > scaleLimitMax || |
| 928 | dtdy > scaleLimitMax || |
| 929 | dsdx < 1/scaleLimitMin || |
| 930 | dtdy < 1/scaleLimitMin) { |
Terence Hampson | 3c560b9 | 2013-09-03 16:58:02 -0400 | [diff] [blame] | 931 | ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \ |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 932 | scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy, |
| 933 | scaleLimitMax,1/scaleLimitMin); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 934 | return -1; |
| 935 | } |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 936 | acquireFd = layer->acquireFenceFd; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 937 | if(dsdx > copybitsMaxScale || |
| 938 | dtdy > copybitsMaxScale || |
| 939 | dsdx < 1/copybitsMinScale || |
| 940 | dtdy < 1/copybitsMinScale){ |
| 941 | // The requested scale is out of the range the hardware |
| 942 | // can support. |
Terence Hampson | 663dfa7 | 2013-08-08 12:35:41 -0400 | [diff] [blame] | 943 | ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\ |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 944 | copybitsMinScale=%f,screen_w=%d,screen_h=%d \ |
| 945 | src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__, |
| 946 | dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h, |
| 947 | src_crop_width,src_crop_height); |
| 948 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 949 | |
| 950 | int tmp_w = src_crop_width; |
| 951 | int tmp_h = src_crop_height; |
| 952 | |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 953 | if (dsdx > copybitsMaxScale) |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 954 | tmp_w = (int)((float)src_crop_width*copybitsMaxScale); |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 955 | if (dtdy > copybitsMaxScale) |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 956 | tmp_h = (int)((float)src_crop_height*copybitsMaxScale); |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 957 | // ceil the tmp_w and tmp_h value to maintain proper ratio |
| 958 | // b/w src and dst (should not cross the desired scale limit |
| 959 | // due to float -> int ) |
| 960 | if (dsdx < 1/copybitsMinScale) |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 961 | tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale); |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 962 | if (dtdy < 1/copybitsMinScale) |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 963 | tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale); |
Ramakant Singh | d2875e1 | 2015-01-19 12:45:41 +0530 | [diff] [blame] | 964 | |
Terence Hampson | 663dfa7 | 2013-08-08 12:35:41 -0400 | [diff] [blame] | 965 | ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 966 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 967 | int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP; |
Terence Hampson | b6a123a | 2013-07-18 11:54:16 -0400 | [diff] [blame] | 968 | int format = fbHandle->format; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 969 | |
Terence Hampson | b6a123a | 2013-07-18 11:54:16 -0400 | [diff] [blame] | 970 | // We do not want copybit to generate alpha values from nothing |
| 971 | if (format == HAL_PIXEL_FORMAT_RGBA_8888 && |
| 972 | src.format != HAL_PIXEL_FORMAT_RGBA_8888) { |
| 973 | format = HAL_PIXEL_FORMAT_RGBX_8888; |
| 974 | } |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 975 | if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 976 | copybit_image_t tmp_dst; |
| 977 | copybit_rect_t tmp_rect; |
| 978 | tmp_dst.w = tmp_w; |
| 979 | tmp_dst.h = tmp_h; |
| 980 | tmp_dst.format = tmpHnd->format; |
| 981 | tmp_dst.handle = tmpHnd; |
| 982 | tmp_dst.horiz_padding = src.horiz_padding; |
| 983 | tmp_dst.vert_padding = src.vert_padding; |
| 984 | tmp_rect.l = 0; |
| 985 | tmp_rect.t = 0; |
| 986 | tmp_rect.r = tmp_dst.w; |
| 987 | tmp_rect.b = tmp_dst.h; |
| 988 | //create one clip region |
| 989 | hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b}; |
| 990 | hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect}; |
| 991 | region_iterator tmp_it(tmp_hwc_reg); |
| 992 | copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 993 | //TODO: once, we are able to read layer alpha, update this |
| 994 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255); |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 995 | copybit->set_sync(copybit, acquireFd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 996 | err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect, |
| 997 | &srcRect, &tmp_it); |
| 998 | if(err < 0){ |
| 999 | ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__, |
| 1000 | __LINE__); |
| 1001 | if(tmpHnd) |
| 1002 | free_buffer(tmpHnd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1003 | return err; |
| 1004 | } |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1005 | // use release fence as aquire fd for next stretch |
Terence Hampson | 1d8db6f | 2013-07-17 11:05:36 -0400 | [diff] [blame] | 1006 | if (ctx->mMDP.version < qdutils::MDP_V4_0) { |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1007 | copybit->flush_get_fence(copybit, &acquireFd); |
Terence Hampson | 1d8db6f | 2013-07-17 11:05:36 -0400 | [diff] [blame] | 1008 | close(acquireFd); |
| 1009 | acquireFd = -1; |
| 1010 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1011 | // copy new src and src rect crop |
| 1012 | src = tmp_dst; |
| 1013 | srcRect = tmp_rect; |
| 1014 | } |
| 1015 | } |
| 1016 | // Copybit region |
| 1017 | hwc_region_t region = layer->visibleRegionScreen; |
| 1018 | region_iterator copybitRegion(region); |
| 1019 | |
| 1020 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH, |
| 1021 | renderBuffer->width); |
| 1022 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT, |
| 1023 | renderBuffer->height); |
| 1024 | copybit->set_parameter(copybit, COPYBIT_TRANSFORM, |
shuoy | 7c101f9 | 2013-08-26 14:48:57 +0800 | [diff] [blame] | 1025 | layerTransform); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 1026 | //TODO: once, we are able to read layer alpha, update this |
| 1027 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1028 | copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, |
| 1029 | layer->blending); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1030 | copybit->set_parameter(copybit, COPYBIT_DITHER, |
| 1031 | (dst.format == HAL_PIXEL_FORMAT_RGB_565)? |
| 1032 | COPYBIT_ENABLE : COPYBIT_DISABLE); |
Shivaraj Shetty | e86506a | 2013-08-06 12:56:30 +0530 | [diff] [blame] | 1033 | copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ? |
| 1034 | COPYBIT_ENABLE : COPYBIT_DISABLE); |
| 1035 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1036 | copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER, |
| 1037 | COPYBIT_ENABLE); |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1038 | copybit->set_sync(copybit, acquireFd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1039 | err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect, |
| 1040 | ©bitRegion); |
| 1041 | copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER, |
| 1042 | COPYBIT_DISABLE); |
| 1043 | |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1044 | if(tmpHnd) { |
| 1045 | if (ctx->mMDP.version < qdutils::MDP_V4_0){ |
| 1046 | int ret = -1, releaseFd; |
| 1047 | // we need to wait for the buffer before freeing |
| 1048 | copybit->flush_get_fence(copybit, &releaseFd); |
| 1049 | ret = sync_wait(releaseFd, 1000); |
| 1050 | if(ret < 0) { |
| 1051 | ALOGE("%s: sync_wait error!! error no = %d err str = %s", |
| 1052 | __FUNCTION__, errno, strerror(errno)); |
| 1053 | } |
| 1054 | close(releaseFd); |
| 1055 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1056 | free_buffer(tmpHnd); |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1057 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1058 | |
| 1059 | if(err < 0) |
| 1060 | ALOGE("%s: copybit stretch failed",__FUNCTION__); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1061 | return err; |
| 1062 | } |
| 1063 | |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1064 | int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer, |
| 1065 | private_handle_t *renderBuffer) |
| 1066 | { |
| 1067 | if (!renderBuffer) { |
| 1068 | ALOGE("%s: Render Buffer is NULL", __FUNCTION__); |
| 1069 | return -1; |
| 1070 | } |
| 1071 | |
| 1072 | // Copybit dst |
| 1073 | copybit_image_t dst; |
| 1074 | dst.w = ALIGN(renderBuffer->width, 32); |
| 1075 | dst.h = renderBuffer->height; |
| 1076 | dst.format = renderBuffer->format; |
| 1077 | dst.base = (void *)renderBuffer->base; |
| 1078 | dst.handle = (native_handle_t *)renderBuffer; |
| 1079 | |
| 1080 | // Copybit dst rect |
| 1081 | hwc_rect_t displayFrame = layer->displayFrame; |
| 1082 | copybit_rect_t dstRect = {displayFrame.left, displayFrame.top, |
| 1083 | displayFrame.right, displayFrame.bottom}; |
| 1084 | |
| 1085 | uint32_t color = layer->transform; |
| 1086 | copybit_device_t *copybit = mEngine; |
| 1087 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH, |
| 1088 | renderBuffer->width); |
| 1089 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT, |
| 1090 | renderBuffer->height); |
| 1091 | copybit->set_parameter(copybit, COPYBIT_DITHER, |
| 1092 | (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? |
| 1093 | COPYBIT_ENABLE : COPYBIT_DISABLE); |
Sushil Chauhan | 2babecc | 2013-12-04 17:29:48 -0800 | [diff] [blame] | 1094 | copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0); |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1095 | copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending); |
| 1096 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha); |
| 1097 | copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE); |
| 1098 | int res = copybit->fill_color(copybit, &dst, &dstRect, color); |
| 1099 | copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE); |
| 1100 | return res; |
| 1101 | } |
| 1102 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 1103 | void CopyBit::getLayerResolution(const hwc_layer_1_t* layer, |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 1104 | unsigned int& width, unsigned int& height) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1105 | { |
| 1106 | hwc_rect_t displayFrame = layer->displayFrame; |
| 1107 | |
| 1108 | width = displayFrame.right - displayFrame.left; |
| 1109 | height = displayFrame.bottom - displayFrame.top; |
| 1110 | } |
| 1111 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1112 | bool CopyBit::validateParams(hwc_context_t *ctx, |
| 1113 | const hwc_display_contents_1_t *list) { |
| 1114 | //Validate parameters |
| 1115 | if (!ctx) { |
| 1116 | ALOGE("%s:Invalid HWC context", __FUNCTION__); |
| 1117 | return false; |
| 1118 | } else if (!list) { |
| 1119 | ALOGE("%s:Invalid HWC layer list", __FUNCTION__); |
| 1120 | return false; |
| 1121 | } |
| 1122 | return true; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1123 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1124 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1125 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1126 | int CopyBit::allocRenderBuffers(int w, int h, int f) |
| 1127 | { |
| 1128 | int ret = 0; |
| 1129 | for (int i = 0; i < NUM_RENDER_BUFFERS; i++) { |
| 1130 | if (mRenderBuffer[i] == NULL) { |
| 1131 | ret = alloc_buffer(&mRenderBuffer[i], |
| 1132 | w, h, f, |
| 1133 | GRALLOC_USAGE_PRIVATE_IOMMU_HEAP); |
| 1134 | } |
| 1135 | if(ret < 0) { |
| 1136 | freeRenderBuffers(); |
| 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | return ret; |
| 1141 | } |
| 1142 | |
| 1143 | void CopyBit::freeRenderBuffers() |
| 1144 | { |
| 1145 | for (int i = 0; i < NUM_RENDER_BUFFERS; i++) { |
| 1146 | if(mRenderBuffer[i]) { |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 1147 | //Since we are freeing buffer close the fence if it has a valid one. |
| 1148 | if(mRelFd[i] >= 0) { |
| 1149 | close(mRelFd[i]); |
| 1150 | mRelFd[i] = -1; |
| 1151 | } |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1152 | free_buffer(mRenderBuffer[i]); |
| 1153 | mRenderBuffer[i] = NULL; |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | private_handle_t * CopyBit::getCurrentRenderBuffer() { |
| 1159 | return mRenderBuffer[mCurRenderBufferIndex]; |
| 1160 | } |
| 1161 | |
| 1162 | void CopyBit::setReleaseFd(int fd) { |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 1163 | if(mRelFd[mCurRenderBufferIndex] >=0) |
| 1164 | close(mRelFd[mCurRenderBufferIndex]); |
| 1165 | mRelFd[mCurRenderBufferIndex] = dup(fd); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1166 | } |
| 1167 | |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 1168 | void CopyBit::setReleaseFdSync(int fd) { |
| 1169 | if (mRelFd[mCurRenderBufferIndex] >=0) { |
| 1170 | int ret = -1; |
| 1171 | ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000); |
| 1172 | if (ret < 0) |
| 1173 | ALOGE("%s: sync_wait error! errno = %d, err str = %s", |
| 1174 | __FUNCTION__, errno, strerror(errno)); |
| 1175 | close(mRelFd[mCurRenderBufferIndex]); |
| 1176 | } |
| 1177 | mRelFd[mCurRenderBufferIndex] = dup(fd); |
| 1178 | } |
| 1179 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1180 | struct copybit_device_t* CopyBit::getCopyBitDevice() { |
| 1181 | return mEngine; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 1184 | CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0), |
| 1185 | mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) { |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 1186 | |
| 1187 | getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres, |
| 1188 | ctx->dpyAttr[dpy].yres, |
| 1189 | HAL_PIXEL_FORMAT_RGBA_8888, |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 1190 | mAlignedWidth, |
| 1191 | mAlignedHeight); |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 1192 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1193 | hw_module_t const *module; |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 1194 | for (int i = 0; i < NUM_RENDER_BUFFERS; i++) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1195 | mRenderBuffer[i] = NULL; |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 1196 | mRelFd[i] = -1; |
| 1197 | } |
Prabhanjan Kandula | 73030ba | 2013-03-15 22:33:39 +0530 | [diff] [blame] | 1198 | |
| 1199 | char value[PROPERTY_VALUE_MAX]; |
| 1200 | property_get("debug.hwc.dynThreshold", value, "2"); |
| 1201 | mDynThreshold = atof(value); |
| 1202 | |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 1203 | property_get("debug.sf.swaprect", value, "0"); |
| 1204 | mSwapRectEnable = atoi(value) ? true:false ; |
| 1205 | mDirtyLayerIndex = -1; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1206 | if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1207 | if(copybit_open(module, &mEngine) < 0) { |
| 1208 | ALOGE("FATAL ERROR: copybit open failed."); |
| 1209 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1210 | } else { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1211 | ALOGE("FATAL ERROR: copybit hw module not found"); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1212 | } |
| 1213 | } |
Saurabh Shah | 661a58f | 2012-08-30 15:30:49 -0700 | [diff] [blame] | 1214 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1215 | CopyBit::~CopyBit() |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1216 | { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1217 | freeRenderBuffers(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1218 | if(mEngine) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1219 | { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1220 | copybit_close(mEngine); |
| 1221 | mEngine = NULL; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1222 | } |
| 1223 | } |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 1224 | CopyBit::LayerCache::LayerCache() { |
| 1225 | reset(); |
| 1226 | } |
| 1227 | void CopyBit::LayerCache::reset() { |
| 1228 | memset(&hnd, 0, sizeof(hnd)); |
| 1229 | layerCount = 0; |
| 1230 | } |
| 1231 | void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx, |
| 1232 | hwc_display_contents_1_t *list, int dpy) |
| 1233 | { |
| 1234 | layerCount = ctx->listStats[dpy].numAppLayers; |
| 1235 | for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){ |
| 1236 | hnd[i] = list->hwLayers[i].handle; |
Dileep Kumar Reddi | aa48888 | 2014-12-16 11:19:45 +0530 | [diff] [blame] | 1237 | displayFrame[i] = list->hwLayers[i].displayFrame; |
Dileep Kumar Reddi | 9dab73a | 2015-02-24 16:15:53 +0530 | [diff] [blame] | 1238 | drop[i] = ctx->copybitDrop[i]; |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | CopyBit::FbCache::FbCache() { |
| 1243 | reset(); |
| 1244 | } |
| 1245 | void CopyBit::FbCache::reset() { |
| 1246 | memset(&FbdirtyRect, 0, sizeof(FbdirtyRect)); |
| 1247 | FbIndex =0; |
| 1248 | } |
| 1249 | |
| 1250 | void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) { |
| 1251 | FbIndex = FbIndex % NUM_RENDER_BUFFERS; |
| 1252 | FbdirtyRect[FbIndex] = dirtyRect; |
| 1253 | FbIndex++; |
| 1254 | } |
| 1255 | |
| 1256 | int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){ |
| 1257 | int sameDirtyCount = 0; |
| 1258 | for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){ |
| 1259 | if( FbdirtyRect[i] == dirtyRect) |
| 1260 | sameDirtyCount++; |
| 1261 | } |
| 1262 | return sameDirtyCount; |
| 1263 | } |
| 1264 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1265 | }; //namespace qhwc |