blob: a4f7f42cd438b3aa71ce78b0449f029d7158bb13 [file] [log] [blame]
Chia-I Wuf2001df2011-07-02 17:57:30 +09001/**************************************************************************
2 *
José Fonseca87712852014-01-17 16:27:50 +00003 * Copyright 2008 VMware, Inc.
Chia-I Wuf2001df2011-07-02 17:57:30 +09004 * 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
Brian Pauladbff7e2005-04-22 21:09:39 +000031#ifndef EGLDISPLAY_INCLUDED
32#define EGLDISPLAY_INCLUDED
33
Emil Velikov7bd16932015-02-28 16:35:22 +000034#include "c99_compat.h"
Emil Velikovefe87f12015-03-06 16:54:55 +000035#include "c11/threads.h"
Chia-I Wu94cb3212010-01-29 09:00:30 +080036
Brian Pauladbff7e2005-04-22 21:09:39 +000037#include "egltypedefs.h"
Chia-I Wu5a2c9372009-08-13 13:38:24 +080038#include "egldefines.h"
Chia-I Wu6717a312010-06-30 17:10:10 +080039#include "eglarray.h"
Chia-I Wu5a2c9372009-08-13 13:38:24 +080040
41
Alexander von Gluck IV83620682015-05-13 17:13:37 -050042#ifdef __cplusplus
43extern "C" {
44#endif
45
Chia-I Wuf22665d2010-06-17 17:14:03 +080046enum _egl_platform_type {
Chia-I Wuf22665d2010-06-17 17:14:03 +080047 _EGL_PLATFORM_X11,
Benjamin Franzkee586c4b2011-02-04 12:22:58 +010048 _EGL_PLATFORM_WAYLAND,
Chia-I Wuf22665d2010-06-17 17:14:03 +080049 _EGL_PLATFORM_DRM,
Chia-I Wub0945c12010-10-11 16:09:52 +080050 _EGL_PLATFORM_ANDROID,
Alexander von Gluck IV400b8332014-12-22 10:10:13 -050051 _EGL_PLATFORM_HAIKU,
Haixia Shi6b8accb2015-06-12 10:10:58 -070052 _EGL_PLATFORM_SURFACELESS,
Emil Velikovd6edcce2019-05-16 18:01:40 +010053 _EGL_PLATFORM_DEVICE,
Chia-I Wuf22665d2010-06-17 17:14:03 +080054
55 _EGL_NUM_PLATFORMS,
56 _EGL_INVALID_PLATFORM = -1
57};
58typedef enum _egl_platform_type _EGLPlatformType;
59
60
Chia-I Wu7abf4262010-01-24 20:30:04 +080061enum _egl_resource_type {
62 _EGL_RESOURCE_CONTEXT,
63 _EGL_RESOURCE_SURFACE,
Chia-I Wua1c4a8a2009-08-15 22:58:13 +080064 _EGL_RESOURCE_IMAGE,
Chia-I Wu4eebea72010-08-14 23:09:12 +080065 _EGL_RESOURCE_SYNC,
Chia-I Wu7abf4262010-01-24 20:30:04 +080066
67 _EGL_NUM_RESOURCES
68};
Chia-I Wu496724b2010-02-19 11:47:54 +080069/* this cannot and need not go into egltypedefs.h */
70typedef enum _egl_resource_type _EGLResourceType;
Chia-I Wu7abf4262010-01-24 20:30:04 +080071
72
73/**
74 * A resource of a display.
75 */
76struct _egl_resource
77{
Chia-I Wuf65ed0a2010-01-26 15:16:49 +080078 /* which display the resource belongs to */
Chia-I Wu7abf4262010-01-24 20:30:04 +080079 _EGLDisplay *Display;
Chia-I Wuf65ed0a2010-01-26 15:16:49 +080080 EGLBoolean IsLinked;
Chia-I Wudc4f8452010-10-23 11:59:03 +080081 EGLint RefCount;
Chia-I Wuf65ed0a2010-01-26 15:16:49 +080082
Kyle Brenneman7206b3a2016-09-12 16:15:10 -040083 EGLLabelKHR Label;
84
Chia-I Wuf65ed0a2010-01-26 15:16:49 +080085 /* used to link resources of the same type */
Chia-I Wu7abf4262010-01-24 20:30:04 +080086 _EGLResource *Next;
87};
88
89
Chia-I Wu5a2c9372009-08-13 13:38:24 +080090/**
91 * Optional EGL extensions info.
92 */
93struct _egl_extensions
94{
Marek Olšák32aa1d72015-06-09 23:08:57 +020095 /* Please keep these sorted alphabetically. */
Tapani Pälli6f5b5702017-12-28 10:51:11 +020096 EGLBoolean ANDROID_blob_cache;
Rob Herring89755272016-02-02 14:23:07 -060097 EGLBoolean ANDROID_framebuffer_target;
Chia-I Wu00b365b2010-10-01 15:27:42 -040098 EGLBoolean ANDROID_image_native_buffer;
Rob Clark0201f012016-11-18 08:39:33 -050099 EGLBoolean ANDROID_native_fence_sync;
Rob Herringe21e81a2016-02-02 14:23:08 -0600100 EGLBoolean ANDROID_recordable;
Fredrik Höglund7d46b452011-12-14 21:24:09 +0100101
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700102 EGLBoolean CHROMIUM_sync_control;
103
Marek Olšák32aa1d72015-06-09 23:08:57 +0200104 EGLBoolean EXT_buffer_age;
105 EGLBoolean EXT_create_context_robustness;
106 EGLBoolean EXT_image_dma_buf_import;
Pekka Paalanenfb2a1c22017-05-30 17:23:35 +0530107 EGLBoolean EXT_image_dma_buf_import_modifiers;
Tapani Pälli41f7de42017-10-31 10:57:42 +0200108 EGLBoolean EXT_pixel_format_float;
Tapani Pälli799b3d12018-04-05 13:02:36 +0300109 EGLBoolean EXT_surface_CTA861_3_metadata;
110 EGLBoolean EXT_surface_SMPTE2086_metadata;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200111 EGLBoolean EXT_swap_buffers_with_damage;
112
Chris Wilson95ecf3d2016-10-27 19:34:46 +0100113 unsigned int IMG_context_priority;
114#define __EGL_CONTEXT_PRIORITY_LOW_BIT 0
115#define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
116#define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2
117
Marek Olšák32aa1d72015-06-09 23:08:57 +0200118 EGLBoolean KHR_cl_event2;
Emil Velikov26541a12016-12-05 14:42:04 +0000119 EGLBoolean KHR_config_attribs;
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400120 EGLBoolean KHR_context_flush_control;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200121 EGLBoolean KHR_create_context;
Eric Engestrom57223fb2018-01-08 15:47:09 +0000122 EGLBoolean KHR_create_context_no_error;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200123 EGLBoolean KHR_fence_sync;
124 EGLBoolean KHR_get_all_proc_addresses;
125 EGLBoolean KHR_gl_colorspace;
126 EGLBoolean KHR_gl_renderbuffer_image;
127 EGLBoolean KHR_gl_texture_2D_image;
128 EGLBoolean KHR_gl_texture_3D_image;
129 EGLBoolean KHR_gl_texture_cubemap_image;
Harish Krupo96fc5fb2017-12-08 21:29:39 +0530130 EGLBoolean KHR_image;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200131 EGLBoolean KHR_image_base;
132 EGLBoolean KHR_image_pixmap;
Chad Versace3dc22382018-04-30 22:32:25 -0700133 EGLBoolean KHR_mutable_render_buffer;
Adam Jacksond9f5b192016-09-09 12:25:34 -0400134 EGLBoolean KHR_no_config_context;
Harish Krupo98275472017-06-09 20:13:34 +0530135 EGLBoolean KHR_partial_update;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200136 EGLBoolean KHR_reusable_sync;
137 EGLBoolean KHR_surfaceless_context;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200138 EGLBoolean KHR_wait_sync;
139
Marek Olšák32aa1d72015-06-09 23:08:57 +0200140 EGLBoolean MESA_drm_image;
141 EGLBoolean MESA_image_dma_buf_export;
Veluri Mithun6afce782019-01-23 22:44:25 +0530142 EGLBoolean MESA_query_driver;
Marek Olšák32aa1d72015-06-09 23:08:57 +0200143
144 EGLBoolean NOK_swap_region;
145 EGLBoolean NOK_texture_from_pixmap;
146
Fredrik Höglund7d46b452011-12-14 21:24:09 +0100147 EGLBoolean NV_post_sub_buffer;
Ian Romanickf1715712012-07-19 15:08:06 -0700148
Marek Olšák32aa1d72015-06-09 23:08:57 +0200149 EGLBoolean WL_bind_wayland_display;
150 EGLBoolean WL_create_wayland_buffer_from_image;
Chia-I Wu5a2c9372009-08-13 13:38:24 +0800151};
Brian Pauladbff7e2005-04-22 21:09:39 +0000152
Chia-I Wuf22665d2010-06-17 17:14:03 +0800153struct _egl_display
Brian Pauladbff7e2005-04-22 21:09:39 +0000154{
Chia-I Wu38feefd2009-08-14 17:47:00 +0800155 /* used to link displays */
156 _EGLDisplay *Next;
157
Emil Velikovefe87f12015-03-06 16:54:55 +0000158 mtx_t Mutex;
Chia-I Wu99bcb1f2010-02-17 17:29:52 +0800159
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800160 _EGLPlatformType Platform; /**< The type of the platform display */
161 void *PlatformDisplay; /**< A pointer to the platform display */
Brian Pauladbff7e2005-04-22 21:09:39 +0000162
Emil Velikov7552fcb2015-07-24 16:19:55 +0200163 _EGLDevice *Device; /**< Device backing the display */
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200164 const _EGLDriver *Driver; /**< Matched driver of the display */
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800165 EGLBoolean Initialized; /**< True if the display is initialized */
Chia-I Wu5a2c9372009-08-13 13:38:24 +0800166
Chia-I Wu655e4592011-01-13 00:27:45 +0800167 /* options that affect how the driver initializes the display */
168 struct {
Eric Engestrom81cea662017-12-20 15:53:09 +0000169 EGLBoolean ForceSoftware; /**< Use software path only */
Adam Jackson8e991ce2019-05-16 18:01:34 +0100170 EGLAttrib *Attribs; /**< Platform-specific options */
Emil Velikovd6edcce2019-05-16 18:01:40 +0100171 int fd; /**< plaform device specific, local fd */
Chia-I Wu655e4592011-01-13 00:27:45 +0800172 } Options;
173
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800174 /* these fields are set by the driver during init */
175 void *DriverData; /**< Driver private data */
Marek Olšák0e4b5642015-05-12 16:40:29 +0200176 EGLint Version; /**< EGL version major*10+minor */
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800177 EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */
178 _EGLExtensions Extensions; /**< Extensions supported */
Chia-I Wu5a2c9372009-08-13 13:38:24 +0800179
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800180 /* these fields are derived from above */
Emil Velikovbbaf22a2015-03-19 01:36:08 +0000181 char VersionString[100]; /**< EGL_VERSION */
182 char ClientAPIsString[100]; /**< EGL_CLIENT_APIS */
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800183 char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */
Chia-I Wu5a2c9372009-08-13 13:38:24 +0800184
Chia-I Wu6717a312010-06-30 17:10:10 +0800185 _EGLArray *Configs;
Brian Paul6052af12008-05-27 16:48:23 -0600186
Chia-I Wuecb3b312010-01-24 20:32:34 +0800187 /* lists of resources */
Chia-I Wu7abf4262010-01-24 20:30:04 +0800188 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
Kyle Brenneman7206b3a2016-09-12 16:15:10 -0400189
190 EGLLabelKHR Label;
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200191
192 EGLSetBlobFuncANDROID BlobCacheSet;
193 EGLGetBlobFuncANDROID BlobCacheGet;
Brian Pauladbff7e2005-04-22 21:09:39 +0000194};
195
196
Chia-I Wuea052992010-06-17 23:45:41 +0800197extern _EGLPlatformType
Chad Versace6d1f83e2014-01-07 14:54:51 -0800198_eglGetNativePlatform(void *nativeDisplay);
Chia-I Wuea052992010-06-17 23:45:41 +0800199
200
Chia-I Wu38feefd2009-08-14 17:47:00 +0800201extern void
202_eglFiniDisplay(void);
203
204
Brian Pauladbff7e2005-04-22 21:09:39 +0000205extern _EGLDisplay *
Adam Jackson8e991ce2019-05-16 18:01:34 +0100206_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
Chia-I Wube9d1ab2009-07-16 21:21:56 -0700207
208
Emil Velikovdd438ae2015-02-28 17:20:01 +0000209extern void
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200210_eglReleaseDisplayResources(const _EGLDriver *drv, _EGLDisplay *disp);
Chia-I Wu3f7e0d52009-07-16 21:21:57 -0700211
212
Emil Velikovdd438ae2015-02-28 17:20:01 +0000213extern void
Jon Smirl7012d012005-05-13 18:31:35 +0000214_eglCleanupDisplay(_EGLDisplay *disp);
215
216
Chia-I Wue484a922009-08-14 18:02:38 +0800217extern EGLBoolean
218_eglCheckDisplayHandle(EGLDisplay dpy);
219
220
Emil Velikovdd438ae2015-02-28 17:20:01 +0000221extern EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000222_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp);
Chia-I Wu7abf4262010-01-24 20:30:04 +0800223
224
Chia-I Wue3734e42009-08-14 18:05:19 +0800225/**
226 * Lookup a handle to find the linked display.
227 * Return NULL if the handle has no corresponding linked display.
228 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000229static inline _EGLDisplay *
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000230_eglLookupDisplay(EGLDisplay dpy)
Chia-I Wue3734e42009-08-14 18:05:19 +0800231{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000232 _EGLDisplay *disp = (_EGLDisplay *) dpy;
233 if (!_eglCheckDisplayHandle(dpy))
234 disp = NULL;
235 return disp;
Chia-I Wue3734e42009-08-14 18:05:19 +0800236}
237
238
239/**
240 * Return the handle of a linked display, or EGL_NO_DISPLAY.
241 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000242static inline EGLDisplay
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000243_eglGetDisplayHandle(_EGLDisplay *disp)
Chia-I Wue3734e42009-08-14 18:05:19 +0800244{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000245 return (EGLDisplay) ((disp) ? disp : EGL_NO_DISPLAY);
Chia-I Wue3734e42009-08-14 18:05:19 +0800246}
247
248
Chia-I Wu7abf4262010-01-24 20:30:04 +0800249extern void
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000250_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp);
Chia-I Wudc4f8452010-10-23 11:59:03 +0800251
252
Emil Velikovdd438ae2015-02-28 17:20:01 +0000253extern void
Chia-I Wudc4f8452010-10-23 11:59:03 +0800254_eglGetResource(_EGLResource *res);
255
256
Emil Velikovdd438ae2015-02-28 17:20:01 +0000257extern EGLBoolean
Chia-I Wudc4f8452010-10-23 11:59:03 +0800258_eglPutResource(_EGLResource *res);
259
260
261extern void
Chia-I Wu4ce33ec2010-10-23 00:37:19 +0800262_eglLinkResource(_EGLResource *res, _EGLResourceType type);
Chia-I Wu7abf4262010-01-24 20:30:04 +0800263
264
265extern void
266_eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
267
268
269/**
270 * Return true if the resource is linked.
271 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000272static inline EGLBoolean
Chia-I Wu7abf4262010-01-24 20:30:04 +0800273_eglIsResourceLinked(_EGLResource *res)
274{
Chia-I Wuf65ed0a2010-01-26 15:16:49 +0800275 return res->IsLinked;
Chia-I Wu7abf4262010-01-24 20:30:04 +0800276}
277
Emil Velikov72b9aa92019-05-16 18:01:33 +0100278static inline size_t
279_eglNumAttribs(const EGLAttrib *attribs)
280{
281 size_t len = 0;
282
283 if (attribs) {
284 while (attribs[len] != EGL_NONE)
285 len += 2;
286 len++;
287 }
288 return len;
289}
290
Chad Versace468cc862014-01-23 07:26:10 -0800291#ifdef HAVE_X11_PLATFORM
292_EGLDisplay*
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500293_eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
Chad Versace468cc862014-01-23 07:26:10 -0800294#endif
295
296#ifdef HAVE_DRM_PLATFORM
297struct gbm_device;
298
299_EGLDisplay*
300_eglGetGbmDisplay(struct gbm_device *native_display,
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500301 const EGLAttrib *attrib_list);
Chad Versace468cc862014-01-23 07:26:10 -0800302#endif
303
304#ifdef HAVE_WAYLAND_PLATFORM
305struct wl_display;
306
307_EGLDisplay*
308_eglGetWaylandDisplay(struct wl_display *native_display,
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500309 const EGLAttrib *attrib_list);
Chad Versace468cc862014-01-23 07:26:10 -0800310#endif
Chia-I Wu7abf4262010-01-24 20:30:04 +0800311
Chad Versacea597c8a2016-10-12 15:48:15 -0700312_EGLDisplay*
313_eglGetSurfacelessDisplay(void *native_display,
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500314 const EGLAttrib *attrib_list);
Alexander von Gluck IV83620682015-05-13 17:13:37 -0500315
renchenglei500b45a2019-06-28 15:21:08 +0800316#ifdef HAVE_ANDROID_PLATFORM
317_EGLDisplay*
318_eglGetAndroidDisplay(void *native_display,
319 const EGLAttrib *attrib_list);
320#endif
321
Emil Velikovd6edcce2019-05-16 18:01:40 +0100322_EGLDisplay*
323_eglGetDeviceDisplay(void *native_display,
324 const EGLAttrib *attrib_list);
325
Alexander von Gluck IV83620682015-05-13 17:13:37 -0500326#ifdef __cplusplus
327}
328#endif
329
Brian Pauladbff7e2005-04-22 21:09:39 +0000330#endif /* EGLDISPLAY_INCLUDED */