blob: 7da69b144a49ebf83cd266e7977e5f5044c451bb [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
Mathias Agopian076b1cc2009-04-10 14:24:30 -070044// ---------------------------------------------------------------------------
45
46struct android_native_base_t
47{
48 /* a magic value defined by the actual EGL native type */
49 int magic;
50
51 /* the sizeof() of the actual EGL native type */
52 int version;
53
54 void* reserved[4];
55
56 /* reference-counting interface */
57 void (*incRef)(struct android_native_base_t* base);
58 void (*decRef)(struct android_native_base_t* base);
59};
60
Mathias Agopianaa8c0ff2009-05-05 18:29:35 -070061// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -070062
Mathias Agopiancb6b9042009-07-30 18:14:56 -070063/* attributes queriable with query() */
64enum {
65 NATIVE_WINDOW_WIDTH = 0,
Mathias Agopian6b1f4102009-08-06 16:04:29 -070066 NATIVE_WINDOW_HEIGHT = 1,
67 NATIVE_WINDOW_FORMAT = 2,
Mathias Agopiancb6b9042009-07-30 18:14:56 -070068};
69
Mathias Agopian076b1cc2009-04-10 14:24:30 -070070struct android_native_window_t
71{
72#ifdef __cplusplus
73 android_native_window_t()
74 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
75 {
76 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
77 common.version = sizeof(android_native_window_t);
78 memset(common.reserved, 0, sizeof(common.reserved));
79 }
80#endif
81
82 struct android_native_base_t common;
83
84 /* flags describing some attributes of this surface or its updater */
85 const uint32_t flags;
86
87 /* min swap interval supported by this updated */
88 const int minSwapInterval;
89
90 /* max swap interval supported by this updated */
91 const int maxSwapInterval;
92
93 /* horizontal and vertical resolution in DPI */
94 const float xdpi;
95 const float ydpi;
96
97 /* Some storage reserved for the OEM's driver. */
98 intptr_t oem[4];
99
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700100
101 /*
102 * Set the swap interval for this surface.
103 *
104 * Returns 0 on success or -errno on error.
105 */
106 int (*setSwapInterval)(struct android_native_window_t* window,
107 int interval);
108
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700109 /*
110 * hook called by EGL to acquire a buffer. After this call, the buffer
111 * is not locked, so its content cannot be modified.
Mathias Agopian0926f502009-05-04 14:17:04 -0700112 * this call may block if no buffers are available.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700113 *
114 * Returns 0 on success or -errno on error.
115 */
116 int (*dequeueBuffer)(struct android_native_window_t* window,
117 struct android_native_buffer_t** buffer);
118
119 /*
120 * hook called by EGL to lock a buffer. This MUST be called before modifying
121 * the content of a buffer. The buffer must have been acquired with
122 * dequeueBuffer first.
123 *
124 * Returns 0 on success or -errno on error.
125 */
126 int (*lockBuffer)(struct android_native_window_t* window,
127 struct android_native_buffer_t* buffer);
128 /*
129 * hook called by EGL when modifications to the render buffer are done.
130 * This unlocks and post the buffer.
131 *
132 * Buffers MUST be queued in the same order than they were dequeued.
133 *
134 * Returns 0 on success or -errno on error.
135 */
136 int (*queueBuffer)(struct android_native_window_t* window,
137 struct android_native_buffer_t* buffer);
138
Mathias Agopiancb6b9042009-07-30 18:14:56 -0700139 /*
140 * hook used to retrieve information about the native window.
141 *
142 * Returns 0 on success or -errno on error.
143 */
144 int (*query)(struct android_native_window_t* window,
Fred Quintanab2fd4662009-08-11 20:49:35 -0700145 int what, int* value);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700146
Fred Quintanab2fd4662009-08-11 20:49:35 -0700147 void* reserved_proc[4];
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700148};
149
Mathias Agopianaa8c0ff2009-05-05 18:29:35 -0700150// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700151
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700152/* FIXME: this is legacy for pixmaps */
153struct egl_native_pixmap_t
154{
155 int32_t version; /* must be 32 */
156 int32_t width;
157 int32_t height;
158 int32_t stride;
159 uint8_t* data;
160 uint8_t format;
161 uint8_t rfu[3];
162 union {
163 uint32_t compressedFormat;
164 int32_t vstride;
165 };
166 int32_t reserved;
167};
168
169/*****************************************************************************/
170
171#ifdef __cplusplus
172}
173#endif
174
175
176/*****************************************************************************/
177
178#ifdef __cplusplus
179
180#include <utils/RefBase.h>
181
182namespace android {
183
184/*
185 * This helper class turns an EGL android_native_xxx type into a C++
186 * reference-counted object; with proper type conversions.
187 */
188template <typename NATIVE_TYPE, typename TYPE, typename REF>
189class EGLNativeBase : public NATIVE_TYPE, public REF
190{
191protected:
192 typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE;
193 EGLNativeBase() : NATIVE_TYPE(), REF() {
194 NATIVE_TYPE::common.incRef = incRef;
195 NATIVE_TYPE::common.decRef = decRef;
196 }
197 static inline TYPE* getSelf(NATIVE_TYPE* self) {
198 return static_cast<TYPE*>(self);
199 }
200 static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
201 return static_cast<TYPE const *>(self);
202 }
203 static inline TYPE* getSelf(android_native_base_t* base) {
204 return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
205 }
206 static inline TYPE const * getSelf(android_native_base_t const* base) {
207 return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
208 }
209 static void incRef(android_native_base_t* base) {
210 EGLNativeBase* self = getSelf(base);
211 self->incStrong(self);
212 }
213 static void decRef(android_native_base_t* base) {
214 EGLNativeBase* self = getSelf(base);
215 self->decStrong(self);
216 }
217};
218
219} // namespace android
220#endif // __cplusplus
221
222/*****************************************************************************/
223
224#endif /* ANDROID_ANDROID_NATIVES_H */