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