codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * |
| 19 | * @author Rama, Meka(v.meka@samsung.com) |
| 20 | Sangwoo, Park(sw5771.park@samsung.com) |
| 21 | Jamie Oh (jung-min.oh@samsung.com) |
| 22 | * @date 2011-03-11 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/atomic.h> |
| 28 | #include <EGL/egl.h> |
| 29 | |
| 30 | #include "SecHWCUtils.h" |
| 31 | #include "gralloc_priv.h" |
| 32 | |
| 33 | #ifdef HWC_HWOVERLAY |
| 34 | #include <GLES/gl.h> |
| 35 | #endif |
| 36 | |
| 37 | //#define CHECK_EGL_FPS |
| 38 | #ifdef CHECK_EGL_FPS |
| 39 | extern void check_fps(); |
| 40 | #endif |
| 41 | |
| 42 | #if defined(BOARD_USES_HDMI) |
| 43 | #include "SecHdmiClient.h" |
| 44 | #include "SecTVOutService.h" |
| 45 | #include "SecHdmi.h" |
| 46 | |
| 47 | static int lcd_width, lcd_height; |
| 48 | static int prev_format = 0; |
| 49 | |
| 50 | #define CHECK_TIME_DEBUG 0 |
| 51 | #define SUPPORT_AUTO_UI_ROTATE |
| 52 | #endif |
| 53 | |
| 54 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 55 | struct hw_device_t** device); |
| 56 | |
| 57 | static struct hw_module_methods_t hwc_module_methods = { |
| 58 | open: hwc_device_open |
| 59 | }; |
| 60 | |
| 61 | hwc_module_t HAL_MODULE_INFO_SYM = { |
| 62 | common: { |
| 63 | tag: HARDWARE_MODULE_TAG, |
| 64 | version_major: 1, |
| 65 | version_minor: 0, |
| 66 | id: HWC_HARDWARE_MODULE_ID, |
| 67 | name: "Samsung S5PC21X hwcomposer module", |
| 68 | author: "SAMSUNG", |
| 69 | methods: &hwc_module_methods, |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | /*****************************************************************************/ |
| 74 | |
| 75 | static void dump_layer(hwc_layer_t const* l) { |
| 76 | LOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, " |
| 77 | "{%d,%d,%d,%d}, {%d,%d,%d,%d}", |
| 78 | l->compositionType, l->flags, l->handle, l->transform, l->blending, |
| 79 | l->sourceCrop.left, |
| 80 | l->sourceCrop.top, |
| 81 | l->sourceCrop.right, |
| 82 | l->sourceCrop.bottom, |
| 83 | l->displayFrame.left, |
| 84 | l->displayFrame.top, |
| 85 | l->displayFrame.right, |
| 86 | l->displayFrame.bottom); |
| 87 | } |
| 88 | |
| 89 | void calculate_rect(struct hwc_win_info_t *win, hwc_layer_t *cur, |
| 90 | sec_rect *rect) |
| 91 | { |
| 92 | rect->x = cur->displayFrame.left; |
| 93 | rect->y = cur->displayFrame.top; |
| 94 | rect->w = cur->displayFrame.right - cur->displayFrame.left; |
| 95 | rect->h = cur->displayFrame.bottom - cur->displayFrame.top; |
| 96 | |
| 97 | if (rect->x < 0) { |
| 98 | if (rect->w + rect->x > win->lcd_info.xres) |
| 99 | rect->w = win->lcd_info.xres; |
| 100 | else |
| 101 | rect->w = rect->w + rect->x; |
| 102 | rect->x = 0; |
| 103 | } else { |
| 104 | if (rect->w + rect->x > win->lcd_info.xres) |
| 105 | rect->w = win->lcd_info.xres - rect->x; |
| 106 | } |
| 107 | if (rect->y < 0) { |
| 108 | if (rect->h + rect->y > win->lcd_info.yres) |
| 109 | rect->h = win->lcd_info.yres; |
| 110 | else |
| 111 | rect->h = rect->h + rect->y; |
| 112 | rect->y = 0; |
| 113 | } else { |
| 114 | if (rect->h + rect->y > win->lcd_info.yres) |
| 115 | rect->h = win->lcd_info.yres - rect->y; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static int set_src_dst_img_rect(hwc_layer_t *cur, |
| 120 | struct hwc_win_info_t *win, |
| 121 | struct sec_img *src_img, |
| 122 | struct sec_img *dst_img, |
| 123 | struct sec_rect *src_rect, |
| 124 | struct sec_rect *dst_rect, |
| 125 | int win_idx) |
| 126 | { |
| 127 | private_handle_t *prev_handle = (private_handle_t *)(cur->handle); |
| 128 | sec_rect rect; |
| 129 | |
| 130 | /* 1. Set src_img from prev_handle */ |
| 131 | src_img->f_w = prev_handle->width; |
| 132 | src_img->f_h = prev_handle->height; |
| 133 | src_img->w = prev_handle->width; |
| 134 | src_img->h = prev_handle->height; |
| 135 | src_img->format = prev_handle->format; |
| 136 | src_img->base = (uint32_t)prev_handle->base; |
| 137 | src_img->offset = prev_handle->offset; |
| 138 | src_img->mem_id = prev_handle->fd; |
| 139 | src_img->paddr = prev_handle->paddr; |
| 140 | src_img->usage = prev_handle->usage; |
| 141 | src_img->uoffset = prev_handle->uoffset; |
| 142 | src_img->voffset = prev_handle->voffset; |
| 143 | |
| 144 | switch (src_img->format) { |
| 145 | case HAL_PIXEL_FORMAT_YV12: |
| 146 | case HAL_PIXEL_FORMAT_YCbCr_420_P: |
| 147 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 148 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 149 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR: |
| 150 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL: |
| 151 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR: |
| 152 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL: |
| 153 | src_img->f_w = (src_img->f_w + 15) & ~15; |
| 154 | src_img->f_h = (src_img->f_h + 15) & ~15; |
| 155 | break; |
| 156 | default: |
| 157 | src_img->f_w = src_img->w; |
| 158 | src_img->f_h = src_img->h; |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | /* 2. Set dst_img from window(lcd) */ |
| 163 | calculate_rect(win, cur, &rect); |
| 164 | dst_img->f_w = win->lcd_info.xres; |
| 165 | dst_img->f_h = win->lcd_info.yres; |
| 166 | dst_img->w = rect.w; |
| 167 | dst_img->h = rect.h; |
| 168 | |
| 169 | switch (win->lcd_info.bits_per_pixel) { |
| 170 | case 32: |
| 171 | dst_img->format = HAL_PIXEL_FORMAT_RGBX_8888; |
| 172 | break; |
| 173 | default: |
| 174 | dst_img->format = HAL_PIXEL_FORMAT_RGB_565; |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | dst_img->base = win->addr[win->buf_index]; |
| 179 | dst_img->offset = 0; |
| 180 | dst_img->mem_id = 0; |
| 181 | |
| 182 | /* 3. Set src_rect(crop rect) */ |
| 183 | if (cur->displayFrame.left < 0) { |
| 184 | src_rect->x = |
| 185 | (0 - cur->displayFrame.left) |
| 186 | *(src_img->w) |
| 187 | /(cur->displayFrame.right - cur->displayFrame.left + 1); |
| 188 | if (cur->displayFrame.right + 1 > win->lcd_info.xres) { |
| 189 | src_rect->w = |
| 190 | (cur->sourceCrop.right - cur->sourceCrop.left + 1) - |
| 191 | src_rect->x - |
| 192 | (cur->displayFrame.right - win->lcd_info.xres) |
| 193 | *(src_img->w) |
| 194 | /(cur->displayFrame.right - cur->displayFrame.left + 1); |
| 195 | } else { |
| 196 | src_rect->w = |
| 197 | (cur->sourceCrop.right - cur->sourceCrop.left + 1) - |
| 198 | src_rect->x; |
| 199 | } |
| 200 | } else { |
| 201 | src_rect->x = cur->sourceCrop.left; |
| 202 | if (cur->displayFrame.right + 1 > win->lcd_info.xres) { |
| 203 | src_rect->w = |
| 204 | (cur->sourceCrop.right - cur->sourceCrop.left + 1) - |
| 205 | src_rect->x - |
| 206 | (cur->displayFrame.right - win->lcd_info.xres) |
| 207 | *(src_img->w) |
| 208 | /(cur->displayFrame.right - cur->displayFrame.left + 1); |
| 209 | } else { |
| 210 | src_rect->w = |
| 211 | (cur->sourceCrop.right - cur->sourceCrop.left + 1); |
| 212 | } |
| 213 | } |
| 214 | if (cur->displayFrame.top < 0) { |
| 215 | src_rect->y = |
| 216 | (0 - cur->displayFrame.top) |
| 217 | *(src_img->h) |
| 218 | /(cur->displayFrame.bottom - cur->displayFrame.top + 1); |
| 219 | if (cur->displayFrame.bottom + 1 > win->lcd_info.yres) { |
| 220 | src_rect->h = |
| 221 | (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) - |
| 222 | src_rect->y - |
| 223 | (cur->displayFrame.bottom - win->lcd_info.yres) |
| 224 | *(src_img->h) |
| 225 | /(cur->displayFrame.bottom - cur->displayFrame.top + 1); |
| 226 | } else { |
| 227 | src_rect->h = |
| 228 | (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) - |
| 229 | src_rect->y; |
| 230 | } |
| 231 | } else { |
| 232 | src_rect->y = cur->sourceCrop.top; |
| 233 | if (cur->displayFrame.bottom + 1 > win->lcd_info.yres) { |
| 234 | src_rect->h = |
| 235 | (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) - |
| 236 | src_rect->y - |
| 237 | (cur->displayFrame.bottom - win->lcd_info.yres) |
| 238 | *(src_img->h) |
| 239 | /(cur->displayFrame.bottom - cur->displayFrame.top + 1); |
| 240 | } else { |
| 241 | src_rect->h = |
| 242 | (cur->sourceCrop.bottom - cur->sourceCrop.top + 1); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 247 | "crop information()::" |
| 248 | "sourceCrop left(%d),top(%d),right(%d),bottom(%d)," |
| 249 | "src_rect x(%d),y(%d),w(%d),h(%d)," |
| 250 | "prev_handle w(%d),h(%d)", |
| 251 | cur->sourceCrop.left, |
| 252 | cur->sourceCrop.top, |
| 253 | cur->sourceCrop.right, |
| 254 | cur->sourceCrop.bottom, |
| 255 | src_rect->x, src_rect->y, src_rect->w, src_rect->h, |
| 256 | prev_handle->width, prev_handle->height); |
| 257 | |
| 258 | src_rect->x = SEC_MAX(src_rect->x, 0); |
| 259 | src_rect->y = SEC_MAX(src_rect->y, 0); |
| 260 | src_rect->w = SEC_MAX(src_rect->w, 0); |
| 261 | src_rect->w = SEC_MIN(src_rect->w, prev_handle->width); |
| 262 | src_rect->h = SEC_MAX(src_rect->h, 0); |
| 263 | src_rect->h = SEC_MIN(src_rect->h, prev_handle->height); |
| 264 | |
| 265 | /* 4. Set dst_rect(fb or lcd) |
| 266 | * fimc dst image will be stored from left top corner |
| 267 | */ |
| 268 | dst_rect->x = 0; |
| 269 | dst_rect->y = 0; |
| 270 | dst_rect->w = win->rect_info.w; |
| 271 | dst_rect->h = win->rect_info.h; |
| 272 | |
| 273 | /* Summery */ |
| 274 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 275 | "set_src_dst_img_rect()::" |
| 276 | "SRC w(%d),h(%d),f_w(%d),f_h(%d),fmt(0x%x)," |
| 277 | "base(0x%x),offset(%d),paddr(0x%X)=>\r\n" |
| 278 | " DST w(%d),h(%d),f(0x%x),base(0x%x)," |
| 279 | "offset(%d),mem_id(%d)," |
| 280 | "rot(%d),win_idx(%d)" |
| 281 | " SRC_RECT x(%d),y(%d),w(%d),h(%d)=>" |
| 282 | "DST_RECT x(%d),y(%d),w(%d),h(%d)", |
| 283 | src_img->w, src_img->h, src_img->f_w, src_img->f_h, src_img->format, |
| 284 | src_img->base, src_img->offset, src_img->paddr, |
| 285 | dst_img->w, dst_img->h, dst_img->format, dst_img->base, |
| 286 | dst_img->offset, dst_img->mem_id, |
| 287 | cur->transform, win_idx, |
| 288 | src_rect->x, src_rect->y, src_rect->w, src_rect->h, |
| 289 | dst_rect->x, dst_rect->y, dst_rect->w, dst_rect->h); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int get_hwc_compos_decision(hwc_layer_t* cur, int iter, int win_cnt) |
| 295 | { |
| 296 | if(cur->flags & HWC_SKIP_LAYER || !cur->handle) { |
| 297 | SEC_HWC_Log(HWC_LOG_DEBUG, "%s::is_skip_layer %d cur->handle %x ", |
| 298 | __func__, cur->flags & HWC_SKIP_LAYER, cur->handle); |
| 299 | |
| 300 | return HWC_FRAMEBUFFER; |
| 301 | } |
| 302 | |
| 303 | private_handle_t *prev_handle = (private_handle_t *)(cur->handle); |
| 304 | int compositionType = HWC_FRAMEBUFFER; |
| 305 | |
| 306 | if (iter == 0) { |
| 307 | /* check here....if we have any resolution constraints */ |
| 308 | if (((cur->sourceCrop.right - cur->sourceCrop.left + 1) < 16) || |
| 309 | ((cur->sourceCrop.bottom - cur->sourceCrop.top + 1) < 8)) |
| 310 | return compositionType; |
| 311 | |
| 312 | if ((cur->transform == HAL_TRANSFORM_ROT_90) || |
| 313 | (cur->transform == HAL_TRANSFORM_ROT_270)) { |
| 314 | if (((cur->displayFrame.right - cur->displayFrame.left + 1) < 4) || |
| 315 | ((cur->displayFrame.bottom - cur->displayFrame.top + 1) < 8)) |
| 316 | return compositionType; |
| 317 | } else if (((cur->displayFrame.right - cur->displayFrame.left + 1) < 8) || |
| 318 | ((cur->displayFrame.bottom - cur->displayFrame.top + 1) < 4)) { |
| 319 | return compositionType; |
| 320 | } |
| 321 | |
| 322 | switch (prev_handle->format) { |
| 323 | case HAL_PIXEL_FORMAT_YV12: /* YCrCb_420_P */ |
| 324 | case HAL_PIXEL_FORMAT_YCbCr_420_P: |
| 325 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 326 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 327 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR: |
| 328 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL: |
| 329 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR: |
| 330 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL: |
| 331 | if ((prev_handle->usage & GRALLOC_USAGE_HWC_HWOVERLAY) && |
| 332 | (cur->blending == HWC_BLENDING_NONE)) |
| 333 | compositionType = HWC_OVERLAY; |
| 334 | else |
| 335 | compositionType = HWC_FRAMEBUFFER; |
| 336 | break; |
| 337 | default: |
| 338 | compositionType = HWC_FRAMEBUFFER; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | #ifdef SUB_TITLES_HWC |
| 344 | else if ((win_cnt > 0) && |
| 345 | (prev_handle->usage & GRALLOC_USAGE_EXTERNAL_DISP)) { |
| 346 | switch (prev_handle->format) { |
| 347 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 348 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 349 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 350 | case HAL_PIXEL_FORMAT_RGB_888: |
| 351 | case HAL_PIXEL_FORMAT_RGB_565: |
| 352 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 353 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 354 | compositionType = HWC_OVERLAY; |
| 355 | break; |
| 356 | default: |
| 357 | compositionType = HWC_FRAMEBUFFER; |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | SEC_HWC_Log(HWC_LOG_DEBUG, "2nd iter###%s:: compositionType %d bpp %d" |
| 362 | " format %x src[%d %d %d %d] dst[%d %d %d %d] srcImg[%d %d]", |
| 363 | __func__, compositionType, prev_handle->bpp, |
| 364 | prev_handle->format, |
| 365 | cur->sourceCrop.left, cur->sourceCrop.right, |
| 366 | cur->sourceCrop.top, cur->sourceCrop.bottom, |
| 367 | cur->displayFrame.left, cur->displayFrame.right, |
| 368 | cur->displayFrame.top, cur->displayFrame.bottom, |
| 369 | prev_handle->width, prev_handle->height); |
| 370 | } |
| 371 | #endif |
| 372 | |
| 373 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 374 | "%s::compositionType(%d)=>0:FB,1:OVERLAY \r\n" |
| 375 | " format(0x%x),magic(0x%x),flags(%d),size(%d),offset(%d)" |
| 376 | "b_addr(0x%x),usage(%d),w(%d),h(%d),bpp(%d)", |
| 377 | "get_hwc_compos_decision()", compositionType, |
| 378 | prev_handle->format, prev_handle->magic, prev_handle->flags, |
| 379 | prev_handle->size, prev_handle->offset, prev_handle->base, |
| 380 | prev_handle->usage, prev_handle->width, prev_handle->height, |
| 381 | prev_handle->bpp); |
| 382 | |
| 383 | return compositionType; |
| 384 | } |
| 385 | |
| 386 | static void reset_win_rect_info(hwc_win_info_t *win) |
| 387 | { |
| 388 | win->rect_info.x = 0; |
| 389 | win->rect_info.y = 0; |
| 390 | win->rect_info.w = 0; |
| 391 | win->rect_info.h = 0; |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | static int assign_overlay_window(struct hwc_context_t *ctx, hwc_layer_t *cur, |
| 397 | int win_idx, int layer_idx) |
| 398 | { |
| 399 | struct hwc_win_info_t *win; |
| 400 | sec_rect rect; |
| 401 | int ret = 0; |
| 402 | |
| 403 | if (NUM_OF_WIN <= win_idx) |
| 404 | return -1; |
| 405 | |
| 406 | win = &ctx->win[win_idx]; |
| 407 | |
| 408 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 409 | "%s:: left(%d),top(%d),right(%d),bottom(%d),transform(%d)" |
| 410 | "lcd_info.xres(%d),lcd_info.yres(%d)", |
| 411 | "++assign_overlay_window()", |
| 412 | cur->displayFrame.left, cur->displayFrame.top, |
| 413 | cur->displayFrame.right, cur->displayFrame.bottom, cur->transform, |
| 414 | win->lcd_info.xres, win->lcd_info.yres); |
| 415 | |
| 416 | calculate_rect(win, cur, &rect); |
| 417 | |
| 418 | if ((rect.x != win->rect_info.x) || (rect.y != win->rect_info.y) || |
| 419 | (rect.w != win->rect_info.w) || (rect.h != win->rect_info.h)){ |
| 420 | win->rect_info.x = rect.x; |
| 421 | win->rect_info.y = rect.y; |
| 422 | win->rect_info.w = rect.w; |
| 423 | win->rect_info.h = rect.h; |
| 424 | //turnoff the window and set the window position with new conf... |
| 425 | if (window_set_pos(win) < 0) { |
| 426 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_set_pos is failed : %s", |
| 427 | __func__, strerror(errno)); |
| 428 | ret = -1; |
| 429 | } |
| 430 | ctx->layer_prev_buf[win_idx] = 0; |
| 431 | } |
| 432 | |
| 433 | win->layer_index = layer_idx; |
| 434 | win->status = HWC_WIN_RESERVED; |
| 435 | |
| 436 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 437 | "%s:: win_x %d win_y %d win_w %d win_h %d lay_idx %d win_idx %d\n", |
| 438 | "--assign_overlay_window()", |
| 439 | win->rect_info.x, win->rect_info.y, win->rect_info.w, |
| 440 | win->rect_info.h, win->layer_index, win_idx ); |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list) |
| 446 | { |
| 447 | struct hwc_context_t* ctx = (struct hwc_context_t*)dev; |
| 448 | int overlay_win_cnt = 0; |
| 449 | int compositionType = 0; |
| 450 | int ret; |
| 451 | |
| 452 | //if geometry is not changed, there is no need to do any work here |
| 453 | if (!list || (!(list->flags & HWC_GEOMETRY_CHANGED))) |
| 454 | return 0; |
| 455 | |
| 456 | //all the windows are free here.... |
| 457 | for (int i = 0 ; i < NUM_OF_WIN; i++) { |
| 458 | ctx->win[i].status = HWC_WIN_FREE; |
| 459 | ctx->win[i].buf_index = 0; |
| 460 | } |
| 461 | |
| 462 | ctx->num_of_hwc_layer = 0; |
| 463 | ctx->num_of_fb_layer = 0; |
| 464 | ctx->num_2d_blit_layer = 0; |
| 465 | |
| 466 | for (int i = 0; i < list->numHwLayers ; i++) { |
| 467 | hwc_layer_t* cur = &list->hwLayers[i]; |
| 468 | |
| 469 | if (overlay_win_cnt < NUM_OF_WIN) { |
| 470 | compositionType = get_hwc_compos_decision(cur, 0, overlay_win_cnt); |
| 471 | |
| 472 | if (compositionType == HWC_FRAMEBUFFER) { |
| 473 | cur->compositionType = HWC_FRAMEBUFFER; |
| 474 | ctx->num_of_fb_layer++; |
| 475 | } else { |
| 476 | ret = assign_overlay_window(ctx, cur, overlay_win_cnt, i); |
| 477 | if (ret != 0) { |
| 478 | LOGE("assign_overlay_window fail, change to frambuffer"); |
| 479 | cur->compositionType = HWC_FRAMEBUFFER; |
| 480 | ctx->num_of_fb_layer++; |
| 481 | continue; |
| 482 | } |
| 483 | |
| 484 | cur->compositionType = HWC_OVERLAY; |
| 485 | cur->hints = HWC_HINT_CLEAR_FB; |
| 486 | overlay_win_cnt++; |
| 487 | ctx->num_of_hwc_layer++; |
| 488 | } |
| 489 | } else { |
| 490 | cur->compositionType = HWC_FRAMEBUFFER; |
| 491 | ctx->num_of_fb_layer++; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | #ifdef SUB_TITLES_HWC |
| 496 | for (int i = 0; i < list->numHwLayers ; i++) { |
| 497 | if (overlay_win_cnt < NUM_OF_WIN) { |
| 498 | hwc_layer_t* cur = &list->hwLayers[i]; |
| 499 | if (get_hwc_compos_decision(cur, 1, overlay_win_cnt) == HWC_OVERLAY) { |
| 500 | ret = assign_overlay_window(ctx, cur, overlay_win_cnt, i); |
| 501 | if (ret == 0) { |
| 502 | cur->compositionType = HWC_OVERLAY; |
| 503 | cur->hints = HWC_HINT_CLEAR_FB; |
| 504 | overlay_win_cnt++; |
| 505 | ctx->num_of_hwc_layer++; |
| 506 | ctx->num_of_fb_layer--; |
| 507 | ctx->num_2d_blit_layer = 1; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | else |
| 512 | break; |
| 513 | } |
| 514 | #endif |
| 515 | |
| 516 | #if defined(BOARD_USES_HDMI) |
| 517 | android::SecHdmiClient *mHdmiClient = android::SecHdmiClient::getInstance(); |
| 518 | mHdmiClient->setHdmiHwcLayer(ctx->num_of_hwc_layer); |
| 519 | #endif |
| 520 | |
| 521 | if (list->numHwLayers != (ctx->num_of_fb_layer + ctx->num_of_hwc_layer)) |
| 522 | SEC_HWC_Log(HWC_LOG_DEBUG, |
| 523 | "%s:: numHwLayers %d num_of_fb_layer %d num_of_hwc_layer %d ", |
| 524 | __func__, list->numHwLayers, ctx->num_of_fb_layer, |
| 525 | ctx->num_of_hwc_layer); |
| 526 | |
| 527 | if (overlay_win_cnt < NUM_OF_WIN) { |
| 528 | //turn off the free windows |
| 529 | for (int i = overlay_win_cnt; i < NUM_OF_WIN; i++) { |
| 530 | window_hide(&ctx->win[i]); |
| 531 | reset_win_rect_info(&ctx->win[i]); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int hwc_set(hwc_composer_device_t *dev, |
| 539 | hwc_display_t dpy, |
| 540 | hwc_surface_t sur, |
| 541 | hwc_layer_list_t* list) |
| 542 | { |
| 543 | struct hwc_context_t *ctx = (struct hwc_context_t *)dev; |
| 544 | int skipped_window_mask = 0; |
| 545 | hwc_layer_t* cur; |
| 546 | struct hwc_win_info_t *win; |
| 547 | int ret; |
| 548 | int pmem_phyaddr; |
| 549 | struct sec_img src_img; |
| 550 | struct sec_img dst_img; |
| 551 | struct sec_rect src_work_rect; |
| 552 | struct sec_rect dst_work_rect; |
| 553 | #if defined(BOARD_USES_HDMI) |
| 554 | int skip_hdmi_rendering = 0; |
| 555 | int rotVal = 0; |
| 556 | #endif |
| 557 | if (!list) { |
| 558 | //turn off the all windows |
| 559 | for (int i = 0; i < NUM_OF_WIN; i++) { |
| 560 | window_hide(&ctx->win[i]); |
| 561 | reset_win_rect_info(&ctx->win[i]); |
| 562 | ctx->win[i].status = HWC_WIN_FREE; |
| 563 | } |
| 564 | ctx->num_of_hwc_layer = 0; |
| 565 | } |
| 566 | |
| 567 | if(ctx->num_of_hwc_layer > NUM_OF_WIN) |
| 568 | ctx->num_of_hwc_layer = NUM_OF_WIN; |
| 569 | |
| 570 | //compose hardware layers here |
| 571 | for (int i = 0; i < ctx->num_of_hwc_layer - ctx->num_2d_blit_layer; i++) { |
| 572 | win = &ctx->win[i]; |
| 573 | if (win->status == HWC_WIN_RESERVED) { |
| 574 | cur = &list->hwLayers[win->layer_index]; |
| 575 | |
| 576 | if (cur->compositionType == HWC_OVERLAY) { |
| 577 | if (ctx->layer_prev_buf[i] == (uint32_t)cur->handle) { |
| 578 | /* |
| 579 | * In android platform, all the graphic buffer are at least |
| 580 | * double buffered (2 or more) this buffer is already rendered. |
| 581 | * It is the redundant src buffer for FIMC rendering. |
| 582 | */ |
| 583 | LOGD("SKIP FIMC rendering for Layer%d", win->layer_index); |
| 584 | #if defined(BOARD_USES_HDMI) |
| 585 | skip_hdmi_rendering = 1; |
| 586 | #endif |
| 587 | continue; |
| 588 | } |
| 589 | ctx->layer_prev_buf[i] = (uint32_t)cur->handle; |
| 590 | // initialize the src & dist context for fimc |
| 591 | set_src_dst_img_rect(cur, win, &src_img, &dst_img, |
| 592 | &src_work_rect, &dst_work_rect, i); |
| 593 | |
| 594 | ret = runFimc(ctx, |
| 595 | &src_img, &src_work_rect, |
| 596 | &dst_img, &dst_work_rect, |
| 597 | cur->transform); |
| 598 | |
| 599 | if (ret < 0) { |
| 600 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::runFimc fail : ret=%d\n", |
| 601 | __func__, ret); |
| 602 | skipped_window_mask |= (1 << i); |
| 603 | continue; |
| 604 | } |
| 605 | |
| 606 | window_pan_display(win); |
| 607 | |
| 608 | win->buf_index = (win->buf_index + 1) % NUM_OF_WIN_BUF; |
| 609 | if (win->power_state == 0) |
| 610 | window_show(win); |
| 611 | } else { |
| 612 | SEC_HWC_Log(HWC_LOG_ERROR, |
| 613 | "%s:: error : layer %d compositionType should have been" |
| 614 | " HWC_OVERLAY ", __func__, win->layer_index); |
| 615 | skipped_window_mask |= (1 << i); |
| 616 | continue; |
| 617 | } |
| 618 | } else { |
| 619 | SEC_HWC_Log(HWC_LOG_ERROR, "%s:: error : window status should have " |
| 620 | "been HWC_WIN_RESERVED by now... ", __func__); |
| 621 | skipped_window_mask |= (1 << i); |
| 622 | continue; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | #ifdef SUB_TITLES_HWC |
| 627 | if (ctx->num_2d_blit_layer) { |
| 628 | g2d_rect srcRect; |
| 629 | g2d_rect dstRect; |
| 630 | |
| 631 | win = &ctx->win[ctx->num_of_hwc_layer - 1]; |
| 632 | cur = &list->hwLayers[win->layer_index]; |
| 633 | set_src_dst_g2d_rect(cur, win, &srcRect, &dstRect); |
| 634 | ret = runG2d(ctx, &srcRect, &dstRect, |
| 635 | cur->transform); |
| 636 | if (ret < 0) { |
| 637 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::runG2d fail : ret=%d\n", |
| 638 | __func__, ret); |
| 639 | skipped_window_mask |= (1 << (ctx->num_of_hwc_layer - 1)); |
| 640 | goto g2d_error; |
| 641 | } |
| 642 | |
| 643 | window_pan_display(win); |
| 644 | |
| 645 | win->buf_index = (win->buf_index + 1) % NUM_OF_WIN_BUF; |
| 646 | if (win->power_state == 0) |
| 647 | window_show(win); |
| 648 | } |
| 649 | |
| 650 | g2d_error: |
| 651 | #endif |
| 652 | |
| 653 | if (skipped_window_mask) { |
| 654 | //turn off the free windows |
| 655 | for (int i = 0; i < NUM_OF_WIN; i++) { |
| 656 | if (skipped_window_mask & (1 << i)) { |
| 657 | window_hide(&ctx->win[i]); |
| 658 | reset_win_rect_info(&ctx->win[i]); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | if (0 < ctx->num_of_fb_layer) { |
| 664 | #ifdef CHECK_EGL_FPS |
| 665 | check_fps(); |
| 666 | #endif |
| 667 | #ifdef HWC_HWOVERLAY |
| 668 | glFinish(); |
| 669 | #endif |
| 670 | EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur); |
| 671 | if (!sucess) |
| 672 | return HWC_EGL_ERROR; |
| 673 | } |
| 674 | |
| 675 | #if defined(BOARD_USES_HDMI) |
| 676 | if (list == NULL || skip_hdmi_rendering == 1) |
| 677 | return 0; |
| 678 | |
| 679 | android::SecHdmiClient *mHdmiClient = android::SecHdmiClient::getInstance(); |
| 680 | |
| 681 | #ifdef SUPPORT_AUTO_UI_ROTATE |
| 682 | cur = &list->hwLayers[0]; |
| 683 | |
| 684 | if (cur->transform == HAL_TRANSFORM_ROT_90 || cur->transform == HAL_TRANSFORM_ROT_270) |
| 685 | mHdmiClient->setHdmiRotate(270, ctx->num_of_hwc_layer); |
| 686 | else |
| 687 | mHdmiClient->setHdmiRotate(0, ctx->num_of_hwc_layer); |
| 688 | #endif |
| 689 | |
| 690 | if (src_img.usage & GRALLOC_USAGE_PRIVATE_SBS_LR) |
| 691 | src_img.format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR; |
| 692 | else if (src_img.usage & GRALLOC_USAGE_PRIVATE_SBS_RL) |
| 693 | src_img.format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL; |
| 694 | else if (src_img.usage & GRALLOC_USAGE_PRIVATE_TB_LR) |
| 695 | src_img.format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR; |
| 696 | else if (src_img.usage & GRALLOC_USAGE_PRIVATE_TB_RL) |
| 697 | src_img.format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL; |
| 698 | |
| 699 | // To support S3D video playback (automatic TV mode change to 3D mode) |
| 700 | if (ctx->num_of_hwc_layer == 1) { |
| 701 | if (src_img.format != prev_format) { |
| 702 | if ((src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR) || |
| 703 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL)) |
| 704 | mHdmiClient->setHdmiResolution(7209601); // V4L2_STD_TVOUT_720P_60_SBS_HALF |
| 705 | else if ((src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR) || |
| 706 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL)) |
| 707 | mHdmiClient->setHdmiResolution(1080924); // V4L2_STD_TVOUT_1080P_24_TB |
| 708 | else |
| 709 | mHdmiClient->setHdmiResolution(DEFAULT_HDMI_RESOLUTION_VALUE); // V4L2_STD_1080P_60 |
| 710 | } |
| 711 | prev_format = src_img.format; |
| 712 | } else { |
| 713 | if ((prev_format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR) || |
| 714 | (prev_format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL) || |
| 715 | (prev_format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR) || |
| 716 | (prev_format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL)) |
| 717 | mHdmiClient->setHdmiResolution(DEFAULT_HDMI_RESOLUTION_VALUE); // V4L2_STD_1080P_60 |
| 718 | prev_format = HAL_PIXEL_FORMAT_BGRA_8888; |
| 719 | } |
| 720 | |
| 721 | if (ctx->num_of_hwc_layer == 1) { |
| 722 | if ((src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED)|| |
| 723 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP) || |
| 724 | (src_img.format == HAL_PIXEL_FORMAT_YCbCr_420_SP) || |
| 725 | (src_img.format == HAL_PIXEL_FORMAT_YCrCb_420_SP) || |
| 726 | (src_img.format == HAL_PIXEL_FORMAT_YCbCr_420_P) || |
| 727 | (src_img.format == HAL_PIXEL_FORMAT_YV12) || |
| 728 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_LR) || |
| 729 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_SBS_RL) || |
| 730 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_LR) || |
| 731 | (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_P_TB_RL)) { |
| 732 | mHdmiClient->blit2Hdmi(src_img.w, src_img.h, |
| 733 | src_img.format, |
| 734 | src_img.base, |
| 735 | src_img.base + src_img.uoffset, |
| 736 | src_img.base + src_img.uoffset + src_img.voffset, |
| 737 | 0, 0, |
| 738 | android::SecHdmiClient::HDMI_MODE_VIDEO, |
| 739 | ctx->num_of_hwc_layer); |
| 740 | } else { |
| 741 | LOGE("%s: Unsupported format = %d", __func__, src_img.format); |
| 742 | } |
| 743 | } |
| 744 | #endif |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int hwc_device_close(struct hw_device_t *dev) |
| 749 | { |
| 750 | struct hwc_context_t* ctx = (struct hwc_context_t*)dev; |
| 751 | int ret = 0; |
| 752 | int i; |
| 753 | if (ctx) { |
| 754 | if (destroyVideoDev(&ctx->fimc) < 0) { |
| 755 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyVideoDev fail", __func__); |
| 756 | ret = -1; |
| 757 | } |
| 758 | #ifdef SUB_TITLES_HWC |
| 759 | if (destroyG2d(&ctx->g2d) < 0) { |
| 760 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyG2d() fail", __func__); |
| 761 | ret = -1; |
| 762 | } |
| 763 | #endif |
| 764 | for (i = 0; i < NUM_OF_WIN; i++) { |
| 765 | if (window_close(&ctx->win[i]) < 0) |
| 766 | SEC_HWC_Log(HWC_LOG_DEBUG, "%s::window_close() fail", __func__); |
| 767 | } |
| 768 | |
| 769 | free(ctx); |
| 770 | } |
| 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 775 | struct hw_device_t** device) |
| 776 | { |
| 777 | int status = 0; |
| 778 | struct hwc_win_info_t *win; |
| 779 | |
| 780 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) |
| 781 | return -EINVAL; |
| 782 | |
| 783 | struct hwc_context_t *dev; |
| 784 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 785 | |
| 786 | /* initialize our state here */ |
| 787 | memset(dev, 0, sizeof(*dev)); |
| 788 | |
| 789 | /* initialize the procs */ |
| 790 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 791 | dev->device.common.version = 0; |
| 792 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 793 | dev->device.common.close = hwc_device_close; |
| 794 | |
| 795 | dev->device.prepare = hwc_prepare; |
| 796 | dev->device.set = hwc_set; |
| 797 | |
| 798 | *device = &dev->device.common; |
| 799 | |
| 800 | //initializing |
| 801 | memset(&(dev->fimc), 0, sizeof(s5p_fimc_t)); |
| 802 | memset(&(dev->s3c_mem), 0, sizeof(struct s3c_mem_t)); |
| 803 | #ifdef USE_HW_PMEM |
| 804 | memset(&(dev->sec_pmem), 0, sizeof(sec_pmem_t)); |
| 805 | #endif |
| 806 | /* open WIN0 & WIN1 here */ |
| 807 | for (int i = 0; i < NUM_OF_WIN; i++) { |
| 808 | if (window_open(&(dev->win[i]), i) < 0) { |
| 809 | SEC_HWC_Log(HWC_LOG_ERROR, |
| 810 | "%s:: Failed to open window %d device ", __func__, i); |
| 811 | status = -EINVAL; |
| 812 | goto err; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | if (window_get_global_lcd_info(dev->win[0].fd, &dev->lcd_info) < 0) { |
| 817 | SEC_HWC_Log(HWC_LOG_ERROR, |
| 818 | "%s::window_get_global_lcd_info is failed : %s", |
| 819 | __func__, strerror(errno)); |
| 820 | status = -EINVAL; |
| 821 | goto err; |
| 822 | } |
| 823 | |
| 824 | #if defined(BOARD_USES_HDMI) |
| 825 | lcd_width = dev->lcd_info.xres; |
| 826 | lcd_height = dev->lcd_info.yres; |
| 827 | #endif |
| 828 | |
| 829 | /* initialize the window context */ |
| 830 | for (int i = 0; i < NUM_OF_WIN; i++) { |
| 831 | win = &dev->win[i]; |
| 832 | memcpy(&win->lcd_info, &dev->lcd_info, sizeof(struct fb_var_screeninfo)); |
| 833 | memcpy(&win->var_info, &dev->lcd_info, sizeof(struct fb_var_screeninfo)); |
| 834 | |
| 835 | win->rect_info.x = 0; |
| 836 | win->rect_info.y = 0; |
| 837 | win->rect_info.w = win->var_info.xres; |
| 838 | win->rect_info.h = win->var_info.yres; |
| 839 | |
| 840 | if (window_set_pos(win) < 0) { |
| 841 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_set_pos is failed : %s", |
| 842 | __func__, strerror(errno)); |
| 843 | status = -EINVAL; |
| 844 | goto err; |
| 845 | } |
| 846 | |
| 847 | if (window_get_info(win, i) < 0) { |
| 848 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_get_info is failed : %s", |
| 849 | __func__, strerror(errno)); |
| 850 | status = -EINVAL; |
| 851 | goto err; |
| 852 | } |
| 853 | |
| 854 | } |
| 855 | |
| 856 | #ifdef USE_HW_PMEM |
| 857 | if (createPmem(&dev->sec_pmem, PMEM_SIZE) < 0) { |
| 858 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::initPmem(%d) fail", __func__, PMEM_SIZE); |
| 859 | } |
| 860 | #endif |
| 861 | |
| 862 | //create PP |
| 863 | if (createVideoDev(&dev->fimc) < 0) { |
| 864 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::creatFimc() fail", __func__); |
| 865 | status = -EINVAL; |
| 866 | goto err; |
| 867 | } |
| 868 | |
| 869 | #ifdef SUB_TITLES_HWC |
| 870 | if (createG2d(&dev->g2d) < 0) { |
| 871 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::createG2d() fail", __func__); |
| 872 | status = -EINVAL; |
| 873 | goto err; |
| 874 | } |
| 875 | #endif |
| 876 | |
| 877 | SEC_HWC_Log(HWC_LOG_DEBUG, "%s:: hwc_device_open: SUCCESS", __func__); |
| 878 | return 0; |
| 879 | |
| 880 | err: |
| 881 | if (destroyVideoDev(&dev->fimc) < 0) |
| 882 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyVideoDev() fail", __func__); |
| 883 | #ifdef SUB_TITLES_HWC |
| 884 | if (destroyG2d(&dev->g2d) < 0) |
| 885 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyG2d() fail", __func__); |
| 886 | #endif |
| 887 | if (destroyMem(&dev->s3c_mem) < 0) |
| 888 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyMem() fail", __func__); |
| 889 | |
| 890 | #ifdef USE_HW_PMEM |
| 891 | if (destroyPmem(&dev->sec_pmem) < 0) |
| 892 | SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyPmem() fail", __func__); |
| 893 | #endif |
| 894 | |
| 895 | for (int i = 0; i < NUM_OF_WIN; i++) { |
| 896 | if (window_close(&dev->win[i]) < 0) |
| 897 | SEC_HWC_Log(HWC_LOG_DEBUG, "%s::window_close() fail", __func__); |
| 898 | } |
| 899 | |
| 900 | return status; |
| 901 | } |