blob: 7bb5f60fc1d68d9f6273a3658ed77fa996d05903 [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 Reddi9dab73a2015-02-24 16:15:53 +0530134bool CopyBit::isLayerChanging(hwc_context_t *ctx,
135 hwc_display_contents_1_t *list, int k) {
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530136 if((mLayerCache.hnd[k] != list->hwLayers[k].handle) ||
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530137 (mLayerCache.drop[k] != ctx->copybitDrop[k]) ||
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530138 (mLayerCache.displayFrame[k].left !=
139 list->hwLayers[k].displayFrame.left) ||
140 (mLayerCache.displayFrame[k].top !=
141 list->hwLayers[k].displayFrame.top) ||
142 (mLayerCache.displayFrame[k].right !=
143 list->hwLayers[k].displayFrame.right) ||
144 (mLayerCache.displayFrame[k].bottom !=
145 list->hwLayers[k].displayFrame.bottom)) {
146 return 1;
147 }
148 return 0;
149}
150
Ramakant Singh21cec722014-03-07 19:11:45 +0530151int CopyBit::getLayersChanging(hwc_context_t *ctx,
152 hwc_display_contents_1_t *list,
153 int dpy){
154
155 int changingLayerIndex = -1;
156 if(mLayerCache.layerCount != ctx->listStats[dpy].numAppLayers) {
157 mLayerCache.reset();
158 mFbCache.reset();
159 mLayerCache.updateCounts(ctx,list,dpy);
160 return -1;
161 }
162
163 int updatingLayerCount = 0;
164 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
165 //swap rect will kick in only for single updating layer
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530166 if(isLayerChanging(ctx, list, k)) {
Ramakant Singh21cec722014-03-07 19:11:45 +0530167 updatingLayerCount ++;
168 if(updatingLayerCount == 1)
169 changingLayerIndex = k;
170 }
171 }
172 //since we are using more than one framebuffers,we have to
173 //kick in swap rect only if we are getting continuous same
174 //dirty rect for same layer at least equal of number of
175 //framebuffers
176
177 if ( updatingLayerCount == 1 ) {
Saurabh Shah93c69052014-04-24 10:27:10 -0700178 hwc_rect_t dirtyRect = list->hwLayers[changingLayerIndex].displayFrame;
179#ifdef QCOM_BSP
180 dirtyRect = list->hwLayers[changingLayerIndex].dirtyRect;
181#endif
Ramakant Singh21cec722014-03-07 19:11:45 +0530182
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530183 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--) {
184 //disable swap rect in case of scaling and video .
185 private_handle_t *hnd =(private_handle_t *)list->hwLayers[k].handle;
186 if(needsScaling(&list->hwLayers[k])||( hnd && isYuvBuffer(hnd))) {
187 mFbCache.reset();
188 return -1;
Ramakant Singh21cec722014-03-07 19:11:45 +0530189 }
190 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530191 if(mFbCache.getUnchangedFbDRCount(dirtyRect) <
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530192 NUM_RENDER_BUFFERS) {
193 mFbCache.insertAndUpdateFbCache(dirtyRect);
Ramakant Singh21cec722014-03-07 19:11:45 +0530194 changingLayerIndex = -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530195 }
196 } else {
Ramakant Singh21cec722014-03-07 19:11:45 +0530197 mFbCache.reset();
198 changingLayerIndex = -1;
199 }
200 mLayerCache.updateCounts(ctx,list,dpy);
201 return changingLayerIndex;
202}
203
204int CopyBit::checkDirtyRect(hwc_context_t *ctx,
205 hwc_display_contents_1_t *list,
206 int dpy) {
207
208 //dirty rect will enable only if
209 //1.Only single layer is updating.
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530210 //2.No scaling
211 //3.No video layer
Ramakant Singh21cec722014-03-07 19:11:45 +0530212 if(mSwapRectEnable == false)
213 return -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530214 return getLayersChanging(ctx, list, dpy);
Ramakant Singh21cec722014-03-07 19:11:45 +0530215}
216
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700217bool CopyBit::prepareOverlap(hwc_context_t *ctx,
218 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700219
220 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
221 ALOGE("%s: Invalid request", __FUNCTION__);
222 return false;
223 }
224
Saurabh Shah15455aa2015-01-28 13:54:48 -0800225 if (mEngine == NULL) {
226 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
227 return false;
228 }
229
230 if (!(validateParams(ctx, list))) {
231 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700232 return false;
233 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700234 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700235
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700236 // Allocate render buffers if they're not allocated
237 int alignW = 0, alignH = 0;
238 int finalW = 0, finalH = 0;
239 for (int i = 0; i < ptorInfo->count; i++) {
240 int ovlapIndex = ptorInfo->layerIndex[i];
241 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
242 // render buffer width will be the max of two layers
243 // Align Widht and height to 32, Mdp would be configured
244 // with Aligned overlap w/h
245 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
246 finalH += ALIGN((overlap.bottom - overlap.top), 32);
247 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700248 // Calculate the dest top, left will always be zero
249 ptorInfo->displayFrame[i].top = (finalH -
250 (ALIGN((overlap.bottom - overlap.top), 32)));
251 }
252 // calculate the right and bottom values
253 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
254 (overlap.right - overlap.left);
255 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
256 (overlap.bottom - overlap.top);
257 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700258
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700259 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700260 alignW, alignH);
261
262 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
263 // Overlap rect has changed, so free render buffers
264 freeRenderBuffers();
265 }
266
267 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
268
269 if (ret < 0) {
270 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
271 return false;
272 }
273
274 mAlignedWidth = alignW;
275 mAlignedHeight = alignH;
276 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
277 return true;
278}
279
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800280bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
281 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700282
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800283 if(mEngine == NULL) {
284 // No copybit device found - cannot use copybit
285 return false;
286 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530287
288 if(ctx->mThermalBurstMode) {
289 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
290 "Running in Thermal Burst mode",__FUNCTION__);
291 return false;
292 }
293
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800294 int compositionType = qdutils::QCCompositionType::
295 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700296
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800297 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
298 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700299 //GPU/CPU composition, don't change layer composition type
300 return true;
301 }
302
Naseer Ahmed45a99602012-07-31 19:15:24 -0700303 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800304 ALOGE("%s:Invalid Params", __FUNCTION__);
305 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700306 }
307
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800308 if(ctx->listStats[dpy].skipCount) {
309 //GPU will be anyways used
310 return false;
311 }
312
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700313 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700314 // Reached max layers supported by HWC.
315 return false;
316 }
317
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800318 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
319 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500320 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500321
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530322 // Following are MDP3 limitations for which we
323 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400324 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500325 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400326 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
327 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500328 int dst_h, dst_w, src_h, src_w;
329 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530330 if(ctx->copybitDrop[i]) {
331 continue;
332 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400333 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530334 if (layer->planeAlpha != 0xFF)
335 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530336 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500337
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700338 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530339 src_h = sourceCrop.right - sourceCrop.left;
340 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500341 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530342 src_h = sourceCrop.bottom - sourceCrop.top;
343 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500344 }
345 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
346 dst_w = layer->displayFrame.right - layer->displayFrame.left;
347
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530348 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
349 ALOGE("%s: wrong params for display screen_w=%d \
350 src_crop_width=%d screen_h=%d src_crop_height=%d",
351 __FUNCTION__, dst_w,src_w,dst_h,src_h);
352 return false;
353 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530354 dx = (float)dst_w/(float)src_w;
355 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530356
Ramakant Singhd5b369f2014-12-09 23:03:43 +0530357 float scale_factor_max = MAX_SCALE_FACTOR;
358 float scale_factor_min = MIN_SCALE_FACTOR;
359
360 if (isAlphaPresent(layer)) {
361 scale_factor_max = MAX_SCALE_FACTOR/4;
362 scale_factor_min = MIN_SCALE_FACTOR*4;
363 }
364
365 if (dx > scale_factor_max || dx < scale_factor_min)
Terence Hampson6b0a4272013-11-06 16:04:51 -0500366 return false;
367
Ramakant Singhd5b369f2014-12-09 23:03:43 +0530368 if (dy > scale_factor_max || dy < scale_factor_min)
Terence Hampson6b0a4272013-11-06 16:04:51 -0500369 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400370 }
371 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500372
373 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530374 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
375 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400376 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700377 int ret = allocRenderBuffers(mAlignedWidth,
378 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700379 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500380 if (ret < 0) {
381 return false;
382 } else {
383 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
384 NUM_RENDER_BUFFERS;
385 }
386 }
387
Terence Hampsond0fd5792013-05-29 11:56:52 -0400388 // We cannot mix copybit layer with layers marked to be drawn on FB
389 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
390 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800391
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530392 mCopyBitDraw = false;
393 if (useCopybitForRGB &&
394 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
395 mCopyBitDraw = true;
396 // numAppLayers-1, as we iterate till 0th layer index
397 // Mark all layers to be drawn by copybit
398 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500399 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700400#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530401 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
402 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400403 list->hwLayers[i].compositionType = HWC_BLIT;
404 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700405#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400406 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700407 }
408 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530409
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700410 return true;
411}
412
Naseer Ahmed183939d2013-03-14 20:44:17 -0400413int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
414{
415 int ret = 0;
416 copybit_rect_t clear_rect = {rect.left, rect.top,
417 rect.right,
418 rect.bottom};
419
420 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700421 buf.w = ALIGN(getWidth(hnd),32);
422 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400423 buf.format = hnd->format;
424 buf.base = (void *)hnd->base;
425 buf.handle = (native_handle_t *)hnd;
426
427 copybit_device_t *copybit = mEngine;
428 ret = copybit->clear(copybit, &buf, &clear_rect);
429 return ret;
430}
431
Ramakant Singh0def28c2014-03-28 20:43:13 +0530432bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
433 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530434 int dpy, int *copybitFd) {
435 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700436 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530437 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
438 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530439
440 if(ctx->enableABC == false)
441 return false;
442
Ramakant Singh467759f2014-04-16 11:09:40 +0530443 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530444 return false;
445
446 layerCount = ctx->listStats[dpy].numAppLayers;
447 //bottom most layer should
448 //equal to FB
449 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
450 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
451 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
452 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
453 if(tmpLayer->transform ||
454 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
455 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
456 (needsScaling(tmpLayer) == true)) {
457 return false;
458 }else {
459 ctx->listStats[dpy].renderBufIndexforABC = 0;
460 }
461 }
462
Ramakant Singh467759f2014-04-16 11:09:40 +0530463 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
464 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530465 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530466
Ramakant Singhcc326612014-06-19 14:19:18 +0530467 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530468 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530469 //enable ABC only for non intersecting layers.
470 hwc_rect_t displayFrame =
471 list->hwLayers[abcRenderBufIdx].displayFrame;
472 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
473 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
474 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
475 if (isValidRect(result)) {
476 ctx->listStats[dpy].renderBufIndexforABC = -1;
477 return false;
478 }
479 }
480 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530481 private_handle_t *renderBuffer =
482 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
483 copybit_device_t *copybit = getCopyBitDevice();
484 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
485 copybit->set_sync(copybit,
486 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
487 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530488 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530489 mDirtyLayerIndex = -1;
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);
Ramakant Singh52e1c0c2014-12-18 23:35:33 +0530498 close(list->hwLayers[last].acquireFenceFd);
499 list->hwLayers[last].acquireFenceFd = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530500 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);
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530551 ALOGD_IF (DEBUG_COPYBIT, "%s:Dirty Layer Index: %d",
552 __FUNCTION__, mDirtyLayerIndex);
Ramakant Singh75b427c2014-12-08 17:09:31 +0530553 hwc_rect_t clearRegion = {0,0,0,0};
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530554 mDirtyRect = list->hwLayers[last].displayFrame;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530555
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +0530556 if (CBUtils::getuiClearRegion(list, clearRegion, layerProp,
Ramakant Singh909bc2a2015-02-10 16:29:21 +0530557 mDirtyLayerIndex)) {
558 int clear_w = clearRegion.right - clearRegion.left;
559 int clear_h = clearRegion.bottom - clearRegion.top;
560 //mdp can't handle solid fill for one line
561 //making solid fill as full in this case
562 //disable swap rect if presents
563 if ((clear_w == 1) || (clear_h ==1)) {
564 clear(renderBuffer, mDirtyRect);
565 mDirtyLayerIndex = -1;
566 }else
567 clear(renderBuffer, clearRegion);
568 }
569 if (mDirtyLayerIndex != -1)
570 mDirtyRect = list->hwLayers[mDirtyLayerIndex].displayFrame;
571
Naseer Ahmed64b81212013-02-14 10:29:47 -0500572 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800573 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500574 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
575 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800576 continue;
577 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530578 if(ctx->copybitDrop[i]) {
579 continue;
580 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800581 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400582 if (list->hwLayers[i].acquireFenceFd != -1
583 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800584 // Wait for acquire Fence on the App buffers.
585 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
586 if(ret < 0) {
587 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
588 __FUNCTION__, errno, strerror(errno));
589 }
590 close(list->hwLayers[i].acquireFenceFd);
591 list->hwLayers[i].acquireFenceFd = -1;
592 }
593 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530594 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800595 copybitLayerCount++;
596 if(retVal < 0) {
597 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
598 }
599 }
600
601 if (copybitLayerCount) {
602 copybit_device_t *copybit = getCopyBitDevice();
603 // Async mode
604 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530605 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
606 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400607 list->hwLayers[last].acquireFenceFd >= 0) {
608 close(list->hwLayers[last].acquireFenceFd);
609 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400610 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800611 }
612 return true;
613}
614
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700615int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700616 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700617 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700618
619 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
620 ALOGE("%s: Invalid request", __FUNCTION__);
621 return fd;
622 }
623
624 private_handle_t *renderBuffer = getCurrentRenderBuffer();
625
626 if (!renderBuffer) {
627 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
628 return fd;
629 }
630
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530631 //Clear the transparent or left out region on the render buffer
632 hwc_rect_t clearRegion = {0,0,0,0};
633 LayerProp *layerProp = ctx->layerProp[0];
634 if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
635 clear(renderBuffer, clearRegion);
636
Sushil Chauhandefd3522014-05-13 18:17:12 -0700637 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700638 for(int j = 0; j < ptorInfo->count; j++) {
639 int ovlapIndex = ptorInfo->layerIndex[j];
640 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530641 if(j) {
642 /**
643 * It's possible that 2 PTOR layers might have overlapping.
644 * In such case, remove the intersection(again if peripheral)
645 * from the lower PTOR layer to avoid overlapping.
646 * If intersection is not on peripheral then compromise
647 * by reducing number of PTOR layers.
648 **/
649 int prevOvlapIndex = ptorInfo->layerIndex[0];
650 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
651 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
652 if(isValidRect(commonRect)) {
653 overlap = deductRect(overlap, commonRect);
654 }
655 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700656
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700657 // Draw overlapped content of layers on render buffer
658 for (int i = 0; i <= ovlapIndex; i++) {
659 hwc_layer_1_t *layer = &list->hwLayers[i];
660 if(!isValidRect(getIntersection(layer->displayFrame,
661 overlap))) {
662 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700663 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700664 if ((list->hwLayers[i].acquireFenceFd != -1)) {
665 // Wait for acquire fence on the App buffers.
666 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
667 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
668 __FUNCTION__, errno, strerror(errno));
669 }
670 close(list->hwLayers[i].acquireFenceFd);
671 list->hwLayers[i].acquireFenceFd = -1;
672 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530673 /*
674 * Find the intersection of layer display frame with PTOR layer
675 * with respect to screen co-ordinates
676 *
677 * Calculated the destination rect by transforming the overlapping
678 * region of layer display frame with respect to PTOR display frame
679 *
680 * Transform the destination rect on to render buffer
681 * */
682 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
683 destRect.left = destRect.left - overlap.left +
684 ptorInfo->displayFrame[j].left;
685 destRect.right = destRect.right- overlap.left +
686 ptorInfo->displayFrame[j].left;
687 destRect.top = destRect.top - overlap.top +
688 ptorInfo->displayFrame[j].top;
689 destRect.bottom = destRect.bottom - overlap.top +
690 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700691
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530692 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
693 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700694 copybitLayerCount++;
695 if(retVal < 0) {
696 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
697 copybitLayerCount = 0;
698 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700699 }
700 }
701
702 if (copybitLayerCount) {
703 copybit_device_t *copybit = getCopyBitDevice();
704 copybit->flush_get_fence(copybit, &fd);
705 }
706
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700707 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
708 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700709 return fd;
710}
711
712int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700713 private_handle_t *renderBuffer, hwc_rect_t overlap,
714 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700715{
716 hwc_context_t* ctx = (hwc_context_t*)(dev);
717 if (!ctx) {
718 ALOGE("%s: null context ", __FUNCTION__);
719 return -1;
720 }
721
722 private_handle_t *hnd = (private_handle_t *)layer->handle;
723 if (!hnd) {
724 ALOGE("%s: invalid handle", __FUNCTION__);
725 return -1;
726 }
727
728 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
729 if (!dstHandle) {
730 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
731 return -1;
732 }
733
734 // Set the Copybit Source
735 copybit_image_t src;
736 src.handle = (native_handle_t *)layer->handle;
737 src.w = hnd->width;
738 src.h = hnd->height;
739 src.base = (void *)hnd->base;
740 src.format = hnd->format;
741 src.horiz_padding = 0;
742 src.vert_padding = 0;
743
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700744
Sushil Chauhandefd3522014-05-13 18:17:12 -0700745 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700746 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700747 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700748 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
749 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700750
751 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700752 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
753 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700754
755 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700756 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
757 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700758
759 // Copybit dst
760 copybit_image_t dst;
761 dst.handle = (native_handle_t *)dstHandle;
762 dst.w = ALIGN(dstHandle->width, 32);
763 dst.h = dstHandle->height;
764 dst.base = (void *)dstHandle->base;
765 dst.format = dstHandle->format;
766
767 copybit_device_t *copybit = mEngine;
768
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700769 // Copybit region is the destRect
770 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
771 hwc_region_t region;
772 region.numRects = 1;
773 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700774 region_iterator copybitRegion(region);
775 int acquireFd = layer->acquireFenceFd;
776
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700777 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
778 renderBuffer->width);
779 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
780 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700781 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
782 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
783 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
784 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700785 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
786 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700787 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700788 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
789 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700790
791 if (err < 0)
792 ALOGE("%s: copybit stretch failed",__FUNCTION__);
793
794 return err;
795}
796
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700797int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800798 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700799{
800 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400801 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700802 if(!ctx) {
803 ALOGE("%s: null context ", __FUNCTION__);
804 return -1;
805 }
806
807 private_handle_t *hnd = (private_handle_t *)layer->handle;
808 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700809 if (layer->flags & HWC_COLOR_FILL) { // Color layer
810 return fillColorUsingCopybit(layer, renderBuffer);
811 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700812 ALOGE("%s: invalid handle", __FUNCTION__);
813 return -1;
814 }
815
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800816 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700817 if(!fbHandle) {
818 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700819 return -1;
820 }
Ramakant Singh140965d2015-01-08 23:45:04 +0530821 uint32_t dynamic_fps = 0;
822#ifdef DYNAMIC_FPS
823 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
824 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
825 dynamic_fps = roundOff(mdata->refreshrate);
826 }
827#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700828 // Set the copybit source:
829 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700830 src.w = getWidth(hnd);
831 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700832 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700833
834 // Handle R/B swap
835 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
836 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
837 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
838 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
839 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
840 }
841 }
842
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700843 src.base = (void *)hnd->base;
844 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700845 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700846 // Initialize vertical padding to zero for now,
847 // this needs to change to accomodate vertical stride
848 // if needed in the future
849 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700850
shuoy7c101f92013-08-26 14:48:57 +0800851 int layerTransform = layer->transform ;
852 // When flip and rotation(90) are present alter the flip,
853 // as GPU is doing the flip and rotation in opposite order
854 // to that of MDP3.0
855 // For 270 degrees, we get 90 + (H+V) which is same as doing
856 // flip first and then rotation (H+V) + 90
857 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
858 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
859 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
860 (layer->transform & HAL_TRANSFORM_ROT_90) &&
861 !(layer->transform == HAL_TRANSFORM_ROT_270)){
862 if(layer->transform & HAL_TRANSFORM_FLIP_H){
863 layerTransform ^= HAL_TRANSFORM_FLIP_H;
864 layerTransform |= HAL_TRANSFORM_FLIP_V;
865 }
866 if(layer->transform & HAL_TRANSFORM_FLIP_V){
867 layerTransform ^= HAL_TRANSFORM_FLIP_V;
868 layerTransform |= HAL_TRANSFORM_FLIP_H;
869 }
870 }
871 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700872 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700873 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700874 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
875 sourceCrop.right,
876 sourceCrop.bottom};
877
878 // Copybit destination rect
879 hwc_rect_t displayFrame = layer->displayFrame;
880 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
881 displayFrame.right,
882 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700883#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530884 //change src and dst with dirtyRect
885 if(mDirtyLayerIndex != -1) {
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530886 hwc_rect_t result = getIntersection(displayFrame, mDirtyRect);
887 if(!isValidRect(result))
888 return true;
889 dstRect.l = result.left;
890 dstRect.t = result.top;
891 dstRect.r = result.right;
892 dstRect.b = result.bottom;
893
894 srcRect.l += (result.left - displayFrame.left);
895 srcRect.t += (result.top - displayFrame.top);
896 srcRect.r -= (displayFrame.right - result.right);
897 srcRect.b -= (displayFrame.bottom - result.bottom);
Ramakant Singh21cec722014-03-07 19:11:45 +0530898 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700899#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700900 // Copybit dst
901 copybit_image_t dst;
902 dst.w = ALIGN(fbHandle->width,32);
903 dst.h = fbHandle->height;
904 dst.format = fbHandle->format;
905 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800906 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700907
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800908 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700909
910 int32_t screen_w = displayFrame.right - displayFrame.left;
911 int32_t screen_h = displayFrame.bottom - displayFrame.top;
912 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
913 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
914
915 // Copybit dst
916 float copybitsMaxScale =
917 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
918 float copybitsMinScale =
919 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
920
Sushil Chauhandffbf432013-12-09 15:33:57 -0800921 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700922 //swap screen width and height
923 int tmp = screen_w;
924 screen_w = screen_h;
925 screen_h = tmp;
926 }
927 private_handle_t *tmpHnd = NULL;
928
929 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
930 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530931 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
932 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700933 return -1;
934 }
935
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530936 float dsdx = (float)screen_w/(float)src_crop_width;
937 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700938
939 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
940 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
941 if(dsdx > scaleLimitMax ||
942 dtdy > scaleLimitMax ||
943 dsdx < 1/scaleLimitMin ||
944 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400945 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700946 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
947 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700948 return -1;
949 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400950 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700951 if(dsdx > copybitsMaxScale ||
952 dtdy > copybitsMaxScale ||
953 dsdx < 1/copybitsMinScale ||
954 dtdy < 1/copybitsMinScale){
955 // The requested scale is out of the range the hardware
956 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400957 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700958 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
959 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
960 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
961 src_crop_width,src_crop_height);
962
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700963
964 int tmp_w = src_crop_width;
965 int tmp_h = src_crop_height;
966
Ramakant Singhd2875e12015-01-19 12:45:41 +0530967 if (dsdx > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530968 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530969 if (dtdy > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530970 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530971 // ceil the tmp_w and tmp_h value to maintain proper ratio
972 // b/w src and dst (should not cross the desired scale limit
973 // due to float -> int )
974 if (dsdx < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530975 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530976 if (dtdy < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530977 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +0530978
Terence Hampson663dfa72013-08-08 12:35:41 -0400979 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700980
Naseer Ahmed64b81212013-02-14 10:29:47 -0500981 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400982 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700983
Terence Hampsonb6a123a2013-07-18 11:54:16 -0400984 // We do not want copybit to generate alpha values from nothing
985 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
986 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
987 format = HAL_PIXEL_FORMAT_RGBX_8888;
988 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800989 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700990 copybit_image_t tmp_dst;
991 copybit_rect_t tmp_rect;
992 tmp_dst.w = tmp_w;
993 tmp_dst.h = tmp_h;
994 tmp_dst.format = tmpHnd->format;
995 tmp_dst.handle = tmpHnd;
996 tmp_dst.horiz_padding = src.horiz_padding;
997 tmp_dst.vert_padding = src.vert_padding;
998 tmp_rect.l = 0;
999 tmp_rect.t = 0;
1000 tmp_rect.r = tmp_dst.w;
1001 tmp_rect.b = tmp_dst.h;
1002 //create one clip region
1003 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
1004 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
1005 region_iterator tmp_it(tmp_hwc_reg);
1006 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001007 //TODO: once, we are able to read layer alpha, update this
1008 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -04001009 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001010 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
1011 &srcRect, &tmp_it);
1012 if(err < 0){
1013 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
1014 __LINE__);
1015 if(tmpHnd)
1016 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001017 return err;
1018 }
Terence Hampsonadf47302013-05-23 12:21:02 -04001019 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001020 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -04001021 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001022 close(acquireFd);
1023 acquireFd = -1;
1024 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001025 // copy new src and src rect crop
1026 src = tmp_dst;
1027 srcRect = tmp_rect;
1028 }
1029 }
1030 // Copybit region
1031 hwc_region_t region = layer->visibleRegionScreen;
1032 region_iterator copybitRegion(region);
1033
1034 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1035 renderBuffer->width);
1036 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1037 renderBuffer->height);
1038 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +08001039 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001040 //TODO: once, we are able to read layer alpha, update this
1041 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Ramakant Singh140965d2015-01-08 23:45:04 +05301042 copybit->set_parameter(copybit, COPYBIT_DYNAMIC_FPS, dynamic_fps);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001043 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
1044 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001045 copybit->set_parameter(copybit, COPYBIT_DITHER,
1046 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1047 COPYBIT_ENABLE : COPYBIT_DISABLE);
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301048 copybit->set_parameter(copybit, COPYBIT_FG_LAYER, isFG ?
1049 COPYBIT_ENABLE : COPYBIT_DISABLE);
1050
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001051 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1052 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001053 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001054 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1055 &copybitRegion);
1056 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1057 COPYBIT_DISABLE);
1058
Terence Hampsonadf47302013-05-23 12:21:02 -04001059 if(tmpHnd) {
1060 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1061 int ret = -1, releaseFd;
1062 // we need to wait for the buffer before freeing
1063 copybit->flush_get_fence(copybit, &releaseFd);
1064 ret = sync_wait(releaseFd, 1000);
1065 if(ret < 0) {
1066 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1067 __FUNCTION__, errno, strerror(errno));
1068 }
1069 close(releaseFd);
1070 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001071 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001072 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001073
1074 if(err < 0)
1075 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001076 return err;
1077}
1078
Sushil Chauhan943797c2013-10-21 17:35:55 -07001079int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1080 private_handle_t *renderBuffer)
1081{
1082 if (!renderBuffer) {
1083 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1084 return -1;
1085 }
1086
1087 // Copybit dst
1088 copybit_image_t dst;
1089 dst.w = ALIGN(renderBuffer->width, 32);
1090 dst.h = renderBuffer->height;
1091 dst.format = renderBuffer->format;
1092 dst.base = (void *)renderBuffer->base;
1093 dst.handle = (native_handle_t *)renderBuffer;
1094
1095 // Copybit dst rect
1096 hwc_rect_t displayFrame = layer->displayFrame;
1097 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1098 displayFrame.right, displayFrame.bottom};
1099
1100 uint32_t color = layer->transform;
1101 copybit_device_t *copybit = mEngine;
1102 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1103 renderBuffer->width);
1104 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1105 renderBuffer->height);
1106 copybit->set_parameter(copybit, COPYBIT_DITHER,
1107 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1108 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001109 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001110 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1111 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1112 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1113 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1114 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1115 return res;
1116}
1117
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001118void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001119 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001120{
1121 hwc_rect_t displayFrame = layer->displayFrame;
1122
1123 width = displayFrame.right - displayFrame.left;
1124 height = displayFrame.bottom - displayFrame.top;
1125}
1126
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001127bool CopyBit::validateParams(hwc_context_t *ctx,
1128 const hwc_display_contents_1_t *list) {
1129 //Validate parameters
1130 if (!ctx) {
1131 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1132 return false;
1133 } else if (!list) {
1134 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1135 return false;
1136 }
1137 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001138}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001139
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001140
Naseer Ahmed64b81212013-02-14 10:29:47 -05001141int CopyBit::allocRenderBuffers(int w, int h, int f)
1142{
1143 int ret = 0;
1144 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1145 if (mRenderBuffer[i] == NULL) {
1146 ret = alloc_buffer(&mRenderBuffer[i],
1147 w, h, f,
1148 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
1149 }
1150 if(ret < 0) {
1151 freeRenderBuffers();
1152 break;
1153 }
1154 }
1155 return ret;
1156}
1157
1158void CopyBit::freeRenderBuffers()
1159{
1160 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1161 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301162 //Since we are freeing buffer close the fence if it has a valid one.
1163 if(mRelFd[i] >= 0) {
1164 close(mRelFd[i]);
1165 mRelFd[i] = -1;
1166 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001167 free_buffer(mRenderBuffer[i]);
1168 mRenderBuffer[i] = NULL;
1169 }
1170 }
1171}
1172
1173private_handle_t * CopyBit::getCurrentRenderBuffer() {
1174 return mRenderBuffer[mCurRenderBufferIndex];
1175}
1176
1177void CopyBit::setReleaseFd(int fd) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301178 if(mRelFd[mCurRenderBufferIndex] >=0)
1179 close(mRelFd[mCurRenderBufferIndex]);
1180 mRelFd[mCurRenderBufferIndex] = dup(fd);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001181}
1182
Sushil Chauhandefd3522014-05-13 18:17:12 -07001183void CopyBit::setReleaseFdSync(int fd) {
1184 if (mRelFd[mCurRenderBufferIndex] >=0) {
1185 int ret = -1;
1186 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1187 if (ret < 0)
1188 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1189 __FUNCTION__, errno, strerror(errno));
1190 close(mRelFd[mCurRenderBufferIndex]);
1191 }
1192 mRelFd[mCurRenderBufferIndex] = dup(fd);
1193}
1194
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001195struct copybit_device_t* CopyBit::getCopyBitDevice() {
1196 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001197}
1198
Shalaj Jaina70b4352014-06-15 13:47:47 -07001199CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1200 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001201
1202 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1203 ctx->dpyAttr[dpy].yres,
1204 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001205 mAlignedWidth,
1206 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001207
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001208 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301209 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001210 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301211 mRelFd[i] = -1;
1212 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301213
1214 char value[PROPERTY_VALUE_MAX];
1215 property_get("debug.hwc.dynThreshold", value, "2");
1216 mDynThreshold = atof(value);
1217
Ramakant Singh21cec722014-03-07 19:11:45 +05301218 property_get("debug.sf.swaprect", value, "0");
1219 mSwapRectEnable = atoi(value) ? true:false ;
1220 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001221 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001222 if(copybit_open(module, &mEngine) < 0) {
1223 ALOGE("FATAL ERROR: copybit open failed.");
1224 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001225 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001226 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001227 }
1228}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001229
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001230CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001231{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001232 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001233 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001234 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001235 copybit_close(mEngine);
1236 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001237 }
1238}
Ramakant Singh21cec722014-03-07 19:11:45 +05301239CopyBit::LayerCache::LayerCache() {
1240 reset();
1241}
1242void CopyBit::LayerCache::reset() {
1243 memset(&hnd, 0, sizeof(hnd));
1244 layerCount = 0;
1245}
1246void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1247 hwc_display_contents_1_t *list, int dpy)
1248{
1249 layerCount = ctx->listStats[dpy].numAppLayers;
1250 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1251 hnd[i] = list->hwLayers[i].handle;
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +05301252 displayFrame[i] = list->hwLayers[i].displayFrame;
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +05301253 drop[i] = ctx->copybitDrop[i];
Ramakant Singh21cec722014-03-07 19:11:45 +05301254 }
1255}
1256
1257CopyBit::FbCache::FbCache() {
1258 reset();
1259}
1260void CopyBit::FbCache::reset() {
1261 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
1262 FbIndex =0;
1263}
1264
1265void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect) {
1266 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1267 FbdirtyRect[FbIndex] = dirtyRect;
1268 FbIndex++;
1269}
1270
1271int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect){
1272 int sameDirtyCount = 0;
1273 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
1274 if( FbdirtyRect[i] == dirtyRect)
1275 sameDirtyCount++;
1276 }
1277 return sameDirtyCount;
1278}
1279
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001280}; //namespace qhwc