1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
31 #ifndef EGLDISPLAY_INCLUDED
32 #define EGLDISPLAY_INCLUDED
33
34 #include "c99_compat.h"
35 #include "c11/threads.h"
36
37 #include "egltypedefs.h"
38 #include "egldefines.h"
39 #include "eglarray.h"
40
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 enum _egl_platform_type {
47 _EGL_PLATFORM_X11,
48 _EGL_PLATFORM_XCB,
49 _EGL_PLATFORM_WAYLAND,
50 _EGL_PLATFORM_DRM,
51 _EGL_PLATFORM_ANDROID,
52 _EGL_PLATFORM_HAIKU,
53 _EGL_PLATFORM_SURFACELESS,
54 _EGL_PLATFORM_DEVICE,
55 _EGL_PLATFORM_WINDOWS,
56
57 _EGL_NUM_PLATFORMS,
58 _EGL_INVALID_PLATFORM = -1
59 };
60 typedef enum _egl_platform_type _EGLPlatformType;
61
62
63 enum _egl_resource_type {
64 _EGL_RESOURCE_CONTEXT,
65 _EGL_RESOURCE_SURFACE,
66 _EGL_RESOURCE_IMAGE,
67 _EGL_RESOURCE_SYNC,
68
69 _EGL_NUM_RESOURCES
70 };
71 /* this cannot and need not go into egltypedefs.h */
72 typedef enum _egl_resource_type _EGLResourceType;
73
74
75 /**
76 * A resource of a display.
77 */
78 struct _egl_resource
79 {
80 /* which display the resource belongs to */
81 _EGLDisplay *Display;
82 EGLBoolean IsLinked;
83 EGLint RefCount;
84
85 EGLLabelKHR Label;
86
87 /* used to link resources of the same type */
88 _EGLResource *Next;
89 };
90
91
92 /**
93 * Optional EGL extensions info.
94 */
95 struct _egl_extensions
96 {
97 /* Please keep these sorted alphabetically. */
98 EGLBoolean ANDROID_blob_cache;
99 EGLBoolean ANDROID_framebuffer_target;
100 EGLBoolean ANDROID_image_native_buffer;
101 EGLBoolean ANDROID_native_fence_sync;
102 EGLBoolean ANDROID_recordable;
103
104 EGLBoolean CHROMIUM_sync_control;
105
106 EGLBoolean EXT_buffer_age;
107 EGLBoolean EXT_create_context_robustness;
108 EGLBoolean EXT_image_dma_buf_import;
109 EGLBoolean EXT_image_dma_buf_import_modifiers;
110 EGLBoolean EXT_pixel_format_float;
111 EGLBoolean EXT_protected_surface;
112 EGLBoolean EXT_present_opaque;
113 EGLBoolean EXT_surface_CTA861_3_metadata;
114 EGLBoolean EXT_surface_SMPTE2086_metadata;
115 EGLBoolean EXT_swap_buffers_with_damage;
116
117 unsigned int IMG_context_priority;
118 #define __EGL_CONTEXT_PRIORITY_LOW_BIT 0
119 #define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
120 #define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2
121
122 EGLBoolean KHR_cl_event2;
123 EGLBoolean KHR_config_attribs;
124 EGLBoolean KHR_context_flush_control;
125 EGLBoolean KHR_create_context;
126 EGLBoolean KHR_create_context_no_error;
127 EGLBoolean KHR_fence_sync;
128 EGLBoolean KHR_get_all_proc_addresses;
129 EGLBoolean KHR_gl_colorspace;
130 EGLBoolean KHR_gl_renderbuffer_image;
131 EGLBoolean KHR_gl_texture_2D_image;
132 EGLBoolean KHR_gl_texture_3D_image;
133 EGLBoolean KHR_gl_texture_cubemap_image;
134 EGLBoolean KHR_image;
135 EGLBoolean KHR_image_base;
136 EGLBoolean KHR_image_pixmap;
137 EGLBoolean KHR_mutable_render_buffer;
138 EGLBoolean KHR_no_config_context;
139 EGLBoolean KHR_partial_update;
140 EGLBoolean KHR_reusable_sync;
141 EGLBoolean KHR_surfaceless_context;
142 EGLBoolean KHR_wait_sync;
143
144 EGLBoolean MESA_drm_image;
145 EGLBoolean MESA_image_dma_buf_export;
146 EGLBoolean MESA_query_driver;
147
148 EGLBoolean NOK_swap_region;
149 EGLBoolean NOK_texture_from_pixmap;
150
151 EGLBoolean NV_post_sub_buffer;
152
153 EGLBoolean WL_bind_wayland_display;
154 EGLBoolean WL_create_wayland_buffer_from_image;
155 };
156
157 struct _egl_display
158 {
159 /* used to link displays */
160 _EGLDisplay *Next;
161
162 mtx_t Mutex;
163
164 _EGLPlatformType Platform; /**< The type of the platform display */
165 void *PlatformDisplay; /**< A pointer to the platform display */
166
167 _EGLDevice *Device; /**< Device backing the display */
168 const _EGLDriver *Driver; /**< Matched driver of the display */
169 EGLBoolean Initialized; /**< True if the display is initialized */
170
171 /* options that affect how the driver initializes the display */
172 struct {
173 EGLBoolean ForceSoftware; /**< Use software path only */
174 EGLAttrib *Attribs; /**< Platform-specific options */
175 int fd; /**< plaform device specific, local fd */
176 } Options;
177
178 /* these fields are set by the driver during init */
179 void *DriverData; /**< Driver private data */
180 EGLint Version; /**< EGL version major*10+minor */
181 EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */
182 _EGLExtensions Extensions; /**< Extensions supported */
183
184 /* these fields are derived from above */
185 char VersionString[100]; /**< EGL_VERSION */
186 char ClientAPIsString[100]; /**< EGL_CLIENT_APIS */
187 char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */
188
189 _EGLArray *Configs;
190
191 /* lists of resources */
192 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
193
194 EGLLabelKHR Label;
195
196 EGLSetBlobFuncANDROID BlobCacheSet;
197 EGLGetBlobFuncANDROID BlobCacheGet;
198 };
199
200
201 extern _EGLPlatformType
202 _eglGetNativePlatform(void *nativeDisplay);
203
204
205 extern void
206 _eglFiniDisplay(void);
207
208
209 extern _EGLDisplay *
210 _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
211
212
213 extern void
214 _eglReleaseDisplayResources(_EGLDisplay *disp);
215
216
217 extern void
218 _eglCleanupDisplay(_EGLDisplay *disp);
219
220
221 extern EGLBoolean
222 _eglCheckDisplayHandle(EGLDisplay dpy);
223
224
225 extern EGLBoolean
226 _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp);
227
228
229 /**
230 * Lookup a handle to find the linked display.
231 * Return NULL if the handle has no corresponding linked display.
232 */
233 static inline _EGLDisplay *
_eglLookupDisplay(EGLDisplay dpy)234 _eglLookupDisplay(EGLDisplay dpy)
235 {
236 _EGLDisplay *disp = (_EGLDisplay *) dpy;
237 if (!_eglCheckDisplayHandle(dpy))
238 disp = NULL;
239 return disp;
240 }
241
242
243 /**
244 * Return the handle of a linked display, or EGL_NO_DISPLAY.
245 */
246 static inline EGLDisplay
_eglGetDisplayHandle(_EGLDisplay * disp)247 _eglGetDisplayHandle(_EGLDisplay *disp)
248 {
249 return (EGLDisplay) ((disp) ? disp : EGL_NO_DISPLAY);
250 }
251
252
253 extern void
254 _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp);
255
256
257 extern void
258 _eglGetResource(_EGLResource *res);
259
260
261 extern EGLBoolean
262 _eglPutResource(_EGLResource *res);
263
264
265 extern void
266 _eglLinkResource(_EGLResource *res, _EGLResourceType type);
267
268
269 extern void
270 _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
271
272
273 /**
274 * Return true if the resource is linked.
275 */
276 static inline EGLBoolean
_eglIsResourceLinked(_EGLResource * res)277 _eglIsResourceLinked(_EGLResource *res)
278 {
279 return res->IsLinked;
280 }
281
282 static inline size_t
_eglNumAttribs(const EGLAttrib * attribs)283 _eglNumAttribs(const EGLAttrib *attribs)
284 {
285 size_t len = 0;
286
287 if (attribs) {
288 while (attribs[len] != EGL_NONE)
289 len += 2;
290 len++;
291 }
292 return len;
293 }
294
295 #ifdef HAVE_X11_PLATFORM
296 _EGLDisplay*
297 _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
298 #endif
299
300 #ifdef HAVE_XCB_PLATFORM
301 typedef struct xcb_connection_t xcb_connection_t;
302 _EGLDisplay*
303 _eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list);
304 #endif
305
306 #ifdef HAVE_DRM_PLATFORM
307 struct gbm_device;
308
309 _EGLDisplay*
310 _eglGetGbmDisplay(struct gbm_device *native_display,
311 const EGLAttrib *attrib_list);
312 #endif
313
314 #ifdef HAVE_WAYLAND_PLATFORM
315 struct wl_display;
316
317 _EGLDisplay*
318 _eglGetWaylandDisplay(struct wl_display *native_display,
319 const EGLAttrib *attrib_list);
320 #endif
321
322 _EGLDisplay*
323 _eglGetSurfacelessDisplay(void *native_display,
324 const EGLAttrib *attrib_list);
325
326 #ifdef HAVE_ANDROID_PLATFORM
327 _EGLDisplay*
328 _eglGetAndroidDisplay(void *native_display,
329 const EGLAttrib *attrib_list);
330 #endif
331
332 _EGLDisplay*
333 _eglGetDeviceDisplay(void *native_display,
334 const EGLAttrib *attrib_list);
335
336 #ifdef __cplusplus
337 }
338 #endif
339
340 #endif /* EGLDISPLAY_INCLUDED */
341