From 9e961569128cdc7f84ae9c30cda5375f580e50db Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 25 Jan 2021 16:04:33 +1100 Subject: [PATCH] [client] egl: use eglGetPlatformDisplay(EXT) if possible --- client/renderers/EGL/dynprocs.c | 4 +++ client/renderers/EGL/dynprocs.h | 7 ++++- client/renderers/EGL/egl.c | 54 +++++++++++++++++---------------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/client/renderers/EGL/dynprocs.c b/client/renderers/EGL/dynprocs.c index 65727d22..44079f4b 100644 --- a/client/renderers/EGL/dynprocs.c +++ b/client/renderers/EGL/dynprocs.c @@ -23,6 +23,10 @@ struct EGLDynProcs g_dynprocs = {0}; void egl_dynProcsInit(void) { + g_dynprocs.eglGetPlatformDisplay = (eglGetPlatformDisplayEXT_t) + eglGetProcAddress("eglGetPlatformDisplay"); + g_dynprocs.eglGetPlatformDisplayEXT = (eglGetPlatformDisplayEXT_t) + eglGetProcAddress("eglGetPlatformDisplayEXT"); g_dynprocs.glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t) eglGetProcAddress("glEGLImageTargetTexture2DOES"); }; diff --git a/client/renderers/EGL/dynprocs.h b/client/renderers/EGL/dynprocs.h index eaefb163..73b1aa83 100644 --- a/client/renderers/EGL/dynprocs.h +++ b/client/renderers/EGL/dynprocs.h @@ -20,10 +20,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include -typedef void (*glEGLImageTargetTexture2DOES_t)(GLenum target, GLeglImageOES image); +typedef EGLDisplay (*eglGetPlatformDisplayEXT_t)(EGLenum platform, + void *native_display, const EGLint *attrib_list); +typedef void (*glEGLImageTargetTexture2DOES_t)(GLenum target, + GLeglImageOES image); struct EGLDynProcs { + eglGetPlatformDisplayEXT_t eglGetPlatformDisplay; + eglGetPlatformDisplayEXT_t eglGetPlatformDisplayEXT; glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES; }; diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index 4ba93eac..f2d24896 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -506,43 +506,28 @@ bool egl_render_startup(void * opaque, SDL_Window * window) return false; } - bool useNative = false; - { - const char *client_exts = eglQueryString(NULL, EGL_EXTENSIONS); - if (strstr(client_exts, "EGL_KHR_platform_base") != NULL) - useNative = true; - } + egl_dynProcsInit(); - DEBUG_INFO("use native: %s", useNative ? "true" : "false"); + EGLNativeDisplayType native; + EGLenum platform; switch(wminfo.subsystem) { case SDL_SYSWM_X11: - { - if (!useNative) - this->display = eglGetPlatformDisplay(EGL_PLATFORM_X11_KHR, wminfo.info.x11.display, NULL); - else - { - EGLNativeDisplayType native = (EGLNativeDisplayType)wminfo.info.x11.display; - this->display = eglGetDisplay(native); - } + native = (EGLNativeDisplayType)wminfo.info.x11.display; + platform = EGL_PLATFORM_X11_KHR; this->nativeWind = (EGLNativeWindowType)wminfo.info.x11.window; break; - } #if defined(SDL_VIDEO_DRIVER_WAYLAND) case SDL_SYSWM_WAYLAND: { int width, height; SDL_GetWindowSize(window, &width, &height); - if (!useNative) - this->display = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, wminfo.info.wl.display, NULL); - else - { - EGLNativeDisplayType native = (EGLNativeDisplayType)wminfo.info.wl.display; - this->display = eglGetDisplay(native); - } - this->nativeWind = (EGLNativeWindowType)wl_egl_window_create(wminfo.info.wl.surface, width, height); + native = (EGLNativeDisplayType)wminfo.info.wl.display; + platform = EGL_PLATFORM_WAYLAND_KHR; + this->nativeWind = (EGLNativeWindowType)wl_egl_window_create( + wminfo.info.wl.surface, width, height); break; } #endif @@ -552,6 +537,25 @@ bool egl_render_startup(void * opaque, SDL_Window * window) return false; } + const char *early_exts = eglQueryString(NULL, EGL_EXTENSIONS); + if (strstr(early_exts, "EGL_KHR_platform_base") != NULL && + g_dynprocs.eglGetPlatformDisplay) + { + DEBUG_INFO("Using eglGetPlatformDisplay"); + this->display = g_dynprocs.eglGetPlatformDisplay(platform, native, NULL); + } + else if (strstr(early_exts, "EGL_EXT_platform_base") != NULL && + g_dynprocs.eglGetPlatformDisplayEXT) + { + DEBUG_INFO("Using eglGetPlatformDisplayEXT"); + this->display = g_dynprocs.eglGetPlatformDisplayEXT(platform, native, NULL); + } + else + { + DEBUG_INFO("Using eglGetDisplay"); + this->display = eglGetDisplay(native); + } + if (this->display == EGL_NO_DISPLAY) { DEBUG_ERROR("eglGetDisplay failed"); @@ -640,8 +644,6 @@ bool egl_render_startup(void * opaque, SDL_Window * window) const char *client_exts = eglQueryString(this->display, EGL_EXTENSIONS); const char *vendor = (const char *)glGetString(GL_VENDOR); - egl_dynProcsInit(); - DEBUG_INFO("EGL : %d.%d", maj, min); DEBUG_INFO("Vendor : %s", vendor); DEBUG_INFO("Renderer : %s", glGetString(GL_RENDERER));