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 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 141 | #define _EGL_CHECK_DISPLAY(disp, ret) \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 142 | do { \ |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 143 | if (!_eglCheckDisplay(disp, __func__)) \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 144 | RETURN_EGL_ERROR(disp, 0, ret); \ |
| 145 | } while (0) |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 146 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 147 | #define _EGL_CHECK_OBJECT(disp, type, obj, ret) \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 148 | do { \ |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 149 | if (!_eglCheck ## type(disp, obj, __func__)) \ |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 150 | RETURN_EGL_ERROR(disp, 0, ret); \ |
| 151 | } while (0) |
| 152 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 153 | #define _EGL_CHECK_SURFACE(disp, surf, ret) \ |
| 154 | _EGL_CHECK_OBJECT(disp, Surface, surf, ret) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 155 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 156 | #define _EGL_CHECK_CONTEXT(disp, context, ret) \ |
| 157 | _EGL_CHECK_OBJECT(disp, Context, context, ret) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 158 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 159 | #define _EGL_CHECK_CONFIG(disp, conf, ret) \ |
| 160 | _EGL_CHECK_OBJECT(disp, Config, conf, ret) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 161 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 162 | #define _EGL_CHECK_SYNC(disp, s, ret) \ |
| 163 | _EGL_CHECK_OBJECT(disp, Sync, s, ret) |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 164 | |
| 165 | |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 166 | struct _egl_entrypoint { |
| 167 | const char *name; |
| 168 | _EGLProc function; |
| 169 | }; |
| 170 | |
| 171 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 172 | static inline bool |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 173 | _eglCheckDisplay(_EGLDisplay *disp, const char *msg) |
| 174 | { |
| 175 | if (!disp) { |
| 176 | _eglError(EGL_BAD_DISPLAY, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 177 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 178 | } |
| 179 | if (!disp->Initialized) { |
| 180 | _eglError(EGL_NOT_INITIALIZED, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 181 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 182 | } |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 183 | return true; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 187 | static inline bool |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 188 | _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) |
| 189 | { |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 190 | if (!_eglCheckDisplay(disp, msg)) |
| 191 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 192 | if (!surf) { |
| 193 | _eglError(EGL_BAD_SURFACE, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 194 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 195 | } |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 196 | return true; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 200 | static inline bool |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 201 | _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) |
| 202 | { |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 203 | if (!_eglCheckDisplay(disp, msg)) |
| 204 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 205 | if (!context) { |
| 206 | _eglError(EGL_BAD_CONTEXT, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 207 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 208 | } |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 209 | return true; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 213 | static inline bool |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 214 | _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) |
| 215 | { |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 216 | if (!_eglCheckDisplay(disp, msg)) |
| 217 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 218 | if (!conf) { |
| 219 | _eglError(EGL_BAD_CONFIG, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 220 | return false; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 221 | } |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 222 | return true; |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 226 | static inline bool |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 227 | _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) |
| 228 | { |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 229 | if (!_eglCheckDisplay(disp, msg)) |
| 230 | return false; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 231 | if (!s) { |
| 232 | _eglError(EGL_BAD_PARAMETER, msg); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 233 | return false; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 234 | } |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 235 | return true; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
Chia-I Wu | f3e03e1 | 2010-02-17 15:22:03 +0800 | [diff] [blame] | 239 | /** |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 240 | * Lookup and lock a display. |
| 241 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 242 | static inline _EGLDisplay * |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 243 | _eglLockDisplay(EGLDisplay dpy) |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 244 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 245 | _EGLDisplay *disp = _eglLookupDisplay(dpy); |
| 246 | if (disp) |
| 247 | mtx_lock(&disp->Mutex); |
| 248 | return disp; |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
| 252 | /** |
| 253 | * Unlock a display. |
| 254 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 255 | static inline void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 256 | _eglUnlockDisplay(_EGLDisplay *disp) |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 257 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 258 | mtx_unlock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 261 | static EGLBoolean |
| 262 | _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object) |
| 263 | { |
| 264 | _EGLThreadInfo *thr = _eglGetCurrentThread(); |
| 265 | if (!_eglIsCurrentThreadDummy()) { |
| 266 | thr->CurrentFuncName = funcName; |
| 267 | thr->CurrentObjectLabel = NULL; |
| 268 | |
| 269 | if (objectType == EGL_OBJECT_THREAD_KHR) |
| 270 | thr->CurrentObjectLabel = thr->Label; |
| 271 | else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp) |
| 272 | thr->CurrentObjectLabel = disp->Label; |
| 273 | else if (object) |
| 274 | thr->CurrentObjectLabel = object->Label; |
| 275 | |
| 276 | return EGL_TRUE; |
| 277 | } |
| 278 | |
Emil Velikov | b94344f | 2017-09-07 17:03:50 +0100 | [diff] [blame] | 279 | _eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 280 | return EGL_FALSE; |
| 281 | } |
| 282 | |
| 283 | #define _EGL_FUNC_START(disp, objectType, object, ret) \ |
| 284 | do { \ |
| 285 | if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \ |
| 286 | if (disp) \ |
| 287 | _eglUnlockDisplay(disp); \ |
| 288 | return ret; \ |
| 289 | } \ |
| 290 | } while(0) |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 291 | |
Chad Versace | 3e0d575 | 2016-09-27 13:27:17 -0700 | [diff] [blame] | 292 | /** |
| 293 | * Convert an attribute list from EGLint[] to EGLAttrib[]. |
| 294 | * |
| 295 | * Return an EGL error code. The output parameter out_attrib_list is modified |
| 296 | * only on success. |
| 297 | */ |
Eric Engestrom | 9e1d35c | 2016-12-08 00:36:03 +0000 | [diff] [blame] | 298 | static EGLint |
Chad Versace | 3e0d575 | 2016-09-27 13:27:17 -0700 | [diff] [blame] | 299 | _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) |
| 300 | { |
| 301 | size_t len = 0; |
| 302 | EGLAttrib *attrib_list; |
| 303 | |
| 304 | if (int_list) { |
| 305 | while (int_list[2*len] != EGL_NONE) |
| 306 | ++len; |
| 307 | } |
| 308 | |
| 309 | if (len == 0) { |
| 310 | *out_attrib_list = NULL; |
| 311 | return EGL_SUCCESS; |
| 312 | } |
| 313 | |
| 314 | if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib)) |
| 315 | return EGL_BAD_ALLOC; |
| 316 | |
| 317 | attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib)); |
| 318 | if (!attrib_list) |
| 319 | return EGL_BAD_ALLOC; |
| 320 | |
| 321 | for (size_t i = 0; i < len; ++i) { |
| 322 | attrib_list[2*i + 0] = int_list[2*i + 0]; |
| 323 | attrib_list[2*i + 1] = int_list[2*i + 1]; |
| 324 | } |
| 325 | |
| 326 | attrib_list[2*len] = EGL_NONE; |
| 327 | |
| 328 | *out_attrib_list = attrib_list; |
| 329 | return EGL_SUCCESS; |
| 330 | } |
| 331 | |
| 332 | |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 333 | static EGLint * |
| 334 | _eglConvertAttribsToInt(const EGLAttrib *attr_list) |
| 335 | { |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 336 | size_t size = _eglNumAttribs(attr_list); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 337 | EGLint *int_attribs = NULL; |
| 338 | |
| 339 | /* Convert attributes from EGLAttrib[] to EGLint[] */ |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 340 | if (size) { |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 341 | int_attribs = calloc(size, sizeof(int_attribs[0])); |
| 342 | if (!int_attribs) |
| 343 | return NULL; |
| 344 | |
Emil Velikov | 72b9aa9 | 2019-05-16 18:01:33 +0100 | [diff] [blame] | 345 | for (size_t i = 0; i < size; i++) |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 346 | int_attribs[i] = attr_list[i]; |
| 347 | } |
| 348 | return int_attribs; |
| 349 | } |
| 350 | |
| 351 | |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 352 | /** |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 353 | * This is typically the first EGL function that an application calls. |
Chia-I Wu | db5ce8b | 2010-02-17 18:39:27 +0800 | [diff] [blame] | 354 | * It associates a private _EGLDisplay object to the native display. |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 355 | */ |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 356 | EGLDisplay EGLAPIENTRY |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 357 | eglGetDisplay(EGLNativeDisplayType nativeDisplay) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 358 | { |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 359 | _EGLPlatformType plat; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 360 | _EGLDisplay *disp; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 361 | void *native_display_ptr; |
| 362 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 363 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
| 364 | |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 365 | STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay)); |
| 366 | native_display_ptr = (void*) nativeDisplay; |
| 367 | |
| 368 | plat = _eglGetNativePlatform(native_display_ptr); |
Adam Jackson | 8e991ce | 2019-05-16 18:01:34 +0100 | [diff] [blame] | 369 | disp = _eglFindDisplay(plat, native_display_ptr, NULL); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 370 | return _eglGetDisplayHandle(disp); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 373 | static EGLDisplay |
| 374 | _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display, |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 375 | const EGLAttrib *attrib_list) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 376 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 377 | _EGLDisplay *disp; |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 378 | |
| 379 | switch (platform) { |
| 380 | #ifdef HAVE_X11_PLATFORM |
| 381 | case EGL_PLATFORM_X11_EXT: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 382 | disp = _eglGetX11Display((Display*) native_display, attrib_list); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 383 | break; |
| 384 | #endif |
| 385 | #ifdef HAVE_DRM_PLATFORM |
| 386 | case EGL_PLATFORM_GBM_MESA: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 387 | disp = _eglGetGbmDisplay((struct gbm_device*) native_display, |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 388 | attrib_list); |
| 389 | break; |
| 390 | #endif |
| 391 | #ifdef HAVE_WAYLAND_PLATFORM |
| 392 | case EGL_PLATFORM_WAYLAND_EXT: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 393 | disp = _eglGetWaylandDisplay((struct wl_display*) native_display, |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 394 | attrib_list); |
| 395 | break; |
| 396 | #endif |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 397 | case EGL_PLATFORM_SURFACELESS_MESA: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 398 | disp = _eglGetSurfacelessDisplay(native_display, attrib_list); |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 399 | break; |
renchenglei | 500b45a | 2019-06-28 15:21:08 +0800 | [diff] [blame] | 400 | #ifdef HAVE_ANDROID_PLATFORM |
| 401 | case EGL_PLATFORM_ANDROID_KHR: |
| 402 | disp = _eglGetAndroidDisplay(native_display, attrib_list); |
| 403 | break; |
| 404 | #endif |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 405 | case EGL_PLATFORM_DEVICE_EXT: |
| 406 | disp = _eglGetDeviceDisplay(native_display, attrib_list); |
| 407 | break; |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 408 | default: |
| 409 | RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL); |
| 410 | } |
| 411 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 412 | return _eglGetDisplayHandle(disp); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 413 | } |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 414 | |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 415 | static EGLDisplay EGLAPIENTRY |
| 416 | eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 417 | const EGLint *int_attribs) |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 418 | { |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 419 | EGLAttrib *attrib_list; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 420 | EGLDisplay disp; |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 421 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 422 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 423 | |
| 424 | if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS) |
| 425 | RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL); |
| 426 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 427 | disp = _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 428 | free(attrib_list); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 429 | return disp; |
Kyle Brenneman | 017946b | 2016-09-12 16:42:56 -0400 | [diff] [blame] | 430 | } |
| 431 | |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 432 | EGLDisplay EGLAPIENTRY |
| 433 | eglGetPlatformDisplay(EGLenum platform, void *native_display, |
| 434 | const EGLAttrib *attrib_list) |
| 435 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 436 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_NO_DISPLAY); |
Adam Jackson | ddcd4b0 | 2017-11-16 13:27:27 -0500 | [diff] [blame] | 437 | return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 440 | /** |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 441 | * Copy the extension into the string and update the string pointer. |
| 442 | */ |
| 443 | static EGLint |
| 444 | _eglAppendExtension(char **str, const char *ext) |
| 445 | { |
| 446 | char *s = *str; |
| 447 | size_t len = strlen(ext); |
| 448 | |
| 449 | if (s) { |
| 450 | memcpy(s, ext, len); |
| 451 | s[len++] = ' '; |
| 452 | s[len] = '\0'; |
| 453 | |
| 454 | *str += len; |
| 455 | } |
| 456 | else { |
| 457 | len++; |
| 458 | } |
| 459 | |
| 460 | return (EGLint) len; |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Examine the individual extension enable/disable flags and recompute |
| 465 | * the driver's Extensions string. |
| 466 | */ |
| 467 | static void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 468 | _eglCreateExtensionsString(_EGLDisplay *disp) |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 469 | { |
| 470 | #define _EGL_CHECK_EXTENSION(ext) \ |
| 471 | do { \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 472 | if (disp->Extensions.ext) { \ |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 473 | _eglAppendExtension(&exts, "EGL_" #ext); \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 474 | assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 475 | } \ |
| 476 | } while (0) |
| 477 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 478 | char *exts = disp->ExtensionsString; |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 479 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 480 | /* Please keep these sorted alphabetically. */ |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 481 | _EGL_CHECK_EXTENSION(ANDROID_blob_cache); |
Rob Herring | 8975527 | 2016-02-02 14:23:07 -0600 | [diff] [blame] | 482 | _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 483 | _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 484 | _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync); |
Rob Herring | e21e81a | 2016-02-02 14:23:08 -0600 | [diff] [blame] | 485 | _EGL_CHECK_EXTENSION(ANDROID_recordable); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 486 | |
| 487 | _EGL_CHECK_EXTENSION(CHROMIUM_sync_control); |
| 488 | |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 489 | _EGL_CHECK_EXTENSION(EXT_buffer_age); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 490 | _EGL_CHECK_EXTENSION(EXT_create_context_robustness); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 491 | _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import); |
Varad Gautam | 4c41229 | 2017-05-30 17:23:40 +0530 | [diff] [blame] | 492 | _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers); |
Tapani Pälli | 799b3d1 | 2018-04-05 13:02:36 +0300 | [diff] [blame] | 493 | _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata); |
| 494 | _EGL_CHECK_EXTENSION(EXT_surface_SMPTE2086_metadata); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 495 | _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage); |
| 496 | |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 497 | _EGL_CHECK_EXTENSION(IMG_context_priority); |
| 498 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 499 | _EGL_CHECK_EXTENSION(KHR_cl_event2); |
Emil Velikov | 26541a1 | 2016-12-05 14:42:04 +0000 | [diff] [blame] | 500 | _EGL_CHECK_EXTENSION(KHR_config_attribs); |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 501 | _EGL_CHECK_EXTENSION(KHR_context_flush_control); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 502 | _EGL_CHECK_EXTENSION(KHR_create_context); |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 503 | _EGL_CHECK_EXTENSION(KHR_create_context_no_error); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 504 | _EGL_CHECK_EXTENSION(KHR_fence_sync); |
| 505 | _EGL_CHECK_EXTENSION(KHR_get_all_proc_addresses); |
| 506 | _EGL_CHECK_EXTENSION(KHR_gl_colorspace); |
| 507 | _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image); |
| 508 | _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image); |
| 509 | _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image); |
| 510 | _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 511 | if (disp->Extensions.KHR_image_base && disp->Extensions.KHR_image_pixmap) |
| 512 | disp->Extensions.KHR_image = EGL_TRUE; |
Harish Krupo | 96fc5fb | 2017-12-08 21:29:39 +0530 | [diff] [blame] | 513 | _EGL_CHECK_EXTENSION(KHR_image); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 514 | _EGL_CHECK_EXTENSION(KHR_image_base); |
| 515 | _EGL_CHECK_EXTENSION(KHR_image_pixmap); |
Chad Versace | 3dc2238 | 2018-04-30 22:32:25 -0700 | [diff] [blame] | 516 | _EGL_CHECK_EXTENSION(KHR_mutable_render_buffer); |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 517 | _EGL_CHECK_EXTENSION(KHR_no_config_context); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 518 | _EGL_CHECK_EXTENSION(KHR_partial_update); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 519 | _EGL_CHECK_EXTENSION(KHR_reusable_sync); |
| 520 | _EGL_CHECK_EXTENSION(KHR_surfaceless_context); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 521 | if (disp->Extensions.EXT_swap_buffers_with_damage) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 522 | _eglAppendExtension(&exts, "EGL_KHR_swap_buffers_with_damage"); |
Tapani Pälli | 41f7de4 | 2017-10-31 10:57:42 +0200 | [diff] [blame] | 523 | _EGL_CHECK_EXTENSION(EXT_pixel_format_float); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 524 | _EGL_CHECK_EXTENSION(KHR_wait_sync); |
| 525 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 526 | if (disp->Extensions.KHR_no_config_context) |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 527 | _eglAppendExtension(&exts, "EGL_MESA_configless_context"); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 528 | _EGL_CHECK_EXTENSION(MESA_drm_image); |
| 529 | _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 530 | _EGL_CHECK_EXTENSION(MESA_query_driver); |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 531 | |
| 532 | _EGL_CHECK_EXTENSION(NOK_swap_region); |
| 533 | _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 534 | |
| 535 | _EGL_CHECK_EXTENSION(NV_post_sub_buffer); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 536 | |
Marek Olšák | 32aa1d7 | 2015-06-09 23:08:57 +0200 | [diff] [blame] | 537 | _EGL_CHECK_EXTENSION(WL_bind_wayland_display); |
| 538 | _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image); |
| 539 | |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 540 | #undef _EGL_CHECK_EXTENSION |
| 541 | } |
| 542 | |
| 543 | static void |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 544 | _eglCreateAPIsString(_EGLDisplay *disp) |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 545 | { |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 546 | #define addstr(str) \ |
| 547 | { \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 548 | const size_t old_len = strlen(disp->ClientAPIsString); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 549 | const size_t add_len = sizeof(str); \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 550 | const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 551 | if (old_len + add_len <= max_len) \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 552 | strcat(disp->ClientAPIsString, str " "); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 553 | else \ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 554 | assert(!"disp->ClientAPIsString is not large enough"); \ |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 555 | } |
| 556 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 557 | if (disp->ClientAPIs & EGL_OPENGL_BIT) |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 558 | addstr("OpenGL"); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 559 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 560 | if (disp->ClientAPIs & EGL_OPENGL_ES_BIT || |
| 561 | disp->ClientAPIs & EGL_OPENGL_ES2_BIT || |
| 562 | disp->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) { |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 563 | addstr("OpenGL_ES"); |
Plamena Manolova | 21edd24 | 2016-05-12 18:21:38 +0100 | [diff] [blame] | 564 | } |
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_OPENVG_BIT) |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 567 | addstr("OpenVG"); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 568 | |
Eric Engestrom | aa78b29 | 2018-08-16 15:31:55 +0100 | [diff] [blame] | 569 | #undef addstr |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Marek Olšák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 572 | static void |
| 573 | _eglComputeVersion(_EGLDisplay *disp) |
| 574 | { |
Marek Olšák | 0e4b564 | 2015-05-12 16:40:29 +0200 | [diff] [blame] | 575 | disp->Version = 14; |
Marek Olšák | a1cb407 | 2015-05-11 22:18:04 +0200 | [diff] [blame] | 576 | |
| 577 | if (disp->Extensions.KHR_fence_sync && |
| 578 | disp->Extensions.KHR_cl_event2 && |
| 579 | disp->Extensions.KHR_wait_sync && |
| 580 | disp->Extensions.KHR_image_base && |
| 581 | disp->Extensions.KHR_gl_texture_2D_image && |
| 582 | disp->Extensions.KHR_gl_texture_3D_image && |
| 583 | disp->Extensions.KHR_gl_texture_cubemap_image && |
| 584 | disp->Extensions.KHR_gl_renderbuffer_image && |
| 585 | disp->Extensions.KHR_create_context && |
| 586 | disp->Extensions.EXT_create_context_robustness && |
| 587 | disp->Extensions.KHR_get_all_proc_addresses && |
| 588 | disp->Extensions.KHR_gl_colorspace && |
| 589 | disp->Extensions.KHR_surfaceless_context) |
| 590 | disp->Version = 15; |
Abhishek Kumar | 0bea2a1 | 2020-05-07 22:02:02 +0530 | [diff] [blame] | 591 | |
| 592 | /* For Android P and below limit the EGL version to 1.4 */ |
| 593 | #if defined(ANDROID) && ANDROID_API_LEVEL <= 28 |
| 594 | disp->Version = 14; |
| 595 | #endif |
Marek Olšák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 596 | } |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 597 | |
| 598 | /** |
Brian Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 599 | * This is typically the second EGL function that an application calls. |
| 600 | * Here we load/initialize the actual hardware driver. |
| 601 | */ |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 602 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 603 | eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 604 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 605 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Jonathan White | 7e2458c | 2008-08-06 13:40:03 -0600 | [diff] [blame] | 606 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 607 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 608 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 609 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 610 | RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); |
Brian Paul | c56e15b | 2008-05-28 15:43:41 -0600 | [diff] [blame] | 611 | |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 612 | if (!disp->Initialized) { |
Eric Engestrom | ed3f1e0 | 2020-07-22 01:19:03 +0200 | [diff] [blame] | 613 | if (!_eglInitializeDisplay(disp)) |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 614 | RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); |
Chia-I Wu | 57929ed | 2010-01-19 18:29:21 +0800 | [diff] [blame] | 615 | |
Chia-I Wu | 310c768 | 2009-08-17 15:53:54 +0800 | [diff] [blame] | 616 | /* limit to APIs supported by core */ |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 617 | disp->ClientAPIs &= _EGL_API_ALL_BITS; |
Chad Versace | 7e8ba77 | 2014-11-20 10:26:38 -0800 | [diff] [blame] | 618 | |
| 619 | /* EGL_KHR_get_all_proc_addresses is a corner-case extension. The spec |
| 620 | * classifies it as an EGL display extension, though conceptually it's an |
| 621 | * EGL client extension. |
| 622 | * |
| 623 | * From the EGL_KHR_get_all_proc_addresses spec: |
| 624 | * |
| 625 | * The EGL implementation must expose the name |
| 626 | * EGL_KHR_client_get_all_proc_addresses if and only if it exposes |
| 627 | * EGL_KHR_get_all_proc_addresses and supports |
| 628 | * EGL_EXT_client_extensions. |
| 629 | * |
| 630 | * Mesa unconditionally exposes both client extensions mentioned above, |
| 631 | * so the spec requires that each EGLDisplay unconditionally expose |
| 632 | * EGL_KHR_get_all_proc_addresses also. |
| 633 | */ |
| 634 | disp->Extensions.KHR_get_all_proc_addresses = EGL_TRUE; |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 635 | |
Emil Velikov | 26541a1 | 2016-12-05 14:42:04 +0000 | [diff] [blame] | 636 | /* Extensions is used to provide EGL 1.3 functionality for 1.2 aware |
| 637 | * programs. It is driver agnostic and handled in the main EGL code. |
| 638 | */ |
| 639 | disp->Extensions.KHR_config_attribs = EGL_TRUE; |
| 640 | |
Marek Olšák | efda9c5 | 2015-05-11 22:16:52 +0200 | [diff] [blame] | 641 | _eglComputeVersion(disp); |
Matt Turner | dac2e7d | 2015-03-10 11:41:57 -0700 | [diff] [blame] | 642 | _eglCreateExtensionsString(disp); |
| 643 | _eglCreateAPIsString(disp); |
Emil Velikov | 3593f37 | 2015-07-14 00:19:54 +0100 | [diff] [blame] | 644 | snprintf(disp->VersionString, sizeof(disp->VersionString), |
Eric Engestrom | a96749b | 2017-10-18 16:32:33 +0100 | [diff] [blame] | 645 | "%d.%d", disp->Version / 10, disp->Version % 10); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 646 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 647 | |
| 648 | /* Update applications version of major and minor if not NULL */ |
| 649 | if ((major != NULL) && (minor != NULL)) { |
Marek Olšák | 0e4b564 | 2015-05-12 16:40:29 +0200 | [diff] [blame] | 650 | *major = disp->Version / 10; |
| 651 | *minor = disp->Version % 10; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 652 | } |
| 653 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 654 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 658 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 659 | eglTerminate(EGLDisplay dpy) |
| 660 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 661 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 662 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 663 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 664 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 665 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 666 | RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 667 | |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 668 | if (disp->Initialized) { |
Eric Engestrom | 435ad51 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 669 | disp->Driver->Terminate(disp); |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 670 | /* do not reset disp->Driver */ |
Dave Airlie | 37e3a11 | 2015-03-16 15:21:55 +1000 | [diff] [blame] | 671 | disp->ClientAPIsString[0] = 0; |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 672 | disp->Initialized = EGL_FALSE; |
Tapani Pälli | 3e03a3f | 2019-08-22 10:49:36 +0300 | [diff] [blame] | 673 | |
| 674 | /* Reset blob cache funcs on terminate. */ |
| 675 | disp->BlobCacheSet = NULL; |
| 676 | disp->BlobCacheGet = NULL; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 677 | } |
| 678 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 679 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 683 | const char * EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 684 | eglQueryString(EGLDisplay dpy, EGLint name) |
| 685 | { |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 686 | _EGLDisplay *disp; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 687 | |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 688 | #if !USE_LIBGLVND |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 689 | if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) { |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 690 | RETURN_EGL_SUCCESS(NULL, _eglGlobal.ClientExtensionString); |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 691 | } |
Emil Velikov | 0a884d7 | 2020-04-08 11:46:47 +0100 | [diff] [blame] | 692 | #endif |
Chad Versace | 3c58d4c | 2013-10-11 16:04:55 -0700 | [diff] [blame] | 693 | |
| 694 | disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 695 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, NULL); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 696 | _EGL_CHECK_DISPLAY(disp, NULL); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 697 | |
Matt Turner | 6c6e2a1 | 2015-03-13 17:00:26 -0700 | [diff] [blame] | 698 | switch (name) { |
| 699 | case EGL_VENDOR: |
| 700 | RETURN_EGL_SUCCESS(disp, _EGL_VENDOR_STRING); |
| 701 | case EGL_VERSION: |
| 702 | RETURN_EGL_SUCCESS(disp, disp->VersionString); |
| 703 | case EGL_EXTENSIONS: |
| 704 | RETURN_EGL_SUCCESS(disp, disp->ExtensionsString); |
| 705 | case EGL_CLIENT_APIS: |
| 706 | RETURN_EGL_SUCCESS(disp, disp->ClientAPIsString); |
| 707 | default: |
| 708 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL); |
| 709 | } |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 713 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 714 | eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, |
| 715 | EGLint config_size, EGLint *num_config) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 716 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 717 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 718 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 719 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 720 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 721 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 722 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Eric Engestrom | 64c7c05 | 2019-01-08 11:14:35 +0000 | [diff] [blame] | 723 | |
| 724 | if (!num_config) |
| 725 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 726 | |
Eric Engestrom | 0345a61 | 2018-05-21 19:48:13 +0100 | [diff] [blame] | 727 | ret = _eglGetConfigs(disp, configs, config_size, num_config); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 728 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 729 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 733 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 734 | eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, |
| 735 | EGLint config_size, EGLint *num_config) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 736 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 737 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 738 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 739 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 740 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 741 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 742 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Eric Engestrom | 64c7c05 | 2019-01-08 11:14:35 +0000 | [diff] [blame] | 743 | |
| 744 | if (!num_config) |
| 745 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 746 | |
Eric Engestrom | 0345a61 | 2018-05-21 19:48:13 +0100 | [diff] [blame] | 747 | ret = _eglChooseConfig(disp, attrib_list, configs, |
Eric Engestrom | eeacd66 | 2019-06-14 16:08:44 +0100 | [diff] [blame] | 748 | config_size, num_config); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 749 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 750 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 754 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 755 | eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 756 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 757 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 758 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 759 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 760 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 761 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 762 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 763 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 764 | _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE); |
Eric Engestrom | 7f848f9 | 2019-06-22 22:31:00 +0100 | [diff] [blame] | 765 | |
Eric Engestrom | 0345a61 | 2018-05-21 19:48:13 +0100 | [diff] [blame] | 766 | ret = _eglGetConfigAttrib(disp, conf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 767 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 768 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 772 | EGLContext EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 773 | eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, |
| 774 | const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 775 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 776 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 777 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
| 778 | _EGLContext *share = _eglLookupContext(share_list, disp); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 779 | _EGLContext *context; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 780 | EGLContext ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 781 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 782 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_CONTEXT); |
| 783 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 784 | _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 785 | |
Tapani Pälli | 5876f3c | 2016-10-20 14:11:16 +0300 | [diff] [blame] | 786 | if (config != EGL_NO_CONFIG_KHR) |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 787 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_CONTEXT); |
Tapani Pälli | 5876f3c | 2016-10-20 14:11:16 +0300 | [diff] [blame] | 788 | else if (!disp->Extensions.KHR_no_config_context) |
Neil Roberts | 4b17dff | 2014-03-07 18:05:46 +0000 | [diff] [blame] | 789 | RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT); |
Kristian Høgsberg | b90a3e7 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 790 | |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 791 | if (!share && share_list != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 792 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 793 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 794 | context = disp->Driver->CreateContext(disp, conf, share, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 795 | ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 796 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 797 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 801 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 802 | eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 803 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 804 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 805 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 806 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 807 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 808 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 809 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 810 | _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 811 | _eglUnlinkContext(context); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 812 | ret = disp->Driver->DestroyContext(disp, context); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 813 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 814 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 818 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 819 | eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, |
| 820 | EGLContext ctx) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 821 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 822 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 823 | _EGLContext *context = _eglLookupContext(ctx, disp); |
| 824 | _EGLSurface *draw_surf = _eglLookupSurface(draw, disp); |
| 825 | _EGLSurface *read_surf = _eglLookupSurface(read, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 826 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 827 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 828 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 829 | |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 830 | if (!disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 831 | RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 832 | |
| 833 | /* display is allowed to be uninitialized under certain condition */ |
| 834 | if (!disp->Initialized) { |
| 835 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE || |
| 836 | ctx != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 837 | RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 838 | } |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 839 | if (!disp->Driver) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 840 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
Chia-I Wu | 1733047 | 2010-01-27 23:51:54 +0800 | [diff] [blame] | 841 | |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 842 | if (!context && ctx != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 843 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 844 | if (!draw_surf || !read_surf) { |
Beren Minor | 0ca0d57 | 2014-03-20 08:36:34 +0100 | [diff] [blame] | 845 | /* From the EGL 1.4 (20130211) spec: |
| 846 | * |
| 847 | * To release the current context without assigning a new one, set ctx |
| 848 | * to EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE. |
| 849 | */ |
| 850 | if (!disp->Extensions.KHR_surfaceless_context && ctx != EGL_NO_CONTEXT) |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 851 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
| 852 | |
| 853 | if ((!draw_surf && draw != EGL_NO_SURFACE) || |
| 854 | (!read_surf && read != EGL_NO_SURFACE)) |
| 855 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
| 856 | if (draw_surf || read_surf) |
| 857 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); |
| 858 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 859 | |
Chad Versace | 23c86c7 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 860 | /* If a native window underlying either draw or read is no longer valid, |
| 861 | * an EGL_BAD_NATIVE_WINDOW error is generated. |
| 862 | */ |
| 863 | if (draw_surf && draw_surf->Lost) |
| 864 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); |
| 865 | if (read_surf && read_surf->Lost) |
| 866 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); |
| 867 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 868 | ret = disp->Driver->MakeCurrent(disp, draw_surf, read_surf, context); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 869 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 870 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 874 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 875 | eglQueryContext(EGLDisplay dpy, EGLContext ctx, |
| 876 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 877 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 878 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 879 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 880 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 881 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 882 | _EGL_FUNC_START(disp, EGL_OBJECT_CONTEXT_KHR, context, EGL_FALSE); |
| 883 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 884 | _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE); |
Eric Engestrom | b792b3e | 2019-06-22 22:31:26 +0100 | [diff] [blame] | 885 | |
Eric Engestrom | b981bab | 2020-08-03 17:03:44 +0200 | [diff] [blame] | 886 | ret = _eglQueryContext(context, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 887 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 888 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 892 | /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says |
| 893 | * that if native_surface was already used to create a window or pixmap, we |
| 894 | * can't create a new one. This is what this function checks for. |
| 895 | */ |
| 896 | static bool |
| 897 | _eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface) |
| 898 | { |
| 899 | _EGLResource *list; |
| 900 | |
| 901 | list = disp->ResourceLists[_EGL_RESOURCE_SURFACE]; |
| 902 | while (list) { |
| 903 | _EGLSurface *surf = (_EGLSurface *) list; |
| 904 | |
| 905 | list = list->Next; |
| 906 | |
| 907 | if (surf->Type == EGL_PBUFFER_BIT) |
| 908 | continue; |
| 909 | |
| 910 | if (surf->NativeSurface == native_surface) |
| 911 | return true; |
| 912 | } |
| 913 | |
| 914 | return false; |
| 915 | } |
| 916 | |
| 917 | |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 918 | static EGLSurface |
| 919 | _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, |
| 920 | void *native_window, const EGLint *attrib_list) |
| 921 | { |
| 922 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 923 | _EGLSurface *surf; |
| 924 | EGLSurface ret; |
| 925 | |
Sinclair Yeh | 91ff0d4 | 2014-06-03 14:00:13 -0700 | [diff] [blame] | 926 | |
| 927 | if (native_window == NULL) |
| 928 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 929 | |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 930 | if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || |
| 931 | disp->Platform == _EGL_PLATFORM_DEVICE)) { |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 932 | /* From the EGL_MESA_platform_surfaceless spec (v1): |
| 933 | * |
| 934 | * eglCreatePlatformWindowSurface fails when called with a <display> |
| 935 | * that belongs to the surfaceless platform. It returns |
| 936 | * EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The |
| 937 | * justification for this unconditional failure is that the |
| 938 | * surfaceless platform has no native windows, and therefore the |
| 939 | * <native_window> parameter is always invalid. |
| 940 | * |
| 941 | * This check must occur before checking the EGLConfig, which emits |
| 942 | * EGL_BAD_CONFIG. |
| 943 | */ |
| 944 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 945 | } |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 946 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 947 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE); |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 948 | |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 949 | if ((conf->SurfaceType & EGL_WINDOW_BIT) == 0) |
| 950 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 951 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 952 | if (_eglNativeSurfaceAlreadyUsed(disp, native_window)) |
| 953 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
| 954 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 955 | surf = disp->Driver->CreateWindowSurface(disp, conf, native_window, attrib_list); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 956 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
| 957 | |
| 958 | RETURN_EGL_EVAL(disp, ret); |
| 959 | } |
| 960 | |
| 961 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 962 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 963 | eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 964 | EGLNativeWindowType window, const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 965 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 966 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 967 | |
| 968 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 969 | STATIC_ASSERT(sizeof(void*) == sizeof(window)); |
| 970 | return _eglCreateWindowSurfaceCommon(disp, config, (void*) window, |
| 971 | attrib_list); |
| 972 | } |
| 973 | |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 974 | static void * |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 975 | _fixupNativeWindow(_EGLDisplay *disp, void *native_window) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 976 | { |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 977 | #ifdef HAVE_X11_PLATFORM |
Emil Velikov | 26fbb9e | 2017-08-08 15:55:36 +0100 | [diff] [blame] | 978 | if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) { |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 979 | /* The `native_window` parameter for the X11 platform differs between |
| 980 | * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In |
| 981 | * eglCreateWindowSurface(), the type of `native_window` is an Xlib |
| 982 | * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is |
| 983 | * `Window*`. Convert `Window*` to `Window` because that's what |
| 984 | * dri2_x11_create_window_surface() expects. |
| 985 | */ |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 986 | return (void *)(* (Window*) native_window); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 987 | } |
| 988 | #endif |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 989 | return native_window; |
| 990 | } |
| 991 | |
| 992 | static EGLSurface EGLAPIENTRY |
| 993 | eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, |
| 994 | void *native_window, |
| 995 | const EGLint *attrib_list) |
| 996 | { |
| 997 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 998 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 999 | native_window = _fixupNativeWindow(disp, native_window); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1000 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1001 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1002 | return _eglCreateWindowSurfaceCommon(disp, config, native_window, |
| 1003 | attrib_list); |
| 1004 | } |
| 1005 | |
| 1006 | |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1007 | EGLSurface EGLAPIENTRY |
| 1008 | eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, |
| 1009 | void *native_window, |
| 1010 | const EGLAttrib *attrib_list) |
| 1011 | { |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1012 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1013 | EGLSurface surface; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1014 | EGLint *int_attribs; |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1015 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1016 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1017 | |
| 1018 | int_attribs = _eglConvertAttribsToInt(attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1019 | if (attrib_list && !int_attribs) |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1020 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1021 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1022 | native_window = _fixupNativeWindow(disp, native_window); |
Kyle Brenneman | 7d7ae5e | 2016-09-12 17:04:38 -0400 | [diff] [blame] | 1023 | surface = _eglCreateWindowSurfaceCommon(disp, config, native_window, |
| 1024 | int_attribs); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1025 | free(int_attribs); |
| 1026 | return surface; |
| 1027 | } |
| 1028 | |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1029 | static void * |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1030 | _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1031 | { |
| 1032 | #ifdef HAVE_X11_PLATFORM |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1033 | /* The `native_pixmap` parameter for the X11 platform differs between |
| 1034 | * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In |
| 1035 | * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib |
| 1036 | * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is |
| 1037 | * `Pixmap*`. Convert `Pixmap*` to `Pixmap` because that's what |
| 1038 | * dri2_x11_create_pixmap_surface() expects. |
| 1039 | */ |
Emil Velikov | 26fbb9e | 2017-08-08 15:55:36 +0100 | [diff] [blame] | 1040 | if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1041 | return (void *)(* (Pixmap*) native_pixmap); |
| 1042 | #endif |
| 1043 | return native_pixmap; |
| 1044 | } |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1045 | |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1046 | static EGLSurface |
| 1047 | _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config, |
| 1048 | void *native_pixmap, const EGLint *attrib_list) |
| 1049 | { |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1050 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1051 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1052 | EGLSurface ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1053 | |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 1054 | if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS || |
| 1055 | disp->Platform == _EGL_PLATFORM_DEVICE)) { |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 1056 | /* From the EGL_MESA_platform_surfaceless spec (v1): |
| 1057 | * |
| 1058 | * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface |
| 1059 | * also fails when called with a <display> that belongs to the |
| 1060 | * surfaceless platform. It returns EGL_NO_SURFACE and generates |
| 1061 | * EGL_BAD_NATIVE_PIXMAP. |
| 1062 | * |
| 1063 | * This check must occur before checking the EGLConfig, which emits |
| 1064 | * EGL_BAD_CONFIG. |
| 1065 | */ |
| 1066 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); |
| 1067 | } |
Chad Versace | a597c8a | 2016-10-12 15:48:15 -0700 | [diff] [blame] | 1068 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1069 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE); |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 1070 | |
| 1071 | if ((conf->SurfaceType & EGL_PIXMAP_BIT) == 0) |
| 1072 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 1073 | |
Emil Velikov | df8efd5 | 2017-08-05 00:25:48 +0100 | [diff] [blame] | 1074 | if (native_pixmap == NULL) |
| 1075 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); |
| 1076 | |
Paulo Zanoni | 73055ae | 2019-05-01 16:26:47 -0700 | [diff] [blame] | 1077 | if (_eglNativeSurfaceAlreadyUsed(disp, native_pixmap)) |
| 1078 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
| 1079 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1080 | surf = disp->Driver->CreatePixmapSurface(disp, conf, native_pixmap, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1081 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1082 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1083 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1087 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1088 | eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 1089 | EGLNativePixmapType pixmap, const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1090 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1091 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1092 | |
| 1093 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1094 | STATIC_ASSERT(sizeof(void*) == sizeof(pixmap)); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1095 | return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1096 | attrib_list); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1097 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1098 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 1099 | static EGLSurface EGLAPIENTRY |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1100 | eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1101 | void *native_pixmap, |
| 1102 | const EGLint *attrib_list) |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1103 | { |
| 1104 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1105 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1106 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1107 | native_pixmap = _fixupNativePixmap(disp, native_pixmap); |
Chad Versace | 468cc86 | 2014-01-23 07:26:10 -0800 | [diff] [blame] | 1108 | return _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, |
| 1109 | attrib_list); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1113 | EGLSurface EGLAPIENTRY |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1114 | eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, |
| 1115 | void *native_pixmap, |
| 1116 | const EGLAttrib *attrib_list) |
| 1117 | { |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1118 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1119 | EGLSurface surface; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1120 | EGLint *int_attribs; |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1121 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1122 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1123 | |
| 1124 | int_attribs = _eglConvertAttribsToInt(attrib_list); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1125 | if (attrib_list && !int_attribs) |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1126 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1127 | |
Eric Engestrom | 4729e1b | 2016-12-08 00:36:02 +0000 | [diff] [blame] | 1128 | native_pixmap = _fixupNativePixmap(disp, native_pixmap); |
Kyle Brenneman | 8cc3d98 | 2016-09-12 17:25:56 -0400 | [diff] [blame] | 1129 | surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, |
| 1130 | int_attribs); |
Marek Olšák | 820a4d4 | 2015-05-12 21:06:41 +0200 | [diff] [blame] | 1131 | free(int_attribs); |
| 1132 | return surface; |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | EGLSurface EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1137 | eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, |
| 1138 | const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1139 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1140 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1141 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1142 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1143 | EGLSurface ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1144 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1145 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1146 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1147 | |
Chad Versace | fbb4af9 | 2016-12-16 11:00:13 -0800 | [diff] [blame] | 1148 | if ((conf->SurfaceType & EGL_PBUFFER_BIT) == 0) |
| 1149 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 1150 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1151 | surf = disp->Driver->CreatePbufferSurface(disp, conf, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1152 | ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1153 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1154 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1158 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1159 | eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 1160 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1161 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1162 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1163 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1164 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1165 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1166 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1167 | _eglUnlinkSurface(surf); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1168 | ret = disp->Driver->DestroySurface(disp, surf); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1169 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1170 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1173 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1174 | eglQuerySurface(EGLDisplay dpy, EGLSurface surface, |
| 1175 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1176 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1177 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1178 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1179 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1180 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1181 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1182 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Eric Engestrom | 58be9d5 | 2019-06-22 22:31:53 +0100 | [diff] [blame] | 1183 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1184 | if (disp->Driver->QuerySurface) |
| 1185 | ret = disp->Driver->QuerySurface(disp, surf, attribute, value); |
Eric Engestrom | 58be9d5 | 2019-06-22 22:31:53 +0100 | [diff] [blame] | 1186 | else |
Eric Engestrom | 982ac69 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1187 | ret = _eglQuerySurface(disp, surf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1188 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1189 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1192 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1193 | eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, |
| 1194 | EGLint attribute, EGLint value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1195 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1196 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1197 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1198 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1199 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1200 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1201 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Eric Engestrom | 9dc00c8 | 2019-06-22 22:32:26 +0100 | [diff] [blame] | 1202 | |
Eric Engestrom | b9fb63a | 2020-08-03 17:08:27 +0200 | [diff] [blame] | 1203 | ret = _eglSurfaceAttrib(disp, surf, attribute, value); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1204 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1205 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1209 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1210 | eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1211 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1212 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1213 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1214 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1215 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1216 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1217 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1218 | ret = disp->Driver->BindTexImage(disp, surf, buffer); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1219 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1220 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1224 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1225 | eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1226 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1227 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1228 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1229 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1230 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1231 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1232 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1233 | ret = disp->Driver->ReleaseTexImage(disp, surf, buffer); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1234 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1235 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1239 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1240 | eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 1241 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1242 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1243 | _EGLContext *ctx = _eglGetCurrentContext(); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1244 | _EGLSurface *surf = ctx ? ctx->DrawSurface : NULL; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1245 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1246 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1247 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1248 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1249 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1250 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1251 | ctx->Resource.Display != disp) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1252 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1253 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1254 | if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1255 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
Chia-I Wu | 57da499 | 2009-10-15 11:08:48 +0800 | [diff] [blame] | 1256 | |
Emil Velikov | 64b4ccd | 2018-09-03 13:05:22 +0100 | [diff] [blame] | 1257 | if (surf->Type != EGL_WINDOW_BIT) |
| 1258 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1259 | |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1260 | interval = CLAMP(interval, |
| 1261 | surf->Config->MinSwapInterval, |
| 1262 | surf->Config->MaxSwapInterval); |
| 1263 | |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1264 | if (surf->SwapInterval != interval) { |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1265 | if (disp->Driver->SwapInterval) |
| 1266 | ret = disp->Driver->SwapInterval(disp, surf, interval); |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1267 | else |
Eric Engestrom | 347840c | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1268 | ret = _eglSwapInterval(disp, surf, interval); |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1269 | } |
| 1270 | else { |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1271 | ret = EGL_TRUE; |
Eric Engestrom | 26d5ca4 | 2019-06-22 22:32:50 +0100 | [diff] [blame] | 1272 | } |
Eric Engestrom | 2714a8f | 2017-07-31 14:49:31 +0100 | [diff] [blame] | 1273 | |
| 1274 | if (ret) |
| 1275 | surf->SwapInterval = interval; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1276 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1277 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1281 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1282 | eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1283 | { |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1284 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1285 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1286 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1287 | EGLBoolean ret; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1288 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1289 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1290 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1291 | |
| 1292 | /* 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] | 1293 | #ifndef _EGL_BUILT_IN_DRIVER_HAIKU |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1294 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1295 | surf != ctx->DrawSurface) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1296 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 1297 | #endif |
Chia-I Wu | bbfd0e2 | 2009-10-15 11:08:33 +0800 | [diff] [blame] | 1298 | |
Emil Velikov | 8f66743 | 2018-09-03 13:05:23 +0100 | [diff] [blame] | 1299 | if (surf->Type != EGL_WINDOW_BIT) |
| 1300 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1301 | |
Chad Versace | 23c86c7 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 1302 | /* From the EGL 1.5 spec: |
| 1303 | * |
| 1304 | * If eglSwapBuffers is called and the native window associated with |
| 1305 | * surface is no longer valid, an EGL_BAD_NATIVE_WINDOW error is |
| 1306 | * generated. |
| 1307 | */ |
| 1308 | if (surf->Lost) |
| 1309 | RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_FALSE); |
| 1310 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1311 | ret = disp->Driver->SwapBuffers(disp, surf); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1312 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1313 | /* EGL_KHR_partial_update |
| 1314 | * Frame boundary successfully reached, |
| 1315 | * reset damage region and reset BufferAgeRead |
| 1316 | */ |
| 1317 | if (ret) { |
| 1318 | surf->SetDamageRegionCalled = EGL_FALSE; |
| 1319 | surf->BufferAgeRead = EGL_FALSE; |
| 1320 | } |
| 1321 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1322 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1326 | static EGLBoolean |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1327 | _eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1328 | const EGLint *rects, EGLint n_rects) |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1329 | { |
| 1330 | _EGLContext *ctx = _eglGetCurrentContext(); |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1331 | EGLBoolean ret; |
| 1332 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1333 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1334 | |
| 1335 | /* surface must be bound to current context in EGL 1.4 */ |
| 1336 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1337 | surf != ctx->DrawSurface) |
| 1338 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
| 1339 | |
Emil Velikov | 8f66743 | 2018-09-03 13:05:23 +0100 | [diff] [blame] | 1340 | if (surf->Type != EGL_WINDOW_BIT) |
| 1341 | RETURN_EGL_EVAL(disp, EGL_TRUE); |
| 1342 | |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1343 | if ((n_rects > 0 && rects == NULL) || n_rects < 0) |
| 1344 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 1345 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1346 | ret = disp->Driver->SwapBuffersWithDamageEXT(disp, surf, rects, n_rects); |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1347 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1348 | /* EGL_KHR_partial_update |
| 1349 | * Frame boundary successfully reached, |
| 1350 | * reset damage region and reset BufferAgeRead |
| 1351 | */ |
| 1352 | if (ret) { |
| 1353 | surf->SetDamageRegionCalled = EGL_FALSE; |
| 1354 | surf->BufferAgeRead = EGL_FALSE; |
| 1355 | } |
| 1356 | |
Robert Bragg | 6425b14 | 2013-04-25 13:41:42 +0100 | [diff] [blame] | 1357 | RETURN_EGL_EVAL(disp, ret); |
| 1358 | } |
| 1359 | |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1360 | static EGLBoolean EGLAPIENTRY |
| 1361 | eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1362 | const EGLint *rects, EGLint n_rects) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1363 | { |
| 1364 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1365 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
| 1366 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1367 | return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static EGLBoolean EGLAPIENTRY |
| 1371 | eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, |
Simon Ser | 9a74746 | 2020-05-07 21:49:25 +0200 | [diff] [blame] | 1372 | const EGLint *rects, EGLint n_rects) |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1373 | { |
| 1374 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1375 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
| 1376 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Eric Engestrom | 9702f91 | 2016-11-16 22:29:53 +0000 | [diff] [blame] | 1377 | return _eglSwapBuffersWithDamageCommon(disp, surf, rects, n_rects); |
Eric Engestrom | 0a606a4 | 2016-10-10 17:33:17 +0100 | [diff] [blame] | 1378 | } |
| 1379 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1380 | /** |
Harish Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1381 | * Clamp the rectangles so that they lie within the surface. |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1382 | */ |
| 1383 | |
| 1384 | static void |
Eric Engestrom | 3ef8aac | 2018-05-21 10:42:10 +0100 | [diff] [blame] | 1385 | _eglSetDamageRegionKHRClampRects(_EGLSurface* surf, |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1386 | EGLint *rects, EGLint n_rects) |
| 1387 | { |
| 1388 | EGLint i; |
| 1389 | EGLint surf_height = surf->Height; |
| 1390 | EGLint surf_width = surf->Width; |
| 1391 | |
| 1392 | for (i = 0; i < (4 * n_rects); i += 4) { |
Harish Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1393 | EGLint x1, y1, x2, y2; |
| 1394 | x1 = rects[i]; |
| 1395 | y1 = rects[i + 1]; |
| 1396 | x2 = rects[i + 2] + x1; |
| 1397 | y2 = rects[i + 3] + y1; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1398 | |
Harish Krupo | fd73460 | 2018-07-08 12:53:00 +0530 | [diff] [blame] | 1399 | rects[i] = CLAMP(x1, 0, surf_width); |
| 1400 | rects[i + 1] = CLAMP(y1, 0, surf_height); |
| 1401 | rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i]; |
| 1402 | rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1]; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | static EGLBoolean EGLAPIENTRY |
| 1407 | eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, |
| 1408 | EGLint *rects, EGLint n_rects) |
| 1409 | { |
| 1410 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1411 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
| 1412 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 1413 | _EGLContext *ctx = _eglGetCurrentContext(); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1414 | EGLBoolean ret; |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1415 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1416 | |
| 1417 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1418 | surf->Type != EGL_WINDOW_BIT || |
| 1419 | ctx->DrawSurface != surf || |
| 1420 | surf->SwapBehavior != EGL_BUFFER_DESTROYED) |
| 1421 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); |
| 1422 | |
| 1423 | /* If the damage region is already set or |
| 1424 | * buffer age is not queried between |
| 1425 | * frame boundaries, throw bad access error |
| 1426 | */ |
| 1427 | |
| 1428 | if (surf->SetDamageRegionCalled || !surf->BufferAgeRead) |
| 1429 | RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE); |
| 1430 | |
Eric Engestrom | 3ef8aac | 2018-05-21 10:42:10 +0100 | [diff] [blame] | 1431 | _eglSetDamageRegionKHRClampRects(surf, rects, n_rects); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1432 | ret = disp->Driver->SetDamageRegion(disp, surf, rects, n_rects); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1433 | |
| 1434 | if (ret) |
| 1435 | surf->SetDamageRegionCalled = EGL_TRUE; |
| 1436 | |
| 1437 | RETURN_EGL_EVAL(disp, ret); |
| 1438 | } |
| 1439 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1440 | EGLBoolean EGLAPIENTRY |
Chia-I Wu | 4aed094 | 2010-01-25 11:55:48 +0800 | [diff] [blame] | 1441 | eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1442 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1443 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1444 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1445 | EGLBoolean ret; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1446 | void *native_pixmap_ptr; |
| 1447 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1448 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1449 | STATIC_ASSERT(sizeof(void*) == sizeof(target)); |
| 1450 | native_pixmap_ptr = (void*) target; |
Chia-I Wu | aed7358 | 2010-02-17 15:43:47 +0800 | [diff] [blame] | 1451 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1452 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1453 | ret = disp->Driver->CopyBuffers(disp, surf, native_pixmap_ptr); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1454 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1455 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1459 | static EGLBoolean |
| 1460 | _eglWaitClientCommon(void) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1461 | { |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1462 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1463 | _EGLDisplay *disp; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1464 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1465 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1466 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1467 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1468 | |
| 1469 | disp = ctx->Resource.Display; |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 1470 | mtx_lock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1471 | |
| 1472 | /* let bad current context imply bad current surface */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1473 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1474 | _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1475 | RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1476 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1477 | /* a valid current context implies an initialized current display */ |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 1478 | assert(disp->Initialized); |
Eric Engestrom | 4e65469 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1479 | ret = disp->Driver->WaitClient(disp, ctx); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1480 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1481 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1482 | } |
| 1483 | |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1484 | EGLBoolean EGLAPIENTRY |
| 1485 | eglWaitClient(void) |
| 1486 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1487 | _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE); |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1488 | return _eglWaitClientCommon(); |
| 1489 | } |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1490 | |
| 1491 | EGLBoolean EGLAPIENTRY |
| 1492 | eglWaitGL(void) |
| 1493 | { |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1494 | /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */ |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1495 | _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext(), EGL_FALSE); |
Kyle Brenneman | 82a2e2c | 2016-09-12 17:35:22 -0400 | [diff] [blame] | 1496 | return _eglWaitClientCommon(); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1500 | EGLBoolean EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1501 | eglWaitNative(EGLint engine) |
| 1502 | { |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1503 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1504 | _EGLDisplay *disp; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1505 | EGLBoolean ret; |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1506 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1507 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1508 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1509 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1510 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1511 | |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1512 | disp = ctx->Resource.Display; |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 1513 | mtx_lock(&disp->Mutex); |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1514 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1515 | /* let bad current context imply bad current surface */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1516 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 1517 | _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1518 | RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1519 | |
Chia-I Wu | 6c21c88 | 2009-09-28 14:12:39 +0800 | [diff] [blame] | 1520 | /* a valid current context implies an initialized current display */ |
Chia-I Wu | a933259 | 2010-01-27 23:55:58 +0800 | [diff] [blame] | 1521 | assert(disp->Initialized); |
Eric Engestrom | b8d1c46 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1522 | ret = disp->Driver->WaitNative(engine); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1523 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1524 | RETURN_EGL_EVAL(disp, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1528 | EGLDisplay EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1529 | eglGetCurrentDisplay(void) |
| 1530 | { |
Chia-I Wu | a171797 | 2010-01-26 17:13:51 +0800 | [diff] [blame] | 1531 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1532 | EGLDisplay ret; |
| 1533 | |
| 1534 | ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY; |
| 1535 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1536 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1540 | EGLContext EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1541 | eglGetCurrentContext(void) |
| 1542 | { |
| 1543 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1544 | EGLContext ret; |
| 1545 | |
| 1546 | ret = _eglGetContextHandle(ctx); |
| 1547 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1548 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1552 | EGLSurface EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1553 | eglGetCurrentSurface(EGLint readdraw) |
| 1554 | { |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1555 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1556 | EGLint err = EGL_SUCCESS; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1557 | _EGLSurface *surf; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1558 | EGLSurface ret; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1559 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1560 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_NO_SURFACE); |
| 1561 | |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1562 | if (!ctx) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1563 | RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE); |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1564 | |
| 1565 | switch (readdraw) { |
| 1566 | case EGL_DRAW: |
| 1567 | surf = ctx->DrawSurface; |
| 1568 | break; |
| 1569 | case EGL_READ: |
| 1570 | surf = ctx->ReadSurface; |
| 1571 | break; |
| 1572 | default: |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1573 | surf = NULL; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1574 | err = EGL_BAD_PARAMETER; |
Chia-I Wu | 6190663 | 2009-09-30 15:34:45 +0800 | [diff] [blame] | 1575 | break; |
| 1576 | } |
| 1577 | |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1578 | ret = _eglGetSurfaceHandle(surf); |
| 1579 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1580 | RETURN_EGL_ERROR(NULL, err, ret); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | |
Brian Paul | 1ed1027 | 2008-05-27 13:45:41 -0600 | [diff] [blame] | 1584 | EGLint EGLAPIENTRY |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1585 | eglGetError(void) |
| 1586 | { |
Brian Paul | 4882279 | 2005-12-10 17:54:00 +0000 | [diff] [blame] | 1587 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
| 1588 | EGLint e = t->LastError; |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1589 | if (!_eglIsCurrentThreadDummy()) |
| 1590 | t->LastError = EGL_SUCCESS; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1591 | return e; |
| 1592 | } |
| 1593 | |
| 1594 | |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1595 | /** |
| 1596 | ** EGL 1.2 |
| 1597 | **/ |
| 1598 | |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1599 | /** |
| 1600 | * Specify the client API to use for subsequent calls including: |
| 1601 | * eglCreateContext() |
| 1602 | * eglGetCurrentContext() |
| 1603 | * eglGetCurrentDisplay() |
| 1604 | * eglGetCurrentSurface() |
| 1605 | * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT) |
| 1606 | * eglWaitClient() |
| 1607 | * eglWaitNative() |
| 1608 | * See section 3.7 "Rendering Context" in the EGL specification for details. |
| 1609 | */ |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1610 | EGLBoolean EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1611 | eglBindAPI(EGLenum api) |
| 1612 | { |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1613 | _EGLThreadInfo *t; |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1614 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1615 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1616 | |
| 1617 | t = _eglGetCurrentThread(); |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1618 | if (_eglIsCurrentThreadDummy()) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1619 | RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE); |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1620 | |
Chia-I Wu | 21b635f | 2009-07-17 11:42:04 -0600 | [diff] [blame] | 1621 | if (!_eglIsApiValid(api)) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1622 | RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE); |
Chia-I Wu | 21b635f | 2009-07-17 11:42:04 -0600 | [diff] [blame] | 1623 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1624 | t->CurrentAPI = api; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1625 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1626 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1627 | } |
Jon Smirl | 7012d01 | 2005-05-13 18:31:35 +0000 | [diff] [blame] | 1628 | |
| 1629 | |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1630 | /** |
| 1631 | * Return the last value set with eglBindAPI(). |
| 1632 | */ |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1633 | EGLenum EGLAPIENTRY |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1634 | eglQueryAPI(void) |
| 1635 | { |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1636 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1637 | EGLenum ret; |
| 1638 | |
| 1639 | /* 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] | 1640 | ret = t->CurrentAPI; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1641 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1642 | RETURN_EGL_SUCCESS(NULL, ret); |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1646 | EGLSurface EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1647 | eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, |
| 1648 | EGLClientBuffer buffer, EGLConfig config, |
| 1649 | const EGLint *attrib_list) |
| 1650 | { |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1651 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1652 | _EGLConfig *conf = _eglLookupConfig(config, disp); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1653 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1654 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_SURFACE); |
| 1655 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1656 | _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1657 | |
Eric Engestrom | e9286eb | 2019-06-22 15:53:36 +0100 | [diff] [blame] | 1658 | /* OpenVG is not supported */ |
| 1659 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1660 | } |
Jon Smirl | 7012d01 | 2005-05-13 18:31:35 +0000 | [diff] [blame] | 1661 | |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1662 | |
nobled | c43ab4f | 2010-07-02 19:38:07 -0400 | [diff] [blame] | 1663 | EGLBoolean EGLAPIENTRY |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1664 | eglReleaseThread(void) |
| 1665 | { |
Chia-I Wu | 11cf3cb | 2010-01-26 17:22:21 +0800 | [diff] [blame] | 1666 | /* unbind current contexts */ |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1667 | if (!_eglIsCurrentThreadDummy()) { |
Chia-I Wu | 11cf3cb | 2010-01-26 17:22:21 +0800 | [diff] [blame] | 1668 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1669 | _EGLContext *ctx = t->CurrentContext; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1670 | |
| 1671 | _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); |
| 1672 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1673 | if (ctx) { |
| 1674 | _EGLDisplay *disp = ctx->Resource.Display; |
Chia-I Wu | 655f465 | 2010-02-17 17:30:44 +0800 | [diff] [blame] | 1675 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1676 | mtx_lock(&disp->Mutex); |
Eric Engestrom | 1a17f1d | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1677 | (void) disp->Driver->MakeCurrent(disp, NULL, NULL, NULL); |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 1678 | mtx_unlock(&disp->Mutex); |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1679 | } |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1680 | } |
Chia-I Wu | 2f2cf46 | 2009-08-11 17:09:39 +0800 | [diff] [blame] | 1681 | |
Chia-I Wu | 75da80b | 2009-07-17 11:41:02 -0600 | [diff] [blame] | 1682 | _eglDestroyCurrentThread(); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1683 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1684 | RETURN_EGL_SUCCESS(NULL, EGL_TRUE); |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1688 | static EGLImage |
| 1689 | _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 1690 | EGLClientBuffer buffer, const EGLint *attr_list) |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1691 | { |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1692 | _EGLContext *context = _eglLookupContext(ctx, disp); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1693 | _EGLImage *img; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1694 | EGLImage ret; |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1695 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1696 | _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1697 | if (!disp->Extensions.KHR_image_base) |
| 1698 | RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1699 | if (!context && ctx != EGL_NO_CONTEXT) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1700 | RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); |
Topi Pohjolainen | 0de013b | 2013-03-22 14:31:01 +0200 | [diff] [blame] | 1701 | /* "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid display, |
| 1702 | * <ctx> must be EGL_NO_CONTEXT..." |
| 1703 | */ |
| 1704 | if (ctx != EGL_NO_CONTEXT && target == EGL_LINUX_DMA_BUF_EXT) |
| 1705 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1706 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1707 | img = disp->Driver->CreateImageKHR(disp, context, target, buffer, attr_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1708 | ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1709 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1710 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1711 | } |
| 1712 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1713 | static EGLImage EGLAPIENTRY |
| 1714 | eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1715 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1716 | { |
| 1717 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1718 | _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] | 1719 | return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list); |
| 1720 | } |
| 1721 | |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1722 | |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1723 | EGLImage EGLAPIENTRY |
| 1724 | eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1725 | EGLClientBuffer buffer, const EGLAttrib *attr_list) |
| 1726 | { |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1727 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1728 | EGLImage image; |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1729 | EGLint *int_attribs; |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1730 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1731 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_NO_IMAGE_KHR); |
| 1732 | |
| 1733 | int_attribs = _eglConvertAttribsToInt(attr_list); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1734 | if (attr_list && !int_attribs) |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1735 | RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_IMAGE); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1736 | |
Kyle Brenneman | 58338c6 | 2016-09-12 17:38:13 -0400 | [diff] [blame] | 1737 | image = _eglCreateImageCommon(disp, ctx, target, buffer, int_attribs); |
Marek Olšák | 515f04e | 2015-05-12 20:42:05 +0200 | [diff] [blame] | 1738 | free(int_attribs); |
| 1739 | return image; |
| 1740 | } |
| 1741 | |
| 1742 | |
Eric Engestrom | df7fa30 | 2017-02-21 23:56:44 +0000 | [diff] [blame] | 1743 | static EGLBoolean |
| 1744 | _eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img) |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1745 | { |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1746 | EGLBoolean ret; |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1747 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1748 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1749 | if (!disp->Extensions.KHR_image_base) |
| 1750 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1751 | if (!img) |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1752 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1753 | |
| 1754 | _eglUnlinkImage(img); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1755 | ret = disp->Driver->DestroyImageKHR(disp, img); |
Chia-I Wu | b3bb180 | 2010-02-17 16:05:27 +0800 | [diff] [blame] | 1756 | |
Chia-I Wu | bef4b47 | 2010-02-19 12:08:50 +0800 | [diff] [blame] | 1757 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Eric Engestrom | df7fa30 | 2017-02-21 23:56:44 +0000 | [diff] [blame] | 1760 | EGLBoolean EGLAPIENTRY |
| 1761 | eglDestroyImage(EGLDisplay dpy, EGLImage image) |
| 1762 | { |
| 1763 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1764 | _EGLImage *img = _eglLookupImage(image, disp); |
| 1765 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 1766 | return _eglDestroyImageCommon(disp, img); |
| 1767 | } |
| 1768 | |
| 1769 | static EGLBoolean EGLAPIENTRY |
| 1770 | eglDestroyImageKHR(EGLDisplay dpy, EGLImage image) |
| 1771 | { |
| 1772 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1773 | _EGLImage *img = _eglLookupImage(image, disp); |
| 1774 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 1775 | return _eglDestroyImageCommon(disp, img); |
| 1776 | } |
| 1777 | |
Chia-I Wu | a1c4a8a | 2009-08-15 22:58:13 +0800 | [diff] [blame] | 1778 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1779 | static EGLSync |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1780 | _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list, |
| 1781 | EGLBoolean orig_is_EGLAttrib, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1782 | EGLenum invalid_type_error) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1783 | { |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1784 | _EGLContext *ctx = _eglGetCurrentContext(); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1785 | _EGLSync *sync; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1786 | EGLSync ret; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1787 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1788 | _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1789 | |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1790 | if (!disp->Extensions.KHR_cl_event2 && orig_is_EGLAttrib) { |
Chad Versace | f2c2f43 | 2016-09-27 13:27:12 -0700 | [diff] [blame] | 1791 | /* There exist two EGLAttrib variants of eglCreateSync*: |
| 1792 | * eglCreateSync64KHR which requires EGL_KHR_cl_event2, and eglCreateSync |
| 1793 | * which requires EGL 1.5. Here we use the presence of EGL_KHR_cl_event2 |
| 1794 | * support as a proxy for EGL 1.5 support, even though that's not |
| 1795 | * entirely correct (though _eglComputeVersion does the same). |
| 1796 | * |
| 1797 | * The EGL spec provides no guidance on how to handle unsupported |
| 1798 | * functions. EGL_BAD_MATCH seems reasonable. |
| 1799 | */ |
| 1800 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); |
| 1801 | } |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1802 | |
Tapani Pälli | 6bf6fcf | 2016-10-25 11:29:53 +0300 | [diff] [blame] | 1803 | /* If type is EGL_SYNC_FENCE and no context is current for the bound API |
| 1804 | * (i.e., eglGetCurrentContext returns EGL_NO_CONTEXT ), an EGL_BAD_MATCH |
| 1805 | * error is generated. |
| 1806 | */ |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1807 | if (!ctx && |
| 1808 | (type == EGL_SYNC_FENCE_KHR || type == EGL_SYNC_NATIVE_FENCE_ANDROID)) |
Tapani Pälli | 6bf6fcf | 2016-10-25 11:29:53 +0300 | [diff] [blame] | 1809 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); |
| 1810 | |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 1811 | /* 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] | 1812 | if (ctx && (ctx->Resource.Display != disp || |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 1813 | (ctx->ClientAPI != EGL_OPENGL_ES_API && |
| 1814 | ctx->ClientAPI != EGL_OPENGL_API))) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1815 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SYNC_KHR); |
| 1816 | |
| 1817 | switch (type) { |
| 1818 | case EGL_SYNC_FENCE_KHR: |
| 1819 | if (!disp->Extensions.KHR_fence_sync) |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1820 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1821 | break; |
| 1822 | case EGL_SYNC_REUSABLE_KHR: |
| 1823 | if (!disp->Extensions.KHR_reusable_sync) |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1824 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1825 | break; |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1826 | case EGL_SYNC_CL_EVENT_KHR: |
| 1827 | if (!disp->Extensions.KHR_cl_event2) |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1828 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1829 | break; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1830 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
| 1831 | if (!disp->Extensions.ANDROID_native_fence_sync) |
| 1832 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
| 1833 | break; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1834 | default: |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1835 | RETURN_EGL_ERROR(disp, invalid_type_error, EGL_NO_SYNC_KHR); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1836 | } |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1837 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1838 | sync = disp->Driver->CreateSyncKHR(disp, type, attrib_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 1839 | ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR; |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1840 | |
| 1841 | RETURN_EGL_EVAL(disp, ret); |
| 1842 | } |
| 1843 | |
| 1844 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 1845 | static EGLSync EGLAPIENTRY |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1846 | eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1847 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1848 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1849 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1850 | |
| 1851 | EGLSync sync; |
| 1852 | EGLAttrib *attrib_list; |
| 1853 | EGLint err; |
| 1854 | |
| 1855 | if (sizeof(int_list[0]) == sizeof(attrib_list[0])) { |
| 1856 | attrib_list = (EGLAttrib *) int_list; |
| 1857 | } else { |
| 1858 | err = _eglConvertIntsToAttribs(int_list, &attrib_list); |
| 1859 | if (err != EGL_SUCCESS) |
| 1860 | RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC); |
| 1861 | } |
| 1862 | |
| 1863 | sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1864 | EGL_BAD_ATTRIBUTE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1865 | |
| 1866 | if (sizeof(int_list[0]) != sizeof(attrib_list[0])) |
| 1867 | free(attrib_list); |
| 1868 | |
| 1869 | /* Don't double-unlock the display. _eglCreateSync already unlocked it. */ |
| 1870 | return sync; |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | static EGLSync EGLAPIENTRY |
| 1875 | eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) |
| 1876 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1877 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1878 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1879 | return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1880 | EGL_BAD_ATTRIBUTE); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | |
Marek Olšák | 2885ba0 | 2015-05-12 20:54:22 +0200 | [diff] [blame] | 1884 | EGLSync EGLAPIENTRY |
| 1885 | eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1886 | { |
Kyle Brenneman | 9a99203 | 2016-09-12 17:40:29 -0400 | [diff] [blame] | 1887 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 1888 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 1889 | return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, |
Marek Olšák | 51c8c66 | 2015-05-12 21:41:32 +0200 | [diff] [blame] | 1890 | EGL_BAD_PARAMETER); |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
Eric Engestrom | b7f6f3b | 2017-02-21 23:56:45 +0000 | [diff] [blame] | 1894 | static EGLBoolean |
| 1895 | _eglDestroySync(_EGLDisplay *disp, _EGLSync *s) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1896 | { |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1897 | EGLBoolean ret; |
| 1898 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1899 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1900 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1901 | disp->Extensions.KHR_fence_sync || |
| 1902 | disp->Extensions.ANDROID_native_fence_sync); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 1903 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1904 | _eglUnlinkSync(s); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1905 | ret = disp->Driver->DestroySyncKHR(disp, s); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1906 | |
| 1907 | RETURN_EGL_EVAL(disp, ret); |
| 1908 | } |
| 1909 | |
Eric Engestrom | b7f6f3b | 2017-02-21 23:56:45 +0000 | [diff] [blame] | 1910 | EGLBoolean EGLAPIENTRY |
| 1911 | eglDestroySync(EGLDisplay dpy, EGLSync sync) |
| 1912 | { |
| 1913 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1914 | _EGLSync *s = _eglLookupSync(sync, disp); |
| 1915 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 1916 | return _eglDestroySync(disp, s); |
| 1917 | } |
| 1918 | |
| 1919 | static EGLBoolean EGLAPIENTRY |
| 1920 | eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync) |
| 1921 | { |
| 1922 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1923 | _EGLSync *s = _eglLookupSync(sync, disp); |
| 1924 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 1925 | return _eglDestroySync(disp, s); |
| 1926 | } |
| 1927 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1928 | |
Eric Engestrom | 66d5ec5 | 2017-02-21 23:56:46 +0000 | [diff] [blame] | 1929 | static EGLint |
| 1930 | _eglClientWaitSyncCommon(_EGLDisplay *disp, EGLDisplay dpy, |
| 1931 | _EGLSync *s, EGLint flags, EGLTime timeout) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1932 | { |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1933 | EGLint ret; |
| 1934 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1935 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1936 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 1937 | disp->Extensions.KHR_fence_sync || |
| 1938 | disp->Extensions.ANDROID_native_fence_sync); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 1939 | |
| 1940 | if (s->SyncStatus == EGL_SIGNALED_KHR) |
| 1941 | RETURN_EGL_EVAL(disp, EGL_CONDITION_SATISFIED_KHR); |
| 1942 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 1943 | /* if sync type is EGL_SYNC_REUSABLE_KHR, dpy should be |
| 1944 | * unlocked here to allow other threads also to be able to |
| 1945 | * go into waiting state. |
| 1946 | */ |
| 1947 | |
| 1948 | if (s->Type == EGL_SYNC_REUSABLE_KHR) |
| 1949 | _eglUnlockDisplay(dpy); |
| 1950 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 1951 | ret = disp->Driver->ClientWaitSyncKHR(disp, s, flags, timeout); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1952 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 1953 | /* |
| 1954 | * 'disp' is already unlocked for reusable sync type, |
| 1955 | * so passing 'NULL' to bypass unlocking display. |
| 1956 | */ |
| 1957 | if (s->Type == EGL_SYNC_REUSABLE_KHR) |
| 1958 | RETURN_EGL_EVAL(NULL, ret); |
| 1959 | else |
| 1960 | RETURN_EGL_EVAL(disp, ret); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1961 | } |
| 1962 | |
Eric Engestrom | 66d5ec5 | 2017-02-21 23:56:46 +0000 | [diff] [blame] | 1963 | EGLint EGLAPIENTRY |
| 1964 | eglClientWaitSync(EGLDisplay dpy, EGLSync sync, |
| 1965 | EGLint flags, EGLTime timeout) |
| 1966 | { |
| 1967 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1968 | _EGLSync *s = _eglLookupSync(sync, disp); |
| 1969 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 1970 | return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout); |
| 1971 | } |
| 1972 | |
| 1973 | static EGLint EGLAPIENTRY |
| 1974 | eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync, |
| 1975 | EGLint flags, EGLTime timeout) |
| 1976 | { |
| 1977 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 1978 | _EGLSync *s = _eglLookupSync(sync, disp); |
| 1979 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 1980 | return _eglClientWaitSyncCommon(disp, dpy, s, flags, timeout); |
| 1981 | } |
| 1982 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 1983 | |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 1984 | static EGLint |
| 1985 | _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags) |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 1986 | { |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 1987 | _EGLContext *ctx = _eglGetCurrentContext(); |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 1988 | EGLint ret; |
| 1989 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 1990 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE); |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 1991 | assert(disp->Extensions.KHR_wait_sync); |
| 1992 | |
Heinrich Fink | 3aa4f3a | 2019-07-30 15:58:20 +0200 | [diff] [blame] | 1993 | /* return an error if the client API doesn't support GL_[OES|MESA]_EGL_sync. */ |
| 1994 | if (ctx == EGL_NO_CONTEXT || |
| 1995 | (ctx->ClientAPI != EGL_OPENGL_ES_API && |
| 1996 | ctx->ClientAPI != EGL_OPENGL_API)) |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 1997 | RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); |
| 1998 | |
| 1999 | /* the API doesn't allow any flags yet */ |
| 2000 | if (flags != 0) |
| 2001 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2002 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2003 | ret = disp->Driver->WaitSyncKHR(disp, s); |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2004 | |
| 2005 | RETURN_EGL_EVAL(disp, ret); |
| 2006 | } |
| 2007 | |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2008 | static EGLint EGLAPIENTRY |
| 2009 | eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags) |
| 2010 | { |
| 2011 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2012 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2013 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2014 | return _eglWaitSyncCommon(disp, s, flags); |
| 2015 | } |
| 2016 | |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2017 | |
Marek Olšák | 7524592 | 2015-05-12 18:13:31 +0200 | [diff] [blame] | 2018 | EGLBoolean EGLAPIENTRY |
| 2019 | eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags) |
| 2020 | { |
| 2021 | /* The KHR version returns EGLint, while the core version returns |
| 2022 | * EGLBoolean. In both cases, the return values can only be EGL_FALSE and |
| 2023 | * EGL_TRUE. |
| 2024 | */ |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2025 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2026 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2027 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Kyle Brenneman | 5b0b844 | 2016-09-12 17:44:36 -0400 | [diff] [blame] | 2028 | return _eglWaitSyncCommon(disp, s, flags); |
Marek Olšák | 7524592 | 2015-05-12 18:13:31 +0200 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2032 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2033 | eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2034 | { |
| 2035 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2036 | _EGLSync *s = _eglLookupSync(sync, disp); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2037 | EGLBoolean ret; |
| 2038 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2039 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 2040 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2041 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2042 | assert(disp->Extensions.KHR_reusable_sync); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2043 | ret = disp->Driver->SignalSyncKHR(disp, s, mode); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2044 | |
| 2045 | RETURN_EGL_EVAL(disp, ret); |
| 2046 | } |
| 2047 | |
| 2048 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2049 | static EGLBoolean |
| 2050 | _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value) |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2051 | { |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2052 | EGLBoolean ret; |
| 2053 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2054 | _EGL_CHECK_SYNC(disp, s, EGL_FALSE); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2055 | assert(disp->Extensions.KHR_reusable_sync || |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2056 | disp->Extensions.KHR_fence_sync || |
| 2057 | disp->Extensions.ANDROID_native_fence_sync); |
Eric Engestrom | 757d2fb | 2019-06-22 22:33:00 +0100 | [diff] [blame] | 2058 | |
Eric Engestrom | 372c6c4 | 2020-08-03 17:19:30 +0200 | [diff] [blame] | 2059 | ret = _eglGetSyncAttrib(disp, s, attribute, value); |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2060 | |
| 2061 | RETURN_EGL_EVAL(disp, ret); |
| 2062 | } |
| 2063 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2064 | EGLBoolean EGLAPIENTRY |
| 2065 | eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value) |
| 2066 | { |
| 2067 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2068 | _EGLSync *s = _eglLookupSync(sync, disp); |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2069 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
Tapani Pälli | 99cbec0 | 2019-06-10 13:06:05 +0300 | [diff] [blame] | 2070 | |
| 2071 | if (!value) |
| 2072 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2073 | |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2074 | return _eglGetSyncAttribCommon(disp, s, attribute, value); |
| 2075 | } |
| 2076 | |
Chia-I Wu | 4eebea7 | 2010-08-14 23:09:12 +0800 | [diff] [blame] | 2077 | |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2078 | static EGLBoolean EGLAPIENTRY |
| 2079 | eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value) |
| 2080 | { |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2081 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2082 | _EGLSync *s = _eglLookupSync(sync, disp); |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2083 | EGLAttrib attrib; |
| 2084 | EGLBoolean result; |
| 2085 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2086 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 2087 | |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2088 | if (!value) |
Chad Versace | 17084b6 | 2016-09-27 23:06:37 -0700 | [diff] [blame] | 2089 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
Dongwon Kim | d1e1563 | 2016-02-02 15:06:28 -0800 | [diff] [blame] | 2090 | |
| 2091 | attrib = *value; |
Kyle Brenneman | 1d535c1 | 2016-09-12 17:46:04 -0400 | [diff] [blame] | 2092 | result = _eglGetSyncAttribCommon(disp, s, attribute, &attrib); |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2093 | |
| 2094 | /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR: |
| 2095 | * |
| 2096 | * If any error occurs, <*value> is not modified. |
| 2097 | */ |
| 2098 | if (result == EGL_FALSE) |
| 2099 | return result; |
| 2100 | |
| 2101 | *value = attrib; |
| 2102 | return result; |
| 2103 | } |
| 2104 | |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2105 | static EGLint EGLAPIENTRY |
| 2106 | eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync) |
| 2107 | { |
| 2108 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2109 | _EGLSync *s = _eglLookupSync(sync, disp); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2110 | EGLBoolean ret; |
| 2111 | |
| 2112 | _EGL_FUNC_START(disp, EGL_OBJECT_SYNC_KHR, s, EGL_FALSE); |
| 2113 | |
| 2114 | /* the spec doesn't seem to specify what happens if the fence |
| 2115 | * type is not EGL_SYNC_NATIVE_FENCE_ANDROID, but this seems |
| 2116 | * sensible: |
| 2117 | */ |
| 2118 | if (!(s && (s->Type == EGL_SYNC_NATIVE_FENCE_ANDROID))) |
| 2119 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_NATIVE_FENCE_FD_ANDROID); |
| 2120 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2121 | _EGL_CHECK_SYNC(disp, s, EGL_NO_NATIVE_FENCE_FD_ANDROID); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2122 | assert(disp->Extensions.ANDROID_native_fence_sync); |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2123 | ret = disp->Driver->DupNativeFenceFDANDROID(disp, s); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2124 | |
| 2125 | RETURN_EGL_EVAL(disp, ret); |
| 2126 | } |
Marek Olšák | 1e79e05 | 2015-05-12 18:14:31 +0200 | [diff] [blame] | 2127 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2128 | static EGLBoolean EGLAPIENTRY |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2129 | eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2130 | EGLint numRects, const EGLint *rects) |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2131 | { |
| 2132 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 2133 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2134 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2135 | EGLBoolean ret; |
| 2136 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2137 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2138 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2139 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2140 | |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2141 | if (!disp->Extensions.NOK_swap_region) |
| 2142 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
| 2143 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2144 | /* surface must be bound to current context in EGL 1.4 */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 2145 | if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || |
| 2146 | surf != ctx->DrawSurface) |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2147 | RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); |
| 2148 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2149 | ret = disp->Driver->SwapBuffersRegionNOK(disp, surf, numRects, rects); |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2150 | |
| 2151 | RETURN_EGL_EVAL(disp, ret); |
| 2152 | } |
| 2153 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2154 | |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2155 | static EGLImage EGLAPIENTRY |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2156 | eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) |
| 2157 | { |
| 2158 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2159 | _EGLImage *img; |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2160 | EGLImage ret; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2161 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2162 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2163 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2164 | _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2165 | if (!disp->Extensions.MESA_drm_image) |
| 2166 | RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2167 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2168 | img = disp->Driver->CreateDRMImageMESA(disp, attr_list); |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 2169 | ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2170 | |
| 2171 | RETURN_EGL_EVAL(disp, ret); |
| 2172 | } |
| 2173 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2174 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2175 | eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2176 | EGLint *name, EGLint *handle, EGLint *stride) |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2177 | { |
| 2178 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2179 | _EGLImage *img = _eglLookupImage(image, disp); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2180 | EGLBoolean ret; |
| 2181 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2182 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2183 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2184 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Chia-I Wu | 6b2f156 | 2010-09-24 02:42:15 +0800 | [diff] [blame] | 2185 | assert(disp->Extensions.MESA_drm_image); |
| 2186 | |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2187 | if (!img) |
| 2188 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2189 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2190 | ret = disp->Driver->ExportDRMImageMESA(disp, img, name, handle, stride); |
Kristian Høgsberg | b7a8893a | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 2191 | |
| 2192 | RETURN_EGL_EVAL(disp, ret); |
| 2193 | } |
| 2194 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2195 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2196 | struct wl_display; |
| 2197 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2198 | static EGLBoolean EGLAPIENTRY |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2199 | eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display) |
| 2200 | { |
| 2201 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2202 | EGLBoolean ret; |
| 2203 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2204 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2205 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2206 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2207 | assert(disp->Extensions.WL_bind_wayland_display); |
| 2208 | |
| 2209 | if (!display) |
| 2210 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2211 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2212 | ret = disp->Driver->BindWaylandDisplayWL(disp, display); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2213 | |
| 2214 | RETURN_EGL_EVAL(disp, ret); |
| 2215 | } |
| 2216 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2217 | static EGLBoolean EGLAPIENTRY |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2218 | eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display) |
| 2219 | { |
| 2220 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2221 | EGLBoolean ret; |
| 2222 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2223 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2224 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2225 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2226 | assert(disp->Extensions.WL_bind_wayland_display); |
| 2227 | |
| 2228 | if (!display) |
| 2229 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2230 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2231 | ret = disp->Driver->UnbindWaylandDisplayWL(disp, display); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2232 | |
| 2233 | RETURN_EGL_EVAL(disp, ret); |
| 2234 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2235 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2236 | static EGLBoolean EGLAPIENTRY |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2237 | eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2238 | EGLint attribute, EGLint *value) |
| 2239 | { |
| 2240 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2241 | EGLBoolean ret; |
| 2242 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2243 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2244 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2245 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2246 | assert(disp->Extensions.WL_bind_wayland_display); |
| 2247 | |
| 2248 | if (!buffer) |
| 2249 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2250 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2251 | ret = disp->Driver->QueryWaylandBufferWL(disp, buffer, attribute, value); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2252 | |
| 2253 | RETURN_EGL_EVAL(disp, ret); |
| 2254 | } |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2255 | |
Emil Velikov | 720125f | 2015-07-10 11:22:13 +0100 | [diff] [blame] | 2256 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2257 | static struct wl_buffer * EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2258 | eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image) |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2259 | { |
| 2260 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2261 | _EGLImage *img; |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2262 | struct wl_buffer *ret; |
| 2263 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2264 | _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL, EGL_FALSE); |
| 2265 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2266 | _EGL_CHECK_DISPLAY(disp, NULL); |
Emil Velikov | 7013114 | 2017-05-15 16:14:15 +0100 | [diff] [blame] | 2267 | if (!disp->Extensions.WL_create_wayland_buffer_from_image) |
| 2268 | RETURN_EGL_EVAL(disp, NULL); |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2269 | |
| 2270 | img = _eglLookupImage(image, disp); |
| 2271 | |
| 2272 | if (!img) |
| 2273 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, NULL); |
| 2274 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2275 | ret = disp->Driver->CreateWaylandBufferFromImageWL(disp, img); |
Neil Roberts | 5cddb1c | 2013-10-28 15:07:03 +0000 | [diff] [blame] | 2276 | |
| 2277 | RETURN_EGL_EVAL(disp, ret); |
| 2278 | } |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2279 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2280 | static EGLBoolean EGLAPIENTRY |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2281 | eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, |
| 2282 | EGLint x, EGLint y, EGLint width, EGLint height) |
| 2283 | { |
| 2284 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2285 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2286 | EGLBoolean ret; |
| 2287 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2288 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2289 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2290 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2291 | |
| 2292 | if (!disp->Extensions.NV_post_sub_buffer) |
| 2293 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
| 2294 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2295 | ret = disp->Driver->PostSubBufferNV(disp, surf, x, y, width, height); |
Fredrik Höglund | 7d46b45 | 2011-12-14 21:24:09 +0100 | [diff] [blame] | 2296 | |
| 2297 | RETURN_EGL_EVAL(disp, ret); |
| 2298 | } |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2299 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2300 | static EGLBoolean EGLAPIENTRY |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2301 | eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2302 | EGLuint64KHR *ust, EGLuint64KHR *msc, |
| 2303 | EGLuint64KHR *sbc) |
| 2304 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2305 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2306 | _EGLSurface *surf = _eglLookupSurface(surface, disp); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2307 | EGLBoolean ret; |
| 2308 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2309 | _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf, EGL_FALSE); |
| 2310 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2311 | _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2312 | if (!disp->Extensions.CHROMIUM_sync_control) |
| 2313 | RETURN_EGL_EVAL(disp, EGL_FALSE); |
| 2314 | |
| 2315 | if (!ust || !msc || !sbc) |
| 2316 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2317 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2318 | ret = disp->Driver->GetSyncValuesCHROMIUM(disp, surf, ust, msc, sbc); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2319 | |
| 2320 | RETURN_EGL_EVAL(disp, ret); |
| 2321 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2322 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2323 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2324 | eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2325 | EGLint *fourcc, EGLint *nplanes, |
Dave Airlie | b5045e2 | 2015-05-05 09:10:34 +1000 | [diff] [blame] | 2326 | EGLuint64KHR *modifiers) |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2327 | { |
| 2328 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2329 | _EGLImage *img = _eglLookupImage(image, disp); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2330 | EGLBoolean ret; |
| 2331 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2332 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2333 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2334 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2335 | assert(disp->Extensions.MESA_image_dma_buf_export); |
| 2336 | |
| 2337 | if (!img) |
| 2338 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2339 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2340 | ret = disp->Driver->ExportDMABUFImageQueryMESA(disp, img, fourcc, nplanes, modifiers); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2341 | |
| 2342 | RETURN_EGL_EVAL(disp, ret); |
| 2343 | } |
| 2344 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2345 | static EGLBoolean EGLAPIENTRY |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2346 | eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2347 | int *fds, EGLint *strides, EGLint *offsets) |
| 2348 | { |
| 2349 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2350 | _EGLImage *img = _eglLookupImage(image, disp); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2351 | EGLBoolean ret; |
| 2352 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2353 | _EGL_FUNC_START(disp, EGL_OBJECT_IMAGE_KHR, img, EGL_FALSE); |
| 2354 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2355 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2356 | assert(disp->Extensions.MESA_image_dma_buf_export); |
| 2357 | |
| 2358 | if (!img) |
| 2359 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); |
| 2360 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2361 | ret = disp->Driver->ExportDMABUFImageMESA(disp, img, fds, strides, offsets); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2362 | |
| 2363 | RETURN_EGL_EVAL(disp, ret); |
| 2364 | } |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2365 | |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2366 | static EGLint EGLAPIENTRY |
| 2367 | eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2368 | EGLLabelKHR label) |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2369 | { |
| 2370 | _EGLDisplay *disp = NULL; |
| 2371 | _EGLResourceType type; |
| 2372 | |
| 2373 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); |
| 2374 | |
| 2375 | if (objectType == EGL_OBJECT_THREAD_KHR) { |
| 2376 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
| 2377 | |
| 2378 | if (!_eglIsCurrentThreadDummy()) { |
| 2379 | t->Label = label; |
| 2380 | return EGL_SUCCESS; |
| 2381 | } |
| 2382 | |
| 2383 | RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC); |
| 2384 | } |
| 2385 | |
| 2386 | disp = _eglLockDisplay(dpy); |
| 2387 | if (disp == NULL) |
| 2388 | RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY); |
| 2389 | |
| 2390 | if (objectType == EGL_OBJECT_DISPLAY_KHR) { |
| 2391 | if (dpy != (EGLDisplay) object) |
| 2392 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); |
| 2393 | |
| 2394 | disp->Label = label; |
| 2395 | RETURN_EGL_EVAL(disp, EGL_SUCCESS); |
| 2396 | } |
| 2397 | |
| 2398 | switch (objectType) { |
| 2399 | case EGL_OBJECT_CONTEXT_KHR: |
| 2400 | type = _EGL_RESOURCE_CONTEXT; |
| 2401 | break; |
| 2402 | case EGL_OBJECT_SURFACE_KHR: |
| 2403 | type = _EGL_RESOURCE_SURFACE; |
| 2404 | break; |
| 2405 | case EGL_OBJECT_IMAGE_KHR: |
| 2406 | type = _EGL_RESOURCE_IMAGE; |
| 2407 | break; |
| 2408 | case EGL_OBJECT_SYNC_KHR: |
| 2409 | type = _EGL_RESOURCE_SYNC; |
| 2410 | break; |
| 2411 | case EGL_OBJECT_STREAM_KHR: |
| 2412 | default: |
| 2413 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); |
| 2414 | } |
| 2415 | |
| 2416 | if (_eglCheckResource(object, type, disp)) { |
| 2417 | _EGLResource *res = (_EGLResource *) object; |
| 2418 | |
| 2419 | res->Label = label; |
| 2420 | RETURN_EGL_EVAL(disp, EGL_SUCCESS); |
| 2421 | } |
| 2422 | |
| 2423 | RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); |
| 2424 | } |
| 2425 | |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2426 | static EGLint EGLAPIENTRY |
| 2427 | eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2428 | const EGLAttrib *attrib_list) |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2429 | { |
| 2430 | unsigned int newEnabled; |
| 2431 | |
| 2432 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); |
| 2433 | |
| 2434 | mtx_lock(_eglGlobal.Mutex); |
| 2435 | |
| 2436 | newEnabled = _eglGlobal.debugTypesEnabled; |
| 2437 | if (attrib_list != NULL) { |
| 2438 | int i; |
| 2439 | |
| 2440 | for (i = 0; attrib_list[i] != EGL_NONE; i += 2) { |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2441 | switch (attrib_list[i]) { |
| 2442 | case EGL_DEBUG_MSG_CRITICAL_KHR: |
| 2443 | case EGL_DEBUG_MSG_ERROR_KHR: |
| 2444 | case EGL_DEBUG_MSG_WARN_KHR: |
| 2445 | case EGL_DEBUG_MSG_INFO_KHR: |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2446 | if (attrib_list[i + 1]) |
| 2447 | newEnabled |= DebugBitFromType(attrib_list[i]); |
| 2448 | else |
| 2449 | newEnabled &= ~DebugBitFromType(attrib_list[i]); |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2450 | break; |
| 2451 | default: |
| 2452 | // On error, set the last error code, call the current |
| 2453 | // debug callback, and return the error code. |
| 2454 | mtx_unlock(_eglGlobal.Mutex); |
| 2455 | _eglReportError(EGL_BAD_ATTRIBUTE, NULL, |
| 2456 | "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]); |
| 2457 | return EGL_BAD_ATTRIBUTE; |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2458 | } |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | if (callback != NULL) { |
| 2463 | _eglGlobal.debugCallback = callback; |
| 2464 | _eglGlobal.debugTypesEnabled = newEnabled; |
| 2465 | } else { |
| 2466 | _eglGlobal.debugCallback = NULL; |
| 2467 | _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR; |
| 2468 | } |
| 2469 | |
| 2470 | mtx_unlock(_eglGlobal.Mutex); |
| 2471 | return EGL_SUCCESS; |
| 2472 | } |
| 2473 | |
| 2474 | static EGLBoolean EGLAPIENTRY |
| 2475 | eglQueryDebugKHR(EGLint attribute, EGLAttrib *value) |
| 2476 | { |
| 2477 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC); |
| 2478 | |
| 2479 | mtx_lock(_eglGlobal.Mutex); |
| 2480 | |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2481 | switch (attribute) { |
| 2482 | case EGL_DEBUG_MSG_CRITICAL_KHR: |
| 2483 | case EGL_DEBUG_MSG_ERROR_KHR: |
| 2484 | case EGL_DEBUG_MSG_WARN_KHR: |
| 2485 | case EGL_DEBUG_MSG_INFO_KHR: |
| 2486 | if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute)) |
| 2487 | *value = EGL_TRUE; |
| 2488 | else |
| 2489 | *value = EGL_FALSE; |
| 2490 | break; |
| 2491 | case EGL_DEBUG_CALLBACK_KHR: |
| 2492 | *value = (EGLAttrib) _eglGlobal.debugCallback; |
| 2493 | break; |
| 2494 | default: |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2495 | mtx_unlock(_eglGlobal.Mutex); |
| 2496 | _eglReportError(EGL_BAD_ATTRIBUTE, NULL, |
Eric Engestrom | 5f4f5aa | 2017-08-08 16:17:13 +0100 | [diff] [blame] | 2497 | "Invalid attribute 0x%04lx", (unsigned long) attribute); |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2498 | return EGL_FALSE; |
Emil Velikov | 4df0d50 | 2017-09-07 17:03:53 +0100 | [diff] [blame] | 2499 | } |
Kyle Brenneman | ca9f26a | 2016-09-12 17:51:22 -0400 | [diff] [blame] | 2500 | |
| 2501 | mtx_unlock(_eglGlobal.Mutex); |
| 2502 | return EGL_TRUE; |
| 2503 | } |
| 2504 | |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2505 | static int |
| 2506 | _eglFunctionCompare(const void *key, const void *elem) |
| 2507 | { |
| 2508 | const char *procname = key; |
| 2509 | const struct _egl_entrypoint *entrypoint = elem; |
| 2510 | return strcmp(procname, entrypoint->name); |
| 2511 | } |
| 2512 | |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2513 | static EGLBoolean EGLAPIENTRY |
| 2514 | eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats, |
| 2515 | EGLint *formats, EGLint *num_formats) |
| 2516 | { |
| 2517 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2518 | EGLBoolean ret; |
| 2519 | |
| 2520 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2521 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2522 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2523 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2524 | ret = disp->Driver->QueryDmaBufFormatsEXT(disp, max_formats, formats, num_formats); |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2525 | |
| 2526 | RETURN_EGL_EVAL(disp, ret); |
| 2527 | } |
| 2528 | |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2529 | static EGLBoolean EGLAPIENTRY |
| 2530 | eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers, |
| 2531 | EGLuint64KHR *modifiers, EGLBoolean *external_only, |
| 2532 | EGLint *num_modifiers) |
| 2533 | { |
| 2534 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2535 | EGLBoolean ret; |
| 2536 | |
| 2537 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2538 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2539 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2540 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2541 | ret = disp->Driver->QueryDmaBufModifiersEXT(disp, format, max_modifiers, modifiers, |
Eric Engestrom | 1bbb0c7 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2542 | external_only, num_modifiers); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2543 | |
| 2544 | RETURN_EGL_EVAL(disp, ret); |
| 2545 | } |
| 2546 | |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2547 | static void EGLAPIENTRY |
| 2548 | eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set, |
| 2549 | EGLGetBlobFuncANDROID get) |
| 2550 | { |
| 2551 | /* This function does not return anything so we cannot |
| 2552 | * utilize the helper macros _EGL_FUNC_START or _EGL_CHECK_DISPLAY. |
| 2553 | */ |
| 2554 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
| 2555 | if (!_eglSetFuncName(__func__, disp, EGL_OBJECT_DISPLAY_KHR, NULL)) { |
| 2556 | if (disp) |
| 2557 | _eglUnlockDisplay(disp); |
| 2558 | return; |
| 2559 | } |
| 2560 | |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2561 | if (!_eglCheckDisplay(disp, __func__)) { |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2562 | if (disp) |
| 2563 | _eglUnlockDisplay(disp); |
| 2564 | return; |
| 2565 | } |
| 2566 | |
| 2567 | if (!set || !get) { |
| 2568 | _eglError(EGL_BAD_PARAMETER, |
| 2569 | "eglSetBlobCacheFuncsANDROID: NULL handler given"); |
| 2570 | _eglUnlockDisplay(disp); |
| 2571 | return; |
| 2572 | } |
| 2573 | |
| 2574 | if (disp->BlobCacheSet) { |
| 2575 | _eglError(EGL_BAD_PARAMETER, |
| 2576 | "eglSetBlobCacheFuncsANDROID: functions already set"); |
| 2577 | _eglUnlockDisplay(disp); |
| 2578 | return; |
| 2579 | } |
| 2580 | |
| 2581 | disp->BlobCacheSet = set; |
| 2582 | disp->BlobCacheGet = get; |
| 2583 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2584 | disp->Driver->SetBlobCacheFuncsANDROID(disp, set, get); |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 2585 | |
| 2586 | _eglUnlockDisplay(disp); |
| 2587 | } |
| 2588 | |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 2589 | static EGLBoolean EGLAPIENTRY |
| 2590 | eglQueryDeviceAttribEXT(EGLDeviceEXT device, |
| 2591 | EGLint attribute, |
| 2592 | EGLAttrib *value) |
| 2593 | { |
| 2594 | _EGLDevice *dev = _eglLookupDevice(device); |
| 2595 | EGLBoolean ret; |
| 2596 | |
| 2597 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2598 | if (!dev) |
| 2599 | RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, EGL_FALSE); |
| 2600 | |
| 2601 | ret = _eglQueryDeviceAttribEXT(dev, attribute, value); |
| 2602 | RETURN_EGL_EVAL(NULL, ret); |
| 2603 | } |
| 2604 | |
| 2605 | static const char * EGLAPIENTRY |
| 2606 | eglQueryDeviceStringEXT(EGLDeviceEXT device, |
| 2607 | EGLint name) |
| 2608 | { |
| 2609 | _EGLDevice *dev = _eglLookupDevice(device); |
| 2610 | |
| 2611 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL); |
| 2612 | if (!dev) |
| 2613 | RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, NULL); |
| 2614 | |
| 2615 | RETURN_EGL_EVAL(NULL, _eglQueryDeviceStringEXT(dev, name)); |
| 2616 | } |
| 2617 | |
| 2618 | static EGLBoolean EGLAPIENTRY |
| 2619 | eglQueryDevicesEXT(EGLint max_devices, |
| 2620 | EGLDeviceEXT *devices, |
| 2621 | EGLint *num_devices) |
| 2622 | { |
| 2623 | EGLBoolean ret; |
| 2624 | |
| 2625 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
| 2626 | ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices, |
| 2627 | num_devices); |
| 2628 | RETURN_EGL_EVAL(NULL, ret); |
| 2629 | } |
| 2630 | |
| 2631 | static EGLBoolean EGLAPIENTRY |
| 2632 | eglQueryDisplayAttribEXT(EGLDisplay dpy, |
| 2633 | EGLint attribute, |
| 2634 | EGLAttrib *value) |
| 2635 | { |
| 2636 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 2637 | |
| 2638 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2639 | _EGL_CHECK_DISPLAY(disp, EGL_FALSE); |
Emil Velikov | 7552fcb | 2015-07-24 16:19:55 +0200 | [diff] [blame] | 2640 | |
| 2641 | switch (attribute) { |
| 2642 | case EGL_DEVICE_EXT: |
| 2643 | *value = (EGLAttrib) disp->Device; |
| 2644 | break; |
| 2645 | default: |
| 2646 | RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE); |
| 2647 | } |
| 2648 | RETURN_EGL_SUCCESS(disp, EGL_TRUE); |
| 2649 | } |
| 2650 | |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2651 | static char * EGLAPIENTRY |
| 2652 | eglGetDisplayDriverConfig(EGLDisplay dpy) |
| 2653 | { |
| 2654 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2655 | char *ret; |
| 2656 | |
| 2657 | _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2658 | _EGL_CHECK_DISPLAY(disp, NULL); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2659 | |
| 2660 | assert(disp->Extensions.MESA_query_driver); |
| 2661 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2662 | ret = disp->Driver->QueryDriverConfig(disp); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2663 | RETURN_EGL_EVAL(disp, ret); |
| 2664 | } |
| 2665 | |
| 2666 | static const char * EGLAPIENTRY |
| 2667 | eglGetDisplayDriverName(EGLDisplay dpy) |
| 2668 | { |
| 2669 | _EGLDisplay *disp = _eglLockDisplay(dpy); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2670 | const char *ret; |
| 2671 | |
| 2672 | _EGL_FUNC_START(disp, EGL_NONE, NULL, NULL); |
Eric Engestrom | c74628f | 2020-08-03 22:50:42 +0200 | [diff] [blame^] | 2673 | _EGL_CHECK_DISPLAY(disp, NULL); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2674 | |
| 2675 | assert(disp->Extensions.MESA_query_driver); |
| 2676 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2677 | ret = disp->Driver->QueryDriverName(disp); |
Veluri Mithun | 6afce78 | 2019-01-23 22:44:25 +0530 | [diff] [blame] | 2678 | RETURN_EGL_EVAL(disp, ret); |
| 2679 | } |
| 2680 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2681 | __eglMustCastToProperFunctionPointerType EGLAPIENTRY |
| 2682 | eglGetProcAddress(const char *procname) |
| 2683 | { |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2684 | static const struct _egl_entrypoint egl_functions[] = { |
Eric Engestrom | 3b69c4a | 2017-02-21 23:56:47 +0000 | [diff] [blame] | 2685 | #define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f }, |
Eric Engestrom | f92fd4d | 2017-02-21 23:56:49 +0000 | [diff] [blame] | 2686 | #include "eglentrypoint.h" |
Eric Engestrom | 3b69c4a | 2017-02-21 23:56:47 +0000 | [diff] [blame] | 2687 | #undef EGL_ENTRYPOINT |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2688 | }; |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2689 | _EGLProc ret = NULL; |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2690 | |
| 2691 | if (!procname) |
| 2692 | RETURN_EGL_SUCCESS(NULL, NULL); |
| 2693 | |
Kyle Brenneman | 6a5545d | 2016-09-12 17:50:40 -0400 | [diff] [blame] | 2694 | _EGL_FUNC_START(NULL, EGL_NONE, NULL, NULL); |
| 2695 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2696 | if (strncmp(procname, "egl", 3) == 0) { |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2697 | const struct _egl_entrypoint *entrypoint = |
| 2698 | bsearch(procname, |
| 2699 | egl_functions, ARRAY_SIZE(egl_functions), |
| 2700 | sizeof(egl_functions[0]), |
| 2701 | _eglFunctionCompare); |
| 2702 | if (entrypoint) |
| 2703 | ret = entrypoint->function; |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2704 | } |
Eric Engestrom | 1534fc6 | 2017-02-21 23:56:52 +0000 | [diff] [blame] | 2705 | |
Emil Velikov | e3cc5ad | 2015-05-11 23:43:48 +0100 | [diff] [blame] | 2706 | if (!ret) |
| 2707 | ret = _eglGetDriverProc(procname); |
| 2708 | |
| 2709 | RETURN_EGL_SUCCESS(NULL, ret); |
| 2710 | } |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2711 | |
| 2712 | static int |
| 2713 | _eglLockDisplayInterop(EGLDisplay dpy, EGLContext context, |
Eric Engestrom | 37be01b | 2020-08-03 22:48:10 +0200 | [diff] [blame] | 2714 | _EGLDisplay **disp, _EGLContext **ctx) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2715 | { |
| 2716 | |
| 2717 | *disp = _eglLockDisplay(dpy); |
| 2718 | if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) { |
| 2719 | if (*disp) |
| 2720 | _eglUnlockDisplay(*disp); |
| 2721 | return MESA_GLINTEROP_INVALID_DISPLAY; |
| 2722 | } |
| 2723 | |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2724 | *ctx = _eglLookupContext(context, *disp); |
| 2725 | if (!*ctx || |
| 2726 | ((*ctx)->ClientAPI != EGL_OPENGL_API && |
| 2727 | (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) { |
| 2728 | _eglUnlockDisplay(*disp); |
| 2729 | return MESA_GLINTEROP_INVALID_CONTEXT; |
| 2730 | } |
| 2731 | |
| 2732 | return MESA_GLINTEROP_SUCCESS; |
| 2733 | } |
| 2734 | |
Marek Olšák | ee39d44 | 2016-11-02 18:59:22 +0100 | [diff] [blame] | 2735 | PUBLIC int |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2736 | MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2737 | struct mesa_glinterop_device_info *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2738 | { |
| 2739 | _EGLDisplay *disp; |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2740 | _EGLContext *ctx; |
| 2741 | int ret; |
| 2742 | |
Eric Engestrom | 37be01b | 2020-08-03 22:48:10 +0200 | [diff] [blame] | 2743 | ret = _eglLockDisplayInterop(dpy, context, &disp, &ctx); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2744 | if (ret != MESA_GLINTEROP_SUCCESS) |
| 2745 | return ret; |
| 2746 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2747 | if (disp->Driver->GLInteropQueryDeviceInfo) |
| 2748 | ret = disp->Driver->GLInteropQueryDeviceInfo(disp, ctx, out); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2749 | else |
| 2750 | ret = MESA_GLINTEROP_UNSUPPORTED; |
| 2751 | |
| 2752 | _eglUnlockDisplay(disp); |
| 2753 | return ret; |
| 2754 | } |
| 2755 | |
Marek Olšák | ee39d44 | 2016-11-02 18:59:22 +0100 | [diff] [blame] | 2756 | PUBLIC int |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2757 | MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2758 | struct mesa_glinterop_export_in *in, |
| 2759 | struct mesa_glinterop_export_out *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2760 | { |
| 2761 | _EGLDisplay *disp; |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2762 | _EGLContext *ctx; |
| 2763 | int ret; |
| 2764 | |
Eric Engestrom | 37be01b | 2020-08-03 22:48:10 +0200 | [diff] [blame] | 2765 | ret = _eglLockDisplayInterop(dpy, context, &disp, &ctx); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2766 | if (ret != MESA_GLINTEROP_SUCCESS) |
| 2767 | return ret; |
| 2768 | |
Eric Engestrom | 5eb5847 | 2020-08-03 22:19:42 +0200 | [diff] [blame] | 2769 | if (disp->Driver->GLInteropExportObject) |
| 2770 | ret = disp->Driver->GLInteropExportObject(disp, ctx, in, out); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2771 | else |
| 2772 | ret = MESA_GLINTEROP_UNSUPPORTED; |
| 2773 | |
| 2774 | _eglUnlockDisplay(disp); |
| 2775 | return ret; |
| 2776 | } |