1 /*
2 * Copyright (C) 2020 Samsung Electronics Co. Ltd.
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 #include <ui/Gralloc.h>
18 #include "VendorGraphicBuffer.h"
19 #include "mali_gralloc_formats.h"
20 #include "mali_gralloc_buffer.h"
21 #include "exynos_format.h"
22 #include "gralloc_helper.h"
23 #include <log/log.h>
24
25 using namespace android;
26 using namespace vendor::graphics;
27
28
lock64(buffer_handle_t handle,uint64_t usage,const Rect & bounds,void ** vaddr,int32_t * outBytesPerPixel,int32_t * outBytesPerStride)29 status_t VendorGraphicBufferMapper::lock64(buffer_handle_t handle, uint64_t usage, const Rect& bounds,
30 void** vaddr, int32_t* outBytesPerPixel, int32_t* outBytesPerStride)
31 {
32 return lockAsync(handle, usage, usage, bounds, vaddr,
33 -1, outBytesPerPixel, outBytesPerStride);
34 }
35
lockYCbCr64(buffer_handle_t handle,uint64_t usage,const Rect & bounds,android_ycbcr * ycbcr)36 status_t VendorGraphicBufferMapper::lockYCbCr64(buffer_handle_t handle,
37 uint64_t usage, const Rect& bounds, android_ycbcr *ycbcr)
38 {
39 status_t err = getGrallocMapper().lock(handle, usage, bounds, -1, ycbcr);
40
41 if (!(usage & VendorGraphicBufferUsage::VIDEO_PRIVATE_DATA))
42 return err;
43
44 /* TODO: clean this typecasting... */
45 const private_handle_t * const hnd = (private_handle_t *)handle;
46
47 switch (hnd->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK)
48 {
49 case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC:
50 case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC:
51 ycbcr->cb = (void *)(hnd->attr_base);
52 break;
53 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC:
54 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC:
55 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50:
56 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75:
57 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40:
58 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60:
59 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80:
60 ycbcr->cr = (void *)(hnd->attr_base);
61 break;
62 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC:
63 ycbcr->cr = (void *)(hnd->attr_base);
64 break;
65 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC:
66 ycbcr->cr = (void *)(hnd->attr_base);
67 break;
68 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
69 ycbcr->cr = (void *)(hnd->attr_base);
70 break;
71 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50:
72 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75:
73 ycbcr->cr = (void *)(hnd->attr_base);
74 break;
75 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40:
76 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60:
77 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80:
78 ycbcr->cr = (void *)(hnd->attr_base);
79 break;
80 case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M:
81 case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL:
82 ycbcr->cb = (void *)(hnd->attr_base);
83 break;
84 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M:
85 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_S10B:
86 ycbcr->cr = (void *)(hnd->attr_base);
87 break;
88 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN:
89 ycbcr->cr = (void *)(hnd->attr_base);
90 break;
91 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_S10B:
92 ycbcr->cr = (void *)(hnd->attr_base);
93 break;
94 case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M:
95 ycbcr->cr = (void *)(hnd->attr_base);
96 break;
97 default:
98 break;
99 }
100
101 return err;
102 }
103