[client] egl: use eglGetPlatformDisplay(EXT) if possible

This commit is contained in:
Geoffrey McRae 2021-01-25 16:04:33 +11:00
parent 837858c214
commit 9e96156912
3 changed files with 38 additions and 27 deletions

View File

@ -23,6 +23,10 @@ struct EGLDynProcs g_dynprocs = {0};
void egl_dynProcsInit(void) void egl_dynProcsInit(void)
{ {
g_dynprocs.eglGetPlatformDisplay = (eglGetPlatformDisplayEXT_t)
eglGetProcAddress("eglGetPlatformDisplay");
g_dynprocs.eglGetPlatformDisplayEXT = (eglGetPlatformDisplayEXT_t)
eglGetProcAddress("eglGetPlatformDisplayEXT");
g_dynprocs.glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t) g_dynprocs.glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t)
eglGetProcAddress("glEGLImageTargetTexture2DOES"); eglGetProcAddress("glEGLImageTargetTexture2DOES");
}; };

View File

@ -20,10 +20,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <SDL2/SDL_egl.h> #include <SDL2/SDL_egl.h>
#include <GL/gl.h> #include <GL/gl.h>
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 struct EGLDynProcs
{ {
eglGetPlatformDisplayEXT_t eglGetPlatformDisplay;
eglGetPlatformDisplayEXT_t eglGetPlatformDisplayEXT;
glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES; glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES;
}; };

View File

@ -506,43 +506,28 @@ bool egl_render_startup(void * opaque, SDL_Window * window)
return false; return false;
} }
bool useNative = false; egl_dynProcsInit();
{
const char *client_exts = eglQueryString(NULL, EGL_EXTENSIONS);
if (strstr(client_exts, "EGL_KHR_platform_base") != NULL)
useNative = true;
}
DEBUG_INFO("use native: %s", useNative ? "true" : "false"); EGLNativeDisplayType native;
EGLenum platform;
switch(wminfo.subsystem) switch(wminfo.subsystem)
{ {
case SDL_SYSWM_X11: case SDL_SYSWM_X11:
{ native = (EGLNativeDisplayType)wminfo.info.x11.display;
if (!useNative) platform = EGL_PLATFORM_X11_KHR;
this->display = eglGetPlatformDisplay(EGL_PLATFORM_X11_KHR, wminfo.info.x11.display, NULL);
else
{
EGLNativeDisplayType native = (EGLNativeDisplayType)wminfo.info.x11.display;
this->display = eglGetDisplay(native);
}
this->nativeWind = (EGLNativeWindowType)wminfo.info.x11.window; this->nativeWind = (EGLNativeWindowType)wminfo.info.x11.window;
break; break;
}
#if defined(SDL_VIDEO_DRIVER_WAYLAND) #if defined(SDL_VIDEO_DRIVER_WAYLAND)
case SDL_SYSWM_WAYLAND: case SDL_SYSWM_WAYLAND:
{ {
int width, height; int width, height;
SDL_GetWindowSize(window, &width, &height); SDL_GetWindowSize(window, &width, &height);
if (!useNative) native = (EGLNativeDisplayType)wminfo.info.wl.display;
this->display = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, wminfo.info.wl.display, NULL); platform = EGL_PLATFORM_WAYLAND_KHR;
else this->nativeWind = (EGLNativeWindowType)wl_egl_window_create(
{ wminfo.info.wl.surface, width, height);
EGLNativeDisplayType native = (EGLNativeDisplayType)wminfo.info.wl.display;
this->display = eglGetDisplay(native);
}
this->nativeWind = (EGLNativeWindowType)wl_egl_window_create(wminfo.info.wl.surface, width, height);
break; break;
} }
#endif #endif
@ -552,6 +537,25 @@ bool egl_render_startup(void * opaque, SDL_Window * window)
return false; 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) if (this->display == EGL_NO_DISPLAY)
{ {
DEBUG_ERROR("eglGetDisplay failed"); 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 *client_exts = eglQueryString(this->display, EGL_EXTENSIONS);
const char *vendor = (const char *)glGetString(GL_VENDOR); const char *vendor = (const char *)glGetString(GL_VENDOR);
egl_dynProcsInit();
DEBUG_INFO("EGL : %d.%d", maj, min); DEBUG_INFO("EGL : %d.%d", maj, min);
DEBUG_INFO("Vendor : %s", vendor); DEBUG_INFO("Vendor : %s", vendor);
DEBUG_INFO("Renderer : %s", glGetString(GL_RENDERER)); DEBUG_INFO("Renderer : %s", glGetString(GL_RENDERER));