1 // clang-format off
2 /*
3 * Copyright (C) 2016-2017 ARM Limited. All rights reserved.
4 *
5 * Copyright (C) 2008 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #ifndef MALI_GRALLOC_FORMATS_H_
21 #define MALI_GRALLOC_FORMATS_H_
22
23 #include <system/graphics.h>
24
25 /* Internal formats are represented in gralloc as a 64bit identifier
26 * where the 32 lower bits are a base format and the 32 upper bits are modifiers.
27 *
28 * Modifier bits are divided into mutually exclusive ones and those that are not.
29 */
30 /* Internal format type */
31 typedef uint64_t mali_gralloc_internal_format;
32
33 /* Internal format masks */
34 #define MALI_GRALLOC_INTFMT_FMT_MASK 0x00000000ffffffffULL
35 #define MALI_GRALLOC_INTFMT_EXT_MASK 0xffffffff00000000ULL
36 #define MALI_GRALLOC_INTFMT_ME_EXT_MASK 0x0000ffff00000000ULL
37 #define MALI_GRALLOC_INTFMT_REG_EXT_MASK 0xffff000000000000ULL
38
39 /* Internal base formats */
40
41 /* Base formats that do not have an identical HAL match
42 * are defined starting at the Android private range
43 */
44 #define MALI_GRALLOC_FORMAT_INTERNAL_RANGE_BASE 0x100
45
46 typedef enum
47 {
48 MALI_GRALLOC_FORMAT_TYPE_USAGE,
49 MALI_GRALLOC_FORMAT_TYPE_INTERNAL,
50 } mali_gralloc_format_type;
51
52 typedef enum
53 {
54 /* Internal definitions for HAL formats. */
55 MALI_GRALLOC_FORMAT_INTERNAL_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
56 MALI_GRALLOC_FORMAT_INTERNAL_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
57 MALI_GRALLOC_FORMAT_INTERNAL_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
58 MALI_GRALLOC_FORMAT_INTERNAL_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
59 MALI_GRALLOC_FORMAT_INTERNAL_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
60 MALI_GRALLOC_FORMAT_INTERNAL_YV12 = HAL_PIXEL_FORMAT_YV12,
61 MALI_GRALLOC_FORMAT_INTERNAL_Y8 = HAL_PIXEL_FORMAT_Y8,
62 MALI_GRALLOC_FORMAT_INTERNAL_Y16 = HAL_PIXEL_FORMAT_Y16,
63 MALI_GRALLOC_FORMAT_INTERNAL_YUV420_888 = HAL_PIXEL_FORMAT_YCbCr_420_888,
64
65 /* Camera specific HAL formats */
66 MALI_GRALLOC_FORMAT_INTERNAL_RAW16 = HAL_PIXEL_FORMAT_RAW16,
67 MALI_GRALLOC_FORMAT_INTERNAL_RAW12 = HAL_PIXEL_FORMAT_RAW12,
68 MALI_GRALLOC_FORMAT_INTERNAL_RAW10 = HAL_PIXEL_FORMAT_RAW10,
69 MALI_GRALLOC_FORMAT_INTERNAL_BLOB = HAL_PIXEL_FORMAT_BLOB,
70
71 /* Flexible YUV formats would be parsed but not have any representation as
72 * internal format itself but one of the ones below
73 */
74
75 /* The internal private formats that have no HAL equivivalent are defined
76 * afterwards starting at a specific base range */
77 MALI_GRALLOC_FORMAT_INTERNAL_NV12 = MALI_GRALLOC_FORMAT_INTERNAL_RANGE_BASE,
78 MALI_GRALLOC_FORMAT_INTERNAL_NV21,
79 MALI_GRALLOC_FORMAT_INTERNAL_YUV422_8BIT,
80
81 /* Extended YUV formats
82 *
83 * NOTE: P010, P210, and Y410 are only supported uncompressed.
84 */
85 MALI_GRALLOC_FORMAT_INTERNAL_Y0L2,
86 MALI_GRALLOC_FORMAT_INTERNAL_P010,
87 MALI_GRALLOC_FORMAT_INTERNAL_P210,
88 MALI_GRALLOC_FORMAT_INTERNAL_Y210,
89 MALI_GRALLOC_FORMAT_INTERNAL_Y410,
90
91 /* Add more internal formats here. Make sure decode_internal_format() is updated. */
92
93 /* These are legacy 0.3 gralloc formats used only by the wrap/unwrap macros. */
94 MALI_GRALLOC_FORMAT_INTERNAL_YV12_WRAP,
95 MALI_GRALLOC_FORMAT_INTERNAL_Y8_WRAP,
96 MALI_GRALLOC_FORMAT_INTERNAL_Y16_WRAP,
97
98 MALI_GRALLOC_FORMAT_INTERNAL_RANGE_LAST,
99 } mali_gralloc_pixel_format;
100
101 /* Format Modifier Bits Locations */
102 #define MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START 32
103 #define MALI_GRALLOC_INTFMT_EXTENSION_BIT_START (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 16)
104
105 /* Mutually Exclusive Modifier Bits */
106
107 /* This format will use AFBC */
108 #define MALI_GRALLOC_INTFMT_AFBC_BASIC (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 0))
109
110 /* This format uses AFBC split block mode */
111 #define MALI_GRALLOC_INTFMT_AFBC_SPLITBLK (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 1))
112
113 #define MALI_GRALLOC_INTFMT_UNUSED (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 2))
114
115 /* This format uses AFBC wide block mode */
116 #define MALI_GRALLOC_INTFMT_AFBC_WIDEBLK (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 3))
117
118 /* Regular Modifier Bits */
119 #define MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS (1ULL << (MALI_GRALLOC_INTFMT_EXTENSION_BIT_START + 0))
120
121 /* This mask should be used to check or clear support for AFBC for an internal format
122 * These bits are mutually exclusive so this mask should not be used to enable support
123 */
124 #define MALI_GRALLOC_INTFMT_AFBCENABLE_MASK \
125 ((uint64_t)(MALI_GRALLOC_INTFMT_AFBC_BASIC | MALI_GRALLOC_INTFMT_AFBC_SPLITBLK | MALI_GRALLOC_INTFMT_AFBC_WIDEBLK))
126
127 /* These are legacy Gralloc 0.3 support macros for passing private formats through the 0.3 alloc interface.
128 * It packs modifier bits together with base format into a 32 bit format identifier.
129 * Gralloc 1.0 interface should use private functions to set private buffer format in the buffer descriptor.
130 *
131 * Packing:
132 *
133 * Bits 15-0: mali_gralloc_pixel_format format
134 * Bits 23-16: mutually exclusive modifier bits
135 * Bits 31-24: regular modifier bits
136 */
mali_gralloc_format_wrapper(int format,int modifiers)137 static inline int mali_gralloc_format_wrapper(int format, int modifiers)
138 {
139 /* Internal formats that are identical to HAL formats
140 * have the same definition. This is convenient for
141 * client parsing code to not have to parse them separately.
142 *
143 * For 3 of the HAL YUV formats that have very large definitions
144 * this causes problems for packing in modifier bits.
145 * Because of this reason we redefine these three formats
146 * while packing/unpacking them.
147 */
148 if (format == MALI_GRALLOC_FORMAT_INTERNAL_YV12)
149 {
150 format = MALI_GRALLOC_FORMAT_INTERNAL_YV12_WRAP;
151 }
152 else if (format == MALI_GRALLOC_FORMAT_INTERNAL_Y8)
153 {
154 format = MALI_GRALLOC_FORMAT_INTERNAL_Y8_WRAP;
155 }
156 else if (format == MALI_GRALLOC_FORMAT_INTERNAL_Y16)
157 {
158 format = MALI_GRALLOC_FORMAT_INTERNAL_Y16_WRAP;
159 }
160
161 return (modifiers | format);
162 }
163
mali_gralloc_format_unwrap(int x)164 static inline uint64_t mali_gralloc_format_unwrap(int x)
165 {
166 uint64_t internal_format = (uint64_t)(((((uint64_t)(x)) & 0xff000000) << 24) | // Regular modifier bits
167 ((((uint64_t)(x)) & 0x00ff0000) << 16) | // Mutually exclusive modifier bits
168 (((uint64_t)(x)) & 0x0000ffff)); // Private format
169
170 uint64_t base_format = internal_format & MALI_GRALLOC_INTFMT_FMT_MASK;
171 uint64_t modifiers = internal_format & MALI_GRALLOC_INTFMT_EXT_MASK;
172
173 if (base_format == MALI_GRALLOC_FORMAT_INTERNAL_YV12_WRAP)
174 {
175 base_format = MALI_GRALLOC_FORMAT_INTERNAL_YV12;
176 }
177 else if (base_format == MALI_GRALLOC_FORMAT_INTERNAL_Y8_WRAP)
178 {
179 base_format = MALI_GRALLOC_FORMAT_INTERNAL_Y8;
180 }
181 else if (base_format == MALI_GRALLOC_FORMAT_INTERNAL_Y16_WRAP)
182 {
183 base_format = MALI_GRALLOC_FORMAT_INTERNAL_Y16;
184 }
185
186 return (modifiers | base_format);
187 }
188
189 #define GRALLOC_PRIVATE_FORMAT_WRAPPER(x) (mali_gralloc_format_wrapper(x, 0))
190 #define GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC(x) (mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_BASIC >> 16)))
191 #define GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_SPLITBLK(x) \
192 (mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_SPLITBLK >> 16)))
193 #define GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_WIDEBLK(x) \
194 (mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_WIDEBLK >> 16)))
195 #define GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_TILED_HEADERS_BASIC(x) \
196 (mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS >> 24) | \
197 (MALI_GRALLOC_INTFMT_AFBC_BASIC >> 16)))
198 #define GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_TILED_HEADERS_WIDE(x) \
199 (mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS >> 24) | \
200 (MALI_GRALLOC_INTFMT_AFBC_WIDEBLK >> 16)))
201 #define GRALLOC_PRIVATE_FORMAT_UNWRAP(x) mali_gralloc_format_unwrap(x)
202
203 /* IP block capability masks */
204 #define MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT ((uint64_t)(1 << 0))
205 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC ((uint64_t)(1 << 1))
206 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK ((uint64_t)(1 << 2))
207 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK ((uint64_t)(1 << 3))
208 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK_YUV_DISABLE ((uint64_t)(1 << 4))
209 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_NOREAD ((uint64_t)(1 << 5))
210 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_NOWRITE ((uint64_t)(1 << 6))
211 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_TILED_HEADERS ((uint64_t)(1 << 7))
212
213 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK \
214 ((uint64_t)(MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC | MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK | \
215 MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK | MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_TILED_HEADERS))
216
217 struct mali_gralloc_format_caps
218 {
219 uint64_t caps_mask;
220 };
221 typedef struct mali_gralloc_format_caps mali_gralloc_format_caps;
222
223 #define MALI_GRALLOC_FORMATCAPS_SYM_NAME mali_gralloc_format_capabilities
224 #define MALI_GRALLOC_FORMATCAPS_SYM_NAME_STR "mali_gralloc_format_capabilities"
225
226 /* Producer and Consumer definitions */
227 typedef enum
228 {
229 MALI_GRALLOC_PRODUCER_VIDEO_DECODER,
230 MALI_GRALLOC_PRODUCER_GPU,
231 MALI_GRALLOC_PRODUCER_CAMERA,
232 } mali_gralloc_producer_type;
233
234 typedef enum
235 {
236
237 /* For surface composition in SurfaceFlinger a producer
238 * will not know what consumer will process a buffer.
239 *
240 * MALI_GRALLOC_CONSUMER_GPU_OR_DISPLAY means the GPU
241 * MUST support the given format but it should be allocated
242 * with preference to the DPU.
243 */
244 MALI_GRALLOC_CONSUMER_GPU_OR_DISPLAY,
245 MALI_GRALLOC_CONSUMER_VIDEO_ENCODER,
246
247 /* This is used when no known "premium" dpu is configured.
248 * For example, HDLCD/CLCD would be such a dpu.
249 */
250 MALI_GRALLOC_CONSUMER_GPU_EXCL,
251 } mali_gralloc_consumer_type;
252
253 /* Internal prototypes */
254 #if defined(GRALLOC_LIBRARY_BUILD)
255 uint64_t mali_gralloc_select_format(uint64_t req_format, mali_gralloc_format_type type, uint64_t usage,
256 int buffer_size);
257 #endif
258
259 #ifdef __cplusplus
260 extern "C" {
261 #endif
262
263 void mali_gralloc_get_gpu_caps(struct mali_gralloc_format_caps *gpu_caps);
264
265 #ifdef __cplusplus
266 }
267 #endif
268
269 #endif /* MALI_GRALLOC_FORMATS_H_ */
270 // clang-format on
271