2 * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3 * Copyright (C) 2010-2011 LunarG Inc.
4 * Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org>
5 * Copyright (C) 2018 Collabora, Robert Foss <robert.foss@collabora.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 #ifndef __ANDROID_GRALLOC_HANDLE_H__
27 #define __ANDROID_GRALLOC_HANDLE_H__
29 #include <cutils/native_handle.h>
32 /* support users of drm_gralloc/gbm_gralloc */
33 #define gralloc_gbm_handle_t gralloc_handle_t
34 #define gralloc_drm_handle_t gralloc_handle_t
36 struct gralloc_handle_t
{
39 /* dma-buf file descriptor
40 * Must be located first since, native_handle_t is allocated
41 * using native_handle_create(), which allocates space for
42 * sizeof(native_handle_t) + sizeof(int) * (numFds + numInts)
43 * numFds = GRALLOC_HANDLE_NUM_FDS
44 * numInts = GRALLOC_HANDLE_NUM_INTS
45 * Where numFds represents the number of FDs and
46 * numInts represents the space needed for the
47 * remainder of this struct.
48 * And the FDs are expected to be found first following
54 uint32_t magic
; /* differentiate between allocator impls */
55 uint32_t version
; /* api version */
57 uint32_t width
; /* width of buffer in pixels */
58 uint32_t height
; /* height of buffer in pixels */
59 uint32_t format
; /* pixel format (Android) */
60 uint32_t usage
; /* android libhardware usage flags */
62 uint32_t stride
; /* the stride in bytes */
63 int data_owner
; /* owner of data (for validation) */
64 uint64_t modifier
__attribute__((aligned(8))); /* buffer modifiers */
67 void *data
; /* pointer to struct gralloc_gbm_bo_t */
69 } __attribute__((aligned(8)));
72 #define GRALLOC_HANDLE_VERSION 4
73 #define GRALLOC_HANDLE_MAGIC 0x60585350
74 #define GRALLOC_HANDLE_NUM_FDS 1
75 #define GRALLOC_HANDLE_NUM_INTS ( \
76 ((sizeof(struct gralloc_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
77 - GRALLOC_HANDLE_NUM_FDS)
79 static inline struct gralloc_handle_t
*gralloc_handle(buffer_handle_t handle
)
81 return (struct gralloc_handle_t
*)handle
;
85 * Create a buffer handle.
87 static inline native_handle_t
*gralloc_handle_create(int32_t width
,
92 struct gralloc_handle_t
*handle
;
93 native_handle_t
*nhandle
= native_handle_create(GRALLOC_HANDLE_NUM_FDS
,
94 GRALLOC_HANDLE_NUM_INTS
);
99 handle
= gralloc_handle(nhandle
);
100 handle
->magic
= GRALLOC_HANDLE_MAGIC
;
101 handle
->version
= GRALLOC_HANDLE_VERSION
;
102 handle
->width
= width
;
103 handle
->height
= height
;
104 handle
->format
= hal_format
;
105 handle
->usage
= usage
;
106 handle
->prime_fd
= -1;