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