Commit | Line | Data |
---|---|---|
6198e543 | 1 | /* |
6198e543 DZ |
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> | |
a8b0b07d RSZ |
21 | #include <limits.h> |
22 | #include <sys/cdefs.h> | |
23 | #include <hardware/gralloc.h> | |
6198e543 DZ |
24 | #include <pthread.h> |
25 | #include <errno.h> | |
a8b0b07d | 26 | #include <unistd.h> |
6198e543 | 27 | |
6198e543 DZ |
28 | #include <cutils/native_handle.h> |
29 | ||
a8b0b07d | 30 | #include <linux/fb.h> |
6198e543 | 31 | |
a8b0b07d | 32 | /*****************************************************************************/ |
6198e543 | 33 | |
a8b0b07d | 34 | struct private_module_t; |
6198e543 | 35 | struct private_handle_t; |
98aa5b4b | 36 | typedef int ion_user_handle_t; |
6198e543 | 37 | |
a8b0b07d | 38 | struct private_module_t { |
6198e543 DZ |
39 | gralloc_module_t base; |
40 | ||
8c372e39 | 41 | struct private_handle_t* framebuffer; |
a8b0b07d RSZ |
42 | uint32_t flags; |
43 | uint32_t numBuffers; | |
44 | uint32_t bufferMask; | |
6198e543 | 45 | pthread_mutex_t lock; |
4d9f47b6 | 46 | unsigned int refcount; |
a8b0b07d RSZ |
47 | buffer_handle_t currentBuffer; |
48 | int ionfd; | |
6198e543 | 49 | |
d37bc2b2 GH |
50 | int xres; |
51 | int yres; | |
52 | int line_length; | |
6198e543 DZ |
53 | float xdpi; |
54 | float ydpi; | |
55 | float fps; | |
dd557381 GH |
56 | void *queue; |
57 | pthread_mutex_t queue_lock; | |
6198e543 | 58 | |
6198e543 DZ |
59 | }; |
60 | ||
a8b0b07d RSZ |
61 | /*****************************************************************************/ |
62 | ||
6198e543 | 63 | #ifdef __cplusplus |
a8b0b07d | 64 | struct private_handle_t : public native_handle { |
6198e543 | 65 | #else |
a8b0b07d | 66 | struct private_handle_t { |
6198e543 DZ |
67 | struct native_handle nativeHandle; |
68 | #endif | |
69 | ||
06f1fa77 AR |
70 | // set if using video encoding colorspace |
71 | #define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0) | |
72 | ||
6198e543 DZ |
73 | enum { |
74 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, | |
75 | PRIV_FLAGS_USES_UMP = 0x00000002, | |
80b3e6c2 | 76 | PRIV_FLAGS_USES_ION = 0x00000020 |
6198e543 DZ |
77 | }; |
78 | ||
a8b0b07d | 79 | // file-descriptors |
6198e543 | 80 | int fd; |
a8b0b07d RSZ |
81 | int fd1; |
82 | int fd2; | |
83 | // ints | |
6198e543 DZ |
84 | int magic; |
85 | int flags; | |
86 | int size; | |
6198e543 | 87 | int offset; |
6198e543 DZ |
88 | |
89 | int format; | |
6198e543 DZ |
90 | int width; |
91 | int height; | |
6198e543 | 92 | int stride; |
70212e56 | 93 | int vstride; |
b528b809 | 94 | int gamut; |
d09ee48e | 95 | int chroma; |
6198e543 | 96 | |
a8b0b07d RSZ |
97 | // FIXME: the attributes below should be out-of-line |
98 | void *base; | |
ec68ab21 RSZ |
99 | void *base1; |
100 | void *base2; | |
98aa5b4b RL |
101 | ion_user_handle_t handle; |
102 | ion_user_handle_t handle1; | |
103 | ion_user_handle_t handle2; | |
6198e543 DZ |
104 | |
105 | #ifdef __cplusplus | |
471812b7 | 106 | static const int sNumFds = 3; |
d09ee48e | 107 | static const int sNumInts = 17; |
6198e543 | 108 | static const int sMagic = 0x3141592; |
06062cd9 | 109 | |
a8b0b07d RSZ |
110 | |
111 | private_handle_t(int fd, int size, int flags, int w, | |
70212e56 | 112 | int h, int format, int stride, int vstride) : |
ec68ab21 | 113 | fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size), |
70212e56 | 114 | offset(0), format(format), width(w), height(h), stride(stride), |
d09ee48e AR |
115 | vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0), |
116 | handle2(0) | |
6198e543 DZ |
117 | { |
118 | version = sizeof(native_handle); | |
ec68ab21 RSZ |
119 | numInts = sNumInts + 2; |
120 | numFds = sNumFds - 2; | |
121 | } | |
122 | ||
123 | private_handle_t(int fd, int fd1, int size, int flags, int w, | |
124 | int h, int format, int stride, int vstride) : | |
125 | fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size), | |
126 | offset(0), format(format), width(w), height(h), stride(stride), | |
d09ee48e AR |
127 | vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0), |
128 | handle(0), handle1(0), handle2(0) | |
ec68ab21 RSZ |
129 | { |
130 | version = sizeof(native_handle); | |
131 | numInts = sNumInts + 1; | |
132 | numFds = sNumFds - 1; | |
6198e543 DZ |
133 | } |
134 | ||
a8b0b07d | 135 | private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w, |
70212e56 | 136 | int h, int format, int stride, int vstride) : |
a8b0b07d | 137 | fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size), |
70212e56 | 138 | offset(0), format(format), width(w), height(h), stride(stride), |
d09ee48e AR |
139 | vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0), |
140 | handle(0), handle1(0), handle2(0) | |
6198e543 DZ |
141 | { |
142 | version = sizeof(native_handle); | |
6198e543 | 143 | numInts = sNumInts; |
a8b0b07d | 144 | numFds = sNumFds; |
6198e543 | 145 | } |
a8b0b07d | 146 | ~private_handle_t() { |
6198e543 DZ |
147 | magic = 0; |
148 | } | |
149 | ||
a8b0b07d | 150 | static int validate(const native_handle* h) { |
6198e543 | 151 | const private_handle_t* hnd = (const private_handle_t*)h; |
6198e543 | 152 | if (!h || h->version != sizeof(native_handle) || |
ec68ab21 RSZ |
153 | hnd->numInts + hnd->numFds != sNumInts + sNumFds || |
154 | hnd->magic != sMagic) | |
a8b0b07d RSZ |
155 | { |
156 | ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h))); | |
6198e543 | 157 | return -EINVAL; |
a8b0b07d | 158 | } |
6198e543 DZ |
159 | return 0; |
160 | } | |
161 | ||
162 | static private_handle_t* dynamicCast(const native_handle* in) | |
163 | { | |
164 | if (validate(in) == 0) | |
165 | return (private_handle_t*) in; | |
166 | ||
167 | return NULL; | |
168 | } | |
a8b0b07d | 169 | |
6198e543 DZ |
170 | #endif |
171 | }; | |
172 | ||
173 | #endif /* GRALLOC_PRIV_H_ */ |