From f9b50971346f18ef55277b7b9df1e743a50ea0f8 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 26 May 2021 13:23:37 +0100 Subject: [PATCH] c/client: Use the EGL compositor's display in swapchain --- doc/changes/compositor/mr.827.md | 2 + src/xrt/compositor/CMakeLists.txt | 1 + src/xrt/compositor/client/comp_egl_client.c | 31 +----------- src/xrt/compositor/client/comp_egl_client.h | 50 +++++++++++++++++++ .../client/comp_gl_eglimage_swapchain.c | 4 +- src/xrt/compositor/meson.build | 1 + 6 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 doc/changes/compositor/mr.827.md create mode 100644 src/xrt/compositor/client/comp_egl_client.h diff --git a/doc/changes/compositor/mr.827.md b/doc/changes/compositor/mr.827.md new file mode 100644 index 000000000..d5aac18e0 --- /dev/null +++ b/doc/changes/compositor/mr.827.md @@ -0,0 +1,2 @@ +client: Use the EGL compositor's display in swapchain, previously it tried to +use the current one, which when running on a new thread would explode. diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt index dd4ce3a7f..4e137fabc 100644 --- a/src/xrt/compositor/CMakeLists.txt +++ b/src/xrt/compositor/CMakeLists.txt @@ -88,6 +88,7 @@ endif() if(XRT_HAVE_EGL) list(APPEND CLIENT_SOURCE_FILES client/comp_egl_client.c + client/comp_egl_client.h ) endif() diff --git a/src/xrt/compositor/client/comp_egl_client.c b/src/xrt/compositor/client/comp_egl_client.c index 77b35deec..f8885397b 100644 --- a/src/xrt/compositor/client/comp_egl_client.c +++ b/src/xrt/compositor/client/comp_egl_client.c @@ -22,6 +22,7 @@ #include "ogl/ogl_api.h" #include "client/comp_gl_client.h" +#include "client/comp_egl_client.h" #include "client/comp_gl_memobj_swapchain.h" #include "client/comp_gl_eglimage_swapchain.h" @@ -116,42 +117,12 @@ old_restore(struct old_helper *old, EGLDisplay current_dpy) } -/* - * - * EGL compositor subclass. - * - */ - -/*! - * EGL based compositor, carries the extra needed EGL information needed by the - * client side code and can handle both GL Desktop or GLES contexts. - * - * @ingroup comp_client - */ -struct client_egl_compositor -{ - struct client_gl_compositor base; - - EGLDisplay dpy; -}; - - /* * * Helper functions. * */ -/*! - * Down-cast helper. - * @protected @memberof client_egl_compositor - */ -static inline struct client_egl_compositor * -client_egl_compositor(struct xrt_compositor *xc) -{ - return (struct client_egl_compositor *)xc; -} - XRT_MAYBE_UNUSED static bool has_extension(const char *extensions, const char *ext) { diff --git a/src/xrt/compositor/client/comp_egl_client.h b/src/xrt/compositor/client/comp_egl_client.h new file mode 100644 index 000000000..14804ed7b --- /dev/null +++ b/src/xrt/compositor/client/comp_egl_client.h @@ -0,0 +1,50 @@ +// Copyright 2019-2021, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Glue code to EGL client side glue code. + * @author Jakob Bornecrantz + * @ingroup comp_client + */ + +#pragma once + +#include "xrt/xrt_compositor.h" + +#include "ogl/egl_api.h" + +#include "client/comp_gl_client.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*! + * EGL based compositor, carries the extra needed EGL information needed by the + * client side code and can handle both GL Desktop or GLES contexts. + * + * @ingroup comp_client + */ +struct client_egl_compositor +{ + struct client_gl_compositor base; + + EGLDisplay dpy; +}; + +/*! + * Down-cast helper. + * @protected @memberof client_egl_compositor + */ +static inline struct client_egl_compositor * +client_egl_compositor(struct xrt_compositor *xc) +{ + return (struct client_egl_compositor *)xc; +} + + +#ifdef __cplusplus +} +#endif diff --git a/src/xrt/compositor/client/comp_gl_eglimage_swapchain.c b/src/xrt/compositor/client/comp_gl_eglimage_swapchain.c index c29e49c2d..797e6cac7 100644 --- a/src/xrt/compositor/client/comp_gl_eglimage_swapchain.c +++ b/src/xrt/compositor/client/comp_gl_eglimage_swapchain.c @@ -27,6 +27,7 @@ #include "ogl/ogl_helpers.h" #include "client/comp_gl_client.h" +#include "client/comp_egl_client.h" #include "client/comp_gl_eglimage_swapchain.h" #include @@ -164,6 +165,7 @@ client_gl_eglimage_swapchain_create(struct xrt_compositor *xc, struct xrt_swapchain_native *xscn, struct client_gl_swapchain **out_sc) { + struct client_egl_compositor *ceglc = client_egl_compositor(xc); ll = debug_get_log_option_egl_swapchain_log(); if (xscn == NULL) { @@ -197,7 +199,7 @@ client_gl_eglimage_swapchain_create(struct xrt_compositor *xc, sc->base.base.base.reference.count = 1; sc->base.base.base.num_images = native_xsc->num_images; // Fetch the number of images from the native swapchain. sc->base.xscn = xscn; - sc->display = eglGetCurrentDisplay(); + sc->display = ceglc->dpy; struct xrt_swapchain_gl *xscgl = &sc->base.base; diff --git a/src/xrt/compositor/meson.build b/src/xrt/compositor/meson.build index 2ac4479c0..69957f81c 100644 --- a/src/xrt/compositor/meson.build +++ b/src/xrt/compositor/meson.build @@ -102,6 +102,7 @@ endif if build_egl compositor_srcs += [ 'client/comp_egl_client.c', + 'client/comp_egl_client.h', ] compositor_deps += [egl] endif