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