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