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