3 #define LOG_TAG "ExynosG2DWrapper"
4 #include "ExynosG2DWrapper.h"
5 #include "ExynosHWCUtils.h"
6 #include "ExynosOverlayDisplay.h"
7 #ifdef USES_VIRTUAL_DISPLAY
8 #include "ExynosExternalDisplay.h"
9 #include "ExynosVirtualDisplay.h"
11 #include "ExynosExternalDisplay.h"
14 #define FIMG2D_WFD_DEFAULT (G2D_LV1)
16 int formatValueHAL2G2D(int hal_format
,
17 color_format
*g2d_format
,
18 pixel_order
*g2d_order
,
21 *g2d_format
= MSK_FORMAT_END
;
22 *g2d_order
= ARGB_ORDER_END
;
27 case HAL_PIXEL_FORMAT_RGB_565
:
28 *g2d_format
= CF_RGB_565
;
33 case HAL_PIXEL_FORMAT_RGBX_8888
:
34 *g2d_format
= CF_XRGB_8888
;
38 #ifdef EXYNOS_SUPPORT_BGRX_8888
39 case HAL_PIXEL_FORMAT_BGRX_8888
:
40 *g2d_format
= CF_XRGB_8888
;
45 case HAL_PIXEL_FORMAT_BGRA_8888
:
46 *g2d_format
= CF_ARGB_8888
;
50 case HAL_PIXEL_FORMAT_RGBA_8888
:
51 *g2d_format
= CF_ARGB_8888
;
55 case HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888
:
56 *g2d_format
= CF_ARGB_8888
;
61 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP
:
62 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_PRIV
:
63 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED
:
64 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M
:
65 *g2d_format
= CF_YCBCR_420
;
70 ALOGE("%s: no matching color format(0x%x): failed",
71 __func__
, hal_format
);
78 #ifdef USES_VIRTUAL_DISPLAY
79 ExynosG2DWrapper::ExynosG2DWrapper(ExynosOverlayDisplay
*display
,
80 ExynosExternalDisplay
*externalDisplay
,
81 ExynosVirtualDisplay
*virtualDisplay
)
83 ExynosG2DWrapper::ExynosG2DWrapper(ExynosOverlayDisplay
*display
, ExynosExternalDisplay
*hdmi
)
87 #ifdef USES_VIRTUAL_DISPLAY
88 mExternalDisplay
= externalDisplay
;
89 mVirtualDisplay
= virtualDisplay
;
92 mExternalDisplay
= hdmi
;
96 ExynosG2DWrapper::~ExynosG2DWrapper()
100 int ExynosG2DWrapper::runCompositor(hwc_layer_1_t
&src_layer
, private_handle_t
*dst_handle
,
101 uint32_t transform
, uint32_t global_alpha
, unsigned long solid
,
102 blit_op mode
, bool force_clear
, unsigned long srcAddress
,
103 unsigned long dstAddress
, int is_lcd
)
106 unsigned long srcYAddress
= 0;
107 unsigned long dstYAddress
= 0;
108 unsigned long dstCbCrAddress
=0;
110 ExynosRect srcImgRect
, dstImgRect
;
112 fimg2d_blit BlitParam
;
113 fimg2d_param g2d_param
;
114 rotation g2d_rotation
;
116 fimg2d_addr srcYAddr
;
117 fimg2d_addr srcCbCrAddr
;
118 fimg2d_image srcImage
;
121 fimg2d_addr dstYAddr
;
122 fimg2d_addr dstCbCrAddr
;
123 fimg2d_image dstImage
;
126 fimg2d_scale Scaling
;
127 fimg2d_repeat Repeat
;
128 fimg2d_bluscr Bluscr
;
129 fimg2d_clip Clipping
;
131 pixel_order g2d_order
;
132 color_format g2d_format
;
133 addr_space addr_type
= ADDR_USER
;
135 uint32_t srcG2d_bpp
, dstG2d_bpp
;
136 uint32_t srcImageSize
, dstImageSize
;
137 bool src_ion_mapped
= false;
138 bool dst_ion_mapped
= false;
140 private_handle_t
*src_handle
= private_handle_t::dynamicCast(src_layer
.handle
);
143 srcImgRect
.x
= src_layer
.sourceCropf
.left
;
144 srcImgRect
.y
= src_layer
.sourceCropf
.top
;
145 srcImgRect
.w
= WIDTH(src_layer
.sourceCropf
);
146 srcImgRect
.h
= HEIGHT(src_layer
.sourceCropf
);
147 srcImgRect
.fullW
= src_handle
->stride
;
148 srcImgRect
.fullH
= src_handle
->vstride
;
149 srcImgRect
.colorFormat
= src_handle
->format
;
152 #ifndef USES_VIRTUAL_DISPLAY
155 w
= mExternalDisplay
->mXres
;
156 h
= mExternalDisplay
->mYres
;
163 dstImgRect
.w
= WIDTH(src_layer
.displayFrame
);
164 dstImgRect
.h
= HEIGHT(src_layer
.displayFrame
);
165 dstImgRect
.fullW
= dst_handle
->stride
;
166 dstImgRect
.fullH
= dst_handle
->vstride
;
167 dstImgRect
.colorFormat
= dst_handle
->format
;
172 dstImgRect
.w
= dst_handle
->width
;
173 dstImgRect
.h
= dst_handle
->height
;
175 dstImgRect
.x
= src_layer
.displayFrame
.left
;
176 dstImgRect
.y
= src_layer
.displayFrame
.top
;
177 dstImgRect
.w
= WIDTH(src_layer
.displayFrame
);
178 dstImgRect
.h
= HEIGHT(src_layer
.displayFrame
);
180 #ifdef USES_VIRTUAL_DISPLAY
181 dstImgRect
.fullW
= dst_handle
->stride
;
182 dstImgRect
.fullH
= dst_handle
->vstride
;
184 dstImgRect
.fullW
= w
;
185 dstImgRect
.fullH
= h
;
187 dstImgRect
.colorFormat
= dst_handle
->format
;
190 g2d_rotation
= rotateValueHAL2G2D(transform
);
193 "s_fw %d s_fh %d s_w %d s_h %d s_x %d s_y %d s_f %x address %x \n"
194 "d_fw %d d_fh %d d_w %d d_h %d d_x %d d_y %d d_f %x address %x \n rot %d ",
196 srcImgRect
.fullW
, srcImgRect
.fullH
, srcImgRect
.w
, srcImgRect
.h
,
197 srcImgRect
.x
, srcImgRect
.y
, srcImgRect
.colorFormat
, src_handle
->fd
,
198 dstImgRect
.fullW
, dstImgRect
.fullH
, dstImgRect
.w
, dstImgRect
.h
,
199 dstImgRect
.x
, dstImgRect
.y
, dstImgRect
.colorFormat
, dst_handle
->fd
, transform
);
201 if (!force_clear
&& src_handle
->fd
>= 0) {
202 int rotatedDstW
= dstImgRect
.w
;
203 int rotatedDstH
= dstImgRect
.h
;
204 if ((g2d_rotation
== ROT_90
) || (g2d_rotation
== ROT_270
)) {
205 if ((srcImgRect
.w
!= dstImgRect
.h
) || (srcImgRect
.h
!= dstImgRect
.w
)) {
206 rotatedDstW
= dstImgRect
.h
;
207 rotatedDstH
= dstImgRect
.w
;
210 if ((srcImgRect
.w
!= dstImgRect
.w
) || (srcImgRect
.h
!= dstImgRect
.h
)) {
211 rotatedDstW
= dstImgRect
.w
;
212 rotatedDstH
= dstImgRect
.h
;
216 if (formatValueHAL2G2D(srcImgRect
.colorFormat
, &g2d_format
, &g2d_order
, &srcG2d_bpp
) < 0) {
217 ALOGE("%s: formatValueHAL2G2D() failed", __func__
);
220 srcImageSize
= srcImgRect
.fullW
*srcImgRect
.fullH
;
222 srcYAddress
= srcAddress
;
224 srcYAddress
= (unsigned long)mmap(NULL
, srcImageSize
*srcG2d_bpp
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, src_handle
->fd
, 0);
225 if (srcYAddress
== (unsigned long)MAP_FAILED
) {
226 ALOGE("%s: failed to mmap for src-Y address", __func__
);
229 src_ion_mapped
= true;
232 srcYAddr
.type
= addr_type
;
233 srcYAddr
.start
= (unsigned long)srcYAddress
;
234 srcCbCrAddr
.type
= addr_type
;
235 srcCbCrAddr
.start
= 0;
237 srcRect
.x1
= srcImgRect
.x
;
238 srcRect
.y1
= srcImgRect
.y
;
239 srcRect
.x2
= srcImgRect
.x
+ srcImgRect
.w
;
240 srcRect
.y2
= srcImgRect
.y
+ srcImgRect
.h
;
241 srcImage
.width
= srcImgRect
.fullW
;
242 srcImage
.height
= srcImgRect
.fullH
;
243 srcImage
.stride
= srcImgRect
.fullW
*srcG2d_bpp
;
244 srcImage
.order
= g2d_order
;
245 srcImage
.fmt
= g2d_format
;
246 srcImage
.addr
= srcYAddr
;
247 srcImage
.plane2
= srcCbCrAddr
;
248 srcImage
.rect
= srcRect
;
249 srcImage
.need_cacheopr
= false;
251 Scaling
.mode
= SCALING_BILINEAR
;
252 Scaling
.src_w
= srcImgRect
.w
;
253 Scaling
.src_h
= srcImgRect
.h
;
254 Scaling
.dst_w
= rotatedDstW
;
255 Scaling
.dst_h
= rotatedDstH
;
257 memset(&srcImage
, 0, sizeof(srcImage
));
258 Scaling
.mode
= NO_SCALING
;
265 if (dst_handle
->fd
>= 0) {
266 if (formatValueHAL2G2D(dstImgRect
.colorFormat
, &g2d_format
, &g2d_order
, &dstG2d_bpp
) < 0) {
267 ALOGE("%s: formatValueHAL2G2D() failed", __func__
);
270 dstImageSize
= dstImgRect
.fullW
*dstImgRect
.fullH
;
272 dstYAddress
= dstAddress
;
274 #ifdef USES_VIRTUAL_DISPLAY
275 if (mVirtualDisplay
== NULL
) {
276 dstYAddress
= (unsigned long)mmap(NULL
, dstImageSize
*dstG2d_bpp
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, dst_handle
->fd
, 0);
277 if (dstYAddress
== (unsigned long)MAP_FAILED
) {
278 ALOGE("%s: failed to mmap for dst-Y address", __func__
);
282 dstYAddress
= (unsigned long)mmap(NULL
, dstImageSize
*dstG2d_bpp
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, dst_handle
->fd
, 0);
283 if (dstYAddress
== (unsigned long)MAP_FAILED
) {
284 ALOGE("%s: failed to mmap for dst-Y address", __func__
);
288 if (dst_handle
->fd1
> 0) {
289 dstCbCrAddress
= (unsigned long)mmap(NULL
, dstImageSize
*dstG2d_bpp
/ 2, PROT_READ
| PROT_WRITE
, MAP_SHARED
, dst_handle
->fd1
, 0);
290 if (dstCbCrAddress
== (unsigned long)MAP_FAILED
) {
291 ALOGE("%s: failed to mmap for dst-CbCr address", __func__
);
292 munmap((void *)dstYAddress
, dstImageSize
*dstG2d_bpp
);
298 dstYAddress
= (unsigned long)mmap(NULL
, dstImageSize
*dstG2d_bpp
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, dst_handle
->fd
, 0);
299 if (dstYAddress
== (unsigned long)MAP_FAILED
) {
300 ALOGE("%s: failed to mmap for dst-Y address", __func__
);
304 dst_ion_mapped
= true;
307 dstYAddr
.type
= addr_type
;
308 dstYAddr
.start
= (unsigned long)dstYAddress
;
309 dstCbCrAddr
.type
= addr_type
;
310 dstCbCrAddr
.start
= (unsigned long)dstCbCrAddress
;
315 dstRect
.x2
= dstImgRect
.fullW
;
316 dstRect
.y2
= dstImgRect
.fullH
;
318 dstRect
.x1
= dstImgRect
.x
;
319 dstRect
.y1
= dstImgRect
.y
;
320 dstRect
.x2
= dstImgRect
.x
+ dstImgRect
.w
;
321 dstRect
.y2
= dstImgRect
.y
+ dstImgRect
.h
;
324 dstImage
.width
= dstImgRect
.fullW
;
325 dstImage
.height
= dstImgRect
.fullH
;
326 dstImage
.stride
= dstImgRect
.fullW
*dstG2d_bpp
;
327 dstImage
.order
= g2d_order
;
328 dstImage
.fmt
= g2d_format
;
329 dstImage
.addr
= dstYAddr
;
330 dstImage
.plane2
= dstCbCrAddr
;
331 dstImage
.rect
= dstRect
;
332 dstImage
.need_cacheopr
= false;
334 memset(&dstImage
, 0, sizeof(dstImage
));
337 Repeat
.mode
= NO_REPEAT
;
338 Repeat
.pad_color
= 0;
339 Bluscr
.mode
= OPAQUE
;
342 Clipping
.enable
= false;
348 g2d_param
.solid_color
= solid
;
349 g2d_param
.g_alpha
= global_alpha
;
350 g2d_param
.dither
= false;
351 g2d_param
.rotate
= g2d_rotation
;
352 g2d_param
.premult
= PREMULTIPLIED
;
353 g2d_param
.scaling
= Scaling
;
354 g2d_param
.repeat
= Repeat
;
355 g2d_param
.bluscr
= Bluscr
;
356 g2d_param
.clipping
= Clipping
;
360 BlitParam
.param
= g2d_param
;
361 BlitParam
.src
= NULL
;
362 BlitParam
.msk
= NULL
;
363 BlitParam
.tmp
= NULL
;
364 BlitParam
.dst
= &dstImage
;
365 BlitParam
.sync
= BLIT_SYNC
;
366 BlitParam
.seq_no
= 0;
367 BlitParam
.qos_lv
= FIMG2D_WFD_DEFAULT
;
370 BlitParam
.param
= g2d_param
;
371 BlitParam
.src
= &srcImage
;
372 BlitParam
.msk
= NULL
;
373 BlitParam
.tmp
= NULL
;
374 BlitParam
.dst
= &dstImage
;
375 BlitParam
.sync
= BLIT_SYNC
;
376 BlitParam
.seq_no
= 0;
377 BlitParam
.qos_lv
= FIMG2D_WFD_DEFAULT
;
380 ret
= stretchFimgApi(&BlitParam
);
383 munmap((void *)srcYAddress
, srcImageSize
*srcG2d_bpp
);
385 if (dst_ion_mapped
) {
386 #ifdef USES_VIRTUAL_DISPLAY
387 if (mVirtualDisplay
== NULL
)
388 munmap((void *)dstYAddress
, dstImageSize
*dstG2d_bpp
);
390 munmap((void *)dstYAddress
, dstImageSize
*dstG2d_bpp
);
391 munmap((void *)dstCbCrAddress
, dstImageSize
*dstG2d_bpp
/ 2);
394 munmap((void *)dstYAddress
, dstImageSize
*dstG2d_bpp
);
399 ALOGE("%s: stretch failed", __func__
);
406 #ifdef USES_VIRTUAL_DISPLAY
407 int ExynosG2DWrapper::runSecureCompositor(hwc_layer_1_t
&src_layer
,
408 private_handle_t
*dst_handle
,
409 private_handle_t
*secure_handle
,
410 uint32_t global_alpha
, unsigned long solid
,
411 blit_op mode
, bool force_clear
)
415 ExynosRect srcImgRect
, dstImgRect
;
417 fimg2d_blit_raw BlitParam
;
418 fimg2d_param g2d_param
;
419 rotation g2d_rotation
= ORIGIN
;
421 fimg2d_addr srcYAddr
;
422 fimg2d_addr srcCbCrAddr
;
423 fimg2d_image srcImage
;
426 fimg2d_addr dstYAddr
;
427 fimg2d_addr dstCbCrAddr
;
428 fimg2d_image dstImage
;
431 fimg2d_scale Scaling
;
432 fimg2d_repeat Repeat
;
433 fimg2d_bluscr Bluscr
;
434 fimg2d_clip Clipping
;
436 pixel_order g2d_order
;
437 color_format g2d_format
;
438 addr_space addr_type
= ADDR_PHYS
;
440 uint32_t srcG2d_bpp
, dstG2d_bpp
;
441 uint32_t srcImageSize
, dstImageSize
;
443 private_handle_t
*src_handle
= private_handle_t::dynamicCast(src_layer
.handle
);
445 srcImgRect
.x
= src_layer
.sourceCropf
.left
;
446 srcImgRect
.y
= src_layer
.sourceCropf
.top
;
447 srcImgRect
.w
= WIDTH(src_layer
.sourceCropf
);
448 srcImgRect
.h
= HEIGHT(src_layer
.sourceCropf
);
449 srcImgRect
.fullW
= src_handle
->stride
;
450 srcImgRect
.fullH
= src_handle
->vstride
;
451 srcImgRect
.colorFormat
= src_handle
->format
;
453 if (!secure_handle
) {
454 ALOGE("%s: secure g2d buffer handle is NULL", __func__
);
461 dstImgRect
.w
= mVirtualDisplay
->mWidth
;
462 dstImgRect
.h
= mVirtualDisplay
->mHeight
;
463 dstImgRect
.fullW
= mVirtualDisplay
->mWidth
;
464 dstImgRect
.fullH
= mVirtualDisplay
->mHeight
;
465 dstImgRect
.colorFormat
= dst_handle
->format
;
467 dstImgRect
.x
= src_layer
.displayFrame
.left
;
468 dstImgRect
.y
= src_layer
.displayFrame
.top
;
469 dstImgRect
.w
= WIDTH(src_layer
.displayFrame
);
470 dstImgRect
.h
= HEIGHT(src_layer
.displayFrame
);
471 dstImgRect
.fullW
= mVirtualDisplay
->mWidth
;
472 dstImgRect
.fullH
= mVirtualDisplay
->mHeight
;
473 dstImgRect
.colorFormat
= dst_handle
->format
;
477 "s_fw %d s_fh %d s_w %d s_h %d s_x %d s_y %d s_f %x address %x \n"
478 "d_fw %d d_fh %d d_w %d d_h %d d_x %d d_y %d d_f %x address %x \n rot %d ",
480 srcImgRect
.fullW
, srcImgRect
.fullH
, srcImgRect
.w
, srcImgRect
.h
,
481 srcImgRect
.x
, srcImgRect
.y
, srcImgRect
.colorFormat
, secure_handle
->fd
,
482 dstImgRect
.fullW
, dstImgRect
.fullH
, dstImgRect
.w
, dstImgRect
.h
,
483 dstImgRect
.x
, dstImgRect
.y
, dstImgRect
.colorFormat
, dst_handle
->fd
, g2d_rotation
);
485 if (secure_handle
->fd
>= 0) {
486 int rotatedDstW
= dstImgRect
.w
;
487 int rotatedDstH
= dstImgRect
.h
;
489 if (formatValueHAL2G2D(srcImgRect
.colorFormat
, &g2d_format
, &g2d_order
, &srcG2d_bpp
) < 0) {
490 ALOGE("%s: formatValueHAL2G2D() failed", __func__
);
493 srcImageSize
= srcImgRect
.fullW
*srcImgRect
.fullH
;
495 srcYAddr
.type
= addr_type
;
496 srcYAddr
.start
= (unsigned long)secure_handle
->fd
;
497 srcCbCrAddr
.type
= addr_type
;
498 srcCbCrAddr
.start
= 0;
500 srcRect
.x1
= srcImgRect
.x
;
501 srcRect
.y1
= srcImgRect
.y
;
502 srcRect
.x2
= srcImgRect
.x
+ srcImgRect
.w
;
503 srcRect
.y2
= srcImgRect
.y
+ srcImgRect
.h
;
504 srcImage
.width
= srcImgRect
.fullW
;
505 srcImage
.height
= srcImgRect
.fullH
;
506 srcImage
.stride
= srcImgRect
.fullW
*srcG2d_bpp
;
507 srcImage
.order
= g2d_order
;
508 srcImage
.fmt
= g2d_format
;
509 srcImage
.addr
= srcYAddr
;
510 srcImage
.plane2
= srcCbCrAddr
;
511 srcImage
.rect
= srcRect
;
512 srcImage
.need_cacheopr
= false;
514 Scaling
.mode
= SCALING_BILINEAR
;
515 Scaling
.src_w
= srcImgRect
.w
;
516 Scaling
.src_h
= srcImgRect
.h
;
517 Scaling
.dst_w
= rotatedDstW
;
518 Scaling
.dst_h
= rotatedDstH
;
520 memset(&srcImage
, 0, sizeof(srcImage
));
521 Scaling
.mode
= NO_SCALING
;
528 if (dst_handle
->fd
>= 0) {
529 if (formatValueHAL2G2D(dstImgRect
.colorFormat
, &g2d_format
, &g2d_order
, &dstG2d_bpp
) < 0) {
530 ALOGE("%s: formatValueHAL2G2D() failed", __func__
);
533 dstImageSize
= dstImgRect
.fullW
*dstImgRect
.fullH
;
534 dstYAddr
.type
= addr_type
;
535 dstYAddr
.start
= (unsigned long)dst_handle
->fd
;
536 dstCbCrAddr
.type
= addr_type
;
537 dstCbCrAddr
.start
= (unsigned long)dst_handle
->fd1
;
542 dstRect
.x2
= dstImgRect
.fullW
;
543 dstRect
.y2
= dstImgRect
.fullH
;
545 dstRect
.x1
= dstImgRect
.x
;
546 dstRect
.y1
= dstImgRect
.y
;
547 dstRect
.x2
= dstImgRect
.x
+ dstImgRect
.w
;
548 dstRect
.y2
= dstImgRect
.y
+ dstImgRect
.h
;
551 dstImage
.width
= dstImgRect
.fullW
;
552 dstImage
.height
= dstImgRect
.fullH
;
553 dstImage
.stride
= dstImgRect
.fullW
*dstG2d_bpp
;
554 dstImage
.order
= g2d_order
;
555 dstImage
.fmt
= g2d_format
;
556 dstImage
.addr
= dstYAddr
;
557 dstImage
.plane2
= dstCbCrAddr
;
558 dstImage
.rect
= dstRect
;
559 dstImage
.need_cacheopr
= false;
561 memset(&dstImage
, 0, sizeof(dstImage
));
564 Repeat
.mode
= NO_REPEAT
;
565 Repeat
.pad_color
= 0;
566 Bluscr
.mode
= OPAQUE
;
569 Clipping
.enable
= false;
575 g2d_param
.solid_color
= solid
;
576 g2d_param
.g_alpha
= global_alpha
;
577 g2d_param
.dither
= false;
578 g2d_param
.rotate
= g2d_rotation
;
579 g2d_param
.premult
= PREMULTIPLIED
;
580 g2d_param
.scaling
= Scaling
;
581 g2d_param
.repeat
= Repeat
;
582 g2d_param
.bluscr
= Bluscr
;
583 g2d_param
.clipping
= Clipping
;
585 memset(&BlitParam
, 0, sizeof(BlitParam
));
587 memcpy(&BlitParam
.param
, &g2d_param
, sizeof(g2d_param
));
588 memcpy(&BlitParam
.src
, &srcImage
, sizeof(srcImage
));
589 memcpy(&BlitParam
.dst
, &dstImage
, sizeof(dstImage
));
590 BlitParam
.sync
= BLIT_SYNC
;
591 BlitParam
.seq_no
= 0;
592 BlitParam
.qos_lv
= FIMG2D_WFD_DEFAULT
;
594 ret
= G2DDRM_Blit(&BlitParam
);
597 ALOGE("%s: G2DDRM_Blit failed(ret=%d)", __func__
, ret
);
604 bool ExynosG2DWrapper::InitSecureG2D()
606 if (mVirtualDisplay
== NULL
)
610 if (mVirtualDisplay
->mPhysicallyLinearBuffer
== NULL
) {
611 ALOGI("initialize secure G2D");
612 ret
= G2DDRM_Initialize();
614 ALOGE("%s: G2DDRM_Initialize failed, ret %d", __func__
, ret
);
619 int usage
= GRALLOC_USAGE_SW_READ_NEVER
|
620 GRALLOC_USAGE_SW_WRITE_NEVER
|
621 GRALLOC_USAGE_HW_COMPOSER
|
622 GRALLOC_USAGE_PROTECTED
|
623 GRALLOC_USAGE_PHYSICALLY_LINEAR
|
624 GRALLOC_USAGE_PRIVATE_NONSECURE
;
625 alloc_device_t
* allocDevice
= mVirtualDisplay
->mAllocDevice
;
626 int ret
= allocDevice
->alloc(allocDevice
,
627 mVirtualDisplay
->mWidth
, mVirtualDisplay
->mHeight
,
628 mVirtualDisplay
->mGLESFormat
, usage
, &mVirtualDisplay
->mPhysicallyLinearBuffer
,
631 ALOGE("failed to allocate secure g2d buffer: %s", strerror(-ret
));
635 mAllocSize
= mVirtualDisplay
->mWidth
* mVirtualDisplay
->mHeight
* 4;
636 private_handle_t
*handle
= private_handle_t::dynamicCast(
637 mVirtualDisplay
->mPhysicallyLinearBuffer
);
638 mVirtualDisplay
->mPhysicallyLinearBufferAddr
= (unsigned long)mmap(NULL
, mAllocSize
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, handle
->fd
, 0);
639 if (mVirtualDisplay
->mPhysicallyLinearBufferAddr
== (unsigned long)MAP_FAILED
) {
640 ALOGE("%s: failed to mmap for virtual display buffer", __func__
);
643 ALOGI("allocated secure g2d input buffer: 0x%lx", mVirtualDisplay
->mPhysicallyLinearBufferAddr
);
650 bool ExynosG2DWrapper::TerminateSecureG2D()
652 if (mVirtualDisplay
== NULL
)
656 if (mVirtualDisplay
->mPhysicallyLinearBuffer
) {
657 ALOGI("free g2d input buffer: 0x%lx", mVirtualDisplay
->mPhysicallyLinearBufferAddr
);
658 munmap((void *)mVirtualDisplay
->mPhysicallyLinearBufferAddr
, mAllocSize
);
659 mVirtualDisplay
->mPhysicallyLinearBufferAddr
= 0;
661 alloc_device_t
* allocDevice
= mVirtualDisplay
->mAllocDevice
;
662 allocDevice
->free(allocDevice
, mVirtualDisplay
->mPhysicallyLinearBuffer
);
663 mVirtualDisplay
->mPhysicallyLinearBuffer
= NULL
;
665 ALOGI("terminate secure G2D");
666 ret
= G2DDRM_Terminate();
668 ALOGE("%s: G2DDRM_Terminate failed, ret %d", __func__
, ret
);
675 void ExynosG2DWrapper::exynos5_cleanup_g2d(int force __unused
)
677 #ifdef G2D_COMPOSITION
678 exynos5_g2d_data_t
&mG2d
= mDisplay
->mG2d
;
680 if (!mDisplay
->mG2dMemoryAllocated
&& !force
)
683 for (int i
= 0; i
< (int)NUM_HW_WIN_FB_PHY
; i
++) {
684 mDisplay
->mG2dCurrentBuffer
[i
] = 0;
685 mDisplay
->mLastG2dLayerHandle
[i
] = 0;
686 for (int j
= 0; j
< NUM_GSC_DST_BUFS
; j
++) {
687 if (mDisplay
->mWinBufFence
[i
][j
] >= 0) {
688 sync_wait(mDisplay
->mWinBufFence
[i
][j
], 1000);
689 close(mDisplay
->mWinBufFence
[i
][j
]);
690 mDisplay
->mWinBufFence
[i
][j
] = -1;
695 memset(&mG2d
, 0, sizeof(mG2d
));
696 mDisplay
->mG2dLayers
= 0;
697 mDisplay
->mG2dComposition
= 0;
699 for (int i
= 0; i
< mDisplay
->mAllocatedLayers
; i
++) {
700 for (int j
= 0; j
< (int)NUM_GSC_DST_BUFS
; j
++) {
701 if (mDisplay
->mWinBufVirtualAddress
[i
][j
]) {
702 munmap((void *)mDisplay
->mWinBufVirtualAddress
[i
][j
], mDisplay
->mWinBufMapSize
[i
]);
703 mDisplay
->mWinBufVirtualAddress
[i
][j
] = 0;
708 for (int i
= 0; i
< mDisplay
->mAllocatedLayers
; i
++) {
709 for (int j
= 0; j
< (int)NUM_GSC_DST_BUFS
; j
++) {
710 if (mDisplay
->mWinBuf
[i
][j
]) {
711 mDisplay
->mAllocDevice
->free(mDisplay
->mAllocDevice
, mDisplay
->mWinBuf
[i
][j
]);
712 mDisplay
->mWinBuf
[i
][j
] = NULL
;
716 mDisplay
->mAllocatedLayers
= 0;
717 mDisplay
->mG2dMemoryAllocated
= 0;
721 int ExynosG2DWrapper::exynos5_g2d_buf_alloc(hwc_display_contents_1_t
* contents __unused
)
723 #ifdef G2D_COMPOSITION
726 int format
= HAL_PIXEL_FORMAT_RGBX_8888
;
729 if (mDisplay
->mG2dMemoryAllocated
)
732 usage
= GRALLOC_USAGE_SW_READ_NEVER
|
733 GRALLOC_USAGE_SW_WRITE_NEVER
| GRALLOC_USAGE_PHYSICALLY_LINEAR
|
734 GRALLOC_USAGE_HW_COMPOSER
;
735 usage
|= GRALLOC_USAGE_PROTECTED
;
736 usage
&= ~GRALLOC_USAGE_PRIVATE_NONSECURE
;
738 for (int i
= 0; i
< mDisplay
->mG2dLayers
; i
++) {
739 int lay_idx
= mDisplay
->mG2d
.ovly_lay_idx
[i
];
740 hwc_layer_1_t
&layer
= contents
->hwLayers
[lay_idx
];
741 w
= WIDTH(layer
.displayFrame
);
742 h
= HEIGHT(layer
.displayFrame
);
744 for (int j
= 0; j
< (int)NUM_GSC_DST_BUFS
; j
++) {
745 int ret
= mDisplay
->mAllocDevice
->alloc(mDisplay
->mAllocDevice
, w
, h
,
746 format
, usage
, &mDisplay
->mWinBuf
[i
][j
],
749 ALOGE("failed to allocate win %d buf %d buffer [w %d h %d f %x]: %s",
750 i
, j
, w
, h
, format
, strerror(-ret
));
751 goto G2D_BUF_ALLOC_FAIL
;
754 mDisplay
->mWinBufMapSize
[i
] = dst_stride
* h
* 4 + 0x8000;
756 mDisplay
->mAllocatedLayers
= mDisplay
->mG2dLayers
;
758 unsigned long vir_addr
;
759 for (int i
= 0; i
< mDisplay
->mG2dLayers
; i
++) {
760 for (int j
= 0; j
< (int)NUM_GSC_DST_BUFS
; j
++) {
761 mDisplay
->mWinBufFence
[i
][j
] = -1;
762 private_handle_t
*buf_handle
= private_handle_t::dynamicCast(mDisplay
->mWinBuf
[i
][j
]);
763 vir_addr
= (unsigned long) mmap(NULL
, mDisplay
->mWinBufMapSize
[i
], PROT_READ
| PROT_WRITE
, MAP_SHARED
, buf_handle
->fd
, 0);
764 if (vir_addr
!= (unsigned long)MAP_FAILED
) {
765 mDisplay
->mWinBufVirtualAddress
[i
][j
] = vir_addr
;
767 ALOGE("Failed to map win %d buf %d buffer", i
, j
);
768 goto G2D_BUF_ALLOC_FAIL
;
773 mDisplay
->mG2dMemoryAllocated
= 1;
777 mDisplay
->mG2dMemoryAllocated
= 1;
778 /* memory released from the caller */
784 int ExynosG2DWrapper::exynos5_config_g2d(hwc_layer_1_t
&layer __unused
, private_handle_t
*dst_handle __unused
, s3c_fb_win_config
&cfg __unused
, int win_idx_2d __unused
, int win_idx __unused
)
786 #ifdef G2D_COMPOSITION
788 int cur_buf
= mDisplay
->mG2dCurrentBuffer
[win_idx_2d
];
790 private_handle_t
*handle
;
792 private_handle_t
*src_handle
= private_handle_t::dynamicCast(layer
.handle
);
794 if (mDisplay
->mLastG2dLayerHandle
[win_idx_2d
] == (uint32_t)layer
.handle
) {
795 prev_buf
= (cur_buf
+ NUM_GSC_DST_BUFS
- 1) % NUM_GSC_DST_BUFS
;
796 if (mDisplay
->mWinBufFence
[win_idx_2d
][prev_buf
] >= 0) {
797 close(mDisplay
->mWinBufFence
[win_idx_2d
][prev_buf
] );
798 mDisplay
->mWinBufFence
[win_idx_2d
][prev_buf
] = -1;
800 mDisplay
->mG2dCurrentBuffer
[win_idx_2d
] = prev_buf
;
801 handle
= private_handle_t::dynamicCast(mDisplay
->mWinBuf
[win_idx_2d
][prev_buf
]);
802 memcpy(dst_handle
, handle
, sizeof(*dst_handle
));
803 dst_handle
->format
= src_handle
->format
;
805 handle
= private_handle_t::dynamicCast(mDisplay
->mWinBuf
[win_idx_2d
][cur_buf
]);
806 memcpy(dst_handle
, handle
, sizeof(*dst_handle
));
807 dst_handle
->format
= src_handle
->format
;
808 if (mDisplay
->mWinBufFence
[win_idx_2d
][cur_buf
] >= 0) {
809 sync_wait(mDisplay
->mWinBufFence
[win_idx_2d
][cur_buf
], 1000);
810 close(mDisplay
->mWinBufFence
[win_idx_2d
][cur_buf
] );
811 mDisplay
->mWinBufFence
[win_idx_2d
][cur_buf
] = -1;
814 if (layer
.acquireFenceFd
>= 0) {
815 sync_wait(layer
.acquireFenceFd
, 1000);
818 if (dst_handle
->format
== HAL_PIXEL_FORMAT_RGBX_8888
) {
819 ret
= runCompositor(layer
, dst_handle
, 0, 0xff, 0, BLIT_OP_SRC
, false, 0,
820 mDisplay
->mWinBufVirtualAddress
[win_idx_2d
][cur_buf
] + 0x8000, 1);
822 ret
= runCompositor(layer
, dst_handle
, 0, 0xff, 0, BLIT_OP_SRC
, false, 0,
823 mDisplay
->mWinBufVirtualAddress
[win_idx_2d
][cur_buf
], 1);
826 ALOGE("%s:runCompositor: Failed", __func__
);
829 mDisplay
->mLastG2dLayerHandle
[win_idx_2d
] = (uint32_t)layer
.handle
;
831 if (layer
.acquireFenceFd
>= 0)
832 close(layer
.acquireFenceFd
);