blob: f9e544cadc7c6755ee970576b2f3e93c188f52d5 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 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_EGLNATIVES_H
18#define ANDROID_EGLNATIVES_H
19
20#include <sys/types.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25/*****************************************************************************/
26
27struct egl_native_window_t;
28struct egl_native_pixmap_t;
29
30
31typedef struct egl_native_window_t* NativeWindowType;
32typedef struct egl_native_pixmap_t* NativePixmapType;
33typedef void* NativeDisplayType;
34
35/*
36 * This a conveniance function to create a NativeWindowType surface
37 * that maps to the whole screen
38 * This function is actually implemented in libui.so
39 */
40
41NativeWindowType android_createDisplaySurface();
42
43/* flags returned from swapBuffer */
44#define EGL_NATIVES_FLAG_SIZE_CHANGED 0x00000001
45
46/* surface flags */
47#define EGL_NATIVES_FLAG_DESTROY_BACKBUFFER 0x00000001
48
49enum native_pixel_format_t
50{
51 NATIVE_PIXEL_FORMAT_RGBA_8888 = 1,
52 NATIVE_PIXEL_FORMAT_RGB_565 = 4,
53 NATIVE_PIXEL_FORMAT_RGBA_5551 = 6,
54 NATIVE_PIXEL_FORMAT_RGBA_4444 = 7,
55 NATIVE_PIXEL_FORMAT_YCbCr_422_SP= 0x10,
56 NATIVE_PIXEL_FORMAT_YCbCr_420_SP= 0x11,
57};
58
59enum native_memory_type_t
60{
61 NATIVE_MEMORY_TYPE_PMEM = 0,
62 NATIVE_MEMORY_TYPE_GPU = 1,
63 NATIVE_MEMORY_TYPE_FB = 2,
64 NATIVE_MEMORY_TYPE_HEAP = 128
65};
66
67
68struct egl_native_window_t
69{
70 /*
71 * magic must be set to 0x600913
72 */
73 uint32_t magic;
74
75 /*
76 * must be sizeof(egl_native_window_t)
77 */
78 uint32_t version;
79
80 /*
81 * ident is reserved for the Android platform
82 */
83 uint32_t ident;
84
85 /*
86 * width, height and stride of the window in pixels
87 * Any of these value can be nul in which case GL commands are
88 * accepted and processed as usual, but not rendering occurs.
89 */
90 int width; // w=h=0 is legal
91 int height;
92 int stride;
93
94 /*
95 * format of the native window (see ui/PixelFormat.h)
96 */
97 int format;
98
99 /*
100 * Offset of the bits in the VRAM
101 */
102 intptr_t offset;
103
104 /*
105 * flags describing some attributes of this surface
106 * EGL_NATIVES_FLAG_DESTROY_BACKBUFFER: backbuffer not preserved after
107 * eglSwapBuffers
108 */
109 uint32_t flags;
110
111 /*
112 * horizontal and vertical resolution in DPI
113 */
114 float xdpi;
115 float ydpi;
116
117 /*
118 * refresh rate in frames per second (Hz)
119 */
120 float fps;
121
122
123 /*
124 * Base memory virtual address of the surface in the CPU side
125 */
126 intptr_t base;
127
128 /*
129 * Heap the offset above is based from
130 */
131 int fd;
132
133 /*
134 * Memory type the surface resides into
135 */
136 uint8_t memory_type;
137
138 /*
139 * Reserved for future use. MUST BE ZERO.
140 */
141 uint8_t reserved_pad[3];
142 int reserved[8];
143
144 /*
145 * Vertical stride (only relevant with planar formats)
146 */
147
148 int vstride;
149
150 /*
151 * Hook called by EGL to hold a reference on this structure
152 */
153 void (*incRef)(NativeWindowType window);
154
155 /*
156 * Hook called by EGL to release a reference on this structure
157 */
158 void (*decRef)(NativeWindowType window);
159
160 /*
161 * Hook called by EGL to perform a page flip. This function
162 * may update the size attributes above, in which case it returns
163 * the EGL_NATIVES_FLAG_SIZE_CHANGED bit set.
164 */
165 uint32_t (*swapBuffers)(NativeWindowType window);
166
167 /*
168 * Hook called by EGL to set the swap rectangle. this hook can be
169 * null (operation not supported)
170 */
171 void (*setSwapRectangle)(NativeWindowType window, int l, int t, int w, int h);
172
173 /*
174 * Reserved for future use. MUST BE ZERO.
175 */
176 void (*reserved_proc_0)(void);
177
178
179 /*
180 * Hook called by EGL to retrieve the next buffer to render into.
181 * This call updates this structure.
182 */
183 uint32_t (*nextBuffer)(NativeWindowType window);
184
185 /*
186 * Hook called by EGL when the native surface is associated to EGL
187 * (eglCreateWindowSurface). Can be NULL.
188 */
189 void (*connect)(NativeWindowType window);
190
191 /*
192 * Hook called by EGL when eglDestroySurface is called. Can be NULL.
193 */
194 void (*disconnect)(NativeWindowType window);
195
196 /*
197 * Reserved for future use. MUST BE ZERO.
198 */
199 void (*reserved_proc[11])(void);
200
201 /*
202 * Some storage reserved for the oem driver.
203 */
204 intptr_t oem[4];
205};
206
207
208struct egl_native_pixmap_t
209{
210 int32_t version; /* must be 32 */
211 int32_t width;
212 int32_t height;
213 int32_t stride;
214 uint8_t* data;
215 uint8_t format;
216 uint8_t rfu[3];
217 union {
218 uint32_t compressedFormat;
219 int32_t vstride;
220 };
221 int32_t reserved;
222};
223
224/*****************************************************************************/
225
226/*
227 * OEM's egl's library (libhgl.so) must imlement these hooks to allocate
228 * the GPU memory they need
229 */
230
231
232typedef struct
233{
234 // for internal use
235 void* user;
236 // virtual address of this area
237 void* base;
238 // size of this area in bytes
239 size_t size;
240 // physical address of this area
241 void* phys;
242 // offset in this area available to the GPU
243 size_t offset;
244 // fd of this area
245 int fd;
246} gpu_area_t;
247
248typedef struct
249{
250 // area where GPU registers are mapped
251 gpu_area_t regs;
252 // number of extra areas (currently limited to 2)
253 int32_t count;
254 // extra GPU areas (currently limited to 2)
255 gpu_area_t gpu[2];
256} request_gpu_t;
257
258
259typedef request_gpu_t* (*OEM_EGL_acquire_gpu_t)(void* user);
260typedef int (*OEM_EGL_release_gpu_t)(void* user, request_gpu_t* handle);
261typedef void (*register_gpu_t)
262 (void* user, OEM_EGL_acquire_gpu_t, OEM_EGL_release_gpu_t);
263
264void oem_register_gpu(
265 void* user,
266 OEM_EGL_acquire_gpu_t acquire,
267 OEM_EGL_release_gpu_t release);
268
269
270/*****************************************************************************/
271
272#ifdef __cplusplus
273}
274#endif
275
276#endif /* ANDROID_EGLNATIVES_H */