blob: 364b15cfb0f4739ec3867186432b8e4e17ad27e2 [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
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530134bool CopyBit::isLayerChanging(hwc_display_contents_1_t *list, int k) {
135 if((mLayerCache.hnd[k] != list->hwLayers[k].handle) ||
136 (mLayerCache.displayFrame[k].left !=
137 list->hwLayers[k].displayFrame.left) ||
138 (mLayerCache.displayFrame[k].top !=
139 list->hwLayers[k].displayFrame.top) ||
140 (mLayerCache.displayFrame[k].right !=
141 list->hwLayers[k].displayFrame.right) ||
142 (mLayerCache.displayFrame[k].bottom !=
143 list->hwLayers[k].displayFrame.bottom)) {
144 return 1;
145 }
146 return 0;
147}
148
Ramakant Singh21cec722014-03-07 19:11:45 +0530149int CopyBit::getLayersChanging(hwc_context_t *ctx,
150 hwc_display_contents_1_t *list,
151 int dpy){
152
153 int changingLayerIndex = -1;
154 if(mLayerCache.layerCount != ctx->listStats[dpy].numAppLayers) {
155 mLayerCache.reset();
156 mFbCache.reset();
157 mLayerCache.updateCounts(ctx,list,dpy);
158 return -1;
159 }
160
161 int updatingLayerCount = 0;
162 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
163 //swap rect will kick in only for single updating layer
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530164 if(isLayerChanging(list, k)) {
Ramakant Singh21cec722014-03-07 19:11:45 +0530165 updatingLayerCount ++;
166 if(updatingLayerCount == 1)
167 changingLayerIndex = k;
168 }
169 }
170 //since we are using more than one framebuffers,we have to
171 //kick in swap rect only if we are getting continuous same
172 //dirty rect for same layer at least equal of number of
173 //framebuffers
174
175 if ( updatingLayerCount == 1 ) {
Saurabh Shah93c69052014-04-24 10:27:10 -0700176 hwc_rect_t dirtyRect = list->hwLayers[changingLayerIndex].displayFrame;
177#ifdef QCOM_BSP
178 dirtyRect = list->hwLayers[changingLayerIndex].dirtyRect;
179#endif
Ramakant Singh21cec722014-03-07 19:11:45 +0530180
181 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
182 //disable swap rect for overlapping visible layer(s)
183 hwc_rect_t displayFrame = list->hwLayers[k].displayFrame;
184 hwc_rect_t result = getIntersection(displayFrame,dirtyRect);
185 if((k != changingLayerIndex) && isValidRect(result)){
186 return -1;
187 }
188 }
189 mFbCache.insertAndUpdateFbCache(dirtyRect);
190 if(mFbCache.getUnchangedFbDRCount(dirtyRect) <
191 NUM_RENDER_BUFFERS)
192 changingLayerIndex = -1;
193 }else {
194 mFbCache.reset();
195 changingLayerIndex = -1;
196 }
197 mLayerCache.updateCounts(ctx,list,dpy);
198 return changingLayerIndex;
199}
200
201int CopyBit::checkDirtyRect(hwc_context_t *ctx,
202 hwc_display_contents_1_t *list,
203 int dpy) {
204
205 //dirty rect will enable only if
206 //1.Only single layer is updating.
207 //2.No overlapping
208 //3.No scaling
209 //4.No video layer
210 if(mSwapRectEnable == false)
211 return -1;
212 int changingLayerIndex = getLayersChanging(ctx, list, dpy);
213 //swap rect will kick in only for single updating layer
214 if(changingLayerIndex == -1){
215 return -1;
216 }
217 if(!needsScaling(&list->hwLayers[changingLayerIndex])){
218 private_handle_t *hnd =
219 (private_handle_t *)list->hwLayers[changingLayerIndex].handle;
220 if( hnd && !isYuvBuffer(hnd))
221 return changingLayerIndex;
222 }
223 return -1;
224}
225
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700226bool CopyBit::prepareOverlap(hwc_context_t *ctx,
227 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700228
229 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
230 ALOGE("%s: Invalid request", __FUNCTION__);
231 return false;
232 }
233
Saurabh Shah15455aa2015-01-28 13:54:48 -0800234 if (mEngine == NULL) {
235 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
236 return false;
237 }
238
239 if (!(validateParams(ctx, list))) {
240 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700241 return false;
242 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700243 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700244
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700245 // Allocate render buffers if they're not allocated
246 int alignW = 0, alignH = 0;
247 int finalW = 0, finalH = 0;
248 for (int i = 0; i < ptorInfo->count; i++) {
249 int ovlapIndex = ptorInfo->layerIndex[i];
250 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
251 // render buffer width will be the max of two layers
252 // Align Widht and height to 32, Mdp would be configured
253 // with Aligned overlap w/h
254 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
255 finalH += ALIGN((overlap.bottom - overlap.top), 32);
256 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700257 // Calculate the dest top, left will always be zero
258 ptorInfo->displayFrame[i].top = (finalH -
259 (ALIGN((overlap.bottom - overlap.top), 32)));
260 }
261 // calculate the right and bottom values
262 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
263 (overlap.right - overlap.left);
264 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
265 (overlap.bottom - overlap.top);
266 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700267
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700268 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700269 alignW, alignH);
270
271 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
272 // Overlap rect has changed, so free render buffers
273 freeRenderBuffers();
274 }
275
276 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
277
278 if (ret < 0) {
279 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
280 return false;
281 }
282
283 mAlignedWidth = alignW;
284 mAlignedHeight = alignH;
285 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
286 return true;
287}
288
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800289bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
290 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700291
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800292 if(mEngine == NULL) {
293 // No copybit device found - cannot use copybit
294 return false;
295 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530296
297 if(ctx->mThermalBurstMode) {
298 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
299 "Running in Thermal Burst mode",__FUNCTION__);
300 return false;
301 }
302
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800303 int compositionType = qdutils::QCCompositionType::
304 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700305
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800306 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
307 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700308 //GPU/CPU composition, don't change layer composition type
309 return true;
310 }
311
Naseer Ahmed45a99602012-07-31 19:15:24 -0700312 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800313 ALOGE("%s:Invalid Params", __FUNCTION__);
314 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700315 }
316
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800317 if(ctx->listStats[dpy].skipCount) {
318 //GPU will be anyways used
319 return false;
320 }
321
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700322 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700323 // Reached max layers supported by HWC.
324 return false;
325 }
326
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800327 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
328 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500329 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500330
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530331 // Following are MDP3 limitations for which we
332 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400333 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500334 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400335 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
336 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500337 int dst_h, dst_w, src_h, src_w;
338 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530339 if(ctx->copybitDrop[i]) {
340 continue;
341 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400342 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530343 if (layer->planeAlpha != 0xFF)
344 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530345 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500346
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700347 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530348 src_h = sourceCrop.right - sourceCrop.left;
349 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500350 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530351 src_h = sourceCrop.bottom - sourceCrop.top;
352 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500353 }
354 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
355 dst_w = layer->displayFrame.right - layer->displayFrame.left;
356
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530357 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
358 ALOGE("%s: wrong params for display screen_w=%d \
359 src_crop_width=%d screen_h=%d src_crop_height=%d",
360 __FUNCTION__, dst_w,src_w,dst_h,src_h);
361 return false;
362 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530363 dx = (float)dst_w/(float)src_w;
364 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530365
Terence Hampson6b0a4272013-11-06 16:04:51 -0500366 if (dx > MAX_SCALE_FACTOR || dx < MIN_SCALE_FACTOR)
367 return false;
368
369 if (dy > MAX_SCALE_FACTOR || dy < MIN_SCALE_FACTOR)
370 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400371 }
372 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500373
374 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530375 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
376 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400377 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700378 int ret = allocRenderBuffers(mAlignedWidth,
379 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700380 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500381 if (ret < 0) {
382 return false;
383 } else {
384 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
385 NUM_RENDER_BUFFERS;
386 }
387 }
388
Terence Hampsond0fd5792013-05-29 11:56:52 -0400389 // We cannot mix copybit layer with layers marked to be drawn on FB
390 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
391 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800392
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530393 mCopyBitDraw = false;
394 if (useCopybitForRGB &&
395 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
396 mCopyBitDraw = true;
397 // numAppLayers-1, as we iterate till 0th layer index
398 // Mark all layers to be drawn by copybit
399 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500400 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700401#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530402 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
403 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400404 list->hwLayers[i].compositionType = HWC_BLIT;
405 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700406#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400407 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700408 }
409 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530410
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700411 return true;
412}
413
Naseer Ahmed183939d2013-03-14 20:44:17 -0400414int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
415{
416 int ret = 0;
417 copybit_rect_t clear_rect = {rect.left, rect.top,
418 rect.right,
419 rect.bottom};
420
421 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700422 buf.w = ALIGN(getWidth(hnd),32);
423 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400424 buf.format = hnd->format;
425 buf.base = (void *)hnd->base;
426 buf.handle = (native_handle_t *)hnd;
427
428 copybit_device_t *copybit = mEngine;
429 ret = copybit->clear(copybit, &buf, &clear_rect);
430 return ret;
431}
432
Ramakant Singh0def28c2014-03-28 20:43:13 +0530433bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
434 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530435 int dpy, int *copybitFd) {
436 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700437 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530438 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
439 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530440
441 if(ctx->enableABC == false)
442 return false;
443
Ramakant Singh467759f2014-04-16 11:09:40 +0530444 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530445 return false;
446
447 layerCount = ctx->listStats[dpy].numAppLayers;
448 //bottom most layer should
449 //equal to FB
450 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
451 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
452 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
453 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
454 if(tmpLayer->transform ||
455 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
456 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
457 (needsScaling(tmpLayer) == true)) {
458 return false;
459 }else {
460 ctx->listStats[dpy].renderBufIndexforABC = 0;
461 }
462 }
463
Ramakant Singh467759f2014-04-16 11:09:40 +0530464 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
465 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530466 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530467
Ramakant Singhcc326612014-06-19 14:19:18 +0530468 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530469 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530470 //enable ABC only for non intersecting layers.
471 hwc_rect_t displayFrame =
472 list->hwLayers[abcRenderBufIdx].displayFrame;
473 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
474 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
475 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
476 if (isValidRect(result)) {
477 ctx->listStats[dpy].renderBufIndexforABC = -1;
478 return false;
479 }
480 }
481 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530482 private_handle_t *renderBuffer =
483 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
484 copybit_device_t *copybit = getCopyBitDevice();
485 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
486 copybit->set_sync(copybit,
487 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
488 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530489 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Ramakant Singh467759f2014-04-16 11:09:40 +0530490 int retVal = drawLayerUsingCopybit(ctx,
491 &(list->hwLayers[i]),renderBuffer, 0);
492 if(retVal < 0) {
493 ALOGE("%s : Copybit failed", __FUNCTION__);
494 }
495 }
496 // Get Release Fence FD of copybit for the App layer(s)
497 copybit->flush_get_fence(copybit, copybitFd);
498 close(list->hwLayers[abcRenderBufIdx].acquireFenceFd);
499 list->hwLayers[abcRenderBufIdx].acquireFenceFd = -1;
500 return true;
501 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530502 }
503 return false;
504}
505
506bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
507 int dpy, int32_t *fd) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800508 // draw layers marked for COPYBIT
509 int retVal = true;
510 int copybitLayerCount = 0;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400511 uint32_t last = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500512 LayerProp *layerProp = ctx->layerProp[dpy];
Terence Hampsonc67b0372013-10-09 11:32:21 -0400513 private_handle_t *renderBuffer;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800514
Ramakant Singh21cec722014-03-07 19:11:45 +0530515 if(mCopyBitDraw == false){
516 mFbCache.reset(); // there is no layer marked for copybit
517 return false ;
518 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530519
Ramakant Singh467759f2014-04-16 11:09:40 +0530520 if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) {
Ramakant Singh0def28c2014-03-28 20:43:13 +0530521 return true;
522 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800523 //render buffer
Ramakant Singhb4106a12014-10-07 18:06:56 +0530524 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
525 ctx->mMDP.version == qdutils::MDP_V3_0_5) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530526 last = (uint32_t)list->numHwLayers - 1;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400527 renderBuffer = (private_handle_t *)list->hwLayers[last].handle;
528 } else {
529 renderBuffer = getCurrentRenderBuffer();
530 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800531 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500532 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800533 return false;
534 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500535
Terence Hampson0124cc72013-04-18 23:45:56 -0700536 if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400537 //Wait for the previous frame to complete before rendering onto it
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530538 if(mRelFd[mCurRenderBufferIndex] >=0) {
539 sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
540 close(mRelFd[mCurRenderBufferIndex]);
541 mRelFd[mCurRenderBufferIndex] = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400542 }
Terence Hampson65fe4522013-10-17 17:40:03 -0400543 } else {
Terence Hampsonc67b0372013-10-09 11:32:21 -0400544 if(list->hwLayers[last].acquireFenceFd >=0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400545 copybit_device_t *copybit = getCopyBitDevice();
Terence Hampsonc67b0372013-10-09 11:32:21 -0400546 copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd);
Terence Hampson65fe4522013-10-17 17:40:03 -0400547 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700548 }
radhakrishna2f00c8f2013-10-21 16:49:21 +0530549
Ramakant Singh21cec722014-03-07 19:11:45 +0530550 mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530551 hwc_rect_t clearRegion = {0,0,0,0};
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +0530552 if (CBUtils::getuiClearRegion(list, clearRegion, layerProp,
553 mDirtyLayerIndex))
Ramakant Singh21cec722014-03-07 19:11:45 +0530554 clear(renderBuffer, clearRegion);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500555 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800556 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500557 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
558 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800559 continue;
560 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530561 if(ctx->copybitDrop[i]) {
562 continue;
563 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530564 //skip non updating layers
565 if((mDirtyLayerIndex != -1) && (mDirtyLayerIndex != i) )
Ramakant Singh762ae082013-11-28 18:45:34 +0530566 continue;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800567 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400568 if (list->hwLayers[i].acquireFenceFd != -1
569 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800570 // Wait for acquire Fence on the App buffers.
571 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
572 if(ret < 0) {
573 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
574 __FUNCTION__, errno, strerror(errno));
575 }
576 close(list->hwLayers[i].acquireFenceFd);
577 list->hwLayers[i].acquireFenceFd = -1;
578 }
579 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530580 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800581 copybitLayerCount++;
582 if(retVal < 0) {
583 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
584 }
585 }
586
587 if (copybitLayerCount) {
588 copybit_device_t *copybit = getCopyBitDevice();
589 // Async mode
590 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530591 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
592 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400593 list->hwLayers[last].acquireFenceFd >= 0) {
594 close(list->hwLayers[last].acquireFenceFd);
595 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400596 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800597 }
598 return true;
599}
600
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700601int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700602 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700603 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700604
605 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
606 ALOGE("%s: Invalid request", __FUNCTION__);
607 return fd;
608 }
609
610 private_handle_t *renderBuffer = getCurrentRenderBuffer();
611
612 if (!renderBuffer) {
613 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
614 return fd;
615 }
616
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530617 //Clear the transparent or left out region on the render buffer
618 hwc_rect_t clearRegion = {0,0,0,0};
619 LayerProp *layerProp = ctx->layerProp[0];
620 if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
621 clear(renderBuffer, clearRegion);
622
Sushil Chauhandefd3522014-05-13 18:17:12 -0700623 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700624 for(int j = 0; j < ptorInfo->count; j++) {
625 int ovlapIndex = ptorInfo->layerIndex[j];
626 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530627 if(j) {
628 /**
629 * It's possible that 2 PTOR layers might have overlapping.
630 * In such case, remove the intersection(again if peripheral)
631 * from the lower PTOR layer to avoid overlapping.
632 * If intersection is not on peripheral then compromise
633 * by reducing number of PTOR layers.
634 **/
635 int prevOvlapIndex = ptorInfo->layerIndex[0];
636 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
637 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
638 if(isValidRect(commonRect)) {
639 overlap = deductRect(overlap, commonRect);
640 }
641 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700642
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700643 // Draw overlapped content of layers on render buffer
644 for (int i = 0; i <= ovlapIndex; i++) {
645 hwc_layer_1_t *layer = &list->hwLayers[i];
646 if(!isValidRect(getIntersection(layer->displayFrame,
647 overlap))) {
648 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700649 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700650 if ((list->hwLayers[i].acquireFenceFd != -1)) {
651 // Wait for acquire fence on the App buffers.
652 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
653 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
654 __FUNCTION__, errno, strerror(errno));
655 }
656 close(list->hwLayers[i].acquireFenceFd);
657 list->hwLayers[i].acquireFenceFd = -1;
658 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530659 /*
660 * Find the intersection of layer display frame with PTOR layer
661 * with respect to screen co-ordinates
662 *
663 * Calculated the destination rect by transforming the overlapping
664 * region of layer display frame with respect to PTOR display frame
665 *
666 * Transform the destination rect on to render buffer
667 * */
668 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
669 destRect.left = destRect.left - overlap.left +
670 ptorInfo->displayFrame[j].left;
671 destRect.right = destRect.right- overlap.left +
672 ptorInfo->displayFrame[j].left;
673 destRect.top = destRect.top - overlap.top +
674 ptorInfo->displayFrame[j].top;
675 destRect.bottom = destRect.bottom - overlap.top +
676 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700677
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530678 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
679 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700680 copybitLayerCount++;
681 if(retVal < 0) {
682 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
683 copybitLayerCount = 0;
684 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700685 }
686 }
687
688 if (copybitLayerCount) {
689 copybit_device_t *copybit = getCopyBitDevice();
690 copybit->flush_get_fence(copybit, &fd);
691 }
692
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700693 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
694 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700695 return fd;
696}
697
698int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700699 private_handle_t *renderBuffer, hwc_rect_t overlap,
700 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700701{
702 hwc_context_t* ctx = (hwc_context_t*)(dev);
703 if (!ctx) {
704 ALOGE("%s: null context ", __FUNCTION__);
705 return -1;
706 }
707
708 private_handle_t *hnd = (private_handle_t *)layer->handle;
709 if (!hnd) {
710 ALOGE("%s: invalid handle", __FUNCTION__);
711 return -1;
712 }
713
714 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
715 if (!dstHandle) {
716 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
717 return -1;
718 }
719
720 // Set the Copybit Source
721 copybit_image_t src;
722 src.handle = (native_handle_t *)layer->handle;
723 src.w = hnd->width;
724 src.h = hnd->height;
725 src.base = (void *)hnd->base;
726 src.format = hnd->format;
727 src.horiz_padding = 0;
728 src.vert_padding = 0;
729
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700730
Sushil Chauhandefd3522014-05-13 18:17:12 -0700731 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700732 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700733 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700734 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
735 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700736
737 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700738 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
739 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700740
741 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700742 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
743 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700744
745 // Copybit dst
746 copybit_image_t dst;
747 dst.handle = (native_handle_t *)dstHandle;
748 dst.w = ALIGN(dstHandle->width, 32);
749 dst.h = dstHandle->height;
750 dst.base = (void *)dstHandle->base;
751 dst.format = dstHandle->format;
752
753 copybit_device_t *copybit = mEngine;
754
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700755 // Copybit region is the destRect
756 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
757 hwc_region_t region;
758 region.numRects = 1;
759 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700760 region_iterator copybitRegion(region);
761 int acquireFd = layer->acquireFenceFd;
762
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700763 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
764 renderBuffer->width);
765 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
766 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700767 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
768 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
769 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
770 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700771 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
772 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700773 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700774 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
775 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700776
777 if (err < 0)
778 ALOGE("%s: copybit stretch failed",__FUNCTION__);
779
780 return err;
781}
782
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700783int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800784 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700785{
786 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400787 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700788 if(!ctx) {
789 ALOGE("%s: null context ", __FUNCTION__);
790 return -1;
791 }
792
793 private_handle_t *hnd = (private_handle_t *)layer->handle;
794 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700795 if (layer->flags & HWC_COLOR_FILL) { // Color layer
796 return fillColorUsingCopybit(layer, renderBuffer);
797 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700798 ALOGE("%s: invalid handle", __FUNCTION__);
799 return -1;
800 }
801
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800802 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700803 if(!fbHandle) {
804 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700805 return -1;
806 }
807
808 // Set the copybit source:
809 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700810 src.w = getWidth(hnd);
811 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700812 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700813
814 // Handle R/B swap
815 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
816 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
817 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
818 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
819 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
820 }
821 }
822
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700823 src.base = (void *)hnd->base;
824 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700825 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700826 // Initialize vertical padding to zero for now,
827 // this needs to change to accomodate vertical stride
828 // if needed in the future
829 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700830
shuoy7c101f92013-08-26 14:48:57 +0800831 int layerTransform = layer->transform ;
832 // When flip and rotation(90) are present alter the flip,
833 // as GPU is doing the flip and rotation in opposite order
834 // to that of MDP3.0
835 // For 270 degrees, we get 90 + (H+V) which is same as doing
836 // flip first and then rotation (H+V) + 90
837 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
838 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
839 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
840 (layer->transform & HAL_TRANSFORM_ROT_90) &&
841 !(layer->transform == HAL_TRANSFORM_ROT_270)){
842 if(layer->transform & HAL_TRANSFORM_FLIP_H){
843 layerTransform ^= HAL_TRANSFORM_FLIP_H;
844 layerTransform |= HAL_TRANSFORM_FLIP_V;
845 }
846 if(layer->transform & HAL_TRANSFORM_FLIP_V){
847 layerTransform ^= HAL_TRANSFORM_FLIP_V;
848 layerTransform |= HAL_TRANSFORM_FLIP_H;
849 }
850 }
851 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700852 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700853 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700854 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
855 sourceCrop.right,
856 sourceCrop.bottom};
857
858 // Copybit destination rect
859 hwc_rect_t displayFrame = layer->displayFrame;
860 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
861 displayFrame.right,
862 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700863#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530864 //change src and dst with dirtyRect
865 if(mDirtyLayerIndex != -1) {
866 srcRect.l = layer->dirtyRect.left;
867 srcRect.t = layer->dirtyRect.top;
868 srcRect.r = layer->dirtyRect.right;
869 srcRect.b = layer->dirtyRect.bottom;
870 dstRect = srcRect;
871 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700872#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700873 // Copybit dst
874 copybit_image_t dst;
875 dst.w = ALIGN(fbHandle->width,32);
876 dst.h = fbHandle->height;
877 dst.format = fbHandle->format;
878 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800879 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700880
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800881 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700882
883 int32_t screen_w = displayFrame.right - displayFrame.left;
884 int32_t screen_h = displayFrame.bottom - displayFrame.top;
885 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
886 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
887
888 // Copybit dst
889 float copybitsMaxScale =
890 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
891 float copybitsMinScale =
892 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
893
Sushil Chauhandffbf432013-12-09 15:33:57 -0800894 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700895 //swap screen width and height
896 int tmp = screen_w;
897 screen_w = screen_h;
898 screen_h = tmp;
899 }
900 private_handle_t *tmpHnd = NULL;
901
902 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
903 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530904 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
905 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700906 return -1;
907 }
908
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530909 float dsdx = (float)screen_w/(float)src_crop_width;
910 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700911
912 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
913 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
914 if(dsdx > scaleLimitMax ||
915 dtdy > scaleLimitMax ||
916 dsdx < 1/scaleLimitMin ||
917 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400918 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700919 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
920 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700921 return -1;
922 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400923 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700924 if(dsdx > copybitsMaxScale ||
925 dtdy > copybitsMaxScale ||
926 dsdx < 1/copybitsMinScale ||
927 dtdy < 1/copybitsMinScale){
928 // The requested scale is out of the range the hardware
929 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400930 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700931 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
932 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
933 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
934 src_crop_width,src_crop_height);
935
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700936
937 int tmp_w = src_crop_width;
938 int tmp_h = src_crop_height;
939
940 if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530941 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
942 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700943 }else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){
Ramakant Singh80f36f22014-02-25 14:11:35 +0530944 // ceil the tmp_w and tmp_h value to maintain proper ratio
945 // b/w src and dst (should not cross the desired scale limit
946 // due to float -> int )
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530947 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
948 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700949 }
Terence Hampson663dfa72013-08-08 12:35:41 -0400950 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700951
Naseer Ahmed64b81212013-02-14 10:29:47 -0500952 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400953 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700954
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400955 // We do not want copybit to generate alpha values from nothing
956 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
957 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
958 format = HAL_PIXEL_FORMAT_RGBX_8888;
959 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800960 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700961 copybit_image_t tmp_dst;
962 copybit_rect_t tmp_rect;
963 tmp_dst.w = tmp_w;
964 tmp_dst.h = tmp_h;
965 tmp_dst.format = tmpHnd->format;
966 tmp_dst.handle = tmpHnd;
967 tmp_dst.horiz_padding = src.horiz_padding;
968 tmp_dst.vert_padding = src.vert_padding;
969 tmp_rect.l = 0;
970 tmp_rect.t = 0;
971 tmp_rect.r = tmp_dst.w;
972 tmp_rect.b = tmp_dst.h;
973 //create one clip region
974 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
975 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
976 region_iterator tmp_it(tmp_hwc_reg);
977 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700978 //TODO: once, we are able to read layer alpha, update this
979 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -0400980 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700981 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
982 &srcRect, &tmp_it);
983 if(err < 0){
984 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
985 __LINE__);
986 if(tmpHnd)
987 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700988 return err;
989 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400990 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400991 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -0400992 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400993 close(acquireFd);
994 acquireFd = -1;
995 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700996 // copy new src and src rect crop
997 src = tmp_dst;
998 srcRect = tmp_rect;
999 }
1000 }
1001 // Copybit region
1002 hwc_region_t region = layer->visibleRegionScreen;
1003 region_iterator copybitRegion(region);
1004
1005 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1006 renderBuffer->width);
1007 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1008 renderBuffer->height);
1009 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +08001010 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001011 //TODO: once, we are able to read layer alpha, update this
1012 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001013 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
1014 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001015 copybit->set_parameter(copybit, COPYBIT_DITHER,
1016 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1017 COPYBIT_ENABLE : COPYBIT_DISABLE);
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301018 copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ?
1019 COPYBIT_ENABLE : COPYBIT_DISABLE);
1020
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001021 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1022 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001023 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001024 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1025 &copybitRegion);
1026 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1027 COPYBIT_DISABLE);
1028
Terence Hampsonadf47302013-05-23 12:21:02 -04001029 if(tmpHnd) {
1030 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1031 int ret = -1, releaseFd;
1032 // we need to wait for the buffer before freeing
1033 copybit->flush_get_fence(copybit, &releaseFd);
1034 ret = sync_wait(releaseFd, 1000);
1035 if(ret < 0) {
1036 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1037 __FUNCTION__, errno, strerror(errno));
1038 }
1039 close(releaseFd);
1040 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001041 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001042 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001043
1044 if(err < 0)
1045 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001046 return err;
1047}
1048
Sushil Chauhan943797c2013-10-21 17:35:55 -07001049int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1050 private_handle_t *renderBuffer)
1051{
1052 if (!renderBuffer) {
1053 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1054 return -1;
1055 }
1056
1057 // Copybit dst
1058 copybit_image_t dst;
1059 dst.w = ALIGN(renderBuffer->width, 32);
1060 dst.h = renderBuffer->height;
1061 dst.format = renderBuffer->format;
1062 dst.base = (void *)renderBuffer->base;
1063 dst.handle = (native_handle_t *)renderBuffer;
1064
1065 // Copybit dst rect
1066 hwc_rect_t displayFrame = layer->displayFrame;
1067 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1068 displayFrame.right, displayFrame.bottom};
1069
1070 uint32_t color = layer->transform;
1071 copybit_device_t *copybit = mEngine;
1072 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1073 renderBuffer->width);
1074 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1075 renderBuffer->height);
1076 copybit->set_parameter(copybit, COPYBIT_DITHER,
1077 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1078 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001079 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001080 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1081 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1082 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1083 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1084 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1085 return res;
1086}
1087
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001088void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001089 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001090{
1091 hwc_rect_t displayFrame = layer->displayFrame;
1092
1093 width = displayFrame.right - displayFrame.left;
1094 height = displayFrame.bottom - displayFrame.top;
1095}
1096
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001097bool CopyBit::validateParams(hwc_context_t *ctx,
1098 const hwc_display_contents_1_t *list) {
1099 //Validate parameters
1100 if (!ctx) {
1101 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1102 return false;
1103 } else if (!list) {
1104 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1105 return false;
1106 }
1107 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001108}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001109
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001110
Naseer Ahmed64b81212013-02-14 10:29:47 -05001111int CopyBit::allocRenderBuffers(int w, int h, int f)
1112{
1113 int ret = 0;
1114 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1115 if (mRenderBuffer[i] == NULL) {
1116 ret = alloc_buffer(&mRenderBuffer[i],
1117 w, h, f,
1118 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
1119 }
1120 if(ret < 0) {
1121 freeRenderBuffers();
1122 break;
1123 }
1124 }
1125 return ret;
1126}
1127
1128void CopyBit::freeRenderBuffers()
1129{
1130 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1131 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301132 //Since we are freeing buffer close the fence if it has a valid one.
1133 if(mRelFd[i] >= 0) {
1134 close(mRelFd[i]);
1135 mRelFd[i] = -1;
1136 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001137 free_buffer(mRenderBuffer[i]);
1138 mRenderBuffer[i] = NULL;
1139 }
1140 }
1141}
1142
1143private_handle_t * CopyBit::getCurrentRenderBuffer() {
1144 return mRenderBuffer[mCurRenderBufferIndex];
1145}
1146
1147void CopyBit::setReleaseFd(int fd) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301148 if(mRelFd[mCurRenderBufferIndex] >=0)
1149 close(mRelFd[mCurRenderBufferIndex]);
1150 mRelFd[mCurRenderBufferIndex] = dup(fd);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001151}
1152
Sushil Chauhandefd3522014-05-13 18:17:12 -07001153void CopyBit::setReleaseFdSync(int fd) {
1154 if (mRelFd[mCurRenderBufferIndex] >=0) {
1155 int ret = -1;
1156 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1157 if (ret < 0)
1158 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1159 __FUNCTION__, errno, strerror(errno));
1160 close(mRelFd[mCurRenderBufferIndex]);
1161 }
1162 mRelFd[mCurRenderBufferIndex] = dup(fd);
1163}
1164
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001165struct copybit_device_t* CopyBit::getCopyBitDevice() {
1166 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001167}
1168
Shalaj Jaina70b4352014-06-15 13:47:47 -07001169CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1170 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001171
1172 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1173 ctx->dpyAttr[dpy].yres,
1174 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001175 mAlignedWidth,
1176 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001177
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001178 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301179 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001180 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301181 mRelFd[i] = -1;
1182 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301183
1184 char value[PROPERTY_VALUE_MAX];
1185 property_get("debug.hwc.dynThreshold", value, "2");
1186 mDynThreshold = atof(value);
1187
Ramakant Singh21cec722014-03-07 19:11:45 +05301188 property_get("debug.sf.swaprect", value, "0");
1189 mSwapRectEnable = atoi(value) ? true:false ;
1190 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001191 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001192 if(copybit_open(module, &mEngine) < 0) {
1193 ALOGE("FATAL ERROR: copybit open failed.");
1194 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001195 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001196 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001197 }
1198}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001199
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001200CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001201{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001202 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001203 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001204 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001205 copybit_close(mEngine);
1206 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001207 }
1208}
Ramakant Singh21cec722014-03-07 19:11:45 +05301209CopyBit::LayerCache::LayerCache() {
1210 reset();
1211}
1212void CopyBit::LayerCache::reset() {
1213 memset(&hnd, 0, sizeof(hnd));
1214 layerCount = 0;
1215}
1216void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1217 hwc_display_contents_1_t *list, int dpy)
1218{
1219 layerCount = ctx->listStats[dpy].numAppLayers;
1220 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1221 hnd[i] = list->hwLayers[i].handle;
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +05301222 displayFrame[i] = list->hwLayers[i].displayFrame;
Ramakant Singh21cec722014-03-07 19:11:45 +05301223 }
1224}
1225
1226CopyBit::FbCache::FbCache() {
1227 reset();
1228}
1229void CopyBit::FbCache::reset() {
1230 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
1231 FbIndex =0;
1232}
1233
1234void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) {
1235 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1236 FbdirtyRect[FbIndex] = dirtyRect;
1237 FbIndex++;
1238}
1239
1240int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){
1241 int sameDirtyCount = 0;
1242 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
1243 if( FbdirtyRect[i] == dirtyRect)
1244 sameDirtyCount++;
1245 }
1246 return sameDirtyCount;
1247}
1248
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001249}; //namespace qhwc