Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2008 VMware, Inc. |
Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 4 | * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> |
| 5 | * Copyright 2010-2011 LunarG, Inc. |
| 6 | * All Rights Reserved. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the |
| 10 | * "Software"), to deal in the Software without restriction, including |
| 11 | * without limitation the rights to use, copy, modify, merge, publish, |
| 12 | * distribute, sub license, and/or sell copies of the Software, and to |
| 13 | * permit persons to whom the Software is furnished to do so, subject to |
| 14 | * the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the |
| 17 | * next paragraph) shall be included in all copies or substantial portions |
| 18 | * of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | * DEALINGS IN THE SOFTWARE. |
| 27 | * |
| 28 | **************************************************************************/ |
| 29 | |
| 30 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 31 | /** |
| 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 Wu | aaa1253 | 2009-09-30 15:08:34 +0800 | [diff] [blame] | 42 | * opaque handles. Internal objects are linked to a display to |
| 43 | * create the handles. |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 44 | * |
Chia-I Wu | aaa1253 | 2009-09-30 15:08:34 +0800 | [diff] [blame] | 45 | * 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 Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 63 | * |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 64 | * 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 Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 73 | * 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 Engestrom | 8d9c204 | 2018-11-15 18:07:33 +0000 | [diff] [blame] | 86 | #ifdef USE_LIBGLVND |
| 87 | #define EGLAPI |
| 88 | #undef PUBLIC |
| 89 | #define PUBLIC |
| 90 | #endif |
| 91 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 92 | #include <stdio.h> |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 93 | #include <stdlib.h> |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 94 | #include <string.h> |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 95 | #include "c99_compat.h" |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 96 | #include "c11/threads.h" |
Emil Velikov | 239e7ee | 2017-05-04 18:55:36 +0100 | [diff] [blame] | 97 | #include "util/macros.h" |
Chia-I Wu | 1e6c10f | 2010-05-31 11:47:58 +0800 | [diff] [blame] | 98 | |
Eric Engestrom | d75fbff | 2018-05-16 14:17:30 +0100 | [diff] [blame] | 99 | #include "egldefines.h" |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 100 | #include "eglglobals.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 101 | #include "eglcontext.h" |
| 102 | #include "egldisplay.h" |
| 103 | #include "egltypedefs.h" |
Chia-I Wu | 94cb321 | 2010-01-29 09:00:30 +0800 | [diff] [blame] | 104 | #include "eglcurrent.h" |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 105 | #include "egldevice.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 106 | #include "egldriver.h" |
| 107 | #include "eglsurface.h" |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 108 | #include "eglconfig.h" |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 109 | #include "eglimage.h" |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 110 | #include "eglsync.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 111 | |
Matt Turner | 4e97084 | 2017-07-06 18:40:53 -0700 | [diff] [blame] | 112 | #include "GL/mesa_glinterop.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 113 | |
| 114 | /** |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 115 | * Macros to help return an API entrypoint. |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 116 | * |
| 117 | * These macros will unlock the display and record the error code. |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 118 | */ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 119 | #define RETURN_EGL_ERROR(disp, err, ret) \ |
| 120 | do { \ |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 121 | if (disp) \ |
| 122 | _eglUnlockDisplay(disp); \ |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 123 | /* EGL error codes are non-zero */ \ |
| 124 | if (err) \ |
Emil Velikov | d780012 | 2015-02-28 16:39:10 +0000 | [diff] [blame] | 125 | _eglError(err, __func__); \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 126 | return ret; \ |
| 127 | } while (0) |
| 128 | |
| 129 | #define RETURN_EGL_SUCCESS(disp, ret) \ |
| 130 | RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret) |
| 131 | |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 132 | /* record EGL_SUCCESS only when ret evaluates to true */ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 133 | #define RETURN_EGL_EVAL(disp, ret) \ |
| 134 | RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret) |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 135 | |
| 136 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 137 | /* |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 138 | * A bunch of macros and checks to simplify error checking. |
| 139 | */ |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 140 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 141 | #define _EGL_CHECK_DISPLAY(disp, ret, drv) \ |
| 142 | do { \ |
Emil Velikov | d780012 | 2015-02-28 16:39:10 +0000 | [diff] [blame] | 143 | drv = _eglCheckDisplay(disp, __func__); \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 144 | if (!drv) \ |
| 145 | RETURN_EGL_ERROR(disp, 0, ret); \ |
| 146 | } while (0) |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 147 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 148 | #define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \ |
| 149 | do { \ |
Emil Velikov | d780012 | 2015-02-28 16:39:10 +0000 | [diff] [blame] | 150 | drv = _eglCheck ## type(disp, obj, __func__); \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 151 | 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 Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 164 | #define _EGL_CHECK_SYNC(disp, s, ret, drv) \ |
| 165 | _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv) |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 166 | |
| 167 | |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 168 | struct _egl_entrypoint { |
| 169 | const char *name; |
| 170 | _EGLProc function; |
| 171 | }; |
| 172 | |
| 173 | |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 174 | static inline const _EGLDriver * |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 175 | _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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 189 | static inline const _EGLDriver * |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 190 | _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) |
| 191 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 192 | const _EGLDriver *drv = _eglCheckDisplay(disp, msg); |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 193 | 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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 203 | static inline const _EGLDriver * |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 204 | _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) |
| 205 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 206 | const _EGLDriver *drv = _eglCheckDisplay(disp, msg); |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 207 | 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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 217 | static inline const _EGLDriver * |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 218 | _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) |
| 219 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 220 | const _EGLDriver *drv = _eglCheckDisplay(disp, msg); |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 221 | 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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 231 | static inline const _EGLDriver * |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 232 | _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) |
| 233 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 234 | const _EGLDriver *drv = _eglCheckDisplay(disp, msg); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 235 | 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 Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 245 | /** |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 246 | * Lookup and lock a display. |
| 247 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 248 | static inline _EGLDisplay * |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 249 | _eglLockDisplay(EGLDisplay dpy) |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 250 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 251 | _EGLDisplay *disp = _eglLookupDisplay(dpy); |
| 252 | if (disp) |
| 253 | mtx_lock(&disp->Mutex); |
| 254 | return disp; |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
| 258 | /** |
| 259 | * Unlock a display. |
| 260 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 261 | static inline void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 262 | _eglUnlockDisplay(_EGLDisplay *disp) |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 263 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 264 | mtx_unlock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 265 | } |
| 266 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 267 | static 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 Velikov | b94344f | 2017-09-07 17:03:50 +0100 | [diff] [blame] | 285 | _eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 286 | 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 Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 297 | |
Chad Versace | 3e0d575 | 2016-09-27 13:27:17 -0700 | [diff] [blame] | 298 | /** |
| 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 Engestrom | 9e1d35c | 2016-12-08 00:36:03 +0000 | [diff] [blame] | 304 | static EGLint |
Chad Versace | 3e0d575 | 2016-09-27 13:27:17 -0700 | [diff] [blame] | 305 | _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šák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 339 | static EGLint * |
| 340 | _eglConvertAttribsToInt(const EGLAttrib *attr_list) |
| 341 | { |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 342 | size_t size = _eglNumAttribs(attr_list); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 343 | EGLint *int_attribs = NULL; |
| 344 | |
| 345 | /* Convert attributes from EGLAttrib[] to EGLint[] */ |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 346 | if (size) { |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 347 | int_attribs = calloc(size, sizeof(int_attribs[0])); |
| 348 | if (!int_attribs) |
| 349 | return NULL; |
| 350 | |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 351 | for (size_t i = 0; i < size; i++) |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 352 | int_attribs[i] = attr_list[i]; |
| 353 | } |
| 354 | return int_attribs; |
| 355 | } |
| 356 | |
| 357 | |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 358 | /** |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 359 | * This is typically the first EGL function that an application calls. |
Chia-I Wu | db5ce8b | 2010-02-17 18:39:27 +0800 | [diff] [blame] | 360 | * It associates a private _EGLDisplay object to the native display. |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 361 | */ |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 362 | EGLDisplay EGLAPIENTRY |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 363 | eglGetDisplay(EGLNativeDisplayType nativeDisplay) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 364 | { |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 365 | _EGLPlatformType plat; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 366 | _EGLDisplay *disp; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 367 | void *native_display_ptr; |
| 368 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 369 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
| 370 | |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 371 | STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay)); |
| 372 | native_display_ptr = (void*) nativeDisplay; |
| 373 | |
| 374 | plat = _eglGetNativePlatform(native_display_ptr); |
Adam Jackson | 8e991ce | 2019-05-16 18:01:34 +0100 | [diff] [blame] | 375 | disp = _eglFindDisplay(plat, native_display_ptr, NULL); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 376 | return _eglGetDisplayHandle(disp); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 379 | static EGLDisplay |
| 380 | _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display, |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 381 | const EGLAttrib *attrib_list) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 382 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 383 | _EGLDisplay *disp; |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 384 | |
| 385 | switch (platform) { |
| 386 | #ifdef HAVE_X11_PLATFORM |
| 387 | case EGL_PLATFORM_X11_EXT: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 388 | disp = _eglGetX11Display((Display*) native_display, attrib_list); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 389 | break; |
| 390 | #endif |
| 391 | #ifdef HAVE_DRM_PLATFORM |
| 392 | case EGL_PLATFORM_GBM_MESA: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 393 | disp = _eglGetGbmDisplay((struct gbm_device*) native_display, |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 394 | attrib_list); |
| 395 | break; |
| 396 | #endif |
| 397 | #ifdef HAVE_WAYLAND_PLATFORM |
| 398 | case EGL_PLATFORM_WAYLAND_EXT: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 399 | disp = _eglGetWaylandDisplay((struct wl_display*) native_display, |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 400 | attrib_list); |
| 401 | break; |
| 402 | #endif |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 403 | case EGL_PLATFORM_SURFACELESS_MESA: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 404 | disp = _eglGetSurfacelessDisplay(native_display, attrib_list); |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 405 | break; |
renchenglei | 500b45a | 2019-06-28 15:21:08 +0800 | [diff] [blame] | 406 | #ifdef HAVE_ANDROID_PLATFORM |
| 407 | case EGL_PLATFORM_ANDROID_KHR: |
| 408 | disp = _eglGetAndroidDisplay(native_display, attrib_list); |
| 409 | break; |
| 410 | #endif |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 411 | case EGL_PLATFORM_DEVICE_EXT: |
| 412 | disp = _eglGetDeviceDisplay(native_display, attrib_list); |
| 413 | break; |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 414 | default: |
| 415 | RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL); |
| 416 | } |
| 417 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 418 | return _eglGetDisplayHandle(disp); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 419 | } |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 420 | |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 421 | static EGLDisplay EGLAPIENTRY |
| 422 | eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 423 | const EGLint *int_attribs) |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 424 | { |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 425 | EGLAttrib *attrib_list; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 426 | EGLDisplay disp; |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 427 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 428 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 429 | |
| 430 | if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS) |
| 431 | RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL); |
| 432 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 433 | disp = _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 434 | free(attrib_list); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 435 | return disp; |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 438 | EGLDisplay EGLAPIENTRY |
| 439 | eglGetPlatformDisplay(EGLenum platform, void *native_display, |
| 440 | const EGLAttrib *attrib_list) |
| 441 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 442 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 443 | return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 446 | /** |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 447 | * Copy the extension into the string and update the string pointer. |
| 448 | */ |
| 449 | static 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 | */ |
| 473 | static void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 474 | _eglCreateExtensionsString(_EGLDisplay *disp) |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 475 | { |
| 476 | #define _EGL_CHECK_EXTENSION(ext) \ |
| 477 | do { \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 478 | if (disp->Extensions.ext) { \ |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 479 | _eglAppendExtension(&exts, "EGL_" #ext); \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 480 | assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 481 | } \ |
| 482 | } while (0) |
| 483 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 484 | char *exts = disp->ExtensionsString; |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 485 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 486 | /* Please keep these sorted alphabetically. */ |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 487 | _EGL_CHECK_EXTENSION(ANDROID_blob_cache); |
Rob Herring | 8975527 | 2016-02-02 14:23:07 -0600 | [diff] [blame] | 488 | _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 489 | _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 490 | _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync); |
Rob Herring | e21e81a | 2016-02-02 14:23:08 -0600 | [diff] [blame] | 491 | _EGL_CHECK_EXTENSION(ANDROID_recordable); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 492 | |
| 493 | _EGL_CHECK_EXTENSION(CHROMIUM_sync_control); |
| 494 | |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 495 | _EGL_CHECK_EXTENSION(EXT_buffer_age); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 496 | _EGL_CHECK_EXTENSION(EXT_create_context_robustness); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 497 | _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import); |
Varad Gautam | 4c41229 | 2017-05-30 17:23:40 +0530 | [diff] [blame] | 498 | _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers); |
Tapani Pälli | 799b3d1 | 2018-04-05 13:02:36 +0300 | [diff] [blame] | 499 | _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata); |
| 500 | _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 501 | _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage); |
| 502 | |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 503 | _EGL_CHECK_EXTENSION(IMG_context_priority); |
| 504 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 505 | _EGL_CHECK_EXTENSION(KHR_cl_event2); |
Emil Velikov | 26541a1 | 2016-12-05 14:42:04 +0000 | [diff] [blame] | 506 | _EGL_CHECK_EXTENSION(KHR_config_attribs); |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 507 | _EGL_CHECK_EXTENSION(KHR_context_flush_control); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 508 | _EGL_CHECK_EXTENSION(KHR_create_context); |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 509 | _EGL_CHECK_EXTENSION(KHR_create_context_no_error); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 510 | _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 Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 517 | if (disp->Extensions.KHR_image_base && disp->Extensions.KHR_image_pixmap) |
| 518 | disp->Extensions.KHR_image = EGL_TRUE; |
Harish Krupo | 96fc5fb | 2017-12-08 21:29:39 +0530 | [diff] [blame] | 519 | _EGL_CHECK_EXTENSION(KHR_image); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 520 | _EGL_CHECK_EXTENSION(KHR_image_base); |
| 521 | _EGL_CHECK_EXTENSION(KHR_image_pixmap); |
Chad Versace | 3dc2238 | 2018-04-30 22:32:25 -0700 | [diff] [blame] | 522 | _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer); |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 523 | _EGL_CHECK_EXTENSION(KHR_no_config_context); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 524 | _EGL_CHECK_EXTENSION(KHR_partial_update); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 525 | _EGL_CHECK_EXTENSION(KHR_reusable_sync); |
| 526 | _EGL_CHECK_EXTENSION(KHR_surfaceless_context); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 527 | if (disp->Extensions.EXT_swap_buffers_with_damage) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 528 | _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage"); |
Tapani Pälli | 41f7de4 | 2017-10-31 10:57:42 +0200 | [diff] [blame] | 529 | _EGL_CHECK_EXTENSION(EXT_pixel_format_float); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 530 | _EGL_CHECK_EXTENSION(KHR_wait_sync); |
| 531 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 532 | if (disp->Extensions.KHR_no_config_context) |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 533 | _eglAppendExtension(&exts, "EGL_MESA_configless_context"); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 534 | _EGL_CHECK_EXTENSION(MESA_drm_image); |
| 535 | _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 536 | _EGL_CHECK_EXTENSION(MESA_query_driver); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 537 | |
| 538 | _EGL_CHECK_EXTENSION(NOK_swap_region); |
| 539 | _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 540 | |
| 541 | _EGL_CHECK_EXTENSION(NV_post_sub_buffer); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 542 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 543 | _EGL_CHECK_EXTENSION(WL_bind_wayland_display); |
| 544 | _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image); |
| 545 | |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 546 | #undef _EGL_CHECK_EXTENSION |
| 547 | } |
| 548 | |
| 549 | static void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 550 | _eglCreateAPIsString(_EGLDisplay *disp) |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 551 | { |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 552 | #define addstr(str) \ |
| 553 | { \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 554 | const size_t old_len = strlen(disp->ClientAPIsString); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 555 | const size_t add_len = sizeof(str); \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 556 | const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 557 | if (old_len + add_len <= max_len) \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 558 | strcat(disp->ClientAPIsString, str " "); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 559 | else \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 560 | assert(!"disp->ClientAPIsString is not large enough"); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 561 | } |
| 562 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 563 | if (disp->ClientAPIs & EGL_OPENGL_BIT) |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 564 | addstr("OpenGL"); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 565 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 566 | if (disp->ClientAPIs & EGL_OPENGL_ES_BIT || |
| 567 | disp->ClientAPIs & EGL_OPENGL_ES2_BIT || |
| 568 | disp->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) { |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 569 | addstr("OpenGL_ES"); |
Plamena Manolova | 21edd24 | 2016-05-12 18:21:38 +0100 | [diff] [blame] | 570 | } |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 571 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 572 | if (disp->ClientAPIs & EGL_OPENVG_BIT) |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 573 | addstr("OpenVG"); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 574 | |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 575 | #undef addstr |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Marek Olšák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 578 | static void |
| 579 | _eglComputeVersion(_EGLDisplay *disp) |
| 580 | { |
Marek Olšák | 0e4b564 | 2015-05-12 16:40:29 +0200 | [diff] [blame] | 581 | disp->Version = 14; |
Marek Olšák | a1cb407 | 2015-05-11 22:18:04 +0200 | [diff] [blame] | 582 | |
| 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 Kumar | 0bea2a1 | 2020-05-07 22:02:02 +0530 | [diff] [blame] | 597 | |
| 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šák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 602 | } |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 603 | |
| 604 | /** |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 605 | * This is typically the second EGL function that an application calls. |
| 606 | * Here we load/initialize the actual hardware driver. |
| 607 | */ |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 608 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 609 | eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 610 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 611 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Jonathan White | 7e2458c | 2008-08-06 13:40:03 -0600 | [diff] [blame] | 612 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 613 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 614 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 615 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 616 | RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); |
Brian Paul | c56e15b | 2008-05-28 15:43:41 -0600 | [diff] [blame] | 617 | |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 618 | if (!disp->Initialized) { |
Eric Engestrom | ed3f1e0 | 2020-07-22 01:19:03 +0200 | [diff] [blame] | 619 | if (!_eglInitializeDisplay(disp)) |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 620 | RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); |
Chia-I Wu | 57929ed | 2010-01-19 18:29:21 +0800 | [diff] [blame] | 621 | |
Chia-I Wu | 310c768 | 2009-08-17 15:53:54 +0800 | [diff] [blame] | 622 | /* limit to APIs supported by core */ |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 623 | disp->ClientAPIs &= _EGL_API_ALL_BITS; |
Chad Versace | 7e8ba77 | 2014-11-20 10:26:38 -0800 | [diff] [blame] | 624 | |
| 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 Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 641 | |
Emil Velikov | 26541a1 | 2016-12-05 14:42:04 +0000 | [diff] [blame] | 642 | /* 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šák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 647 | _eglComputeVersion(disp); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 648 | _eglCreateExtensionsString(disp); |
| 649 | _eglCreateAPIsString(disp); |
Emil Velikov | 3593f37 | 2015-07-14 00:19:54 +0100 | [diff] [blame] | 650 | snprintf(disp->VersionString, sizeof(disp->VersionString), |
Eric Engestrom | a96749b | 2017-10-18 16:32:33 +0100 | [diff] [blame] | 651 | "%d.%d", disp->Version / 10, disp->Version % 10); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 652 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 653 | |
| 654 | /* Update applications version of major and minor if not NULL */ |
| 655 | if ((major != NULL) && (minor != NULL)) { |
Marek Olšák | 0e4b564 | 2015-05-12 16:40:29 +0200 | [diff] [blame] | 656 | *major = disp->Version / 10; |
| 657 | *minor = disp->Version % 10; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 658 | } |
| 659 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 660 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 664 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 665 | eglTerminate(EGLDisplay dpy) |
| 666 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 667 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 668 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 669 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 670 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 671 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 672 | RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 673 | |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 674 | if (disp->Initialized) { |
Eric Engestrom | 435ad51 | 2018-04-22 16:48:15 +0200 | [diff] [blame^] | 675 | disp->Driver->Terminate(disp); |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 676 | /* do not reset disp->Driver */ |
Dave Airlie | 37e3a11 | 2015-03-16 15:21:55 +1000 | [diff] [blame] | 677 | disp->ClientAPIsString[0] = 0; |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 678 | disp->Initialized = EGL_FALSE; |
Tapani Pälli | 3e03a3f | 2019-08-22 10:49:36 +0300 | [diff] [blame] | 679 | |
| 680 | /* Reset blob cache funcs on terminate. */ |
| 681 | disp->BlobCacheSet = NULL; |
| 682 | disp->BlobCacheGet = NULL; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 683 | } |
| 684 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 685 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 689 | const char * EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 690 | eglQueryString(EGLDisplay dpy, EGLint name) |
| 691 | { |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 692 | _EGLDisplay *disp; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 693 | const _EGLDriver *drv; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 694 | |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 695 | #if !USE_LIBGLVND |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 696 | if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) { |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 697 | RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString); |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 698 | } |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 699 | #endif |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 700 | |
| 701 | disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 702 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 703 | _EGL_CHECK_DISPLAY(disp, NULL, drv); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 704 | |
Matt Turner | 6c6e2a1 | 2015-03-13 17:00:26 -0700 | [diff] [blame] | 705 | 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 Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 720 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 721 | eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, |
| 722 | EGLint config_size, EGLint *num_config) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 723 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 724 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 725 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 726 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 727 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 728 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 729 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 730 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
Eric Engestrom | 64c7c05 | 2019-01-08 11:14:35 +0000 | [diff] [blame] | 731 | |
| 732 | if (!num_config) |
| 733 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 734 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 735 | ret = _eglGetConfigs(drv, disp, configs, config_size, num_config); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 736 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 737 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 741 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 742 | eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, |
| 743 | EGLint config_size, EGLint *num_config) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 744 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 745 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 746 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 747 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 748 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 749 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 750 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 751 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
Eric Engestrom | 64c7c05 | 2019-01-08 11:14:35 +0000 | [diff] [blame] | 752 | |
| 753 | if (!num_config) |
| 754 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 755 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 756 | ret = _eglChooseConfig(drv, disp, attrib_list, configs, |
| 757 | config_size, num_config); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 758 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 759 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 763 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 764 | eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 765 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 766 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 767 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 768 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 769 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 770 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 771 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 772 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 773 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 774 | _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv); |
Eric Engestrom | 7f848f9 | 2019-06-22 22:31:00 +0100 | [diff] [blame] | 775 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 776 | ret = _eglGetConfigAttrib(drv, disp, conf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 777 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 778 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 782 | EGLContext EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 783 | eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, |
| 784 | const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 785 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 786 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 787 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
| 788 | _EGLContext *share = _eglLookupContext(share_list, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 789 | const _EGLDriver *drv; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 790 | _EGLContext *context; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 791 | EGLContext ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 792 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 793 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT); |
| 794 | |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 795 | _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv); |
| 796 | |
Tapani Pälli | 5876f3c | 2016-10-20 14:11:16 +0300 | [diff] [blame] | 797 | 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 Roberts | 4b17dff | 2014-03-07 18:05:46 +0000 | [diff] [blame] | 800 | RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT); |
Kristian Høgsberg | b90a3e7 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 801 | |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 802 | if (!share && share_list != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 803 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 804 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 805 | context = drv->CreateContext(drv, disp, conf, share, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 806 | ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 807 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 808 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 812 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 813 | eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 814 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 815 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 816 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 817 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 818 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 819 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 820 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 821 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 822 | _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 823 | _eglUnlinkContext(context); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 824 | ret = drv->DestroyContext(drv, disp, context); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 825 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 826 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 830 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 831 | eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, |
| 832 | EGLContext ctx) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 833 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 834 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 835 | _EGLContext *context = _eglLookupContext(ctx, disp); |
| 836 | _EGLSurface *draw_surf = _eglLookupSurface(draw, disp); |
| 837 | _EGLSurface *read_surf = _eglLookupSurface(read, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 838 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 839 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 840 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 841 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 842 | |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 843 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 844 | RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 845 | 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 Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 851 | RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 852 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 853 | if (!drv) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 854 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 855 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 856 | if (!context && ctx != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 857 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 858 | if (!draw_surf || !read_surf) { |
Beren Minor | 0ca0d57 | 2014-03-20 08:36:34 +0100 | [diff] [blame] | 859 | /* 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 Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 865 | 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 Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 873 | |
Chad Versace | 23c86c7 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 874 | /* 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 882 | ret = drv->MakeCurrent(drv, disp, draw_surf, read_surf, context); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 883 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 884 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 888 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 889 | eglQueryContext(EGLDisplay dpy, EGLContext ctx, |
| 890 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 891 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 892 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 893 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 894 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 895 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 896 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 897 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 898 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 899 | _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv); |
Eric Engestrom | b792b3e | 2019-06-22 22:31:26 +0100 | [diff] [blame] | 900 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 901 | ret = _eglQueryContext(drv, disp, context, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 902 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 903 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 907 | /* 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 | */ |
| 911 | static 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 Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 933 | static EGLSurface |
| 934 | _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, |
| 935 | void *native_window, const EGLint *attrib_list) |
| 936 | { |
| 937 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 938 | const _EGLDriver *drv; |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 939 | _EGLSurface *surf; |
| 940 | EGLSurface ret; |
| 941 | |
Sinclair Yeh | 91ff0d4 | 2014-06-03 14:00:13 -0700 | [diff] [blame] | 942 | |
| 943 | if (native_window == NULL) |
| 944 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 945 | |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 946 | if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || |
| 947 | disp->Platform == _EGL_PLATFORM_DEVICE)) { |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 948 | /* 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 Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 962 | |
| 963 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); |
| 964 | |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 965 | if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0) |
| 966 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 967 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 968 | if (_eglNativeSurfaceAlreadyUsed(disp, native_window)) |
| 969 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
| 970 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 971 | surf = drv->CreateWindowSurface(drv, disp, conf, native_window, |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 972 | attrib_list); |
| 973 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
| 974 | |
| 975 | RETURN_EGL_EVAL(disp, ret); |
| 976 | } |
| 977 | |
| 978 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 979 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 980 | eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 981 | EGLNativeWindowType window, const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 982 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 983 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 984 | |
| 985 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 986 | STATIC_ASSERT(sizeof(void*) == sizeof(window)); |
| 987 | return _eglCreateWindowSurfaceCommon(disp, config, (void*) window, |
| 988 | attrib_list); |
| 989 | } |
| 990 | |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 991 | static void * |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 992 | _fixupNativeWindow(_EGLDisplay *disp, void *native_window) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 993 | { |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 994 | #ifdef HAVE_X11_PLATFORM |
Emil Velikov | 26fbb9e | 2017-08-08 15:55:36 +0100 | [diff] [blame] | 995 | if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) { |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 996 | /* 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 Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1003 | return (void *)(* (Window*) native_window); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1004 | } |
| 1005 | #endif |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1006 | return native_window; |
| 1007 | } |
| 1008 | |
| 1009 | static EGLSurface EGLAPIENTRY |
| 1010 | eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, |
| 1011 | void *native_window, |
| 1012 | const EGLint *attrib_list) |
| 1013 | { |
| 1014 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1015 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1016 | native_window = _fixupNativeWindow(disp, native_window); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1017 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1018 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1019 | return _eglCreateWindowSurfaceCommon(disp, config, native_window, |
| 1020 | attrib_list); |
| 1021 | } |
| 1022 | |
| 1023 | |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1024 | EGLSurface EGLAPIENTRY |
| 1025 | eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, |
| 1026 | void *native_window, |
| 1027 | const EGLAttrib *attrib_list) |
| 1028 | { |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1029 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1030 | EGLSurface surface; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1031 | EGLint *int_attribs; |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1032 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1033 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1034 | |
| 1035 | int_attribs = _eglConvertAttribsToInt(attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1036 | if (attrib_list && !int_attribs) |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1037 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1038 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1039 | native_window = _fixupNativeWindow(disp, native_window); |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1040 | surface = _eglCreateWindowSurfaceCommon(disp, config, native_window, |
| 1041 | int_attribs); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1042 | free(int_attribs); |
| 1043 | return surface; |
| 1044 | } |
| 1045 | |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1046 | static void * |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1047 | _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1048 | { |
| 1049 | #ifdef HAVE_X11_PLATFORM |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1050 | /* 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 Velikov | 26fbb9e | 2017-08-08 15:55:36 +0100 | [diff] [blame] | 1057 | if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1058 | return (void *)(* (Pixmap*) native_pixmap); |
| 1059 | #endif |
| 1060 | return native_pixmap; |
| 1061 | } |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1062 | |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1063 | static EGLSurface |
| 1064 | _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config, |
| 1065 | void *native_pixmap, const EGLint *attrib_list) |
| 1066 | { |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1067 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1068 | const _EGLDriver *drv; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1069 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1070 | EGLSurface ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1071 | |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 1072 | if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || |
| 1073 | disp->Platform == _EGL_PLATFORM_DEVICE)) { |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 1074 | /* 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 Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 1086 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1087 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 1088 | |
| 1089 | if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0) |
| 1090 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 1091 | |
Emil Velikov | df8efd5 | 2017-08-05 00:25:48 +0100 | [diff] [blame] | 1092 | if (native_pixmap == NULL) |
| 1093 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); |
| 1094 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 1095 | if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap)) |
| 1096 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
| 1097 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1098 | surf = drv->CreatePixmapSurface(drv, disp, conf, native_pixmap, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1099 | attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1100 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1101 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1102 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1106 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1107 | eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 1108 | EGLNativePixmapType pixmap, const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1109 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1110 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1111 | |
| 1112 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1113 | STATIC_ASSERT(sizeof(void*) == sizeof(pixmap)); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1114 | return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1115 | attrib_list); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1116 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1117 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 1118 | static EGLSurface EGLAPIENTRY |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1119 | eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1120 | void *native_pixmap, |
| 1121 | const EGLint *attrib_list) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1122 | { |
| 1123 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1124 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1125 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1126 | native_pixmap = _fixupNativePixmap(disp, native_pixmap); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1127 | return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, |
| 1128 | attrib_list); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1132 | EGLSurface EGLAPIENTRY |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1133 | eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, |
| 1134 | void *native_pixmap, |
| 1135 | const EGLAttrib *attrib_list) |
| 1136 | { |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1137 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1138 | EGLSurface surface; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1139 | EGLint *int_attribs; |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1140 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1141 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1142 | |
| 1143 | int_attribs = _eglConvertAttribsToInt(attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1144 | if (attrib_list && !int_attribs) |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1145 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1146 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1147 | native_pixmap = _fixupNativePixmap(disp, native_pixmap); |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1148 | surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, |
| 1149 | int_attribs); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1150 | free(int_attribs); |
| 1151 | return surface; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1156 | eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, |
| 1157 | const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1158 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1159 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1160 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1161 | const _EGLDriver *drv; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1162 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1163 | EGLSurface ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1164 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1165 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1166 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1167 | |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 1168 | if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0) |
| 1169 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 1170 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1171 | surf = drv->CreatePbufferSurface(drv, disp, conf, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1172 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1173 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1174 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1178 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1179 | eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 1180 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1181 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1182 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1183 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1184 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1185 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1186 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1187 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1188 | _eglUnlinkSurface(surf); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1189 | ret = drv->DestroySurface(drv, disp, surf); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1190 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1191 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1194 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1195 | eglQuerySurface(EGLDisplay dpy, EGLSurface surface, |
| 1196 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1197 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1198 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1199 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1200 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1201 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1202 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1203 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1204 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Eric Engestrom | 58be9d5 | 2019-06-22 22:31:53 +0100 | [diff] [blame] | 1205 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1206 | if (drv->QuerySurface) |
| 1207 | ret = drv->QuerySurface(drv, disp, surf, attribute, value); |
Eric Engestrom | 58be9d5 | 2019-06-22 22:31:53 +0100 | [diff] [blame] | 1208 | else |
| 1209 | ret = _eglQuerySurface(drv, disp, surf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1210 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1211 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1214 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1215 | eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, |
| 1216 | EGLint attribute, EGLint value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1217 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1218 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1219 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1220 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1221 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1222 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1223 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1224 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Eric Engestrom | 9dc00c8 | 2019-06-22 22:32:26 +0100 | [diff] [blame] | 1225 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 1226 | ret = _eglSurfaceAttrib(drv, disp, surf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1227 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1228 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1232 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1233 | eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1234 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1235 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1236 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1237 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1238 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1239 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1240 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1241 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1242 | ret = drv->BindTexImage(drv, disp, surf, buffer); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1243 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1244 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1248 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1249 | eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1250 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1251 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1252 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1253 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1254 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1255 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1256 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1257 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1258 | ret = drv->ReleaseTexImage(drv, disp, surf, buffer); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1259 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1260 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1264 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1265 | eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 1266 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1267 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1268 | _EGLContext *ctx = _eglGetCurrentContext(); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1269 | _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1270 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1271 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1272 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1273 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1274 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1275 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1276 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1277 | ctx->Resource.Display != disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1278 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1279 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1280 | if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1281 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1282 | |
Emil Velikov | 64b4ccd | 2018-09-03 13:05:22 +0100 | [diff] [blame] | 1283 | if (surf->Type != EGL_WINDOW_BIT) |
| 1284 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1285 | |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1286 | interval = CLAMP(interval, |
| 1287 | surf->Config->MinSwapInterval, |
| 1288 | surf->Config->MaxSwapInterval); |
| 1289 | |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1290 | if (surf->SwapInterval != interval) { |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1291 | if (drv->SwapInterval) |
| 1292 | ret = drv->SwapInterval(drv, disp, surf, interval); |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1293 | else |
| 1294 | ret = _eglSwapInterval(drv, disp, surf, interval); |
| 1295 | } |
| 1296 | else { |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1297 | ret = EGL_TRUE; |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1298 | } |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1299 | |
| 1300 | if (ret) |
| 1301 | surf->SwapInterval = interval; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1302 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1303 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1307 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1308 | eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1309 | { |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1310 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1311 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1312 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1313 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1314 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1315 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1316 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1317 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1318 | |
| 1319 | /* surface must be bound to current context in EGL 1.4 */ |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 1320 | #ifndef _EGL_BUILT_IN_DRIVER_HAIKU |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1321 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1322 | surf != ctx->DrawSurface) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1323 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 1324 | #endif |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1325 | |
Emil Velikov | 8f66743 | 2018-09-03 13:05:23 +0100 | [diff] [blame] | 1326 | if (surf->Type != EGL_WINDOW_BIT) |
| 1327 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1328 | |
Chad Versace | 23c86c7 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 1329 | /* 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1338 | ret = drv->SwapBuffers(drv, disp, surf); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1339 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1340 | /* 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 Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1349 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1353 | static EGLBoolean |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1354 | _eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1355 | const EGLint *rects, EGLint n_rects) |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1356 | { |
| 1357 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1358 | const _EGLDriver *drv; |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1359 | 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 Velikov | 8f66743 | 2018-09-03 13:05:23 +0100 | [diff] [blame] | 1368 | if (surf->Type != EGL_WINDOW_BIT) |
| 1369 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1370 | |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1371 | if ((n_rects > 0 && rects == NULL) || n_rects < 0) |
| 1372 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 1373 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1374 | ret = drv->SwapBuffersWithDamageEXT(drv, disp, surf, rects, n_rects); |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1375 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1376 | /* 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 Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1385 | RETURN_EGL_EVAL(disp, ret); |
| 1386 | } |
| 1387 | |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1388 | static EGLBoolean EGLAPIENTRY |
| 1389 | eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1390 | const EGLint *rects, EGLint n_rects) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1391 | { |
| 1392 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1393 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
| 1394 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1395 | return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | static EGLBoolean EGLAPIENTRY |
| 1399 | eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1400 | const EGLint *rects, EGLint n_rects) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1401 | { |
| 1402 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1403 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
| 1404 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1405 | return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1408 | /** |
Harish Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1409 | * Clamp the rectangles so that they lie within the surface. |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1410 | */ |
| 1411 | |
| 1412 | static 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 Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1421 | 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 Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1426 | |
Harish Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1427 | 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 Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | static EGLBoolean EGLAPIENTRY |
| 1435 | eglSetDamageRegionKHR(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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1442 | const _EGLDriver *drv; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1443 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1461 | ret = drv->SetDamageRegion(drv, disp, surf, rects, n_rects); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1462 | |
| 1463 | if (ret) |
| 1464 | surf->SetDamageRegionCalled = EGL_TRUE; |
| 1465 | |
| 1466 | RETURN_EGL_EVAL(disp, ret); |
| 1467 | } |
| 1468 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1469 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 1470 | eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1471 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1472 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1473 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1474 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1475 | EGLBoolean ret; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1476 | void *native_pixmap_ptr; |
| 1477 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1478 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1479 | STATIC_ASSERT(sizeof(void*) == sizeof(target)); |
| 1480 | native_pixmap_ptr = (void*) target; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1481 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1482 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1483 | ret = drv->CopyBuffers(drv, disp, surf, native_pixmap_ptr); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1484 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1485 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1489 | static EGLBoolean |
| 1490 | _eglWaitClientCommon(void) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1491 | { |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1492 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1493 | _EGLDisplay *disp; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1494 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1495 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1496 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1497 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1498 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1499 | |
| 1500 | disp = ctx->Resource.Display; |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 1501 | mtx_lock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1502 | |
| 1503 | /* let bad current context imply bad current surface */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1504 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1505 | _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1506 | RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1507 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1508 | /* a valid current context implies an initialized current display */ |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 1509 | assert(disp->Initialized); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1510 | drv = disp->Driver; |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1511 | ret = drv->WaitClient(drv, disp, ctx); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1512 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1513 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1514 | } |
| 1515 | |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1516 | EGLBoolean EGLAPIENTRY |
| 1517 | eglWaitClient(void) |
| 1518 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1519 | _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE); |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1520 | return _eglWaitClientCommon(); |
| 1521 | } |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1522 | |
| 1523 | EGLBoolean EGLAPIENTRY |
| 1524 | eglWaitGL(void) |
| 1525 | { |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1526 | /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */ |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1527 | _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE); |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1528 | return _eglWaitClientCommon(); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1532 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1533 | eglWaitNative(EGLint engine) |
| 1534 | { |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1535 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1536 | _EGLDisplay *disp; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1537 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1538 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1539 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1540 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1541 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1542 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1543 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1544 | |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1545 | disp = ctx->Resource.Display; |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 1546 | mtx_lock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1547 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1548 | /* let bad current context imply bad current surface */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1549 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1550 | _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1551 | RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1552 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1553 | /* a valid current context implies an initialized current display */ |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 1554 | assert(disp->Initialized); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1555 | drv = disp->Driver; |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1556 | ret = drv->WaitNative(drv, disp, engine); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1557 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1558 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1562 | EGLDisplay EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1563 | eglGetCurrentDisplay(void) |
| 1564 | { |
Chia-I Wu | a171797 | 2010-01-26 17:13:51 +0800 | [diff] [blame] | 1565 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1566 | EGLDisplay ret; |
| 1567 | |
| 1568 | ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY; |
| 1569 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1570 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1574 | EGLContext EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1575 | eglGetCurrentContext(void) |
| 1576 | { |
| 1577 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1578 | EGLContext ret; |
| 1579 | |
| 1580 | ret = _eglGetContextHandle(ctx); |
| 1581 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1582 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1586 | EGLSurface EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1587 | eglGetCurrentSurface(EGLint readdraw) |
| 1588 | { |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1589 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1590 | EGLint err = EGL_SUCCESS; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1591 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1592 | EGLSurface ret; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1593 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1594 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE); |
| 1595 | |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1596 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1597 | RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE); |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1598 | |
| 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 Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1607 | surf = NULL; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1608 | err = EGL_BAD_PARAMETER; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1609 | break; |
| 1610 | } |
| 1611 | |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1612 | ret = _eglGetSurfaceHandle(surf); |
| 1613 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1614 | RETURN_EGL_ERROR(NULL, err, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1618 | EGLint EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1619 | eglGetError(void) |
| 1620 | { |
Brian Paul | 4882279 | 2005-12-10 17:54:00 +0000 | [diff] [blame] | 1621 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
| 1622 | EGLint e = t->LastError; |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1623 | if (!_eglIsCurrentThreadDummy()) |
| 1624 | t->LastError = EGL_SUCCESS; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1625 | return e; |
| 1626 | } |
| 1627 | |
| 1628 | |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1629 | /** |
| 1630 | ** EGL 1.2 |
| 1631 | **/ |
| 1632 | |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1633 | /** |
| 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 | */ |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1644 | EGLBoolean EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1645 | eglBindAPI(EGLenum api) |
| 1646 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1647 | _EGLThreadInfo *t; |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1648 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1649 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1650 | |
| 1651 | t = _eglGetCurrentThread(); |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1652 | if (_eglIsCurrentThreadDummy()) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1653 | RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE); |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1654 | |
Chia-I Wu | 21b635f | 2009-07-17 11:42:04 -0600 | [diff] [blame] | 1655 | if (!_eglIsApiValid(api)) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1656 | RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE); |
Chia-I Wu | 21b635f | 2009-07-17 11:42:04 -0600 | [diff] [blame] | 1657 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1658 | t->CurrentAPI = api; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1659 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1660 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1661 | } |
Jon Smirl | 7012d01 | 2005-05-13 18:31:35 +0000 | [diff] [blame] | 1662 | |
| 1663 | |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1664 | /** |
| 1665 | * Return the last value set with eglBindAPI(). |
| 1666 | */ |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1667 | EGLenum EGLAPIENTRY |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1668 | eglQueryAPI(void) |
| 1669 | { |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1670 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1671 | EGLenum ret; |
| 1672 | |
| 1673 | /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */ |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1674 | ret = t->CurrentAPI; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1675 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1676 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1680 | EGLSurface EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1681 | eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, |
| 1682 | EGLClientBuffer buffer, EGLConfig config, |
| 1683 | const EGLint *attrib_list) |
| 1684 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1685 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1686 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1687 | const _EGLDriver *drv; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1688 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1689 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1690 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1691 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1692 | |
Eric Engestrom | e9286eb | 2019-06-22 15:53:36 +0100 | [diff] [blame] | 1693 | /* OpenVG is not supported */ |
| 1694 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1695 | } |
Jon Smirl | 7012d01 | 2005-05-13 18:31:35 +0000 | [diff] [blame] | 1696 | |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1697 | |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1698 | EGLBoolean EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1699 | eglReleaseThread(void) |
| 1700 | { |
Chia-I Wu | 11cf3cb | 2010-01-26 17:22:21 +0800 | [diff] [blame] | 1701 | /* unbind current contexts */ |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1702 | if (!_eglIsCurrentThreadDummy()) { |
Chia-I Wu | 11cf3cb | 2010-01-26 17:22:21 +0800 | [diff] [blame] | 1703 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1704 | _EGLContext *ctx = t->CurrentContext; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1705 | |
| 1706 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1707 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1708 | if (ctx) { |
| 1709 | _EGLDisplay *disp = ctx->Resource.Display; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1710 | const _EGLDriver *drv; |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1711 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1712 | mtx_lock(&disp->Mutex); |
| 1713 | drv = disp->Driver; |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1714 | (void) drv->MakeCurrent(drv, disp, NULL, NULL, NULL); |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1715 | mtx_unlock(&disp->Mutex); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1716 | } |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1717 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1718 | |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1719 | _eglDestroyCurrentThread(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1720 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1721 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1725 | static EGLImage |
| 1726 | _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1727 | EGLClientBuffer buffer, const EGLint *attr_list) |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1728 | { |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1729 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1730 | const _EGLDriver *drv; |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1731 | _EGLImage *img; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1732 | EGLImage ret; |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1733 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1734 | _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1735 | if (!disp->Extensions.KHR_image_base) |
| 1736 | RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1737 | if (!context && ctx != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1738 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); |
Topi Pohjolainen | 0de013b | 2013-03-22 14:31:01 +0200 | [diff] [blame] | 1739 | /* "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 Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1744 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1745 | img = drv->CreateImageKHR(drv, disp, context, target, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1746 | buffer, attr_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1747 | ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1748 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1749 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1750 | } |
| 1751 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1752 | static EGLImage EGLAPIENTRY |
| 1753 | eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1754 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1755 | { |
| 1756 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1757 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR); |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1758 | return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list); |
| 1759 | } |
| 1760 | |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1761 | |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1762 | EGLImage EGLAPIENTRY |
| 1763 | eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1764 | EGLClientBuffer buffer, const EGLAttrib *attr_list) |
| 1765 | { |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1766 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1767 | EGLImage image; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1768 | EGLint *int_attribs; |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1769 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1770 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR); |
| 1771 | |
| 1772 | int_attribs = _eglConvertAttribsToInt(attr_list); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1773 | if (attr_list && !int_attribs) |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1774 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1775 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1776 | image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1777 | free(int_attribs); |
| 1778 | return image; |
| 1779 | } |
| 1780 | |
| 1781 | |
Eric Engestrom | df7fa30 | 2017-02-21 23:56:44 +0000 | [diff] [blame] | 1782 | static EGLBoolean |
| 1783 | _eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img) |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1784 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1785 | const _EGLDriver *drv; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1786 | EGLBoolean ret; |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1787 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1788 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1789 | if (!disp->Extensions.KHR_image_base) |
| 1790 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1791 | if (!img) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1792 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1793 | |
| 1794 | _eglUnlinkImage(img); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1795 | ret = drv->DestroyImageKHR(drv, disp, img); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1796 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1797 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1798 | } |
| 1799 | |
Eric Engestrom | df7fa30 | 2017-02-21 23:56:44 +0000 | [diff] [blame] | 1800 | EGLBoolean EGLAPIENTRY |
| 1801 | eglDestroyImage(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 | |
| 1809 | static EGLBoolean EGLAPIENTRY |
| 1810 | eglDestroyImageKHR(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 Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1818 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1819 | static EGLSync |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1820 | _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list, |
| 1821 | EGLBoolean orig_is_EGLAttrib, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1822 | EGLenum invalid_type_error) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1823 | { |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1824 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1825 | const _EGLDriver *drv; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1826 | _EGLSync *sync; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1827 | EGLSync ret; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1828 | |
| 1829 | _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1830 | |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1831 | if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) { |
Chad Versace | f2c2f43 | 2016-09-27 13:27:12 -0700 | [diff] [blame] | 1832 | /* 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šák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1843 | |
Tapani Pälli | 6bf6fcf | 2016-10-25 11:29:53 +0300 | [diff] [blame] | 1844 | /* 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 Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1848 | if (!ctx && |
| 1849 | (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID)) |
Tapani Pälli | 6bf6fcf | 2016-10-25 11:29:53 +0300 | [diff] [blame] | 1850 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); |
| 1851 | |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 1852 | /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */ |
Tapani Pälli | 6bf6fcf | 2016-10-25 11:29:53 +0300 | [diff] [blame] | 1853 | if (ctx && (ctx->Resource.Display != disp || |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 1854 | (ctx->ClientAPI != EGL_OPENGL_ES_API && |
| 1855 | ctx->ClientAPI != EGL_OPENGL_API))) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1856 | 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šák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1861 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1862 | break; |
| 1863 | case EGL_SYNC_REUSABLE_KHR: |
| 1864 | if (!disp->Extensions.KHR_reusable_sync) |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1865 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1866 | break; |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1867 | case EGL_SYNC_CL_EVENT_KHR: |
| 1868 | if (!disp->Extensions.KHR_cl_event2) |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1869 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1870 | break; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1871 | 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šák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1875 | default: |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1876 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1877 | } |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1878 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1879 | sync = drv->CreateSyncKHR(drv, disp, type, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1880 | ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1881 | |
| 1882 | RETURN_EGL_EVAL(disp, ret); |
| 1883 | } |
| 1884 | |
| 1885 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1886 | static EGLSync EGLAPIENTRY |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1887 | eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1888 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1889 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1890 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1891 | |
| 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šák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1905 | EGL_BAD_ATTRIBUTE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1906 | |
| 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šák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | static EGLSync EGLAPIENTRY |
| 1916 | eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) |
| 1917 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1918 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1919 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1920 | return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1921 | EGL_BAD_ATTRIBUTE); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | |
Marek Olšák | 2885ba0 | 2015-05-12 20:54:22 +0200 | [diff] [blame] | 1925 | EGLSync EGLAPIENTRY |
| 1926 | eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1927 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1928 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1929 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1930 | return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1931 | EGL_BAD_PARAMETER); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | |
Eric Engestrom | b7f6f3b | 2017-02-21 23:56:45 +0000 | [diff] [blame] | 1935 | static EGLBoolean |
| 1936 | _eglDestroySync(_EGLDisplay *disp, _EGLSync *s) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1937 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1938 | const _EGLDriver *drv; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1939 | EGLBoolean ret; |
| 1940 | |
| 1941 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1942 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1943 | disp->Extensions.KHR_fence_sync || |
| 1944 | disp->Extensions.ANDROID_native_fence_sync); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1945 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1946 | _eglUnlinkSync(s); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1947 | ret = drv->DestroySyncKHR(drv, disp, s); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1948 | |
| 1949 | RETURN_EGL_EVAL(disp, ret); |
| 1950 | } |
| 1951 | |
Eric Engestrom | b7f6f3b | 2017-02-21 23:56:45 +0000 | [diff] [blame] | 1952 | EGLBoolean EGLAPIENTRY |
| 1953 | eglDestroySync(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 | |
| 1961 | static EGLBoolean EGLAPIENTRY |
| 1962 | eglDestroySyncKHR(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 Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1970 | |
Eric Engestrom | 66d5ec5 | 2017-02-21 23:56:46 +0000 | [diff] [blame] | 1971 | static EGLint |
| 1972 | _eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy, |
| 1973 | _EGLSync *s, EGLint flags, EGLTime timeout) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1974 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 1975 | const _EGLDriver *drv; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1976 | EGLint ret; |
| 1977 | |
| 1978 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1979 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1980 | disp->Extensions.KHR_fence_sync || |
| 1981 | disp->Extensions.ANDROID_native_fence_sync); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1982 | |
| 1983 | if (s->SyncStatus == EGL_SIGNALED_KHR) |
| 1984 | RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR); |
| 1985 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 1986 | /* 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1994 | ret = drv->ClientWaitSyncKHR(drv, disp, s, flags, timeout); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1995 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 1996 | /* |
| 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 Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2004 | } |
| 2005 | |
Eric Engestrom | 66d5ec5 | 2017-02-21 23:56:46 +0000 | [diff] [blame] | 2006 | EGLint EGLAPIENTRY |
| 2007 | eglClientWaitSync(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 | |
| 2016 | static EGLint EGLAPIENTRY |
| 2017 | eglClientWaitSyncKHR(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 Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2026 | |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2027 | static EGLint |
| 2028 | _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags) |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2029 | { |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2030 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2031 | const _EGLDriver *drv; |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2032 | EGLint ret; |
| 2033 | |
| 2034 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); |
| 2035 | assert(disp->Extensions.KHR_wait_sync); |
| 2036 | |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 2037 | /* 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šák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2041 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2047 | ret = drv->WaitSyncKHR(drv, disp, s); |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2048 | |
| 2049 | RETURN_EGL_EVAL(disp, ret); |
| 2050 | } |
| 2051 | |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2052 | static EGLint EGLAPIENTRY |
| 2053 | eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags) |
| 2054 | { |
| 2055 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2056 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2057 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2058 | return _eglWaitSyncCommon(disp, s, flags); |
| 2059 | } |
| 2060 | |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2061 | |
Marek Olšák | 7524592 | 2015-05-12 18:13:31 +0200 | [diff] [blame] | 2062 | EGLBoolean EGLAPIENTRY |
| 2063 | eglWaitSync(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 Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2069 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2070 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2071 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2072 | return _eglWaitSyncCommon(disp, s, flags); |
Marek Olšák | 7524592 | 2015-05-12 18:13:31 +0200 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2076 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2077 | eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2078 | { |
| 2079 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2080 | _EGLSync *s = _eglLookupSync(sync, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2081 | const _EGLDriver *drv; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2082 | EGLBoolean ret; |
| 2083 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2084 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 2085 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2086 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2087 | assert(disp->Extensions.KHR_reusable_sync); |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2088 | ret = drv->SignalSyncKHR(drv, disp, s, mode); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2089 | |
| 2090 | RETURN_EGL_EVAL(disp, ret); |
| 2091 | } |
| 2092 | |
| 2093 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2094 | static EGLBoolean |
| 2095 | _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2096 | { |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2097 | const _EGLDriver *drv; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2098 | EGLBoolean ret; |
| 2099 | |
| 2100 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2101 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2102 | disp->Extensions.KHR_fence_sync || |
| 2103 | disp->Extensions.ANDROID_native_fence_sync); |
Eric Engestrom | 757d2fb | 2019-06-22 22:33:00 +0100 | [diff] [blame] | 2104 | |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 2105 | ret = _eglGetSyncAttrib(drv, disp, s, attribute, value); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2106 | |
| 2107 | RETURN_EGL_EVAL(disp, ret); |
| 2108 | } |
| 2109 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2110 | EGLBoolean EGLAPIENTRY |
| 2111 | eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value) |
| 2112 | { |
| 2113 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2114 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2115 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Tapani Pälli | 99cbec0 | 2019-06-10 13:06:05 +0300 | [diff] [blame] | 2116 | |
| 2117 | if (!value) |
| 2118 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2119 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2120 | return _eglGetSyncAttribCommon(disp, s, attribute, value); |
| 2121 | } |
| 2122 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2123 | |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2124 | static EGLBoolean EGLAPIENTRY |
| 2125 | eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value) |
| 2126 | { |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2127 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2128 | _EGLSync *s = _eglLookupSync(sync, disp); |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2129 | EGLAttrib attrib; |
| 2130 | EGLBoolean result; |
| 2131 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2132 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 2133 | |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2134 | if (!value) |
Chad Versace | 17084b6 | 2016-09-27 23:06:37 -0700 | [diff] [blame] | 2135 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2136 | |
| 2137 | attrib = *value; |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2138 | result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib); |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2139 | |
| 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 Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2151 | static EGLint EGLAPIENTRY |
| 2152 | eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync) |
| 2153 | { |
| 2154 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2155 | _EGLSync *s = _eglLookupSync(sync, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2156 | const _EGLDriver *drv; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2157 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2170 | ret = drv->DupNativeFenceFDANDROID(drv, disp, s); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2171 | |
| 2172 | RETURN_EGL_EVAL(disp, ret); |
| 2173 | } |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2174 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2175 | static EGLBoolean EGLAPIENTRY |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2176 | eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2177 | EGLint numRects, const EGLint *rects) |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2178 | { |
| 2179 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 2180 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2181 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2182 | const _EGLDriver *drv; |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2183 | EGLBoolean ret; |
| 2184 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2185 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2186 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2187 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); |
| 2188 | |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2189 | if (!disp->Extensions.NOK_swap_region) |
| 2190 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
| 2191 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2192 | /* surface must be bound to current context in EGL 1.4 */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 2193 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 2194 | surf != ctx->DrawSurface) |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2195 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
| 2196 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2197 | ret = drv->SwapBuffersRegionNOK(drv, disp, surf, numRects, rects); |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2198 | |
| 2199 | RETURN_EGL_EVAL(disp, ret); |
| 2200 | } |
| 2201 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2202 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2203 | static EGLImage EGLAPIENTRY |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2204 | eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) |
| 2205 | { |
| 2206 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2207 | const _EGLDriver *drv; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2208 | _EGLImage *img; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2209 | EGLImage ret; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2210 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2211 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2212 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2213 | _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2214 | if (!disp->Extensions.MESA_drm_image) |
| 2215 | RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2216 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2217 | img = drv->CreateDRMImageMESA(drv, disp, attr_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 2218 | ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2219 | |
| 2220 | RETURN_EGL_EVAL(disp, ret); |
| 2221 | } |
| 2222 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2223 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2224 | eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2225 | EGLint *name, EGLint *handle, EGLint *stride) |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2226 | { |
| 2227 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2228 | _EGLImage *img = _eglLookupImage(image, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2229 | const _EGLDriver *drv; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2230 | EGLBoolean ret; |
| 2231 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2232 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2233 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2234 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2235 | assert(disp->Extensions.MESA_drm_image); |
| 2236 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2237 | if (!img) |
| 2238 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2239 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2240 | ret = drv->ExportDRMImageMESA(drv, disp, img, name, handle, stride); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2241 | |
| 2242 | RETURN_EGL_EVAL(disp, ret); |
| 2243 | } |
| 2244 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2245 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2246 | struct wl_display; |
| 2247 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2248 | static EGLBoolean EGLAPIENTRY |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2249 | eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display) |
| 2250 | { |
| 2251 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2252 | const _EGLDriver *drv; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2253 | EGLBoolean ret; |
| 2254 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2255 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2256 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2257 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2263 | ret = drv->BindWaylandDisplayWL(drv, disp, display); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2264 | |
| 2265 | RETURN_EGL_EVAL(disp, ret); |
| 2266 | } |
| 2267 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2268 | static EGLBoolean EGLAPIENTRY |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2269 | eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display) |
| 2270 | { |
| 2271 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2272 | const _EGLDriver *drv; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2273 | EGLBoolean ret; |
| 2274 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2275 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2276 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2277 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2283 | ret = drv->UnbindWaylandDisplayWL(drv, disp, display); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2284 | |
| 2285 | RETURN_EGL_EVAL(disp, ret); |
| 2286 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2287 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2288 | static EGLBoolean EGLAPIENTRY |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2289 | eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2290 | EGLint attribute, EGLint *value) |
| 2291 | { |
| 2292 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2293 | const _EGLDriver *drv; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2294 | EGLBoolean ret; |
| 2295 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2296 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2297 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2298 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2304 | ret = drv->QueryWaylandBufferWL(drv, disp, buffer, attribute, value); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2305 | |
| 2306 | RETURN_EGL_EVAL(disp, ret); |
| 2307 | } |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2308 | |
Emil Velikov | 720125f | 2015-07-10 11:22:13 +0100 | [diff] [blame] | 2309 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2310 | static struct wl_buffer * EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2311 | eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image) |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2312 | { |
| 2313 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2314 | _EGLImage *img; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2315 | const _EGLDriver *drv; |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2316 | struct wl_buffer *ret; |
| 2317 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2318 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2319 | |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2320 | _EGL_CHECK_DISPLAY(disp, NULL, drv); |
Emil Velikov | 7013114 | 2017-05-15 16:14:15 +0100 | [diff] [blame] | 2321 | if (!disp->Extensions.WL_create_wayland_buffer_from_image) |
| 2322 | RETURN_EGL_EVAL(disp, NULL); |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2323 | |
| 2324 | img = _eglLookupImage(image, disp); |
| 2325 | |
| 2326 | if (!img) |
| 2327 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL); |
| 2328 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2329 | ret = drv->CreateWaylandBufferFromImageWL(drv, disp, img); |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2330 | |
| 2331 | RETURN_EGL_EVAL(disp, ret); |
| 2332 | } |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2333 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2334 | static EGLBoolean EGLAPIENTRY |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2335 | eglPostSubBufferNV(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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2340 | const _EGLDriver *drv; |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2341 | EGLBoolean ret; |
| 2342 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2343 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2344 | |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2345 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2350 | ret = drv->PostSubBufferNV(drv, disp, surf, x, y, width, height); |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2351 | |
| 2352 | RETURN_EGL_EVAL(disp, ret); |
| 2353 | } |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2354 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2355 | static EGLBoolean EGLAPIENTRY |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2356 | eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2357 | EGLuint64KHR *ust, EGLuint64KHR *msc, |
| 2358 | EGLuint64KHR *sbc) |
| 2359 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2360 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2361 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2362 | const _EGLDriver *drv; |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2363 | EGLBoolean ret; |
| 2364 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2365 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2366 | |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2367 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2374 | ret = drv->GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2375 | |
| 2376 | RETURN_EGL_EVAL(disp, ret); |
| 2377 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2378 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2379 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2380 | eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2381 | EGLint *fourcc, EGLint *nplanes, |
Dave Airlie | b5045e2 | 2015-05-05 09:10:34 +1000 | [diff] [blame] | 2382 | EGLuint64KHR *modifiers) |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2383 | { |
| 2384 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2385 | _EGLImage *img = _eglLookupImage(image, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2386 | const _EGLDriver *drv; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2387 | EGLBoolean ret; |
| 2388 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2389 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2390 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2391 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2397 | ret = drv->ExportDMABUFImageQueryMESA(drv, disp, img, fourcc, nplanes, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2398 | modifiers); |
| 2399 | |
| 2400 | RETURN_EGL_EVAL(disp, ret); |
| 2401 | } |
| 2402 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2403 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2404 | eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2405 | int *fds, EGLint *strides, EGLint *offsets) |
| 2406 | { |
| 2407 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2408 | _EGLImage *img = _eglLookupImage(image, disp); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2409 | const _EGLDriver *drv; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2410 | EGLBoolean ret; |
| 2411 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2412 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2413 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2414 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2420 | ret = drv->ExportDMABUFImageMESA(drv, disp, img, fds, strides, offsets); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2421 | |
| 2422 | RETURN_EGL_EVAL(disp, ret); |
| 2423 | } |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2424 | |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2425 | static EGLint EGLAPIENTRY |
| 2426 | eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2427 | EGLLabelKHR label) |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2428 | { |
| 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 Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2485 | static EGLint EGLAPIENTRY |
| 2486 | eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2487 | const EGLAttrib *attrib_list) |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2488 | { |
| 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 Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2500 | 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 Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2505 | if (attrib_list[i + 1]) |
| 2506 | newEnabled |= DebugBitFromType(attrib_list[i]); |
| 2507 | else |
| 2508 | newEnabled &= ~DebugBitFromType(attrib_list[i]); |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2509 | 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 Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2517 | } |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2518 | } |
| 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 | |
| 2533 | static EGLBoolean EGLAPIENTRY |
| 2534 | eglQueryDebugKHR(EGLint attribute, EGLAttrib *value) |
| 2535 | { |
| 2536 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); |
| 2537 | |
| 2538 | mtx_lock(_eglGlobal.Mutex); |
| 2539 | |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2540 | 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 Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2554 | mtx_unlock(_eglGlobal.Mutex); |
| 2555 | _eglReportError(EGL_BAD_ATTRIBUTE, NULL, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2556 | "Invalid attribute 0x%04lx", (unsigned long) attribute); |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2557 | return EGL_FALSE; |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2558 | } |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2559 | |
| 2560 | mtx_unlock(_eglGlobal.Mutex); |
| 2561 | return EGL_TRUE; |
| 2562 | } |
| 2563 | |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2564 | static 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 Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2572 | static EGLBoolean EGLAPIENTRY |
| 2573 | eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats, |
| 2574 | EGLint *formats, EGLint *num_formats) |
| 2575 | { |
| 2576 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2577 | const _EGLDriver *drv; |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2578 | EGLBoolean ret; |
| 2579 | |
| 2580 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2581 | |
| 2582 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
| 2583 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2584 | ret = drv->QueryDmaBufFormatsEXT(drv, disp, max_formats, formats, |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2585 | num_formats); |
| 2586 | |
| 2587 | RETURN_EGL_EVAL(disp, ret); |
| 2588 | } |
| 2589 | |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2590 | static EGLBoolean EGLAPIENTRY |
| 2591 | eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers, |
| 2592 | EGLuint64KHR *modifiers, EGLBoolean *external_only, |
| 2593 | EGLint *num_modifiers) |
| 2594 | { |
| 2595 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2596 | const _EGLDriver *drv; |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2597 | EGLBoolean ret; |
| 2598 | |
| 2599 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2600 | |
| 2601 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); |
| 2602 | |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2603 | ret = drv->QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers, |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2604 | modifiers, external_only, |
| 2605 | num_modifiers); |
| 2606 | |
| 2607 | RETURN_EGL_EVAL(disp, ret); |
| 2608 | } |
| 2609 | |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2610 | static void EGLAPIENTRY |
| 2611 | eglSetBlobCacheFuncsANDROID(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 Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2624 | const _EGLDriver *drv = _eglCheckDisplay(disp, __func__); |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2625 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2648 | drv->SetBlobCacheFuncsANDROID(drv, disp, set, get); |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2649 | |
| 2650 | _eglUnlockDisplay(disp); |
| 2651 | } |
| 2652 | |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 2653 | static EGLBoolean EGLAPIENTRY |
| 2654 | eglQueryDeviceAttribEXT(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 | |
| 2669 | static const char * EGLAPIENTRY |
| 2670 | eglQueryDeviceStringEXT(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 | |
| 2682 | static EGLBoolean EGLAPIENTRY |
| 2683 | eglQueryDevicesEXT(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 | |
| 2695 | static EGLBoolean EGLAPIENTRY |
| 2696 | eglQueryDisplayAttribEXT(EGLDisplay dpy, |
| 2697 | EGLint attribute, |
| 2698 | EGLAttrib *value) |
| 2699 | { |
| 2700 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2701 | const _EGLDriver *drv; |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 2702 | |
| 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 Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2716 | static char * EGLAPIENTRY |
| 2717 | eglGetDisplayDriverConfig(EGLDisplay dpy) |
| 2718 | { |
| 2719 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2720 | const _EGLDriver *drv; |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2721 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2728 | ret = drv->QueryDriverConfig(disp); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2729 | RETURN_EGL_EVAL(disp, ret); |
| 2730 | } |
| 2731 | |
| 2732 | static const char * EGLAPIENTRY |
| 2733 | eglGetDisplayDriverName(EGLDisplay dpy) |
| 2734 | { |
| 2735 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2736 | const _EGLDriver *drv; |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2737 | 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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2744 | ret = drv->QueryDriverName(disp); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2745 | RETURN_EGL_EVAL(disp, ret); |
| 2746 | } |
| 2747 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2748 | __eglMustCastToProperFunctionPointerType EGLAPIENTRY |
| 2749 | eglGetProcAddress(const char *procname) |
| 2750 | { |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2751 | static const struct _egl_entrypoint egl_functions[] = { |
Eric Engestrom | 3b69c4a | 2017-02-21 23:56:47 +0000 | [diff] [blame] | 2752 | #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f }, |
Eric Engestrom | f92fd4d | 2017-02-21 23:56:49 +0000 | [diff] [blame] | 2753 | #include "eglentrypoint.h" |
Eric Engestrom | 3b69c4a | 2017-02-21 23:56:47 +0000 | [diff] [blame] | 2754 | #undef EGL_ENTRYPOINT |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2755 | }; |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2756 | _EGLProc ret = NULL; |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2757 | |
| 2758 | if (!procname) |
| 2759 | RETURN_EGL_SUCCESS(NULL, NULL); |
| 2760 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2761 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL); |
| 2762 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2763 | if (strncmp(procname, "egl", 3) == 0) { |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2764 | 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 Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2771 | } |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2772 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2773 | if (!ret) |
| 2774 | ret = _eglGetDriverProc(procname); |
| 2775 | |
| 2776 | RETURN_EGL_SUCCESS(NULL, ret); |
| 2777 | } |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2778 | |
| 2779 | static int |
| 2780 | _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context, |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2781 | _EGLDisplay **disp, const _EGLDriver **drv, |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2782 | _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šák | ee39d44 | 2016-11-02 18:59:22 +0100 | [diff] [blame] | 2805 | PUBLIC int |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2806 | MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2807 | struct mesa_glinterop_device_info *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2808 | { |
| 2809 | _EGLDisplay *disp; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2810 | const _EGLDriver *drv; |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2811 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2818 | if (drv->GLInteropQueryDeviceInfo) |
| 2819 | ret = drv->GLInteropQueryDeviceInfo(disp, ctx, out); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2820 | else |
| 2821 | ret = MESA_GLINTEROP_UNSUPPORTED; |
| 2822 | |
| 2823 | _eglUnlockDisplay(disp); |
| 2824 | return ret; |
| 2825 | } |
| 2826 | |
Marek Olšák | ee39d44 | 2016-11-02 18:59:22 +0100 | [diff] [blame] | 2827 | PUBLIC int |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2828 | MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2829 | struct mesa_glinterop_export_in *in, |
| 2830 | struct mesa_glinterop_export_out *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2831 | { |
| 2832 | _EGLDisplay *disp; |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2833 | const _EGLDriver *drv; |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2834 | _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 Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 2841 | if (drv->GLInteropExportObject) |
| 2842 | ret = drv->GLInteropExportObject(disp, ctx, in, out); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2843 | else |
| 2844 | ret = MESA_GLINTEROP_UNSUPPORTED; |
| 2845 | |
| 2846 | _eglUnlockDisplay(disp); |
| 2847 | return ret; |
| 2848 | } |