blob: 0398ea7eb7c17c9de81abc2bcfafa16cfb127059 [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
63struct android_native_window_t
64{
65#ifdef __cplusplus
66 android_native_window_t()
67 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
68 {
69 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
70 common.version = sizeof(android_native_window_t);
71 memset(common.reserved, 0, sizeof(common.reserved));
72 }
73#endif
74
75 struct android_native_base_t common;
76
77 /* flags describing some attributes of this surface or its updater */
78 const uint32_t flags;
79
80 /* min swap interval supported by this updated */
81 const int minSwapInterval;
82
83 /* max swap interval supported by this updated */
84 const int maxSwapInterval;
85
86 /* horizontal and vertical resolution in DPI */
87 const float xdpi;
88 const float ydpi;
89
90 /* Some storage reserved for the OEM's driver. */
91 intptr_t oem[4];
92
Mathias Agopian076b1cc2009-04-10 14:24:30 -070093
94 /*
95 * Set the swap interval for this surface.
96 *
97 * Returns 0 on success or -errno on error.
98 */
99 int (*setSwapInterval)(struct android_native_window_t* window,
100 int interval);
101
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700102 /*
103 * hook called by EGL to acquire a buffer. After this call, the buffer
104 * is not locked, so its content cannot be modified.
Mathias Agopian0926f502009-05-04 14:17:04 -0700105 * this call may block if no buffers are available.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700106 *
107 * Returns 0 on success or -errno on error.
108 */
109 int (*dequeueBuffer)(struct android_native_window_t* window,
110 struct android_native_buffer_t** buffer);
111
112 /*
113 * hook called by EGL to lock a buffer. This MUST be called before modifying
114 * the content of a buffer. The buffer must have been acquired with
115 * dequeueBuffer first.
116 *
117 * Returns 0 on success or -errno on error.
118 */
119 int (*lockBuffer)(struct android_native_window_t* window,
120 struct android_native_buffer_t* buffer);
121 /*
122 * hook called by EGL when modifications to the render buffer are done.
123 * This unlocks and post the buffer.
124 *
125 * Buffers MUST be queued in the same order than they were dequeued.
126 *
127 * Returns 0 on success or -errno on error.
128 */
129 int (*queueBuffer)(struct android_native_window_t* window,
130 struct android_native_buffer_t* buffer);
131
132
133 void* reserved_proc[5];
134};
135
Mathias Agopianaa8c0ff2009-05-05 18:29:35 -0700136// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700137
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700138/* FIXME: this is legacy for pixmaps */
139struct egl_native_pixmap_t
140{
141 int32_t version; /* must be 32 */
142 int32_t width;
143 int32_t height;
144 int32_t stride;
145 uint8_t* data;
146 uint8_t format;
147 uint8_t rfu[3];
148 union {
149 uint32_t compressedFormat;
150 int32_t vstride;
151 };
152 int32_t reserved;
153};
154
155/*****************************************************************************/
156
157#ifdef __cplusplus
158}
159#endif
160
161
162/*****************************************************************************/
163
164#ifdef __cplusplus
165
166#include <utils/RefBase.h>
167
168namespace android {
169
170/*
171 * This helper class turns an EGL android_native_xxx type into a C++
172 * reference-counted object; with proper type conversions.
173 */
174template <typename NATIVE_TYPE, typename TYPE, typename REF>
175class EGLNativeBase : public NATIVE_TYPE, public REF
176{
177protected:
178 typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE;
179 EGLNativeBase() : NATIVE_TYPE(), REF() {
180 NATIVE_TYPE::common.incRef = incRef;
181 NATIVE_TYPE::common.decRef = decRef;
182 }
183 static inline TYPE* getSelf(NATIVE_TYPE* self) {
184 return static_cast<TYPE*>(self);
185 }
186 static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
187 return static_cast<TYPE const *>(self);
188 }
189 static inline TYPE* getSelf(android_native_base_t* base) {
190 return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
191 }
192 static inline TYPE const * getSelf(android_native_base_t const* base) {
193 return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
194 }
195 static void incRef(android_native_base_t* base) {
196 EGLNativeBase* self = getSelf(base);
197 self->incStrong(self);
198 }
199 static void decRef(android_native_base_t* base) {
200 EGLNativeBase* self = getSelf(base);
201 self->decStrong(self);
202 }
203};
204
205} // namespace android
206#endif // __cplusplus
207
208/*****************************************************************************/
209
210#endif /* ANDROID_ANDROID_NATIVES_H */