am 84a0fc9c: am e83cfe69: Merge commit \'504c5d9c6e05cecabcb2404a2fd1a05259602858...
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos5.git] / include / gralloc_priv.h
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef GRALLOC_PRIV_H_
18 #define GRALLOC_PRIV_H_
19
20 #include <stdint.h>
21 #include <limits.h>
22 #include <sys/cdefs.h>
23 #include <hardware/gralloc.h>
24 #include <pthread.h>
25 #include <errno.h>
26 #include <unistd.h>
27
28 #include <cutils/native_handle.h>
29
30 #include <linux/fb.h>
31
32 /*****************************************************************************/
33
34 struct private_module_t;
35 struct private_handle_t;
36 typedef int ion_user_handle_t;
37
38 struct private_module_t {
39 gralloc_module_t base;
40
41 struct private_handle_t* framebuffer;
42 uint32_t flags;
43 uint32_t numBuffers;
44 uint32_t bufferMask;
45 pthread_mutex_t lock;
46 buffer_handle_t currentBuffer;
47 int ionfd;
48
49 int xres;
50 int yres;
51 int line_length;
52 float xdpi;
53 float ydpi;
54 float fps;
55 void *queue;
56 pthread_mutex_t queue_lock;
57
58 };
59
60 /*****************************************************************************/
61
62 #ifdef __cplusplus
63 struct private_handle_t : public native_handle {
64 #else
65 struct private_handle_t {
66 struct native_handle nativeHandle;
67 #endif
68
69 // set if using video encoding colorspace
70 #define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0)
71
72 enum {
73 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
74 PRIV_FLAGS_USES_UMP = 0x00000002,
75 PRIV_FLAGS_USES_ION = 0x00000020
76 };
77
78 // file-descriptors
79 int fd;
80 int fd1;
81 int fd2;
82 // ints
83 int magic;
84 int flags;
85 int size;
86 int offset;
87
88 int format;
89 int width;
90 int height;
91 int stride;
92 int vstride;
93 int gamut;
94 int chroma;
95
96 // FIXME: the attributes below should be out-of-line
97 void *base;
98 void *base1;
99 void *base2;
100 ion_user_handle_t handle;
101 ion_user_handle_t handle1;
102 ion_user_handle_t handle2;
103
104 #ifdef __cplusplus
105 static const int sNumFds = 3;
106 static const int sNumInts = 17;
107 static const int sMagic = 0x3141592;
108
109
110 private_handle_t(int fd, int size, int flags, int w,
111 int h, int format, int stride, int vstride) :
112 fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
113 offset(0), format(format), width(w), height(h), stride(stride),
114 vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0),
115 handle2(0)
116 {
117 version = sizeof(native_handle);
118 numInts = sNumInts + 2;
119 numFds = sNumFds - 2;
120 }
121
122 private_handle_t(int fd, int fd1, int size, int flags, int w,
123 int h, int format, int stride, int vstride) :
124 fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
125 offset(0), format(format), width(w), height(h), stride(stride),
126 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
127 handle(0), handle1(0), handle2(0)
128 {
129 version = sizeof(native_handle);
130 numInts = sNumInts + 1;
131 numFds = sNumFds - 1;
132 }
133
134 private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
135 int h, int format, int stride, int vstride) :
136 fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
137 offset(0), format(format), width(w), height(h), stride(stride),
138 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
139 handle(0), handle1(0), handle2(0)
140 {
141 version = sizeof(native_handle);
142 numInts = sNumInts;
143 numFds = sNumFds;
144 }
145 ~private_handle_t() {
146 magic = 0;
147 }
148
149 static int validate(const native_handle* h) {
150 const private_handle_t* hnd = (const private_handle_t*)h;
151 if (!h || h->version != sizeof(native_handle) ||
152 hnd->numInts + hnd->numFds != sNumInts + sNumFds ||
153 hnd->magic != sMagic)
154 {
155 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
156 return -EINVAL;
157 }
158 return 0;
159 }
160
161 static private_handle_t* dynamicCast(const native_handle* in)
162 {
163 if (validate(in) == 0)
164 return (private_handle_t*) in;
165
166 return NULL;
167 }
168
169 #endif
170 };
171
172 #endif /* GRALLOC_PRIV_H_ */