blob: ee5b3b7a3aea91d1e528853ac43d5658f9479cea [file] [log] [blame]
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08003 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed31da0b12012-07-31 18:55:33 -07004 *
radhakrishna2f00c8f2013-10-21 16:49:21 +05305 * Not a Contribution.
Naseer Ahmed31da0b12012-07-31 18:55:33 -07006 *
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 Ahmed45a99602012-07-31 19:15:24 -070020#define DEBUG_COPYBIT 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#include <copybit.h>
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080022#include <utils/Timers.h>
Terence Hampson0124cc72013-04-18 23:45:56 -070023#include <mdp_version.h>
Naseer Ahmed45a99602012-07-31 19:15:24 -070024#include "hwc_copybit.h"
25#include "comptype.h"
Naseer Ahmed64b81212013-02-14 10:29:47 -050026#include "gr.h"
radhakrishna2f00c8f2013-10-21 16:49:21 +053027#include "cb_utils.h"
Ramakant Singh762ae082013-11-28 18:45:34 +053028#include "cb_swap_rect.h"
Ramakant Singh80f36f22014-02-25 14:11:35 +053029#include "math.h"
Saurabh Shah74eff4d2014-03-28 16:33:13 -070030#include "sync/sync.h"
31
radhakrishna2f00c8f2013-10-21 16:49:21 +053032using namespace qdutils;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070033namespace qhwc {
34
Naseer Ahmed31da0b12012-07-31 18:55:33 -070035struct range {
36 int current;
37 int end;
38};
39struct region_iterator : public copybit_region_t {
40
41 region_iterator(hwc_region_t region) {
42 mRegion = region;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +053043 r.end = (int)region.numRects;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070044 r.current = 0;
45 this->next = iterate;
46 }
47
48private:
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.R361da4f2012-11-28 10:42:59 -080072void CopyBit::reset() {
73 mIsModeOn = false;
74 mCopyBitDraw = false;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070075}
76
Naseer Ahmed45a99602012-07-31 19:15:24 -070077bool CopyBit::canUseCopybitForYUV(hwc_context_t *ctx) {
78 // return true for non-overlay targets
Terence Hampsond0fd5792013-05-29 11:56:52 -040079 if(ctx->mMDP.hasOverlay && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Naseer Ahmed45a99602012-07-31 19:15:24 -070080 return false;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070081 }
82 return true;
83}
Naseer Ahmed45a99602012-07-31 19:15:24 -070084
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080085bool 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 Ahmed45a99602012-07-31 19:15:24 -070090
Naseer Ahmed45a99602012-07-31 19:15:24 -070091 if (compositionType & qdutils::COMPOSITION_TYPE_DYN) {
92 // DYN Composition:
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +053093 // use copybit, if (TotalRGBRenderArea < threashold * FB Area)
Naseer Ahmed45a99602012-07-31 19:15:24 -070094 // this is done based on perf inputs in ICS
95 // TODO: Above condition needs to be re-evaluated in JB
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080096 int fbWidth = ctx->dpyAttr[dpy].xres;
97 int fbHeight = ctx->dpyAttr[dpy].yres;
98 unsigned int fbArea = (fbWidth * fbHeight);
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +053099 unsigned int renderArea = getRGBRenderingArea(ctx, list);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700100 ALOGD_IF (DEBUG_COPYBIT, "%s:renderArea %u, fbArea %u",
101 __FUNCTION__, renderArea, fbArea);
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530102 if (renderArea < (mDynThreshold * fbArea)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700103 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 Reddi4070e932014-09-30 09:00:57 +0530115unsigned int CopyBit::getRGBRenderingArea (const hwc_context_t *ctx,
116 const hwc_display_contents_1_t *list) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700117 //Calculates total rendering area for RGB layers
118 unsigned int renderArea = 0;
119 unsigned int w=0, h=0;
Terence Hampsonef379d42013-05-21 10:38:01 -0400120 // 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 Ahmed45a99602012-07-31 19:15:24 -0700123 private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
124 if (hnd) {
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530125 if (BUFFER_TYPE_UI == hnd->bufferType && !ctx->copybitDrop[i]) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700126 getLayerResolution(&list->hwLayers[i], w, h);
127 renderArea += (w*h);
128 }
129 }
130 }
131 return renderArea;
132}
133
Ramakant Singh21cec722014-03-07 19:11:45 +0530134int CopyBit::getLayersChanging(hwc_context_t *ctx,
135 hwc_display_contents_1_t *list,
136 int dpy){
137
138 int changingLayerIndex = -1;
139 if(mLayerCache.layerCount != ctx->listStats[dpy].numAppLayers) {
140 mLayerCache.reset();
141 mFbCache.reset();
142 mLayerCache.updateCounts(ctx,list,dpy);
143 return -1;
144 }
145
146 int updatingLayerCount = 0;
147 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
148 //swap rect will kick in only for single updating layer
149 if(mLayerCache.hnd[k] != list->hwLayers[k].handle){
150 updatingLayerCount ++;
151 if(updatingLayerCount == 1)
152 changingLayerIndex = k;
153 }
154 }
155 //since we are using more than one framebuffers,we have to
156 //kick in swap rect only if we are getting continuous same
157 //dirty rect for same layer at least equal of number of
158 //framebuffers
159
160 if ( updatingLayerCount == 1 ) {
Saurabh Shah93c69052014-04-24 10:27:10 -0700161 hwc_rect_t dirtyRect = list->hwLayers[changingLayerIndex].displayFrame;
162#ifdef QCOM_BSP
163 dirtyRect = list->hwLayers[changingLayerIndex].dirtyRect;
164#endif
Ramakant Singh21cec722014-03-07 19:11:45 +0530165
166 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
167 //disable swap rect for overlapping visible layer(s)
168 hwc_rect_t displayFrame = list->hwLayers[k].displayFrame;
169 hwc_rect_t result = getIntersection(displayFrame,dirtyRect);
170 if((k != changingLayerIndex) && isValidRect(result)){
171 return -1;
172 }
173 }
174 mFbCache.insertAndUpdateFbCache(dirtyRect);
175 if(mFbCache.getUnchangedFbDRCount(dirtyRect) <
176 NUM_RENDER_BUFFERS)
177 changingLayerIndex = -1;
178 }else {
179 mFbCache.reset();
180 changingLayerIndex = -1;
181 }
182 mLayerCache.updateCounts(ctx,list,dpy);
183 return changingLayerIndex;
184}
185
186int CopyBit::checkDirtyRect(hwc_context_t *ctx,
187 hwc_display_contents_1_t *list,
188 int dpy) {
189
190 //dirty rect will enable only if
191 //1.Only single layer is updating.
192 //2.No overlapping
193 //3.No scaling
194 //4.No video layer
195 if(mSwapRectEnable == false)
196 return -1;
197 int changingLayerIndex = getLayersChanging(ctx, list, dpy);
198 //swap rect will kick in only for single updating layer
199 if(changingLayerIndex == -1){
200 return -1;
201 }
202 if(!needsScaling(&list->hwLayers[changingLayerIndex])){
203 private_handle_t *hnd =
204 (private_handle_t *)list->hwLayers[changingLayerIndex].handle;
205 if( hnd && !isYuvBuffer(hnd))
206 return changingLayerIndex;
207 }
208 return -1;
209}
210
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700211bool CopyBit::prepareOverlap(hwc_context_t *ctx,
212 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700213
214 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
215 ALOGE("%s: Invalid request", __FUNCTION__);
216 return false;
217 }
218
Saurabh Shah15455aa2015-01-28 13:54:48 -0800219 if (mEngine == NULL) {
220 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
221 return false;
222 }
223
224 if (!(validateParams(ctx, list))) {
225 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700226 return false;
227 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700228 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700229
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700230 // Allocate render buffers if they're not allocated
231 int alignW = 0, alignH = 0;
232 int finalW = 0, finalH = 0;
233 for (int i = 0; i < ptorInfo->count; i++) {
234 int ovlapIndex = ptorInfo->layerIndex[i];
235 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
236 // render buffer width will be the max of two layers
237 // Align Widht and height to 32, Mdp would be configured
238 // with Aligned overlap w/h
239 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
240 finalH += ALIGN((overlap.bottom - overlap.top), 32);
241 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700242 // Calculate the dest top, left will always be zero
243 ptorInfo->displayFrame[i].top = (finalH -
244 (ALIGN((overlap.bottom - overlap.top), 32)));
245 }
246 // calculate the right and bottom values
247 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
248 (overlap.right - overlap.left);
249 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
250 (overlap.bottom - overlap.top);
251 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700252
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700253 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700254 alignW, alignH);
255
256 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
257 // Overlap rect has changed, so free render buffers
258 freeRenderBuffers();
259 }
260
261 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
262
263 if (ret < 0) {
264 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
265 return false;
266 }
267
268 mAlignedWidth = alignW;
269 mAlignedHeight = alignH;
270 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
271 return true;
272}
273
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800274bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
275 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700276
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800277 if(mEngine == NULL) {
278 // No copybit device found - cannot use copybit
279 return false;
280 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530281
282 if(ctx->mThermalBurstMode) {
283 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
284 "Running in Thermal Burst mode",__FUNCTION__);
285 return false;
286 }
287
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800288 int compositionType = qdutils::QCCompositionType::
289 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700290
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800291 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
292 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700293 //GPU/CPU composition, don't change layer composition type
294 return true;
295 }
296
Naseer Ahmed45a99602012-07-31 19:15:24 -0700297 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800298 ALOGE("%s:Invalid Params", __FUNCTION__);
299 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700300 }
301
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800302 if(ctx->listStats[dpy].skipCount) {
303 //GPU will be anyways used
304 return false;
305 }
306
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700307 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700308 // Reached max layers supported by HWC.
309 return false;
310 }
311
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800312 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
313 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500314 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500315
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530316 // Following are MDP3 limitations for which we
317 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400318 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500319 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400320 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
321 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500322 int dst_h, dst_w, src_h, src_w;
323 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530324 if(ctx->copybitDrop[i]) {
325 continue;
326 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400327 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530328 if (layer->planeAlpha != 0xFF)
329 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530330 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500331
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700332 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530333 src_h = sourceCrop.right - sourceCrop.left;
334 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500335 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530336 src_h = sourceCrop.bottom - sourceCrop.top;
337 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500338 }
339 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
340 dst_w = layer->displayFrame.right - layer->displayFrame.left;
341
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530342 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
343 ALOGE("%s: wrong params for display screen_w=%d \
344 src_crop_width=%d screen_h=%d src_crop_height=%d",
345 __FUNCTION__, dst_w,src_w,dst_h,src_h);
346 return false;
347 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530348 dx = (float)dst_w/(float)src_w;
349 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530350
Terence Hampson6b0a4272013-11-06 16:04:51 -0500351 if (dx > MAX_SCALE_FACTOR || dx < MIN_SCALE_FACTOR)
352 return false;
353
354 if (dy > MAX_SCALE_FACTOR || dy < MIN_SCALE_FACTOR)
355 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400356 }
357 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500358
359 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530360 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
361 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400362 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700363 int ret = allocRenderBuffers(mAlignedWidth,
364 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700365 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500366 if (ret < 0) {
367 return false;
368 } else {
369 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
370 NUM_RENDER_BUFFERS;
371 }
372 }
373
Terence Hampsond0fd5792013-05-29 11:56:52 -0400374 // We cannot mix copybit layer with layers marked to be drawn on FB
375 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
376 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800377
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530378 mCopyBitDraw = false;
379 if (useCopybitForRGB &&
380 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
381 mCopyBitDraw = true;
382 // numAppLayers-1, as we iterate till 0th layer index
383 // Mark all layers to be drawn by copybit
384 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500385 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700386#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530387 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
388 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400389 list->hwLayers[i].compositionType = HWC_BLIT;
390 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700391#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400392 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700393 }
394 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530395
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700396 return true;
397}
398
Naseer Ahmed183939d2013-03-14 20:44:17 -0400399int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
400{
401 int ret = 0;
402 copybit_rect_t clear_rect = {rect.left, rect.top,
403 rect.right,
404 rect.bottom};
405
406 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700407 buf.w = ALIGN(getWidth(hnd),32);
408 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400409 buf.format = hnd->format;
410 buf.base = (void *)hnd->base;
411 buf.handle = (native_handle_t *)hnd;
412
413 copybit_device_t *copybit = mEngine;
414 ret = copybit->clear(copybit, &buf, &clear_rect);
415 return ret;
416}
417
Ramakant Singh0def28c2014-03-28 20:43:13 +0530418bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
419 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530420 int dpy, int *copybitFd) {
421 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700422 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530423 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
424 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530425
426 if(ctx->enableABC == false)
427 return false;
428
Ramakant Singh467759f2014-04-16 11:09:40 +0530429 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530430 return false;
431
432 layerCount = ctx->listStats[dpy].numAppLayers;
433 //bottom most layer should
434 //equal to FB
435 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
436 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
437 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
438 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
439 if(tmpLayer->transform ||
440 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
441 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
442 (needsScaling(tmpLayer) == true)) {
443 return false;
444 }else {
445 ctx->listStats[dpy].renderBufIndexforABC = 0;
446 }
447 }
448
Ramakant Singh467759f2014-04-16 11:09:40 +0530449 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
450 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530451 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530452
Ramakant Singhcc326612014-06-19 14:19:18 +0530453 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530454 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530455 //enable ABC only for non intersecting layers.
456 hwc_rect_t displayFrame =
457 list->hwLayers[abcRenderBufIdx].displayFrame;
458 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
459 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
460 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
461 if (isValidRect(result)) {
462 ctx->listStats[dpy].renderBufIndexforABC = -1;
463 return false;
464 }
465 }
466 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530467 private_handle_t *renderBuffer =
468 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
469 copybit_device_t *copybit = getCopyBitDevice();
470 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
471 copybit->set_sync(copybit,
472 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
473 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530474 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Ramakant Singh467759f2014-04-16 11:09:40 +0530475 int retVal = drawLayerUsingCopybit(ctx,
476 &(list->hwLayers[i]),renderBuffer, 0);
477 if(retVal < 0) {
478 ALOGE("%s : Copybit failed", __FUNCTION__);
479 }
480 }
481 // Get Release Fence FD of copybit for the App layer(s)
482 copybit->flush_get_fence(copybit, copybitFd);
483 close(list->hwLayers[abcRenderBufIdx].acquireFenceFd);
484 list->hwLayers[abcRenderBufIdx].acquireFenceFd = -1;
485 return true;
486 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530487 }
488 return false;
489}
490
491bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
492 int dpy, int32_t *fd) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800493 // draw layers marked for COPYBIT
494 int retVal = true;
495 int copybitLayerCount = 0;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400496 uint32_t last = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500497 LayerProp *layerProp = ctx->layerProp[dpy];
Terence Hampsonc67b0372013-10-09 11:32:21 -0400498 private_handle_t *renderBuffer;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800499
Ramakant Singh21cec722014-03-07 19:11:45 +0530500 if(mCopyBitDraw == false){
501 mFbCache.reset(); // there is no layer marked for copybit
502 return false ;
503 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530504
Ramakant Singh467759f2014-04-16 11:09:40 +0530505 if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) {
Ramakant Singh0def28c2014-03-28 20:43:13 +0530506 return true;
507 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800508 //render buffer
Ramakant Singhb4106a12014-10-07 18:06:56 +0530509 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
510 ctx->mMDP.version == qdutils::MDP_V3_0_5) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530511 last = (uint32_t)list->numHwLayers - 1;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400512 renderBuffer = (private_handle_t *)list->hwLayers[last].handle;
513 } else {
514 renderBuffer = getCurrentRenderBuffer();
515 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800516 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500517 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800518 return false;
519 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500520
Terence Hampson0124cc72013-04-18 23:45:56 -0700521 if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400522 //Wait for the previous frame to complete before rendering onto it
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530523 if(mRelFd[mCurRenderBufferIndex] >=0) {
524 sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
525 close(mRelFd[mCurRenderBufferIndex]);
526 mRelFd[mCurRenderBufferIndex] = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400527 }
Terence Hampson65fe4522013-10-17 17:40:03 -0400528 } else {
Terence Hampsonc67b0372013-10-09 11:32:21 -0400529 if(list->hwLayers[last].acquireFenceFd >=0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400530 copybit_device_t *copybit = getCopyBitDevice();
Terence Hampsonc67b0372013-10-09 11:32:21 -0400531 copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd);
Terence Hampson65fe4522013-10-17 17:40:03 -0400532 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700533 }
radhakrishna2f00c8f2013-10-21 16:49:21 +0530534
Ramakant Singh21cec722014-03-07 19:11:45 +0530535 mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530536 hwc_rect_t clearRegion = {0,0,0,0};
537 if (CBUtils::getuiClearRegion(list, clearRegion, layerProp)){
538 if (mDirtyLayerIndex != -1){
539 hwc_layer_1_t *layer = &list->hwLayers[mDirtyLayerIndex];
Saurabh Shah93c69052014-04-24 10:27:10 -0700540#ifdef QCOM_BSP
Ramakant Singh75b427c2014-12-08 17:09:31 +0530541 hwc_rect_t result = getIntersection(layer->dirtyRect,clearRegion);
542 if(isValidRect(result))
543 clear(renderBuffer,result);
Saurabh Shah93c69052014-04-24 10:27:10 -0700544#else
Ramakant Singh75b427c2014-12-08 17:09:31 +0530545 clear(renderBuffer,clearRegion);
Saurabh Shah93c69052014-04-24 10:27:10 -0700546#endif
Ramakant Singh75b427c2014-12-08 17:09:31 +0530547 } else {
Ramakant Singh21cec722014-03-07 19:11:45 +0530548 clear(renderBuffer, clearRegion);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530549 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530550 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500551 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800552 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500553 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
554 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800555 continue;
556 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530557 if(ctx->copybitDrop[i]) {
558 continue;
559 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530560 //skip non updating layers
561 if((mDirtyLayerIndex != -1) && (mDirtyLayerIndex != i) )
Ramakant Singh762ae082013-11-28 18:45:34 +0530562 continue;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800563 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400564 if (list->hwLayers[i].acquireFenceFd != -1
565 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800566 // Wait for acquire Fence on the App buffers.
567 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
568 if(ret < 0) {
569 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
570 __FUNCTION__, errno, strerror(errno));
571 }
572 close(list->hwLayers[i].acquireFenceFd);
573 list->hwLayers[i].acquireFenceFd = -1;
574 }
575 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530576 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800577 copybitLayerCount++;
578 if(retVal < 0) {
579 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
580 }
581 }
582
583 if (copybitLayerCount) {
584 copybit_device_t *copybit = getCopyBitDevice();
585 // Async mode
586 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530587 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
588 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400589 list->hwLayers[last].acquireFenceFd >= 0) {
590 close(list->hwLayers[last].acquireFenceFd);
591 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400592 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800593 }
594 return true;
595}
596
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700597int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700598 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700599 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700600
601 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
602 ALOGE("%s: Invalid request", __FUNCTION__);
603 return fd;
604 }
605
606 private_handle_t *renderBuffer = getCurrentRenderBuffer();
607
608 if (!renderBuffer) {
609 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
610 return fd;
611 }
612
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530613 //Clear the transparent or left out region on the render buffer
614 hwc_rect_t clearRegion = {0,0,0,0};
615 LayerProp *layerProp = ctx->layerProp[0];
616 if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
617 clear(renderBuffer, clearRegion);
618
Sushil Chauhandefd3522014-05-13 18:17:12 -0700619 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700620 for(int j = 0; j < ptorInfo->count; j++) {
621 int ovlapIndex = ptorInfo->layerIndex[j];
622 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530623 if(j) {
624 /**
625 * It's possible that 2 PTOR layers might have overlapping.
626 * In such case, remove the intersection(again if peripheral)
627 * from the lower PTOR layer to avoid overlapping.
628 * If intersection is not on peripheral then compromise
629 * by reducing number of PTOR layers.
630 **/
631 int prevOvlapIndex = ptorInfo->layerIndex[0];
632 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
633 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
634 if(isValidRect(commonRect)) {
635 overlap = deductRect(overlap, commonRect);
636 }
637 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700638
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700639 // Draw overlapped content of layers on render buffer
640 for (int i = 0; i <= ovlapIndex; i++) {
641 hwc_layer_1_t *layer = &list->hwLayers[i];
642 if(!isValidRect(getIntersection(layer->displayFrame,
643 overlap))) {
644 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700645 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700646 if ((list->hwLayers[i].acquireFenceFd != -1)) {
647 // Wait for acquire fence on the App buffers.
648 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
649 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
650 __FUNCTION__, errno, strerror(errno));
651 }
652 close(list->hwLayers[i].acquireFenceFd);
653 list->hwLayers[i].acquireFenceFd = -1;
654 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530655 /*
656 * Find the intersection of layer display frame with PTOR layer
657 * with respect to screen co-ordinates
658 *
659 * Calculated the destination rect by transforming the overlapping
660 * region of layer display frame with respect to PTOR display frame
661 *
662 * Transform the destination rect on to render buffer
663 * */
664 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
665 destRect.left = destRect.left - overlap.left +
666 ptorInfo->displayFrame[j].left;
667 destRect.right = destRect.right- overlap.left +
668 ptorInfo->displayFrame[j].left;
669 destRect.top = destRect.top - overlap.top +
670 ptorInfo->displayFrame[j].top;
671 destRect.bottom = destRect.bottom - overlap.top +
672 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700673
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530674 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
675 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700676 copybitLayerCount++;
677 if(retVal < 0) {
678 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
679 copybitLayerCount = 0;
680 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700681 }
682 }
683
684 if (copybitLayerCount) {
685 copybit_device_t *copybit = getCopyBitDevice();
686 copybit->flush_get_fence(copybit, &fd);
687 }
688
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700689 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
690 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700691 return fd;
692}
693
694int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700695 private_handle_t *renderBuffer, hwc_rect_t overlap,
696 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700697{
698 hwc_context_t* ctx = (hwc_context_t*)(dev);
699 if (!ctx) {
700 ALOGE("%s: null context ", __FUNCTION__);
701 return -1;
702 }
703
704 private_handle_t *hnd = (private_handle_t *)layer->handle;
705 if (!hnd) {
706 ALOGE("%s: invalid handle", __FUNCTION__);
707 return -1;
708 }
709
710 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
711 if (!dstHandle) {
712 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
713 return -1;
714 }
715
716 // Set the Copybit Source
717 copybit_image_t src;
718 src.handle = (native_handle_t *)layer->handle;
719 src.w = hnd->width;
720 src.h = hnd->height;
721 src.base = (void *)hnd->base;
722 src.format = hnd->format;
723 src.horiz_padding = 0;
724 src.vert_padding = 0;
725
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700726
Sushil Chauhandefd3522014-05-13 18:17:12 -0700727 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700728 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700729 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700730 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
731 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700732
733 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700734 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
735 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700736
737 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700738 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
739 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700740
741 // Copybit dst
742 copybit_image_t dst;
743 dst.handle = (native_handle_t *)dstHandle;
744 dst.w = ALIGN(dstHandle->width, 32);
745 dst.h = dstHandle->height;
746 dst.base = (void *)dstHandle->base;
747 dst.format = dstHandle->format;
748
749 copybit_device_t *copybit = mEngine;
750
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700751 // Copybit region is the destRect
752 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
753 hwc_region_t region;
754 region.numRects = 1;
755 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700756 region_iterator copybitRegion(region);
757 int acquireFd = layer->acquireFenceFd;
758
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700759 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
760 renderBuffer->width);
761 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
762 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700763 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
764 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
765 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
766 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700767 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
768 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700769 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700770 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
771 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700772
773 if (err < 0)
774 ALOGE("%s: copybit stretch failed",__FUNCTION__);
775
776 return err;
777}
778
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700779int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800780 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700781{
782 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400783 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700784 if(!ctx) {
785 ALOGE("%s: null context ", __FUNCTION__);
786 return -1;
787 }
788
789 private_handle_t *hnd = (private_handle_t *)layer->handle;
790 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700791 if (layer->flags & HWC_COLOR_FILL) { // Color layer
792 return fillColorUsingCopybit(layer, renderBuffer);
793 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700794 ALOGE("%s: invalid handle", __FUNCTION__);
795 return -1;
796 }
797
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800798 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700799 if(!fbHandle) {
800 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700801 return -1;
802 }
803
804 // Set the copybit source:
805 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700806 src.w = getWidth(hnd);
807 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700808 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700809
810 // Handle R/B swap
811 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
812 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
813 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
814 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
815 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
816 }
817 }
818
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700819 src.base = (void *)hnd->base;
820 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700821 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700822 // Initialize vertical padding to zero for now,
823 // this needs to change to accomodate vertical stride
824 // if needed in the future
825 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700826
shuoy7c101f92013-08-26 14:48:57 +0800827 int layerTransform = layer->transform ;
828 // When flip and rotation(90) are present alter the flip,
829 // as GPU is doing the flip and rotation in opposite order
830 // to that of MDP3.0
831 // For 270 degrees, we get 90 + (H+V) which is same as doing
832 // flip first and then rotation (H+V) + 90
833 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
834 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
835 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
836 (layer->transform & HAL_TRANSFORM_ROT_90) &&
837 !(layer->transform == HAL_TRANSFORM_ROT_270)){
838 if(layer->transform & HAL_TRANSFORM_FLIP_H){
839 layerTransform ^= HAL_TRANSFORM_FLIP_H;
840 layerTransform |= HAL_TRANSFORM_FLIP_V;
841 }
842 if(layer->transform & HAL_TRANSFORM_FLIP_V){
843 layerTransform ^= HAL_TRANSFORM_FLIP_V;
844 layerTransform |= HAL_TRANSFORM_FLIP_H;
845 }
846 }
847 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700848 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700849 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700850 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
851 sourceCrop.right,
852 sourceCrop.bottom};
853
854 // Copybit destination rect
855 hwc_rect_t displayFrame = layer->displayFrame;
856 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
857 displayFrame.right,
858 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700859#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530860 //change src and dst with dirtyRect
861 if(mDirtyLayerIndex != -1) {
862 srcRect.l = layer->dirtyRect.left;
863 srcRect.t = layer->dirtyRect.top;
864 srcRect.r = layer->dirtyRect.right;
865 srcRect.b = layer->dirtyRect.bottom;
866 dstRect = srcRect;
867 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700868#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700869 // Copybit dst
870 copybit_image_t dst;
871 dst.w = ALIGN(fbHandle->width,32);
872 dst.h = fbHandle->height;
873 dst.format = fbHandle->format;
874 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800875 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700876
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800877 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700878
879 int32_t screen_w = displayFrame.right - displayFrame.left;
880 int32_t screen_h = displayFrame.bottom - displayFrame.top;
881 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
882 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
883
884 // Copybit dst
885 float copybitsMaxScale =
886 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
887 float copybitsMinScale =
888 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
889
Sushil Chauhandffbf432013-12-09 15:33:57 -0800890 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700891 //swap screen width and height
892 int tmp = screen_w;
893 screen_w = screen_h;
894 screen_h = tmp;
895 }
896 private_handle_t *tmpHnd = NULL;
897
898 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
899 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530900 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
901 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700902 return -1;
903 }
904
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530905 float dsdx = (float)screen_w/(float)src_crop_width;
906 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700907
908 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
909 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
910 if(dsdx > scaleLimitMax ||
911 dtdy > scaleLimitMax ||
912 dsdx < 1/scaleLimitMin ||
913 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400914 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700915 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
916 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700917 return -1;
918 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400919 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700920 if(dsdx > copybitsMaxScale ||
921 dtdy > copybitsMaxScale ||
922 dsdx < 1/copybitsMinScale ||
923 dtdy < 1/copybitsMinScale){
924 // The requested scale is out of the range the hardware
925 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400926 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700927 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
928 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
929 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
930 src_crop_width,src_crop_height);
931
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700932
933 int tmp_w = src_crop_width;
934 int tmp_h = src_crop_height;
935
936 if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530937 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
938 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700939 }else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){
Ramakant Singh80f36f22014-02-25 14:11:35 +0530940 // ceil the tmp_w and tmp_h value to maintain proper ratio
941 // b/w src and dst (should not cross the desired scale limit
942 // due to float -> int )
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530943 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
944 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700945 }
Terence Hampson663dfa72013-08-08 12:35:41 -0400946 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700947
Naseer Ahmed64b81212013-02-14 10:29:47 -0500948 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400949 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700950
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400951 // We do not want copybit to generate alpha values from nothing
952 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
953 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
954 format = HAL_PIXEL_FORMAT_RGBX_8888;
955 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800956 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700957 copybit_image_t tmp_dst;
958 copybit_rect_t tmp_rect;
959 tmp_dst.w = tmp_w;
960 tmp_dst.h = tmp_h;
961 tmp_dst.format = tmpHnd->format;
962 tmp_dst.handle = tmpHnd;
963 tmp_dst.horiz_padding = src.horiz_padding;
964 tmp_dst.vert_padding = src.vert_padding;
965 tmp_rect.l = 0;
966 tmp_rect.t = 0;
967 tmp_rect.r = tmp_dst.w;
968 tmp_rect.b = tmp_dst.h;
969 //create one clip region
970 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
971 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
972 region_iterator tmp_it(tmp_hwc_reg);
973 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700974 //TODO: once, we are able to read layer alpha, update this
975 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -0400976 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700977 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
978 &srcRect, &tmp_it);
979 if(err < 0){
980 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
981 __LINE__);
982 if(tmpHnd)
983 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700984 return err;
985 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400986 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400987 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -0400988 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400989 close(acquireFd);
990 acquireFd = -1;
991 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700992 // copy new src and src rect crop
993 src = tmp_dst;
994 srcRect = tmp_rect;
995 }
996 }
997 // Copybit region
998 hwc_region_t region = layer->visibleRegionScreen;
999 region_iterator copybitRegion(region);
1000
1001 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1002 renderBuffer->width);
1003 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1004 renderBuffer->height);
1005 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +08001006 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001007 //TODO: once, we are able to read layer alpha, update this
1008 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001009 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
1010 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001011 copybit->set_parameter(copybit, COPYBIT_DITHER,
1012 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1013 COPYBIT_ENABLE : COPYBIT_DISABLE);
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301014 copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ?
1015 COPYBIT_ENABLE : COPYBIT_DISABLE);
1016
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001017 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1018 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001019 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001020 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1021 &copybitRegion);
1022 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1023 COPYBIT_DISABLE);
1024
Terence Hampsonadf47302013-05-23 12:21:02 -04001025 if(tmpHnd) {
1026 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1027 int ret = -1, releaseFd;
1028 // we need to wait for the buffer before freeing
1029 copybit->flush_get_fence(copybit, &releaseFd);
1030 ret = sync_wait(releaseFd, 1000);
1031 if(ret < 0) {
1032 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1033 __FUNCTION__, errno, strerror(errno));
1034 }
1035 close(releaseFd);
1036 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001037 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001038 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001039
1040 if(err < 0)
1041 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001042 return err;
1043}
1044
Sushil Chauhan943797c2013-10-21 17:35:55 -07001045int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1046 private_handle_t *renderBuffer)
1047{
1048 if (!renderBuffer) {
1049 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1050 return -1;
1051 }
1052
1053 // Copybit dst
1054 copybit_image_t dst;
1055 dst.w = ALIGN(renderBuffer->width, 32);
1056 dst.h = renderBuffer->height;
1057 dst.format = renderBuffer->format;
1058 dst.base = (void *)renderBuffer->base;
1059 dst.handle = (native_handle_t *)renderBuffer;
1060
1061 // Copybit dst rect
1062 hwc_rect_t displayFrame = layer->displayFrame;
1063 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1064 displayFrame.right, displayFrame.bottom};
1065
1066 uint32_t color = layer->transform;
1067 copybit_device_t *copybit = mEngine;
1068 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1069 renderBuffer->width);
1070 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1071 renderBuffer->height);
1072 copybit->set_parameter(copybit, COPYBIT_DITHER,
1073 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1074 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001075 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001076 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1077 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1078 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1079 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1080 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1081 return res;
1082}
1083
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001084void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001085 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001086{
1087 hwc_rect_t displayFrame = layer->displayFrame;
1088
1089 width = displayFrame.right - displayFrame.left;
1090 height = displayFrame.bottom - displayFrame.top;
1091}
1092
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001093bool CopyBit::validateParams(hwc_context_t *ctx,
1094 const hwc_display_contents_1_t *list) {
1095 //Validate parameters
1096 if (!ctx) {
1097 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1098 return false;
1099 } else if (!list) {
1100 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1101 return false;
1102 }
1103 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001104}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001105
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001106
Naseer Ahmed64b81212013-02-14 10:29:47 -05001107int CopyBit::allocRenderBuffers(int w, int h, int f)
1108{
1109 int ret = 0;
1110 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1111 if (mRenderBuffer[i] == NULL) {
1112 ret = alloc_buffer(&mRenderBuffer[i],
1113 w, h, f,
1114 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
1115 }
1116 if(ret < 0) {
1117 freeRenderBuffers();
1118 break;
1119 }
1120 }
1121 return ret;
1122}
1123
1124void CopyBit::freeRenderBuffers()
1125{
1126 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1127 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301128 //Since we are freeing buffer close the fence if it has a valid one.
1129 if(mRelFd[i] >= 0) {
1130 close(mRelFd[i]);
1131 mRelFd[i] = -1;
1132 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001133 free_buffer(mRenderBuffer[i]);
1134 mRenderBuffer[i] = NULL;
1135 }
1136 }
1137}
1138
1139private_handle_t * CopyBit::getCurrentRenderBuffer() {
1140 return mRenderBuffer[mCurRenderBufferIndex];
1141}
1142
1143void CopyBit::setReleaseFd(int fd) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301144 if(mRelFd[mCurRenderBufferIndex] >=0)
1145 close(mRelFd[mCurRenderBufferIndex]);
1146 mRelFd[mCurRenderBufferIndex] = dup(fd);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001147}
1148
Sushil Chauhandefd3522014-05-13 18:17:12 -07001149void CopyBit::setReleaseFdSync(int fd) {
1150 if (mRelFd[mCurRenderBufferIndex] >=0) {
1151 int ret = -1;
1152 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1153 if (ret < 0)
1154 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1155 __FUNCTION__, errno, strerror(errno));
1156 close(mRelFd[mCurRenderBufferIndex]);
1157 }
1158 mRelFd[mCurRenderBufferIndex] = dup(fd);
1159}
1160
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001161struct copybit_device_t* CopyBit::getCopyBitDevice() {
1162 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001163}
1164
Shalaj Jaina70b4352014-06-15 13:47:47 -07001165CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1166 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001167
1168 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1169 ctx->dpyAttr[dpy].yres,
1170 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001171 mAlignedWidth,
1172 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001173
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001174 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301175 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001176 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301177 mRelFd[i] = -1;
1178 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301179
1180 char value[PROPERTY_VALUE_MAX];
1181 property_get("debug.hwc.dynThreshold", value, "2");
1182 mDynThreshold = atof(value);
1183
Ramakant Singh21cec722014-03-07 19:11:45 +05301184 property_get("debug.sf.swaprect", value, "0");
1185 mSwapRectEnable = atoi(value) ? true:false ;
1186 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001187 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001188 if(copybit_open(module, &mEngine) < 0) {
1189 ALOGE("FATAL ERROR: copybit open failed.");
1190 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001191 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001192 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001193 }
1194}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001195
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001196CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001197{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001198 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001199 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001200 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001201 copybit_close(mEngine);
1202 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001203 }
1204}
Ramakant Singh21cec722014-03-07 19:11:45 +05301205CopyBit::LayerCache::LayerCache() {
1206 reset();
1207}
1208void CopyBit::LayerCache::reset() {
1209 memset(&hnd, 0, sizeof(hnd));
1210 layerCount = 0;
1211}
1212void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1213 hwc_display_contents_1_t *list, int dpy)
1214{
1215 layerCount = ctx->listStats[dpy].numAppLayers;
1216 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1217 hnd[i] = list->hwLayers[i].handle;
1218 }
1219}
1220
1221CopyBit::FbCache::FbCache() {
1222 reset();
1223}
1224void CopyBit::FbCache::reset() {
1225 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
1226 FbIndex =0;
1227}
1228
1229void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) {
1230 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1231 FbdirtyRect[FbIndex] = dirtyRect;
1232 FbIndex++;
1233}
1234
1235int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){
1236 int sameDirtyCount = 0;
1237 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
1238 if( FbdirtyRect[i] == dirtyRect)
1239 sameDirtyCount++;
1240 }
1241 return sameDirtyCount;
1242}
1243
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001244}; //namespace qhwc