blob: b5c5e79c751b85a379e8b2171e2cd8ec1a1b5f92 [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/**
32 * Public EGL API entrypoints
33 *
34 * Generally, we use the EGLDisplay parameter as a key to lookup the
35 * appropriate device driver handle, then jump though the driver's
36 * dispatch table to handle the function.
37 *
38 * That allows us the option of supporting multiple, simultaneous,
39 * heterogeneous hardware devices in the future.
40 *
41 * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are
Chia-I Wuaaa12532009-09-30 15:08:34 +080042 * opaque handles. Internal objects are linked to a display to
43 * create the handles.
Brian Pauladbff7e2005-04-22 21:09:39 +000044 *
Chia-I Wuaaa12532009-09-30 15:08:34 +080045 * For each public API entry point, the opaque handles are looked up
46 * before being dispatched to the drivers. When it fails to look up
47 * a handle, one of
48 *
49 * EGL_BAD_DISPLAY
50 * EGL_BAD_CONFIG
51 * EGL_BAD_CONTEXT
52 * EGL_BAD_SURFACE
53 * EGL_BAD_SCREEN_MESA
54 * EGL_BAD_MODE_MESA
55 *
56 * is generated and the driver function is not called. An
57 * uninitialized EGLDisplay has no driver associated with it. When
58 * such display is detected,
59 *
60 * EGL_NOT_INITIALIZED
61 *
62 * is generated.
Brian Pauladbff7e2005-04-22 21:09:39 +000063 *
Chia-I Wubbfd0e22009-10-15 11:08:33 +080064 * Some of the entry points use current display, context, or surface
65 * implicitly. For such entry points, the implicit objects are also
66 * checked before calling the driver function. Other than the
67 * errors listed above,
68 *
69 * EGL_BAD_CURRENT_SURFACE
70 *
71 * may also be generated.
72 *
Brian Pauladbff7e2005-04-22 21:09:39 +000073 * Notes on naming conventions:
74 *
75 * eglFooBar - public EGL function
76 * EGL_FOO_BAR - public EGL token
77 * EGLDatatype - public EGL datatype
78 *
79 * _eglFooBar - private EGL function
80 * _EGLDatatype - private EGL datatype, typedef'd struct
81 * _egl_struct - private EGL struct, non-typedef'd
82 *
83 */
84
85
Eric Engestrom8d9c2042018-11-15 18:07:33 +000086#ifdef USE_LIBGLVND
87#define EGLAPI
88#undef PUBLIC
89#define PUBLIC
90#endif
91
Brian Pauladbff7e2005-04-22 21:09:39 +000092#include <stdio.h>
Brian Paulb2006a42006-01-30 00:10:55 +000093#include <stdlib.h>
Brian Pauladbff7e2005-04-22 21:09:39 +000094#include <string.h>
Emil Velikov7bd16932015-02-28 16:35:22 +000095#include "c99_compat.h"
Emil Velikovefe87f12015-03-06 16:54:55 +000096#include "c11/threads.h"
Emil Velikov239e7ee2017-05-04 18:55:36 +010097#include "util/macros.h"
Chia-I Wu1e6c10f2010-05-31 11:47:58 +080098
Eric Engestromd75fbff2018-05-16 14:17:30 +010099#include "egldefines.h"
Chad Versace3c58d4c2013-10-11 16:04:55 -0700100#include "eglglobals.h"
Brian Pauladbff7e2005-04-22 21:09:39 +0000101#include "eglcontext.h"
102#include "egldisplay.h"
103#include "egltypedefs.h"
Chia-I Wu94cb3212010-01-29 09:00:30 +0800104#include "eglcurrent.h"
Emil Velikov7552fcb2015-07-24 16:19:55 +0200105#include "egldevice.h"
Brian Pauladbff7e2005-04-22 21:09:39 +0000106#include "egldriver.h"
107#include "eglsurface.h"
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800108#include "eglconfig.h"
Chia-I Wua1c4a8a2009-08-15 22:58:13 +0800109#include "eglimage.h"
Chia-I Wu4eebea72010-08-14 23:09:12 +0800110#include "eglsync.h"
Brian Pauladbff7e2005-04-22 21:09:39 +0000111
Matt Turner4e970842017-07-06 18:40:53 -0700112#include "GL/mesa_glinterop.h"
Brian Pauladbff7e2005-04-22 21:09:39 +0000113
114/**
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800115 * Macros to help return an API entrypoint.
Chia-I Wu655f4652010-02-17 17:30:44 +0800116 *
117 * These macros will unlock the display and record the error code.
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800118 */
Chia-I Wubef4b472010-02-19 12:08:50 +0800119#define RETURN_EGL_ERROR(disp, err, ret) \
120 do { \
Chia-I Wu655f4652010-02-17 17:30:44 +0800121 if (disp) \
122 _eglUnlockDisplay(disp); \
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800123 /* EGL error codes are non-zero */ \
124 if (err) \
Emil Velikovd7800122015-02-28 16:39:10 +0000125 _eglError(err, __func__); \
Chia-I Wubef4b472010-02-19 12:08:50 +0800126 return ret; \
127 } while (0)
128
129#define RETURN_EGL_SUCCESS(disp, ret) \
130 RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret)
131
Chia-I Wub3bb1802010-02-17 16:05:27 +0800132/* record EGL_SUCCESS only when ret evaluates to true */
Chia-I Wubef4b472010-02-19 12:08:50 +0800133#define RETURN_EGL_EVAL(disp, ret) \
134 RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret)
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800135
136
Chia-I Wubef4b472010-02-19 12:08:50 +0800137/*
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800138 * A bunch of macros and checks to simplify error checking.
139 */
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800140
Chia-I Wubef4b472010-02-19 12:08:50 +0800141#define _EGL_CHECK_DISPLAY(disp, ret, drv) \
142 do { \
Emil Velikovd7800122015-02-28 16:39:10 +0000143 drv = _eglCheckDisplay(disp, __func__); \
Chia-I Wubef4b472010-02-19 12:08:50 +0800144 if (!drv) \
145 RETURN_EGL_ERROR(disp, 0, ret); \
146 } while (0)
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800147
Chia-I Wubef4b472010-02-19 12:08:50 +0800148#define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \
149 do { \
Emil Velikovd7800122015-02-28 16:39:10 +0000150 drv = _eglCheck ## type(disp, obj, __func__); \
Chia-I Wubef4b472010-02-19 12:08:50 +0800151 if (!drv) \
152 RETURN_EGL_ERROR(disp, 0, ret); \
153 } while (0)
154
155#define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \
156 _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv)
157
158#define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \
159 _EGL_CHECK_OBJECT(disp, Context, context, ret, drv)
160
161#define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \
162 _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv)
163
Chia-I Wu4eebea72010-08-14 23:09:12 +0800164#define _EGL_CHECK_SYNC(disp, s, ret, drv) \
165 _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800166
167
Eric Engestrom1534fc62017-02-21 23:56:52 +0000168struct _egl_entrypoint {
169 const char *name;
170 _EGLProc function;
171};
172
173
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200174static inline const _EGLDriver *
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800175_eglCheckDisplay(_EGLDisplay *disp, const char *msg)
176{
177 if (!disp) {
178 _eglError(EGL_BAD_DISPLAY, msg);
179 return NULL;
180 }
181 if (!disp->Initialized) {
182 _eglError(EGL_NOT_INITIALIZED, msg);
183 return NULL;
184 }
185 return disp->Driver;
186}
187
188
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200189static inline const _EGLDriver *
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800190_eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg)
191{
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200192 const _EGLDriver *drv = _eglCheckDisplay(disp, msg);
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800193 if (!drv)
194 return NULL;
195 if (!surf) {
196 _eglError(EGL_BAD_SURFACE, msg);
197 return NULL;
198 }
199 return drv;
200}
201
202
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200203static inline const _EGLDriver *
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800204_eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg)
205{
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200206 const _EGLDriver *drv = _eglCheckDisplay(disp, msg);
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800207 if (!drv)
208 return NULL;
209 if (!context) {
210 _eglError(EGL_BAD_CONTEXT, msg);
211 return NULL;
212 }
213 return drv;
214}
215
216
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200217static inline const _EGLDriver *
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800218_eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg)
219{
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200220 const _EGLDriver *drv = _eglCheckDisplay(disp, msg);
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800221 if (!drv)
222 return NULL;
223 if (!conf) {
224 _eglError(EGL_BAD_CONFIG, msg);
225 return NULL;
226 }
227 return drv;
228}
229
230
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200231static inline const _EGLDriver *
Chia-I Wu4eebea72010-08-14 23:09:12 +0800232_eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg)
233{
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200234 const _EGLDriver *drv = _eglCheckDisplay(disp, msg);
Chia-I Wu4eebea72010-08-14 23:09:12 +0800235 if (!drv)
236 return NULL;
237 if (!s) {
238 _eglError(EGL_BAD_PARAMETER, msg);
239 return NULL;
240 }
241 return drv;
242}
243
244
Chia-I Wuf3e03e12010-02-17 15:22:03 +0800245/**
Chia-I Wu655f4652010-02-17 17:30:44 +0800246 * Lookup and lock a display.
247 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000248static inline _EGLDisplay *
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000249_eglLockDisplay(EGLDisplay dpy)
Chia-I Wu655f4652010-02-17 17:30:44 +0800250{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000251 _EGLDisplay *disp = _eglLookupDisplay(dpy);
252 if (disp)
253 mtx_lock(&disp->Mutex);
254 return disp;
Chia-I Wu655f4652010-02-17 17:30:44 +0800255}
256
257
258/**
259 * Unlock a display.
260 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000261static inline void
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000262_eglUnlockDisplay(_EGLDisplay *disp)
Chia-I Wu655f4652010-02-17 17:30:44 +0800263{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000264 mtx_unlock(&disp->Mutex);
Chia-I Wu655f4652010-02-17 17:30:44 +0800265}
266
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400267static EGLBoolean
268_eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
269{
270 _EGLThreadInfo *thr = _eglGetCurrentThread();
271 if (!_eglIsCurrentThreadDummy()) {
272 thr->CurrentFuncName = funcName;
273 thr->CurrentObjectLabel = NULL;
274
275 if (objectType == EGL_OBJECT_THREAD_KHR)
276 thr->CurrentObjectLabel = thr->Label;
277 else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp)
278 thr->CurrentObjectLabel = disp->Label;
279 else if (object)
280 thr->CurrentObjectLabel = object->Label;
281
282 return EGL_TRUE;
283 }
284
Emil Velikovb94344f2017-09-07 17:03:50 +0100285 _eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400286 return EGL_FALSE;
287}
288
289#define _EGL_FUNC_START(disp, objectType, object, ret) \
290 do { \
291 if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
292 if (disp) \
293 _eglUnlockDisplay(disp); \
294 return ret; \
295 } \
296 } while(0)
Chia-I Wu655f4652010-02-17 17:30:44 +0800297
Chad Versace3e0d5752016-09-27 13:27:17 -0700298/**
299 * Convert an attribute list from EGLint[] to EGLAttrib[].
300 *
301 * Return an EGL error code. The output parameter out_attrib_list is modified
302 * only on success.
303 */
Eric Engestrom9e1d35c2016-12-08 00:36:03 +0000304static EGLint
Chad Versace3e0d5752016-09-27 13:27:17 -0700305_eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
306{
307 size_t len = 0;
308 EGLAttrib *attrib_list;
309
310 if (int_list) {
311 while (int_list[2*len] != EGL_NONE)
312 ++len;
313 }
314
315 if (len == 0) {
316 *out_attrib_list = NULL;
317 return EGL_SUCCESS;
318 }
319
320 if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib))
321 return EGL_BAD_ALLOC;
322
323 attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib));
324 if (!attrib_list)
325 return EGL_BAD_ALLOC;
326
327 for (size_t i = 0; i < len; ++i) {
328 attrib_list[2*i + 0] = int_list[2*i + 0];
329 attrib_list[2*i + 1] = int_list[2*i + 1];
330 }
331
332 attrib_list[2*len] = EGL_NONE;
333
334 *out_attrib_list = attrib_list;
335 return EGL_SUCCESS;
336}
337
338
Marek Olšák515f04e2015-05-12 20:42:05 +0200339static EGLint *
340_eglConvertAttribsToInt(const EGLAttrib *attr_list)
341{
Emil Velikov72b9aa92019-05-16 18:01:33 +0100342 size_t size = _eglNumAttribs(attr_list);
Marek Olšák515f04e2015-05-12 20:42:05 +0200343 EGLint *int_attribs = NULL;
344
345 /* Convert attributes from EGLAttrib[] to EGLint[] */
Emil Velikov72b9aa92019-05-16 18:01:33 +0100346 if (size) {
Marek Olšák515f04e2015-05-12 20:42:05 +0200347 int_attribs = calloc(size, sizeof(int_attribs[0]));
348 if (!int_attribs)
349 return NULL;
350
Emil Velikov72b9aa92019-05-16 18:01:33 +0100351 for (size_t i = 0; i < size; i++)
Marek Olšák515f04e2015-05-12 20:42:05 +0200352 int_attribs[i] = attr_list[i];
353 }
354 return int_attribs;
355}
356
357
Chia-I Wu655f4652010-02-17 17:30:44 +0800358/**
Brian Paul6052af12008-05-27 16:48:23 -0600359 * This is typically the first EGL function that an application calls.
Chia-I Wudb5ce8b2010-02-17 18:39:27 +0800360 * It associates a private _EGLDisplay object to the native display.
Brian Pauladbff7e2005-04-22 21:09:39 +0000361 */
Brian Paul1ed10272008-05-27 13:45:41 -0600362EGLDisplay EGLAPIENTRY
Chia-I Wu4aed0942010-01-25 11:55:48 +0800363eglGetDisplay(EGLNativeDisplayType nativeDisplay)
Brian Pauladbff7e2005-04-22 21:09:39 +0000364{
Chad Versace6d1f83e2014-01-07 14:54:51 -0800365 _EGLPlatformType plat;
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000366 _EGLDisplay *disp;
Chad Versace6d1f83e2014-01-07 14:54:51 -0800367 void *native_display_ptr;
368
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400369 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
370
Chad Versace6d1f83e2014-01-07 14:54:51 -0800371 STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay));
372 native_display_ptr = (void*) nativeDisplay;
373
374 plat = _eglGetNativePlatform(native_display_ptr);
Adam Jackson8e991ce2019-05-16 18:01:34 +0100375 disp = _eglFindDisplay(plat, native_display_ptr, NULL);
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000376 return _eglGetDisplayHandle(disp);
Brian Pauladbff7e2005-04-22 21:09:39 +0000377}
378
Kyle Brenneman017946b2016-09-12 16:42:56 -0400379static EGLDisplay
380_eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500381 const EGLAttrib *attrib_list)
Chad Versace468cc862014-01-23 07:26:10 -0800382{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000383 _EGLDisplay *disp;
Chad Versace468cc862014-01-23 07:26:10 -0800384
385 switch (platform) {
386#ifdef HAVE_X11_PLATFORM
387 case EGL_PLATFORM_X11_EXT:
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000388 disp = _eglGetX11Display((Display*) native_display, attrib_list);
Chad Versace468cc862014-01-23 07:26:10 -0800389 break;
390#endif
391#ifdef HAVE_DRM_PLATFORM
392 case EGL_PLATFORM_GBM_MESA:
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000393 disp = _eglGetGbmDisplay((struct gbm_device*) native_display,
Chad Versace468cc862014-01-23 07:26:10 -0800394 attrib_list);
395 break;
396#endif
397#ifdef HAVE_WAYLAND_PLATFORM
398 case EGL_PLATFORM_WAYLAND_EXT:
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000399 disp = _eglGetWaylandDisplay((struct wl_display*) native_display,
Chad Versace468cc862014-01-23 07:26:10 -0800400 attrib_list);
401 break;
402#endif
Chad Versacea597c8a2016-10-12 15:48:15 -0700403 case EGL_PLATFORM_SURFACELESS_MESA:
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000404 disp = _eglGetSurfacelessDisplay(native_display, attrib_list);
Chad Versacea597c8a2016-10-12 15:48:15 -0700405 break;
renchenglei500b45a2019-06-28 15:21:08 +0800406#ifdef HAVE_ANDROID_PLATFORM
407 case EGL_PLATFORM_ANDROID_KHR:
408 disp = _eglGetAndroidDisplay(native_display, attrib_list);
409 break;
410#endif
Emil Velikovd6edcce2019-05-16 18:01:40 +0100411 case EGL_PLATFORM_DEVICE_EXT:
412 disp = _eglGetDeviceDisplay(native_display, attrib_list);
413 break;
Chad Versace468cc862014-01-23 07:26:10 -0800414 default:
415 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
416 }
417
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000418 return _eglGetDisplayHandle(disp);
Chad Versace468cc862014-01-23 07:26:10 -0800419}
Brian Pauladbff7e2005-04-22 21:09:39 +0000420
Kyle Brenneman017946b2016-09-12 16:42:56 -0400421static EGLDisplay EGLAPIENTRY
422eglGetPlatformDisplayEXT(EGLenum platform, void *native_display,
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500423 const EGLint *int_attribs)
Kyle Brenneman017946b2016-09-12 16:42:56 -0400424{
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500425 EGLAttrib *attrib_list;
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000426 EGLDisplay disp;
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500427
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400428 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500429
430 if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS)
431 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
432
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000433 disp = _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500434 free(attrib_list);
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000435 return disp;
Kyle Brenneman017946b2016-09-12 16:42:56 -0400436}
437
Marek Olšák820a4d42015-05-12 21:06:41 +0200438EGLDisplay EGLAPIENTRY
439eglGetPlatformDisplay(EGLenum platform, void *native_display,
440 const EGLAttrib *attrib_list)
441{
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400442 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY);
Adam Jacksonddcd4b02017-11-16 13:27:27 -0500443 return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list);
Marek Olšák820a4d42015-05-12 21:06:41 +0200444}
445
Brian Paul6052af12008-05-27 16:48:23 -0600446/**
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700447 * Copy the extension into the string and update the string pointer.
448 */
449static EGLint
450_eglAppendExtension(char **str, const char *ext)
451{
452 char *s = *str;
453 size_t len = strlen(ext);
454
455 if (s) {
456 memcpy(s, ext, len);
457 s[len++] = ' ';
458 s[len] = '\0';
459
460 *str += len;
461 }
462 else {
463 len++;
464 }
465
466 return (EGLint) len;
467}
468
469/**
470 * Examine the individual extension enable/disable flags and recompute
471 * the driver's Extensions string.
472 */
473static void
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000474_eglCreateExtensionsString(_EGLDisplay *disp)
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700475{
476#define _EGL_CHECK_EXTENSION(ext) \
477 do { \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000478 if (disp->Extensions.ext) { \
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700479 _eglAppendExtension(&exts, "EGL_" #ext); \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000480 assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700481 } \
482 } while (0)
483
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000484 char *exts = disp->ExtensionsString;
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700485
Marek Olšák32aa1d72015-06-09 23:08:57 +0200486 /* Please keep these sorted alphabetically. */
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200487 _EGL_CHECK_EXTENSION(ANDROID_blob_cache);
Rob Herring89755272016-02-02 14:23:07 -0600488 _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target);
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700489 _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
Rob Clark0201f012016-11-18 08:39:33 -0500490 _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync);
Rob Herringe21e81a2016-02-02 14:23:08 -0600491 _EGL_CHECK_EXTENSION(ANDROID_recordable);
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700492
493 _EGL_CHECK_EXTENSION(CHROMIUM_sync_control);
494
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700495 _EGL_CHECK_EXTENSION(EXT_buffer_age);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200496 _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700497 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
Varad Gautam4c412292017-05-30 17:23:40 +0530498 _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
Tapani Pälli799b3d12018-04-05 13:02:36 +0300499 _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata);
500 _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200501 _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
502
Chris Wilson95ecf3d2016-10-27 19:34:46 +0100503 _EGL_CHECK_EXTENSION(IMG_context_priority);
504
Marek Olšák32aa1d72015-06-09 23:08:57 +0200505 _EGL_CHECK_EXTENSION(KHR_cl_event2);
Emil Velikov26541a12016-12-05 14:42:04 +0000506 _EGL_CHECK_EXTENSION(KHR_config_attribs);
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400507 _EGL_CHECK_EXTENSION(KHR_context_flush_control);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200508 _EGL_CHECK_EXTENSION(KHR_create_context);
Grigori Goronzy49095192017-06-29 02:44:03 +0200509 _EGL_CHECK_EXTENSION(KHR_create_context_no_error);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200510 _EGL_CHECK_EXTENSION(KHR_fence_sync);
511 _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses);
512 _EGL_CHECK_EXTENSION(KHR_gl_colorspace);
513 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
514 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
515 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
516 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000517 if (disp->Extensions.KHR_image_base && disp->Extensions.KHR_image_pixmap)
518 disp->Extensions.KHR_image = EGL_TRUE;
Harish Krupo96fc5fb2017-12-08 21:29:39 +0530519 _EGL_CHECK_EXTENSION(KHR_image);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200520 _EGL_CHECK_EXTENSION(KHR_image_base);
521 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
Chad Versace3dc22382018-04-30 22:32:25 -0700522 _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer);
Adam Jacksond9f5b192016-09-09 12:25:34 -0400523 _EGL_CHECK_EXTENSION(KHR_no_config_context);
Harish Krupo98275472017-06-09 20:13:34 +0530524 _EGL_CHECK_EXTENSION(KHR_partial_update);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200525 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
526 _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000527 if (disp->Extensions.EXT_swap_buffers_with_damage)
Eric Engestrom0a606a42016-10-10 17:33:17 +0100528 _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage");
Tapani Pälli41f7de42017-10-31 10:57:42 +0200529 _EGL_CHECK_EXTENSION(EXT_pixel_format_float);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200530 _EGL_CHECK_EXTENSION(KHR_wait_sync);
531
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000532 if (disp->Extensions.KHR_no_config_context)
Adam Jacksond9f5b192016-09-09 12:25:34 -0400533 _eglAppendExtension(&exts, "EGL_MESA_configless_context");
Marek Olšák32aa1d72015-06-09 23:08:57 +0200534 _EGL_CHECK_EXTENSION(MESA_drm_image);
535 _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
Veluri Mithun6afce782019-01-23 22:44:25 +0530536 _EGL_CHECK_EXTENSION(MESA_query_driver);
Marek Olšák32aa1d72015-06-09 23:08:57 +0200537
538 _EGL_CHECK_EXTENSION(NOK_swap_region);
539 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700540
541 _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
Dave Airlie8f7338f2014-03-03 13:57:16 +1000542
Marek Olšák32aa1d72015-06-09 23:08:57 +0200543 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
544 _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
545
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700546#undef _EGL_CHECK_EXTENSION
547}
548
549static void
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000550_eglCreateAPIsString(_EGLDisplay *disp)
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700551{
Eric Engestromaa78b292018-08-16 15:31:55 +0100552#define addstr(str) \
553 { \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000554 const size_t old_len = strlen(disp->ClientAPIsString); \
Eric Engestromaa78b292018-08-16 15:31:55 +0100555 const size_t add_len = sizeof(str); \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000556 const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \
Eric Engestromaa78b292018-08-16 15:31:55 +0100557 if (old_len + add_len <= max_len) \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000558 strcat(disp->ClientAPIsString, str " "); \
Eric Engestromaa78b292018-08-16 15:31:55 +0100559 else \
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000560 assert(!"disp->ClientAPIsString is not large enough"); \
Eric Engestromaa78b292018-08-16 15:31:55 +0100561 }
562
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000563 if (disp->ClientAPIs & EGL_OPENGL_BIT)
Eric Engestromaa78b292018-08-16 15:31:55 +0100564 addstr("OpenGL");
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700565
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000566 if (disp->ClientAPIs & EGL_OPENGL_ES_BIT ||
567 disp->ClientAPIs & EGL_OPENGL_ES2_BIT ||
568 disp->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) {
Eric Engestromaa78b292018-08-16 15:31:55 +0100569 addstr("OpenGL_ES");
Plamena Manolova21edd242016-05-12 18:21:38 +0100570 }
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700571
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000572 if (disp->ClientAPIs & EGL_OPENVG_BIT)
Eric Engestromaa78b292018-08-16 15:31:55 +0100573 addstr("OpenVG");
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700574
Eric Engestromaa78b292018-08-16 15:31:55 +0100575#undef addstr
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700576}
577
Marek Olšákefda9c52015-05-11 22:16:52 +0200578static void
579_eglComputeVersion(_EGLDisplay *disp)
580{
Marek Olšák0e4b5642015-05-12 16:40:29 +0200581 disp->Version = 14;
Marek Olšáka1cb4072015-05-11 22:18:04 +0200582
583 if (disp->Extensions.KHR_fence_sync &&
584 disp->Extensions.KHR_cl_event2 &&
585 disp->Extensions.KHR_wait_sync &&
586 disp->Extensions.KHR_image_base &&
587 disp->Extensions.KHR_gl_texture_2D_image &&
588 disp->Extensions.KHR_gl_texture_3D_image &&
589 disp->Extensions.KHR_gl_texture_cubemap_image &&
590 disp->Extensions.KHR_gl_renderbuffer_image &&
591 disp->Extensions.KHR_create_context &&
592 disp->Extensions.EXT_create_context_robustness &&
593 disp->Extensions.KHR_get_all_proc_addresses &&
594 disp->Extensions.KHR_gl_colorspace &&
595 disp->Extensions.KHR_surfaceless_context)
596 disp->Version = 15;
Abhishek Kumar0bea2a12020-05-07 22:02:02 +0530597
598 /* For Android P and below limit the EGL version to 1.4 */
599#if defined(ANDROID) && ANDROID_API_LEVEL <= 28
600 disp->Version = 14;
601#endif
Marek Olšákefda9c52015-05-11 22:16:52 +0200602}
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700603
604/**
Brian Paul6052af12008-05-27 16:48:23 -0600605 * This is typically the second EGL function that an application calls.
606 * Here we load/initialize the actual hardware driver.
607 */
Brian Paul1ed10272008-05-27 13:45:41 -0600608EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +0000609eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
610{
Chia-I Wu655f4652010-02-17 17:30:44 +0800611 _EGLDisplay *disp = _eglLockDisplay(dpy);
Jonathan White7e2458c2008-08-06 13:40:03 -0600612
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400613 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
614
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800615 if (!disp)
Chia-I Wubef4b472010-02-19 12:08:50 +0800616 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
Brian Paulc56e15b2008-05-28 15:43:41 -0600617
Chia-I Wua9332592010-01-27 23:55:58 +0800618 if (!disp->Initialized) {
Eric Engestromed3f1e02020-07-22 01:19:03 +0200619 if (!_eglInitializeDisplay(disp))
Chia-I Wuf2aa3612010-07-04 15:55:12 +0800620 RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
Chia-I Wu57929ed2010-01-19 18:29:21 +0800621
Chia-I Wu310c7682009-08-17 15:53:54 +0800622 /* limit to APIs supported by core */
Chia-I Wua4a38dc2011-01-13 16:53:13 +0800623 disp->ClientAPIs &= _EGL_API_ALL_BITS;
Chad Versace7e8ba772014-11-20 10:26:38 -0800624
625 /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec
626 * classifies it as an EGL display extension, though conceptually it's an
627 * EGL client extension.
628 *
629 * From the EGL_KHR_get_all_proc_addresses spec:
630 *
631 * The EGL implementation must expose the name
632 * EGL_KHR_client_get_all_proc_addresses if and only if it exposes
633 * EGL_KHR_get_all_proc_addresses and supports
634 * EGL_EXT_client_extensions.
635 *
636 * Mesa unconditionally exposes both client extensions mentioned above,
637 * so the spec requires that each EGLDisplay unconditionally expose
638 * EGL_KHR_get_all_proc_addresses also.
639 */
640 disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE;
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700641
Emil Velikov26541a12016-12-05 14:42:04 +0000642 /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware
643 * programs. It is driver agnostic and handled in the main EGL code.
644 */
645 disp->Extensions.KHR_config_attribs = EGL_TRUE;
646
Marek Olšákefda9c52015-05-11 22:16:52 +0200647 _eglComputeVersion(disp);
Matt Turnerdac2e7d2015-03-10 11:41:57 -0700648 _eglCreateExtensionsString(disp);
649 _eglCreateAPIsString(disp);
Emil Velikov3593f372015-07-14 00:19:54 +0100650 snprintf(disp->VersionString, sizeof(disp->VersionString),
Eric Engestroma96749b2017-10-18 16:32:33 +0100651 "%d.%d", disp->Version / 10, disp->Version % 10);
Brian Pauladbff7e2005-04-22 21:09:39 +0000652 }
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800653
654 /* Update applications version of major and minor if not NULL */
655 if ((major != NULL) && (minor != NULL)) {
Marek Olšák0e4b5642015-05-12 16:40:29 +0200656 *major = disp->Version / 10;
657 *minor = disp->Version % 10;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800658 }
659
Chia-I Wubef4b472010-02-19 12:08:50 +0800660 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
Brian Pauladbff7e2005-04-22 21:09:39 +0000661}
662
663
Brian Paul1ed10272008-05-27 13:45:41 -0600664EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +0000665eglTerminate(EGLDisplay dpy)
666{
Chia-I Wu655f4652010-02-17 17:30:44 +0800667 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800668
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400669 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
670
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800671 if (!disp)
Chia-I Wubef4b472010-02-19 12:08:50 +0800672 RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800673
Chia-I Wua9332592010-01-27 23:55:58 +0800674 if (disp->Initialized) {
Eric Engestrom435ad512018-04-22 16:48:15 +0200675 disp->Driver->Terminate(disp);
Chia-I Wua9332592010-01-27 23:55:58 +0800676 /* do not reset disp->Driver */
Dave Airlie37e3a112015-03-16 15:21:55 +1000677 disp->ClientAPIsString[0] = 0;
Chia-I Wua9332592010-01-27 23:55:58 +0800678 disp->Initialized = EGL_FALSE;
Tapani Pälli3e03a3f2019-08-22 10:49:36 +0300679
680 /* Reset blob cache funcs on terminate. */
681 disp->BlobCacheSet = NULL;
682 disp->BlobCacheGet = NULL;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800683 }
684
Chia-I Wubef4b472010-02-19 12:08:50 +0800685 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
Brian Pauladbff7e2005-04-22 21:09:39 +0000686}
687
688
Brian Paul1ed10272008-05-27 13:45:41 -0600689const char * EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +0000690eglQueryString(EGLDisplay dpy, EGLint name)
691{
Chad Versace3c58d4c2013-10-11 16:04:55 -0700692 _EGLDisplay *disp;
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200693 const _EGLDriver *drv;
Chia-I Wuaed73582010-02-17 15:43:47 +0800694
Emil Velikov0a884d72020-04-08 11:46:47 +0100695#if !USE_LIBGLVND
Chad Versace3c58d4c2013-10-11 16:04:55 -0700696 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {
Emil Velikov0a884d72020-04-08 11:46:47 +0100697 RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString);
Chad Versace3c58d4c2013-10-11 16:04:55 -0700698 }
Emil Velikov0a884d72020-04-08 11:46:47 +0100699#endif
Chad Versace3c58d4c2013-10-11 16:04:55 -0700700
701 disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400702 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL);
Chia-I Wubef4b472010-02-19 12:08:50 +0800703 _EGL_CHECK_DISPLAY(disp, NULL, drv);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800704
Matt Turner6c6e2a12015-03-13 17:00:26 -0700705 switch (name) {
706 case EGL_VENDOR:
707 RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING);
708 case EGL_VERSION:
709 RETURN_EGL_SUCCESS(disp, disp->VersionString);
710 case EGL_EXTENSIONS:
711 RETURN_EGL_SUCCESS(disp, disp->ExtensionsString);
712 case EGL_CLIENT_APIS:
713 RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString);
714 default:
715 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
716 }
Brian Pauladbff7e2005-04-22 21:09:39 +0000717}
718
719
Brian Paul1ed10272008-05-27 13:45:41 -0600720EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800721eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
722 EGLint config_size, EGLint *num_config)
Brian Pauladbff7e2005-04-22 21:09:39 +0000723{
Chia-I Wu655f4652010-02-17 17:30:44 +0800724 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200725 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800726 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +0800727
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400728 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
729
Chia-I Wubef4b472010-02-19 12:08:50 +0800730 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
Eric Engestrom64c7c052019-01-08 11:14:35 +0000731
732 if (!num_config)
733 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
734
Eric Engestromeeacd662019-06-14 16:08:44 +0100735 ret = _eglGetConfigs(drv, disp, configs, config_size, num_config);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800736
Chia-I Wubef4b472010-02-19 12:08:50 +0800737 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000738}
739
740
Brian Paul1ed10272008-05-27 13:45:41 -0600741EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800742eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
743 EGLint config_size, EGLint *num_config)
Brian Pauladbff7e2005-04-22 21:09:39 +0000744{
Chia-I Wu655f4652010-02-17 17:30:44 +0800745 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200746 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800747 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +0800748
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400749 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
750
Chia-I Wubef4b472010-02-19 12:08:50 +0800751 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
Eric Engestrom64c7c052019-01-08 11:14:35 +0000752
753 if (!num_config)
754 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
755
Eric Engestromeeacd662019-06-14 16:08:44 +0100756 ret = _eglChooseConfig(drv, disp, attrib_list, configs,
757 config_size, num_config);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800758
Chia-I Wubef4b472010-02-19 12:08:50 +0800759 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000760}
761
762
Brian Paul1ed10272008-05-27 13:45:41 -0600763EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800764eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
765 EGLint attribute, EGLint *value)
Brian Pauladbff7e2005-04-22 21:09:39 +0000766{
Chia-I Wu655f4652010-02-17 17:30:44 +0800767 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800768 _EGLConfig *conf = _eglLookupConfig(config, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200769 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800770 EGLBoolean ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800771
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400772 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
773
Chia-I Wubef4b472010-02-19 12:08:50 +0800774 _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv);
Eric Engestrom7f848f92019-06-22 22:31:00 +0100775
Eric Engestromeeacd662019-06-14 16:08:44 +0100776 ret = _eglGetConfigAttrib(drv, disp, conf, attribute, value);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800777
Chia-I Wubef4b472010-02-19 12:08:50 +0800778 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000779}
780
781
Brian Paul1ed10272008-05-27 13:45:41 -0600782EGLContext EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800783eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
784 const EGLint *attrib_list)
Brian Pauladbff7e2005-04-22 21:09:39 +0000785{
Chia-I Wu655f4652010-02-17 17:30:44 +0800786 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800787 _EGLConfig *conf = _eglLookupConfig(config, disp);
788 _EGLContext *share = _eglLookupContext(share_list, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200789 const _EGLDriver *drv;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800790 _EGLContext *context;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800791 EGLContext ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800792
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400793 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT);
794
Chia-I Wu6b2f1562010-09-24 02:42:15 +0800795 _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv);
796
Tapani Pälli5876f3c2016-10-20 14:11:16 +0300797 if (config != EGL_NO_CONFIG_KHR)
798 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT, drv);
799 else if (!disp->Extensions.KHR_no_config_context)
Neil Roberts4b17dff2014-03-07 18:05:46 +0000800 RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT);
Kristian Høgsbergb90a3e72010-06-02 22:48:06 -0400801
Chia-I Wub3bb1802010-02-17 16:05:27 +0800802 if (!share && share_list != EGL_NO_CONTEXT)
Chia-I Wubef4b472010-02-19 12:08:50 +0800803 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800804
Eric Engestromcc034482020-07-20 13:38:24 +0200805 context = drv->CreateContext(drv, disp, conf, share, attrib_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +0800806 ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800807
Chia-I Wubef4b472010-02-19 12:08:50 +0800808 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000809}
810
811
Brian Paul1ed10272008-05-27 13:45:41 -0600812EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +0000813eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
814{
Chia-I Wu655f4652010-02-17 17:30:44 +0800815 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +0800816 _EGLContext *context = _eglLookupContext(ctx, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200817 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800818 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +0800819
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400820 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
821
Chia-I Wubef4b472010-02-19 12:08:50 +0800822 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800823 _eglUnlinkContext(context);
Eric Engestromcc034482020-07-20 13:38:24 +0200824 ret = drv->DestroyContext(drv, disp, context);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800825
Chia-I Wubef4b472010-02-19 12:08:50 +0800826 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000827}
828
829
Brian Paul1ed10272008-05-27 13:45:41 -0600830EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800831eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
832 EGLContext ctx)
Brian Pauladbff7e2005-04-22 21:09:39 +0000833{
Chia-I Wu655f4652010-02-17 17:30:44 +0800834 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800835 _EGLContext *context = _eglLookupContext(ctx, disp);
836 _EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
837 _EGLSurface *read_surf = _eglLookupSurface(read, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200838 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800839 EGLBoolean ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800840
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400841 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
842
Chia-I Wu17330472010-01-27 23:51:54 +0800843 if (!disp)
Chia-I Wubef4b472010-02-19 12:08:50 +0800844 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
Chia-I Wu17330472010-01-27 23:51:54 +0800845 drv = disp->Driver;
846
847 /* display is allowed to be uninitialized under certain condition */
848 if (!disp->Initialized) {
849 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE ||
850 ctx != EGL_NO_CONTEXT)
Chia-I Wubef4b472010-02-19 12:08:50 +0800851 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE);
Chia-I Wu17330472010-01-27 23:51:54 +0800852 }
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800853 if (!drv)
Chia-I Wubef4b472010-02-19 12:08:50 +0800854 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
Chia-I Wu17330472010-01-27 23:51:54 +0800855
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800856 if (!context && ctx != EGL_NO_CONTEXT)
Chia-I Wubef4b472010-02-19 12:08:50 +0800857 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
Chia-I Wu6b2f1562010-09-24 02:42:15 +0800858 if (!draw_surf || !read_surf) {
Beren Minor0ca0d572014-03-20 08:36:34 +0100859 /* From the EGL 1.4 (20130211) spec:
860 *
861 * To release the current context without assigning a new one, set ctx
862 * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE.
863 */
864 if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT)
Chia-I Wu6b2f1562010-09-24 02:42:15 +0800865 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
866
867 if ((!draw_surf && draw != EGL_NO_SURFACE) ||
868 (!read_surf && read != EGL_NO_SURFACE))
869 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
870 if (draw_surf || read_surf)
871 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
872 }
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800873
Chad Versace23c86c72017-05-04 17:46:33 -0700874 /* If a native window underlying either draw or read is no longer valid,
875 * an EGL_BAD_NATIVE_WINDOW error is generated.
876 */
877 if (draw_surf && draw_surf->Lost)
878 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
879 if (read_surf && read_surf->Lost)
880 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
881
Eric Engestromcc034482020-07-20 13:38:24 +0200882 ret = drv->MakeCurrent(drv, disp, draw_surf, read_surf, context);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800883
Chia-I Wubef4b472010-02-19 12:08:50 +0800884 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000885}
886
887
Brian Paul1ed10272008-05-27 13:45:41 -0600888EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800889eglQueryContext(EGLDisplay dpy, EGLContext ctx,
890 EGLint attribute, EGLint *value)
Brian Pauladbff7e2005-04-22 21:09:39 +0000891{
Chia-I Wu655f4652010-02-17 17:30:44 +0800892 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +0800893 _EGLContext *context = _eglLookupContext(ctx, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200894 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +0800895 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +0800896
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400897 _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE);
898
Chia-I Wubef4b472010-02-19 12:08:50 +0800899 _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv);
Eric Engestromb792b3e2019-06-22 22:31:26 +0100900
Eric Engestromeeacd662019-06-14 16:08:44 +0100901 ret = _eglQueryContext(drv, disp, context, attribute, value);
Chia-I Wub3bb1802010-02-17 16:05:27 +0800902
Chia-I Wubef4b472010-02-19 12:08:50 +0800903 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +0000904}
905
906
Paulo Zanoni73055ae2019-05-01 16:26:47 -0700907/* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says
908 * that if native_surface was already used to create a window or pixmap, we
909 * can't create a new one. This is what this function checks for.
910 */
911static bool
912_eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface)
913{
914 _EGLResource *list;
915
916 list = disp->ResourceLists[_EGL_RESOURCE_SURFACE];
917 while (list) {
918 _EGLSurface *surf = (_EGLSurface *) list;
919
920 list = list->Next;
921
922 if (surf->Type == EGL_PBUFFER_BIT)
923 continue;
924
925 if (surf->NativeSurface == native_surface)
926 return true;
927 }
928
929 return false;
930}
931
932
Chad Versace468cc862014-01-23 07:26:10 -0800933static EGLSurface
934_eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
935 void *native_window, const EGLint *attrib_list)
936{
937 _EGLConfig *conf = _eglLookupConfig(config, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200938 const _EGLDriver *drv;
Chad Versace468cc862014-01-23 07:26:10 -0800939 _EGLSurface *surf;
940 EGLSurface ret;
941
Sinclair Yeh91ff0d42014-06-03 14:00:13 -0700942
943 if (native_window == NULL)
944 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
945
Emil Velikovd6edcce2019-05-16 18:01:40 +0100946 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
947 disp->Platform == _EGL_PLATFORM_DEVICE)) {
Chad Versacea597c8a2016-10-12 15:48:15 -0700948 /* From the EGL_MESA_platform_surfaceless spec (v1):
949 *
950 * eglCreatePlatformWindowSurface fails when called with a <display>
951 * that belongs to the surfaceless platform. It returns
952 * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
953 * justification for this unconditional failure is that the
954 * surfaceless platform has no native windows, and therefore the
955 * <native_window> parameter is always invalid.
956 *
957 * This check must occur before checking the EGLConfig, which emits
958 * EGL_BAD_CONFIG.
959 */
960 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
961 }
Chad Versacea597c8a2016-10-12 15:48:15 -0700962
963 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
964
Chad Versacefbb4af92016-12-16 11:00:13 -0800965 if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0)
966 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
967
Paulo Zanoni73055ae2019-05-01 16:26:47 -0700968 if (_eglNativeSurfaceAlreadyUsed(disp, native_window))
969 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
970
Eric Engestromcc034482020-07-20 13:38:24 +0200971 surf = drv->CreateWindowSurface(drv, disp, conf, native_window,
Chad Versace468cc862014-01-23 07:26:10 -0800972 attrib_list);
973 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
974
975 RETURN_EGL_EVAL(disp, ret);
976}
977
978
Brian Paul1ed10272008-05-27 13:45:41 -0600979EGLSurface EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +0800980eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
Chia-I Wu4aed0942010-01-25 11:55:48 +0800981 EGLNativeWindowType window, const EGLint *attrib_list)
Brian Pauladbff7e2005-04-22 21:09:39 +0000982{
Chia-I Wu655f4652010-02-17 17:30:44 +0800983 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -0400984
985 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
Chad Versace468cc862014-01-23 07:26:10 -0800986 STATIC_ASSERT(sizeof(void*) == sizeof(window));
987 return _eglCreateWindowSurfaceCommon(disp, config, (void*) window,
988 attrib_list);
989}
990
Kyle Brenneman7d7ae5e2016-09-12 17:04:38 -0400991static void *
Eric Engestrom4729e1b2016-12-08 00:36:02 +0000992_fixupNativeWindow(_EGLDisplay *disp, void *native_window)
Chad Versace468cc862014-01-23 07:26:10 -0800993{
Chad Versace468cc862014-01-23 07:26:10 -0800994#ifdef HAVE_X11_PLATFORM
Emil Velikov26fbb9e2017-08-08 15:55:36 +0100995 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
Chad Versace468cc862014-01-23 07:26:10 -0800996 /* The `native_window` parameter for the X11 platform differs between
997 * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
998 * eglCreateWindowSurface(), the type of `native_window` is an Xlib
999 * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
1000 * `Window*`. Convert `Window*` to `Window` because that's what
1001 * dri2_x11_create_window_surface() expects.
1002 */
Kyle Brenneman7d7ae5e2016-09-12 17:04:38 -04001003 return (void *)(* (Window*) native_window);
Chad Versace468cc862014-01-23 07:26:10 -08001004 }
1005#endif
Kyle Brenneman7d7ae5e2016-09-12 17:04:38 -04001006 return native_window;
1007}
1008
1009static EGLSurface EGLAPIENTRY
1010eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
1011 void *native_window,
1012 const EGLint *attrib_list)
1013{
1014 _EGLDisplay *disp = _eglLockDisplay(dpy);
1015
Eric Engestrom4729e1b2016-12-08 00:36:02 +00001016 native_window = _fixupNativeWindow(disp, native_window);
Chad Versace468cc862014-01-23 07:26:10 -08001017
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001018 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
Chad Versace468cc862014-01-23 07:26:10 -08001019 return _eglCreateWindowSurfaceCommon(disp, config, native_window,
1020 attrib_list);
1021}
1022
1023
Marek Olšák820a4d42015-05-12 21:06:41 +02001024EGLSurface EGLAPIENTRY
1025eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
1026 void *native_window,
1027 const EGLAttrib *attrib_list)
1028{
Kyle Brenneman7d7ae5e2016-09-12 17:04:38 -04001029 _EGLDisplay *disp = _eglLockDisplay(dpy);
Marek Olšák820a4d42015-05-12 21:06:41 +02001030 EGLSurface surface;
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001031 EGLint *int_attribs;
Marek Olšák820a4d42015-05-12 21:06:41 +02001032
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001033 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1034
1035 int_attribs = _eglConvertAttribsToInt(attrib_list);
Marek Olšák820a4d42015-05-12 21:06:41 +02001036 if (attrib_list && !int_attribs)
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001037 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
Marek Olšák820a4d42015-05-12 21:06:41 +02001038
Eric Engestrom4729e1b2016-12-08 00:36:02 +00001039 native_window = _fixupNativeWindow(disp, native_window);
Kyle Brenneman7d7ae5e2016-09-12 17:04:38 -04001040 surface = _eglCreateWindowSurfaceCommon(disp, config, native_window,
1041 int_attribs);
Marek Olšák820a4d42015-05-12 21:06:41 +02001042 free(int_attribs);
1043 return surface;
1044}
1045
Kyle Brenneman8cc3d982016-09-12 17:25:56 -04001046static void *
Eric Engestrom4729e1b2016-12-08 00:36:02 +00001047_fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
Kyle Brenneman8cc3d982016-09-12 17:25:56 -04001048{
1049#ifdef HAVE_X11_PLATFORM
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01001050 /* The `native_pixmap` parameter for the X11 platform differs between
1051 * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
1052 * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
1053 * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
1054 * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what
1055 * dri2_x11_create_pixmap_surface() expects.
1056 */
Emil Velikov26fbb9e2017-08-08 15:55:36 +01001057 if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
Kyle Brenneman8cc3d982016-09-12 17:25:56 -04001058 return (void *)(* (Pixmap*) native_pixmap);
1059#endif
1060 return native_pixmap;
1061}
Marek Olšák820a4d42015-05-12 21:06:41 +02001062
Chad Versace468cc862014-01-23 07:26:10 -08001063static EGLSurface
1064_eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
1065 void *native_pixmap, const EGLint *attrib_list)
1066{
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001067 _EGLConfig *conf = _eglLookupConfig(config, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001068 const _EGLDriver *drv;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001069 _EGLSurface *surf;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001070 EGLSurface ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001071
Emil Velikovd6edcce2019-05-16 18:01:40 +01001072 if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
1073 disp->Platform == _EGL_PLATFORM_DEVICE)) {
Chad Versacea597c8a2016-10-12 15:48:15 -07001074 /* From the EGL_MESA_platform_surfaceless spec (v1):
1075 *
1076 * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
1077 * also fails when called with a <display> that belongs to the
1078 * surfaceless platform. It returns EGL_NO_SURFACE and generates
1079 * EGL_BAD_NATIVE_PIXMAP.
1080 *
1081 * This check must occur before checking the EGLConfig, which emits
1082 * EGL_BAD_CONFIG.
1083 */
1084 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1085 }
Chad Versacea597c8a2016-10-12 15:48:15 -07001086
Chia-I Wubef4b472010-02-19 12:08:50 +08001087 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
Chad Versacefbb4af92016-12-16 11:00:13 -08001088
1089 if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0)
1090 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1091
Emil Velikovdf8efd52017-08-05 00:25:48 +01001092 if (native_pixmap == NULL)
1093 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
1094
Paulo Zanoni73055ae2019-05-01 16:26:47 -07001095 if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap))
1096 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
1097
Eric Engestromcc034482020-07-20 13:38:24 +02001098 surf = drv->CreatePixmapSurface(drv, disp, conf, native_pixmap,
Chad Versace6d1f83e2014-01-07 14:54:51 -08001099 attrib_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +08001100 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001101
Chia-I Wubef4b472010-02-19 12:08:50 +08001102 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001103}
1104
1105
Brian Paul1ed10272008-05-27 13:45:41 -06001106EGLSurface EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001107eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
Chia-I Wu4aed0942010-01-25 11:55:48 +08001108 EGLNativePixmapType pixmap, const EGLint *attrib_list)
Brian Pauladbff7e2005-04-22 21:09:39 +00001109{
Chia-I Wu655f4652010-02-17 17:30:44 +08001110 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001111
1112 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
Chad Versace6d1f83e2014-01-07 14:54:51 -08001113 STATIC_ASSERT(sizeof(void*) == sizeof(pixmap));
Chad Versace468cc862014-01-23 07:26:10 -08001114 return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01001115 attrib_list);
Chad Versace468cc862014-01-23 07:26:10 -08001116}
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001117
Emil Velikove3cc5ad2015-05-11 23:43:48 +01001118static EGLSurface EGLAPIENTRY
Chad Versace468cc862014-01-23 07:26:10 -08001119eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01001120 void *native_pixmap,
1121 const EGLint *attrib_list)
Chad Versace468cc862014-01-23 07:26:10 -08001122{
1123 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001124
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001125 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
Eric Engestrom4729e1b2016-12-08 00:36:02 +00001126 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
Chad Versace468cc862014-01-23 07:26:10 -08001127 return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1128 attrib_list);
Brian Pauladbff7e2005-04-22 21:09:39 +00001129}
1130
1131
Brian Paul1ed10272008-05-27 13:45:41 -06001132EGLSurface EGLAPIENTRY
Marek Olšák820a4d42015-05-12 21:06:41 +02001133eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
1134 void *native_pixmap,
1135 const EGLAttrib *attrib_list)
1136{
Kyle Brenneman8cc3d982016-09-12 17:25:56 -04001137 _EGLDisplay *disp = _eglLockDisplay(dpy);
Marek Olšák820a4d42015-05-12 21:06:41 +02001138 EGLSurface surface;
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001139 EGLint *int_attribs;
Marek Olšák820a4d42015-05-12 21:06:41 +02001140
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001141 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1142
1143 int_attribs = _eglConvertAttribsToInt(attrib_list);
Marek Olšák820a4d42015-05-12 21:06:41 +02001144 if (attrib_list && !int_attribs)
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001145 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
Marek Olšák820a4d42015-05-12 21:06:41 +02001146
Eric Engestrom4729e1b2016-12-08 00:36:02 +00001147 native_pixmap = _fixupNativePixmap(disp, native_pixmap);
Kyle Brenneman8cc3d982016-09-12 17:25:56 -04001148 surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap,
1149 int_attribs);
Marek Olšák820a4d42015-05-12 21:06:41 +02001150 free(int_attribs);
1151 return surface;
1152}
1153
1154
1155EGLSurface EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001156eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
1157 const EGLint *attrib_list)
Brian Pauladbff7e2005-04-22 21:09:39 +00001158{
Chia-I Wu655f4652010-02-17 17:30:44 +08001159 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001160 _EGLConfig *conf = _eglLookupConfig(config, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001161 const _EGLDriver *drv;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001162 _EGLSurface *surf;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001163 EGLSurface ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001164
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001165 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001166 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001167
Chad Versacefbb4af92016-12-16 11:00:13 -08001168 if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0)
1169 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
1170
Eric Engestromcc034482020-07-20 13:38:24 +02001171 surf = drv->CreatePbufferSurface(drv, disp, conf, attrib_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +08001172 ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001173
Chia-I Wubef4b472010-02-19 12:08:50 +08001174 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001175}
1176
1177
Brian Paul1ed10272008-05-27 13:45:41 -06001178EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001179eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1180{
Chia-I Wu655f4652010-02-17 17:30:44 +08001181 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001182 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001183 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001184 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001185
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001186 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001187 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001188 _eglUnlinkSurface(surf);
Eric Engestromcc034482020-07-20 13:38:24 +02001189 ret = drv->DestroySurface(drv, disp, surf);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001190
Chia-I Wubef4b472010-02-19 12:08:50 +08001191 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001192}
1193
Brian Paul1ed10272008-05-27 13:45:41 -06001194EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001195eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
1196 EGLint attribute, EGLint *value)
Brian Pauladbff7e2005-04-22 21:09:39 +00001197{
Chia-I Wu655f4652010-02-17 17:30:44 +08001198 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001199 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001200 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001201 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001202
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001203 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001204 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Eric Engestrom58be9d52019-06-22 22:31:53 +01001205
Eric Engestromcc034482020-07-20 13:38:24 +02001206 if (drv->QuerySurface)
1207 ret = drv->QuerySurface(drv, disp, surf, attribute, value);
Eric Engestrom58be9d52019-06-22 22:31:53 +01001208 else
1209 ret = _eglQuerySurface(drv, disp, surf, attribute, value);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001210
Chia-I Wubef4b472010-02-19 12:08:50 +08001211 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001212}
1213
Brian Paul1ed10272008-05-27 13:45:41 -06001214EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001215eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
1216 EGLint attribute, EGLint value)
Brian Pauladbff7e2005-04-22 21:09:39 +00001217{
Chia-I Wu655f4652010-02-17 17:30:44 +08001218 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001219 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001220 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001221 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001222
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001223 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001224 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Eric Engestrom9dc00c82019-06-22 22:32:26 +01001225
Eric Engestromeeacd662019-06-14 16:08:44 +01001226 ret = _eglSurfaceAttrib(drv, disp, surf, attribute, value);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001227
Chia-I Wubef4b472010-02-19 12:08:50 +08001228 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001229}
1230
1231
Brian Paul1ed10272008-05-27 13:45:41 -06001232EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001233eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1234{
Chia-I Wu655f4652010-02-17 17:30:44 +08001235 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001236 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001237 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001238 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001239
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001240 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001241 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Eric Engestromcc034482020-07-20 13:38:24 +02001242 ret = drv->BindTexImage(drv, disp, surf, buffer);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001243
Chia-I Wubef4b472010-02-19 12:08:50 +08001244 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001245}
1246
1247
Brian Paul1ed10272008-05-27 13:45:41 -06001248EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001249eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1250{
Chia-I Wu655f4652010-02-17 17:30:44 +08001251 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001252 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001253 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001254 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001255
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001256 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001257 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Eric Engestromcc034482020-07-20 13:38:24 +02001258 ret = drv->ReleaseTexImage(drv, disp, surf, buffer);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001259
Chia-I Wubef4b472010-02-19 12:08:50 +08001260 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001261}
1262
1263
Brian Paul1ed10272008-05-27 13:45:41 -06001264EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001265eglSwapInterval(EGLDisplay dpy, EGLint interval)
1266{
Chia-I Wu655f4652010-02-17 17:30:44 +08001267 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu57da4992009-10-15 11:08:48 +08001268 _EGLContext *ctx = _eglGetCurrentContext();
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001269 _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001270 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001271 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001272
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001273 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001274 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
Chia-I Wu57da4992009-10-15 11:08:48 +08001275
Chia-I Wud19afc52010-10-23 12:52:26 +08001276 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1277 ctx->Resource.Display != disp)
Chia-I Wubef4b472010-02-19 12:08:50 +08001278 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE);
Chia-I Wu57da4992009-10-15 11:08:48 +08001279
Chia-I Wud19afc52010-10-23 12:52:26 +08001280 if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE)
Chia-I Wubef4b472010-02-19 12:08:50 +08001281 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
Chia-I Wu57da4992009-10-15 11:08:48 +08001282
Emil Velikov64b4ccd2018-09-03 13:05:22 +01001283 if (surf->Type != EGL_WINDOW_BIT)
1284 RETURN_EGL_EVAL(disp, EGL_TRUE);
1285
Eric Engestrom2714a8f2017-07-31 14:49:31 +01001286 interval = CLAMP(interval,
1287 surf->Config->MinSwapInterval,
1288 surf->Config->MaxSwapInterval);
1289
Eric Engestrom26d5ca42019-06-22 22:32:50 +01001290 if (surf->SwapInterval != interval) {
Eric Engestromcc034482020-07-20 13:38:24 +02001291 if (drv->SwapInterval)
1292 ret = drv->SwapInterval(drv, disp, surf, interval);
Eric Engestrom26d5ca42019-06-22 22:32:50 +01001293 else
1294 ret = _eglSwapInterval(drv, disp, surf, interval);
1295 }
1296 else {
Eric Engestrom2714a8f2017-07-31 14:49:31 +01001297 ret = EGL_TRUE;
Eric Engestrom26d5ca42019-06-22 22:32:50 +01001298 }
Eric Engestrom2714a8f2017-07-31 14:49:31 +01001299
1300 if (ret)
1301 surf->SwapInterval = interval;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001302
Chia-I Wubef4b472010-02-19 12:08:50 +08001303 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001304}
1305
1306
Brian Paul1ed10272008-05-27 13:45:41 -06001307EGLBoolean EGLAPIENTRY
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001308eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
Brian Pauladbff7e2005-04-22 21:09:39 +00001309{
Chia-I Wubbfd0e22009-10-15 11:08:33 +08001310 _EGLContext *ctx = _eglGetCurrentContext();
Chia-I Wu655f4652010-02-17 17:30:44 +08001311 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001312 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001313 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001314 EGLBoolean ret;
Chia-I Wuaed73582010-02-17 15:43:47 +08001315
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001316 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chia-I Wubef4b472010-02-19 12:08:50 +08001317 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Chia-I Wubbfd0e22009-10-15 11:08:33 +08001318
1319 /* surface must be bound to current context in EGL 1.4 */
Alexander von Gluck IV400b8332014-12-22 10:10:13 -05001320 #ifndef _EGL_BUILT_IN_DRIVER_HAIKU
Chia-I Wud19afc52010-10-23 12:52:26 +08001321 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1322 surf != ctx->DrawSurface)
Chia-I Wubef4b472010-02-19 12:08:50 +08001323 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
Alexander von Gluck IV400b8332014-12-22 10:10:13 -05001324 #endif
Chia-I Wubbfd0e22009-10-15 11:08:33 +08001325
Emil Velikov8f667432018-09-03 13:05:23 +01001326 if (surf->Type != EGL_WINDOW_BIT)
1327 RETURN_EGL_EVAL(disp, EGL_TRUE);
1328
Chad Versace23c86c72017-05-04 17:46:33 -07001329 /* From the EGL 1.5 spec:
1330 *
1331 * If eglSwapBuffers is called and the native window associated with
1332 * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is
1333 * generated.
1334 */
1335 if (surf->Lost)
1336 RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
1337
Eric Engestromcc034482020-07-20 13:38:24 +02001338 ret = drv->SwapBuffers(drv, disp, surf);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001339
Harish Krupo98275472017-06-09 20:13:34 +05301340 /* EGL_KHR_partial_update
1341 * Frame boundary successfully reached,
1342 * reset damage region and reset BufferAgeRead
1343 */
1344 if (ret) {
1345 surf->SetDamageRegionCalled = EGL_FALSE;
1346 surf->BufferAgeRead = EGL_FALSE;
1347 }
1348
Chia-I Wubef4b472010-02-19 12:08:50 +08001349 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001350}
1351
1352
Eric Engestrom0a606a42016-10-10 17:33:17 +01001353static EGLBoolean
Eric Engestrom9702f912016-11-16 22:29:53 +00001354_eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf,
Simon Ser9a747462020-05-07 21:49:25 +02001355 const EGLint *rects, EGLint n_rects)
Robert Bragg6425b142013-04-25 13:41:42 +01001356{
1357 _EGLContext *ctx = _eglGetCurrentContext();
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001358 const _EGLDriver *drv;
Robert Bragg6425b142013-04-25 13:41:42 +01001359 EGLBoolean ret;
1360
1361 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1362
1363 /* surface must be bound to current context in EGL 1.4 */
1364 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1365 surf != ctx->DrawSurface)
1366 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
1367
Emil Velikov8f667432018-09-03 13:05:23 +01001368 if (surf->Type != EGL_WINDOW_BIT)
1369 RETURN_EGL_EVAL(disp, EGL_TRUE);
1370
Robert Bragg6425b142013-04-25 13:41:42 +01001371 if ((n_rects > 0 && rects == NULL) || n_rects < 0)
1372 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
1373
Eric Engestromcc034482020-07-20 13:38:24 +02001374 ret = drv->SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects);
Robert Bragg6425b142013-04-25 13:41:42 +01001375
Harish Krupo98275472017-06-09 20:13:34 +05301376 /* EGL_KHR_partial_update
1377 * Frame boundary successfully reached,
1378 * reset damage region and reset BufferAgeRead
1379 */
1380 if (ret) {
1381 surf->SetDamageRegionCalled = EGL_FALSE;
1382 surf->BufferAgeRead = EGL_FALSE;
1383 }
1384
Robert Bragg6425b142013-04-25 13:41:42 +01001385 RETURN_EGL_EVAL(disp, ret);
1386}
1387
Eric Engestrom0a606a42016-10-10 17:33:17 +01001388static EGLBoolean EGLAPIENTRY
1389eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
Simon Ser9a747462020-05-07 21:49:25 +02001390 const EGLint *rects, EGLint n_rects)
Eric Engestrom0a606a42016-10-10 17:33:17 +01001391{
1392 _EGLDisplay *disp = _eglLockDisplay(dpy);
1393 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1394 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Eric Engestrom9702f912016-11-16 22:29:53 +00001395 return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
Eric Engestrom0a606a42016-10-10 17:33:17 +01001396}
1397
1398static EGLBoolean EGLAPIENTRY
1399eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
Simon Ser9a747462020-05-07 21:49:25 +02001400 const EGLint *rects, EGLint n_rects)
Eric Engestrom0a606a42016-10-10 17:33:17 +01001401{
1402 _EGLDisplay *disp = _eglLockDisplay(dpy);
1403 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1404 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Eric Engestrom9702f912016-11-16 22:29:53 +00001405 return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects);
Eric Engestrom0a606a42016-10-10 17:33:17 +01001406}
1407
Harish Krupo98275472017-06-09 20:13:34 +05301408/**
Harish Krupofd734602018-07-08 12:53:00 +05301409 * Clamp the rectangles so that they lie within the surface.
Harish Krupo98275472017-06-09 20:13:34 +05301410 */
1411
1412static void
1413_eglSetDamageRegionKHRClampRects(_EGLDisplay* disp, _EGLSurface* surf,
1414 EGLint *rects, EGLint n_rects)
1415{
1416 EGLint i;
1417 EGLint surf_height = surf->Height;
1418 EGLint surf_width = surf->Width;
1419
1420 for (i = 0; i < (4 * n_rects); i += 4) {
Harish Krupofd734602018-07-08 12:53:00 +05301421 EGLint x1, y1, x2, y2;
1422 x1 = rects[i];
1423 y1 = rects[i + 1];
1424 x2 = rects[i + 2] + x1;
1425 y2 = rects[i + 3] + y1;
Harish Krupo98275472017-06-09 20:13:34 +05301426
Harish Krupofd734602018-07-08 12:53:00 +05301427 rects[i] = CLAMP(x1, 0, surf_width);
1428 rects[i + 1] = CLAMP(y1, 0, surf_height);
1429 rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i];
1430 rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1];
Harish Krupo98275472017-06-09 20:13:34 +05301431 }
1432}
1433
1434static EGLBoolean EGLAPIENTRY
1435eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1436 EGLint *rects, EGLint n_rects)
1437{
1438 _EGLDisplay *disp = _eglLockDisplay(dpy);
1439 _EGLSurface *surf = _eglLookupSurface(surface, disp);
1440 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
1441 _EGLContext *ctx = _eglGetCurrentContext();
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001442 const _EGLDriver *drv;
Harish Krupo98275472017-06-09 20:13:34 +05301443 EGLBoolean ret;
1444 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
1445
1446 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1447 surf->Type != EGL_WINDOW_BIT ||
1448 ctx->DrawSurface != surf ||
1449 surf->SwapBehavior != EGL_BUFFER_DESTROYED)
1450 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
1451
1452 /* If the damage region is already set or
1453 * buffer age is not queried between
1454 * frame boundaries, throw bad access error
1455 */
1456
1457 if (surf->SetDamageRegionCalled || !surf->BufferAgeRead)
1458 RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE);
1459
1460 _eglSetDamageRegionKHRClampRects(disp, surf, rects, n_rects);
Eric Engestromcc034482020-07-20 13:38:24 +02001461 ret = drv->SetDamageRegion(drv, disp, surf, rects, n_rects);
Harish Krupo98275472017-06-09 20:13:34 +05301462
1463 if (ret)
1464 surf->SetDamageRegionCalled = EGL_TRUE;
1465
1466 RETURN_EGL_EVAL(disp, ret);
1467}
1468
Brian Paul1ed10272008-05-27 13:45:41 -06001469EGLBoolean EGLAPIENTRY
Chia-I Wu4aed0942010-01-25 11:55:48 +08001470eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
Brian Pauladbff7e2005-04-22 21:09:39 +00001471{
Chia-I Wu655f4652010-02-17 17:30:44 +08001472 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wuaed73582010-02-17 15:43:47 +08001473 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001474 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001475 EGLBoolean ret;
Chad Versace6d1f83e2014-01-07 14:54:51 -08001476 void *native_pixmap_ptr;
1477
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001478 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
Chad Versace6d1f83e2014-01-07 14:54:51 -08001479 STATIC_ASSERT(sizeof(void*) == sizeof(target));
1480 native_pixmap_ptr = (void*) target;
Chia-I Wuaed73582010-02-17 15:43:47 +08001481
Chia-I Wubef4b472010-02-19 12:08:50 +08001482 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
Eric Engestromcc034482020-07-20 13:38:24 +02001483 ret = drv->CopyBuffers(drv, disp, surf, native_pixmap_ptr);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001484
Chia-I Wubef4b472010-02-19 12:08:50 +08001485 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001486}
1487
1488
Kyle Brenneman82a2e2c2016-09-12 17:35:22 -04001489static EGLBoolean
1490_eglWaitClientCommon(void)
Brian Pauladbff7e2005-04-22 21:09:39 +00001491{
Chia-I Wu6c21c882009-09-28 14:12:39 +08001492 _EGLContext *ctx = _eglGetCurrentContext();
1493 _EGLDisplay *disp;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001494 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001495 EGLBoolean ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001496
Chia-I Wu6c21c882009-09-28 14:12:39 +08001497 if (!ctx)
Chia-I Wubef4b472010-02-19 12:08:50 +08001498 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001499
1500 disp = ctx->Resource.Display;
Emil Velikovefe87f12015-03-06 16:54:55 +00001501 mtx_lock(&disp->Mutex);
Chia-I Wu655f4652010-02-17 17:30:44 +08001502
1503 /* let bad current context imply bad current surface */
Chia-I Wud19afc52010-10-23 12:52:26 +08001504 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1505 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
Chia-I Wubef4b472010-02-19 12:08:50 +08001506 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001507
Chia-I Wu6c21c882009-09-28 14:12:39 +08001508 /* a valid current context implies an initialized current display */
Chia-I Wua9332592010-01-27 23:55:58 +08001509 assert(disp->Initialized);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001510 drv = disp->Driver;
Eric Engestromcc034482020-07-20 13:38:24 +02001511 ret = drv->WaitClient(drv, disp, ctx);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001512
Chia-I Wubef4b472010-02-19 12:08:50 +08001513 RETURN_EGL_EVAL(disp, ret);
Chia-I Wu6c21c882009-09-28 14:12:39 +08001514}
1515
Kyle Brenneman82a2e2c2016-09-12 17:35:22 -04001516EGLBoolean EGLAPIENTRY
1517eglWaitClient(void)
1518{
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001519 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
Kyle Brenneman82a2e2c2016-09-12 17:35:22 -04001520 return _eglWaitClientCommon();
1521}
Chia-I Wu6c21c882009-09-28 14:12:39 +08001522
1523EGLBoolean EGLAPIENTRY
1524eglWaitGL(void)
1525{
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001526 /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001527 _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE);
Kyle Brenneman82a2e2c2016-09-12 17:35:22 -04001528 return _eglWaitClientCommon();
Brian Pauladbff7e2005-04-22 21:09:39 +00001529}
1530
1531
Brian Paul1ed10272008-05-27 13:45:41 -06001532EGLBoolean EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001533eglWaitNative(EGLint engine)
1534{
Chia-I Wu6c21c882009-09-28 14:12:39 +08001535 _EGLContext *ctx = _eglGetCurrentContext();
1536 _EGLDisplay *disp;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001537 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001538 EGLBoolean ret;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001539
Chia-I Wu6c21c882009-09-28 14:12:39 +08001540 if (!ctx)
Chia-I Wubef4b472010-02-19 12:08:50 +08001541 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001542
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001543 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1544
Chia-I Wu655f4652010-02-17 17:30:44 +08001545 disp = ctx->Resource.Display;
Emil Velikovefe87f12015-03-06 16:54:55 +00001546 mtx_lock(&disp->Mutex);
Chia-I Wu655f4652010-02-17 17:30:44 +08001547
Chia-I Wu6c21c882009-09-28 14:12:39 +08001548 /* let bad current context imply bad current surface */
Chia-I Wud19afc52010-10-23 12:52:26 +08001549 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
1550 _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE)
Chia-I Wubef4b472010-02-19 12:08:50 +08001551 RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001552
Chia-I Wu6c21c882009-09-28 14:12:39 +08001553 /* a valid current context implies an initialized current display */
Chia-I Wua9332592010-01-27 23:55:58 +08001554 assert(disp->Initialized);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001555 drv = disp->Driver;
Eric Engestromcc034482020-07-20 13:38:24 +02001556 ret = drv->WaitNative(drv, disp, engine);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001557
Chia-I Wubef4b472010-02-19 12:08:50 +08001558 RETURN_EGL_EVAL(disp, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001559}
1560
1561
Brian Paul1ed10272008-05-27 13:45:41 -06001562EGLDisplay EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001563eglGetCurrentDisplay(void)
1564{
Chia-I Wua1717972010-01-26 17:13:51 +08001565 _EGLContext *ctx = _eglGetCurrentContext();
Chia-I Wub3bb1802010-02-17 16:05:27 +08001566 EGLDisplay ret;
1567
1568 ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
1569
Chia-I Wubef4b472010-02-19 12:08:50 +08001570 RETURN_EGL_SUCCESS(NULL, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001571}
1572
1573
Brian Paul1ed10272008-05-27 13:45:41 -06001574EGLContext EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001575eglGetCurrentContext(void)
1576{
1577 _EGLContext *ctx = _eglGetCurrentContext();
Chia-I Wub3bb1802010-02-17 16:05:27 +08001578 EGLContext ret;
1579
1580 ret = _eglGetContextHandle(ctx);
1581
Chia-I Wubef4b472010-02-19 12:08:50 +08001582 RETURN_EGL_SUCCESS(NULL, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001583}
1584
1585
Brian Paul1ed10272008-05-27 13:45:41 -06001586EGLSurface EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001587eglGetCurrentSurface(EGLint readdraw)
1588{
Chia-I Wu61906632009-09-30 15:34:45 +08001589 _EGLContext *ctx = _eglGetCurrentContext();
Chia-I Wub3bb1802010-02-17 16:05:27 +08001590 EGLint err = EGL_SUCCESS;
Chia-I Wu61906632009-09-30 15:34:45 +08001591 _EGLSurface *surf;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001592 EGLSurface ret;
Chia-I Wu61906632009-09-30 15:34:45 +08001593
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001594 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE);
1595
Chia-I Wu61906632009-09-30 15:34:45 +08001596 if (!ctx)
Chia-I Wubef4b472010-02-19 12:08:50 +08001597 RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE);
Chia-I Wu61906632009-09-30 15:34:45 +08001598
1599 switch (readdraw) {
1600 case EGL_DRAW:
1601 surf = ctx->DrawSurface;
1602 break;
1603 case EGL_READ:
1604 surf = ctx->ReadSurface;
1605 break;
1606 default:
Chia-I Wu61906632009-09-30 15:34:45 +08001607 surf = NULL;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001608 err = EGL_BAD_PARAMETER;
Chia-I Wu61906632009-09-30 15:34:45 +08001609 break;
1610 }
1611
Chia-I Wub3bb1802010-02-17 16:05:27 +08001612 ret = _eglGetSurfaceHandle(surf);
1613
Chia-I Wubef4b472010-02-19 12:08:50 +08001614 RETURN_EGL_ERROR(NULL, err, ret);
Brian Pauladbff7e2005-04-22 21:09:39 +00001615}
1616
1617
Brian Paul1ed10272008-05-27 13:45:41 -06001618EGLint EGLAPIENTRY
Brian Pauladbff7e2005-04-22 21:09:39 +00001619eglGetError(void)
1620{
Brian Paul48822792005-12-10 17:54:00 +00001621 _EGLThreadInfo *t = _eglGetCurrentThread();
1622 EGLint e = t->LastError;
Chia-I Wu75da80b2009-07-17 11:41:02 -06001623 if (!_eglIsCurrentThreadDummy())
1624 t->LastError = EGL_SUCCESS;
Brian Pauladbff7e2005-04-22 21:09:39 +00001625 return e;
1626}
1627
1628
Brian Paulb2006a42006-01-30 00:10:55 +00001629/**
1630 ** EGL 1.2
1631 **/
1632
Brian Pauld5078b92008-05-30 13:45:40 -06001633/**
1634 * Specify the client API to use for subsequent calls including:
1635 * eglCreateContext()
1636 * eglGetCurrentContext()
1637 * eglGetCurrentDisplay()
1638 * eglGetCurrentSurface()
1639 * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT)
1640 * eglWaitClient()
1641 * eglWaitNative()
1642 * See section 3.7 "Rendering Context" in the EGL specification for details.
1643 */
nobledc43ab4f2010-07-02 19:38:07 -04001644EGLBoolean EGLAPIENTRY
Brian Paulb2006a42006-01-30 00:10:55 +00001645eglBindAPI(EGLenum api)
1646{
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001647 _EGLThreadInfo *t;
Brian Paulb2006a42006-01-30 00:10:55 +00001648
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001649 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1650
1651 t = _eglGetCurrentThread();
Chia-I Wu75da80b2009-07-17 11:41:02 -06001652 if (_eglIsCurrentThreadDummy())
Chia-I Wubef4b472010-02-19 12:08:50 +08001653 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
Chia-I Wu75da80b2009-07-17 11:41:02 -06001654
Chia-I Wu21b635f2009-07-17 11:42:04 -06001655 if (!_eglIsApiValid(api))
Chia-I Wubef4b472010-02-19 12:08:50 +08001656 RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
Chia-I Wu21b635f2009-07-17 11:42:04 -06001657
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001658 t->CurrentAPI = api;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001659
Chia-I Wubef4b472010-02-19 12:08:50 +08001660 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
Brian Paulb2006a42006-01-30 00:10:55 +00001661}
Jon Smirl7012d012005-05-13 18:31:35 +00001662
1663
Brian Pauld5078b92008-05-30 13:45:40 -06001664/**
1665 * Return the last value set with eglBindAPI().
1666 */
nobledc43ab4f2010-07-02 19:38:07 -04001667EGLenum EGLAPIENTRY
Brian Pauld5078b92008-05-30 13:45:40 -06001668eglQueryAPI(void)
1669{
Brian Pauld5078b92008-05-30 13:45:40 -06001670 _EGLThreadInfo *t = _eglGetCurrentThread();
Chia-I Wub3bb1802010-02-17 16:05:27 +08001671 EGLenum ret;
1672
1673 /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001674 ret = t->CurrentAPI;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001675
Chia-I Wubef4b472010-02-19 12:08:50 +08001676 RETURN_EGL_SUCCESS(NULL, ret);
Brian Pauld5078b92008-05-30 13:45:40 -06001677}
1678
1679
nobledc43ab4f2010-07-02 19:38:07 -04001680EGLSurface EGLAPIENTRY
Brian Paulb2006a42006-01-30 00:10:55 +00001681eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
1682 EGLClientBuffer buffer, EGLConfig config,
1683 const EGLint *attrib_list)
1684{
Chia-I Wu655f4652010-02-17 17:30:44 +08001685 _EGLDisplay *disp = _eglLockDisplay(dpy);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001686 _EGLConfig *conf = _eglLookupConfig(config, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001687 const _EGLDriver *drv;
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001688
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001689 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE);
1690
Chia-I Wubef4b472010-02-19 12:08:50 +08001691 _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001692
Eric Engestrome9286eb2019-06-22 15:53:36 +01001693 /* OpenVG is not supported */
1694 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE);
Brian Paulb2006a42006-01-30 00:10:55 +00001695}
Jon Smirl7012d012005-05-13 18:31:35 +00001696
Brian Paulb2006a42006-01-30 00:10:55 +00001697
nobledc43ab4f2010-07-02 19:38:07 -04001698EGLBoolean EGLAPIENTRY
Brian Paulb2006a42006-01-30 00:10:55 +00001699eglReleaseThread(void)
1700{
Chia-I Wu11cf3cb2010-01-26 17:22:21 +08001701 /* unbind current contexts */
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001702 if (!_eglIsCurrentThreadDummy()) {
Chia-I Wu11cf3cb2010-01-26 17:22:21 +08001703 _EGLThreadInfo *t = _eglGetCurrentThread();
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001704 _EGLContext *ctx = t->CurrentContext;
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001705
1706 _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
1707
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001708 if (ctx) {
1709 _EGLDisplay *disp = ctx->Resource.Display;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001710 const _EGLDriver *drv;
Chia-I Wu655f4652010-02-17 17:30:44 +08001711
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001712 mtx_lock(&disp->Mutex);
1713 drv = disp->Driver;
Eric Engestromcc034482020-07-20 13:38:24 +02001714 (void) drv->MakeCurrent(drv, disp, NULL, NULL, NULL);
Kyle Brenneman6e066f72016-07-08 15:21:17 -06001715 mtx_unlock(&disp->Mutex);
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001716 }
Brian Paulb2006a42006-01-30 00:10:55 +00001717 }
Chia-I Wu2f2cf462009-08-11 17:09:39 +08001718
Chia-I Wu75da80b2009-07-17 11:41:02 -06001719 _eglDestroyCurrentThread();
Chia-I Wub3bb1802010-02-17 16:05:27 +08001720
Chia-I Wubef4b472010-02-19 12:08:50 +08001721 RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
Brian Paulb2006a42006-01-30 00:10:55 +00001722}
1723
1724
Kyle Brenneman58338c62016-09-12 17:38:13 -04001725static EGLImage
1726_eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01001727 EGLClientBuffer buffer, const EGLint *attr_list)
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001728{
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001729 _EGLContext *context = _eglLookupContext(ctx, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001730 const _EGLDriver *drv;
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001731 _EGLImage *img;
Marek Olšákd333d302015-05-12 17:34:57 +02001732 EGLImage ret;
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001733
Chia-I Wubef4b472010-02-19 12:08:50 +08001734 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08001735 if (!disp->Extensions.KHR_image_base)
1736 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001737 if (!context && ctx != EGL_NO_CONTEXT)
Chia-I Wubef4b472010-02-19 12:08:50 +08001738 RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
Topi Pohjolainen0de013b2013-03-22 14:31:01 +02001739 /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display,
1740 * <ctx> must be EGL_NO_CONTEXT..."
1741 */
1742 if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT)
1743 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001744
Eric Engestromcc034482020-07-20 13:38:24 +02001745 img = drv->CreateImageKHR(drv, disp, context, target,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01001746 buffer, attr_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +08001747 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001748
Chia-I Wubef4b472010-02-19 12:08:50 +08001749 RETURN_EGL_EVAL(disp, ret);
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001750}
1751
Kyle Brenneman58338c62016-09-12 17:38:13 -04001752static EGLImage EGLAPIENTRY
1753eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1754 EGLClientBuffer buffer, const EGLint *attr_list)
1755{
1756 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001757 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
Kyle Brenneman58338c62016-09-12 17:38:13 -04001758 return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list);
1759}
1760
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001761
Marek Olšák515f04e2015-05-12 20:42:05 +02001762EGLImage EGLAPIENTRY
1763eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1764 EGLClientBuffer buffer, const EGLAttrib *attr_list)
1765{
Kyle Brenneman58338c62016-09-12 17:38:13 -04001766 _EGLDisplay *disp = _eglLockDisplay(dpy);
Marek Olšák515f04e2015-05-12 20:42:05 +02001767 EGLImage image;
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001768 EGLint *int_attribs;
Marek Olšák515f04e2015-05-12 20:42:05 +02001769
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001770 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR);
1771
1772 int_attribs = _eglConvertAttribsToInt(attr_list);
Marek Olšák515f04e2015-05-12 20:42:05 +02001773 if (attr_list && !int_attribs)
Kyle Brenneman58338c62016-09-12 17:38:13 -04001774 RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE);
Marek Olšák515f04e2015-05-12 20:42:05 +02001775
Kyle Brenneman58338c62016-09-12 17:38:13 -04001776 image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs);
Marek Olšák515f04e2015-05-12 20:42:05 +02001777 free(int_attribs);
1778 return image;
1779}
1780
1781
Eric Engestromdf7fa302017-02-21 23:56:44 +00001782static EGLBoolean
1783_eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img)
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001784{
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001785 const _EGLDriver *drv;
Chia-I Wub3bb1802010-02-17 16:05:27 +08001786 EGLBoolean ret;
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001787
Chia-I Wubef4b472010-02-19 12:08:50 +08001788 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08001789 if (!disp->Extensions.KHR_image_base)
1790 RETURN_EGL_EVAL(disp, EGL_FALSE);
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001791 if (!img)
Chia-I Wubef4b472010-02-19 12:08:50 +08001792 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001793
1794 _eglUnlinkImage(img);
Eric Engestromcc034482020-07-20 13:38:24 +02001795 ret = drv->DestroyImageKHR(drv, disp, img);
Chia-I Wub3bb1802010-02-17 16:05:27 +08001796
Chia-I Wubef4b472010-02-19 12:08:50 +08001797 RETURN_EGL_EVAL(disp, ret);
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001798}
1799
Eric Engestromdf7fa302017-02-21 23:56:44 +00001800EGLBoolean EGLAPIENTRY
1801eglDestroyImage(EGLDisplay dpy, EGLImage image)
1802{
1803 _EGLDisplay *disp = _eglLockDisplay(dpy);
1804 _EGLImage *img = _eglLookupImage(image, disp);
1805 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1806 return _eglDestroyImageCommon(disp, img);
1807}
1808
1809static EGLBoolean EGLAPIENTRY
1810eglDestroyImageKHR(EGLDisplay dpy, EGLImage image)
1811{
1812 _EGLDisplay *disp = _eglLockDisplay(dpy);
1813 _EGLImage *img = _eglLookupImage(image, disp);
1814 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
1815 return _eglDestroyImageCommon(disp, img);
1816}
1817
Chia-I Wua1c4a8a2009-08-15 22:58:13 +08001818
Marek Olšákd333d302015-05-12 17:34:57 +02001819static EGLSync
Chad Versace80448852016-09-27 13:27:21 -07001820_eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list,
1821 EGLBoolean orig_is_EGLAttrib,
Marek Olšák51c8c662015-05-12 21:41:32 +02001822 EGLenum invalid_type_error)
Chia-I Wu4eebea72010-08-14 23:09:12 +08001823{
Marek Olšák9a0bda22015-04-10 10:56:02 +02001824 _EGLContext *ctx = _eglGetCurrentContext();
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001825 const _EGLDriver *drv;
Chia-I Wu4eebea72010-08-14 23:09:12 +08001826 _EGLSync *sync;
Marek Olšákd333d302015-05-12 17:34:57 +02001827 EGLSync ret;
Chia-I Wu4eebea72010-08-14 23:09:12 +08001828
1829 _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001830
Chad Versace80448852016-09-27 13:27:21 -07001831 if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) {
Chad Versacef2c2f432016-09-27 13:27:12 -07001832 /* There exist two EGLAttrib variants of eglCreateSync*:
1833 * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync
1834 * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2
1835 * support as a proxy for EGL 1.5 support, even though that's not
1836 * entirely correct (though _eglComputeVersion does the same).
1837 *
1838 * The EGL spec provides no guidance on how to handle unsupported
1839 * functions. EGL_BAD_MATCH seems reasonable.
1840 */
1841 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1842 }
Marek Olšák290a3eb2015-04-10 13:16:30 +02001843
Tapani Pälli6bf6fcf2016-10-25 11:29:53 +03001844 /* If type is EGL_SYNC_FENCE and no context is current for the bound API
1845 * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH
1846 * error is generated.
1847 */
Rob Clark0201f012016-11-18 08:39:33 -05001848 if (!ctx &&
1849 (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID))
Tapani Pälli6bf6fcf2016-10-25 11:29:53 +03001850 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1851
Heinrich Fink3aa4f3a2019-07-30 15:58:20 +02001852 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
Tapani Pälli6bf6fcf2016-10-25 11:29:53 +03001853 if (ctx && (ctx->Resource.Display != disp ||
Heinrich Fink3aa4f3a2019-07-30 15:58:20 +02001854 (ctx->ClientAPI != EGL_OPENGL_ES_API &&
1855 ctx->ClientAPI != EGL_OPENGL_API)))
Marek Olšák9a0bda22015-04-10 10:56:02 +02001856 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
1857
1858 switch (type) {
1859 case EGL_SYNC_FENCE_KHR:
1860 if (!disp->Extensions.KHR_fence_sync)
Marek Olšák51c8c662015-05-12 21:41:32 +02001861 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001862 break;
1863 case EGL_SYNC_REUSABLE_KHR:
1864 if (!disp->Extensions.KHR_reusable_sync)
Marek Olšák51c8c662015-05-12 21:41:32 +02001865 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001866 break;
Marek Olšák290a3eb2015-04-10 13:16:30 +02001867 case EGL_SYNC_CL_EVENT_KHR:
1868 if (!disp->Extensions.KHR_cl_event2)
Marek Olšák51c8c662015-05-12 21:41:32 +02001869 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
Marek Olšák290a3eb2015-04-10 13:16:30 +02001870 break;
Rob Clark0201f012016-11-18 08:39:33 -05001871 case EGL_SYNC_NATIVE_FENCE_ANDROID:
1872 if (!disp->Extensions.ANDROID_native_fence_sync)
1873 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
1874 break;
Marek Olšák9a0bda22015-04-10 10:56:02 +02001875 default:
Marek Olšák51c8c662015-05-12 21:41:32 +02001876 RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001877 }
Chia-I Wu4eebea72010-08-14 23:09:12 +08001878
Eric Engestromcc034482020-07-20 13:38:24 +02001879 sync = drv->CreateSyncKHR(drv, disp, type, attrib_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +08001880 ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR;
Chia-I Wu4eebea72010-08-14 23:09:12 +08001881
1882 RETURN_EGL_EVAL(disp, ret);
1883}
1884
1885
Marek Olšákd333d302015-05-12 17:34:57 +02001886static EGLSync EGLAPIENTRY
Chad Versace80448852016-09-27 13:27:21 -07001887eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list)
Marek Olšák290a3eb2015-04-10 13:16:30 +02001888{
Kyle Brenneman9a992032016-09-12 17:40:29 -04001889 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001890 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
Chad Versace80448852016-09-27 13:27:21 -07001891
1892 EGLSync sync;
1893 EGLAttrib *attrib_list;
1894 EGLint err;
1895
1896 if (sizeof(int_list[0]) == sizeof(attrib_list[0])) {
1897 attrib_list = (EGLAttrib *) int_list;
1898 } else {
1899 err = _eglConvertIntsToAttribs(int_list, &attrib_list);
1900 if (err != EGL_SUCCESS)
1901 RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC);
1902 }
1903
1904 sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE,
Marek Olšák51c8c662015-05-12 21:41:32 +02001905 EGL_BAD_ATTRIBUTE);
Chad Versace80448852016-09-27 13:27:21 -07001906
1907 if (sizeof(int_list[0]) != sizeof(attrib_list[0]))
1908 free(attrib_list);
1909
1910 /* Don't double-unlock the display. _eglCreateSync already unlocked it. */
1911 return sync;
Marek Olšák51c8c662015-05-12 21:41:32 +02001912}
1913
1914
1915static EGLSync EGLAPIENTRY
1916eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
1917{
Kyle Brenneman9a992032016-09-12 17:40:29 -04001918 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001919 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
Chad Versace80448852016-09-27 13:27:21 -07001920 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
Marek Olšák51c8c662015-05-12 21:41:32 +02001921 EGL_BAD_ATTRIBUTE);
Marek Olšák290a3eb2015-04-10 13:16:30 +02001922}
1923
1924
Marek Olšák2885ba02015-05-12 20:54:22 +02001925EGLSync EGLAPIENTRY
1926eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
Marek Olšák290a3eb2015-04-10 13:16:30 +02001927{
Kyle Brenneman9a992032016-09-12 17:40:29 -04001928 _EGLDisplay *disp = _eglLockDisplay(dpy);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04001929 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
Chad Versace80448852016-09-27 13:27:21 -07001930 return _eglCreateSync(disp, type, attrib_list, EGL_TRUE,
Marek Olšák51c8c662015-05-12 21:41:32 +02001931 EGL_BAD_PARAMETER);
Marek Olšák290a3eb2015-04-10 13:16:30 +02001932}
1933
1934
Eric Engestromb7f6f3b2017-02-21 23:56:45 +00001935static EGLBoolean
1936_eglDestroySync(_EGLDisplay *disp, _EGLSync *s)
Chia-I Wu4eebea72010-08-14 23:09:12 +08001937{
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001938 const _EGLDriver *drv;
Chia-I Wu4eebea72010-08-14 23:09:12 +08001939 EGLBoolean ret;
1940
1941 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001942 assert(disp->Extensions.KHR_reusable_sync ||
Rob Clark0201f012016-11-18 08:39:33 -05001943 disp->Extensions.KHR_fence_sync ||
1944 disp->Extensions.ANDROID_native_fence_sync);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08001945
Chia-I Wu4eebea72010-08-14 23:09:12 +08001946 _eglUnlinkSync(s);
Eric Engestromcc034482020-07-20 13:38:24 +02001947 ret = drv->DestroySyncKHR(drv, disp, s);
Chia-I Wu4eebea72010-08-14 23:09:12 +08001948
1949 RETURN_EGL_EVAL(disp, ret);
1950}
1951
Eric Engestromb7f6f3b2017-02-21 23:56:45 +00001952EGLBoolean EGLAPIENTRY
1953eglDestroySync(EGLDisplay dpy, EGLSync sync)
1954{
1955 _EGLDisplay *disp = _eglLockDisplay(dpy);
1956 _EGLSync *s = _eglLookupSync(sync, disp);
1957 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1958 return _eglDestroySync(disp, s);
1959}
1960
1961static EGLBoolean EGLAPIENTRY
1962eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync)
1963{
1964 _EGLDisplay *disp = _eglLockDisplay(dpy);
1965 _EGLSync *s = _eglLookupSync(sync, disp);
1966 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
1967 return _eglDestroySync(disp, s);
1968}
1969
Chia-I Wu4eebea72010-08-14 23:09:12 +08001970
Eric Engestrom66d5ec52017-02-21 23:56:46 +00001971static EGLint
1972_eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy,
1973 _EGLSync *s, EGLint flags, EGLTime timeout)
Chia-I Wu4eebea72010-08-14 23:09:12 +08001974{
Eric Engestrom9c6fa942020-07-31 01:38:41 +02001975 const _EGLDriver *drv;
Chia-I Wu4eebea72010-08-14 23:09:12 +08001976 EGLint ret;
1977
1978 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001979 assert(disp->Extensions.KHR_reusable_sync ||
Rob Clark0201f012016-11-18 08:39:33 -05001980 disp->Extensions.KHR_fence_sync ||
1981 disp->Extensions.ANDROID_native_fence_sync);
Marek Olšák9a0bda22015-04-10 10:56:02 +02001982
1983 if (s->SyncStatus == EGL_SIGNALED_KHR)
1984 RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR);
1985
Dongwon Kim70299472016-04-04 17:14:10 -07001986 /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be
1987 * unlocked here to allow other threads also to be able to
1988 * go into waiting state.
1989 */
1990
1991 if (s->Type == EGL_SYNC_REUSABLE_KHR)
1992 _eglUnlockDisplay(dpy);
1993
Eric Engestromcc034482020-07-20 13:38:24 +02001994 ret = drv->ClientWaitSyncKHR(drv, disp, s, flags, timeout);
Chia-I Wu4eebea72010-08-14 23:09:12 +08001995
Dongwon Kim70299472016-04-04 17:14:10 -07001996 /*
1997 * 'disp' is already unlocked for reusable sync type,
1998 * so passing 'NULL' to bypass unlocking display.
1999 */
2000 if (s->Type == EGL_SYNC_REUSABLE_KHR)
2001 RETURN_EGL_EVAL(NULL, ret);
2002 else
2003 RETURN_EGL_EVAL(disp, ret);
Chia-I Wu4eebea72010-08-14 23:09:12 +08002004}
2005
Eric Engestrom66d5ec52017-02-21 23:56:46 +00002006EGLint EGLAPIENTRY
2007eglClientWaitSync(EGLDisplay dpy, EGLSync sync,
2008 EGLint flags, EGLTime timeout)
2009{
2010 _EGLDisplay *disp = _eglLockDisplay(dpy);
2011 _EGLSync *s = _eglLookupSync(sync, disp);
2012 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2013 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2014}
2015
2016static EGLint EGLAPIENTRY
2017eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync,
2018 EGLint flags, EGLTime timeout)
2019{
2020 _EGLDisplay *disp = _eglLockDisplay(dpy);
2021 _EGLSync *s = _eglLookupSync(sync, disp);
2022 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2023 return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout);
2024}
2025
Chia-I Wu4eebea72010-08-14 23:09:12 +08002026
Kyle Brenneman5b0b8442016-09-12 17:44:36 -04002027static EGLint
2028_eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags)
Marek Olšáka8617cc2015-04-10 12:04:18 +02002029{
Marek Olšáka8617cc2015-04-10 12:04:18 +02002030 _EGLContext *ctx = _eglGetCurrentContext();
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002031 const _EGLDriver *drv;
Marek Olšáka8617cc2015-04-10 12:04:18 +02002032 EGLint ret;
2033
2034 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
2035 assert(disp->Extensions.KHR_wait_sync);
2036
Heinrich Fink3aa4f3a2019-07-30 15:58:20 +02002037 /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */
2038 if (ctx == EGL_NO_CONTEXT ||
2039 (ctx->ClientAPI != EGL_OPENGL_ES_API &&
2040 ctx->ClientAPI != EGL_OPENGL_API))
Marek Olšáka8617cc2015-04-10 12:04:18 +02002041 RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
2042
2043 /* the API doesn't allow any flags yet */
2044 if (flags != 0)
2045 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2046
Eric Engestromcc034482020-07-20 13:38:24 +02002047 ret = drv->WaitSyncKHR(drv, disp, s);
Marek Olšáka8617cc2015-04-10 12:04:18 +02002048
2049 RETURN_EGL_EVAL(disp, ret);
2050}
2051
Kyle Brenneman5b0b8442016-09-12 17:44:36 -04002052static EGLint EGLAPIENTRY
2053eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags)
2054{
2055 _EGLDisplay *disp = _eglLockDisplay(dpy);
2056 _EGLSync *s = _eglLookupSync(sync, disp);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002057 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
Kyle Brenneman5b0b8442016-09-12 17:44:36 -04002058 return _eglWaitSyncCommon(disp, s, flags);
2059}
2060
Marek Olšáka8617cc2015-04-10 12:04:18 +02002061
Marek Olšák75245922015-05-12 18:13:31 +02002062EGLBoolean EGLAPIENTRY
2063eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
2064{
2065 /* The KHR version returns EGLint, while the core version returns
2066 * EGLBoolean. In both cases, the return values can only be EGL_FALSE and
2067 * EGL_TRUE.
2068 */
Kyle Brenneman5b0b8442016-09-12 17:44:36 -04002069 _EGLDisplay *disp = _eglLockDisplay(dpy);
2070 _EGLSync *s = _eglLookupSync(sync, disp);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002071 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
Kyle Brenneman5b0b8442016-09-12 17:44:36 -04002072 return _eglWaitSyncCommon(disp, s, flags);
Marek Olšák75245922015-05-12 18:13:31 +02002073}
2074
2075
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002076static EGLBoolean EGLAPIENTRY
Marek Olšákd333d302015-05-12 17:34:57 +02002077eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode)
Chia-I Wu4eebea72010-08-14 23:09:12 +08002078{
2079 _EGLDisplay *disp = _eglLockDisplay(dpy);
2080 _EGLSync *s = _eglLookupSync(sync, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002081 const _EGLDriver *drv;
Chia-I Wu4eebea72010-08-14 23:09:12 +08002082 EGLBoolean ret;
2083
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002084 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2085
Chia-I Wu4eebea72010-08-14 23:09:12 +08002086 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08002087 assert(disp->Extensions.KHR_reusable_sync);
Eric Engestromcc034482020-07-20 13:38:24 +02002088 ret = drv->SignalSyncKHR(drv, disp, s, mode);
Chia-I Wu4eebea72010-08-14 23:09:12 +08002089
2090 RETURN_EGL_EVAL(disp, ret);
2091}
2092
2093
Kyle Brenneman1d535c12016-09-12 17:46:04 -04002094static EGLBoolean
2095_eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value)
Chia-I Wu4eebea72010-08-14 23:09:12 +08002096{
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002097 const _EGLDriver *drv;
Chia-I Wu4eebea72010-08-14 23:09:12 +08002098 EGLBoolean ret;
2099
2100 _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv);
Marek Olšák9a0bda22015-04-10 10:56:02 +02002101 assert(disp->Extensions.KHR_reusable_sync ||
Rob Clark0201f012016-11-18 08:39:33 -05002102 disp->Extensions.KHR_fence_sync ||
2103 disp->Extensions.ANDROID_native_fence_sync);
Eric Engestrom757d2fb2019-06-22 22:33:00 +01002104
Eric Engestromeeacd662019-06-14 16:08:44 +01002105 ret = _eglGetSyncAttrib(drv, disp, s, attribute, value);
Chia-I Wu4eebea72010-08-14 23:09:12 +08002106
2107 RETURN_EGL_EVAL(disp, ret);
2108}
2109
Kyle Brenneman1d535c12016-09-12 17:46:04 -04002110EGLBoolean EGLAPIENTRY
2111eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value)
2112{
2113 _EGLDisplay *disp = _eglLockDisplay(dpy);
2114 _EGLSync *s = _eglLookupSync(sync, disp);
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002115 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
Tapani Pälli99cbec02019-06-10 13:06:05 +03002116
2117 if (!value)
2118 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2119
Kyle Brenneman1d535c12016-09-12 17:46:04 -04002120 return _eglGetSyncAttribCommon(disp, s, attribute, value);
2121}
2122
Chia-I Wu4eebea72010-08-14 23:09:12 +08002123
Marek Olšák1e79e052015-05-12 18:14:31 +02002124static EGLBoolean EGLAPIENTRY
2125eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
2126{
Kyle Brenneman1d535c12016-09-12 17:46:04 -04002127 _EGLDisplay *disp = _eglLockDisplay(dpy);
2128 _EGLSync *s = _eglLookupSync(sync, disp);
Dongwon Kimd1e15632016-02-02 15:06:28 -08002129 EGLAttrib attrib;
2130 EGLBoolean result;
2131
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002132 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2133
Dongwon Kimd1e15632016-02-02 15:06:28 -08002134 if (!value)
Chad Versace17084b62016-09-27 23:06:37 -07002135 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
Dongwon Kimd1e15632016-02-02 15:06:28 -08002136
2137 attrib = *value;
Kyle Brenneman1d535c12016-09-12 17:46:04 -04002138 result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib);
Marek Olšák1e79e052015-05-12 18:14:31 +02002139
2140 /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
2141 *
2142 * If any error occurs, <*value> is not modified.
2143 */
2144 if (result == EGL_FALSE)
2145 return result;
2146
2147 *value = attrib;
2148 return result;
2149}
2150
Rob Clark0201f012016-11-18 08:39:33 -05002151static EGLint EGLAPIENTRY
2152eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync)
2153{
2154 _EGLDisplay *disp = _eglLockDisplay(dpy);
2155 _EGLSync *s = _eglLookupSync(sync, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002156 const _EGLDriver *drv;
Rob Clark0201f012016-11-18 08:39:33 -05002157 EGLBoolean ret;
2158
2159 _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE);
2160
2161 /* the spec doesn't seem to specify what happens if the fence
2162 * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems
2163 * sensible:
2164 */
2165 if (!(s && (s->Type == EGL_SYNC_NATIVE_FENCE_ANDROID)))
2166 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_NATIVE_FENCE_FD_ANDROID);
2167
2168 _EGL_CHECK_SYNC(disp, s, EGL_NO_NATIVE_FENCE_FD_ANDROID, drv);
2169 assert(disp->Extensions.ANDROID_native_fence_sync);
Eric Engestromcc034482020-07-20 13:38:24 +02002170 ret = drv->DupNativeFenceFDANDROID(drv, disp, s);
Rob Clark0201f012016-11-18 08:39:33 -05002171
2172 RETURN_EGL_EVAL(disp, ret);
2173}
Marek Olšák1e79e052015-05-12 18:14:31 +02002174
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002175static EGLBoolean EGLAPIENTRY
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002176eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01002177 EGLint numRects, const EGLint *rects)
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002178{
2179 _EGLContext *ctx = _eglGetCurrentContext();
2180 _EGLDisplay *disp = _eglLockDisplay(dpy);
2181 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002182 const _EGLDriver *drv;
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002183 EGLBoolean ret;
2184
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002185 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2186
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002187 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2188
Chia-I Wu6b2f1562010-09-24 02:42:15 +08002189 if (!disp->Extensions.NOK_swap_region)
2190 RETURN_EGL_EVAL(disp, EGL_FALSE);
2191
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002192 /* surface must be bound to current context in EGL 1.4 */
Chia-I Wud19afc52010-10-23 12:52:26 +08002193 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
2194 surf != ctx->DrawSurface)
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002195 RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
2196
Eric Engestromcc034482020-07-20 13:38:24 +02002197 ret = drv->SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
Kristian Høgsberg52c554a2010-05-06 22:01:35 -04002198
2199 RETURN_EGL_EVAL(disp, ret);
2200}
2201
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002202
Marek Olšákd333d302015-05-12 17:34:57 +02002203static EGLImage EGLAPIENTRY
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002204eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list)
2205{
2206 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002207 const _EGLDriver *drv;
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002208 _EGLImage *img;
Marek Olšákd333d302015-05-12 17:34:57 +02002209 EGLImage ret;
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002210
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002211 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2212
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002213 _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08002214 if (!disp->Extensions.MESA_drm_image)
2215 RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR);
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002216
Eric Engestromcc034482020-07-20 13:38:24 +02002217 img = drv->CreateDRMImageMESA(drv, disp, attr_list);
Chia-I Wu4ce33ec2010-10-23 00:37:19 +08002218 ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR;
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002219
2220 RETURN_EGL_EVAL(disp, ret);
2221}
2222
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002223static EGLBoolean EGLAPIENTRY
Marek Olšákd333d302015-05-12 17:34:57 +02002224eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01002225 EGLint *name, EGLint *handle, EGLint *stride)
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002226{
2227 _EGLDisplay *disp = _eglLockDisplay(dpy);
2228 _EGLImage *img = _eglLookupImage(image, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002229 const _EGLDriver *drv;
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002230 EGLBoolean ret;
2231
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002232 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2233
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002234 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
Chia-I Wu6b2f1562010-09-24 02:42:15 +08002235 assert(disp->Extensions.MESA_drm_image);
2236
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002237 if (!img)
2238 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2239
Eric Engestromcc034482020-07-20 13:38:24 +02002240 ret = drv->ExportDRMImageMESA(drv, disp, img, name, handle, stride);
Kristian Høgsbergb7a8893a2010-06-04 14:28:59 -04002241
2242 RETURN_EGL_EVAL(disp, ret);
2243}
2244
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002245
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002246struct wl_display;
2247
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002248static EGLBoolean EGLAPIENTRY
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002249eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2250{
2251 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002252 const _EGLDriver *drv;
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002253 EGLBoolean ret;
2254
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002255 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2256
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002257 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2258 assert(disp->Extensions.WL_bind_wayland_display);
2259
2260 if (!display)
2261 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2262
Eric Engestromcc034482020-07-20 13:38:24 +02002263 ret = drv->BindWaylandDisplayWL(drv, disp, display);
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002264
2265 RETURN_EGL_EVAL(disp, ret);
2266}
2267
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002268static EGLBoolean EGLAPIENTRY
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002269eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
2270{
2271 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002272 const _EGLDriver *drv;
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002273 EGLBoolean ret;
2274
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002275 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2276
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002277 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2278 assert(disp->Extensions.WL_bind_wayland_display);
2279
2280 if (!display)
2281 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2282
Eric Engestromcc034482020-07-20 13:38:24 +02002283 ret = drv->UnbindWaylandDisplayWL(drv, disp, display);
Benjamin Franzke6b369c42011-02-21 16:22:34 +01002284
2285 RETURN_EGL_EVAL(disp, ret);
2286}
Kristian Høgsberge6a33572012-07-05 16:43:04 -04002287
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002288static EGLBoolean EGLAPIENTRY
Ander Conselvan de Oliveira8d29b522013-07-18 15:11:25 +03002289eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
Kristian Høgsberge6a33572012-07-05 16:43:04 -04002290 EGLint attribute, EGLint *value)
2291{
2292 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002293 const _EGLDriver *drv;
Kristian Høgsberge6a33572012-07-05 16:43:04 -04002294 EGLBoolean ret;
2295
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002296 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2297
Kristian Høgsberge6a33572012-07-05 16:43:04 -04002298 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2299 assert(disp->Extensions.WL_bind_wayland_display);
2300
2301 if (!buffer)
2302 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2303
Eric Engestromcc034482020-07-20 13:38:24 +02002304 ret = drv->QueryWaylandBufferWL(drv, disp, buffer, attribute, value);
Kristian Høgsberge6a33572012-07-05 16:43:04 -04002305
2306 RETURN_EGL_EVAL(disp, ret);
2307}
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002308
Emil Velikov720125f2015-07-10 11:22:13 +01002309
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002310static struct wl_buffer * EGLAPIENTRY
Marek Olšákd333d302015-05-12 17:34:57 +02002311eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image)
Neil Roberts5cddb1c2013-10-28 15:07:03 +00002312{
2313 _EGLDisplay *disp = _eglLockDisplay(dpy);
2314 _EGLImage *img;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002315 const _EGLDriver *drv;
Neil Roberts5cddb1c2013-10-28 15:07:03 +00002316 struct wl_buffer *ret;
2317
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002318 _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE);
2319
Neil Roberts5cddb1c2013-10-28 15:07:03 +00002320 _EGL_CHECK_DISPLAY(disp, NULL, drv);
Emil Velikov70131142017-05-15 16:14:15 +01002321 if (!disp->Extensions.WL_create_wayland_buffer_from_image)
2322 RETURN_EGL_EVAL(disp, NULL);
Neil Roberts5cddb1c2013-10-28 15:07:03 +00002323
2324 img = _eglLookupImage(image, disp);
2325
2326 if (!img)
2327 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL);
2328
Eric Engestromcc034482020-07-20 13:38:24 +02002329 ret = drv->CreateWaylandBufferFromImageWL(drv, disp, img);
Neil Roberts5cddb1c2013-10-28 15:07:03 +00002330
2331 RETURN_EGL_EVAL(disp, ret);
2332}
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002333
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002334static EGLBoolean EGLAPIENTRY
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002335eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
2336 EGLint x, EGLint y, EGLint width, EGLint height)
2337{
2338 _EGLDisplay *disp = _eglLockDisplay(dpy);
2339 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002340 const _EGLDriver *drv;
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002341 EGLBoolean ret;
2342
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002343 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2344
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002345 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2346
2347 if (!disp->Extensions.NV_post_sub_buffer)
2348 RETURN_EGL_EVAL(disp, EGL_FALSE);
2349
Eric Engestromcc034482020-07-20 13:38:24 +02002350 ret = drv->PostSubBufferNV(drv, disp, surf, x, y, width, height);
Fredrik Höglund7d46b452011-12-14 21:24:09 +01002351
2352 RETURN_EGL_EVAL(disp, ret);
2353}
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002354
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002355static EGLBoolean EGLAPIENTRY
Eric Engestrom54fa5ec2019-02-02 11:38:45 +00002356eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface,
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002357 EGLuint64KHR *ust, EGLuint64KHR *msc,
2358 EGLuint64KHR *sbc)
2359{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +00002360 _EGLDisplay *disp = _eglLockDisplay(dpy);
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002361 _EGLSurface *surf = _eglLookupSurface(surface, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002362 const _EGLDriver *drv;
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002363 EGLBoolean ret;
2364
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002365 _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE);
2366
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002367 _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
2368 if (!disp->Extensions.CHROMIUM_sync_control)
2369 RETURN_EGL_EVAL(disp, EGL_FALSE);
2370
2371 if (!ust || !msc || !sbc)
2372 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2373
Eric Engestromcc034482020-07-20 13:38:24 +02002374 ret = drv->GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc);
Sarah Sharpc524f3e2014-05-06 12:10:57 -07002375
2376 RETURN_EGL_EVAL(disp, ret);
2377}
Dave Airlie8f7338f2014-03-03 13:57:16 +10002378
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002379static EGLBoolean EGLAPIENTRY
Marek Olšákd333d302015-05-12 17:34:57 +02002380eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image,
Dave Airlie8f7338f2014-03-03 13:57:16 +10002381 EGLint *fourcc, EGLint *nplanes,
Dave Airlieb5045e22015-05-05 09:10:34 +10002382 EGLuint64KHR *modifiers)
Dave Airlie8f7338f2014-03-03 13:57:16 +10002383{
2384 _EGLDisplay *disp = _eglLockDisplay(dpy);
2385 _EGLImage *img = _eglLookupImage(image, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002386 const _EGLDriver *drv;
Dave Airlie8f7338f2014-03-03 13:57:16 +10002387 EGLBoolean ret;
2388
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002389 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2390
Dave Airlie8f7338f2014-03-03 13:57:16 +10002391 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2392 assert(disp->Extensions.MESA_image_dma_buf_export);
2393
2394 if (!img)
2395 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2396
Eric Engestromcc034482020-07-20 13:38:24 +02002397 ret = drv->ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes,
Dave Airlie8f7338f2014-03-03 13:57:16 +10002398 modifiers);
2399
2400 RETURN_EGL_EVAL(disp, ret);
2401}
2402
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002403static EGLBoolean EGLAPIENTRY
Marek Olšákd333d302015-05-12 17:34:57 +02002404eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image,
Dave Airlie8f7338f2014-03-03 13:57:16 +10002405 int *fds, EGLint *strides, EGLint *offsets)
2406{
2407 _EGLDisplay *disp = _eglLockDisplay(dpy);
2408 _EGLImage *img = _eglLookupImage(image, disp);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002409 const _EGLDriver *drv;
Dave Airlie8f7338f2014-03-03 13:57:16 +10002410 EGLBoolean ret;
2411
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002412 _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE);
2413
Dave Airlie8f7338f2014-03-03 13:57:16 +10002414 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2415 assert(disp->Extensions.MESA_image_dma_buf_export);
2416
2417 if (!img)
2418 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
2419
Eric Engestromcc034482020-07-20 13:38:24 +02002420 ret = drv->ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets);
Dave Airlie8f7338f2014-03-03 13:57:16 +10002421
2422 RETURN_EGL_EVAL(disp, ret);
2423}
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002424
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002425static EGLint EGLAPIENTRY
2426eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01002427 EGLLabelKHR label)
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002428{
2429 _EGLDisplay *disp = NULL;
2430 _EGLResourceType type;
2431
2432 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2433
2434 if (objectType == EGL_OBJECT_THREAD_KHR) {
2435 _EGLThreadInfo *t = _eglGetCurrentThread();
2436
2437 if (!_eglIsCurrentThreadDummy()) {
2438 t->Label = label;
2439 return EGL_SUCCESS;
2440 }
2441
2442 RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
2443 }
2444
2445 disp = _eglLockDisplay(dpy);
2446 if (disp == NULL)
2447 RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
2448
2449 if (objectType == EGL_OBJECT_DISPLAY_KHR) {
2450 if (dpy != (EGLDisplay) object)
2451 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2452
2453 disp->Label = label;
2454 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2455 }
2456
2457 switch (objectType) {
2458 case EGL_OBJECT_CONTEXT_KHR:
2459 type = _EGL_RESOURCE_CONTEXT;
2460 break;
2461 case EGL_OBJECT_SURFACE_KHR:
2462 type = _EGL_RESOURCE_SURFACE;
2463 break;
2464 case EGL_OBJECT_IMAGE_KHR:
2465 type = _EGL_RESOURCE_IMAGE;
2466 break;
2467 case EGL_OBJECT_SYNC_KHR:
2468 type = _EGL_RESOURCE_SYNC;
2469 break;
2470 case EGL_OBJECT_STREAM_KHR:
2471 default:
2472 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2473 }
2474
2475 if (_eglCheckResource(object, type, disp)) {
2476 _EGLResource *res = (_EGLResource *) object;
2477
2478 res->Label = label;
2479 RETURN_EGL_EVAL(disp, EGL_SUCCESS);
2480 }
2481
2482 RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
2483}
2484
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002485static EGLint EGLAPIENTRY
2486eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01002487 const EGLAttrib *attrib_list)
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002488{
2489 unsigned int newEnabled;
2490
2491 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2492
2493 mtx_lock(_eglGlobal.Mutex);
2494
2495 newEnabled = _eglGlobal.debugTypesEnabled;
2496 if (attrib_list != NULL) {
2497 int i;
2498
2499 for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
Emil Velikov4df0d502017-09-07 17:03:53 +01002500 switch (attrib_list[i]) {
2501 case EGL_DEBUG_MSG_CRITICAL_KHR:
2502 case EGL_DEBUG_MSG_ERROR_KHR:
2503 case EGL_DEBUG_MSG_WARN_KHR:
2504 case EGL_DEBUG_MSG_INFO_KHR:
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002505 if (attrib_list[i + 1])
2506 newEnabled |= DebugBitFromType(attrib_list[i]);
2507 else
2508 newEnabled &= ~DebugBitFromType(attrib_list[i]);
Emil Velikov4df0d502017-09-07 17:03:53 +01002509 break;
2510 default:
2511 // On error, set the last error code, call the current
2512 // debug callback, and return the error code.
2513 mtx_unlock(_eglGlobal.Mutex);
2514 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
2515 "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
2516 return EGL_BAD_ATTRIBUTE;
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002517 }
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002518 }
2519 }
2520
2521 if (callback != NULL) {
2522 _eglGlobal.debugCallback = callback;
2523 _eglGlobal.debugTypesEnabled = newEnabled;
2524 } else {
2525 _eglGlobal.debugCallback = NULL;
2526 _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
2527 }
2528
2529 mtx_unlock(_eglGlobal.Mutex);
2530 return EGL_SUCCESS;
2531}
2532
2533static EGLBoolean EGLAPIENTRY
2534eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
2535{
2536 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
2537
2538 mtx_lock(_eglGlobal.Mutex);
2539
Emil Velikov4df0d502017-09-07 17:03:53 +01002540 switch (attribute) {
2541 case EGL_DEBUG_MSG_CRITICAL_KHR:
2542 case EGL_DEBUG_MSG_ERROR_KHR:
2543 case EGL_DEBUG_MSG_WARN_KHR:
2544 case EGL_DEBUG_MSG_INFO_KHR:
2545 if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
2546 *value = EGL_TRUE;
2547 else
2548 *value = EGL_FALSE;
2549 break;
2550 case EGL_DEBUG_CALLBACK_KHR:
2551 *value = (EGLAttrib) _eglGlobal.debugCallback;
2552 break;
2553 default:
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002554 mtx_unlock(_eglGlobal.Mutex);
2555 _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
Eric Engestrom5f4f5aa2017-08-08 16:17:13 +01002556 "Invalid attribute 0x%04lx", (unsigned long) attribute);
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002557 return EGL_FALSE;
Emil Velikov4df0d502017-09-07 17:03:53 +01002558 }
Kyle Brennemanca9f26a2016-09-12 17:51:22 -04002559
2560 mtx_unlock(_eglGlobal.Mutex);
2561 return EGL_TRUE;
2562}
2563
Eric Engestrom1534fc62017-02-21 23:56:52 +00002564static int
2565_eglFunctionCompare(const void *key, const void *elem)
2566{
2567 const char *procname = key;
2568 const struct _egl_entrypoint *entrypoint = elem;
2569 return strcmp(procname, entrypoint->name);
2570}
2571
Varad Gautam6719e052017-05-30 17:23:38 +05302572static EGLBoolean EGLAPIENTRY
2573eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
2574 EGLint *formats, EGLint *num_formats)
2575{
2576 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002577 const _EGLDriver *drv;
Varad Gautam6719e052017-05-30 17:23:38 +05302578 EGLBoolean ret;
2579
2580 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2581
2582 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2583
Eric Engestromcc034482020-07-20 13:38:24 +02002584 ret = drv->QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
Varad Gautam6719e052017-05-30 17:23:38 +05302585 num_formats);
2586
2587 RETURN_EGL_EVAL(disp, ret);
2588}
2589
Varad Gautamde3c4592017-05-30 17:23:39 +05302590static EGLBoolean EGLAPIENTRY
2591eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
2592 EGLuint64KHR *modifiers, EGLBoolean *external_only,
2593 EGLint *num_modifiers)
2594{
2595 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002596 const _EGLDriver *drv;
Varad Gautamde3c4592017-05-30 17:23:39 +05302597 EGLBoolean ret;
2598
2599 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2600
2601 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2602
Eric Engestromcc034482020-07-20 13:38:24 +02002603 ret = drv->QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
Varad Gautamde3c4592017-05-30 17:23:39 +05302604 modifiers, external_only,
2605 num_modifiers);
2606
2607 RETURN_EGL_EVAL(disp, ret);
2608}
2609
Tapani Pälli6f5b5702017-12-28 10:51:11 +02002610static void EGLAPIENTRY
2611eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set,
2612 EGLGetBlobFuncANDROID get)
2613{
2614 /* This function does not return anything so we cannot
2615 * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY.
2616 */
2617 _EGLDisplay *disp = _eglLockDisplay(dpy);
2618 if (!_eglSetFuncName(__func__, disp, EGL_OBJECT_DISPLAY_KHR, NULL)) {
2619 if (disp)
2620 _eglUnlockDisplay(disp);
2621 return;
2622 }
2623
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002624 const _EGLDriver *drv = _eglCheckDisplay(disp, __func__);
Tapani Pälli6f5b5702017-12-28 10:51:11 +02002625 if (!drv) {
2626 if (disp)
2627 _eglUnlockDisplay(disp);
2628 return;
2629 }
2630
2631 if (!set || !get) {
2632 _eglError(EGL_BAD_PARAMETER,
2633 "eglSetBlobCacheFuncsANDROID: NULL handler given");
2634 _eglUnlockDisplay(disp);
2635 return;
2636 }
2637
2638 if (disp->BlobCacheSet) {
2639 _eglError(EGL_BAD_PARAMETER,
2640 "eglSetBlobCacheFuncsANDROID: functions already set");
2641 _eglUnlockDisplay(disp);
2642 return;
2643 }
2644
2645 disp->BlobCacheSet = set;
2646 disp->BlobCacheGet = get;
2647
Eric Engestromcc034482020-07-20 13:38:24 +02002648 drv->SetBlobCacheFuncsANDROID(drv, disp, set, get);
Tapani Pälli6f5b5702017-12-28 10:51:11 +02002649
2650 _eglUnlockDisplay(disp);
2651}
2652
Emil Velikov7552fcb2015-07-24 16:19:55 +02002653static EGLBoolean EGLAPIENTRY
2654eglQueryDeviceAttribEXT(EGLDeviceEXT device,
2655 EGLint attribute,
2656 EGLAttrib *value)
2657{
2658 _EGLDevice *dev = _eglLookupDevice(device);
2659 EGLBoolean ret;
2660
2661 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2662 if (!dev)
2663 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, EGL_FALSE);
2664
2665 ret = _eglQueryDeviceAttribEXT(dev, attribute, value);
2666 RETURN_EGL_EVAL(NULL, ret);
2667}
2668
2669static const char * EGLAPIENTRY
2670eglQueryDeviceStringEXT(EGLDeviceEXT device,
2671 EGLint name)
2672{
2673 _EGLDevice *dev = _eglLookupDevice(device);
2674
2675 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2676 if (!dev)
2677 RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, NULL);
2678
2679 RETURN_EGL_EVAL(NULL, _eglQueryDeviceStringEXT(dev, name));
2680}
2681
2682static EGLBoolean EGLAPIENTRY
2683eglQueryDevicesEXT(EGLint max_devices,
2684 EGLDeviceEXT *devices,
2685 EGLint *num_devices)
2686{
2687 EGLBoolean ret;
2688
2689 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2690 ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices,
2691 num_devices);
2692 RETURN_EGL_EVAL(NULL, ret);
2693}
2694
2695static EGLBoolean EGLAPIENTRY
2696eglQueryDisplayAttribEXT(EGLDisplay dpy,
2697 EGLint attribute,
2698 EGLAttrib *value)
2699{
2700 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002701 const _EGLDriver *drv;
Emil Velikov7552fcb2015-07-24 16:19:55 +02002702
2703 _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
2704 _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
2705
2706 switch (attribute) {
2707 case EGL_DEVICE_EXT:
2708 *value = (EGLAttrib) disp->Device;
2709 break;
2710 default:
2711 RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE);
2712 }
2713 RETURN_EGL_SUCCESS(disp, EGL_TRUE);
2714}
2715
Veluri Mithun6afce782019-01-23 22:44:25 +05302716static char * EGLAPIENTRY
2717eglGetDisplayDriverConfig(EGLDisplay dpy)
2718{
2719 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002720 const _EGLDriver *drv;
Veluri Mithun6afce782019-01-23 22:44:25 +05302721 char *ret;
2722
2723 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2724 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2725
2726 assert(disp->Extensions.MESA_query_driver);
2727
Eric Engestromcc034482020-07-20 13:38:24 +02002728 ret = drv->QueryDriverConfig(disp);
Veluri Mithun6afce782019-01-23 22:44:25 +05302729 RETURN_EGL_EVAL(disp, ret);
2730}
2731
2732static const char * EGLAPIENTRY
2733eglGetDisplayDriverName(EGLDisplay dpy)
2734{
2735 _EGLDisplay *disp = _eglLockDisplay(dpy);
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002736 const _EGLDriver *drv;
Veluri Mithun6afce782019-01-23 22:44:25 +05302737 const char *ret;
2738
2739 _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL);
2740 _EGL_CHECK_DISPLAY(disp, NULL, drv);
2741
2742 assert(disp->Extensions.MESA_query_driver);
2743
Eric Engestromcc034482020-07-20 13:38:24 +02002744 ret = drv->QueryDriverName(disp);
Veluri Mithun6afce782019-01-23 22:44:25 +05302745 RETURN_EGL_EVAL(disp, ret);
2746}
2747
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002748__eglMustCastToProperFunctionPointerType EGLAPIENTRY
2749eglGetProcAddress(const char *procname)
2750{
Eric Engestrom1534fc62017-02-21 23:56:52 +00002751 static const struct _egl_entrypoint egl_functions[] = {
Eric Engestrom3b69c4a2017-02-21 23:56:47 +00002752#define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f },
Eric Engestromf92fd4d2017-02-21 23:56:49 +00002753#include "eglentrypoint.h"
Eric Engestrom3b69c4a2017-02-21 23:56:47 +00002754#undef EGL_ENTRYPOINT
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002755 };
Eric Engestrom1534fc62017-02-21 23:56:52 +00002756 _EGLProc ret = NULL;
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002757
2758 if (!procname)
2759 RETURN_EGL_SUCCESS(NULL, NULL);
2760
Kyle Brenneman6a5545d2016-09-12 17:50:40 -04002761 _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL);
2762
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002763 if (strncmp(procname, "egl", 3) == 0) {
Eric Engestrom1534fc62017-02-21 23:56:52 +00002764 const struct _egl_entrypoint *entrypoint =
2765 bsearch(procname,
2766 egl_functions, ARRAY_SIZE(egl_functions),
2767 sizeof(egl_functions[0]),
2768 _eglFunctionCompare);
2769 if (entrypoint)
2770 ret = entrypoint->function;
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002771 }
Eric Engestrom1534fc62017-02-21 23:56:52 +00002772
Emil Velikove3cc5ad2015-05-11 23:43:48 +01002773 if (!ret)
2774 ret = _eglGetDriverProc(procname);
2775
2776 RETURN_EGL_SUCCESS(NULL, ret);
2777}
Marek Olšákb6eda702016-03-03 15:59:48 +01002778
2779static int
2780_eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002781 _EGLDisplay **disp, const _EGLDriver **drv,
Marek Olšákb6eda702016-03-03 15:59:48 +01002782 _EGLContext **ctx)
2783{
2784
2785 *disp = _eglLockDisplay(dpy);
2786 if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
2787 if (*disp)
2788 _eglUnlockDisplay(*disp);
2789 return MESA_GLINTEROP_INVALID_DISPLAY;
2790 }
2791
2792 *drv = (*disp)->Driver;
2793
2794 *ctx = _eglLookupContext(context, *disp);
2795 if (!*ctx ||
2796 ((*ctx)->ClientAPI != EGL_OPENGL_API &&
2797 (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
2798 _eglUnlockDisplay(*disp);
2799 return MESA_GLINTEROP_INVALID_CONTEXT;
2800 }
2801
2802 return MESA_GLINTEROP_SUCCESS;
2803}
2804
Marek Olšákee39d442016-11-02 18:59:22 +01002805PUBLIC int
Marek Olšákb6eda702016-03-03 15:59:48 +01002806MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002807 struct mesa_glinterop_device_info *out)
Marek Olšákb6eda702016-03-03 15:59:48 +01002808{
2809 _EGLDisplay *disp;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002810 const _EGLDriver *drv;
Marek Olšákb6eda702016-03-03 15:59:48 +01002811 _EGLContext *ctx;
2812 int ret;
2813
2814 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2815 if (ret != MESA_GLINTEROP_SUCCESS)
2816 return ret;
2817
Eric Engestromcc034482020-07-20 13:38:24 +02002818 if (drv->GLInteropQueryDeviceInfo)
2819 ret = drv->GLInteropQueryDeviceInfo(disp, ctx, out);
Marek Olšákb6eda702016-03-03 15:59:48 +01002820 else
2821 ret = MESA_GLINTEROP_UNSUPPORTED;
2822
2823 _eglUnlockDisplay(disp);
2824 return ret;
2825}
2826
Marek Olšákee39d442016-11-02 18:59:22 +01002827PUBLIC int
Marek Olšákb6eda702016-03-03 15:59:48 +01002828MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002829 struct mesa_glinterop_export_in *in,
2830 struct mesa_glinterop_export_out *out)
Marek Olšákb6eda702016-03-03 15:59:48 +01002831{
2832 _EGLDisplay *disp;
Eric Engestrom9c6fa942020-07-31 01:38:41 +02002833 const _EGLDriver *drv;
Marek Olšákb6eda702016-03-03 15:59:48 +01002834 _EGLContext *ctx;
2835 int ret;
2836
2837 ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
2838 if (ret != MESA_GLINTEROP_SUCCESS)
2839 return ret;
2840
Eric Engestromcc034482020-07-20 13:38:24 +02002841 if (drv->GLInteropExportObject)
2842 ret = drv->GLInteropExportObject(disp, ctx, in, out);
Marek Olšákb6eda702016-03-03 15:59:48 +01002843 else
2844 ret = MESA_GLINTEROP_UNSUPPORTED;
2845
2846 _eglUnlockDisplay(disp);
2847 return ret;
2848}