OSDN Git Service

Add support for modifiers
[android-x86/external-gbm_gralloc.git] / gralloc_drm_handle.h
1 /*
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  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24
25 #ifndef _GRALLOC_DRM_HANDLE_H_
26 #define _GRALLOC_DRM_HANDLE_H_
27
28 #include <cutils/log.h>
29 #include <cutils/native_handle.h>
30 #include <system/graphics.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct gralloc_drm_handle_t {
37         native_handle_t base;
38
39         /* file descriptors */
40         int prime_fd;
41
42         /* integers */
43         int magic;
44
45         int width;
46         int height;
47         int format;
48         int usage;
49
50         int name;   /* the name of the bo */
51         int stride; /* the stride in bytes */
52         uint64_t modifier; /* buffer modifiers */
53
54         int data_owner; /* owner of data (for validation) */
55         union {
56                 void *data; /* pointer to struct gralloc_gbm_bo_t */
57                 uint64_t reserved;
58         } __attribute__((aligned(8)));
59 };
60 #define GRALLOC_GBM_HANDLE_MAGIC 0x5f47424d
61 #define GRALLOC_GBM_HANDLE_NUM_FDS 1
62 #define GRALLOC_GBM_HANDLE_NUM_INTS (                                           \
63         ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int))   \
64          - GRALLOC_GBM_HANDLE_NUM_FDS)
65
66 static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
67 {
68         struct gralloc_drm_handle_t *handle =
69                 (struct gralloc_drm_handle_t *) _handle;
70
71         if (handle && (handle->base.version != sizeof(handle->base) ||
72                        handle->base.numInts != GRALLOC_GBM_HANDLE_NUM_INTS ||
73                        handle->base.numFds != GRALLOC_GBM_HANDLE_NUM_FDS ||
74                        handle->magic != GRALLOC_GBM_HANDLE_MAGIC)) {
75                 ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x",
76                         handle->base.version, handle->base.numInts,
77                         handle->base.numFds, handle->magic);
78                 handle = NULL;
79         }
80
81         return handle;
82 }
83
84 static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle)
85 {
86         struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
87         return (handle) ? handle->prime_fd : -1;
88 }
89
90 static inline int gralloc_drm_get_gem_handle(buffer_handle_t handle)
91 {
92         return 0; /* Not supported, return invalid handle. */
93 }
94
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif /* _GRALLOC_DRM_HANDLE_H_ */