Commit | Line | Data |
---|---|---|
5763fb39 T |
1 | //#define LOG_NDEBUG 0 |
2 | #undef LOG_TAG | |
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" | |
10 | #else | |
11 | #include "ExynosExternalDisplay.h" | |
12 | #endif | |
13 | ||
14 | #define FIMG2D_WFD_DEFAULT (G2D_LV1) | |
15 | ||
16 | int formatValueHAL2G2D(int hal_format, | |
17 | color_format *g2d_format, | |
18 | pixel_order *g2d_order, | |
19 | uint32_t *g2d_bpp) | |
20 | { | |
21 | *g2d_format = MSK_FORMAT_END; | |
22 | *g2d_order = ARGB_ORDER_END; | |
23 | *g2d_bpp = 0; | |
24 | ||
25 | switch (hal_format) { | |
26 | /* 16bpp */ | |
27 | case HAL_PIXEL_FORMAT_RGB_565: | |
28 | *g2d_format = CF_RGB_565; | |
29 | *g2d_order = AX_RGB; | |
30 | *g2d_bpp = 2; | |
31 | break; | |
32 | /* 32bpp */ | |
33 | case HAL_PIXEL_FORMAT_RGBX_8888: | |
34 | *g2d_format = CF_XRGB_8888; | |
35 | *g2d_order = AX_BGR; | |
36 | *g2d_bpp = 4; | |
37 | break; | |
38 | #ifdef EXYNOS_SUPPORT_BGRX_8888 | |
39 | case HAL_PIXEL_FORMAT_BGRX_8888: | |
40 | *g2d_format = CF_XRGB_8888; | |
41 | *g2d_order = AX_RGB; | |
42 | *g2d_bpp = 4; | |
43 | break; | |
44 | #endif | |
45 | case HAL_PIXEL_FORMAT_BGRA_8888: | |
46 | *g2d_format = CF_ARGB_8888; | |
47 | *g2d_order = AX_RGB; | |
48 | *g2d_bpp = 4; | |
49 | break; | |
50 | case HAL_PIXEL_FORMAT_RGBA_8888: | |
51 | *g2d_format = CF_ARGB_8888; | |
52 | *g2d_order = AX_BGR; | |
53 | *g2d_bpp = 4; | |
54 | break; | |
55 | case HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888: | |
56 | *g2d_format = CF_ARGB_8888; | |
57 | *g2d_order = BGR_AX; | |
58 | *g2d_bpp = 4; | |
59 | break; | |
60 | /* 12bpp */ | |
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; | |
66 | *g2d_order = P2_CRCB; | |
67 | *g2d_bpp = 1; | |
68 | break; | |
69 | default: | |
70 | ALOGE("%s: no matching color format(0x%x): failed", | |
71 | __func__, hal_format); | |
72 | return -1; | |
73 | break; | |
74 | } | |
75 | return 0; | |
76 | } | |
77 | ||
78 | #ifdef USES_VIRTUAL_DISPLAY | |
79 | ExynosG2DWrapper::ExynosG2DWrapper(ExynosOverlayDisplay *display, | |
80 | ExynosExternalDisplay *externalDisplay, | |
81 | ExynosVirtualDisplay *virtualDisplay) | |
82 | #else | |
83 | ExynosG2DWrapper::ExynosG2DWrapper(ExynosOverlayDisplay *display, ExynosExternalDisplay *hdmi) | |
84 | #endif | |
85 | { | |
86 | mDisplay = display; | |
87 | #ifdef USES_VIRTUAL_DISPLAY | |
88 | mExternalDisplay = externalDisplay; | |
89 | mVirtualDisplay = virtualDisplay; | |
90 | mAllocSize = 0; | |
91 | #else | |
92 | mExternalDisplay = hdmi; | |
93 | #endif | |
94 | } | |
95 | ||
96 | ExynosG2DWrapper::~ExynosG2DWrapper() | |
97 | { | |
98 | } | |
99 | ||
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) | |
104 | { | |
105 | int ret = 0; | |
106 | unsigned long srcYAddress = 0; | |
5763fb39 T |
107 | unsigned long dstYAddress = 0; |
108 | unsigned long dstCbCrAddress =0; | |
109 | ||
110 | ExynosRect srcImgRect, dstImgRect; | |
111 | ||
112 | fimg2d_blit BlitParam; | |
113 | fimg2d_param g2d_param; | |
114 | rotation g2d_rotation; | |
115 | ||
116 | fimg2d_addr srcYAddr; | |
117 | fimg2d_addr srcCbCrAddr; | |
118 | fimg2d_image srcImage; | |
119 | fimg2d_rect srcRect; | |
120 | ||
121 | fimg2d_addr dstYAddr; | |
122 | fimg2d_addr dstCbCrAddr; | |
123 | fimg2d_image dstImage; | |
124 | fimg2d_rect dstRect; | |
125 | ||
126 | fimg2d_scale Scaling; | |
127 | fimg2d_repeat Repeat; | |
128 | fimg2d_bluscr Bluscr; | |
129 | fimg2d_clip Clipping; | |
130 | ||
131 | pixel_order g2d_order; | |
132 | color_format g2d_format; | |
133 | addr_space addr_type = ADDR_USER; | |
134 | ||
135 | uint32_t srcG2d_bpp, dstG2d_bpp; | |
136 | uint32_t srcImageSize, dstImageSize; | |
137 | bool src_ion_mapped = false; | |
138 | bool dst_ion_mapped = false; | |
139 | ||
140 | private_handle_t *src_handle = private_handle_t::dynamicCast(src_layer.handle); | |
141 | ||
142 | if (!force_clear) { | |
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; | |
150 | } | |
151 | ||
152 | #ifndef USES_VIRTUAL_DISPLAY | |
153 | int w, h; | |
154 | { | |
155 | w = mExternalDisplay->mXres; | |
156 | h = mExternalDisplay->mYres; | |
157 | } | |
158 | #endif | |
159 | ||
160 | if (is_lcd) { | |
161 | dstImgRect.x = 0; | |
162 | dstImgRect.y = 0; | |
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; | |
168 | } else { | |
169 | if (force_clear) { | |
170 | dstImgRect.x = 0; | |
171 | dstImgRect.y = 0; | |
172 | dstImgRect.w = dst_handle->width; | |
173 | dstImgRect.h = dst_handle->height; | |
174 | } else { | |
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); | |
179 | } | |
180 | #ifdef USES_VIRTUAL_DISPLAY | |
181 | dstImgRect.fullW = dst_handle->stride; | |
182 | dstImgRect.fullH = dst_handle->vstride; | |
183 | #else | |
184 | dstImgRect.fullW = w; | |
185 | dstImgRect.fullH = h; | |
186 | #endif | |
187 | dstImgRect.colorFormat = dst_handle->format; | |
188 | } | |
189 | ||
190 | g2d_rotation = rotateValueHAL2G2D(transform); | |
191 | ||
192 | ALOGV("%s: \n" | |
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 ", | |
195 | __func__, | |
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); | |
200 | ||
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; | |
208 | } | |
209 | } else { | |
210 | if ((srcImgRect.w != dstImgRect.w) || (srcImgRect.h != dstImgRect.h)) { | |
211 | rotatedDstW = dstImgRect.w; | |
212 | rotatedDstH = dstImgRect.h; | |
213 | } | |
214 | } | |
215 | ||
216 | if (formatValueHAL2G2D(srcImgRect.colorFormat, &g2d_format, &g2d_order, &srcG2d_bpp) < 0) { | |
217 | ALOGE("%s: formatValueHAL2G2D() failed", __func__); | |
218 | return -1; | |
219 | } | |
220 | srcImageSize = srcImgRect.fullW*srcImgRect.fullH; | |
221 | if (srcAddress) { | |
222 | srcYAddress = srcAddress; | |
223 | } else { | |
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__); | |
227 | return -ENOMEM; | |
228 | } | |
229 | src_ion_mapped = true; | |
230 | } | |
231 | ||
232 | srcYAddr.type = addr_type; | |
233 | srcYAddr.start = (unsigned long)srcYAddress; | |
234 | srcCbCrAddr.type = addr_type; | |
235 | srcCbCrAddr.start = 0; | |
236 | ||
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; | |
250 | ||
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; | |
256 | } else { | |
257 | memset(&srcImage, 0, sizeof(srcImage)); | |
258 | Scaling.mode = NO_SCALING; | |
259 | Scaling.src_w= 0; | |
260 | Scaling.src_h= 0; | |
261 | Scaling.dst_w= 0; | |
262 | Scaling.dst_h= 0; | |
263 | } | |
264 | ||
265 | if (dst_handle->fd >= 0) { | |
266 | if (formatValueHAL2G2D(dstImgRect.colorFormat, &g2d_format, &g2d_order, &dstG2d_bpp) < 0) { | |
267 | ALOGE("%s: formatValueHAL2G2D() failed", __func__); | |
268 | return -1; | |
269 | } | |
270 | dstImageSize = dstImgRect.fullW*dstImgRect.fullH; | |
271 | if (dstAddress) { | |
272 | dstYAddress = dstAddress; | |
273 | } else { | |
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__); | |
279 | return -ENOMEM; | |
280 | } | |
281 | } else { | |
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__); | |
285 | return -ENOMEM; | |
286 | } | |
287 | ||
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); | |
293 | return -ENOMEM; | |
294 | } | |
295 | } | |
296 | } | |
297 | #else | |
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__); | |
301 | return -ENOMEM; | |
302 | } | |
303 | #endif | |
304 | dst_ion_mapped = true; | |
305 | } | |
306 | ||
307 | dstYAddr.type = addr_type; | |
308 | dstYAddr.start = (unsigned long)dstYAddress; | |
309 | dstCbCrAddr.type = addr_type; | |
310 | dstCbCrAddr.start = (unsigned long)dstCbCrAddress; | |
311 | ||
312 | if (force_clear) { | |
313 | dstRect.x1 = 0; | |
314 | dstRect.y1 = 0; | |
315 | dstRect.x2 = dstImgRect.fullW; | |
316 | dstRect.y2 = dstImgRect.fullH; | |
317 | } else { | |
318 | dstRect.x1 = dstImgRect.x; | |
319 | dstRect.y1 = dstImgRect.y; | |
320 | dstRect.x2 = dstImgRect.x + dstImgRect.w; | |
321 | dstRect.y2 = dstImgRect.y + dstImgRect.h; | |
322 | } | |
323 | ||
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; | |
333 | } else { | |
334 | memset(&dstImage, 0, sizeof(dstImage)); | |
335 | } | |
336 | ||
337 | Repeat.mode = NO_REPEAT; | |
338 | Repeat.pad_color = 0; | |
339 | Bluscr.mode = OPAQUE; | |
340 | Bluscr.bs_color = 0; | |
341 | Bluscr.bg_color = 0; | |
342 | Clipping.enable = false; | |
343 | Clipping.x1 = 0; | |
344 | Clipping.y1 = 0; | |
345 | Clipping.x2 = 0; | |
346 | Clipping.y2 = 0; | |
347 | ||
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; | |
357 | ||
358 | if (force_clear) { | |
359 | BlitParam.op = mode; | |
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; | |
368 | } else { | |
369 | BlitParam.op = mode; | |
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; | |
378 | } | |
379 | ||
380 | ret = stretchFimgApi(&BlitParam); | |
381 | ||
382 | if (src_ion_mapped) | |
383 | munmap((void *)srcYAddress, srcImageSize*srcG2d_bpp); | |
384 | ||
385 | if (dst_ion_mapped) { | |
386 | #ifdef USES_VIRTUAL_DISPLAY | |
387 | if (mVirtualDisplay == NULL) | |
388 | munmap((void *)dstYAddress, dstImageSize*dstG2d_bpp); | |
389 | else { | |
390 | munmap((void *)dstYAddress, dstImageSize*dstG2d_bpp); | |
391 | munmap((void *)dstCbCrAddress, dstImageSize*dstG2d_bpp / 2); | |
392 | } | |
393 | #else | |
394 | munmap((void *)dstYAddress, dstImageSize*dstG2d_bpp); | |
395 | #endif | |
396 | } | |
397 | ||
398 | if (ret < 0) { | |
399 | ALOGE("%s: stretch failed", __func__); | |
400 | return -1; | |
401 | } | |
402 | ||
403 | return 0; | |
404 | } | |
405 | ||
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) | |
412 | { | |
413 | int ret = 0; | |
5763fb39 T |
414 | |
415 | ExynosRect srcImgRect, dstImgRect; | |
416 | ||
417 | fimg2d_blit_raw BlitParam; | |
418 | fimg2d_param g2d_param; | |
419 | rotation g2d_rotation = ORIGIN; | |
420 | ||
421 | fimg2d_addr srcYAddr; | |
422 | fimg2d_addr srcCbCrAddr; | |
423 | fimg2d_image srcImage; | |
424 | fimg2d_rect srcRect; | |
425 | ||
426 | fimg2d_addr dstYAddr; | |
427 | fimg2d_addr dstCbCrAddr; | |
428 | fimg2d_image dstImage; | |
429 | fimg2d_rect dstRect; | |
430 | ||
431 | fimg2d_scale Scaling; | |
432 | fimg2d_repeat Repeat; | |
433 | fimg2d_bluscr Bluscr; | |
434 | fimg2d_clip Clipping; | |
435 | ||
436 | pixel_order g2d_order; | |
437 | color_format g2d_format; | |
438 | addr_space addr_type = ADDR_PHYS; | |
439 | ||
440 | uint32_t srcG2d_bpp, dstG2d_bpp; | |
441 | uint32_t srcImageSize, dstImageSize; | |
5763fb39 T |
442 | |
443 | private_handle_t *src_handle = private_handle_t::dynamicCast(src_layer.handle); | |
444 | ||
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; | |
452 | ||
453 | if (!secure_handle) { | |
454 | ALOGE("%s: secure g2d buffer handle is NULL", __func__); | |
455 | return -1; | |
456 | } | |
457 | ||
458 | if (force_clear) { | |
459 | dstImgRect.x = 0; | |
460 | dstImgRect.y = 0; | |
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; | |
466 | } else { | |
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; | |
474 | } | |
475 | ||
476 | ALOGV("%s: \n" | |
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 ", | |
479 | __func__, | |
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); | |
484 | ||
485 | if (secure_handle->fd >= 0) { | |
486 | int rotatedDstW = dstImgRect.w; | |
487 | int rotatedDstH = dstImgRect.h; | |
488 | ||
489 | if (formatValueHAL2G2D(srcImgRect.colorFormat, &g2d_format, &g2d_order, &srcG2d_bpp) < 0) { | |
490 | ALOGE("%s: formatValueHAL2G2D() failed", __func__); | |
491 | return -1; | |
492 | } | |
493 | srcImageSize = srcImgRect.fullW*srcImgRect.fullH; | |
494 | ||
495 | srcYAddr.type = addr_type; | |
496 | srcYAddr.start = (unsigned long)secure_handle->fd; | |
497 | srcCbCrAddr.type = addr_type; | |
498 | srcCbCrAddr.start = 0; | |
499 | ||
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; | |
513 | ||
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; | |
519 | } else { | |
520 | memset(&srcImage, 0, sizeof(srcImage)); | |
521 | Scaling.mode = NO_SCALING; | |
522 | Scaling.src_w= 0; | |
523 | Scaling.src_h= 0; | |
524 | Scaling.dst_w= 0; | |
525 | Scaling.dst_h= 0; | |
526 | } | |
527 | ||
528 | if (dst_handle->fd >= 0) { | |
529 | if (formatValueHAL2G2D(dstImgRect.colorFormat, &g2d_format, &g2d_order, &dstG2d_bpp) < 0) { | |
530 | ALOGE("%s: formatValueHAL2G2D() failed", __func__); | |
531 | return -1; | |
532 | } | |
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; | |
538 | ||
539 | if (force_clear) { | |
540 | dstRect.x1 = 0; | |
541 | dstRect.y1 = 0; | |
542 | dstRect.x2 = dstImgRect.fullW; | |
543 | dstRect.y2 = dstImgRect.fullH; | |
544 | } else { | |
545 | dstRect.x1 = dstImgRect.x; | |
546 | dstRect.y1 = dstImgRect.y; | |
547 | dstRect.x2 = dstImgRect.x + dstImgRect.w; | |
548 | dstRect.y2 = dstImgRect.y + dstImgRect.h; | |
549 | } | |
550 | ||
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; | |
560 | } else { | |
561 | memset(&dstImage, 0, sizeof(dstImage)); | |
562 | } | |
563 | ||
564 | Repeat.mode = NO_REPEAT; | |
565 | Repeat.pad_color = 0; | |
566 | Bluscr.mode = OPAQUE; | |
567 | Bluscr.bs_color = 0; | |
568 | Bluscr.bg_color = 0; | |
569 | Clipping.enable = false; | |
570 | Clipping.x1 = 0; | |
571 | Clipping.y1 = 0; | |
572 | Clipping.x2 = 0; | |
573 | Clipping.y2 = 0; | |
574 | ||
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; | |
584 | ||
585 | memset(&BlitParam, 0, sizeof(BlitParam)); | |
586 | BlitParam.op = mode; | |
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; | |
593 | ||
594 | ret = G2DDRM_Blit(&BlitParam); | |
595 | ||
596 | if (ret != 0) { | |
597 | ALOGE("%s: G2DDRM_Blit failed(ret=%d)", __func__, ret); | |
598 | return -1; | |
599 | } | |
600 | ||
601 | return 0; | |
602 | } | |
603 | ||
604 | bool ExynosG2DWrapper::InitSecureG2D() | |
605 | { | |
606 | if (mVirtualDisplay == NULL) | |
607 | return false; | |
608 | ||
609 | int ret = 0; | |
610 | if (mVirtualDisplay->mPhysicallyLinearBuffer == NULL) { | |
611 | ALOGI("initialize secure G2D"); | |
612 | ret = G2DDRM_Initialize(); | |
613 | if (ret != 0) { | |
614 | ALOGE("%s: G2DDRM_Initialize failed, ret %d", __func__, ret); | |
615 | return false; | |
616 | } | |
617 | ||
618 | int dst_stride; | |
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, | |
629 | &dst_stride); | |
630 | if (ret < 0) { | |
631 | ALOGE("failed to allocate secure g2d buffer: %s", strerror(-ret)); | |
632 | G2DDRM_Terminate(); | |
633 | return false; | |
634 | } else { | |
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__); | |
641 | return -ENOMEM; | |
642 | } | |
429d6b1e | 643 | ALOGI("allocated secure g2d input buffer: 0x%lx", mVirtualDisplay->mPhysicallyLinearBufferAddr); |
5763fb39 T |
644 | } |
645 | } | |
646 | return true; | |
647 | ||
648 | } | |
649 | ||
650 | bool ExynosG2DWrapper::TerminateSecureG2D() | |
651 | { | |
652 | if (mVirtualDisplay == NULL) | |
653 | return false; | |
654 | ||
655 | int ret = 0; | |
656 | if (mVirtualDisplay->mPhysicallyLinearBuffer) { | |
429d6b1e | 657 | ALOGI("free g2d input buffer: 0x%lx", mVirtualDisplay->mPhysicallyLinearBufferAddr); |
5763fb39 T |
658 | munmap((void *)mVirtualDisplay->mPhysicallyLinearBufferAddr, mAllocSize); |
659 | mVirtualDisplay->mPhysicallyLinearBufferAddr = 0; | |
660 | ||
661 | alloc_device_t* allocDevice = mVirtualDisplay->mAllocDevice; | |
662 | allocDevice->free(allocDevice, mVirtualDisplay->mPhysicallyLinearBuffer); | |
663 | mVirtualDisplay->mPhysicallyLinearBuffer = NULL; | |
664 | ||
665 | ALOGI("terminate secure G2D"); | |
666 | ret = G2DDRM_Terminate(); | |
667 | if (ret != 0) { | |
668 | ALOGE("%s: G2DDRM_Terminate failed, ret %d", __func__, ret); | |
669 | } | |
670 | } | |
671 | return 0; | |
672 | } | |
673 | #endif | |
674 | ||
429d6b1e | 675 | void ExynosG2DWrapper::exynos5_cleanup_g2d(int force __unused) |
5763fb39 T |
676 | { |
677 | #ifdef G2D_COMPOSITION | |
678 | exynos5_g2d_data_t &mG2d = mDisplay->mG2d; | |
679 | ||
680 | if (!mDisplay->mG2dMemoryAllocated && !force) | |
681 | return; | |
682 | ||
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; | |
691 | } | |
692 | } | |
693 | } | |
694 | ||
695 | memset(&mG2d, 0, sizeof(mG2d)); | |
696 | mDisplay->mG2dLayers = 0; | |
697 | mDisplay->mG2dComposition = 0; | |
698 | ||
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; | |
704 | } | |
705 | } | |
706 | } | |
707 | ||
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; | |
713 | } | |
714 | } | |
715 | } | |
716 | mDisplay->mAllocatedLayers = 0; | |
717 | mDisplay->mG2dMemoryAllocated = 0; | |
718 | #endif | |
719 | } | |
720 | ||
429d6b1e | 721 | int ExynosG2DWrapper::exynos5_g2d_buf_alloc(hwc_display_contents_1_t* contents __unused) |
5763fb39 T |
722 | { |
723 | #ifdef G2D_COMPOSITION | |
724 | int w, h; | |
725 | int dst_stride; | |
726 | int format = HAL_PIXEL_FORMAT_RGBX_8888; | |
727 | int usage; | |
728 | ||
729 | if (mDisplay->mG2dMemoryAllocated) | |
730 | return 0; | |
731 | ||
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; | |
737 | ||
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); | |
743 | ||
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], | |
747 | &dst_stride); | |
748 | if (ret < 0) { | |
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; | |
752 | } | |
753 | } | |
754 | mDisplay->mWinBufMapSize[i] = dst_stride * h * 4 + 0x8000; | |
755 | } | |
756 | mDisplay->mAllocatedLayers = mDisplay->mG2dLayers; | |
757 | ||
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; | |
766 | } else { | |
767 | ALOGE("Failed to map win %d buf %d buffer", i, j); | |
768 | goto G2D_BUF_ALLOC_FAIL; | |
769 | } | |
770 | } | |
771 | } | |
772 | ||
773 | mDisplay->mG2dMemoryAllocated = 1; | |
774 | return 0; | |
775 | ||
776 | G2D_BUF_ALLOC_FAIL: | |
777 | mDisplay->mG2dMemoryAllocated = 1; | |
778 | /* memory released from the caller */ | |
779 | ||
780 | #endif | |
781 | return 1; | |
782 | } | |
783 | ||
429d6b1e | 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) |
5763fb39 T |
785 | { |
786 | #ifdef G2D_COMPOSITION | |
787 | int ret = 0; | |
788 | int cur_buf = mDisplay->mG2dCurrentBuffer[win_idx_2d]; | |
789 | int prev_buf; | |
790 | private_handle_t *handle; | |
791 | int fence = -1; | |
792 | private_handle_t *src_handle = private_handle_t::dynamicCast(layer.handle); | |
793 | ||
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; | |
799 | } | |
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; | |
804 | } else { | |
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; | |
812 | } | |
813 | ||
814 | if (layer.acquireFenceFd >= 0) { | |
815 | sync_wait(layer.acquireFenceFd, 1000); | |
816 | } | |
817 | ||
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); | |
821 | } else { | |
822 | ret = runCompositor(layer, dst_handle, 0, 0xff, 0, BLIT_OP_SRC, false, 0, | |
823 | mDisplay->mWinBufVirtualAddress[win_idx_2d][cur_buf], 1); | |
824 | } | |
825 | if (ret < 0) | |
826 | ALOGE("%s:runCompositor: Failed", __func__); | |
827 | } | |
828 | ||
829 | mDisplay->mLastG2dLayerHandle[win_idx_2d] = (uint32_t)layer.handle; | |
830 | ||
831 | if (layer.acquireFenceFd >= 0) | |
832 | close(layer.acquireFenceFd); | |
833 | ||
834 | return fence; | |
835 | #else | |
836 | return -1; | |
837 | #endif | |
838 | } | |
839 |