blob: f547f1979a302ea8ea27e3320950f9e59816b144 [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
Dileep Kumar Reddiad376f12015-05-08 10:00:04 +053085bool CopyBit::isSmartBlitPossible(const hwc_display_contents_1_t *list){
86 if(list->numHwLayers > 2) {
87 hwc_rect_t displayFrame0 = {0, 0, 0, 0};
88 hwc_rect_t displayFrame1 = {0, 0, 0, 0};
89 for (unsigned int i=0; i<list->numHwLayers -1; i++) {
90 hwc_rect_t displayFrame = getIntersection(mDirtyRect,
91 list->hwLayers[i].displayFrame);
92 if (isValidRect(displayFrame) && !isValidRect(displayFrame0)) {
93 displayFrame0 = displayFrame;
94 } else if(isValidRect(displayFrame)) {
95 displayFrame1 = displayFrame;
96 break;
97 }
98 }
99 if((displayFrame0 == displayFrame1) &&
100 not (list->flags & (MDP_ROT_90 | MDP_FLIP_UD | MDP_FLIP_LR))) {
101 ALOGD_IF (DEBUG_COPYBIT, "%s:Smart Bilt Possible",__FUNCTION__);
102 return true;
103 }
104 }
105 return false;
106}
107
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800108bool CopyBit::canUseCopybitForRGB(hwc_context_t *ctx,
109 hwc_display_contents_1_t *list,
110 int dpy) {
111 int compositionType = qdutils::QCCompositionType::
112 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700113
Naseer Ahmed45a99602012-07-31 19:15:24 -0700114 if (compositionType & qdutils::COMPOSITION_TYPE_DYN) {
115 // DYN Composition:
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530116 // use copybit, if (TotalRGBRenderArea < threashold * FB Area)
Naseer Ahmed45a99602012-07-31 19:15:24 -0700117 // this is done based on perf inputs in ICS
118 // TODO: Above condition needs to be re-evaluated in JB
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800119 int fbWidth = ctx->dpyAttr[dpy].xres;
120 int fbHeight = ctx->dpyAttr[dpy].yres;
121 unsigned int fbArea = (fbWidth * fbHeight);
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530122 unsigned int renderArea = getRGBRenderingArea(ctx, list);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700123 ALOGD_IF (DEBUG_COPYBIT, "%s:renderArea %u, fbArea %u",
124 __FUNCTION__, renderArea, fbArea);
Dileep Kumar Reddiad376f12015-05-08 10:00:04 +0530125 double dynThreshold = mDynThreshold;
126 if(not isSmartBlitPossible(list))
127 dynThreshold -= 1;
128
129 if (renderArea < (dynThreshold * fbArea)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700130 return true;
131 }
132 } else if ((compositionType & qdutils::COMPOSITION_TYPE_MDP)) {
133 // MDP composition, use COPYBIT always
134 return true;
135 } else if ((compositionType & qdutils::COMPOSITION_TYPE_C2D)) {
136 // C2D composition, use COPYBIT
137 return true;
138 }
139 return false;
140}
141
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530142unsigned int CopyBit::getRGBRenderingArea (const hwc_context_t *ctx,
143 const hwc_display_contents_1_t *list) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700144 //Calculates total rendering area for RGB layers
145 unsigned int renderArea = 0;
146 unsigned int w=0, h=0;
Terence Hampsonef379d42013-05-21 10:38:01 -0400147 // Skipping last layer since FrameBuffer layer should not affect
148 // which composition to choose
149 for (unsigned int i=0; i<list->numHwLayers -1; i++) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700150 private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
151 if (hnd) {
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530152 if (BUFFER_TYPE_UI == hnd->bufferType && !ctx->copybitDrop[i]) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700153 getLayerResolution(&list->hwLayers[i], w, h);
154 renderArea += (w*h);
155 }
156 }
157 }
158 return renderArea;
159}
160
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530161bool CopyBit::isLayerChanging(hwc_context_t *ctx,
162 hwc_display_contents_1_t *list, int k) {
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530163 if((mLayerCache.hnd[k] != list->hwLayers[k].handle) ||
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530164 (mLayerCache.drop[k] != ctx->copybitDrop[k]) ||
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +0530165 (mLayerCache.displayFrame[k].left !=
166 list->hwLayers[k].displayFrame.left) ||
167 (mLayerCache.displayFrame[k].top !=
168 list->hwLayers[k].displayFrame.top) ||
169 (mLayerCache.displayFrame[k].right !=
170 list->hwLayers[k].displayFrame.right) ||
171 (mLayerCache.displayFrame[k].bottom !=
172 list->hwLayers[k].displayFrame.bottom)) {
173 return 1;
174 }
175 return 0;
176}
177
Ramakant Singh21cec722014-03-07 19:11:45 +0530178int CopyBit::getLayersChanging(hwc_context_t *ctx,
179 hwc_display_contents_1_t *list,
180 int dpy){
181
182 int changingLayerIndex = -1;
183 if(mLayerCache.layerCount != ctx->listStats[dpy].numAppLayers) {
184 mLayerCache.reset();
185 mFbCache.reset();
186 mLayerCache.updateCounts(ctx,list,dpy);
187 return -1;
188 }
189
190 int updatingLayerCount = 0;
191 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--){
192 //swap rect will kick in only for single updating layer
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530193 if(isLayerChanging(ctx, list, k)) {
Ramakant Singh21cec722014-03-07 19:11:45 +0530194 updatingLayerCount ++;
195 if(updatingLayerCount == 1)
196 changingLayerIndex = k;
197 }
198 }
199 //since we are using more than one framebuffers,we have to
200 //kick in swap rect only if we are getting continuous same
201 //dirty rect for same layer at least equal of number of
202 //framebuffers
203
Dileep Kumar Reddi45da4572015-04-21 08:29:25 +0530204 if ( updatingLayerCount <= 1 ) {
205 hwc_rect_t dirtyRect;
206 if (updatingLayerCount == 0) {
207 dirtyRect.left = INVALID_DIMENSION;
208 dirtyRect.top = INVALID_DIMENSION;
209 dirtyRect.right = INVALID_DIMENSION;
210 dirtyRect.bottom = INVALID_DIMENSION;
211 changingLayerIndex = NO_UPDATING_LAYER;
212 } else {
213 dirtyRect = list->hwLayers[changingLayerIndex].displayFrame;
Saurabh Shah93c69052014-04-24 10:27:10 -0700214#ifdef QCOM_BSP
Dileep Kumar Reddi45da4572015-04-21 08:29:25 +0530215 dirtyRect = list->hwLayers[changingLayerIndex].dirtyRect;
Saurabh Shah93c69052014-04-24 10:27:10 -0700216#endif
Dileep Kumar Reddi45da4572015-04-21 08:29:25 +0530217 }
Ramakant Singh21cec722014-03-07 19:11:45 +0530218
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530219 for (int k = ctx->listStats[dpy].numAppLayers-1; k >= 0 ; k--) {
220 //disable swap rect in case of scaling and video .
221 private_handle_t *hnd =(private_handle_t *)list->hwLayers[k].handle;
Dileep Kumar Reddic3545042015-03-11 19:37:06 +0530222 if(needsScaling(&list->hwLayers[k])||( hnd && isYuvBuffer(hnd)) ||
223 (list->hwLayers[k].transform & HAL_TRANSFORM_ROT_90)) {
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530224 mFbCache.reset();
225 return -1;
Ramakant Singh21cec722014-03-07 19:11:45 +0530226 }
227 }
Ramakant Singh19ead272015-03-18 14:11:31 +0530228 hwc_rect_t displayRect = list->hwLayers[changingLayerIndex].displayFrame;
229 if(mFbCache.getUnchangedFbDRCount(dirtyRect, displayRect) <
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530230 NUM_RENDER_BUFFERS) {
Ramakant Singh19ead272015-03-18 14:11:31 +0530231 mFbCache.insertAndUpdateFbCache(dirtyRect, displayRect);
Ramakant Singh21cec722014-03-07 19:11:45 +0530232 changingLayerIndex = -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530233 }
234 } else {
Ramakant Singh21cec722014-03-07 19:11:45 +0530235 mFbCache.reset();
236 changingLayerIndex = -1;
237 }
238 mLayerCache.updateCounts(ctx,list,dpy);
239 return changingLayerIndex;
240}
241
242int CopyBit::checkDirtyRect(hwc_context_t *ctx,
243 hwc_display_contents_1_t *list,
244 int dpy) {
245
246 //dirty rect will enable only if
247 //1.Only single layer is updating.
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530248 //2.No scaling
249 //3.No video layer
Ramakant Singh21cec722014-03-07 19:11:45 +0530250 if(mSwapRectEnable == false)
251 return -1;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530252 return getLayersChanging(ctx, list, dpy);
Ramakant Singh21cec722014-03-07 19:11:45 +0530253}
254
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700255bool CopyBit::prepareOverlap(hwc_context_t *ctx,
256 hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700257
258 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
259 ALOGE("%s: Invalid request", __FUNCTION__);
260 return false;
261 }
262
Saurabh Shah15455aa2015-01-28 13:54:48 -0800263 if (mEngine == NULL) {
264 ALOGW("%s: Copybit HAL not enabled", __FUNCTION__);
265 return false;
266 }
267
268 if (!(validateParams(ctx, list))) {
269 ALOGE("%s: validateParams() failed", __FUNCTION__);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700270 return false;
271 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700272 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700273
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700274 // Allocate render buffers if they're not allocated
275 int alignW = 0, alignH = 0;
276 int finalW = 0, finalH = 0;
277 for (int i = 0; i < ptorInfo->count; i++) {
278 int ovlapIndex = ptorInfo->layerIndex[i];
279 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
280 // render buffer width will be the max of two layers
281 // Align Widht and height to 32, Mdp would be configured
282 // with Aligned overlap w/h
283 finalW = max(finalW, ALIGN((overlap.right - overlap.left), 32));
284 finalH += ALIGN((overlap.bottom - overlap.top), 32);
285 if(finalH > ALIGN((overlap.bottom - overlap.top), 32)) {
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700286 // Calculate the dest top, left will always be zero
287 ptorInfo->displayFrame[i].top = (finalH -
288 (ALIGN((overlap.bottom - overlap.top), 32)));
289 }
290 // calculate the right and bottom values
291 ptorInfo->displayFrame[i].right = ptorInfo->displayFrame[i].left +
292 (overlap.right - overlap.left);
293 ptorInfo->displayFrame[i].bottom = ptorInfo->displayFrame[i].top +
294 (overlap.bottom - overlap.top);
295 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700296
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700297 getBufferSizeAndDimensions(finalW, finalH, HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -0700298 alignW, alignH);
299
300 if ((mAlignedWidth != alignW) || (mAlignedHeight != alignH)) {
301 // Overlap rect has changed, so free render buffers
302 freeRenderBuffers();
303 }
304
305 int ret = allocRenderBuffers(alignW, alignH, HAL_PIXEL_FORMAT_RGBA_8888);
306
307 if (ret < 0) {
308 ALOGE("%s: Render buffer allocation failed", __FUNCTION__);
309 return false;
310 }
311
312 mAlignedWidth = alignW;
313 mAlignedHeight = alignH;
314 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) % NUM_RENDER_BUFFERS;
315 return true;
316}
317
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800318bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
319 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700320
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800321 if(mEngine == NULL) {
322 // No copybit device found - cannot use copybit
323 return false;
324 }
Dileep Kumar Reddia25a9182014-07-24 20:01:44 +0530325
326 if(ctx->mThermalBurstMode) {
327 ALOGD_IF (DEBUG_COPYBIT, "%s:Copybit failed,"
328 "Running in Thermal Burst mode",__FUNCTION__);
329 return false;
330 }
331
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800332 int compositionType = qdutils::QCCompositionType::
333 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700334
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800335 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
336 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700337 //GPU/CPU composition, don't change layer composition type
338 return true;
339 }
340
Naseer Ahmed45a99602012-07-31 19:15:24 -0700341 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800342 ALOGE("%s:Invalid Params", __FUNCTION__);
343 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700344 }
345
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800346 if(ctx->listStats[dpy].skipCount) {
347 //GPU will be anyways used
348 return false;
349 }
350
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700351 if (ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) {
Sushil Chauhanb00f59d2013-04-29 18:35:54 -0700352 // Reached max layers supported by HWC.
353 return false;
354 }
355
Dileep Kumar Reddiad376f12015-05-08 10:00:04 +0530356 mDirtyLayerIndex = checkDirtyRect(ctx, list, dpy);
357 ALOGD_IF (DEBUG_COPYBIT, "%s:Dirty Layer Index: %d",
358 __FUNCTION__, mDirtyLayerIndex);
359 hwc_rect_t clearRegion = {0,0,0,0};
360 int last = (uint32_t)list->numHwLayers - 1;
361 mDirtyRect = list->hwLayers[last].displayFrame;
362 if (mDirtyLayerIndex != -1) {
363 if (mDirtyLayerIndex == NO_UPDATING_LAYER) {
364 mDirtyRect = clearRegion;
365 } else {
366 mDirtyRect = list->hwLayers[mDirtyLayerIndex].displayFrame;
367 }
368 }
369
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800370 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
371 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500372 LayerProp *layerProp = ctx->layerProp[dpy];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500373
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530374 // Following are MDP3 limitations for which we
375 // need to fallback to GPU composition:
Terence Hampsonb1021932013-09-18 11:15:19 -0400376 // 1. Plane alpha is not supported by MDP3.
Terence Hampson6b0a4272013-11-06 16:04:51 -0500377 // 2. Scaling is within range
Terence Hampsonc235bda2013-07-12 12:47:38 -0400378 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
379 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Terence Hampson6b0a4272013-11-06 16:04:51 -0500380 int dst_h, dst_w, src_h, src_w;
381 float dx, dy;
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530382 if(ctx->copybitDrop[i]) {
383 continue;
384 }
Terence Hampsonc235bda2013-07-12 12:47:38 -0400385 hwc_layer_1_t *layer = (hwc_layer_1_t *) &list->hwLayers[i];
Radhika Ranjan Soni46cf4e92013-08-06 16:40:05 +0530386 if (layer->planeAlpha != 0xFF)
387 return true;
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530388 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Terence Hampson6b0a4272013-11-06 16:04:51 -0500389
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700390 if (has90Transform(layer)) {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530391 src_h = sourceCrop.right - sourceCrop.left;
392 src_w = sourceCrop.bottom - sourceCrop.top;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500393 } else {
Ramakant Singhf2b51e62013-11-28 12:07:51 +0530394 src_h = sourceCrop.bottom - sourceCrop.top;
395 src_w = sourceCrop.right - sourceCrop.left;
Terence Hampson6b0a4272013-11-06 16:04:51 -0500396 }
397 dst_h = layer->displayFrame.bottom - layer->displayFrame.top;
398 dst_w = layer->displayFrame.right - layer->displayFrame.left;
399
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530400 if(src_w <=0 || src_h<=0 ||dst_w<=0 || dst_h<=0 ) {
401 ALOGE("%s: wrong params for display screen_w=%d \
402 src_crop_width=%d screen_h=%d src_crop_height=%d",
403 __FUNCTION__, dst_w,src_w,dst_h,src_h);
404 return false;
405 }
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530406 dx = (float)dst_w/(float)src_w;
407 dy = (float)dst_h/(float)src_h;
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530408
Ramakant Singhd5b369f2014-12-09 23:03:43 +0530409 float scale_factor_max = MAX_SCALE_FACTOR;
410 float scale_factor_min = MIN_SCALE_FACTOR;
411
412 if (isAlphaPresent(layer)) {
413 scale_factor_max = MAX_SCALE_FACTOR/4;
414 scale_factor_min = MIN_SCALE_FACTOR*4;
415 }
416
417 if (dx > scale_factor_max || dx < scale_factor_min)
Terence Hampson6b0a4272013-11-06 16:04:51 -0500418 return false;
419
Ramakant Singhd5b369f2014-12-09 23:03:43 +0530420 if (dy > scale_factor_max || dy < scale_factor_min)
Terence Hampson6b0a4272013-11-06 16:04:51 -0500421 return false;
Terence Hampsonc235bda2013-07-12 12:47:38 -0400422 }
423 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500424
425 //Allocate render buffers if they're not allocated
Ramakant Singhb4106a12014-10-07 18:06:56 +0530426 if ((ctx->mMDP.version != qdutils::MDP_V3_0_4 &&
427 ctx->mMDP.version != qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400428 (useCopybitForYUV || useCopybitForRGB)) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700429 int ret = allocRenderBuffers(mAlignedWidth,
430 mAlignedHeight,
Saurabh Shah220a30c2013-10-29 16:12:12 -0700431 HAL_PIXEL_FORMAT_RGBA_8888);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500432 if (ret < 0) {
433 return false;
434 } else {
435 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
436 NUM_RENDER_BUFFERS;
437 }
438 }
439
Terence Hampsond0fd5792013-05-29 11:56:52 -0400440 // We cannot mix copybit layer with layers marked to be drawn on FB
441 if (!useCopybitForYUV && ctx->listStats[dpy].yuvCount)
442 return true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800443
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530444 mCopyBitDraw = false;
445 if (useCopybitForRGB &&
446 (useCopybitForYUV || !ctx->listStats[dpy].yuvCount)) {
447 mCopyBitDraw = true;
448 // numAppLayers-1, as we iterate till 0th layer index
449 // Mark all layers to be drawn by copybit
450 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500451 layerProp[i].mFlags |= HWC_COPYBIT;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700452#ifdef QCOM_BSP
Ramakant Singhb4106a12014-10-07 18:06:56 +0530453 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
454 ctx->mMDP.version == qdutils::MDP_V3_0_5)
Terence Hampsonc67b0372013-10-09 11:32:21 -0400455 list->hwLayers[i].compositionType = HWC_BLIT;
456 else
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700457#endif
Terence Hampsonc67b0372013-10-09 11:32:21 -0400458 list->hwLayers[i].compositionType = HWC_OVERLAY;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700459 }
460 }
Radhika Ranjan Soni14f6c4b2013-08-28 17:04:49 +0530461
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700462 return true;
463}
464
Naseer Ahmed183939d2013-03-14 20:44:17 -0400465int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
466{
467 int ret = 0;
468 copybit_rect_t clear_rect = {rect.left, rect.top,
469 rect.right,
470 rect.bottom};
471
472 copybit_image_t buf;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700473 buf.w = ALIGN(getWidth(hnd),32);
474 buf.h = getHeight(hnd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400475 buf.format = hnd->format;
476 buf.base = (void *)hnd->base;
477 buf.handle = (native_handle_t *)hnd;
478
479 copybit_device_t *copybit = mEngine;
480 ret = copybit->clear(copybit, &buf, &clear_rect);
481 return ret;
482}
483
Ramakant Singh0def28c2014-03-28 20:43:13 +0530484bool CopyBit::drawUsingAppBufferComposition(hwc_context_t *ctx,
485 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +0530486 int dpy, int *copybitFd) {
487 int layerCount = 0;
Shalaj Jaina70b4352014-06-15 13:47:47 -0700488 uint32_t last = (uint32_t)list->numHwLayers - 1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530489 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
490 private_handle_t *fbhnd = (private_handle_t *)fbLayer->handle;
Ramakant Singh0def28c2014-03-28 20:43:13 +0530491
492 if(ctx->enableABC == false)
493 return false;
494
Ramakant Singh467759f2014-04-16 11:09:40 +0530495 if(ctx->listStats[dpy].numAppLayers > MAX_LAYERS_FOR_ABC )
Ramakant Singh0def28c2014-03-28 20:43:13 +0530496 return false;
497
498 layerCount = ctx->listStats[dpy].numAppLayers;
499 //bottom most layer should
500 //equal to FB
501 hwc_layer_1_t *tmpLayer = &list->hwLayers[0];
502 private_handle_t *hnd = (private_handle_t *)tmpLayer->handle;
503 if(hnd && fbhnd && (hnd->size == fbhnd->size) &&
504 (hnd->width == fbhnd->width) && (hnd->height == fbhnd->height)){
505 if(tmpLayer->transform ||
Dileep Kumar Reddi2f8a13e2015-03-26 18:01:23 +0530506 (list->flags & HWC_GEOMETRY_CHANGED) ||
Ramakant Singh0def28c2014-03-28 20:43:13 +0530507 (!(hnd->format == HAL_PIXEL_FORMAT_RGBA_8888 ||
508 hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)) ||
509 (needsScaling(tmpLayer) == true)) {
510 return false;
511 }else {
512 ctx->listStats[dpy].renderBufIndexforABC = 0;
513 }
514 }
515
Ramakant Singh467759f2014-04-16 11:09:40 +0530516 if(ctx->listStats[dpy].renderBufIndexforABC == 0) {
517 if(layerCount == 1)
Ramakant Singh0def28c2014-03-28 20:43:13 +0530518 return true;
Ramakant Singh467759f2014-04-16 11:09:40 +0530519
Ramakant Singhcc326612014-06-19 14:19:18 +0530520 if(layerCount == MAX_LAYERS_FOR_ABC) {
Ramakant Singh467759f2014-04-16 11:09:40 +0530521 int abcRenderBufIdx = ctx->listStats[dpy].renderBufIndexforABC;
Ramakant Singhcc326612014-06-19 14:19:18 +0530522 //enable ABC only for non intersecting layers.
523 hwc_rect_t displayFrame =
524 list->hwLayers[abcRenderBufIdx].displayFrame;
525 for (int i = abcRenderBufIdx + 1; i < layerCount; i++) {
526 hwc_rect_t tmpDisplayFrame = list->hwLayers[i].displayFrame;
527 hwc_rect_t result = getIntersection(displayFrame,tmpDisplayFrame);
528 if (isValidRect(result)) {
529 ctx->listStats[dpy].renderBufIndexforABC = -1;
530 return false;
531 }
532 }
533 // Pass the Acquire Fence FD to driver for base layer
Ramakant Singh467759f2014-04-16 11:09:40 +0530534 private_handle_t *renderBuffer =
535 (private_handle_t *)list->hwLayers[abcRenderBufIdx].handle;
536 copybit_device_t *copybit = getCopyBitDevice();
537 if(list->hwLayers[abcRenderBufIdx].acquireFenceFd >=0){
538 copybit->set_sync(copybit,
539 list->hwLayers[abcRenderBufIdx].acquireFenceFd);
540 }
Ramakant Singhcc326612014-06-19 14:19:18 +0530541 for(int i = abcRenderBufIdx + 1; i < layerCount; i++){
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530542 mDirtyLayerIndex = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530543 int retVal = drawLayerUsingCopybit(ctx,
544 &(list->hwLayers[i]),renderBuffer, 0);
545 if(retVal < 0) {
546 ALOGE("%s : Copybit failed", __FUNCTION__);
547 }
548 }
549 // Get Release Fence FD of copybit for the App layer(s)
550 copybit->flush_get_fence(copybit, copybitFd);
Ramakant Singh52e1c0c2014-12-18 23:35:33 +0530551 close(list->hwLayers[last].acquireFenceFd);
552 list->hwLayers[last].acquireFenceFd = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +0530553 return true;
554 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530555 }
556 return false;
557}
558
559bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
560 int dpy, int32_t *fd) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800561 // draw layers marked for COPYBIT
562 int retVal = true;
563 int copybitLayerCount = 0;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400564 uint32_t last = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500565 LayerProp *layerProp = ctx->layerProp[dpy];
Terence Hampsonc67b0372013-10-09 11:32:21 -0400566 private_handle_t *renderBuffer;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800567
Ramakant Singh21cec722014-03-07 19:11:45 +0530568 if(mCopyBitDraw == false){
569 mFbCache.reset(); // there is no layer marked for copybit
570 return false ;
571 }
Ramakant Singh0def28c2014-03-28 20:43:13 +0530572
Ramakant Singh467759f2014-04-16 11:09:40 +0530573 if(drawUsingAppBufferComposition(ctx, list, dpy, fd)) {
Ramakant Singh0def28c2014-03-28 20:43:13 +0530574 return true;
575 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800576 //render buffer
Ramakant Singhb4106a12014-10-07 18:06:56 +0530577 if (ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
578 ctx->mMDP.version == qdutils::MDP_V3_0_5) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530579 last = (uint32_t)list->numHwLayers - 1;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400580 renderBuffer = (private_handle_t *)list->hwLayers[last].handle;
581 } else {
582 renderBuffer = getCurrentRenderBuffer();
583 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800584 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500585 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800586 return false;
587 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500588
Terence Hampson0124cc72013-04-18 23:45:56 -0700589 if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400590 //Wait for the previous frame to complete before rendering onto it
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530591 if(mRelFd[mCurRenderBufferIndex] >=0) {
592 sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
593 close(mRelFd[mCurRenderBufferIndex]);
594 mRelFd[mCurRenderBufferIndex] = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400595 }
Terence Hampson65fe4522013-10-17 17:40:03 -0400596 } else {
Terence Hampsonc67b0372013-10-09 11:32:21 -0400597 if(list->hwLayers[last].acquireFenceFd >=0) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400598 copybit_device_t *copybit = getCopyBitDevice();
Terence Hampsonc67b0372013-10-09 11:32:21 -0400599 copybit->set_sync(copybit, list->hwLayers[last].acquireFenceFd);
Terence Hampson65fe4522013-10-17 17:40:03 -0400600 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700601 }
radhakrishna2f00c8f2013-10-21 16:49:21 +0530602
Dileep Kumar Reddi45da4572015-04-21 08:29:25 +0530603 if (mDirtyLayerIndex != NO_UPDATING_LAYER &&
Dileep Kumar Reddi2d0c0ef2015-05-07 17:24:23 +0530604 not CBUtils::uiClearRegion(list, ctx->mMDP.version, layerProp,
605 mDirtyLayerIndex, mEngine, renderBuffer)){
606 mDirtyLayerIndex = -1;
Ramakant Singh909bc2a2015-02-10 16:29:21 +0530607 }
Dileep Kumar Reddi2d0c0ef2015-05-07 17:24:23 +0530608
Naseer Ahmed64b81212013-02-14 10:29:47 -0500609 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800610 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500611 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
612 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800613 continue;
614 }
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530615 if(ctx->copybitDrop[i]) {
616 continue;
617 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800618 int ret = -1;
Terence Hampsonadf47302013-05-23 12:21:02 -0400619 if (list->hwLayers[i].acquireFenceFd != -1
620 && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800621 // Wait for acquire Fence on the App buffers.
622 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
623 if(ret < 0) {
624 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
625 __FUNCTION__, errno, strerror(errno));
626 }
627 close(list->hwLayers[i].acquireFenceFd);
628 list->hwLayers[i].acquireFenceFd = -1;
629 }
630 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
Ramakant Singh21cec722014-03-07 19:11:45 +0530631 renderBuffer, !i);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800632 copybitLayerCount++;
633 if(retVal < 0) {
634 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
635 }
636 }
637
638 if (copybitLayerCount) {
639 copybit_device_t *copybit = getCopyBitDevice();
640 // Async mode
641 copybit->flush_get_fence(copybit, fd);
Ramakant Singhb4106a12014-10-07 18:06:56 +0530642 if((ctx->mMDP.version == qdutils::MDP_V3_0_4 ||
643 ctx->mMDP.version == qdutils::MDP_V3_0_5) &&
Terence Hampsonc67b0372013-10-09 11:32:21 -0400644 list->hwLayers[last].acquireFenceFd >= 0) {
645 close(list->hwLayers[last].acquireFenceFd);
646 list->hwLayers[last].acquireFenceFd = -1;
Terence Hampson65fe4522013-10-17 17:40:03 -0400647 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800648 }
649 return true;
650}
651
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700652int CopyBit::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Sushil Chauhandefd3522014-05-13 18:17:12 -0700653 int fd = -1;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700654 PtorInfo* ptorInfo = &(ctx->mPtorInfo);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700655
656 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
657 ALOGE("%s: Invalid request", __FUNCTION__);
658 return fd;
659 }
660
661 private_handle_t *renderBuffer = getCurrentRenderBuffer();
662
663 if (!renderBuffer) {
664 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
665 return fd;
666 }
667
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530668 //Clear the transparent or left out region on the render buffer
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530669 LayerProp *layerProp = ctx->layerProp[0];
Dileep Kumar Reddi2d0c0ef2015-05-07 17:24:23 +0530670 CBUtils::uiClearRegion(list, ctx->mMDP.version, layerProp, -1,
671 mEngine, renderBuffer);
Dileep Kumar Reddid1f08e42014-11-05 21:24:27 +0530672
Sushil Chauhandefd3522014-05-13 18:17:12 -0700673 int copybitLayerCount = 0;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700674 for(int j = 0; j < ptorInfo->count; j++) {
675 int ovlapIndex = ptorInfo->layerIndex[j];
676 hwc_rect_t overlap = list->hwLayers[ovlapIndex].displayFrame;
Prabhanjan Kandula9889a202014-09-04 21:50:35 +0530677 if(j) {
678 /**
679 * It's possible that 2 PTOR layers might have overlapping.
680 * In such case, remove the intersection(again if peripheral)
681 * from the lower PTOR layer to avoid overlapping.
682 * If intersection is not on peripheral then compromise
683 * by reducing number of PTOR layers.
684 **/
685 int prevOvlapIndex = ptorInfo->layerIndex[0];
686 hwc_rect_t prevOvlap = list->hwLayers[prevOvlapIndex].displayFrame;
687 hwc_rect_t commonRect = getIntersection(prevOvlap, overlap);
688 if(isValidRect(commonRect)) {
689 overlap = deductRect(overlap, commonRect);
690 }
691 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700692
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700693 // Draw overlapped content of layers on render buffer
694 for (int i = 0; i <= ovlapIndex; i++) {
695 hwc_layer_1_t *layer = &list->hwLayers[i];
696 if(!isValidRect(getIntersection(layer->displayFrame,
697 overlap))) {
698 continue;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700699 }
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700700 if ((list->hwLayers[i].acquireFenceFd != -1)) {
701 // Wait for acquire fence on the App buffers.
702 if(sync_wait(list->hwLayers[i].acquireFenceFd, 1000) < 0) {
703 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
704 __FUNCTION__, errno, strerror(errno));
705 }
706 close(list->hwLayers[i].acquireFenceFd);
707 list->hwLayers[i].acquireFenceFd = -1;
708 }
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530709 /*
710 * Find the intersection of layer display frame with PTOR layer
711 * with respect to screen co-ordinates
712 *
713 * Calculated the destination rect by transforming the overlapping
714 * region of layer display frame with respect to PTOR display frame
715 *
716 * Transform the destination rect on to render buffer
717 * */
718 hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
719 destRect.left = destRect.left - overlap.left +
720 ptorInfo->displayFrame[j].left;
721 destRect.right = destRect.right- overlap.left +
722 ptorInfo->displayFrame[j].left;
723 destRect.top = destRect.top - overlap.top +
724 ptorInfo->displayFrame[j].top;
725 destRect.bottom = destRect.bottom - overlap.top +
726 ptorInfo->displayFrame[j].top;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700727
Dileep Kumar Reddi408fde52014-11-04 22:53:15 +0530728 int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
729 overlap, destRect);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700730 copybitLayerCount++;
731 if(retVal < 0) {
732 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);
733 copybitLayerCount = 0;
734 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700735 }
736 }
737
738 if (copybitLayerCount) {
739 copybit_device_t *copybit = getCopyBitDevice();
740 copybit->flush_get_fence(copybit, &fd);
741 }
742
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700743 ALOGD_IF(DEBUG_COPYBIT, "%s: done! copybitLayerCount = %d", __FUNCTION__,
744 copybitLayerCount);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700745 return fd;
746}
747
748int CopyBit::drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700749 private_handle_t *renderBuffer, hwc_rect_t overlap,
750 hwc_rect_t destRect)
Sushil Chauhandefd3522014-05-13 18:17:12 -0700751{
752 hwc_context_t* ctx = (hwc_context_t*)(dev);
753 if (!ctx) {
754 ALOGE("%s: null context ", __FUNCTION__);
755 return -1;
756 }
757
758 private_handle_t *hnd = (private_handle_t *)layer->handle;
759 if (!hnd) {
760 ALOGE("%s: invalid handle", __FUNCTION__);
761 return -1;
762 }
763
764 private_handle_t *dstHandle = (private_handle_t *)renderBuffer;
765 if (!dstHandle) {
766 ALOGE("%s: RenderBuffer handle is NULL", __FUNCTION__);
767 return -1;
768 }
769
770 // Set the Copybit Source
771 copybit_image_t src;
772 src.handle = (native_handle_t *)layer->handle;
773 src.w = hnd->width;
774 src.h = hnd->height;
775 src.base = (void *)hnd->base;
776 src.format = hnd->format;
777 src.horiz_padding = 0;
778 src.vert_padding = 0;
779
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700780
Sushil Chauhandefd3522014-05-13 18:17:12 -0700781 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700782 hwc_rect_t iRect = getIntersection(dispFrame, overlap);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700783 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700784 qhwc::calculate_crop_rects(crop, dispFrame, iRect,
785 layer->transform);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700786
787 // Copybit source rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700788 copybit_rect_t srcRect = {crop.left, crop.top, crop.right,
789 crop.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700790
791 // Copybit destination rect
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700792 copybit_rect_t dstRect = {destRect.left, destRect.top, destRect.right,
793 destRect.bottom};
Sushil Chauhandefd3522014-05-13 18:17:12 -0700794
795 // Copybit dst
796 copybit_image_t dst;
797 dst.handle = (native_handle_t *)dstHandle;
798 dst.w = ALIGN(dstHandle->width, 32);
799 dst.h = dstHandle->height;
800 dst.base = (void *)dstHandle->base;
801 dst.format = dstHandle->format;
802
803 copybit_device_t *copybit = mEngine;
804
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700805 // Copybit region is the destRect
806 hwc_rect_t regRect = {dstRect.l,dstRect.t, dstRect.r, dstRect.b};
807 hwc_region_t region;
808 region.numRects = 1;
809 region.rects = &regRect;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700810 region_iterator copybitRegion(region);
811 int acquireFd = layer->acquireFenceFd;
812
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700813 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
814 renderBuffer->width);
815 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
816 renderBuffer->height);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700817 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
818 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
819 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
820 copybit->set_parameter(copybit, COPYBIT_DITHER,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700821 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ? COPYBIT_ENABLE :
822 COPYBIT_DISABLE);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700823 copybit->set_sync(copybit, acquireFd);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700824 int err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
825 &copybitRegion);
Sushil Chauhandefd3522014-05-13 18:17:12 -0700826
827 if (err < 0)
828 ALOGE("%s: copybit stretch failed",__FUNCTION__);
829
830 return err;
831}
832
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700833int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800834 private_handle_t *renderBuffer, bool isFG)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700835{
836 hwc_context_t* ctx = (hwc_context_t*)(dev);
Terence Hampsonadf47302013-05-23 12:21:02 -0400837 int err = 0, acquireFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700838 if(!ctx) {
839 ALOGE("%s: null context ", __FUNCTION__);
840 return -1;
841 }
842
843 private_handle_t *hnd = (private_handle_t *)layer->handle;
844 if(!hnd) {
Sushil Chauhan943797c2013-10-21 17:35:55 -0700845 if (layer->flags & HWC_COLOR_FILL) { // Color layer
846 return fillColorUsingCopybit(layer, renderBuffer);
847 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700848 ALOGE("%s: invalid handle", __FUNCTION__);
849 return -1;
850 }
851
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800852 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700853 if(!fbHandle) {
854 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700855 return -1;
856 }
Ramakant Singh140965d2015-01-08 23:45:04 +0530857 uint32_t dynamic_fps = 0;
858#ifdef DYNAMIC_FPS
859 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
860 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
861 dynamic_fps = roundOff(mdata->refreshrate);
862 }
863#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700864 // Set the copybit source:
865 copybit_image_t src;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700866 src.w = getWidth(hnd);
867 src.h = getHeight(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700868 src.format = hnd->format;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700869
870 // Handle R/B swap
871 if ((layer->flags & HWC_FORMAT_RB_SWAP)) {
872 if (src.format == HAL_PIXEL_FORMAT_RGBA_8888) {
873 src.format = HAL_PIXEL_FORMAT_BGRA_8888;
874 } else if (src.format == HAL_PIXEL_FORMAT_RGBX_8888) {
875 src.format = HAL_PIXEL_FORMAT_BGRX_8888;
876 }
877 }
878
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700879 src.base = (void *)hnd->base;
880 src.handle = (native_handle_t *)layer->handle;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -0700881 src.horiz_padding = src.w - getWidth(hnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700882 // Initialize vertical padding to zero for now,
883 // this needs to change to accomodate vertical stride
884 // if needed in the future
885 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700886
shuoy7c101f92013-08-26 14:48:57 +0800887 int layerTransform = layer->transform ;
888 // When flip and rotation(90) are present alter the flip,
889 // as GPU is doing the flip and rotation in opposite order
890 // to that of MDP3.0
891 // For 270 degrees, we get 90 + (H+V) which is same as doing
892 // flip first and then rotation (H+V) + 90
893 if (qdutils::MDPVersion::getInstance().getMDPVersion() < 400) {
894 if (((layer->transform& HAL_TRANSFORM_FLIP_H) ||
895 (layer->transform & HAL_TRANSFORM_FLIP_V)) &&
896 (layer->transform & HAL_TRANSFORM_ROT_90) &&
897 !(layer->transform == HAL_TRANSFORM_ROT_270)){
898 if(layer->transform & HAL_TRANSFORM_FLIP_H){
899 layerTransform ^= HAL_TRANSFORM_FLIP_H;
900 layerTransform |= HAL_TRANSFORM_FLIP_V;
901 }
902 if(layer->transform & HAL_TRANSFORM_FLIP_V){
903 layerTransform ^= HAL_TRANSFORM_FLIP_V;
904 layerTransform |= HAL_TRANSFORM_FLIP_H;
905 }
906 }
907 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700908 // Copybit source rect
Saurabh Shah62e1d732013-09-17 10:44:05 -0700909 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700910 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
911 sourceCrop.right,
912 sourceCrop.bottom};
913
914 // Copybit destination rect
915 hwc_rect_t displayFrame = layer->displayFrame;
916 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
917 displayFrame.right,
918 displayFrame.bottom};
Saurabh Shah93c69052014-04-24 10:27:10 -0700919#ifdef QCOM_BSP
Ramakant Singh21cec722014-03-07 19:11:45 +0530920 //change src and dst with dirtyRect
921 if(mDirtyLayerIndex != -1) {
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530922 hwc_rect_t result = getIntersection(displayFrame, mDirtyRect);
923 if(!isValidRect(result))
924 return true;
925 dstRect.l = result.left;
926 dstRect.t = result.top;
927 dstRect.r = result.right;
928 dstRect.b = result.bottom;
929
930 srcRect.l += (result.left - displayFrame.left);
931 srcRect.t += (result.top - displayFrame.top);
932 srcRect.r -= (displayFrame.right - result.right);
933 srcRect.b -= (displayFrame.bottom - result.bottom);
Ramakant Singh21cec722014-03-07 19:11:45 +0530934 }
Saurabh Shah93c69052014-04-24 10:27:10 -0700935#endif
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700936 // Copybit dst
937 copybit_image_t dst;
938 dst.w = ALIGN(fbHandle->width,32);
939 dst.h = fbHandle->height;
940 dst.format = fbHandle->format;
941 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800942 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700943
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800944 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700945
946 int32_t screen_w = displayFrame.right - displayFrame.left;
947 int32_t screen_h = displayFrame.bottom - displayFrame.top;
948 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
949 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
950
951 // Copybit dst
952 float copybitsMaxScale =
953 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
954 float copybitsMinScale =
955 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
956
Sushil Chauhandffbf432013-12-09 15:33:57 -0800957 if (layer->transform & HWC_TRANSFORM_ROT_90) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700958 //swap screen width and height
959 int tmp = screen_w;
960 screen_w = screen_h;
961 screen_h = tmp;
962 }
963 private_handle_t *tmpHnd = NULL;
964
965 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
966 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
Ramakant Singh0b35f2c2014-01-07 11:25:48 +0530967 screen_h=%d src_crop_height=%d", __FUNCTION__, screen_w,
968 src_crop_width,screen_h,src_crop_height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700969 return -1;
970 }
971
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530972 float dsdx = (float)screen_w/(float)src_crop_width;
973 float dtdy = (float)screen_h/(float)src_crop_height;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700974
975 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
976 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
977 if(dsdx > scaleLimitMax ||
978 dtdy > scaleLimitMax ||
979 dsdx < 1/scaleLimitMin ||
980 dtdy < 1/scaleLimitMin) {
Terence Hampson3c560b92013-09-03 16:58:02 -0400981 ALOGW("%s: greater than max supported size dsdx=%f dtdy=%f \
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700982 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
983 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700984 return -1;
985 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400986 acquireFd = layer->acquireFenceFd;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700987 if(dsdx > copybitsMaxScale ||
988 dtdy > copybitsMaxScale ||
989 dsdx < 1/copybitsMinScale ||
990 dtdy < 1/copybitsMinScale){
991 // The requested scale is out of the range the hardware
992 // can support.
Terence Hampson663dfa72013-08-08 12:35:41 -0400993 ALOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700994 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
995 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
996 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
997 src_crop_width,src_crop_height);
998
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700999
1000 int tmp_w = src_crop_width;
1001 int tmp_h = src_crop_height;
1002
Ramakant Singhd2875e12015-01-19 12:45:41 +05301003 if (dsdx > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301004 tmp_w = (int)((float)src_crop_width*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +05301005 if (dtdy > copybitsMaxScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301006 tmp_h = (int)((float)src_crop_height*copybitsMaxScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +05301007 // ceil the tmp_w and tmp_h value to maintain proper ratio
1008 // b/w src and dst (should not cross the desired scale limit
1009 // due to float -> int )
1010 if (dsdx < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301011 tmp_w = (int)ceil((float)src_crop_width/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +05301012 if (dtdy < 1/copybitsMinScale)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301013 tmp_h = (int)ceil((float)src_crop_height/copybitsMinScale);
Ramakant Singhd2875e12015-01-19 12:45:41 +05301014
Terence Hampson663dfa72013-08-08 12:35:41 -04001015 ALOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001016
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -05001017 int usage = 0;
Terence Hampsonb6a123a2013-07-18 11:54:16 -04001018 int format = fbHandle->format;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001019
Terence Hampsonb6a123a2013-07-18 11:54:16 -04001020 // We do not want copybit to generate alpha values from nothing
1021 if (format == HAL_PIXEL_FORMAT_RGBA_8888 &&
1022 src.format != HAL_PIXEL_FORMAT_RGBA_8888) {
1023 format = HAL_PIXEL_FORMAT_RGBX_8888;
1024 }
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001025 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, format, usage) && tmpHnd) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001026 copybit_image_t tmp_dst;
1027 copybit_rect_t tmp_rect;
1028 tmp_dst.w = tmp_w;
1029 tmp_dst.h = tmp_h;
1030 tmp_dst.format = tmpHnd->format;
1031 tmp_dst.handle = tmpHnd;
1032 tmp_dst.horiz_padding = src.horiz_padding;
1033 tmp_dst.vert_padding = src.vert_padding;
1034 tmp_rect.l = 0;
1035 tmp_rect.t = 0;
1036 tmp_rect.r = tmp_dst.w;
1037 tmp_rect.b = tmp_dst.h;
1038 //create one clip region
1039 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
1040 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
1041 region_iterator tmp_it(tmp_hwc_reg);
1042 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001043 //TODO: once, we are able to read layer alpha, update this
1044 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Terence Hampsonadf47302013-05-23 12:21:02 -04001045 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001046 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
1047 &srcRect, &tmp_it);
1048 if(err < 0){
1049 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
1050 __LINE__);
1051 if(tmpHnd)
1052 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001053 return err;
1054 }
Terence Hampsonadf47302013-05-23 12:21:02 -04001055 // use release fence as aquire fd for next stretch
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001056 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Terence Hampsonadf47302013-05-23 12:21:02 -04001057 copybit->flush_get_fence(copybit, &acquireFd);
Terence Hampson1d8db6f2013-07-17 11:05:36 -04001058 close(acquireFd);
1059 acquireFd = -1;
1060 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001061 // copy new src and src rect crop
1062 src = tmp_dst;
1063 srcRect = tmp_rect;
1064 }
1065 }
1066 // Copybit region
1067 hwc_region_t region = layer->visibleRegionScreen;
Dileep Kumar Reddib588ebd2015-03-18 15:25:22 +05301068 //Do not use visible regions in case of scaling
1069 if (region.numRects > 1) {
1070 if (needsScaling(layer)) {
1071 region.numRects = 1;
1072 region.rects = &layer->displayFrame;
1073 }
1074 }
1075
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001076 region_iterator copybitRegion(region);
1077
1078 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1079 renderBuffer->width);
1080 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1081 renderBuffer->height);
1082 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
shuoy7c101f92013-08-26 14:48:57 +08001083 layerTransform);
Naseer Ahmed45a99602012-07-31 19:15:24 -07001084 //TODO: once, we are able to read layer alpha, update this
1085 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Ramakant Singh140965d2015-01-08 23:45:04 +05301086 copybit->set_parameter(copybit, COPYBIT_DYNAMIC_FPS, dynamic_fps);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001087 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
1088 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001089 copybit->set_parameter(copybit, COPYBIT_DITHER,
1090 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
1091 COPYBIT_ENABLE : COPYBIT_DISABLE);
Ramakant Singh495f09f2015-04-13 20:06:41 +05301092 copybit->set_parameter(copybit, COPYBIT_FG_LAYER,
1093 (layer->blending == HWC_BLENDING_NONE || isFG ) ?
Shivaraj Shettye86506a2013-08-06 12:56:30 +05301094 COPYBIT_ENABLE : COPYBIT_DISABLE);
1095
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001096 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1097 COPYBIT_ENABLE);
Terence Hampsonadf47302013-05-23 12:21:02 -04001098 copybit->set_sync(copybit, acquireFd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001099 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
1100 &copybitRegion);
1101 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
1102 COPYBIT_DISABLE);
1103
Terence Hampsonadf47302013-05-23 12:21:02 -04001104 if(tmpHnd) {
1105 if (ctx->mMDP.version < qdutils::MDP_V4_0){
1106 int ret = -1, releaseFd;
1107 // we need to wait for the buffer before freeing
1108 copybit->flush_get_fence(copybit, &releaseFd);
1109 ret = sync_wait(releaseFd, 1000);
1110 if(ret < 0) {
1111 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
1112 __FUNCTION__, errno, strerror(errno));
1113 }
1114 close(releaseFd);
1115 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001116 free_buffer(tmpHnd);
Terence Hampsonadf47302013-05-23 12:21:02 -04001117 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001118
1119 if(err < 0)
1120 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001121 return err;
1122}
1123
Sushil Chauhan943797c2013-10-21 17:35:55 -07001124int CopyBit::fillColorUsingCopybit(hwc_layer_1_t *layer,
1125 private_handle_t *renderBuffer)
1126{
1127 if (!renderBuffer) {
1128 ALOGE("%s: Render Buffer is NULL", __FUNCTION__);
1129 return -1;
1130 }
1131
1132 // Copybit dst
1133 copybit_image_t dst;
1134 dst.w = ALIGN(renderBuffer->width, 32);
1135 dst.h = renderBuffer->height;
1136 dst.format = renderBuffer->format;
1137 dst.base = (void *)renderBuffer->base;
1138 dst.handle = (native_handle_t *)renderBuffer;
1139
1140 // Copybit dst rect
1141 hwc_rect_t displayFrame = layer->displayFrame;
1142 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
1143 displayFrame.right, displayFrame.bottom};
1144
1145 uint32_t color = layer->transform;
1146 copybit_device_t *copybit = mEngine;
1147 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
1148 renderBuffer->width);
1149 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
1150 renderBuffer->height);
1151 copybit->set_parameter(copybit, COPYBIT_DITHER,
1152 (dst.format == HAL_PIXEL_FORMAT_RGB_565) ?
1153 COPYBIT_ENABLE : COPYBIT_DISABLE);
Sushil Chauhan2babecc2013-12-04 17:29:48 -08001154 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
Sushil Chauhan943797c2013-10-21 17:35:55 -07001155 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, layer->blending);
1156 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, layer->planeAlpha);
1157 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_ENABLE);
1158 int res = copybit->fill_color(copybit, &dst, &dstRect, color);
1159 copybit->set_parameter(copybit,COPYBIT_BLIT_TO_FRAMEBUFFER,COPYBIT_DISABLE);
1160 return res;
1161}
1162
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001163void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -07001164 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001165{
1166 hwc_rect_t displayFrame = layer->displayFrame;
Dileep Kumar Reddiad376f12015-05-08 10:00:04 +05301167 hwc_rect_t result = getIntersection(mDirtyRect, displayFrame);
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001168
Dileep Kumar Reddiad376f12015-05-08 10:00:04 +05301169 width = result.right - result.left;
1170 height = result.bottom - result.top;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001171}
1172
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001173bool CopyBit::validateParams(hwc_context_t *ctx,
1174 const hwc_display_contents_1_t *list) {
1175 //Validate parameters
1176 if (!ctx) {
1177 ALOGE("%s:Invalid HWC context", __FUNCTION__);
1178 return false;
1179 } else if (!list) {
1180 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
1181 return false;
1182 }
1183 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001184}
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001185
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001186
Naseer Ahmed64b81212013-02-14 10:29:47 -05001187int CopyBit::allocRenderBuffers(int w, int h, int f)
1188{
1189 int ret = 0;
1190 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1191 if (mRenderBuffer[i] == NULL) {
1192 ret = alloc_buffer(&mRenderBuffer[i],
Naseer Ahmed8d0d72a2014-12-19 16:25:09 -05001193 w, h, f, 0);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001194 }
1195 if(ret < 0) {
1196 freeRenderBuffers();
1197 break;
1198 }
1199 }
1200 return ret;
1201}
1202
1203void CopyBit::freeRenderBuffers()
1204{
1205 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
1206 if(mRenderBuffer[i]) {
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301207 //Since we are freeing buffer close the fence if it has a valid one.
1208 if(mRelFd[i] >= 0) {
1209 close(mRelFd[i]);
1210 mRelFd[i] = -1;
1211 }
Naseer Ahmed64b81212013-02-14 10:29:47 -05001212 free_buffer(mRenderBuffer[i]);
1213 mRenderBuffer[i] = NULL;
1214 }
1215 }
1216}
1217
1218private_handle_t * CopyBit::getCurrentRenderBuffer() {
1219 return mRenderBuffer[mCurRenderBufferIndex];
1220}
1221
1222void CopyBit::setReleaseFd(int fd) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001223 if (mRelFd[mCurRenderBufferIndex] >=0) {
1224 int ret = -1;
1225 ret = sync_wait(mRelFd[mCurRenderBufferIndex], 1000);
1226 if (ret < 0)
1227 ALOGE("%s: sync_wait error! errno = %d, err str = %s",
1228 __FUNCTION__, errno, strerror(errno));
1229 close(mRelFd[mCurRenderBufferIndex]);
1230 }
1231 mRelFd[mCurRenderBufferIndex] = dup(fd);
1232}
1233
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001234struct copybit_device_t* CopyBit::getCopyBitDevice() {
1235 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001236}
1237
Shalaj Jaina70b4352014-06-15 13:47:47 -07001238CopyBit::CopyBit(hwc_context_t *ctx, const int& dpy) : mEngine(0),
1239 mIsModeOn(false), mCopyBitDraw(false), mCurRenderBufferIndex(0) {
Saurabh Shah220a30c2013-10-29 16:12:12 -07001240
1241 getBufferSizeAndDimensions(ctx->dpyAttr[dpy].xres,
1242 ctx->dpyAttr[dpy].yres,
1243 HAL_PIXEL_FORMAT_RGBA_8888,
Sushil Chauhandefd3522014-05-13 18:17:12 -07001244 mAlignedWidth,
1245 mAlignedHeight);
Saurabh Shah220a30c2013-10-29 16:12:12 -07001246
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001247 hw_module_t const *module;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301248 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001249 mRenderBuffer[i] = NULL;
Prabhanjan Kandula5719da42013-11-01 00:14:04 +05301250 mRelFd[i] = -1;
1251 }
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +05301252
1253 char value[PROPERTY_VALUE_MAX];
1254 property_get("debug.hwc.dynThreshold", value, "2");
1255 mDynThreshold = atof(value);
1256
Ramakant Singh21cec722014-03-07 19:11:45 +05301257 property_get("debug.sf.swaprect", value, "0");
1258 mSwapRectEnable = atoi(value) ? true:false ;
1259 mDirtyLayerIndex = -1;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001260 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001261 if(copybit_open(module, &mEngine) < 0) {
1262 ALOGE("FATAL ERROR: copybit open failed.");
1263 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001264 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001265 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001266 }
1267}
Saurabh Shah661a58f2012-08-30 15:30:49 -07001268
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001269CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001270{
Naseer Ahmed64b81212013-02-14 10:29:47 -05001271 freeRenderBuffers();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001272 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001273 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001274 copybit_close(mEngine);
1275 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001276 }
1277}
Ramakant Singh21cec722014-03-07 19:11:45 +05301278CopyBit::LayerCache::LayerCache() {
1279 reset();
1280}
1281void CopyBit::LayerCache::reset() {
1282 memset(&hnd, 0, sizeof(hnd));
1283 layerCount = 0;
1284}
1285void CopyBit::LayerCache::updateCounts(hwc_context_t *ctx,
1286 hwc_display_contents_1_t *list, int dpy)
1287{
1288 layerCount = ctx->listStats[dpy].numAppLayers;
1289 for (int i=0; i<ctx->listStats[dpy].numAppLayers; i++){
1290 hnd[i] = list->hwLayers[i].handle;
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +05301291 displayFrame[i] = list->hwLayers[i].displayFrame;
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +05301292 drop[i] = ctx->copybitDrop[i];
Ramakant Singh21cec722014-03-07 19:11:45 +05301293 }
1294}
1295
1296CopyBit::FbCache::FbCache() {
1297 reset();
1298}
1299void CopyBit::FbCache::reset() {
1300 memset(&FbdirtyRect, 0, sizeof(FbdirtyRect));
Ramakant Singh19ead272015-03-18 14:11:31 +05301301 memset(&FbdisplayRect, 0, sizeof(FbdisplayRect));
Ramakant Singh21cec722014-03-07 19:11:45 +05301302 FbIndex =0;
1303}
1304
Ramakant Singh19ead272015-03-18 14:11:31 +05301305void CopyBit::FbCache::insertAndUpdateFbCache(hwc_rect_t dirtyRect,
1306 hwc_rect_t displayRect) {
Ramakant Singh21cec722014-03-07 19:11:45 +05301307 FbIndex = FbIndex % NUM_RENDER_BUFFERS;
1308 FbdirtyRect[FbIndex] = dirtyRect;
Ramakant Singh19ead272015-03-18 14:11:31 +05301309 FbdisplayRect[FbIndex] = displayRect;
Ramakant Singh21cec722014-03-07 19:11:45 +05301310 FbIndex++;
1311}
1312
Ramakant Singh19ead272015-03-18 14:11:31 +05301313int CopyBit::FbCache::getUnchangedFbDRCount(hwc_rect_t dirtyRect,
1314 hwc_rect_t displayRect){
Ramakant Singh21cec722014-03-07 19:11:45 +05301315 int sameDirtyCount = 0;
1316 for (int i = 0 ; i < NUM_RENDER_BUFFERS ; i++ ){
Ramakant Singh19ead272015-03-18 14:11:31 +05301317 if( FbdirtyRect[i] == dirtyRect &&
1318 FbdisplayRect[i] == displayRect)
Ramakant Singh21cec722014-03-07 19:11:45 +05301319 sameDirtyCount++;
1320 }
1321 return sameDirtyCount;
1322}
1323
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001324}; //namespace qhwc