blob: 30935cbcc622e22521ed6ac37d39bf64a0201708 [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
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530166 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--) {
167 //disable swap rect in case of scaling and video .
168 private_handle_t *hnd =(private_handle_t *)list->hwLayers[k].handle;
169 if(needsScaling(&list->hwLayers[k])||( hnd && isYuvBuffer(hnd))) {
170 mFbCache.reset();
171 return -1;
Ramakant Singh21cec722014-03-07 19:11:45 +0530172 }
173 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530174 if(mFbCache.getUnchangedFbDRCount(dirtyRect) <
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530175 NUM_RENDER_BUFFERS) {
176 mFbCache.insertAndUpdateFbCache(dirtyRect);
Ramakant Singh21cec722014-03-07 19:11:45 +0530177 changingLayerIndex = -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530178 }
179 } else {
Ramakant Singh21cec722014-03-07 19:11:45 +0530180 mFbCache.reset();
181 changingLayerIndex = -1;
182 }
183 mLayerCache.updateCounts(ctx,list,dpy);
184 return changingLayerIndex;
185}
186
187int CopyBit::checkDirtyRect(hwc_context_t *ctx,
188 hwc_display_contents_1_t *list,
189 int dpy) {
190
191 //dirty rect will enable only if
192 //1.Only single layer is updating.
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530193 //2.No scaling
194 //3.No video layer
Ramakant Singh21cec722014-03-07 19:11:45 +0530195 if(mSwapRectEnable == false)
196 return -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530197 return getLayersChanging(ctx, list, dpy);
Ramakant Singh21cec722014-03-07 19:11:45 +0530198}
199
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700200bool CopyBit::prepareOverlap(hwc_context_t *ctx,
201 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700202
203 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
204 ALOGE("%s: Invalid request", __FUNCTION__);
205 return false;
206 }
207
Saurabh Shah15455aa2015-01-28 13:54:48 -0800208 if (mEngine == NULL) {
209 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
210 return false;
211 }
212
213 if (!(validateParams(ctx, list))) {
214 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700215 return false;
216 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700217 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700218
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700219 // Allocate render buffers if they're not allocated
220 int alignW = 0, alignH = 0;
221 int finalW = 0, finalH = 0;
222 for (int i = 0; i < ptorInfo->count; i++) {
223 int ovlapIndex = ptorInfo->layerIndex[i];
224 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
225 // render buffer width will be the max of two layers
226 // Align Widht and height to 32, Mdp would be configured
227 // with Aligned overlap w/h
228 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
229 finalH += ALIGN((overlap.bottom - overlap.top), 32);
230 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700231 // Calculate the dest top, left will always be zero
232 ptorInfo->displayFrame[i].top = (finalH -
233 (ALIGN((overlap.bottom - overlap.top), 32)));
234 }
235 // calculate the right and bottom values
236 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
237 (overlap.right - overlap.left);
238 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
239 (overlap.bottom - overlap.top);
240 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700241
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700242 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700243 alignW, alignH);
244
245 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
246 // Overlap rect has changed, so free render buffers
247 freeRenderBuffers();
248 }
249
250 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
251
252 if (ret < 0) {
253 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
254 return false;
255 }
256
257 mAlignedWidth = alignW;
258 mAlignedHeight = alignH;
259 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
260 return true;
261}
262
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800263bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
264 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700265
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800266 if(mEngine == NULL) {
267 // No copybit device found - cannot use copybit
268 return false;
269 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530270
271 if(ctx->mThermalBurstMode) {
272 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
273 "Running in Thermal Burst mode",__FUNCTION__);
274 return false;
275 }
276
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800277 int compositionType = qdutils::QCCompositionType::
278 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700279
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800280 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
281 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700282 //GPU/CPU composition, don't change layer composition type
283 return true;
284 }
285
Naseer Ahmed45a99602012-07-31 19:15:24 -0700286 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800287 ALOGE("%s:Invalid Params", __FUNCTION__);
288 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700289 }
290
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800291 if(ctx->listStats[dpy].skipCount) {
292 //GPU will be anyways used
293 return false;
294 }
295
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700296 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700297 // Reached max layers supported by HWC.
298 return false;
299 }
300
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800301 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
302 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500303 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500304
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530305 // Following are MDP3 limitations for which we
306 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400307 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500308 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400309 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
310 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500311 int dst_h, dst_w, src_h, src_w;
312 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530313 if(ctx->copybitDrop[i]) {
314 continue;
315 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400316 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530317 if (layer->planeAlpha != 0xFF)
318 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530319 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500320
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700321 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530322 src_h = sourceCrop.right - sourceCrop.left;
323 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500324 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530325 src_h = sourceCrop.bottom - sourceCrop.top;
326 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500327 }
328 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
329 dst_w = layer->displayFrame.right - layer->displayFrame.left;
330
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530331 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
332 ALOGE("%s: wrong params for display screen_w=%d \
333 src_crop_width=%d screen_h=%d src_crop_height=%d",
334 __FUNCTION__, dst_w,src_w,dst_h,src_h);
335 return false;
336 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530337 dx = (float)dst_w/(float)src_w;
338 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530339
Terence Hampson6b0a4272013-11-06 16:04:51 -0500340 if (dx > MAX_SCALE_FACTOR || dx < MIN_SCALE_FACTOR)
341 return false;
342
343 if (dy > MAX_SCALE_FACTOR || dy < MIN_SCALE_FACTOR)
344 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400345 }
346 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500347
348 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530349 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
350 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400351 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700352 int ret = allocRenderBuffers(mAlignedWidth,
353 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700354 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500355 if (ret < 0) {
356 return false;
357 } else {
358 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
359 NUM_RENDER_BUFFERS;
360 }
361 }
362
Terence Hampsond0fd5792013-05-29 11:56:52 -0400363 // We cannot mix copybit layer with layers marked to be drawn on FB
364 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
365 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800366
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530367 mCopyBitDraw = false;
368 if (useCopybitForRGB &&
369 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
370 mCopyBitDraw = true;
371 // numAppLayers-1, as we iterate till 0th layer index
372 // Mark all layers to be drawn by copybit
373 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500374 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700375#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530376 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
377 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400378 list->hwLayers[i].compositionType = HWC_BLIT;
379 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700380#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400381 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700382 }
383 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530384
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700385 return true;
386}
387
Naseer Ahmed183939d2013-03-14 20:44:17 -0400388int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
389{
390 int ret = 0;
391 copybit_rect_t clear_rect = {rect.left, rect.top,
392 rect.right,
393 rect.bottom};
394
395 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700396 buf.w = ALIGN(getWidth(hnd),32);
397 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400398 buf.format = hnd->format;
399 buf.base = (void *)hnd->base;
400 buf.handle = (native_handle_t *)hnd;
401
402 copybit_device_t *copybit = mEngine;
403 ret = copybit->clear(copybit, &buf, &clear_rect);
404 return ret;
405}
406
Ramakant Singh0def28c2014-03-28 20:43:13 +0530407bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
408 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530409 int dpy, int *copybitFd) {
410 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700411 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530412 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
413 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530414
415 if(ctx->enableABC == false)
416 return false;
417
Ramakant Singh467759f2014-04-16 11:09:40 +0530418 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530419 return false;
420
421 layerCount = ctx->listStats[dpy].numAppLayers;
422 //bottom most layer should
423 //equal to FB
424 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
425 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
426 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
427 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
428 if(tmpLayer->transform ||
429 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
430 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
431 (needsScaling(tmpLayer) == true)) {
432 return false;
433 }else {
434 ctx->listStats[dpy].renderBufIndexforABC = 0;
435 }
436 }
437
Ramakant Singh467759f2014-04-16 11:09:40 +0530438 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
439 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530440 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530441
Ramakant Singhcc326612014-06-19 14:19:18 +0530442 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530443 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530444 //enable ABC only for non intersecting layers.
445 hwc_rect_t displayFrame =
446 list->hwLayers[abcRenderBufIdx].displayFrame;
447 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
448 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
449 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
450 if (isValidRect(result)) {
451 ctx->listStats[dpy].renderBufIndexforABC = -1;
452 return false;
453 }
454 }
455 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530456 private_handle_t *renderBuffer =
457 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
458 copybit_device_t *copybit = getCopyBitDevice();
459 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
460 copybit->set_sync(copybit,
461 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
462 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530463 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530464 mDirtyLayerIndex = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530465 int retVal = drawLayerUsingCopybit(ctx,
466 &(list->hwLayers[i]),renderBuffer, 0);
467 if(retVal < 0) {
468 ALOGE("%s : Copybit failed", __FUNCTION__);
469 }
470 }
471 // Get Release Fence FD of copybit for the App layer(s)
472 copybit->flush_get_fence(copybit, copybitFd);
473 close(list->hwLayers[abcRenderBufIdx].acquireFenceFd);
474 list->hwLayers[abcRenderBufIdx].acquireFenceFd = -1;
475 return true;
476 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530477 }
478 return false;
479}
480
481bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
482 int dpy, int32_t *fd) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800483 // draw layers marked for COPYBIT
484 int retVal = true;
485 int copybitLayerCount = 0;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400486 uint32_t last = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500487 LayerProp *layerProp = ctx->layerProp[dpy];
Terence Hampsonc67b0372013-10-09 11:32:21 -0400488 private_handle_t *renderBuffer;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800489
Ramakant Singh21cec722014-03-07 19:11:45 +0530490 if(mCopyBitDraw == false){
491 mFbCache.reset(); // there is no layer marked for copybit
492 return false ;
493 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530494
Ramakant Singh467759f2014-04-16 11:09:40 +0530495 if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) {
Ramakant Singh0def28c2014-03-28 20:43:13 +0530496 return true;
497 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800498 //render buffer
Ramakant Singhb4106a12014-10-07 18:06:56 +0530499 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
500 ctx->mMDP.version == qdutils::MDP_V3_0_5) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530501 last = (uint32_t)list->numHwLayers - 1;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400502 renderBuffer = (private_handle_t *)list->hwLayers[last].handle;
503 } else {
504 renderBuffer = getCurrentRenderBuffer();
505 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800506 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500507 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800508 return false;
509 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500510
Terence Hampson0124cc72013-04-18 23:45:56 -0700511 if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400512 //Wait for the previous frame to complete before rendering onto it
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530513 if(mRelFd[mCurRenderBufferIndex] >=0) {
514 sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
515 close(mRelFd[mCurRenderBufferIndex]);
516 mRelFd[mCurRenderBufferIndex] = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400517 }
Terence Hampson65fe4522013-10-17 17:40:03 -0400518 } else {
Terence Hampsonc67b0372013-10-09 11:32:21 -0400519 if(list->hwLayers[last].acquireFenceFd >=0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400520 copybit_device_t *copybit = getCopyBitDevice();
Terence Hampsonc67b0372013-10-09 11:32:21 -0400521 copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd);
Terence Hampson65fe4522013-10-17 17:40:03 -0400522 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700523 }
radhakrishna2f00c8f2013-10-21 16:49:21 +0530524
Ramakant Singh21cec722014-03-07 19:11:45 +0530525 mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy);
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530526 ALOGD_IF (DEBUG_COPYBIT, "%s:Dirty Layer Index: %d",
527 __FUNCTION__, mDirtyLayerIndex);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530528 hwc_rect_t clearRegion = {0,0,0,0};
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530529 mDirtyRect = list->hwLayers[last].displayFrame;
530 if (mDirtyLayerIndex != -1)
531 mDirtyRect = list->hwLayers[mDirtyLayerIndex].displayFrame;
532
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +0530533 if (CBUtils::getuiClearRegion(list, clearRegion, layerProp,
534 mDirtyLayerIndex))
Ramakant Singh21cec722014-03-07 19:11:45 +0530535 clear(renderBuffer, clearRegion);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500536 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800537 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500538 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
539 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800540 continue;
541 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530542 if(ctx->copybitDrop[i]) {
543 continue;
544 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800545 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400546 if (list->hwLayers[i].acquireFenceFd != -1
547 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800548 // Wait for acquire Fence on the App buffers.
549 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
550 if(ret < 0) {
551 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
552 __FUNCTION__, errno, strerror(errno));
553 }
554 close(list->hwLayers[i].acquireFenceFd);
555 list->hwLayers[i].acquireFenceFd = -1;
556 }
557 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530558 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800559 copybitLayerCount++;
560 if(retVal < 0) {
561 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
562 }
563 }
564
565 if (copybitLayerCount) {
566 copybit_device_t *copybit = getCopyBitDevice();
567 // Async mode
568 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530569 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
570 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400571 list->hwLayers[last].acquireFenceFd >= 0) {
572 close(list->hwLayers[last].acquireFenceFd);
573 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400574 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800575 }
576 return true;
577}
578
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700579int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700580 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700581 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700582
583 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
584 ALOGE("%s: Invalid request", __FUNCTION__);
585 return fd;
586 }
587
588 private_handle_t *renderBuffer = getCurrentRenderBuffer();
589
590 if (!renderBuffer) {
591 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
592 return fd;
593 }
594
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530595 //Clear the transparent or left out region on the render buffer
596 hwc_rect_t clearRegion = {0,0,0,0};
597 LayerProp *layerProp = ctx->layerProp[0];
598 if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
599 clear(renderBuffer, clearRegion);
600
Sushil Chauhandefd3522014-05-13 18:17:12 -0700601 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700602 for(int j = 0; j < ptorInfo->count; j++) {
603 int ovlapIndex = ptorInfo->layerIndex[j];
604 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530605 if(j) {
606 /**
607 * It's possible that 2 PTOR layers might have overlapping.
608 * In such case, remove the intersection(again if peripheral)
609 * from the lower PTOR layer to avoid overlapping.
610 * If intersection is not on peripheral then compromise
611 * by reducing number of PTOR layers.
612 **/
613 int prevOvlapIndex = ptorInfo->layerIndex[0];
614 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
615 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
616 if(isValidRect(commonRect)) {
617 overlap = deductRect(overlap, commonRect);
618 }
619 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700620
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700621 // Draw overlapped content of layers on render buffer
622 for (int i = 0; i <= ovlapIndex; i++) {
623 hwc_layer_1_t *layer = &list->hwLayers[i];
624 if(!isValidRect(getIntersection(layer->displayFrame,
625 overlap))) {
626 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700627 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700628 if ((list->hwLayers[i].acquireFenceFd != -1)) {
629 // Wait for acquire fence on the App buffers.
630 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
631 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
632 __FUNCTION__, errno, strerror(errno));
633 }
634 close(list->hwLayers[i].acquireFenceFd);
635 list->hwLayers[i].acquireFenceFd = -1;
636 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530637 /*
638 * Find the intersection of layer display frame with PTOR layer
639 * with respect to screen co-ordinates
640 *
641 * Calculated the destination rect by transforming the overlapping
642 * region of layer display frame with respect to PTOR display frame
643 *
644 * Transform the destination rect on to render buffer
645 * */
646 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
647 destRect.left = destRect.left - overlap.left +
648 ptorInfo->displayFrame[j].left;
649 destRect.right = destRect.right- overlap.left +
650 ptorInfo->displayFrame[j].left;
651 destRect.top = destRect.top - overlap.top +
652 ptorInfo->displayFrame[j].top;
653 destRect.bottom = destRect.bottom - overlap.top +
654 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700655
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530656 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
657 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700658 copybitLayerCount++;
659 if(retVal < 0) {
660 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
661 copybitLayerCount = 0;
662 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700663 }
664 }
665
666 if (copybitLayerCount) {
667 copybit_device_t *copybit = getCopyBitDevice();
668 copybit->flush_get_fence(copybit, &fd);
669 }
670
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700671 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
672 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700673 return fd;
674}
675
676int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700677 private_handle_t *renderBuffer, hwc_rect_t overlap,
678 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700679{
680 hwc_context_t* ctx = (hwc_context_t*)(dev);
681 if (!ctx) {
682 ALOGE("%s: null context ", __FUNCTION__);
683 return -1;
684 }
685
686 private_handle_t *hnd = (private_handle_t *)layer->handle;
687 if (!hnd) {
688 ALOGE("%s: invalid handle", __FUNCTION__);
689 return -1;
690 }
691
692 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
693 if (!dstHandle) {
694 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
695 return -1;
696 }
697
698 // Set the Copybit Source
699 copybit_image_t src;
700 src.handle = (native_handle_t *)layer->handle;
701 src.w = hnd->width;
702 src.h = hnd->height;
703 src.base = (void *)hnd->base;
704 src.format = hnd->format;
705 src.horiz_padding = 0;
706 src.vert_padding = 0;
707
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700708
Sushil Chauhandefd3522014-05-13 18:17:12 -0700709 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700710 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700711 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700712 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
713 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700714
715 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700716 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
717 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700718
719 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700720 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
721 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700722
723 // Copybit dst
724 copybit_image_t dst;
725 dst.handle = (native_handle_t *)dstHandle;
726 dst.w = ALIGN(dstHandle->width, 32);
727 dst.h = dstHandle->height;
728 dst.base = (void *)dstHandle->base;
729 dst.format = dstHandle->format;
730
731 copybit_device_t *copybit = mEngine;
732
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700733 // Copybit region is the destRect
734 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
735 hwc_region_t region;
736 region.numRects = 1;
737 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700738 region_iterator copybitRegion(region);
739 int acquireFd = layer->acquireFenceFd;
740
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700741 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
742 renderBuffer->width);
743 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
744 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700745 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
746 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
747 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
748 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700749 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
750 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700751 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700752 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
753 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700754
755 if (err < 0)
756 ALOGE("%s: copybit stretch failed",__FUNCTION__);
757
758 return err;
759}
760
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700761int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800762 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700763{
764 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400765 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700766 if(!ctx) {
767 ALOGE("%s: null context ", __FUNCTION__);
768 return -1;
769 }
770
771 private_handle_t *hnd = (private_handle_t *)layer->handle;
772 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700773 if (layer->flags & HWC_COLOR_FILL) { // Color layer
774 return fillColorUsingCopybit(layer, renderBuffer);
775 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700776 ALOGE("%s: invalid handle", __FUNCTION__);
777 return -1;
778 }
779
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800780 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700781 if(!fbHandle) {
782 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700783 return -1;
784 }
785
786 // Set the copybit source:
787 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700788 src.w = getWidth(hnd);
789 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700790 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700791
792 // Handle R/B swap
793 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
794 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
795 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
796 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
797 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
798 }
799 }
800
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700801 src.base = (void *)hnd->base;
802 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700803 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700804 // Initialize vertical padding to zero for now,
805 // this needs to change to accomodate vertical stride
806 // if needed in the future
807 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700808
shuoy7c101f92013-08-26 14:48:57 +0800809 int layerTransform = layer->transform ;
810 // When flip and rotation(90) are present alter the flip,
811 // as GPU is doing the flip and rotation in opposite order
812 // to that of MDP3.0
813 // For 270 degrees, we get 90 + (H+V) which is same as doing
814 // flip first and then rotation (H+V) + 90
815 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
816 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
817 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
818 (layer->transform & HAL_TRANSFORM_ROT_90) &&
819 !(layer->transform == HAL_TRANSFORM_ROT_270)){
820 if(layer->transform & HAL_TRANSFORM_FLIP_H){
821 layerTransform ^= HAL_TRANSFORM_FLIP_H;
822 layerTransform |= HAL_TRANSFORM_FLIP_V;
823 }
824 if(layer->transform & HAL_TRANSFORM_FLIP_V){
825 layerTransform ^= HAL_TRANSFORM_FLIP_V;
826 layerTransform |= HAL_TRANSFORM_FLIP_H;
827 }
828 }
829 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700830 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700831 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700832 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
833 sourceCrop.right,
834 sourceCrop.bottom};
835
836 // Copybit destination rect
837 hwc_rect_t displayFrame = layer->displayFrame;
838 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
839 displayFrame.right,
840 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700841#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530842 //change src and dst with dirtyRect
843 if(mDirtyLayerIndex != -1) {
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530844 hwc_rect_t result = getIntersection(displayFrame, mDirtyRect);
845 if(!isValidRect(result))
846 return true;
847 dstRect.l = result.left;
848 dstRect.t = result.top;
849 dstRect.r = result.right;
850 dstRect.b = result.bottom;
851
852 srcRect.l += (result.left - displayFrame.left);
853 srcRect.t += (result.top - displayFrame.top);
854 srcRect.r -= (displayFrame.right - result.right);
855 srcRect.b -= (displayFrame.bottom - result.bottom);
Ramakant Singh21cec722014-03-07 19:11:45 +0530856 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700857#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700858 // Copybit dst
859 copybit_image_t dst;
860 dst.w = ALIGN(fbHandle->width,32);
861 dst.h = fbHandle->height;
862 dst.format = fbHandle->format;
863 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800864 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700865
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800866 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700867
868 int32_t screen_w = displayFrame.right - displayFrame.left;
869 int32_t screen_h = displayFrame.bottom - displayFrame.top;
870 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
871 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
872
873 // Copybit dst
874 float copybitsMaxScale =
875 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
876 float copybitsMinScale =
877 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
878
Sushil Chauhandffbf432013-12-09 15:33:57 -0800879 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700880 //swap screen width and height
881 int tmp = screen_w;
882 screen_w = screen_h;
883 screen_h = tmp;
884 }
885 private_handle_t *tmpHnd = NULL;
886
887 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
888 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530889 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
890 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700891 return -1;
892 }
893
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530894 float dsdx = (float)screen_w/(float)src_crop_width;
895 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700896
897 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
898 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
899 if(dsdx > scaleLimitMax ||
900 dtdy > scaleLimitMax ||
901 dsdx < 1/scaleLimitMin ||
902 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400903 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700904 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
905 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700906 return -1;
907 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400908 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700909 if(dsdx > copybitsMaxScale ||
910 dtdy > copybitsMaxScale ||
911 dsdx < 1/copybitsMinScale ||
912 dtdy < 1/copybitsMinScale){
913 // The requested scale is out of the range the hardware
914 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400915 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700916 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
917 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
918 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
919 src_crop_width,src_crop_height);
920
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700921
922 int tmp_w = src_crop_width;
923 int tmp_h = src_crop_height;
924
925 if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530926 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
927 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700928 }else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){
Ramakant Singh80f36f22014-02-25 14:11:35 +0530929 // ceil the tmp_w and tmp_h value to maintain proper ratio
930 // b/w src and dst (should not cross the desired scale limit
931 // due to float -> int )
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530932 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
933 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700934 }
Terence Hampson663dfa72013-08-08 12:35:41 -0400935 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700936
Naseer Ahmed64b81212013-02-14 10:29:47 -0500937 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400938 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700939
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400940 // We do not want copybit to generate alpha values from nothing
941 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
942 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
943 format = HAL_PIXEL_FORMAT_RGBX_8888;
944 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800945 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700946 copybit_image_t tmp_dst;
947 copybit_rect_t tmp_rect;
948 tmp_dst.w = tmp_w;
949 tmp_dst.h = tmp_h;
950 tmp_dst.format = tmpHnd->format;
951 tmp_dst.handle = tmpHnd;
952 tmp_dst.horiz_padding = src.horiz_padding;
953 tmp_dst.vert_padding = src.vert_padding;
954 tmp_rect.l = 0;
955 tmp_rect.t = 0;
956 tmp_rect.r = tmp_dst.w;
957 tmp_rect.b = tmp_dst.h;
958 //create one clip region
959 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
960 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
961 region_iterator tmp_it(tmp_hwc_reg);
962 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700963 //TODO: once, we are able to read layer alpha, update this
964 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -0400965 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700966 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
967 &srcRect, &tmp_it);
968 if(err < 0){
969 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
970 __LINE__);
971 if(tmpHnd)
972 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700973 return err;
974 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400975 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400976 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -0400977 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400978 close(acquireFd);
979 acquireFd = -1;
980 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700981 // copy new src and src rect crop
982 src = tmp_dst;
983 srcRect = tmp_rect;
984 }
985 }
986 // Copybit region
987 hwc_region_t region = layer->visibleRegionScreen;
988 region_iterator copybitRegion(region);
989
990 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
991 renderBuffer->width);
992 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
993 renderBuffer->height);
994 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +0800995 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700996 //TODO: once, we are able to read layer alpha, update this
997 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800998 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
999 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001000 copybit->set_parameter(copybit, COPYBIT_DITHER,
1001 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1002 COPYBIT_ENABLE : COPYBIT_DISABLE);
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301003 copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ?
1004 COPYBIT_ENABLE : COPYBIT_DISABLE);
1005
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001006 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1007 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001008 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001009 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1010 &copybitRegion);
1011 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1012 COPYBIT_DISABLE);
1013
Terence Hampsonadf47302013-05-23 12:21:02 -04001014 if(tmpHnd) {
1015 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1016 int ret = -1, releaseFd;
1017 // we need to wait for the buffer before freeing
1018 copybit->flush_get_fence(copybit, &releaseFd);
1019 ret = sync_wait(releaseFd, 1000);
1020 if(ret < 0) {
1021 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1022 __FUNCTION__, errno, strerror(errno));
1023 }
1024 close(releaseFd);
1025 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001026 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001027 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001028
1029 if(err < 0)
1030 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001031 return err;
1032}
1033
Sushil Chauhan943797c2013-10-21 17:35:55 -07001034int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1035 private_handle_t *renderBuffer)
1036{
1037 if (!renderBuffer) {
1038 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1039 return -1;
1040 }
1041
1042 // Copybit dst
1043 copybit_image_t dst;
1044 dst.w = ALIGN(renderBuffer->width, 32);
1045 dst.h = renderBuffer->height;
1046 dst.format = renderBuffer->format;
1047 dst.base = (void *)renderBuffer->base;
1048 dst.handle = (native_handle_t *)renderBuffer;
1049
1050 // Copybit dst rect
1051 hwc_rect_t displayFrame = layer->displayFrame;
1052 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1053 displayFrame.right, displayFrame.bottom};
1054
1055 uint32_t color = layer->transform;
1056 copybit_device_t *copybit = mEngine;
1057 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1058 renderBuffer->width);
1059 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1060 renderBuffer->height);
1061 copybit->set_parameter(copybit, COPYBIT_DITHER,
1062 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1063 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001064 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001065 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1066 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1067 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1068 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1069 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1070 return res;
1071}
1072
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001073void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001074 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001075{
1076 hwc_rect_t displayFrame = layer->displayFrame;
1077
1078 width = displayFrame.right - displayFrame.left;
1079 height = displayFrame.bottom - displayFrame.top;
1080}
1081
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001082bool CopyBit::validateParams(hwc_context_t *ctx,
1083 const hwc_display_contents_1_t *list) {
1084 //Validate parameters
1085 if (!ctx) {
1086 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1087 return false;
1088 } else if (!list) {
1089 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1090 return false;
1091 }
1092 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001093}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001094
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001095
Naseer Ahmed64b81212013-02-14 10:29:47 -05001096int CopyBit::allocRenderBuffers(int w, int h, int f)
1097{
1098 int ret = 0;
1099 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1100 if (mRenderBuffer[i] == NULL) {
1101 ret = alloc_buffer(&mRenderBuffer[i],
1102 w, h, f,
1103 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
1104 }
1105 if(ret < 0) {
1106 freeRenderBuffers();
1107 break;
1108 }
1109 }
1110 return ret;
1111}
1112
1113void CopyBit::freeRenderBuffers()
1114{
1115 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1116 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301117 //Since we are freeing buffer close the fence if it has a valid one.
1118 if(mRelFd[i] >= 0) {
1119 close(mRelFd[i]);
1120 mRelFd[i] = -1;
1121 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001122 free_buffer(mRenderBuffer[i]);
1123 mRenderBuffer[i] = NULL;
1124 }
1125 }
1126}
1127
1128private_handle_t * CopyBit::getCurrentRenderBuffer() {
1129 return mRenderBuffer[mCurRenderBufferIndex];
1130}
1131
1132void CopyBit::setReleaseFd(int fd) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301133 if(mRelFd[mCurRenderBufferIndex] >=0)
1134 close(mRelFd[mCurRenderBufferIndex]);
1135 mRelFd[mCurRenderBufferIndex] = dup(fd);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001136}
1137
Sushil Chauhandefd3522014-05-13 18:17:12 -07001138void CopyBit::setReleaseFdSync(int fd) {
1139 if (mRelFd[mCurRenderBufferIndex] >=0) {
1140 int ret = -1;
1141 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1142 if (ret < 0)
1143 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1144 __FUNCTION__, errno, strerror(errno));
1145 close(mRelFd[mCurRenderBufferIndex]);
1146 }
1147 mRelFd[mCurRenderBufferIndex] = dup(fd);
1148}
1149
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001150struct copybit_device_t* CopyBit::getCopyBitDevice() {
1151 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001152}
1153
Shalaj Jaina70b4352014-06-15 13:47:47 -07001154CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1155 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001156
1157 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1158 ctx->dpyAttr[dpy].yres,
1159 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001160 mAlignedWidth,
1161 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001162
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001163 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301164 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001165 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301166 mRelFd[i] = -1;
1167 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301168
1169 char value[PROPERTY_VALUE_MAX];
1170 property_get("debug.hwc.dynThreshold", value, "2");
1171 mDynThreshold = atof(value);
1172
Ramakant Singh21cec722014-03-07 19:11:45 +05301173 property_get("debug.sf.swaprect", value, "0");
1174 mSwapRectEnable = atoi(value) ? true:false ;
1175 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001176 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001177 if(copybit_open(module, &mEngine) < 0) {
1178 ALOGE("FATAL ERROR: copybit open failed.");
1179 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001180 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001181 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001182 }
1183}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001184
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001185CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001186{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001187 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001188 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001189 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001190 copybit_close(mEngine);
1191 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001192 }
1193}
Ramakant Singh21cec722014-03-07 19:11:45 +05301194CopyBit::LayerCache::LayerCache() {
1195 reset();
1196}
1197void CopyBit::LayerCache::reset() {
1198 memset(&hnd, 0, sizeof(hnd));
1199 layerCount = 0;
1200}
1201void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1202 hwc_display_contents_1_t *list, int dpy)
1203{
1204 layerCount = ctx->listStats[dpy].numAppLayers;
1205 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1206 hnd[i] = list->hwLayers[i].handle;
1207 }
1208}
1209
1210CopyBit::FbCache::FbCache() {
1211 reset();
1212}
1213void CopyBit::FbCache::reset() {
1214 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
1215 FbIndex =0;
1216}
1217
1218void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) {
1219 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1220 FbdirtyRect[FbIndex] = dirtyRect;
1221 FbIndex++;
1222}
1223
1224int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){
1225 int sameDirtyCount = 0;
1226 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
1227 if( FbdirtyRect[i] == dirtyRect)
1228 sameDirtyCount++;
1229 }
1230 return sameDirtyCount;
1231}
1232
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001233}; //namespace qhwc