Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 4 | * |
| 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 Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 21 | #define DEBUG_COPYBIT 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <copybit.h> |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 23 | #include <utils/Timers.h> |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 24 | #include "hwc_copybit.h" |
| 25 | #include "comptype.h" |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 26 | |
| 27 | namespace qhwc { |
| 28 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 29 | struct range { |
| 30 | int current; |
| 31 | int end; |
| 32 | }; |
| 33 | struct region_iterator : public copybit_region_t { |
| 34 | |
| 35 | region_iterator(hwc_region_t region) { |
| 36 | mRegion = region; |
| 37 | r.end = region.numRects; |
| 38 | r.current = 0; |
| 39 | this->next = iterate; |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | static int iterate(copybit_region_t const * self, copybit_rect_t* rect){ |
| 44 | if (!self || !rect) { |
| 45 | ALOGE("iterate invalid parameters"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | region_iterator const* me = |
| 50 | static_cast<region_iterator const*>(self); |
| 51 | if (me->r.current != me->r.end) { |
| 52 | rect->l = me->mRegion.rects[me->r.current].left; |
| 53 | rect->t = me->mRegion.rects[me->r.current].top; |
| 54 | rect->r = me->mRegion.rects[me->r.current].right; |
| 55 | rect->b = me->mRegion.rects[me->r.current].bottom; |
| 56 | me->r.current++; |
| 57 | return 1; |
| 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | hwc_region_t mRegion; |
| 63 | mutable range r; |
| 64 | }; |
| 65 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 66 | void CopyBit::reset() { |
| 67 | mIsModeOn = false; |
| 68 | mCopyBitDraw = false; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 71 | bool CopyBit::canUseCopybitForYUV(hwc_context_t *ctx) { |
| 72 | // return true for non-overlay targets |
| 73 | if(ctx->mMDP.hasOverlay) { |
| 74 | return false; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 75 | } |
| 76 | return true; |
| 77 | } |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 78 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 79 | bool CopyBit::canUseCopybitForRGB(hwc_context_t *ctx, |
| 80 | hwc_display_contents_1_t *list, |
| 81 | int dpy) { |
| 82 | int compositionType = qdutils::QCCompositionType:: |
| 83 | getInstance().getCompositionType(); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 84 | |
| 85 | if ((compositionType & qdutils::COMPOSITION_TYPE_C2D) || |
| 86 | (compositionType & qdutils::COMPOSITION_TYPE_DYN)) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 87 | if(ctx->listStats[dpy].yuvCount) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 88 | //Overlay up & running. Dont use COPYBIT for RGB layers. |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (compositionType & qdutils::COMPOSITION_TYPE_DYN) { |
| 94 | // DYN Composition: |
| 95 | // use copybit, if (TotalRGBRenderArea < 2 * FB Area) |
| 96 | // this is done based on perf inputs in ICS |
| 97 | // TODO: Above condition needs to be re-evaluated in JB |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 98 | int fbWidth = ctx->dpyAttr[dpy].xres; |
| 99 | int fbHeight = ctx->dpyAttr[dpy].yres; |
| 100 | unsigned int fbArea = (fbWidth * fbHeight); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 101 | unsigned int renderArea = getRGBRenderingArea(list); |
| 102 | ALOGD_IF (DEBUG_COPYBIT, "%s:renderArea %u, fbArea %u", |
| 103 | __FUNCTION__, renderArea, fbArea); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 104 | if (renderArea <= (2 * fbArea)) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | } else if ((compositionType & qdutils::COMPOSITION_TYPE_MDP)) { |
| 108 | // MDP composition, use COPYBIT always |
| 109 | return true; |
| 110 | } else if ((compositionType & qdutils::COMPOSITION_TYPE_C2D)) { |
| 111 | // C2D composition, use COPYBIT |
| 112 | return true; |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 117 | unsigned int CopyBit::getRGBRenderingArea |
| 118 | (const hwc_display_contents_1_t *list) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 119 | //Calculates total rendering area for RGB layers |
| 120 | unsigned int renderArea = 0; |
| 121 | unsigned int w=0, h=0; |
| 122 | for (unsigned int i=0; i<list->numHwLayers; i++) { |
| 123 | private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle; |
| 124 | if (hnd) { |
| 125 | if (BUFFER_TYPE_UI == hnd->bufferType) { |
| 126 | getLayerResolution(&list->hwLayers[i], w, h); |
| 127 | renderArea += (w*h); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | return renderArea; |
| 132 | } |
| 133 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 134 | bool CopyBit::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 135 | int dpy) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 136 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 137 | if(mEngine == NULL) { |
| 138 | // No copybit device found - cannot use copybit |
| 139 | return false; |
| 140 | } |
| 141 | int compositionType = qdutils::QCCompositionType:: |
| 142 | getInstance().getCompositionType(); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 143 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 144 | if ((compositionType == qdutils::COMPOSITION_TYPE_GPU) || |
| 145 | (compositionType == qdutils::COMPOSITION_TYPE_CPU)) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 146 | //GPU/CPU composition, don't change layer composition type |
| 147 | return true; |
| 148 | } |
| 149 | |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 150 | if(!(validateParams(ctx, list))) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 151 | ALOGE("%s:Invalid Params", __FUNCTION__); |
| 152 | return false; |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 155 | if(ctx->listStats[dpy].skipCount) { |
| 156 | //GPU will be anyways used |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | bool useCopybitForYUV = canUseCopybitForYUV(ctx); |
| 161 | bool useCopybitForRGB = canUseCopybitForRGB(ctx, list, dpy); |
| 162 | |
| 163 | // numAppLayers-1, as we iterate till 0th layer index |
| 164 | for (int i = ctx->listStats[dpy].numAppLayers-1; i >= 0 ; i--) { |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 165 | private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle; |
| 166 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 167 | if (hnd->bufferType == BUFFER_TYPE_VIDEO) { |
| 168 | //YUV layer, check, if copybit can be used |
| 169 | // mark the video layer to gpu when all layer is |
| 170 | // going to gpu in case of dynamic composition. |
| 171 | if (useCopybitForYUV) { |
| 172 | list->hwLayers[i].compositionType = HWC_BLIT; |
| 173 | mCopyBitDraw = true; |
| 174 | } |
| 175 | } else if (hnd->bufferType == BUFFER_TYPE_UI) { |
| 176 | //RGB layer, check, if copybit can be used |
| 177 | if (useCopybitForRGB) { |
| 178 | ALOGD_IF(DEBUG_COPYBIT, "%s: Marking layer[%d] for copybit for" |
| 179 | "dpy[%d] ", __FUNCTION__, i, dpy); |
| 180 | list->hwLayers[i].compositionType = HWC_BLIT; |
| 181 | mCopyBitDraw = true; |
| 182 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | return true; |
| 186 | } |
| 187 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 188 | bool CopyBit::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 189 | int dpy, int32_t *fd) { |
| 190 | // draw layers marked for COPYBIT |
| 191 | int retVal = true; |
| 192 | int copybitLayerCount = 0; |
| 193 | |
| 194 | if(mCopyBitDraw == false) // there is no layer marked for copybit |
| 195 | return true ; |
| 196 | |
| 197 | size_t fbLayerIndex = ctx->listStats[dpy].fbLayerIndex; |
| 198 | hwc_layer_1_t *fbLayer = &list->hwLayers[fbLayerIndex]; |
| 199 | //render buffer |
| 200 | private_handle_t *renderBuffer = (private_handle_t *)fbLayer->handle; |
| 201 | if (!renderBuffer) { |
| 202 | ALOGE("%s: HWC_FRAMEBUFFER_TARGET layer handle is NULL", __FUNCTION__); |
| 203 | return false; |
| 204 | } |
| 205 | // numAppLayers-1, as we iterate from 0th layer index with HWC_BLIT flag |
| 206 | for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) { |
| 207 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
| 208 | if(!list->hwLayers[i].compositionType == HWC_BLIT) { |
| 209 | ALOGD_IF(DEBUG_COPYBIT, "%s: Not Marked for C2D", __FUNCTION__); |
| 210 | continue; |
| 211 | } |
| 212 | int ret = -1; |
| 213 | if (list->hwLayers[i].acquireFenceFd != -1 ) { |
| 214 | // Wait for acquire Fence on the App buffers. |
| 215 | ret = sync_wait(list->hwLayers[i].acquireFenceFd, 1000); |
| 216 | if(ret < 0) { |
| 217 | ALOGE("%s: sync_wait error!! error no = %d err str = %s", |
| 218 | __FUNCTION__, errno, strerror(errno)); |
| 219 | } |
| 220 | close(list->hwLayers[i].acquireFenceFd); |
| 221 | list->hwLayers[i].acquireFenceFd = -1; |
| 222 | } |
| 223 | retVal = drawLayerUsingCopybit(ctx, &(list->hwLayers[i]), |
| 224 | renderBuffer, dpy); |
| 225 | copybitLayerCount++; |
| 226 | if(retVal < 0) { |
| 227 | ALOGE("%s : drawLayerUsingCopybit failed", __FUNCTION__); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (copybitLayerCount) { |
| 232 | copybit_device_t *copybit = getCopyBitDevice(); |
| 233 | // Async mode |
| 234 | copybit->flush_get_fence(copybit, fd); |
| 235 | } |
| 236 | return true; |
| 237 | } |
| 238 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 239 | int CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 240 | private_handle_t *renderBuffer, int dpy) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 241 | { |
| 242 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 243 | int err = 0; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 244 | if(!ctx) { |
| 245 | ALOGE("%s: null context ", __FUNCTION__); |
| 246 | return -1; |
| 247 | } |
| 248 | |
| 249 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 250 | if(!hnd) { |
| 251 | ALOGE("%s: invalid handle", __FUNCTION__); |
| 252 | return -1; |
| 253 | } |
| 254 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 255 | private_handle_t *fbHandle = (private_handle_t *)renderBuffer; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 256 | if(!fbHandle) { |
| 257 | ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | // Set the copybit source: |
| 262 | copybit_image_t src; |
| 263 | src.w = hnd->width; |
| 264 | src.h = hnd->height; |
| 265 | src.format = hnd->format; |
| 266 | src.base = (void *)hnd->base; |
| 267 | src.handle = (native_handle_t *)layer->handle; |
| 268 | src.horiz_padding = src.w - hnd->width; |
| 269 | // Initialize vertical padding to zero for now, |
| 270 | // this needs to change to accomodate vertical stride |
| 271 | // if needed in the future |
| 272 | src.vert_padding = 0; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 273 | |
| 274 | // Copybit source rect |
| 275 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 276 | copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top, |
| 277 | sourceCrop.right, |
| 278 | sourceCrop.bottom}; |
| 279 | |
| 280 | // Copybit destination rect |
| 281 | hwc_rect_t displayFrame = layer->displayFrame; |
| 282 | copybit_rect_t dstRect = {displayFrame.left, displayFrame.top, |
| 283 | displayFrame.right, |
| 284 | displayFrame.bottom}; |
| 285 | |
| 286 | // Copybit dst |
| 287 | copybit_image_t dst; |
| 288 | dst.w = ALIGN(fbHandle->width,32); |
| 289 | dst.h = fbHandle->height; |
| 290 | dst.format = fbHandle->format; |
| 291 | dst.base = (void *)fbHandle->base; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 292 | dst.handle = (native_handle_t *)fbHandle; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 293 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 294 | copybit_device_t *copybit = mEngine; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 295 | |
| 296 | int32_t screen_w = displayFrame.right - displayFrame.left; |
| 297 | int32_t screen_h = displayFrame.bottom - displayFrame.top; |
| 298 | int32_t src_crop_width = sourceCrop.right - sourceCrop.left; |
| 299 | int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top; |
| 300 | |
| 301 | // Copybit dst |
| 302 | float copybitsMaxScale = |
| 303 | (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT); |
| 304 | float copybitsMinScale = |
| 305 | (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT); |
| 306 | |
| 307 | if((layer->transform == HWC_TRANSFORM_ROT_90) || |
| 308 | (layer->transform == HWC_TRANSFORM_ROT_270)) { |
| 309 | //swap screen width and height |
| 310 | int tmp = screen_w; |
| 311 | screen_w = screen_h; |
| 312 | screen_h = tmp; |
| 313 | } |
| 314 | private_handle_t *tmpHnd = NULL; |
| 315 | |
| 316 | if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) { |
| 317 | ALOGE("%s: wrong params for display screen_w=%d src_crop_width=%d \ |
| 318 | screen_w=%d src_crop_width=%d", __FUNCTION__, screen_w, |
| 319 | src_crop_width,screen_w,src_crop_width); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | float dsdx = (float)screen_w/src_crop_width; |
| 324 | float dtdy = (float)screen_h/src_crop_height; |
| 325 | |
| 326 | float scaleLimitMax = copybitsMaxScale * copybitsMaxScale; |
| 327 | float scaleLimitMin = copybitsMinScale * copybitsMinScale; |
| 328 | if(dsdx > scaleLimitMax || |
| 329 | dtdy > scaleLimitMax || |
| 330 | dsdx < 1/scaleLimitMin || |
| 331 | dtdy < 1/scaleLimitMin) { |
| 332 | ALOGE("%s: greater than max supported size dsdx=%f dtdy=%f \ |
| 333 | scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy, |
| 334 | scaleLimitMax,1/scaleLimitMin); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 335 | return -1; |
| 336 | } |
| 337 | if(dsdx > copybitsMaxScale || |
| 338 | dtdy > copybitsMaxScale || |
| 339 | dsdx < 1/copybitsMinScale || |
| 340 | dtdy < 1/copybitsMinScale){ |
| 341 | // The requested scale is out of the range the hardware |
| 342 | // can support. |
| 343 | ALOGE("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,\ |
| 344 | copybitsMinScale=%f,screen_w=%d,screen_h=%d \ |
| 345 | src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__, |
| 346 | dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h, |
| 347 | src_crop_width,src_crop_height); |
| 348 | |
| 349 | //Driver makes width and height as even |
| 350 | //that may cause wrong calculation of the ratio |
| 351 | //in display and crop.Hence we make |
| 352 | //crop width and height as even. |
| 353 | src_crop_width = (src_crop_width/2)*2; |
| 354 | src_crop_height = (src_crop_height/2)*2; |
| 355 | |
| 356 | int tmp_w = src_crop_width; |
| 357 | int tmp_h = src_crop_height; |
| 358 | |
| 359 | if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){ |
| 360 | tmp_w = src_crop_width*copybitsMaxScale; |
| 361 | tmp_h = src_crop_height*copybitsMaxScale; |
| 362 | }else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){ |
| 363 | tmp_w = src_crop_width/copybitsMinScale; |
| 364 | tmp_h = src_crop_height/copybitsMinScale; |
| 365 | tmp_w = (tmp_w/2)*2; |
| 366 | tmp_h = (tmp_h/2)*2; |
| 367 | } |
| 368 | ALOGE("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h); |
| 369 | |
| 370 | int usage = GRALLOC_USAGE_PRIVATE_MM_HEAP; |
| 371 | |
| 372 | if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, fbHandle->format, usage)){ |
| 373 | copybit_image_t tmp_dst; |
| 374 | copybit_rect_t tmp_rect; |
| 375 | tmp_dst.w = tmp_w; |
| 376 | tmp_dst.h = tmp_h; |
| 377 | tmp_dst.format = tmpHnd->format; |
| 378 | tmp_dst.handle = tmpHnd; |
| 379 | tmp_dst.horiz_padding = src.horiz_padding; |
| 380 | tmp_dst.vert_padding = src.vert_padding; |
| 381 | tmp_rect.l = 0; |
| 382 | tmp_rect.t = 0; |
| 383 | tmp_rect.r = tmp_dst.w; |
| 384 | tmp_rect.b = tmp_dst.h; |
| 385 | //create one clip region |
| 386 | hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b}; |
| 387 | hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect}; |
| 388 | region_iterator tmp_it(tmp_hwc_reg); |
| 389 | copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 390 | //TODO: once, we are able to read layer alpha, update this |
| 391 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 392 | err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect, |
| 393 | &srcRect, &tmp_it); |
| 394 | if(err < 0){ |
| 395 | ALOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__, |
| 396 | __LINE__); |
| 397 | if(tmpHnd) |
| 398 | free_buffer(tmpHnd); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 399 | return err; |
| 400 | } |
| 401 | // copy new src and src rect crop |
| 402 | src = tmp_dst; |
| 403 | srcRect = tmp_rect; |
| 404 | } |
| 405 | } |
| 406 | // Copybit region |
| 407 | hwc_region_t region = layer->visibleRegionScreen; |
| 408 | region_iterator copybitRegion(region); |
| 409 | |
| 410 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH, |
| 411 | renderBuffer->width); |
| 412 | copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT, |
| 413 | renderBuffer->height); |
| 414 | copybit->set_parameter(copybit, COPYBIT_TRANSFORM, |
| 415 | layer->transform); |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 416 | //TODO: once, we are able to read layer alpha, update this |
| 417 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 255); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 418 | copybit->set_parameter(copybit, COPYBIT_BLEND_MODE, |
| 419 | layer->blending); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 420 | copybit->set_parameter(copybit, COPYBIT_DITHER, |
| 421 | (dst.format == HAL_PIXEL_FORMAT_RGB_565)? |
| 422 | COPYBIT_ENABLE : COPYBIT_DISABLE); |
| 423 | copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER, |
| 424 | COPYBIT_ENABLE); |
| 425 | err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect, |
| 426 | ©bitRegion); |
| 427 | copybit->set_parameter(copybit, COPYBIT_BLIT_TO_FRAMEBUFFER, |
| 428 | COPYBIT_DISABLE); |
| 429 | |
| 430 | if(tmpHnd) |
| 431 | free_buffer(tmpHnd); |
| 432 | |
| 433 | if(err < 0) |
| 434 | ALOGE("%s: copybit stretch failed",__FUNCTION__); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 435 | return err; |
| 436 | } |
| 437 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 438 | void CopyBit::getLayerResolution(const hwc_layer_1_t* layer, |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 439 | unsigned int& width, unsigned int& height) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 440 | { |
| 441 | hwc_rect_t displayFrame = layer->displayFrame; |
| 442 | |
| 443 | width = displayFrame.right - displayFrame.left; |
| 444 | height = displayFrame.bottom - displayFrame.top; |
| 445 | } |
| 446 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 447 | bool CopyBit::validateParams(hwc_context_t *ctx, |
| 448 | const hwc_display_contents_1_t *list) { |
| 449 | //Validate parameters |
| 450 | if (!ctx) { |
| 451 | ALOGE("%s:Invalid HWC context", __FUNCTION__); |
| 452 | return false; |
| 453 | } else if (!list) { |
| 454 | ALOGE("%s:Invalid HWC layer list", __FUNCTION__); |
| 455 | return false; |
| 456 | } |
| 457 | return true; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 458 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 459 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 460 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 461 | struct copybit_device_t* CopyBit::getCopyBitDevice() { |
| 462 | return mEngine; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 465 | CopyBit::CopyBit():mIsModeOn(false), mCopyBitDraw(false){ |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 466 | hw_module_t const *module; |
| 467 | if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 468 | if(copybit_open(module, &mEngine) < 0) { |
| 469 | ALOGE("FATAL ERROR: copybit open failed."); |
| 470 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 471 | } else { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 472 | ALOGE("FATAL ERROR: copybit hw module not found"); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
Saurabh Shah | 661a58f | 2012-08-30 15:30:49 -0700 | [diff] [blame] | 475 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 476 | CopyBit::~CopyBit() |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 477 | { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 478 | if(mEngine) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 479 | { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 480 | copybit_close(mEngine); |
| 481 | mEngine = NULL; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 484 | }; //namespace qhwc |