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 | #include <assert.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | #include "eglconfig.h" |
| 35 | #include "eglcontext.h" |
Brian Paul | d548bf4 | 2005-11-27 23:57:19 +0000 | [diff] [blame] | 36 | #include "egldisplay.h" |
Chia-I Wu | 94cb321 | 2010-01-29 09:00:30 +0800 | [diff] [blame] | 37 | #include "eglcurrent.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 38 | #include "eglsurface.h" |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 39 | #include "egllog.h" |
Eric Engestrom | d75fbff | 2018-05-16 14:17:30 +0100 | [diff] [blame] | 40 | #include "util/macros.h" |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 41 | |
| 42 | |
| 43 | /** |
| 44 | * Return the API bit (one of EGL_xxx_BIT) of the context. |
| 45 | */ |
| 46 | static EGLint |
| 47 | _eglGetContextAPIBit(_EGLContext *ctx) |
| 48 | { |
| 49 | EGLint bit = 0; |
| 50 | |
| 51 | switch (ctx->ClientAPI) { |
| 52 | case EGL_OPENGL_ES_API: |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 53 | switch (ctx->ClientMajorVersion) { |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 54 | case 1: |
| 55 | bit = EGL_OPENGL_ES_BIT; |
| 56 | break; |
| 57 | case 2: |
| 58 | bit = EGL_OPENGL_ES2_BIT; |
| 59 | break; |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 60 | case 3: |
| 61 | bit = EGL_OPENGL_ES3_BIT_KHR; |
| 62 | break; |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 63 | default: |
| 64 | break; |
| 65 | } |
| 66 | break; |
| 67 | case EGL_OPENVG_API: |
| 68 | bit = EGL_OPENVG_BIT; |
| 69 | break; |
| 70 | case EGL_OPENGL_API: |
| 71 | bit = EGL_OPENGL_BIT; |
| 72 | break; |
| 73 | default: |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | return bit; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Parse the list of context attributes and return the proper error code. |
| 83 | */ |
| 84 | static EGLint |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 85 | _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 86 | const EGLint *attrib_list) |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 87 | { |
| 88 | EGLenum api = ctx->ClientAPI; |
| 89 | EGLint i, err = EGL_SUCCESS; |
| 90 | |
| 91 | if (!attrib_list) |
| 92 | return EGL_SUCCESS; |
| 93 | |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 94 | if (api == EGL_OPENVG_API && attrib_list[0] != EGL_NONE) { |
| 95 | _eglLog(_EGL_DEBUG, "bad context attribute 0x%04x", attrib_list[0]); |
| 96 | return EGL_BAD_ATTRIBUTE; |
| 97 | } |
| 98 | |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 99 | for (i = 0; attrib_list[i] != EGL_NONE; i++) { |
| 100 | EGLint attr = attrib_list[i++]; |
| 101 | EGLint val = attrib_list[i]; |
| 102 | |
| 103 | switch (attr) { |
| 104 | case EGL_CONTEXT_CLIENT_VERSION: |
Frank Binns | d9603be | 2015-08-12 16:36:00 +0100 | [diff] [blame] | 105 | /* The EGL 1.4 spec says: |
| 106 | * |
| 107 | * "attribute EGL_CONTEXT_CLIENT_VERSION is only valid when the |
| 108 | * current rendering API is EGL_OPENGL_ES_API" |
| 109 | * |
| 110 | * The EGL_KHR_create_context spec says: |
| 111 | * |
| 112 | * "EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098 |
| 113 | * (this token is an alias for EGL_CONTEXT_CLIENT_VERSION)" |
| 114 | * |
| 115 | * "The values for attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 116 | * EGL_CONTEXT_MINOR_VERSION_KHR specify the requested client API |
| 117 | * version. They are only meaningful for OpenGL and OpenGL ES |
| 118 | * contexts, and specifying them for other types of contexts will |
| 119 | * generate an error." |
| 120 | */ |
| 121 | if ((api != EGL_OPENGL_ES_API && |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 122 | (!disp->Extensions.KHR_create_context || api != EGL_OPENGL_API))) { |
Frank Binns | d9603be | 2015-08-12 16:36:00 +0100 | [diff] [blame] | 123 | err = EGL_BAD_ATTRIBUTE; |
| 124 | break; |
| 125 | } |
| 126 | |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 127 | ctx->ClientMajorVersion = val; |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 128 | break; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 129 | |
| 130 | case EGL_CONTEXT_MINOR_VERSION_KHR: |
Frank Binns | d9603be | 2015-08-12 16:36:00 +0100 | [diff] [blame] | 131 | /* The EGL_KHR_create_context spec says: |
| 132 | * |
| 133 | * "The values for attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 134 | * EGL_CONTEXT_MINOR_VERSION_KHR specify the requested client API |
| 135 | * version. They are only meaningful for OpenGL and OpenGL ES |
| 136 | * contexts, and specifying them for other types of contexts will |
| 137 | * generate an error." |
| 138 | */ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 139 | if (!disp->Extensions.KHR_create_context || |
Frank Binns | d9603be | 2015-08-12 16:36:00 +0100 | [diff] [blame] | 140 | (api != EGL_OPENGL_ES_API && api != EGL_OPENGL_API)) { |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 141 | err = EGL_BAD_ATTRIBUTE; |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | ctx->ClientMinorVersion = val; |
| 146 | break; |
| 147 | |
| 148 | case EGL_CONTEXT_FLAGS_KHR: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 149 | if (!disp->Extensions.KHR_create_context) { |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 150 | err = EGL_BAD_ATTRIBUTE; |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | /* The EGL_KHR_create_context spec says: |
| 155 | * |
Matthew Waters | 11cabc4 | 2015-09-14 18:35:45 +0100 | [diff] [blame] | 156 | * "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in |
| 157 | * EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created. |
| 158 | * [...] |
| 159 | * In some cases a debug context may be identical to a non-debug |
| 160 | * context. This bit is supported for OpenGL and OpenGL ES |
| 161 | * contexts." |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 162 | */ |
Matthew Waters | 11cabc4 | 2015-09-14 18:35:45 +0100 | [diff] [blame] | 163 | if ((val & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) && |
| 164 | (api != EGL_OPENGL_API && api != EGL_OPENGL_ES_API)) { |
| 165 | err = EGL_BAD_ATTRIBUTE; |
| 166 | break; |
| 167 | } |
| 168 | |
| 169 | /* The EGL_KHR_create_context spec says: |
| 170 | * |
| 171 | * "If the EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR flag bit |
| 172 | * is set in EGL_CONTEXT_FLAGS_KHR, then a <forward-compatible> |
| 173 | * context will be created. Forward-compatible contexts are |
| 174 | * defined only for OpenGL versions 3.0 and later. They must not |
| 175 | * support functionality marked as <deprecated> by that version of |
| 176 | * the API, while a non-forward-compatible context must support |
| 177 | * all functionality in that version, deprecated or not. This bit |
| 178 | * is supported for OpenGL contexts, and requesting a |
| 179 | * forward-compatible context for OpenGL versions less than 3.0 |
| 180 | * will generate an error." |
Andrii Simiklit | 5c581b3 | 2018-10-11 13:53:21 +0300 | [diff] [blame] | 181 | * |
| 182 | * Note: since the forward-compatible flag can be set more than one way, |
| 183 | * the OpenGL version check is performed once, below. |
Matthew Waters | 11cabc4 | 2015-09-14 18:35:45 +0100 | [diff] [blame] | 184 | */ |
| 185 | if ((val & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) && |
Andrii Simiklit | 5c581b3 | 2018-10-11 13:53:21 +0300 | [diff] [blame] | 186 | api != EGL_OPENGL_API) { |
Matthew Waters | 11cabc4 | 2015-09-14 18:35:45 +0100 | [diff] [blame] | 187 | err = EGL_BAD_ATTRIBUTE; |
| 188 | break; |
| 189 | } |
| 190 | |
Matthew Waters | 11cabc4 | 2015-09-14 18:35:45 +0100 | [diff] [blame] | 191 | if ((val & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) && |
Chad Versace | b85c0b5 | 2016-12-22 17:06:14 -0800 | [diff] [blame] | 192 | api != EGL_OPENGL_API) { |
| 193 | /* The EGL_KHR_create_context spec says: |
| 194 | * |
| 195 | * 10) Which error should be generated if robust buffer access |
| 196 | * or reset notifications are requested under OpenGL ES? |
| 197 | * |
| 198 | * As per Issue 6, this extension does not support creating |
| 199 | * robust contexts for OpenGL ES. This is only supported via |
| 200 | * the EGL_EXT_create_context_robustness extension. |
| 201 | * |
| 202 | * Attempting to use this extension to create robust OpenGL |
| 203 | * ES context will generate an EGL_BAD_ATTRIBUTE error. This |
| 204 | * specific error is generated because this extension does |
| 205 | * not define the EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR |
| 206 | * and EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR |
| 207 | * bits for OpenGL ES contexts. Thus, use of these bits fall |
| 208 | * under condition described by: "If an attribute is |
| 209 | * specified that is not meaningful for the client API |
| 210 | * type.." in the above specification. |
| 211 | * |
| 212 | * The spec requires that we emit the error even if the display |
| 213 | * supports EGL_EXT_create_context_robustness. To create a robust |
| 214 | * GLES context, the *attribute* |
| 215 | * EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT must be used, not the |
| 216 | * *flag* EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR. |
| 217 | */ |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 218 | err = EGL_BAD_ATTRIBUTE; |
| 219 | break; |
| 220 | } |
| 221 | |
Marek Olšák | f9f8944 | 2015-05-12 00:44:20 +0200 | [diff] [blame] | 222 | ctx->Flags |= val; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 223 | break; |
| 224 | |
| 225 | case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 226 | if (!disp->Extensions.KHR_create_context) { |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 227 | err = EGL_BAD_ATTRIBUTE; |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | /* The EGL_KHR_create_context spec says: |
| 232 | * |
| 233 | * "[EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR] is only meaningful for |
| 234 | * OpenGL contexts, and specifying it for other types of |
| 235 | * contexts, including OpenGL ES contexts, will generate an |
| 236 | * error." |
| 237 | */ |
| 238 | if (api != EGL_OPENGL_API) { |
| 239 | err = EGL_BAD_ATTRIBUTE; |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | ctx->Profile = val; |
| 244 | break; |
| 245 | |
| 246 | case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR: |
| 247 | /* The EGL_KHR_create_context spec says: |
| 248 | * |
| 249 | * "[EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR] is only |
| 250 | * meaningful for OpenGL contexts, and specifying it for other |
| 251 | * types of contexts, including OpenGL ES contexts, will generate |
| 252 | * an error." |
Kenneth Graunke | 28c2ce7 | 2019-05-16 22:05:51 -0700 | [diff] [blame] | 253 | * |
| 254 | * EGL 1.5 defines EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY |
| 255 | * (without a suffix) which has the same value as the KHR token, |
| 256 | * and specifies that it now works with both GL and ES contexts: |
| 257 | * |
| 258 | * "This attribute is supported only for OpenGL and OpenGL ES |
| 259 | * contexts." |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 260 | */ |
Kenneth Graunke | 28c2ce7 | 2019-05-16 22:05:51 -0700 | [diff] [blame] | 261 | if (!(disp->Extensions.KHR_create_context && api == EGL_OPENGL_API) |
| 262 | && !(disp->Version >= 15 && (api == EGL_OPENGL_API || |
| 263 | api == EGL_OPENGL_ES_API))) { |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 264 | err = EGL_BAD_ATTRIBUTE; |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | ctx->ResetNotificationStrategy = val; |
| 269 | break; |
| 270 | |
Ian Romanick | f171571 | 2012-07-19 15:08:06 -0700 | [diff] [blame] | 271 | case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 272 | /* The EGL_EXT_create_context_robustness spec says: |
| 273 | * |
| 274 | * "[EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT] is only |
| 275 | * meaningful for OpenGL ES contexts, and specifying it for other |
| 276 | * types of contexts will generate an EGL_BAD_ATTRIBUTE error." |
| 277 | */ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 278 | if (!disp->Extensions.EXT_create_context_robustness |
Ian Romanick | f171571 | 2012-07-19 15:08:06 -0700 | [diff] [blame] | 279 | || api != EGL_OPENGL_ES_API) { |
| 280 | err = EGL_BAD_ATTRIBUTE; |
| 281 | break; |
| 282 | } |
| 283 | |
| 284 | ctx->ResetNotificationStrategy = val; |
| 285 | break; |
| 286 | |
| 287 | case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 288 | if (!disp->Extensions.EXT_create_context_robustness) { |
Ian Romanick | f171571 | 2012-07-19 15:08:06 -0700 | [diff] [blame] | 289 | err = EGL_BAD_ATTRIBUTE; |
| 290 | break; |
| 291 | } |
| 292 | |
Marek Olšák | f9f8944 | 2015-05-12 00:44:20 +0200 | [diff] [blame] | 293 | if (val == EGL_TRUE) |
| 294 | ctx->Flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; |
Ian Romanick | f171571 | 2012-07-19 15:08:06 -0700 | [diff] [blame] | 295 | break; |
| 296 | |
Marek Olšák | 706466f | 2015-05-12 00:44:56 +0200 | [diff] [blame] | 297 | case EGL_CONTEXT_OPENGL_ROBUST_ACCESS: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 298 | if (disp->Version < 15) { |
Marek Olšák | 706466f | 2015-05-12 00:44:56 +0200 | [diff] [blame] | 299 | err = EGL_BAD_ATTRIBUTE; |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | if (val == EGL_TRUE) |
| 304 | ctx->Flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; |
| 305 | break; |
| 306 | |
| 307 | case EGL_CONTEXT_OPENGL_DEBUG: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 308 | if (disp->Version < 15) { |
Marek Olšák | 706466f | 2015-05-12 00:44:56 +0200 | [diff] [blame] | 309 | err = EGL_BAD_ATTRIBUTE; |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | if (val == EGL_TRUE) |
| 314 | ctx->Flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; |
| 315 | break; |
| 316 | |
| 317 | case EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 318 | if (disp->Version < 15) { |
Marek Olšák | 706466f | 2015-05-12 00:44:56 +0200 | [diff] [blame] | 319 | err = EGL_BAD_ATTRIBUTE; |
| 320 | break; |
| 321 | } |
| 322 | |
| 323 | if (val == EGL_TRUE) |
| 324 | ctx->Flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; |
| 325 | break; |
| 326 | |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 327 | case EGL_CONTEXT_OPENGL_NO_ERROR_KHR: |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 328 | if (disp->Version < 14 || |
| 329 | !disp->Extensions.KHR_create_context_no_error) { |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 330 | err = EGL_BAD_ATTRIBUTE; |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | /* The KHR_no_error spec only applies against OpenGL 2.0+ and |
| 335 | * OpenGL ES 2.0+ |
| 336 | */ |
| 337 | if ((api != EGL_OPENGL_API && api != EGL_OPENGL_ES_API) || |
| 338 | ctx->ClientMajorVersion < 2) { |
| 339 | err = EGL_BAD_ATTRIBUTE; |
| 340 | break; |
| 341 | } |
| 342 | |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 343 | /* Canonicalize value to EGL_TRUE/EGL_FALSE definitions */ |
| 344 | ctx->NoError = !!val; |
| 345 | break; |
| 346 | |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 347 | case EGL_CONTEXT_PRIORITY_LEVEL_IMG: |
| 348 | /* The EGL_IMG_context_priority spec says: |
| 349 | * |
| 350 | * "EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of |
| 351 | * the context to be created. This attribute is a hint, as an |
| 352 | * implementation may not support multiple contexts at some |
| 353 | * priority levels and system policy may limit access to high |
| 354 | * priority contexts to appropriate system privilege level. The |
| 355 | * default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is |
| 356 | * EGL_CONTEXT_PRIORITY_MEDIUM_IMG." |
| 357 | */ |
| 358 | { |
| 359 | int bit; |
| 360 | |
| 361 | switch (val) { |
| 362 | case EGL_CONTEXT_PRIORITY_HIGH_IMG: |
| 363 | bit = __EGL_CONTEXT_PRIORITY_HIGH_BIT; |
| 364 | break; |
| 365 | case EGL_CONTEXT_PRIORITY_MEDIUM_IMG: |
| 366 | bit = __EGL_CONTEXT_PRIORITY_MEDIUM_BIT; |
| 367 | break; |
| 368 | case EGL_CONTEXT_PRIORITY_LOW_IMG: |
| 369 | bit = __EGL_CONTEXT_PRIORITY_LOW_BIT; |
| 370 | break; |
| 371 | default: |
| 372 | bit = -1; |
| 373 | break; |
| 374 | } |
| 375 | |
| 376 | if (bit < 0) { |
| 377 | err = EGL_BAD_ATTRIBUTE; |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | /* "This extension allows an EGLContext to be created with a |
| 382 | * priority hint. It is possible that an implementation will not |
| 383 | * honour the hint, especially if there are constraints on the |
| 384 | * number of high priority contexts available in the system, or |
| 385 | * system policy limits access to high priority contexts to |
| 386 | * appropriate system privilege level. A query is provided to find |
| 387 | * the real priority level assigned to the context after creation." |
| 388 | * |
| 389 | * We currently assume that the driver applies the priority hint |
| 390 | * and filters out any it cannot handle during the screen setup, |
| 391 | * e.g. dri2_setup_screen(). As such we can mask any change that |
| 392 | * the driver would fail, and ctx->ContextPriority matches the |
| 393 | * hint applied to the driver/hardware backend. |
| 394 | */ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 395 | if (disp->Extensions.IMG_context_priority & (1 << bit)) |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 396 | ctx->ContextPriority = val; |
| 397 | |
| 398 | break; |
| 399 | } |
| 400 | |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 401 | case EGL_CONTEXT_RELEASE_BEHAVIOR_KHR: |
| 402 | if (val == EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR || |
| 403 | val == EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR) { |
| 404 | ctx->ReleaseBehavior = val; |
| 405 | } else { |
| 406 | err = EGL_BAD_ATTRIBUTE; |
| 407 | } |
| 408 | break; |
| 409 | |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 410 | default: |
| 411 | err = EGL_BAD_ATTRIBUTE; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | if (err != EGL_SUCCESS) { |
| 416 | _eglLog(_EGL_DEBUG, "bad context attribute 0x%04x", attr); |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 421 | if (api == EGL_OPENGL_API) { |
| 422 | /* The EGL_KHR_create_context spec says: |
| 423 | * |
| 424 | * "If the requested OpenGL version is less than 3.2, |
| 425 | * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR is ignored and the |
| 426 | * functionality of the context is determined solely by the |
| 427 | * requested version." |
| 428 | * |
| 429 | * Since the value is ignored, only validate the setting if the version |
| 430 | * is >= 3.2. |
| 431 | */ |
| 432 | if (ctx->ClientMajorVersion >= 4 |
| 433 | || (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) { |
| 434 | switch (ctx->Profile) { |
| 435 | case EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR: |
| 436 | case EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR: |
| 437 | break; |
| 438 | |
| 439 | default: |
| 440 | /* The EGL_KHR_create_context spec says: |
| 441 | * |
| 442 | * "* If an OpenGL context is requested, the requested version |
| 443 | * is greater than 3.2, and the value for attribute |
Matt Turner | 587d5db | 2012-10-08 17:01:34 -0700 | [diff] [blame] | 444 | * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has |
| 445 | * any bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR |
| 446 | * and EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has |
| 447 | * more than one of these bits set; or if the implementation does |
| 448 | * not support the requested profile, then an EGL_BAD_MATCH error |
| 449 | * is generated." |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 450 | */ |
Matt Turner | 587d5db | 2012-10-08 17:01:34 -0700 | [diff] [blame] | 451 | err = EGL_BAD_MATCH; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /* The EGL_KHR_create_context spec says: |
| 457 | * |
| 458 | * "* If an OpenGL context is requested and the values for |
| 459 | * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 460 | * EGL_CONTEXT_MINOR_VERSION_KHR, when considered together with |
| 461 | * the value for attribute |
| 462 | * EGL_CONTEXT_FORWARD_COMPATIBLE_BIT_KHR, specify an OpenGL |
| 463 | * version and feature set that are not defined, than an |
| 464 | * EGL_BAD_MATCH error is generated. |
| 465 | * |
| 466 | * ... Thus, examples of invalid combinations of attributes |
| 467 | * include: |
| 468 | * |
| 469 | * - Major version < 1 or > 4 |
| 470 | * - Major version == 1 and minor version < 0 or > 5 |
| 471 | * - Major version == 2 and minor version < 0 or > 1 |
| 472 | * - Major version == 3 and minor version < 0 or > 2 |
| 473 | * - Major version == 4 and minor version < 0 or > 2 |
| 474 | * - Forward-compatible flag set and major version < 3" |
| 475 | */ |
| 476 | if (ctx->ClientMajorVersion < 1 || ctx->ClientMinorVersion < 0) |
| 477 | err = EGL_BAD_MATCH; |
| 478 | |
| 479 | switch (ctx->ClientMajorVersion) { |
| 480 | case 1: |
| 481 | if (ctx->ClientMinorVersion > 5 |
| 482 | || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) |
| 483 | err = EGL_BAD_MATCH; |
| 484 | break; |
| 485 | |
| 486 | case 2: |
| 487 | if (ctx->ClientMinorVersion > 1 |
| 488 | || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) |
| 489 | err = EGL_BAD_MATCH; |
| 490 | break; |
| 491 | |
| 492 | case 3: |
| 493 | /* Note: The text above is incorrect. There *is* an OpenGL 3.3! |
| 494 | */ |
| 495 | if (ctx->ClientMinorVersion > 3) |
| 496 | err = EGL_BAD_MATCH; |
| 497 | break; |
| 498 | |
| 499 | case 4: |
| 500 | default: |
| 501 | /* Don't put additional version checks here. We don't know that |
| 502 | * there won't be versions > 4.2. |
| 503 | */ |
| 504 | break; |
| 505 | } |
| 506 | } else if (api == EGL_OPENGL_ES_API) { |
| 507 | /* The EGL_KHR_create_context spec says: |
| 508 | * |
| 509 | * "* If an OpenGL ES context is requested and the values for |
| 510 | * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 511 | * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that |
| 512 | * is not defined, than an EGL_BAD_MATCH error is generated. |
| 513 | * |
| 514 | * ... Examples of invalid combinations of attributes include: |
| 515 | * |
| 516 | * - Major version < 1 or > 2 |
| 517 | * - Major version == 1 and minor version < 0 or > 1 |
| 518 | * - Major version == 2 and minor version != 0 |
| 519 | */ |
| 520 | if (ctx->ClientMajorVersion < 1 || ctx->ClientMinorVersion < 0) |
| 521 | err = EGL_BAD_MATCH; |
| 522 | |
| 523 | switch (ctx->ClientMajorVersion) { |
| 524 | case 1: |
| 525 | if (ctx->ClientMinorVersion > 1) |
| 526 | err = EGL_BAD_MATCH; |
| 527 | break; |
| 528 | |
| 529 | case 2: |
Ian Romanick | dbecb41 | 2012-07-19 16:12:13 -0700 | [diff] [blame] | 530 | if (ctx->ClientMinorVersion > 0) |
| 531 | err = EGL_BAD_MATCH; |
| 532 | break; |
| 533 | |
| 534 | case 3: |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 535 | /* Don't put additional version checks here. We don't know that |
Ian Romanick | dbecb41 | 2012-07-19 16:12:13 -0700 | [diff] [blame] | 536 | * there won't be versions > 3.0. |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 537 | */ |
| 538 | break; |
Anuj Phogat | d308f57 | 2014-06-18 17:35:18 -0700 | [diff] [blame] | 539 | |
| 540 | default: |
| 541 | err = EGL_BAD_MATCH; |
| 542 | break; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
| 546 | switch (ctx->ResetNotificationStrategy) { |
| 547 | case EGL_NO_RESET_NOTIFICATION_KHR: |
| 548 | case EGL_LOSE_CONTEXT_ON_RESET_KHR: |
| 549 | break; |
| 550 | |
| 551 | default: |
| 552 | err = EGL_BAD_ATTRIBUTE; |
| 553 | break; |
| 554 | } |
| 555 | |
Grigori Goronzy | 39bf775 | 2017-07-19 23:51:55 +0200 | [diff] [blame] | 556 | /* The EGL_KHR_create_context_no_error spec says: |
| 557 | * |
| 558 | * "BAD_MATCH is generated if the EGL_CONTEXT_OPENGL_NO_ERROR_KHR is TRUE at |
| 559 | * the same time as a debug or robustness context is specified." |
| 560 | */ |
| 561 | if (ctx->NoError && (ctx->Flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR || |
| 562 | ctx->Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) { |
| 563 | err = EGL_BAD_MATCH; |
| 564 | } |
| 565 | |
Matt Turner | 971750e | 2012-08-24 16:26:54 -0700 | [diff] [blame] | 566 | if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 567 | | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR |
| 568 | | EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) { |
| 569 | err = EGL_BAD_ATTRIBUTE; |
| 570 | } |
| 571 | |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 572 | return err; |
| 573 | } |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 574 | |
| 575 | |
| 576 | /** |
Brian Paul | 5e7dba5 | 2008-05-27 14:21:25 -0600 | [diff] [blame] | 577 | * Initialize the given _EGLContext object to defaults and/or the values |
| 578 | * in the attrib_list. |
Adam Jackson | a279760 | 2016-09-07 17:41:56 -0400 | [diff] [blame] | 579 | * |
| 580 | * According to EGL 1.5 Section 3.7: |
| 581 | * |
Adam Jackson | dbda375 | 2016-09-08 13:21:24 -0400 | [diff] [blame] | 582 | * "EGL_OPENGL_API and EGL_OPENGL_ES_API are interchangeable for all |
| 583 | * purposes except eglCreateContext." |
Adam Jackson | a279760 | 2016-09-07 17:41:56 -0400 | [diff] [blame] | 584 | * |
| 585 | * And since we only support GL and GLES, this is the only place where the |
| 586 | * bound API matters at all. We look up the current API from the current |
| 587 | * thread, and stash that in the context we're initializing. Our caller is |
| 588 | * responsible for determining whether that's an API it supports. |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 589 | */ |
Brian Paul | d548bf4 | 2005-11-27 23:57:19 +0000 | [diff] [blame] | 590 | EGLBoolean |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 591 | _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf, |
Chia-I Wu | d69242b | 2010-01-31 13:33:57 +0800 | [diff] [blame] | 592 | const EGLint *attrib_list) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 593 | { |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 594 | const EGLenum api = eglQueryAPI(); |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 595 | EGLint err; |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 596 | |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 597 | if (api == EGL_NONE) |
| 598 | return _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); |
Brian Paul | d548bf4 | 2005-11-27 23:57:19 +0000 | [diff] [blame] | 599 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 600 | _eglInitResource(&ctx->Resource, sizeof(*ctx), disp); |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 601 | ctx->ClientAPI = api; |
| 602 | ctx->Config = conf; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 603 | ctx->Profile = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; |
Brian Paul | 9f6a4e2 | 2008-06-19 21:19:33 -0600 | [diff] [blame] | 604 | |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 605 | ctx->ClientMajorVersion = 1; /* the default, per EGL spec */ |
| 606 | ctx->ClientMinorVersion = 0; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 607 | ctx->Flags = 0; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 608 | ctx->ResetNotificationStrategy = EGL_NO_RESET_NOTIFICATION_KHR; |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 609 | ctx->ContextPriority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG; |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 610 | ctx->ReleaseBehavior = EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR; |
Brian Paul | a8533d5 | 2008-06-19 16:06:56 -0600 | [diff] [blame] | 611 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 612 | err = _eglParseContextAttribList(ctx, disp, attrib_list); |
Chia-I Wu | 5eb3359 | 2010-08-20 13:19:10 +0800 | [diff] [blame] | 613 | if (err == EGL_SUCCESS && ctx->Config) { |
Chia-I Wu | 3fa2188 | 2010-10-14 16:38:58 +0800 | [diff] [blame] | 614 | EGLint api_bit; |
Chia-I Wu | 5eb3359 | 2010-08-20 13:19:10 +0800 | [diff] [blame] | 615 | |
Chia-I Wu | 5eb3359 | 2010-08-20 13:19:10 +0800 | [diff] [blame] | 616 | api_bit = _eglGetContextAPIBit(ctx); |
Chia-I Wu | 3fa2188 | 2010-10-14 16:38:58 +0800 | [diff] [blame] | 617 | if (!(ctx->Config->RenderableType & api_bit)) { |
Chia-I Wu | 5eb3359 | 2010-08-20 13:19:10 +0800 | [diff] [blame] | 618 | _eglLog(_EGL_DEBUG, "context api is 0x%x while config supports 0x%x", |
Chia-I Wu | 3fa2188 | 2010-10-14 16:38:58 +0800 | [diff] [blame] | 619 | api_bit, ctx->Config->RenderableType); |
Chia-I Wu | 5eb3359 | 2010-08-20 13:19:10 +0800 | [diff] [blame] | 620 | err = EGL_BAD_CONFIG; |
| 621 | } |
| 622 | } |
Chia-I Wu | caa5c8d | 2010-01-31 12:57:53 +0800 | [diff] [blame] | 623 | if (err != EGL_SUCCESS) |
| 624 | return _eglError(err, "eglCreateContext"); |
Brian Paul | d548bf4 | 2005-11-27 23:57:19 +0000 | [diff] [blame] | 625 | |
| 626 | return EGL_TRUE; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 630 | static EGLint |
| 631 | _eglQueryContextRenderBuffer(_EGLContext *ctx) |
| 632 | { |
| 633 | _EGLSurface *surf = ctx->DrawSurface; |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 634 | |
Chad Versace | f48f9a7 | 2018-04-07 14:23:48 -0700 | [diff] [blame] | 635 | /* From the EGL 1.5 spec: |
| 636 | * |
| 637 | * - If the context is not bound to a surface, then EGL_NONE will be |
| 638 | * returned. |
| 639 | */ |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 640 | if (!surf) |
| 641 | return EGL_NONE; |
Chad Versace | f48f9a7 | 2018-04-07 14:23:48 -0700 | [diff] [blame] | 642 | |
| 643 | switch (surf->Type) { |
| 644 | default: |
| 645 | unreachable("bad EGLSurface type"); |
| 646 | case EGL_PIXMAP_BIT: |
| 647 | /* - If the context is bound to a pixmap surface, then EGL_SINGLE_BUFFER |
| 648 | * will be returned. |
| 649 | */ |
| 650 | return EGL_SINGLE_BUFFER; |
| 651 | case EGL_PBUFFER_BIT: |
| 652 | /* - If the context is bound to a pbuffer surface, then EGL_BACK_BUFFER |
| 653 | * will be returned. |
| 654 | */ |
| 655 | return EGL_BACK_BUFFER; |
| 656 | case EGL_WINDOW_BIT: |
| 657 | /* - If the context is bound to a window surface, then either |
| 658 | * EGL_BACK_BUFFER or EGL_SINGLE_BUFFER may be returned. The value |
| 659 | * returned depends on both the buffer requested by the setting of the |
| 660 | * EGL_RENDER_BUFFER property of the surface [...], and on the client |
| 661 | * API (not all client APIs support single-buffer Rendering to window |
| 662 | * surfaces). Some client APIs allow control of whether rendering goes |
| 663 | * to the front or back buffer. This client API-specific choice is not |
| 664 | * reflected in the returned value, which only describes the buffer |
| 665 | * that will be rendered to by default if not overridden by the client |
| 666 | * API. |
| 667 | */ |
| 668 | return surf->ActiveRenderBuffer; |
| 669 | } |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 670 | } |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 671 | |
| 672 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 673 | EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 674 | _eglQueryContext(const _EGLDriver *drv, _EGLDisplay *disp, _EGLContext *c, |
Brian Paul | d548bf4 | 2005-11-27 23:57:19 +0000 | [diff] [blame] | 675 | EGLint attribute, EGLint *value) |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 676 | { |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 677 | (void) drv; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 678 | (void) disp; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 679 | |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 680 | if (!value) |
| 681 | return _eglError(EGL_BAD_PARAMETER, "eglQueryContext"); |
| 682 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 683 | switch (attribute) { |
| 684 | case EGL_CONFIG_ID: |
Adam Jackson | cc45a5c | 2016-09-09 12:25:33 -0400 | [diff] [blame] | 685 | /* |
| 686 | * From EGL_KHR_no_config_context: |
| 687 | * |
| 688 | * "Querying EGL_CONFIG_ID returns the ID of the EGLConfig with |
| 689 | * respect to which the context was created, or zero if created |
| 690 | * without respect to an EGLConfig." |
| 691 | */ |
| 692 | *value = c->Config ? c->Config->ConfigID : 0; |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 693 | break; |
| 694 | case EGL_CONTEXT_CLIENT_VERSION: |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 695 | *value = c->ClientMajorVersion; |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 696 | break; |
Brian Paul | b2006a4 | 2006-01-30 00:10:55 +0000 | [diff] [blame] | 697 | case EGL_CONTEXT_CLIENT_TYPE: |
| 698 | *value = c->ClientAPI; |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 699 | break; |
| 700 | case EGL_RENDER_BUFFER: |
| 701 | *value = _eglQueryContextRenderBuffer(c); |
| 702 | break; |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 703 | case EGL_CONTEXT_PRIORITY_LEVEL_IMG: |
| 704 | *value = c->ContextPriority; |
| 705 | break; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 706 | default: |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 707 | return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext"); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 708 | } |
Chia-I Wu | d845f27 | 2009-09-27 17:00:51 +0800 | [diff] [blame] | 709 | |
| 710 | return EGL_TRUE; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
| 714 | /** |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 715 | * Bind the context to the thread and return the previous context. |
| 716 | * |
| 717 | * Note that the context may be NULL. |
| 718 | */ |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 719 | _EGLContext * |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 720 | _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t) |
| 721 | { |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 722 | _EGLContext *oldCtx; |
| 723 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 724 | oldCtx = t->CurrentContext; |
Chia-I Wu | 551bfe7 | 2010-03-28 02:11:16 +0800 | [diff] [blame] | 725 | if (ctx != oldCtx) { |
| 726 | if (oldCtx) |
| 727 | oldCtx->Binding = NULL; |
| 728 | if (ctx) |
| 729 | ctx->Binding = t; |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 730 | |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 731 | t->CurrentContext = ctx; |
Chia-I Wu | 551bfe7 | 2010-03-28 02:11:16 +0800 | [diff] [blame] | 732 | } |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 733 | |
| 734 | return oldCtx; |
| 735 | } |
| 736 | |
| 737 | |
| 738 | /** |
| 739 | * Return true if the given context and surfaces can be made current. |
| 740 | */ |
| 741 | static EGLBoolean |
| 742 | _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) |
| 743 | { |
| 744 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 745 | _EGLDisplay *disp; |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 746 | |
| 747 | if (_eglIsCurrentThreadDummy()) |
| 748 | return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent"); |
| 749 | |
| 750 | /* this is easy */ |
| 751 | if (!ctx) { |
| 752 | if (draw || read) |
| 753 | return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); |
| 754 | return EGL_TRUE; |
| 755 | } |
| 756 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 757 | disp = ctx->Resource.Display; |
| 758 | if (!disp->Extensions.KHR_surfaceless_context |
Ian Romanick | b50703a | 2012-07-18 09:38:34 -0700 | [diff] [blame] | 759 | && (draw == NULL || read == NULL)) |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 760 | return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); |
| 761 | |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 762 | /* |
| 763 | * The spec says |
| 764 | * |
| 765 | * "If ctx is current to some other thread, or if either draw or read are |
| 766 | * bound to contexts in another thread, an EGL_BAD_ACCESS error is |
| 767 | * generated." |
| 768 | * |
Chia-I Wu | 0d43cbe | 2010-10-23 16:51:01 +0800 | [diff] [blame] | 769 | * and |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 770 | * |
| 771 | * "at most one context may be bound to a particular surface at a given |
| 772 | * time" |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 773 | */ |
Chia-I Wu | 0d43cbe | 2010-10-23 16:51:01 +0800 | [diff] [blame] | 774 | if (ctx->Binding && ctx->Binding != t) |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 775 | return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); |
Chia-I Wu | 0d43cbe | 2010-10-23 16:51:01 +0800 | [diff] [blame] | 776 | if (draw && draw->CurrentContext && draw->CurrentContext != ctx) { |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 777 | if (draw->CurrentContext->Binding != t) |
Chia-I Wu | 0d43cbe | 2010-10-23 16:51:01 +0800 | [diff] [blame] | 778 | return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); |
| 779 | } |
| 780 | if (read && read->CurrentContext && read->CurrentContext != ctx) { |
Kyle Brenneman | 6e066f7 | 2016-07-08 15:21:17 -0600 | [diff] [blame] | 781 | if (read->CurrentContext->Binding != t) |
Chia-I Wu | 0d43cbe | 2010-10-23 16:51:01 +0800 | [diff] [blame] | 782 | return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); |
| 783 | } |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 784 | |
Neil Roberts | 551d459 | 2014-03-07 18:05:47 +0000 | [diff] [blame] | 785 | /* If the context has a config then it must match that of the two |
| 786 | * surfaces */ |
| 787 | if (ctx->Config) { |
| 788 | if ((draw && draw->Config != ctx->Config) || |
| 789 | (read && read->Config != ctx->Config)) |
| 790 | return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); |
| 791 | } else { |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 792 | /* Otherwise we must be using the EGL_KHR_no_config_context |
Neil Roberts | 551d459 | 2014-03-07 18:05:47 +0000 | [diff] [blame] | 793 | * extension */ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 794 | assert(disp->Extensions.KHR_no_config_context); |
Neil Roberts | 551d459 | 2014-03-07 18:05:47 +0000 | [diff] [blame] | 795 | |
| 796 | /* The extension doesn't permit binding draw and read buffers with |
| 797 | * differing contexts */ |
| 798 | if (draw && read && draw->Config != read->Config) |
| 799 | return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); |
| 800 | } |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 801 | |
Chia-I Wu | 7c09296 | 2010-01-26 16:53:40 +0800 | [diff] [blame] | 802 | return EGL_TRUE; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | /** |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 807 | * Bind the context to the current thread and given surfaces. Return the |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 808 | * previous bound context and surfaces. The caller should unreference the |
| 809 | * returned context and surfaces. |
| 810 | * |
| 811 | * Making a second call with the resources returned by the first call |
| 812 | * unsurprisingly undoes the first call, except for the resouce reference |
| 813 | * counts. |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 814 | */ |
| 815 | EGLBoolean |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 816 | _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, |
| 817 | _EGLContext **old_ctx, |
| 818 | _EGLSurface **old_draw, _EGLSurface **old_read) |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 819 | { |
| 820 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 821 | _EGLContext *prev_ctx; |
| 822 | _EGLSurface *prev_draw, *prev_read; |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 823 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 824 | if (!_eglCheckMakeCurrent(ctx, draw, read)) |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 825 | return EGL_FALSE; |
| 826 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 827 | /* increment refcounts before binding */ |
| 828 | _eglGetContext(ctx); |
| 829 | _eglGetSurface(draw); |
| 830 | _eglGetSurface(read); |
| 831 | |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 832 | /* bind the new context */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 833 | prev_ctx = _eglBindContextToThread(ctx, t); |
Chia-I Wu | bbe459b | 2010-04-05 21:26:34 +0800 | [diff] [blame] | 834 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 835 | /* break previous bindings */ |
| 836 | if (prev_ctx) { |
| 837 | prev_draw = prev_ctx->DrawSurface; |
| 838 | prev_read = prev_ctx->ReadSurface; |
Chia-I Wu | 848945e | 2010-04-06 11:51:25 +0800 | [diff] [blame] | 839 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 840 | if (prev_draw) |
| 841 | prev_draw->CurrentContext = NULL; |
| 842 | if (prev_read) |
| 843 | prev_read->CurrentContext = NULL; |
Chia-I Wu | ea9e5db | 2010-09-10 18:26:03 +0800 | [diff] [blame] | 844 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 845 | prev_ctx->DrawSurface = NULL; |
| 846 | prev_ctx->ReadSurface = NULL; |
| 847 | } |
| 848 | else { |
| 849 | prev_draw = prev_read = NULL; |
Chia-I Wu | bbe459b | 2010-04-05 21:26:34 +0800 | [diff] [blame] | 850 | } |
| 851 | |
Chia-I Wu | ea9e5db | 2010-09-10 18:26:03 +0800 | [diff] [blame] | 852 | /* establish new bindings */ |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 853 | if (ctx) { |
| 854 | if (draw) |
| 855 | draw->CurrentContext = ctx; |
| 856 | if (read) |
| 857 | read->CurrentContext = ctx; |
Chia-I Wu | ea9e5db | 2010-09-10 18:26:03 +0800 | [diff] [blame] | 858 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 859 | ctx->DrawSurface = draw; |
| 860 | ctx->ReadSurface = read; |
Chia-I Wu | ea9e5db | 2010-09-10 18:26:03 +0800 | [diff] [blame] | 861 | } |
| 862 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 863 | assert(old_ctx && old_draw && old_read); |
| 864 | *old_ctx = prev_ctx; |
| 865 | *old_draw = prev_draw; |
| 866 | *old_read = prev_read; |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 867 | |
| 868 | return EGL_TRUE; |
| 869 | } |