1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef EGL_CLIENT_SURFACE_H
29#define EGL_CLIENT_SURFACE_H
30
31#include "interface/khronos/include/EGL/egl.h"
32#include "interface/khronos/include/EGL/eglext.h"
33#include "interface/khronos/include/VG/openvg.h"
34#include "interface/khronos/egl/egl_int.h"
35
36#include "interface/khronos/common/khrn_client_platform.h"
37
38typedef enum {
39 WINDOW,
40 PBUFFER,
41 PIXMAP
42} EGL_SURFACE_TYPE_T;
43
44typedef enum {
45 SRGB,
46 LINEAR
47} EGL_SURFACE_COLORSPACE_T;
48
49typedef enum {
50 NONPRE,
51 PRE
52} EGL_SURFACE_ALPHAFORMAT_T;
53
54typedef struct {
55 EGLSurface name;
56
57 /*
58 type
59
60 Invariants:
61
62 (EGL_SURFACE_TYPE)
63 type in {WINDOW, PBUFFER, PIXMAP}
64 */
65 EGL_SURFACE_TYPE_T type;
66
67 /*
68 colorspace
69
70 Invariants:
71
72 (EGL_SURFACE_COLORSPACE)
73 colorspace in {SRGB, LINEAR}
74 */
75 EGL_SURFACE_COLORSPACE_T colorspace;
76
77 /*
78 alphaformat
79
80 Invariants:
81
82 (EGL_SURFACE_ALPHAFORMAT)
83 alphaformat in {NONPRE, PRE}
84 */
85 EGL_SURFACE_ALPHAFORMAT_T alphaformat;
86
87 /*
88 config
89
90 Invariants:
91
92 (EGL_SURFACE_CONFIG)
93 config is a valid EGLConfig
94 */
95 EGLConfig config;
96
97 uint32_t base_width;
98 uint32_t base_height;
99
100 /*
101 buffers
102
103 Usually 1 or 3.
104
105 Invariants:
106
107 (EGL_SURFACE_BUFFERS)
108 1 <= buffers <= EGL_MAX_BUFFERS
109 */
110 uint32_t buffers;
111
112 /*
113 width
114
115 Invariants:
116
117 (EGL_SURFACE_WIDTH)
118 1 <= width <= EGL_CONFIG_MAX_WIDTH
119 */
120 uint32_t width;
121
122 /*
123 height
124
125 Invariants:
126
127 (EGL_SURFACE_HEIGHT)
128 1 <= height <= EGL_CONFIG_MAX_HEIGHT
129 */
130 uint32_t height;
131
132 EGL_SURFACE_ID_T serverbuffer;
133
134 /*
135 context_binding_count
136
137 Invariant:
138
139 (EGL_SURFACE_BINDING_COUNT)
140 If we are current, how many times we are bound to the current context. Otherwise 0.
141 */
142 uint32_t context_binding_count;
143 struct CLIENT_THREAD_STATE *thread; // If we are current, which the EGL client state for the thread are we associated with.
144
145#if EGL_KHR_lock_surface
146 EGLBoolean is_locked;
147 void *mapped_buffer;
148#endif
149
150 /*
151 is_destroyed
152
153 Invariant:
154
155 (EGL_SURFACE_IS_DESTROYED)
156 Iff true, is not a member of the CLIENT_PROCESS_STATE_T.surfaces
157 */
158 bool is_destroyed;
159
160 /*
161 swap_behavior
162
163 Invariant:
164
165 (EGL_SURFACE_SWAP_BEHAVIOUR)
166 swap_behavior in {EGL_BUFFER_DESTROYED, EGL_BUFFER_PRESERVED}
167 */
168 EGLint swap_behavior;
169
170 /*
171 multisample_resolve
172
173 Invariant:
174
175 (EGL_SURFACE_MULTISAMPLE_RESOLVE)
176 multisample_resolve == EGL_MULTISAMPLE_RESOLVE_DEFAULT
177 */
178 EGLint multisample_resolve;
179
180 /* For WINDOW types only */
181
182 /*
183 win
184
185 Validity:
186 type == WINDOW
187 */
188 EGLNativeWindowType win;
189 /*
190 win
191
192 Validity:
193 type == WINDOW
194 */
195 uint32_t swap_interval;
196 uint32_t internal_handle; // stores "serverwin"
197
198 /*
199 avail_buffers
200
201 named counting semaphore, only used for triple-buffered window surfaces
202
203 Validity:
204 avail_buffers_valid
205 */
206 PLATFORM_SEMAPHORE_T avail_buffers;
207 bool avail_buffers_valid;
208
209 /* For PBUFFER types only */
210
211 /*
212 largest_pbuffer
213
214 Validity:
215 type == PBUFFER
216 */
217 bool largest_pbuffer;
218
219 /*
220 mipmap_texture
221
222 Validity:
223 type == PBUFFER
224 */
225 bool mipmap_texture;
226
227 /*
228 mipmap_level
229
230 Validity:
231 type == PBUFFER
232 */
233 uint32_t mipmap_level;
234
235 /*
236 texture_format
237
238 Validity:
239 type == PBUFFER
240
241 Invariant:
242 texture_format in {EGL_NO_TEXTURE, EGL_TEXTURE_RGB, EGL_TEXTURE_RGBA}
243 */
244 EGLenum texture_format;
245
246 /*
247 texture_target
248
249 Validity:
250 type == PBUFFER
251
252 Invariant:
253 texture_target in {EGL_NO_TEXTURE, EGL_TEXTURE_2D}
254 */
255 EGLenum texture_target;
256
257 /* For PIXMAP types only */
258
259 /*
260 pixmap
261
262 Validity:
263 type == PIXMAP
264
265 Invariant:
266 pixmap is a valid client-side pixmap handle for pixmap P
267 */
268 EGLNativePixmapType pixmap;
269
270 /*
271 pixmap_server_handle
272
273 Validity:
274 type == PIXMAP
275
276 Invariant:
277 If P is a server-side pixmap then
278 pixmap_server_handle is a valid server-side handle for pixmap P
279 else
280 pixmap_server_handle = [0, -1]
281 */
282 uint32_t pixmap_server_handle[2];
283
284 /*
285 pixmap_server_handle
286
287 Validity:
288 type == PIXMAP
289 */
290 bool server_owned;
291} EGL_SURFACE_T;
292
293extern bool egl_surface_check_attribs(
294 EGL_SURFACE_TYPE_T type,
295 const EGLint *attrib_list,
296 bool *linear,
297 bool *premult,
298 bool *single,
299 int *width,
300 int *height,
301 bool *largest_pbuffer,
302 EGLenum *texture_format,
303 EGLenum *texture_target,
304 bool *mipmap_texture
305);
306struct CLIENT_PROCESS_STATE;
307
308extern EGL_SURFACE_T *egl_surface_create(
309 EGLSurface name,
310 EGL_SURFACE_TYPE_T type,
311 EGL_SURFACE_COLORSPACE_T colorspace,
312 EGL_SURFACE_ALPHAFORMAT_T alphaformat,
313 uint32_t buffers,
314 uint32_t width,
315 uint32_t height,
316 EGLConfig config,
317 EGLNativeWindowType win,
318 uint32_t serverwin,
319 bool largest_pbuffer,
320 bool texture_compatibility,
321 bool mipmap_texture,
322 EGLenum texture_format,
323 EGLenum texture_target,
324 EGLNativePixmapType pixmap,
325 const uint32_t *pixmap_server_handle);
326extern EGL_SURFACE_T *egl_surface_from_vg_image(
327 VGImage vg_handle,
328 EGLSurface name,
329 EGLConfig config,
330 EGLBoolean largest_pbuffer,
331 EGLBoolean mipmap_texture,
332 EGLenum texture_format,
333 EGLenum texture_target,
334 EGLint *error);
335extern void egl_surface_free(EGL_SURFACE_T *surface);
336
337extern EGLBoolean egl_surface_get_attrib(EGL_SURFACE_T *surface, EGLint attrib, EGLint *value);
338extern EGLint egl_surface_set_attrib(EGL_SURFACE_T *surface, EGLint attrib, EGLint value);
339extern EGLint egl_surface_get_render_buffer(EGL_SURFACE_T *surface);
340
341#if EGL_KHR_lock_surface
342extern EGLint egl_surface_get_mapped_buffer_attrib(EGL_SURFACE_T *surface, EGLint attrib, EGLint *value);
343#endif
344extern void egl_surface_maybe_free(EGL_SURFACE_T *surface);
345
346#endif
347