The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/client: Create a share context instead of using context directly

+71
+71
src/xrt/compositor/client/comp_egl_client.c
··· 134 134 } 135 135 } 136 136 137 + static inline void 138 + destroy_context_with_check(EGLDisplay display, EGLContext context, const char *func) 139 + { 140 + EGLBoolean eret = eglDestroyContext(display, context); 141 + if (eret == EGL_FALSE) { 142 + U_LOG_E("eglDestroyContext: %s (%s)", egl_error_str(eglGetError()), func); 143 + } 144 + } 145 + 146 + #define DESTROY_CONTEXT(DPY, CTX) destroy_context_with_check(DPY, CTX, __func__) 147 + 137 148 XRT_MAYBE_UNUSED static bool 138 149 has_extension(const char *extensions, const char *ext) 139 150 { ··· 190 201 } 191 202 192 203 static xrt_result_t 204 + create_context( 205 + EGLDisplay display, EGLConfig config, EGLContext app_context, EGLint api_type, EGLContext *out_our_context) 206 + { 207 + EGLint old_api_type = eglQueryAPI(); 208 + 209 + eglBindAPI(api_type); 210 + 211 + // clang-format off 212 + EGLint attrs[] = { 213 + EGL_CONTEXT_MAJOR_VERSION_KHR, 3, 214 + EGL_CONTEXT_MINOR_VERSION_KHR, 1, // Panfrost only supports 3.1 215 + EGL_NONE, EGL_NONE, 216 + EGL_NONE, 217 + }; 218 + // clang-format on 219 + 220 + if (api_type == EGL_OPENGL_API) { 221 + attrs[4] = EGL_CONTEXT_OPENGL_PROFILE_MASK; 222 + attrs[5] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT; 223 + } 224 + 225 + EGLContext our_context = eglCreateContext(display, config, app_context, attrs); 226 + 227 + // Restore old API type. 228 + if (old_api_type == EGL_NONE) { 229 + eglBindAPI(old_api_type); 230 + } 231 + 232 + if (our_context == EGL_NO_CONTEXT) { 233 + EGL_ERROR("eglCreateContext: %s", egl_error_str(eglGetError())); 234 + return XRT_ERROR_OPENGL; 235 + } 236 + 237 + *out_our_context = our_context; 238 + 239 + return XRT_SUCCESS; 240 + } 241 + 242 + static xrt_result_t 193 243 load_gl_functions(EGLint egl_client_type, PFNEGLGETPROCADDRESSPROC get_gl_procaddr) 194 244 { 195 245 switch (egl_client_type) { ··· 395 445 396 446 client_gl_compositor_close(&ceglc->base); 397 447 448 + DESTROY_CONTEXT(ceglc->current.dpy, ceglc->current.ctx); 449 + ceglc->current.ctx = EGL_NO_CONTEXT; 450 + ceglc->current.dpy = EGL_NO_DISPLAY; 451 + 398 452 free(ceglc); 399 453 } 400 454 ··· 444 498 445 499 446 500 /* 501 + * Create context. 502 + */ 503 + 504 + xret = create_context(display, config, context, egl_client_type, &context); 505 + if (xret != XRT_SUCCESS) { 506 + return xret; 507 + } 508 + 509 + 510 + /* 447 511 * Make current. 448 512 */ 449 513 ··· 460 524 egl_error_str(eglGetError()), // 461 525 (void *)old.dpy, (void *)old.ctx, (void *)old.read, (void *)old.draw, // 462 526 (void *)display, (void *)context, NULL, NULL); // 527 + 528 + DESTROY_CONTEXT(display, context); 529 + 463 530 // No need to restore on failure. 464 531 return XRT_ERROR_OPENGL; 465 532 } ··· 473 540 xret = load_gl_functions(egl_client_type, get_gl_procaddr); 474 541 if (xret != XRT_SUCCESS) { 475 542 restore_context(&old); 543 + DESTROY_CONTEXT(display, context); 476 544 return xret; 477 545 } 478 546 ··· 480 548 xret = check_context_and_debug_print(egl_client_type); 481 549 if (xret != XRT_SUCCESS) { 482 550 restore_context(&old); 551 + DESTROY_CONTEXT(display, context); 483 552 return xret; 484 553 } 485 554 ··· 490 559 xret = get_client_gl_functions(&sc_create_func, &insert_fence_func); 491 560 if (xret != XRT_SUCCESS) { 492 561 restore_context(&old); 562 + DESTROY_CONTEXT(display, context); 493 563 return xret; 494 564 } 495 565 ··· 513 583 free(ceglc); 514 584 EGL_ERROR("Failed to initialize compositor"); 515 585 restore_context(&old); 586 + DESTROY_CONTEXT(display, context); 516 587 return XRT_ERROR_OPENGL; 517 588 } 518 589