blob: 3f40753733f0c093da2eebf769a14caf1bb7d39d [file] [log] [blame]
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08003 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed31da0b12012-07-31 18:55:33 -07004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Naseer Ahmed45a99602012-07-31 19:15:24 -070021#define DEBUG_COPYBIT 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <copybit.h>
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080023#include <utils/Timers.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"
Naseer Ahmed74214722013-02-09 08:11:36 -050027
Naseer Ahmed31da0b12012-07-31 18:55:33 -070028namespace qhwc {
29
Naseer Ahmed31da0b12012-07-31 18:55:33 -070030struct range {
31 int current;
32 int end;
33};
34struct region_iterator : public copybit_region_t {
35
36 region_iterator(hwc_region_t region) {
37 mRegion = region;
38 r.end = region.numRects;
39 r.current = 0;
40 this->next = iterate;
41 }
42
43private:
44 static int iterate(copybit_region_t const * self, copybit_rect_t* rect){
45 if (!self || !rect) {
46 ALOGE("iterate invalid parameters");
47 return 0;
48 }
49
50 region_iterator const* me =
51 static_cast<region_iterator const*>(self);
52 if (me->r.current != me->r.end) {
53 rect->l = me->mRegion.rects[me->r.current].left;
54 rect->t = me->mRegion.rects[me->r.current].top;
55 rect->r = me->mRegion.rects[me->r.current].right;
56 rect->b = me->mRegion.rects[me->r.current].bottom;
57 me->r.current++;
58 return 1;
59 }
60 return 0;
61 }
62
63 hwc_region_t mRegion;
64 mutable range r;
65};
66
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080067void CopyBit::reset() {
68 mIsModeOn = false;
69 mCopyBitDraw = false;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070070}
71
Naseer Ahmed45a99602012-07-31 19:15:24 -070072bool CopyBit::canUseCopybitForYUV(hwc_context_t *ctx) {
73 // return true for non-overlay targets
74 if(ctx->mMDP.hasOverlay) {
75 return false;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070076 }
77 return true;
78}
Naseer Ahmed45a99602012-07-31 19:15:24 -070079
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080080bool CopyBit::canUseCopybitForRGB(hwc_context_t *ctx,
81 hwc_display_contents_1_t *list,
82 int dpy) {
83 int compositionType = qdutils::QCCompositionType::
84 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -070085
86 if ((compositionType & qdutils::COMPOSITION_TYPE_C2D) ||
87 (compositionType & qdutils::COMPOSITION_TYPE_DYN)) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080088 if(ctx->listStats[dpy].yuvCount) {
Naseer Ahmed45a99602012-07-31 19:15:24 -070089 //Overlay up & running. Dont use COPYBIT for RGB layers.
Naseer Ahmed45a99602012-07-31 19:15:24 -070090 return false;
91 }
92 }
93
94 if (compositionType & qdutils::COMPOSITION_TYPE_DYN) {
95 // DYN Composition:
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +053096 // use copybit, if (TotalRGBRenderArea < threashold * FB Area)
Naseer Ahmed45a99602012-07-31 19:15:24 -070097 // this is done based on perf inputs in ICS
98 // TODO: Above condition needs to be re-evaluated in JB
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080099 int fbWidth = ctx->dpyAttr[dpy].xres;
100 int fbHeight = ctx->dpyAttr[dpy].yres;
101 unsigned int fbArea = (fbWidth * fbHeight);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700102 unsigned int renderArea = getRGBRenderingArea(list);
103 ALOGD_IF (DEBUG_COPYBIT, "%s:renderArea %u, fbArea %u",
104 __FUNCTION__, renderArea, fbArea);
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530105 if (renderArea < (mDynThreshold * fbArea)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700106 return true;
107 }
108 } else if ((compositionType & qdutils::COMPOSITION_TYPE_MDP)) {
109 // MDP composition, use COPYBIT always
110 return true;
111 } else if ((compositionType & qdutils::COMPOSITION_TYPE_C2D)) {
112 // C2D composition, use COPYBIT
113 return true;
114 }
115 return false;
116}
117
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800118unsigned int CopyBit::getRGBRenderingArea
119 (const hwc_display_contents_1_t *list) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700120 //Calculates total rendering area for RGB layers
121 unsigned int renderArea = 0;
122 unsigned int w=0, h=0;
123 for (unsigned int i=0; i<list->numHwLayers; i++) {
124 private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
125 if (hnd) {
126 if (BUFFER_TYPE_UI == hnd->bufferType) {
127 getLayerResolution(&list->hwLayers[i], w, h);
128 renderArea += (w*h);
129 }
130 }
131 }
132 return renderArea;
133}
134
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800135bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
136 int dpy) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700137
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800138 if(mEngine == NULL) {
139 // No copybit device found - cannot use copybit
140 return false;
141 }
142 int compositionType = qdutils::QCCompositionType::
143 getInstance().getCompositionType();
Naseer Ahmed45a99602012-07-31 19:15:24 -0700144
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800145 if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) ||
146 (compositionType == qdutils::COMPOSITION_TYPE_CPU)) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700147 //GPU/CPU composition, don't change layer composition type
148 return true;
149 }
150
Naseer Ahmed45a99602012-07-31 19:15:24 -0700151 if(!(validateParams(ctx, list))) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800152 ALOGE("%s:Invalid Params", __FUNCTION__);
153 return false;
Naseer Ahmed45a99602012-07-31 19:15:24 -0700154 }
155
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800156 if(ctx->listStats[dpy].skipCount) {
157 //GPU will be anyways used
158 return false;
159 }
160
161 bool useCopybitForYUV = canUseCopybitForYUV(ctx);
162 bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500163 LayerProp *layerProp = ctx->layerProp[dpy];
164 size_t fbLayerIndex = ctx->listStats[dpy].fbLayerIndex;
165 hwc_layer_1_t *fbLayer = &list->hwLayers[fbLayerIndex];
166 private_handle_t *fbHnd = (private_handle_t *)fbLayer->handle;
167
168
169
170 //Allocate render buffers if they're not allocated
171 if (useCopybitForYUV || useCopybitForRGB) {
172 int ret = allocRenderBuffers(fbHnd->width,
173 fbHnd->height,
174 fbHnd->format);
175 if (ret < 0) {
176 return false;
177 } else {
178 mCurRenderBufferIndex = (mCurRenderBufferIndex + 1) %
179 NUM_RENDER_BUFFERS;
180 }
181 }
182
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800183
184 // numAppLayers-1, as we iterate till 0th layer index
185 for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) {
Naseer Ahmed45a99602012-07-31 19:15:24 -0700186 private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
187
Naseer Ahmed64b81212013-02-14 10:29:47 -0500188 if ((hnd->bufferType == BUFFER_TYPE_VIDEO && useCopybitForYUV) ||
189 (hnd->bufferType == BUFFER_TYPE_UI && useCopybitForRGB)) {
190 layerProp[i].mFlags |= HWC_COPYBIT;
191 list->hwLayers[i].compositionType = HWC_OVERLAY;
192 mCopyBitDraw = true;
193 } else {
194 // We currently cannot mix copybit layers with layers marked to
195 // be drawn on the framebuffer or that are on the layer cache.
196 mCopyBitDraw = false;
197 //There is no need to reset layer properties here as we return in
198 //draw if mCopyBitDraw is false
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700199 }
200 }
201 return true;
202}
203
Naseer Ahmed183939d2013-03-14 20:44:17 -0400204int CopyBit::clear (private_handle_t* hnd, hwc_rect_t& rect)
205{
206 int ret = 0;
207 copybit_rect_t clear_rect = {rect.left, rect.top,
208 rect.right,
209 rect.bottom};
210
211 copybit_image_t buf;
212 buf.w = ALIGN(hnd->width,32);
213 buf.h = hnd->height;
214 buf.format = hnd->format;
215 buf.base = (void *)hnd->base;
216 buf.handle = (native_handle_t *)hnd;
217
218 copybit_device_t *copybit = mEngine;
219 ret = copybit->clear(copybit, &buf, &clear_rect);
220 return ret;
221}
222
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800223bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
224 int dpy, int32_t *fd) {
225 // draw layers marked for COPYBIT
226 int retVal = true;
227 int copybitLayerCount = 0;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500228 LayerProp *layerProp = ctx->layerProp[dpy];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800229
230 if(mCopyBitDraw == false) // there is no layer marked for copybit
Naseer Ahmed64b81212013-02-14 10:29:47 -0500231 return false ;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800232
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800233 //render buffer
Naseer Ahmed64b81212013-02-14 10:29:47 -0500234 private_handle_t *renderBuffer = getCurrentRenderBuffer();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800235 if (!renderBuffer) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500236 ALOGE("%s: Render buffer layer handle is NULL", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800237 return false;
238 }
Naseer Ahmed64b81212013-02-14 10:29:47 -0500239
240 //Wait for the previous frame to complete before rendering onto it
241 if(mRelFd[0] >=0) {
242 sync_wait(mRelFd[0], 1000);
243 close(mRelFd[0]);
244 mRelFd[0] = -1;
245 }
Naseer Ahmed183939d2013-03-14 20:44:17 -0400246
247 //Clear the visible region on the render buffer
248 //XXX: Do this only when needed.
249 hwc_rect_t clearRegion;
250 getNonWormholeRegion(list, clearRegion);
251 clear(renderBuffer, clearRegion);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500252 // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800253 for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
254 hwc_layer_1_t *layer = &list->hwLayers[i];
Naseer Ahmed64b81212013-02-14 10:29:47 -0500255 if(!(layerProp[i].mFlags & HWC_COPYBIT)) {
256 ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for copybit", __FUNCTION__);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800257 continue;
258 }
259 int ret = -1;
260 if (list->hwLayers[i].acquireFenceFd != -1 ) {
261 // Wait for acquire Fence on the App buffers.
262 ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000);
263 if(ret < 0) {
264 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
265 __FUNCTION__, errno, strerror(errno));
266 }
267 close(list->hwLayers[i].acquireFenceFd);
268 list->hwLayers[i].acquireFenceFd = -1;
269 }
270 retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]),
271 renderBuffer, dpy);
272 copybitLayerCount++;
273 if(retVal < 0) {
274 ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__);
275 }
276 }
277
278 if (copybitLayerCount) {
279 copybit_device_t *copybit = getCopyBitDevice();
280 // Async mode
281 copybit->flush_get_fence(copybit, fd);
282 }
283 return true;
284}
285
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700286int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800287 private_handle_t *renderBuffer, int dpy)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700288{
289 hwc_context_t* ctx = (hwc_context_t*)(dev);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800290 int err = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700291 if(!ctx) {
292 ALOGE("%s: null context ", __FUNCTION__);
293 return -1;
294 }
295
296 private_handle_t *hnd = (private_handle_t *)layer->handle;
297 if(!hnd) {
298 ALOGE("%s: invalid handle", __FUNCTION__);
299 return -1;
300 }
301
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800302 private_handle_t *fbHandle = (private_handle_t *)renderBuffer;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700303 if(!fbHandle) {
304 ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700305 return -1;
306 }
307
308 // Set the copybit source:
309 copybit_image_t src;
310 src.w = hnd->width;
311 src.h = hnd->height;
312 src.format = hnd->format;
313 src.base = (void *)hnd->base;
314 src.handle = (native_handle_t *)layer->handle;
315 src.horiz_padding = src.w - hnd->width;
316 // Initialize vertical padding to zero for now,
317 // this needs to change to accomodate vertical stride
318 // if needed in the future
319 src.vert_padding = 0;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700320
321 // Copybit source rect
322 hwc_rect_t sourceCrop = layer->sourceCrop;
323 copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
324 sourceCrop.right,
325 sourceCrop.bottom};
326
327 // Copybit destination rect
328 hwc_rect_t displayFrame = layer->displayFrame;
329 copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
330 displayFrame.right,
331 displayFrame.bottom};
332
333 // Copybit dst
334 copybit_image_t dst;
335 dst.w = ALIGN(fbHandle->width,32);
336 dst.h = fbHandle->height;
337 dst.format = fbHandle->format;
338 dst.base = (void *)fbHandle->base;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800339 dst.handle = (native_handle_t *)fbHandle;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700340
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800341 copybit_device_t *copybit = mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700342
343 int32_t screen_w = displayFrame.right - displayFrame.left;
344 int32_t screen_h = displayFrame.bottom - displayFrame.top;
345 int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
346 int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
347
348 // Copybit dst
349 float copybitsMaxScale =
350 (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
351 float copybitsMinScale =
352 (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
353
354 if((layer->transform == HWC_TRANSFORM_ROT_90) ||
355 (layer->transform == HWC_TRANSFORM_ROT_270)) {
356 //swap screen width and height
357 int tmp = screen_w;
358 screen_w = screen_h;
359 screen_h = tmp;
360 }
361 private_handle_t *tmpHnd = NULL;
362
363 if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
364 ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \
365 screen_w=%d src_crop_width=%d", __FUNCTION__, screen_w,
366 src_crop_width,screen_w,src_crop_width);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700367 return -1;
368 }
369
370 float dsdx = (float)screen_w/src_crop_width;
371 float dtdy = (float)screen_h/src_crop_height;
372
373 float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
374 float scaleLimitMin = copybitsMinScale * copybitsMinScale;
375 if(dsdx > scaleLimitMax ||
376 dtdy > scaleLimitMax ||
377 dsdx < 1/scaleLimitMin ||
378 dtdy < 1/scaleLimitMin) {
379 ALOGE("%s: greater than max supported size dsdx=%f dtdy=%f \
380 scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,
381 scaleLimitMax,1/scaleLimitMin);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700382 return -1;
383 }
384 if(dsdx > copybitsMaxScale ||
385 dtdy > copybitsMaxScale ||
386 dsdx < 1/copybitsMinScale ||
387 dtdy < 1/copybitsMinScale){
388 // The requested scale is out of the range the hardware
389 // can support.
390 ALOGE("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\
391 copybitsMinScale=%f,screen_w=%d,screen_h=%d \
392 src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
393 dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,
394 src_crop_width,src_crop_height);
395
396 //Driver makes width and height as even
397 //that may cause wrong calculation of the ratio
398 //in display and crop.Hence we make
399 //crop width and height as even.
400 src_crop_width = (src_crop_width/2)*2;
401 src_crop_height = (src_crop_height/2)*2;
402
403 int tmp_w = src_crop_width;
404 int tmp_h = src_crop_height;
405
406 if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){
407 tmp_w = src_crop_width*copybitsMaxScale;
408 tmp_h = src_crop_height*copybitsMaxScale;
409 }else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){
410 tmp_w = src_crop_width/copybitsMinScale;
411 tmp_h = src_crop_height/copybitsMinScale;
412 tmp_w = (tmp_w/2)*2;
413 tmp_h = (tmp_h/2)*2;
414 }
415 ALOGE("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
416
Naseer Ahmed64b81212013-02-14 10:29:47 -0500417 int usage = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700418
419 if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, fbHandle->format, usage)){
420 copybit_image_t tmp_dst;
421 copybit_rect_t tmp_rect;
422 tmp_dst.w = tmp_w;
423 tmp_dst.h = tmp_h;
424 tmp_dst.format = tmpHnd->format;
425 tmp_dst.handle = tmpHnd;
426 tmp_dst.horiz_padding = src.horiz_padding;
427 tmp_dst.vert_padding = src.vert_padding;
428 tmp_rect.l = 0;
429 tmp_rect.t = 0;
430 tmp_rect.r = tmp_dst.w;
431 tmp_rect.b = tmp_dst.h;
432 //create one clip region
433 hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
434 hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
435 region_iterator tmp_it(tmp_hwc_reg);
436 copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700437 //TODO: once, we are able to read layer alpha, update this
438 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700439 err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect,
440 &srcRect, &tmp_it);
441 if(err < 0){
442 ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,
443 __LINE__);
444 if(tmpHnd)
445 free_buffer(tmpHnd);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700446 return err;
447 }
448 // copy new src and src rect crop
449 src = tmp_dst;
450 srcRect = tmp_rect;
451 }
452 }
453 // Copybit region
454 hwc_region_t region = layer->visibleRegionScreen;
455 region_iterator copybitRegion(region);
456
457 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH,
458 renderBuffer->width);
459 copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT,
460 renderBuffer->height);
461 copybit->set_parameter(copybit, COPYBIT_TRANSFORM,
462 layer->transform);
Naseer Ahmed45a99602012-07-31 19:15:24 -0700463 //TODO: once, we are able to read layer alpha, update this
464 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800465 copybit->set_parameter(copybit, COPYBIT_BLEND_MODE,
466 layer->blending);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700467 copybit->set_parameter(copybit, COPYBIT_DITHER,
468 (dst.format == HAL_PIXEL_FORMAT_RGB_565)?
469 COPYBIT_ENABLE : COPYBIT_DISABLE);
470 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
471 COPYBIT_ENABLE);
472 err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect,
473 &copybitRegion);
474 copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER,
475 COPYBIT_DISABLE);
476
477 if(tmpHnd)
478 free_buffer(tmpHnd);
479
480 if(err < 0)
481 ALOGE("%s: copybit stretch failed",__FUNCTION__);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700482 return err;
483}
484
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700485void CopyBit::getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -0700486 unsigned int& width, unsigned int& height)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700487{
488 hwc_rect_t displayFrame = layer->displayFrame;
489
490 width = displayFrame.right - displayFrame.left;
491 height = displayFrame.bottom - displayFrame.top;
492}
493
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800494bool CopyBit::validateParams(hwc_context_t *ctx,
495 const hwc_display_contents_1_t *list) {
496 //Validate parameters
497 if (!ctx) {
498 ALOGE("%s:Invalid HWC context", __FUNCTION__);
499 return false;
500 } else if (!list) {
501 ALOGE("%s:Invalid HWC layer list", __FUNCTION__);
502 return false;
503 }
504 return true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700505}
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700506
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700507
Naseer Ahmed64b81212013-02-14 10:29:47 -0500508int CopyBit::allocRenderBuffers(int w, int h, int f)
509{
510 int ret = 0;
511 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
512 if (mRenderBuffer[i] == NULL) {
513 ret = alloc_buffer(&mRenderBuffer[i],
514 w, h, f,
515 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP);
516 }
517 if(ret < 0) {
518 freeRenderBuffers();
519 break;
520 }
521 }
522 return ret;
523}
524
525void CopyBit::freeRenderBuffers()
526{
527 for (int i = 0; i < NUM_RENDER_BUFFERS; i++) {
528 if(mRenderBuffer[i]) {
529 free_buffer(mRenderBuffer[i]);
530 mRenderBuffer[i] = NULL;
531 }
532 }
533}
534
535private_handle_t * CopyBit::getCurrentRenderBuffer() {
536 return mRenderBuffer[mCurRenderBufferIndex];
537}
538
539void CopyBit::setReleaseFd(int fd) {
540 if(mRelFd[0] >=0)
541 close(mRelFd[0]);
542 mRelFd[0] = mRelFd[1];
543 mRelFd[1] = dup(fd);
544}
545
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800546struct copybit_device_t* CopyBit::getCopyBitDevice() {
547 return mEngine;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700548}
549
Naseer Ahmed64b81212013-02-14 10:29:47 -0500550CopyBit::CopyBit():mIsModeOn(false), mCopyBitDraw(false),
551 mCurRenderBufferIndex(0){
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700552 hw_module_t const *module;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500553 for (int i = 0; i < NUM_RENDER_BUFFERS; i++)
554 mRenderBuffer[i] = NULL;
555 mRelFd[0] = -1;
556 mRelFd[1] = -1;
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530557
558 char value[PROPERTY_VALUE_MAX];
559 property_get("debug.hwc.dynThreshold", value, "2");
560 mDynThreshold = atof(value);
561
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700562 if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800563 if(copybit_open(module, &mEngine) < 0) {
564 ALOGE("FATAL ERROR: copybit open failed.");
565 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700566 } else {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800567 ALOGE("FATAL ERROR: copybit hw module not found");
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700568 }
569}
Saurabh Shah661a58f2012-08-30 15:30:49 -0700570
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800571CopyBit::~CopyBit()
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700572{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500573 freeRenderBuffers();
574 if(mRelFd[0] >=0)
575 close(mRelFd[0]);
576 if(mRelFd[1] >=0)
577 close(mRelFd[1]);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800578 if(mEngine)
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700579 {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800580 copybit_close(mEngine);
581 mEngine = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700582 }
583}
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700584}; //namespace qhwc