blob: 65482d7b8648069c2643d4cc639a3255bb40e672 [file] [log] [blame]
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Ramakant Singhd2875e12015-01-19 12:45:41 +05303 * Copyright (C) 2012-2015, 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
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530181 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--) {
182 //disable swap rect in case of scaling and video .
183 private_handle_t *hnd =(private_handle_t *)list->hwLayers[k].handle;
184 if(needsScaling(&list->hwLayers[k])||( hnd && isYuvBuffer(hnd))) {
185 mFbCache.reset();
186 return -1;
Ramakant Singh21cec722014-03-07 19:11:45 +0530187 }
188 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530189 if(mFbCache.getUnchangedFbDRCount(dirtyRect) <
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530190 NUM_RENDER_BUFFERS) {
191 mFbCache.insertAndUpdateFbCache(dirtyRect);
Ramakant Singh21cec722014-03-07 19:11:45 +0530192 changingLayerIndex = -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530193 }
194 } else {
Ramakant Singh21cec722014-03-07 19:11:45 +0530195 mFbCache.reset();
196 changingLayerIndex = -1;
197 }
198 mLayerCache.updateCounts(ctx,list,dpy);
199 return changingLayerIndex;
200}
201
202int CopyBit::checkDirtyRect(hwc_context_t *ctx,
203 hwc_display_contents_1_t *list,
204 int dpy) {
205
206 //dirty rect will enable only if
207 //1.Only single layer is updating.
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530208 //2.No scaling
209 //3.No video layer
Ramakant Singh21cec722014-03-07 19:11:45 +0530210 if(mSwapRectEnable == false)
211 return -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530212 return getLayersChanging(ctx, list, dpy);
Ramakant Singh21cec722014-03-07 19:11:45 +0530213}
214
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700215bool CopyBit::prepareOverlap(hwc_context_t *ctx,
216 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700217
218 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
219 ALOGE("%s: Invalid request", __FUNCTION__);
220 return false;
221 }
222
Saurabh Shah15455aa2015-01-28 13:54:48 -0800223 if (mEngine == NULL) {
224 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
225 return false;
226 }
227
228 if (!(validateParams(ctx, list))) {
229 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700230 return false;
231 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700232 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700233
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700234 // Allocate render buffers if they're not allocated
235 int alignW = 0, alignH = 0;
236 int finalW = 0, finalH = 0;
237 for (int i = 0; i < ptorInfo->count; i++) {
238 int ovlapIndex = ptorInfo->layerIndex[i];
239 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
240 // render buffer width will be the max of two layers
241 // Align Widht and height to 32, Mdp would be configured
242 // with Aligned overlap w/h
243 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
244 finalH += ALIGN((overlap.bottom - overlap.top), 32);
245 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700246 // Calculate the dest top, left will always be zero
247 ptorInfo->displayFrame[i].top = (finalH -
248 (ALIGN((overlap.bottom - overlap.top), 32)));
249 }
250 // calculate the right and bottom values
251 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
252 (overlap.right - overlap.left);
253 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
254 (overlap.bottom - overlap.top);
255 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700256
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700257 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700258 alignW, alignH);
259
260 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
261 // Overlap rect has changed, so free render buffers
262 freeRenderBuffers();
263 }
264
265 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
266
267 if (ret < 0) {
268 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
269 return false;
270 }
271
272 mAlignedWidth = alignW;
273 mAlignedHeight = alignH;
274 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
275 return true;
276}
277
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800278bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
279 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700280
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800281 if(mEngine == NULL) {
282 // No copybit device found - cannot use copybit
283 return false;
284 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530285
286 if(ctx->mThermalBurstMode) {
287 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
288 "Running in Thermal Burst mode",__FUNCTION__);
289 return false;
290 }
291
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800292 int compositionType = qdutils::QCCompositionType::
293 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700294
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800295 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
296 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700297 //GPU/CPU composition, don't change layer composition type
298 return true;
299 }
300
Naseer Ahmed45a99602012-07-31 19:15:24 -0700301 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800302 ALOGE("%s:Invalid Params", __FUNCTION__);
303 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700304 }
305
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800306 if(ctx->listStats[dpy].skipCount) {
307 //GPU will be anyways used
308 return false;
309 }
310
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700311 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700312 // Reached max layers supported by HWC.
313 return false;
314 }
315
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800316 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
317 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500318 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500319
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530320 // Following are MDP3 limitations for which we
321 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400322 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500323 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400324 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
325 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500326 int dst_h, dst_w, src_h, src_w;
327 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530328 if(ctx->copybitDrop[i]) {
329 continue;
330 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400331 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530332 if (layer->planeAlpha != 0xFF)
333 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530334 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500335
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700336 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530337 src_h = sourceCrop.right - sourceCrop.left;
338 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500339 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530340 src_h = sourceCrop.bottom - sourceCrop.top;
341 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500342 }
343 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
344 dst_w = layer->displayFrame.right - layer->displayFrame.left;
345
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530346 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
347 ALOGE("%s: wrong params for display screen_w=%d \
348 src_crop_width=%d screen_h=%d src_crop_height=%d",
349 __FUNCTION__, dst_w,src_w,dst_h,src_h);
350 return false;
351 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530352 dx = (float)dst_w/(float)src_w;
353 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530354
Terence Hampson6b0a4272013-11-06 16:04:51 -0500355 if (dx > MAX_SCALE_FACTOR || dx < MIN_SCALE_FACTOR)
356 return false;
357
358 if (dy > MAX_SCALE_FACTOR || dy < MIN_SCALE_FACTOR)
359 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400360 }
361 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500362
363 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530364 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
365 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400366 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700367 int ret = allocRenderBuffers(mAlignedWidth,
368 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700369 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500370 if (ret < 0) {
371 return false;
372 } else {
373 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
374 NUM_RENDER_BUFFERS;
375 }
376 }
377
Terence Hampsond0fd5792013-05-29 11:56:52 -0400378 // We cannot mix copybit layer with layers marked to be drawn on FB
379 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
380 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800381
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530382 mCopyBitDraw = false;
383 if (useCopybitForRGB &&
384 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
385 mCopyBitDraw = true;
386 // numAppLayers-1, as we iterate till 0th layer index
387 // Mark all layers to be drawn by copybit
388 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500389 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700390#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530391 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
392 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400393 list->hwLayers[i].compositionType = HWC_BLIT;
394 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700395#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400396 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700397 }
398 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530399
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700400 return true;
401}
402
Naseer Ahmed183939d2013-03-14 20:44:17 -0400403int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
404{
405 int ret = 0;
406 copybit_rect_t clear_rect = {rect.left, rect.top,
407 rect.right,
408 rect.bottom};
409
410 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700411 buf.w = ALIGN(getWidth(hnd),32);
412 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400413 buf.format = hnd->format;
414 buf.base = (void *)hnd->base;
415 buf.handle = (native_handle_t *)hnd;
416
417 copybit_device_t *copybit = mEngine;
418 ret = copybit->clear(copybit, &buf, &clear_rect);
419 return ret;
420}
421
Ramakant Singh0def28c2014-03-28 20:43:13 +0530422bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
423 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530424 int dpy, int *copybitFd) {
425 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700426 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530427 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
428 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530429
430 if(ctx->enableABC == false)
431 return false;
432
Ramakant Singh467759f2014-04-16 11:09:40 +0530433 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530434 return false;
435
436 layerCount = ctx->listStats[dpy].numAppLayers;
437 //bottom most layer should
438 //equal to FB
439 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
440 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
441 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
442 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
443 if(tmpLayer->transform ||
444 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
445 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
446 (needsScaling(tmpLayer) == true)) {
447 return false;
448 }else {
449 ctx->listStats[dpy].renderBufIndexforABC = 0;
450 }
451 }
452
Ramakant Singh467759f2014-04-16 11:09:40 +0530453 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
454 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530455 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530456
Ramakant Singhcc326612014-06-19 14:19:18 +0530457 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530458 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530459 //enable ABC only for non intersecting layers.
460 hwc_rect_t displayFrame =
461 list->hwLayers[abcRenderBufIdx].displayFrame;
462 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
463 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
464 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
465 if (isValidRect(result)) {
466 ctx->listStats[dpy].renderBufIndexforABC = -1;
467 return false;
468 }
469 }
470 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530471 private_handle_t *renderBuffer =
472 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
473 copybit_device_t *copybit = getCopyBitDevice();
474 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
475 copybit->set_sync(copybit,
476 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
477 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530478 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530479 mDirtyLayerIndex = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530480 int retVal = drawLayerUsingCopybit(ctx,
481 &(list->hwLayers[i]),renderBuffer, 0);
482 if(retVal < 0) {
483 ALOGE("%s : Copybit failed", __FUNCTION__);
484 }
485 }
486 // Get Release Fence FD of copybit for the App layer(s)
487 copybit->flush_get_fence(copybit, copybitFd);
Ramakant Singh52e1c0c2014-12-18 23:35:33 +0530488 close(list->hwLayers[last].acquireFenceFd);
489 list->hwLayers[last].acquireFenceFd = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530490 return true;
491 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530492 }
493 return false;
494}
495
496bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
497 int dpy, int32_t *fd) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800498 // draw layers marked for COPYBIT
499 int retVal = true;
500 int copybitLayerCount = 0;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400501 uint32_t last = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500502 LayerProp *layerProp = ctx->layerProp[dpy];
Terence Hampsonc67b0372013-10-09 11:32:21 -0400503 private_handle_t *renderBuffer;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800504
Ramakant Singh21cec722014-03-07 19:11:45 +0530505 if(mCopyBitDraw == false){
506 mFbCache.reset(); // there is no layer marked for copybit
507 return false ;
508 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530509
Ramakant Singh467759f2014-04-16 11:09:40 +0530510 if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) {
Ramakant Singh0def28c2014-03-28 20:43:13 +0530511 return true;
512 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800513 //render buffer
Ramakant Singhb4106a12014-10-07 18:06:56 +0530514 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
515 ctx->mMDP.version == qdutils::MDP_V3_0_5) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530516 last = (uint32_t)list->numHwLayers - 1;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400517 renderBuffer = (private_handle_t *)list->hwLayers[last].handle;
518 } else {
519 renderBuffer = getCurrentRenderBuffer();
520 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800521 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500522 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800523 return false;
524 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500525
Terence Hampson0124cc72013-04-18 23:45:56 -0700526 if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400527 //Wait for the previous frame to complete before rendering onto it
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530528 if(mRelFd[mCurRenderBufferIndex] >=0) {
529 sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
530 close(mRelFd[mCurRenderBufferIndex]);
531 mRelFd[mCurRenderBufferIndex] = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400532 }
Terence Hampson65fe4522013-10-17 17:40:03 -0400533 } else {
Terence Hampsonc67b0372013-10-09 11:32:21 -0400534 if(list->hwLayers[last].acquireFenceFd >=0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400535 copybit_device_t *copybit = getCopyBitDevice();
Terence Hampsonc67b0372013-10-09 11:32:21 -0400536 copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd);
Terence Hampson65fe4522013-10-17 17:40:03 -0400537 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700538 }
radhakrishna2f00c8f2013-10-21 16:49:21 +0530539
Ramakant Singh21cec722014-03-07 19:11:45 +0530540 mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy);
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530541 ALOGD_IF (DEBUG_COPYBIT, "%s:Dirty Layer Index: %d",
542 __FUNCTION__, mDirtyLayerIndex);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530543 hwc_rect_t clearRegion = {0,0,0,0};
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530544 mDirtyRect = list->hwLayers[last].displayFrame;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530545
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +0530546 if (CBUtils::getuiClearRegion(list, clearRegion, layerProp,
Ramakant Singh909bc2a2015-02-10 16:29:21 +0530547 mDirtyLayerIndex)) {
548 int clear_w = clearRegion.right - clearRegion.left;
549 int clear_h = clearRegion.bottom - clearRegion.top;
550 //mdp can't handle solid fill for one line
551 //making solid fill as full in this case
552 //disable swap rect if presents
553 if ((clear_w == 1) || (clear_h ==1)) {
554 clear(renderBuffer, mDirtyRect);
555 mDirtyLayerIndex = -1;
556 }else
557 clear(renderBuffer, clearRegion);
558 }
559 if (mDirtyLayerIndex != -1)
560 mDirtyRect = list->hwLayers[mDirtyLayerIndex].displayFrame;
561
Naseer Ahmed64b81212013-02-14 10:29:47 -0500562 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800563 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500564 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
565 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800566 continue;
567 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530568 if(ctx->copybitDrop[i]) {
569 continue;
570 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800571 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400572 if (list->hwLayers[i].acquireFenceFd != -1
573 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800574 // Wait for acquire Fence on the App buffers.
575 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
576 if(ret < 0) {
577 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
578 __FUNCTION__, errno, strerror(errno));
579 }
580 close(list->hwLayers[i].acquireFenceFd);
581 list->hwLayers[i].acquireFenceFd = -1;
582 }
583 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530584 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800585 copybitLayerCount++;
586 if(retVal < 0) {
587 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
588 }
589 }
590
591 if (copybitLayerCount) {
592 copybit_device_t *copybit = getCopyBitDevice();
593 // Async mode
594 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530595 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
596 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400597 list->hwLayers[last].acquireFenceFd >= 0) {
598 close(list->hwLayers[last].acquireFenceFd);
599 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400600 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800601 }
602 return true;
603}
604
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700605int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700606 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700607 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700608
609 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
610 ALOGE("%s: Invalid request", __FUNCTION__);
611 return fd;
612 }
613
614 private_handle_t *renderBuffer = getCurrentRenderBuffer();
615
616 if (!renderBuffer) {
617 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
618 return fd;
619 }
620
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530621 //Clear the transparent or left out region on the render buffer
622 hwc_rect_t clearRegion = {0,0,0,0};
623 LayerProp *layerProp = ctx->layerProp[0];
624 if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
625 clear(renderBuffer, clearRegion);
626
Sushil Chauhandefd3522014-05-13 18:17:12 -0700627 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700628 for(int j = 0; j < ptorInfo->count; j++) {
629 int ovlapIndex = ptorInfo->layerIndex[j];
630 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530631 if(j) {
632 /**
633 * It's possible that 2 PTOR layers might have overlapping.
634 * In such case, remove the intersection(again if peripheral)
635 * from the lower PTOR layer to avoid overlapping.
636 * If intersection is not on peripheral then compromise
637 * by reducing number of PTOR layers.
638 **/
639 int prevOvlapIndex = ptorInfo->layerIndex[0];
640 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
641 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
642 if(isValidRect(commonRect)) {
643 overlap = deductRect(overlap, commonRect);
644 }
645 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700646
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700647 // Draw overlapped content of layers on render buffer
648 for (int i = 0; i <= ovlapIndex; i++) {
649 hwc_layer_1_t *layer = &list->hwLayers[i];
650 if(!isValidRect(getIntersection(layer->displayFrame,
651 overlap))) {
652 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700653 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700654 if ((list->hwLayers[i].acquireFenceFd != -1)) {
655 // Wait for acquire fence on the App buffers.
656 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
657 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
658 __FUNCTION__, errno, strerror(errno));
659 }
660 close(list->hwLayers[i].acquireFenceFd);
661 list->hwLayers[i].acquireFenceFd = -1;
662 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530663 /*
664 * Find the intersection of layer display frame with PTOR layer
665 * with respect to screen co-ordinates
666 *
667 * Calculated the destination rect by transforming the overlapping
668 * region of layer display frame with respect to PTOR display frame
669 *
670 * Transform the destination rect on to render buffer
671 * */
672 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
673 destRect.left = destRect.left - overlap.left +
674 ptorInfo->displayFrame[j].left;
675 destRect.right = destRect.right- overlap.left +
676 ptorInfo->displayFrame[j].left;
677 destRect.top = destRect.top - overlap.top +
678 ptorInfo->displayFrame[j].top;
679 destRect.bottom = destRect.bottom - overlap.top +
680 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700681
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530682 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
683 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700684 copybitLayerCount++;
685 if(retVal < 0) {
686 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
687 copybitLayerCount = 0;
688 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700689 }
690 }
691
692 if (copybitLayerCount) {
693 copybit_device_t *copybit = getCopyBitDevice();
694 copybit->flush_get_fence(copybit, &fd);
695 }
696
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700697 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
698 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700699 return fd;
700}
701
702int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700703 private_handle_t *renderBuffer, hwc_rect_t overlap,
704 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700705{
706 hwc_context_t* ctx = (hwc_context_t*)(dev);
707 if (!ctx) {
708 ALOGE("%s: null context ", __FUNCTION__);
709 return -1;
710 }
711
712 private_handle_t *hnd = (private_handle_t *)layer->handle;
713 if (!hnd) {
714 ALOGE("%s: invalid handle", __FUNCTION__);
715 return -1;
716 }
717
718 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
719 if (!dstHandle) {
720 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
721 return -1;
722 }
723
724 // Set the Copybit Source
725 copybit_image_t src;
726 src.handle = (native_handle_t *)layer->handle;
727 src.w = hnd->width;
728 src.h = hnd->height;
729 src.base = (void *)hnd->base;
730 src.format = hnd->format;
731 src.horiz_padding = 0;
732 src.vert_padding = 0;
733
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700734
Sushil Chauhandefd3522014-05-13 18:17:12 -0700735 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700736 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700737 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700738 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
739 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700740
741 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700742 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
743 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700744
745 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700746 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
747 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700748
749 // Copybit dst
750 copybit_image_t dst;
751 dst.handle = (native_handle_t *)dstHandle;
752 dst.w = ALIGN(dstHandle->width, 32);
753 dst.h = dstHandle->height;
754 dst.base = (void *)dstHandle->base;
755 dst.format = dstHandle->format;
756
757 copybit_device_t *copybit = mEngine;
758
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700759 // Copybit region is the destRect
760 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
761 hwc_region_t region;
762 region.numRects = 1;
763 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700764 region_iterator copybitRegion(region);
765 int acquireFd = layer->acquireFenceFd;
766
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700767 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
768 renderBuffer->width);
769 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
770 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700771 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
772 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
773 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
774 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700775 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
776 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700777 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700778 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
779 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700780
781 if (err < 0)
782 ALOGE("%s: copybit stretch failed",__FUNCTION__);
783
784 return err;
785}
786
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700787int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800788 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700789{
790 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400791 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700792 if(!ctx) {
793 ALOGE("%s: null context ", __FUNCTION__);
794 return -1;
795 }
796
797 private_handle_t *hnd = (private_handle_t *)layer->handle;
798 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700799 if (layer->flags & HWC_COLOR_FILL) { // Color layer
800 return fillColorUsingCopybit(layer, renderBuffer);
801 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700802 ALOGE("%s: invalid handle", __FUNCTION__);
803 return -1;
804 }
805
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800806 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700807 if(!fbHandle) {
808 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700809 return -1;
810 }
811
812 // Set the copybit source:
813 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700814 src.w = getWidth(hnd);
815 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700816 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700817
818 // Handle R/B swap
819 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
820 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
821 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
822 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
823 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
824 }
825 }
826
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700827 src.base = (void *)hnd->base;
828 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700829 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700830 // Initialize vertical padding to zero for now,
831 // this needs to change to accomodate vertical stride
832 // if needed in the future
833 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700834
shuoy7c101f92013-08-26 14:48:57 +0800835 int layerTransform = layer->transform ;
836 // When flip and rotation(90) are present alter the flip,
837 // as GPU is doing the flip and rotation in opposite order
838 // to that of MDP3.0
839 // For 270 degrees, we get 90 + (H+V) which is same as doing
840 // flip first and then rotation (H+V) + 90
841 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
842 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
843 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
844 (layer->transform & HAL_TRANSFORM_ROT_90) &&
845 !(layer->transform == HAL_TRANSFORM_ROT_270)){
846 if(layer->transform & HAL_TRANSFORM_FLIP_H){
847 layerTransform ^= HAL_TRANSFORM_FLIP_H;
848 layerTransform |= HAL_TRANSFORM_FLIP_V;
849 }
850 if(layer->transform & HAL_TRANSFORM_FLIP_V){
851 layerTransform ^= HAL_TRANSFORM_FLIP_V;
852 layerTransform |= HAL_TRANSFORM_FLIP_H;
853 }
854 }
855 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700856 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700857 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700858 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
859 sourceCrop.right,
860 sourceCrop.bottom};
861
862 // Copybit destination rect
863 hwc_rect_t displayFrame = layer->displayFrame;
864 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
865 displayFrame.right,
866 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700867#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530868 //change src and dst with dirtyRect
869 if(mDirtyLayerIndex != -1) {
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530870 hwc_rect_t result = getIntersection(displayFrame, mDirtyRect);
871 if(!isValidRect(result))
872 return true;
873 dstRect.l = result.left;
874 dstRect.t = result.top;
875 dstRect.r = result.right;
876 dstRect.b = result.bottom;
877
878 srcRect.l += (result.left - displayFrame.left);
879 srcRect.t += (result.top - displayFrame.top);
880 srcRect.r -= (displayFrame.right - result.right);
881 srcRect.b -= (displayFrame.bottom - result.bottom);
Ramakant Singh21cec722014-03-07 19:11:45 +0530882 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700883#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700884 // Copybit dst
885 copybit_image_t dst;
886 dst.w = ALIGN(fbHandle->width,32);
887 dst.h = fbHandle->height;
888 dst.format = fbHandle->format;
889 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800890 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700891
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800892 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700893
894 int32_t screen_w = displayFrame.right - displayFrame.left;
895 int32_t screen_h = displayFrame.bottom - displayFrame.top;
896 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
897 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
898
899 // Copybit dst
900 float copybitsMaxScale =
901 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
902 float copybitsMinScale =
903 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
904
Sushil Chauhandffbf432013-12-09 15:33:57 -0800905 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700906 //swap screen width and height
907 int tmp = screen_w;
908 screen_w = screen_h;
909 screen_h = tmp;
910 }
911 private_handle_t *tmpHnd = NULL;
912
913 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
914 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530915 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
916 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700917 return -1;
918 }
919
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530920 float dsdx = (float)screen_w/(float)src_crop_width;
921 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700922
923 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
924 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
925 if(dsdx > scaleLimitMax ||
926 dtdy > scaleLimitMax ||
927 dsdx < 1/scaleLimitMin ||
928 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400929 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700930 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
931 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700932 return -1;
933 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400934 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700935 if(dsdx > copybitsMaxScale ||
936 dtdy > copybitsMaxScale ||
937 dsdx < 1/copybitsMinScale ||
938 dtdy < 1/copybitsMinScale){
939 // The requested scale is out of the range the hardware
940 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400941 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700942 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
943 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
944 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
945 src_crop_width,src_crop_height);
946
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700947
948 int tmp_w = src_crop_width;
949 int tmp_h = src_crop_height;
950
Ramakant Singhd2875e12015-01-19 12:45:41 +0530951 if (dsdx > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530952 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530953 if (dtdy > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530954 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530955 // ceil the tmp_w and tmp_h value to maintain proper ratio
956 // b/w src and dst (should not cross the desired scale limit
957 // due to float -> int )
958 if (dsdx < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530959 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530960 if (dtdy < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530961 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530962
Terence Hampson663dfa72013-08-08 12:35:41 -0400963 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700964
Naseer Ahmed64b81212013-02-14 10:29:47 -0500965 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400966 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700967
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400968 // We do not want copybit to generate alpha values from nothing
969 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
970 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
971 format = HAL_PIXEL_FORMAT_RGBX_8888;
972 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800973 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700974 copybit_image_t tmp_dst;
975 copybit_rect_t tmp_rect;
976 tmp_dst.w = tmp_w;
977 tmp_dst.h = tmp_h;
978 tmp_dst.format = tmpHnd->format;
979 tmp_dst.handle = tmpHnd;
980 tmp_dst.horiz_padding = src.horiz_padding;
981 tmp_dst.vert_padding = src.vert_padding;
982 tmp_rect.l = 0;
983 tmp_rect.t = 0;
984 tmp_rect.r = tmp_dst.w;
985 tmp_rect.b = tmp_dst.h;
986 //create one clip region
987 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
988 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
989 region_iterator tmp_it(tmp_hwc_reg);
990 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700991 //TODO: once, we are able to read layer alpha, update this
992 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -0400993 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700994 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
995 &srcRect, &tmp_it);
996 if(err < 0){
997 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
998 __LINE__);
999 if(tmpHnd)
1000 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001001 return err;
1002 }
Terence Hampsonadf47302013-05-23 12:21:02 -04001003 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001004 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -04001005 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001006 close(acquireFd);
1007 acquireFd = -1;
1008 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001009 // copy new src and src rect crop
1010 src = tmp_dst;
1011 srcRect = tmp_rect;
1012 }
1013 }
1014 // Copybit region
1015 hwc_region_t region = layer->visibleRegionScreen;
1016 region_iterator copybitRegion(region);
1017
1018 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1019 renderBuffer->width);
1020 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1021 renderBuffer->height);
1022 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +08001023 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001024 //TODO: once, we are able to read layer alpha, update this
1025 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001026 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
1027 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001028 copybit->set_parameter(copybit, COPYBIT_DITHER,
1029 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1030 COPYBIT_ENABLE : COPYBIT_DISABLE);
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301031 copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ?
1032 COPYBIT_ENABLE : COPYBIT_DISABLE);
1033
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001034 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1035 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001036 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001037 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1038 &copybitRegion);
1039 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1040 COPYBIT_DISABLE);
1041
Terence Hampsonadf47302013-05-23 12:21:02 -04001042 if(tmpHnd) {
1043 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1044 int ret = -1, releaseFd;
1045 // we need to wait for the buffer before freeing
1046 copybit->flush_get_fence(copybit, &releaseFd);
1047 ret = sync_wait(releaseFd, 1000);
1048 if(ret < 0) {
1049 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1050 __FUNCTION__, errno, strerror(errno));
1051 }
1052 close(releaseFd);
1053 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001054 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001055 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001056
1057 if(err < 0)
1058 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001059 return err;
1060}
1061
Sushil Chauhan943797c2013-10-21 17:35:55 -07001062int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1063 private_handle_t *renderBuffer)
1064{
1065 if (!renderBuffer) {
1066 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1067 return -1;
1068 }
1069
1070 // Copybit dst
1071 copybit_image_t dst;
1072 dst.w = ALIGN(renderBuffer->width, 32);
1073 dst.h = renderBuffer->height;
1074 dst.format = renderBuffer->format;
1075 dst.base = (void *)renderBuffer->base;
1076 dst.handle = (native_handle_t *)renderBuffer;
1077
1078 // Copybit dst rect
1079 hwc_rect_t displayFrame = layer->displayFrame;
1080 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1081 displayFrame.right, displayFrame.bottom};
1082
1083 uint32_t color = layer->transform;
1084 copybit_device_t *copybit = mEngine;
1085 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1086 renderBuffer->width);
1087 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1088 renderBuffer->height);
1089 copybit->set_parameter(copybit, COPYBIT_DITHER,
1090 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1091 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001092 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001093 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1094 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1095 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1096 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1097 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1098 return res;
1099}
1100
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001101void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001102 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001103{
1104 hwc_rect_t displayFrame = layer->displayFrame;
1105
1106 width = displayFrame.right - displayFrame.left;
1107 height = displayFrame.bottom - displayFrame.top;
1108}
1109
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001110bool CopyBit::validateParams(hwc_context_t *ctx,
1111 const hwc_display_contents_1_t *list) {
1112 //Validate parameters
1113 if (!ctx) {
1114 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1115 return false;
1116 } else if (!list) {
1117 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1118 return false;
1119 }
1120 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001121}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001122
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001123
Naseer Ahmed64b81212013-02-14 10:29:47 -05001124int CopyBit::allocRenderBuffers(int w, int h, int f)
1125{
1126 int ret = 0;
1127 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1128 if (mRenderBuffer[i] == NULL) {
1129 ret = alloc_buffer(&mRenderBuffer[i],
1130 w, h, f,
1131 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
1132 }
1133 if(ret < 0) {
1134 freeRenderBuffers();
1135 break;
1136 }
1137 }
1138 return ret;
1139}
1140
1141void CopyBit::freeRenderBuffers()
1142{
1143 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1144 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301145 //Since we are freeing buffer close the fence if it has a valid one.
1146 if(mRelFd[i] >= 0) {
1147 close(mRelFd[i]);
1148 mRelFd[i] = -1;
1149 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001150 free_buffer(mRenderBuffer[i]);
1151 mRenderBuffer[i] = NULL;
1152 }
1153 }
1154}
1155
1156private_handle_t * CopyBit::getCurrentRenderBuffer() {
1157 return mRenderBuffer[mCurRenderBufferIndex];
1158}
1159
1160void CopyBit::setReleaseFd(int fd) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301161 if(mRelFd[mCurRenderBufferIndex] >=0)
1162 close(mRelFd[mCurRenderBufferIndex]);
1163 mRelFd[mCurRenderBufferIndex] = dup(fd);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001164}
1165
Sushil Chauhandefd3522014-05-13 18:17:12 -07001166void CopyBit::setReleaseFdSync(int fd) {
1167 if (mRelFd[mCurRenderBufferIndex] >=0) {
1168 int ret = -1;
1169 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1170 if (ret < 0)
1171 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1172 __FUNCTION__, errno, strerror(errno));
1173 close(mRelFd[mCurRenderBufferIndex]);
1174 }
1175 mRelFd[mCurRenderBufferIndex] = dup(fd);
1176}
1177
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001178struct copybit_device_t* CopyBit::getCopyBitDevice() {
1179 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001180}
1181
Shalaj Jaina70b4352014-06-15 13:47:47 -07001182CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1183 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001184
1185 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1186 ctx->dpyAttr[dpy].yres,
1187 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001188 mAlignedWidth,
1189 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001190
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001191 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301192 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001193 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301194 mRelFd[i] = -1;
1195 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301196
1197 char value[PROPERTY_VALUE_MAX];
1198 property_get("debug.hwc.dynThreshold", value, "2");
1199 mDynThreshold = atof(value);
1200
Ramakant Singh21cec722014-03-07 19:11:45 +05301201 property_get("debug.sf.swaprect", value, "0");
1202 mSwapRectEnable = atoi(value) ? true:false ;
1203 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001204 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001205 if(copybit_open(module, &mEngine) < 0) {
1206 ALOGE("FATAL ERROR: copybit open failed.");
1207 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001208 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001209 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001210 }
1211}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001212
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001213CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001214{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001215 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001216 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001217 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001218 copybit_close(mEngine);
1219 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001220 }
1221}
Ramakant Singh21cec722014-03-07 19:11:45 +05301222CopyBit::LayerCache::LayerCache() {
1223 reset();
1224}
1225void CopyBit::LayerCache::reset() {
1226 memset(&hnd, 0, sizeof(hnd));
1227 layerCount = 0;
1228}
1229void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1230 hwc_display_contents_1_t *list, int dpy)
1231{
1232 layerCount = ctx->listStats[dpy].numAppLayers;
1233 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1234 hnd[i] = list->hwLayers[i].handle;
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +05301235 displayFrame[i] = list->hwLayers[i].displayFrame;
Ramakant Singh21cec722014-03-07 19:11:45 +05301236 }
1237}
1238
1239CopyBit::FbCache::FbCache() {
1240 reset();
1241}
1242void CopyBit::FbCache::reset() {
1243 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
1244 FbIndex =0;
1245}
1246
1247void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) {
1248 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1249 FbdirtyRect[FbIndex] = dirtyRect;
1250 FbIndex++;
1251}
1252
1253int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){
1254 int sameDirtyCount = 0;
1255 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
1256 if( FbdirtyRect[i] == dirtyRect)
1257 sameDirtyCount++;
1258 }
1259 return sameDirtyCount;
1260}
1261
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001262}; //namespace qhwc