Debian Codegraph @

src/egl/main/egldisplay.h

raw
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <[email protected]>
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 #ifndef EGLDISPLAY_INCLUDED
31 #define EGLDISPLAY_INCLUDED
32
33 #include "util/rwlock.h"
34 #include "util/simple_mtx.h"
35
36 #include "eglarray.h"
37 #include "egldefines.h"
38 #include "egltypedefs.h"
39
40 #ifdef HAVE_X11_PLATFORM
41 #include <X11/Xlib.h>
42 #endif
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 enum _egl_platform_type {
49 _EGL_PLATFORM_X11,
50 _EGL_PLATFORM_XCB,
51 _EGL_PLATFORM_WAYLAND,
52 _EGL_PLATFORM_DRM,
53 _EGL_PLATFORM_ANDROID,
54 _EGL_PLATFORM_HAIKU,
55 _EGL_PLATFORM_SURFACELESS,
56 _EGL_PLATFORM_DEVICE,
57 _EGL_PLATFORM_WINDOWS,
58
59 _EGL_NUM_PLATFORMS,
60 _EGL_INVALID_PLATFORM = -1
61 };
62 typedef enum _egl_platform_type _EGLPlatformType;
63
64 enum _egl_resource_type {
65 _EGL_RESOURCE_CONTEXT,
66 _EGL_RESOURCE_SURFACE,
67 _EGL_RESOURCE_IMAGE,
68 _EGL_RESOURCE_SYNC,
69
70 _EGL_NUM_RESOURCES
71 };
72 /* this cannot and need not go into egltypedefs.h */
73 typedef enum _egl_resource_type _EGLResourceType;
74
75 /**
76 * A resource of a display.
77 */
78 struct _egl_resource {
79 /* which display the resource belongs to */
80 _EGLDisplay *Display;
81 EGLBoolean IsLinked;
82 EGLint RefCount;
83
84 EGLLabelKHR Label;
85
86 /* used to link resources of the same type */
87 _EGLResource *Next;
88 };
89
90 /**
91 * Optional EGL extensions info.
92 */
93 struct _egl_extensions {
94 /* Please keep these sorted alphabetically. */
95 EGLBoolean ANDROID_blob_cache;
96 EGLBoolean ANDROID_framebuffer_target;
97 EGLBoolean ANDROID_image_native_buffer;
98 EGLBoolean ANDROID_native_fence_sync;
99 EGLBoolean ANDROID_recordable;
100
101 EGLBoolean ANGLE_sync_control_rate;
102 EGLBoolean CHROMIUM_sync_control;
103
104 EGLBoolean EXT_buffer_age;
105 EGLBoolean EXT_config_select_group;
106 EGLBoolean EXT_create_context_robustness;
107 EGLBoolean EXT_image_dma_buf_import;
108 EGLBoolean EXT_image_dma_buf_import_modifiers;
109 EGLBoolean EXT_pixel_format_float;
110 EGLBoolean EXT_present_opaque;
111 EGLBoolean EXT_protected_content;
112 EGLBoolean EXT_protected_surface;
113 EGLBoolean EXT_query_reset_notification_strategy;
114 EGLBoolean EXT_surface_compression;
115 EGLBoolean EXT_surface_CTA861_3_metadata;
116 EGLBoolean EXT_surface_SMPTE2086_metadata;
117 EGLBoolean EXT_swap_buffers_with_damage;
118
119 unsigned int IMG_context_priority;
120 #define __EGL_CONTEXT_PRIORITY_LOW_BIT 0
121 #define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
122 #define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2
123 #define __EGL_CONTEXT_PRIORITY_REALTIME_BIT 3
124
125 EGLBoolean KHR_cl_event2;
126 EGLBoolean KHR_config_attribs;
127 EGLBoolean KHR_context_flush_control;
128 EGLBoolean KHR_create_context;
129 EGLBoolean KHR_create_context_no_error;
130 EGLBoolean KHR_fence_sync;
131 EGLBoolean KHR_get_all_proc_addresses;
132 EGLBoolean KHR_gl_colorspace;
133 EGLBoolean KHR_gl_renderbuffer_image;
134 EGLBoolean KHR_gl_texture_2D_image;
135 EGLBoolean KHR_gl_texture_3D_image;
136 EGLBoolean KHR_gl_texture_cubemap_image;
137 EGLBoolean KHR_image;
138 EGLBoolean KHR_image_base;
139 EGLBoolean KHR_image_pixmap;
140 EGLBoolean KHR_mutable_render_buffer;
141 EGLBoolean KHR_no_config_context;
142 EGLBoolean KHR_partial_update;
143 EGLBoolean KHR_reusable_sync;
144 EGLBoolean KHR_surfaceless_context;
145 EGLBoolean KHR_wait_sync;
146
147 EGLBoolean MESA_gl_interop;
148 EGLBoolean MESA_image_dma_buf_export;
149 EGLBoolean MESA_query_driver;
150 EGLBoolean MESA_x11_native_visual_id;
151
152 EGLBoolean NOK_texture_from_pixmap;
153
154 EGLBoolean NV_context_priority_realtime;
155
156 EGLBoolean WL_bind_wayland_display;
157 EGLBoolean WL_create_wayland_buffer_from_image;
158 };
159
160 struct _egl_display {
161 /* used to link displays */
162 _EGLDisplay *Next;
163
164 /**
165 * The big-display-lock (BDL) which protects our internal state. EGL
166 * drivers should use their own locking, as needed, to protect their
167 * own state, rather than relying on this.
168 */
169 simple_mtx_t Mutex;
170
171 /**
172 * The spec appears to allow eglTerminate() to race with more or less
173 * any other egl call. To allow for this, while relaxing the BDL to
174 * allow other egl calls to happen in parallel, a rwlock is used. All
175 * points where the BDL lock is acquired also acquire TerminateLock
176 * for reading, while eglTerminate() itself acquires the TerminateLock
177 * for writing.
178 *
179 * Note, we could conceivably just replace the BDL with a single
180 * rwlock. But there are a couple shortcomings of u_rwlock:
181 *
182 * 1) The WIN32 implementation does not allow promoting a read-
183 * lock to write-lock, nor recursive locking, whereas the
184 * pthread based implementation does. Because of this, it
185 * would be difficult to keep the eglapi layer portable if
186 * we depended on any less-than-trivial rwlock usage.
187 *
188 * 2) We'd lose simple_mtx_assert_locked().
189 */
190 struct u_rwlock TerminateLock;
191
192 _EGLPlatformType Platform; /**< The type of the platform display */
193 void *PlatformDisplay; /**< A pointer to the platform display */
194
195 _EGLDevice *Device; /**< Device backing the display */
196 const _EGLDriver *Driver; /**< Matched driver of the display */
197 EGLBoolean Initialized; /**< True if the display is initialized */
198
199 /* options that affect how the driver initializes the display */
200 struct {
201 EGLBoolean Zink; /**< Use kopper only */
202 EGLBoolean ForceSoftware; /**< Use software path only */
203 EGLBoolean GalliumHudWarn; /**< Using hud, warn when querying buffer age */
204 EGLAttrib *Attribs; /**< Platform-specific options */
205 int fd; /**< Platform device specific, local fd */
206 } Options;
207
208 /* these fields are set by the driver during init */
209 void *DriverData; /**< Driver private data */
210 EGLint Version; /**< EGL version major*10+minor */
211 EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */
212 _EGLExtensions Extensions; /**< Extensions supported */
213 EGLBoolean RobustBufferAccess; /**< Supports robust buffer access behavior */
214
215 /* these fields are derived from above */
216 char VersionString[100]; /**< EGL_VERSION */
217 char ClientAPIsString[100]; /**< EGL_CLIENT_APIS */
218 char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */
219
220 _EGLArray *Configs;
221
222 /* lists of resources */
223 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
224
225 EGLLabelKHR Label;
226
227 EGLSetBlobFuncANDROID BlobCacheSet;
228 EGLGetBlobFuncANDROID BlobCacheGet;
229 };
230
231 extern _EGLDisplay *
232 _eglLockDisplay(EGLDisplay dpy);
233
234 extern void
235 _eglUnlockDisplay(_EGLDisplay *disp);
236
237 extern _EGLPlatformType
238 _eglGetNativePlatform(void *nativeDisplay);
239
240 extern void
241 _eglFiniDisplay(void);
242
243 extern _EGLDisplay *
244 _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
245
246 extern void
247 _eglReleaseDisplayResources(_EGLDisplay *disp);
248
249 extern void
250 _eglCleanupDisplay(_EGLDisplay *disp);
251
252 extern EGLBoolean
253 _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp);
254
255 /**
256 * Return the handle of a linked display, or EGL_NO_DISPLAY.
257 */
258 static inline EGLDisplay
259 _eglGetDisplayHandle(_EGLDisplay *disp)
260 {
261 return (EGLDisplay)((disp) ? disp : EGL_NO_DISPLAY);
262 }
263
264 static inline EGLBoolean
265 _eglHasAttrib(_EGLDisplay *disp, EGLAttrib attrib)
266 {
267 EGLAttrib *attribs = disp->Options.Attribs;
268
269 if (!attribs) {
270 return EGL_FALSE;
271 }
272
273 for (int i = 0; attribs[i] != EGL_NONE; i += 2) {
274 if (attrib == attribs[i]) {
275 return EGL_TRUE;
276 }
277 }
278 return EGL_FALSE;
279 }
280
281 extern void
282 _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp);
283
284 extern void
285 _eglGetResource(_EGLResource *res);
286
287 extern EGLBoolean
288 _eglPutResource(_EGLResource *res);
289
290 extern void
291 _eglLinkResource(_EGLResource *res, _EGLResourceType type);
292
293 extern void
294 _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
295
296 /**
297 * Return true if the resource is linked.
298 */
299 static inline EGLBoolean
300 _eglIsResourceLinked(_EGLResource *res)
301 {
302 return res->IsLinked;
303 }
304
305 static inline size_t
306 _eglNumAttribs(const EGLAttrib *attribs)
307 {
308 size_t len = 0;
309
310 if (attribs) {
311 while (attribs[len] != EGL_NONE)
312 len += 2;
313 len++;
314 }
315 return len;
316 }
317
318 #ifdef HAVE_X11_PLATFORM
319 _EGLDisplay *
320 _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
321 #endif
322
323 #ifdef HAVE_XCB_PLATFORM
324 typedef struct xcb_connection_t xcb_connection_t;
325 _EGLDisplay *
326 _eglGetXcbDisplay(xcb_connection_t *native_display,
327 const EGLAttrib *attrib_list);
328 #endif
329
330 #ifdef HAVE_DRM_PLATFORM
331 struct gbm_device;
332
333 _EGLDisplay *
334 _eglGetGbmDisplay(struct gbm_device *native_display,
335 const EGLAttrib *attrib_list);
336 #endif
337
338 #ifdef HAVE_WAYLAND_PLATFORM
339 struct wl_display;
340
341 _EGLDisplay *
342 _eglGetWaylandDisplay(struct wl_display *native_display,
343 const EGLAttrib *attrib_list);
344 #endif
345
346 _EGLDisplay *
347 _eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list);
348
349 #ifdef HAVE_ANDROID_PLATFORM
350 _EGLDisplay *
351 _eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list);
352 #endif
353
354 _EGLDisplay *
355 _eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list);
356
357 #ifdef __cplusplus
358 }
359 #endif
360
361 #endif /* EGLDISPLAY_INCLUDED */