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>
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 #ifndef _GRALLOC_DRM_HANDLE_H_
26 #define _GRALLOC_DRM_HANDLE_H_
28 #include <cutils/log.h>
29 #include <cutils/native_handle.h>
30 #include <system/graphics.h>
36 struct gralloc_drm_handle_t {
39 /* file descriptors */
50 int name; /* the name of the bo */
51 int stride; /* the stride in bytes */
52 uint64_t modifier; /* buffer modifiers */
54 int data_owner; /* owner of data (for validation) */
56 void *data; /* pointer to struct gralloc_gbm_bo_t */
58 } __attribute__((aligned(8)));
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)
66 static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
68 struct gralloc_drm_handle_t *handle =
69 (struct gralloc_drm_handle_t *) _handle;
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);
84 static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle)
86 struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
87 return (handle) ? handle->prime_fd : -1;
90 static inline int gralloc_drm_get_gem_handle(buffer_handle_t handle)
92 return 0; /* Not supported, return invalid handle. */
98 #endif /* _GRALLOC_DRM_HANDLE_H_ */