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