xref: /aosp_15_r20/external/mesa3d/src/util/u_gralloc/u_gralloc_libdrm.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (C) 2010-2011 Chia-I Wu <[email protected]>
3  * Copyright (C) 2010-2011 LunarG Inc.
4  * Copyright (C) 2016 Linaro, Ltd., Rob Herring <[email protected]>
5  * Copyright (C) 2018 Collabora, Robert Foss <[email protected]>
6  *
7  * SPDX-License-Identifier: MIT
8  *
9  * Copied from:
10  * https://gitlab.freedesktop.org/mesa/drm/-/blob/6abc164052e4902f67213baa279d743cf46227d4/android/gralloc_handle.h
11  */
12 
13 #ifndef __ANDROID_GRALLOC_HANDLE_H__
14 #define __ANDROID_GRALLOC_HANDLE_H__
15 
16 #include <cutils/native_handle.h>
17 #include <stdint.h>
18 
19 struct gralloc_handle_t {
20 	native_handle_t base;
21 
22 	/* dma-buf file descriptor
23 	 * Must be located first since, native_handle_t is allocated
24 	 * using native_handle_create(), which allocates space for
25 	 * sizeof(native_handle_t) + sizeof(int) * (numFds + numInts)
26 	 * numFds = GRALLOC_HANDLE_NUM_FDS
27 	 * numInts = GRALLOC_HANDLE_NUM_INTS
28 	 * Where numFds represents the number of FDs and
29 	 * numInts represents the space needed for the
30 	 * remainder of this struct.
31 	 * And the FDs are expected to be found first following
32 	 * native_handle_t.
33 	 */
34 	int prime_fd;
35 
36 	/* api variables */
37 	uint32_t magic; /* differentiate between allocator impls */
38 	uint32_t version; /* api version */
39 
40 	uint32_t width; /* width of buffer in pixels */
41 	uint32_t height; /* height of buffer in pixels */
42 	uint32_t format; /* pixel format (Android) */
43 	uint32_t usage; /* android libhardware usage flags */
44 
45 	uint32_t stride; /* the stride in bytes */
46 	int data_owner; /* owner of data (for validation) */
47 	uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */
48 
49 	union {
50 		void *data; /* pointer to struct gralloc_gbm_bo_t */
51 		uint64_t reserved;
52 	} __attribute__((aligned(8)));
53 };
54 
55 #define GRALLOC_HANDLE_VERSION 4
56 #define GRALLOC_HANDLE_MAGIC 0x60585350
57 #define GRALLOC_HANDLE_NUM_FDS 1
58 #define GRALLOC_HANDLE_NUM_INTS (	\
59 	((sizeof(struct gralloc_handle_t) - sizeof(native_handle_t))/sizeof(int))	\
60 	 - GRALLOC_HANDLE_NUM_FDS)
61 
62 #endif /* __ANDROID_GRALLOC_HANDLE_H__ */
63