blob: 928dc2ab60044a50d781cf26c294359605f813c1 [file] [log] [blame]
John Stultz16100f62017-05-03 11:12:18 -07001/*
John Stultz18814f62018-02-22 16:02:49 -08002 * Copyright (C) 2016-2017 ARM Limited. All rights reserved.
John Stultz16100f62017-05-03 11:12:18 -07003 *
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 */
30typedef uint64_t mali_gralloc_internal_format;
31
32/* Internal format masks */
John Stultz18814f62018-02-22 16:02:49 -080033#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
John Stultz16100f62017-05-03 11:12:18 -070037
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
45typedef enum
46{
John Stultz18814f62018-02-22 16:02:49 -080047 MALI_GRALLOC_FORMAT_TYPE_USAGE,
48 MALI_GRALLOC_FORMAT_TYPE_INTERNAL,
49} mali_gralloc_format_type;
John Stultz16100f62017-05-03 11:12:18 -070050
John Stultz18814f62018-02-22 16:02:49 -080051typedef 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,
John Stultz16100f62017-05-03 11:12:18 -070063
John Stultz18814f62018-02-22 16:02:49 -080064 /* 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
John Stultz16100f62017-05-03 11:12:18 -070071 * internal format itself but one of the ones below
72 */
73
John Stultz18814f62018-02-22 16:02:49 -080074 /* The internal private formats that have no HAL equivivalent are defined
John Stultz16100f62017-05-03 11:12:18 -070075 * afterwards starting at a specific base range */
John Stultz18814f62018-02-22 16:02:49 -080076 MALI_GRALLOC_FORMAT_INTERNAL_NV12 = MALI_GRALLOC_FORMAT_INTERNAL_RANGE_BASE,
77 MALI_GRALLOC_FORMAT_INTERNAL_NV21,
78 MALI_GRALLOC_FORMAT_INTERNAL_YUV422_8BIT,
John Stultz16100f62017-05-03 11:12:18 -070079
John Stultz18814f62018-02-22 16:02:49 -080080 /* Extended YUV formats
John Stultz16100f62017-05-03 11:12:18 -070081 *
82 * NOTE: P010, P210, and Y410 are only supported uncompressed.
83 */
John Stultz18814f62018-02-22 16:02:49 -080084 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,
John Stultz16100f62017-05-03 11:12:18 -070089
John Stultz18814f62018-02-22 16:02:49 -080090 /* Add more internal formats here. Make sure decode_internal_format() is updated. */
John Stultz16100f62017-05-03 11:12:18 -070091
John Stultz18814f62018-02-22 16:02:49 -080092 /* 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,
John Stultz16100f62017-05-03 11:12:18 -070096
97 MALI_GRALLOC_FORMAT_INTERNAL_RANGE_LAST,
98} mali_gralloc_pixel_format;
99
John Stultz16100f62017-05-03 11:12:18 -0700100/* Format Modifier Bits Locations */
John Stultz18814f62018-02-22 16:02:49 -0800101#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)
John Stultz16100f62017-05-03 11:12:18 -0700103
104/* Mutually Exclusive Modifier Bits */
105
106/* This format will use AFBC */
John Stultz18814f62018-02-22 16:02:49 -0800107#define MALI_GRALLOC_INTFMT_AFBC_BASIC (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 0))
John Stultz16100f62017-05-03 11:12:18 -0700108
109/* This format uses AFBC split block mode */
John Stultz18814f62018-02-22 16:02:49 -0800110#define MALI_GRALLOC_INTFMT_AFBC_SPLITBLK (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 1))
John Stultz16100f62017-05-03 11:12:18 -0700111
John Stultz18814f62018-02-22 16:02:49 -0800112#define MALI_GRALLOC_INTFMT_UNUSED (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 2))
John Stultz16100f62017-05-03 11:12:18 -0700113
114/* This format uses AFBC wide block mode */
John Stultz18814f62018-02-22 16:02:49 -0800115#define MALI_GRALLOC_INTFMT_AFBC_WIDEBLK (1ULL << (MALI_GRALLOC_INTFMT_ME_EXTENSION_BIT_START + 3))
John Stultz16100f62017-05-03 11:12:18 -0700116
117/* Regular Modifier Bits */
John Stultz18814f62018-02-22 16:02:49 -0800118#define MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS (1ULL << (MALI_GRALLOC_INTFMT_EXTENSION_BIT_START + 0))
John Stultz16100f62017-05-03 11:12:18 -0700119
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 */
John Stultz18814f62018-02-22 16:02:49 -0800123#define MALI_GRALLOC_INTFMT_AFBCENABLE_MASK \
124 ((uint64_t)(MALI_GRALLOC_INTFMT_AFBC_BASIC | MALI_GRALLOC_INTFMT_AFBC_SPLITBLK | MALI_GRALLOC_INTFMT_AFBC_WIDEBLK))
John Stultz16100f62017-05-03 11:12:18 -0700125
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 */
136static inline int mali_gralloc_format_wrapper(int format, int modifiers)
137{
John Stultz18814f62018-02-22 16:02:49 -0800138 /* 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);
John Stultz16100f62017-05-03 11:12:18 -0700161}
162
163static inline uint64_t mali_gralloc_format_unwrap(int x)
164{
John Stultz18814f62018-02-22 16:02:49 -0800165 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
John Stultz16100f62017-05-03 11:12:18 -0700168
John Stultz18814f62018-02-22 16:02:49 -0800169 uint64_t base_format = internal_format & MALI_GRALLOC_INTFMT_FMT_MASK;
170 uint64_t modifiers = internal_format & MALI_GRALLOC_INTFMT_EXT_MASK;
John Stultz16100f62017-05-03 11:12:18 -0700171
John Stultz18814f62018-02-22 16:02:49 -0800172 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);
John Stultz16100f62017-05-03 11:12:18 -0700186}
187
John Stultz18814f62018-02-22 16:02:49 -0800188#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)
John Stultz16100f62017-05-03 11:12:18 -0700201
202/* IP block capability masks */
John Stultz18814f62018-02-22 16:02:49 -0800203#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))
John Stultz16100f62017-05-03 11:12:18 -0700211
John Stultz18814f62018-02-22 16:02:49 -0800212#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))
John Stultz16100f62017-05-03 11:12:18 -0700215
216struct mali_gralloc_format_caps
217{
218 uint64_t caps_mask;
219};
220typedef struct mali_gralloc_format_caps mali_gralloc_format_caps;
221
John Stultz18814f62018-02-22 16:02:49 -0800222#define MALI_GRALLOC_FORMATCAPS_SYM_NAME mali_gralloc_format_capabilities
223#define MALI_GRALLOC_FORMATCAPS_SYM_NAME_STR "mali_gralloc_format_capabilities"
John Stultz16100f62017-05-03 11:12:18 -0700224
225/* Producer and Consumer definitions */
226typedef enum
227{
228 MALI_GRALLOC_PRODUCER_VIDEO_DECODER,
229 MALI_GRALLOC_PRODUCER_GPU,
230 MALI_GRALLOC_PRODUCER_CAMERA,
231} mali_gralloc_producer_type;
232
233typedef enum
234{
235
John Stultz18814f62018-02-22 16:02:49 -0800236 /* For surface composition in SurfaceFlinger a producer
John Stultz16100f62017-05-03 11:12:18 -0700237 * 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 */
John Stultz18814f62018-02-22 16:02:49 -0800243 MALI_GRALLOC_CONSUMER_GPU_OR_DISPLAY,
244 MALI_GRALLOC_CONSUMER_VIDEO_ENCODER,
John Stultz16100f62017-05-03 11:12:18 -0700245
John Stultz18814f62018-02-22 16:02:49 -0800246 /* This is used when no known "premium" dpu is configured.
John Stultz16100f62017-05-03 11:12:18 -0700247 * For example, HDLCD/CLCD would be such a dpu.
248 */
John Stultz18814f62018-02-22 16:02:49 -0800249 MALI_GRALLOC_CONSUMER_GPU_EXCL,
John Stultz16100f62017-05-03 11:12:18 -0700250} mali_gralloc_consumer_type;
251
John Stultz18814f62018-02-22 16:02:49 -0800252/* Internal prototypes */
253#if defined(GRALLOC_LIBRARY_BUILD)
254uint64_t mali_gralloc_select_format(uint64_t req_format, mali_gralloc_format_type type, uint64_t usage,
255 int buffer_size);
256#endif
John Stultz16100f62017-05-03 11:12:18 -0700257
258#ifdef __cplusplus
John Stultz18814f62018-02-22 16:02:49 -0800259extern "C" {
John Stultz16100f62017-05-03 11:12:18 -0700260#endif
261
262void 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_ */