Commit | Line | Data |
---|---|---|
5763fb39 T |
1 | /* |
2 | * Copyright (C) 2013 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 | #include <linux/ion.h> | |
32 | ||
33 | enum { | |
34 | PREFER_COMPRESSION_NO_CHANGE = 0x00, | |
35 | PREFER_COMPRESSION_ENABLE = 0x01, | |
36 | PREFER_COMPRESSION_DISABLE = 0x02, | |
37 | }; | |
38 | ||
39 | /*****************************************************************************/ | |
40 | ||
41 | struct private_module_t; | |
42 | struct private_handle_t; | |
43 | ||
44 | struct private_module_t { | |
45 | gralloc_module_t base; | |
46 | ||
47 | private_handle_t* framebuffer; | |
48 | uint32_t flags; | |
49 | uint32_t numBuffers; | |
50 | uint32_t bufferMask; | |
51 | pthread_mutex_t lock; | |
52 | buffer_handle_t currentBuffer; | |
53 | int ionfd; | |
54 | ||
55 | struct fb_var_screeninfo info; | |
56 | struct fb_fix_screeninfo finfo; | |
57 | int xres; | |
58 | int yres; | |
59 | int line_length; | |
60 | float xdpi; | |
61 | float ydpi; | |
62 | float fps; | |
63 | void *queue; | |
64 | pthread_mutex_t queue_lock; | |
65 | ||
66 | }; | |
67 | ||
68 | /*****************************************************************************/ | |
69 | ||
70 | #ifdef __cplusplus | |
71 | struct private_handle_t : public native_handle { | |
72 | #else | |
73 | struct private_handle_t { | |
74 | struct native_handle nativeHandle; | |
75 | #endif | |
76 | ||
77 | enum { | |
78 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, | |
79 | PRIV_FLAGS_USES_UMP = 0x00000002, | |
80 | PRIV_FLAGS_USES_ION = 0x00000020 | |
81 | }; | |
82 | ||
83 | // file-descriptors | |
84 | int fd; | |
85 | int fd1; | |
86 | int fd2; | |
87 | // ints | |
88 | int magic; | |
89 | int flags; | |
90 | int size; | |
91 | int offset; | |
92 | ||
93 | int format; | |
94 | int width; | |
95 | int height; | |
96 | int stride; | |
97 | int vstride; | |
98 | int frameworkFormat; | |
99 | ||
100 | ion_user_handle_t handle; | |
101 | ion_user_handle_t handle1; | |
102 | ion_user_handle_t handle2; | |
103 | ||
104 | // FIXME: the attributes below should be out-of-line | |
105 | uint64_t base __attribute__((aligned(8))); | |
106 | uint64_t base1 __attribute__((aligned(8))); | |
107 | uint64_t base2 __attribute__((aligned(8))); | |
108 | ||
109 | #ifdef __cplusplus | |
110 | static inline int sNumInts() { | |
111 | return (((sizeof(private_handle_t) - sizeof(native_handle_t))/sizeof(int)) - sNumFds); | |
112 | } | |
113 | static const int sNumFds = 3; | |
114 | static const int sMagic = 0x3141592; | |
115 | ||
116 | private_handle_t(int fd, int size, int flags) : | |
117 | fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size), | |
1733faf4 JA |
118 | offset(0), format(0), width(0), height(0), stride(0), vstride(0), frameworkFormat(0), |
119 | handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0), | |
120 | dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE), | |
121 | internal_format(0), is_compressible(0), compressed_out(0) | |
122 | ||
5763fb39 T |
123 | { |
124 | version = sizeof(native_handle); | |
125 | numInts = sNumInts() + 2; | |
126 | numFds = sNumFds -2 ; | |
127 | } | |
128 | ||
129 | private_handle_t(int fd, int size, int flags, int w, | |
130 | int h, int format, uint64_t internal_format, int frameworkFormat, int stride, int vstride, int is_compressible) : | |
131 | fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size), | |
1733faf4 JA |
132 | offset(0), format(format), width(w), height(h), stride(stride), vstride(vstride), frameworkFormat(frameworkFormat), |
133 | handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0), | |
134 | dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE), | |
135 | internal_format(internal_format), is_compressible(is_compressible), compressed_out(0) | |
136 | ||
5763fb39 T |
137 | { |
138 | version = sizeof(native_handle); | |
139 | numInts = sNumInts() + 2; | |
140 | numFds = sNumFds - 2; | |
141 | } | |
142 | ||
143 | private_handle_t(int fd, int fd1, int size, int flags, int w, | |
144 | int h, int format, uint64_t internal_format, int frameworkFormat, int stride, int vstride, int is_compressible) : | |
145 | fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size), | |
1733faf4 JA |
146 | offset(0), format(format), width(w), height(h), stride(stride), vstride(vstride), frameworkFormat(frameworkFormat), |
147 | handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0), | |
148 | dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE), | |
149 | internal_format(internal_format), is_compressible(is_compressible), compressed_out(0) | |
150 | ||
5763fb39 T |
151 | { |
152 | version = sizeof(native_handle); | |
153 | numInts = sNumInts() + 1; | |
154 | numFds = sNumFds - 1; | |
155 | } | |
156 | ||
157 | private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w, | |
158 | int h, int format, uint64_t internal_format, int frameworkFormat, int stride, int vstride, int is_compressible) : | |
159 | fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size), | |
1733faf4 JA |
160 | offset(0), format(format), width(w), height(h), stride(stride), vstride(vstride), frameworkFormat(frameworkFormat), |
161 | handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0), | |
162 | dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE), | |
163 | internal_format(internal_format), is_compressible(is_compressible), compressed_out(0) | |
164 | ||
5763fb39 T |
165 | { |
166 | version = sizeof(native_handle); | |
167 | numInts = sNumInts(); | |
168 | numFds = sNumFds; | |
169 | } | |
170 | ~private_handle_t() { | |
171 | magic = 0; | |
172 | } | |
173 | ||
174 | static int validate(const native_handle* h) { | |
175 | const private_handle_t* hnd = (const private_handle_t*)h; | |
176 | if (!h || h->version != sizeof(native_handle) || | |
177 | hnd->numInts + hnd->numFds != sNumInts() + sNumFds || | |
178 | hnd->magic != sMagic) | |
179 | { | |
180 | ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h))); | |
181 | return -EINVAL; | |
182 | } | |
183 | return 0; | |
184 | } | |
185 | ||
186 | static private_handle_t* dynamicCast(const native_handle* in) | |
187 | { | |
188 | if (validate(in) == 0) | |
189 | return (private_handle_t*) in; | |
190 | ||
191 | return NULL; | |
192 | } | |
193 | ||
194 | int lock_usage; | |
195 | int lock_offset; | |
196 | int lock_len; | |
197 | ||
198 | int dssRatio; | |
199 | int cropLeft; | |
200 | int cropTop; | |
201 | int cropRight; | |
202 | int cropBottom; | |
203 | ||
204 | int prefer_compression; | |
205 | uint64_t internal_format; | |
206 | int is_compressible; | |
207 | int compressed_out; | |
208 | ||
209 | #endif | |
210 | }; | |
211 | ||
212 | #define DSS_CROP_X 0 | |
213 | #define DSS_CROP_Y 360 | |
214 | #define DSS_CROP_W 1920 | |
215 | #define DSS_CROP_H 1080 | |
216 | ||
217 | enum { | |
218 | PRIVATE_DATA_DSS_STATUS = 0x00000001, | |
219 | PRIVATE_DATA_DSS_CROP = 0x00000002 | |
220 | }; | |
221 | ||
222 | #define CRC_LIMIT_WIDTH (720) | |
223 | #define CRC_LIMIT_HEIGHT (1280) | |
224 | #define CRC_TILE_SIZE (16) | |
225 | #define CRC_BUFFER_KEY (0x12131415) | |
226 | struct gralloc_crc_header { | |
227 | int crcBufferKey; | |
228 | int crcPartial; | |
229 | int reserved[2]; | |
230 | }; | |
231 | ||
232 | #endif /* GRALLOC_PRIV_H_ */ |