• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3  * Copyright (C) 2010-2011 LunarG Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _GRALLOC_DRM_HANDLE_H_
25 #define _GRALLOC_DRM_HANDLE_H_
26 
27 #include <cutils/native_handle.h>
28 #include <system/graphics.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct gralloc_drm_bo_t;
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 	struct gralloc_drm_bo_t *data; /* pointer to struct gralloc_drm_bo_t */
54 
55 	// FIXME: the attributes below should be out-of-line
56 	uint64_t unknown __attribute__((aligned(8)));
57 	int data_owner; /* owner of data (for validation) */
58 };
59 #define GRALLOC_DRM_HANDLE_MAGIC 0x12345678
60 #define GRALLOC_DRM_HANDLE_NUM_FDS 1
61 #define GRALLOC_DRM_HANDLE_NUM_INTS (						\
62 	((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int))	\
63 	 - GRALLOC_DRM_HANDLE_NUM_FDS)
64 
gralloc_drm_handle(buffer_handle_t _handle)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_DRM_HANDLE_NUM_INTS ||
72 	               handle->base.numFds != GRALLOC_DRM_HANDLE_NUM_FDS ||
73 	               handle->magic != GRALLOC_DRM_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 #ifdef __cplusplus
84 }
85 #endif
86 #endif /* _GRALLOC_DRM_HANDLE_H_ */
87