OSDN Git Service

Open the device node with O_CLOEXEC
[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_GBM_HANDLE_H_
26 #define _GRALLOC_GBM_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
53         int data_owner; /* owner of data (for validation) */
54         union {
55                 void *data; /* pointer to struct gralloc_gbm_bo_t */
56                 uint64_t reserved;
57         } __attribute__((aligned(8)));
58 };
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)
64
65 static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
66 {
67         struct gralloc_drm_handle_t *handle =
68                 (struct gralloc_drm_handle_t *) _handle;
69
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);
77                 handle = NULL;
78         }
79
80         return handle;
81 }
82
83 static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle)
84 {
85         struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
86         return (handle) ? handle->prime_fd : -1;
87 }
88
89 #ifdef __cplusplus
90 }
91 #endif
92 #endif /* _GRALLOC_GBM_HANDLE_H_ */