blob: e3c3b86e49f408e930fd3a537b97113feed57725 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
2 * Copyright (C) 2009 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 ANDROID_ANDROID_NATIVES_H
18#define ANDROID_ANDROID_NATIVES_H
19
20#include <sys/types.h>
21#include <string.h>
22
23#include <hardware/gralloc.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/*****************************************************************************/
30
31#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
32 (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
33
34#define ANDROID_NATIVE_WINDOW_MAGIC \
35 ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
36
37#define ANDROID_NATIVE_BUFFER_MAGIC \
38 ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
39
40// ---------------------------------------------------------------------------
41
42struct android_native_buffer_t;
43
44enum {
45 /* attributes of this surface or its updater */
46 SURFACE_FLAG_PRESERVE_CONTENT = FRAMEBUFFER_RESERVED0,
47 SURFACE_FLAG_MAPPED = FRAMEBUFFER_FLAG_MAPPED,
48};
49
50
51// ---------------------------------------------------------------------------
52
53struct android_native_base_t
54{
55 /* a magic value defined by the actual EGL native type */
56 int magic;
57
58 /* the sizeof() of the actual EGL native type */
59 int version;
60
61 void* reserved[4];
62
63 /* reference-counting interface */
64 void (*incRef)(struct android_native_base_t* base);
65 void (*decRef)(struct android_native_base_t* base);
66};
67
68
69struct android_native_window_t
70{
71#ifdef __cplusplus
72 android_native_window_t()
73 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
74 {
75 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
76 common.version = sizeof(android_native_window_t);
77 memset(common.reserved, 0, sizeof(common.reserved));
78 }
79#endif
80
81 struct android_native_base_t common;
82
83 /* flags describing some attributes of this surface or its updater */
84 const uint32_t flags;
85
86 /* min swap interval supported by this updated */
87 const int minSwapInterval;
88
89 /* max swap interval supported by this updated */
90 const int maxSwapInterval;
91
92 /* horizontal and vertical resolution in DPI */
93 const float xdpi;
94 const float ydpi;
95
96 /* Some storage reserved for the OEM's driver. */
97 intptr_t oem[4];
98
99 /*
100 * hook called by EGL when the native surface is made current
101 * (eglMakeCurrent()). This hook can be NULL.
102 */
103 void (*connect)(struct android_native_window_t* window);
104
105 /*
106 * hook called by EGL when the native surface in not current any-longer.
107 * This hook can be NULL.
108 */
109 void (*disconnect)(struct android_native_window_t* window);
110
111
112 /*
113 * Set the swap interval for this surface.
114 *
115 * Returns 0 on success or -errno on error.
116 */
117 int (*setSwapInterval)(struct android_native_window_t* window,
118 int interval);
119
120
121 /*
122 * FIXME: needs documentation for setSwapRectangle
123 * tentative: rect used during queueBuffer to indicate which part of
124 * the screen needs updating.
125 */
126 int (*setSwapRectangle)(struct android_native_window_t* window,
127 int left, int top, int width, int height);
128
129
130 /*
131 * hook called by EGL to acquire a buffer. After this call, the buffer
132 * is not locked, so its content cannot be modified.
133 * this call may block if no buffers are availlable.
134 *
135 * Returns 0 on success or -errno on error.
136 */
137 int (*dequeueBuffer)(struct android_native_window_t* window,
138 struct android_native_buffer_t** buffer);
139
140 /*
141 * hook called by EGL to lock a buffer. This MUST be called before modifying
142 * the content of a buffer. The buffer must have been acquired with
143 * dequeueBuffer first.
144 *
145 * Returns 0 on success or -errno on error.
146 */
147 int (*lockBuffer)(struct android_native_window_t* window,
148 struct android_native_buffer_t* buffer);
149 /*
150 * hook called by EGL when modifications to the render buffer are done.
151 * This unlocks and post the buffer.
152 *
153 * Buffers MUST be queued in the same order than they were dequeued.
154 *
155 * Returns 0 on success or -errno on error.
156 */
157 int (*queueBuffer)(struct android_native_window_t* window,
158 struct android_native_buffer_t* buffer);
159
160
161 void* reserved_proc[5];
162};
163
164
165struct android_native_buffer_t
166{
167#ifdef __cplusplus
168 android_native_buffer_t() {
169 common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
170 common.version = sizeof(android_native_buffer_t);
171 memset(common.reserved, 0, sizeof(common.reserved));
172 }
173#endif
174
175 struct android_native_base_t common;
176
177 int width;
178 int height;
179 int stride;
180 int format;
181 int usage;
182 void* bits; // non-zero if buffer is mmaped
183
184 void* reserved[2];
185
186 int (*getHandle)(struct android_native_buffer_t const * base,
187 buffer_handle_t* handle);
188
189 void* reserved_proc[7];
190};
191
192
193/* FIXME: this is legacy for pixmaps */
194struct egl_native_pixmap_t
195{
196 int32_t version; /* must be 32 */
197 int32_t width;
198 int32_t height;
199 int32_t stride;
200 uint8_t* data;
201 uint8_t format;
202 uint8_t rfu[3];
203 union {
204 uint32_t compressedFormat;
205 int32_t vstride;
206 };
207 int32_t reserved;
208};
209
210/*****************************************************************************/
211
212#ifdef __cplusplus
213}
214#endif
215
216
217/*****************************************************************************/
218
219#ifdef __cplusplus
220
221#include <utils/RefBase.h>
222
223namespace android {
224
225/*
226 * This helper class turns an EGL android_native_xxx type into a C++
227 * reference-counted object; with proper type conversions.
228 */
229template <typename NATIVE_TYPE, typename TYPE, typename REF>
230class EGLNativeBase : public NATIVE_TYPE, public REF
231{
232protected:
233 typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE;
234 EGLNativeBase() : NATIVE_TYPE(), REF() {
235 NATIVE_TYPE::common.incRef = incRef;
236 NATIVE_TYPE::common.decRef = decRef;
237 }
238 static inline TYPE* getSelf(NATIVE_TYPE* self) {
239 return static_cast<TYPE*>(self);
240 }
241 static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
242 return static_cast<TYPE const *>(self);
243 }
244 static inline TYPE* getSelf(android_native_base_t* base) {
245 return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
246 }
247 static inline TYPE const * getSelf(android_native_base_t const* base) {
248 return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
249 }
250 static void incRef(android_native_base_t* base) {
251 EGLNativeBase* self = getSelf(base);
252 self->incStrong(self);
253 }
254 static void decRef(android_native_base_t* base) {
255 EGLNativeBase* self = getSelf(base);
256 self->decStrong(self);
257 }
258};
259
260} // namespace android
261#endif // __cplusplus
262
263/*****************************************************************************/
264
265#endif /* ANDROID_ANDROID_NATIVES_H */