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_GBM_HANDLE_H_
26 #define _GRALLOC_GBM_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 */
53 int data_owner; /* owner of data (for validation) */
55 void *data; /* pointer to struct gralloc_gbm_bo_t */
57 } __attribute__((aligned(8)));
59 #define GRALLOC_GBM_HANDLE_MAGIC 0x12345678
60 #define GRALLOC_GBM_HANDLE_NUM_FDS 1
61 #define GRALLOC_GBM_HANDLE_NUM_INTS ( \
62 ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
63 - GRALLOC_GBM_HANDLE_NUM_FDS)
65 static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
67 struct gralloc_drm_handle_t *handle =
68 (struct gralloc_drm_handle_t *) _handle;
70 if (handle && (handle->base.version != sizeof(handle->base) ||
71 handle->base.numInts != GRALLOC_GBM_HANDLE_NUM_INTS ||
72 handle->base.numFds != GRALLOC_GBM_HANDLE_NUM_FDS ||
73 handle->magic != GRALLOC_GBM_HANDLE_MAGIC)) {
74 ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x",
75 handle->base.version, handle->base.numInts,
76 handle->base.numFds, handle->magic);
83 static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle)
85 struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
86 return (handle) ? handle->prime_fd : -1;
92 #endif /* _GRALLOC_GBM_HANDLE_H_ */