• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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     /* Internal definitions for HAL formats. */
48     MALI_GRALLOC_FORMAT_INTERNAL_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
49     MALI_GRALLOC_FORMAT_INTERNAL_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
50     MALI_GRALLOC_FORMAT_INTERNAL_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
51     MALI_GRALLOC_FORMAT_INTERNAL_RGB_565 = HAL_PIXEL_FORMAT_RGB_565 ,
52     MALI_GRALLOC_FORMAT_INTERNAL_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
53     MALI_GRALLOC_FORMAT_INTERNAL_YV12 = HAL_PIXEL_FORMAT_YV12 ,
54     MALI_GRALLOC_FORMAT_INTERNAL_Y8 = HAL_PIXEL_FORMAT_Y8,
55     MALI_GRALLOC_FORMAT_INTERNAL_Y16 = HAL_PIXEL_FORMAT_Y16,
56     MALI_GRALLOC_FORMAT_INTERNAL_YUV420_888 = HAL_PIXEL_FORMAT_YCbCr_420_888,
57 
58     /* Camera specific HAL formats */
59     MALI_GRALLOC_FORMAT_INTERNAL_RAW16 = HAL_PIXEL_FORMAT_RAW16,
60     MALI_GRALLOC_FORMAT_INTERNAL_RAW12 = HAL_PIXEL_FORMAT_RAW12,
61     MALI_GRALLOC_FORMAT_INTERNAL_RAW10 = HAL_PIXEL_FORMAT_RAW10,
62     MALI_GRALLOC_FORMAT_INTERNAL_BLOB = HAL_PIXEL_FORMAT_BLOB,
63 
64     /* Flexible YUV formats would be parsed but not have any representation as
65      * internal format itself but one of the ones below
66      */
67 
68     /* The internal private formats that have no HAL equivivalent are defined
69      * afterwards starting at a specific base range */
70     MALI_GRALLOC_FORMAT_INTERNAL_NV12 = MALI_GRALLOC_FORMAT_INTERNAL_RANGE_BASE,
71     MALI_GRALLOC_FORMAT_INTERNAL_NV21,
72     MALI_GRALLOC_FORMAT_INTERNAL_YUV422_8BIT,
73 
74     /* Extended YUV formats
75      *
76      * NOTE: P010, P210, and Y410 are only supported uncompressed.
77      */
78     MALI_GRALLOC_FORMAT_INTERNAL_Y0L2,
79     MALI_GRALLOC_FORMAT_INTERNAL_P010,
80     MALI_GRALLOC_FORMAT_INTERNAL_P210,
81     MALI_GRALLOC_FORMAT_INTERNAL_Y210,
82     MALI_GRALLOC_FORMAT_INTERNAL_Y410,
83 
84     /* Add more internal formats here. Make sure decode_internal_format() is updated. */
85 
86     /* These are legacy 0.3 gralloc formats used only by the wrap/unwrap macros. */
87     MALI_GRALLOC_FORMAT_INTERNAL_YV12_WRAP,
88     MALI_GRALLOC_FORMAT_INTERNAL_Y8_WRAP,
89     MALI_GRALLOC_FORMAT_INTERNAL_Y16_WRAP,
90 
91 	MALI_GRALLOC_FORMAT_INTERNAL_RANGE_LAST,
92 } mali_gralloc_pixel_format;
93 
94 
95 /* Format Modifier Bits Locations */
96 #define MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START             32
97 #define MALI_GRALLOC_INTFMT_EXTENSION_BIT_START                (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START+16)
98 
99 /* Mutually Exclusive Modifier Bits */
100 
101 /* This format will use AFBC */
102 #define    MALI_GRALLOC_INTFMT_AFBC_BASIC                 (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START+0))
103 
104 /* This format uses AFBC split block mode */
105 #define    MALI_GRALLOC_INTFMT_AFBC_SPLITBLK        (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START+1))
106 
107 #define    MALI_GRALLOC_INTFMT_UNUSED               (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START+2))
108 
109 /* This format uses AFBC wide block mode */
110 #define    MALI_GRALLOC_INTFMT_AFBC_WIDEBLK         (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START+3))
111 
112 
113 /* Regular Modifier Bits */
114 #define    MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS   (1ULL << (MALI_GRALLOC_INTFMT_EXTENSION_BIT_START+0))
115 
116 
117 /* This mask should be used to check or clear support for AFBC for an internal format
118  * These bits are mutually exclusive so this mask should not be used to enable support
119  */
120 #define    MALI_GRALLOC_INTFMT_AFBCENABLE_MASK                   ((uint64_t) (MALI_GRALLOC_INTFMT_AFBC_BASIC | \
121                                                                    MALI_GRALLOC_INTFMT_AFBC_SPLITBLK | \
122                                                                    MALI_GRALLOC_INTFMT_AFBC_WIDEBLK))
123 
124 /* Prototypes */
125 uint64_t mali_gralloc_select_format(int req_format,int usage, int buffer_size);
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     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     return (modifiers | base_format);
185 }
186 
187 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER(x)                           ( mali_gralloc_format_wrapper(x, 0) )
188 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC(x)                      ( mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_BASIC >> 16)) )
189 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_SPLITBLK(x)             ( mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_SPLITBLK >> 16)) )
190 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_WIDEBLK(x)              ( mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_WIDEBLK >> 16)) )
191 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_TILED_HEADERS_BASIC(x)  ( mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS >> 24) | \
192                                                                                                         (MALI_GRALLOC_INTFMT_AFBC_BASIC >> 16)))
193 #define    GRALLOC_PRIVATE_FORMAT_WRAPPER_AFBC_TILED_HEADERS_WIDE(x)   ( mali_gralloc_format_wrapper(x, (MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS >> 24) | \
194                                                                                                         (MALI_GRALLOC_INTFMT_AFBC_WIDEBLK >> 16)))
195 #define    GRALLOC_PRIVATE_FORMAT_UNWRAP(x)                            mali_gralloc_format_unwrap(x)
196 
197 /* IP block capability masks */
198 #define MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT            ((uint64_t) (1 << 0))
199 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC                 ((uint64_t) (1 << 1))
200 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK              ((uint64_t) (1 << 2))
201 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK               ((uint64_t) (1 << 3))
202 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK_YUV_DISABLE   ((uint64_t) (1 << 4))
203 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_NOREAD            ((uint64_t) (1 << 5))
204 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_NOWRITE           ((uint64_t) (1 << 6))
205 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_TILED_HEADERS         ((uint64_t) (1 << 7))
206 
207 #define MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK ((uint64_t) (MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC | \
208                                                                     MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK | \
209                                                                     MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK | \
210                                                                     MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_TILED_HEADERS))
211 
212 struct mali_gralloc_format_caps
213 {
214 	uint64_t caps_mask;
215 };
216 typedef struct mali_gralloc_format_caps mali_gralloc_format_caps;
217 
218 #define MALI_GRALLOC_FORMATCAPS_SYM_NAME        mali_gralloc_format_capabilities
219 #define MALI_GRALLOC_FORMATCAPS_SYM_NAME_STR    "mali_gralloc_format_capabilities"
220 
221 /* Producer and Consumer definitions */
222 typedef enum
223 {
224 	MALI_GRALLOC_PRODUCER_VIDEO_DECODER,
225 	MALI_GRALLOC_PRODUCER_GPU,
226 	MALI_GRALLOC_PRODUCER_CAMERA,
227 } mali_gralloc_producer_type;
228 
229 typedef enum
230 {
231 
232     /* For surface composition in SurfaceFlinger a producer
233      * will not know what consumer will process a buffer.
234      *
235      * MALI_GRALLOC_CONSUMER_GPU_OR_DISPLAY means the GPU
236      * MUST support the given format but it should be allocated
237      * with preference to the DPU.
238      */
239     MALI_GRALLOC_CONSUMER_GPU_OR_DISPLAY,
240     MALI_GRALLOC_CONSUMER_VIDEO_ENCODER,
241 
242 
243     /* This is used when no known "premium" dpu is configured.
244      * For example, HDLCD/CLCD would be such a dpu.
245      */
246     MALI_GRALLOC_CONSUMER_GPU_EXCL,
247 } mali_gralloc_consumer_type;
248 
249 
250 /*
251  * Below usage types overlap, this is intentional.
252  * The reason is that for Gralloc 0.3 there are very
253  * few usage flags we have at our disposal.
254  *
255  * The overlapping is handled by processing the definitions
256  * in a specific order.
257  *
258  * MALI_GRALLOC_USAGE_PRIVATE_FORMAT and MALI_GRALLOC_USAGE_NO_AFBC
259  * don't overlap and are processed first.
260  *
261  * MALI_GRALLOC_USAGE_YUV_CONF are only for YUV formats and clients
262  * using MALI_GRALLOC_USAGE_NO_AFBC must never allocate YUV formats.
263  * The latter is strictly enforced and allocations will fail.
264  *
265  * MALI_GRALLOC_USAGE_AFBC_PADDING is only valid if MALI_GRALLOC_USAGE_NO_AFBC
266  * is not present.
267  */
268 typedef enum
269 {
270 	/* The client has specified a private format in the format parameter */
271 	MALI_GRALLOC_USAGE_PRIVATE_FORMAT = (int) GRALLOC_USAGE_PRIVATE_3,
272 
273 	/* Buffer won't be allocated as AFBC */
274 	MALI_GRALLOC_USAGE_NO_AFBC = (int) (GRALLOC_USAGE_PRIVATE_1 | GRALLOC_USAGE_PRIVATE_2),
275 
276 	/* Valid only for YUV allocations */
277 	MALI_GRALLOC_USAGE_YUV_CONF_0 = 0,
278 	MALI_GRALLOC_USAGE_YUV_CONF_1 = (int) GRALLOC_USAGE_PRIVATE_1,
279 	MALI_GRALLOC_USAGE_YUV_CONF_2 = (int) GRALLOC_USAGE_PRIVATE_0,
280 	MALI_GRALLOC_USAGE_YUV_CONF_3 = (int) (GRALLOC_USAGE_PRIVATE_0 | GRALLOC_USAGE_PRIVATE_1),
281 	MALI_GRALLOC_USAGE_YUV_CONF_MASK = MALI_GRALLOC_USAGE_YUV_CONF_3,
282 
283 	/* A very specific alignment is requested on some buffers */
284 	MALI_GRALLOC_USAGE_AFBC_PADDING = GRALLOC_USAGE_PRIVATE_2,
285 
286 } mali_gralloc_usage_type;
287 
288 /* Prototypes */
289 uint64_t mali_gralloc_select_format(int req_format,int usage, int buffer_size);
290 
291 #ifdef __cplusplus
292 extern "C"
293 {
294 #endif
295 
296 void mali_gralloc_get_gpu_caps(struct mali_gralloc_format_caps *gpu_caps);
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif /* MALI_GRALLOC_FORMATS_H_ */
303