Skip to content

Commit

Permalink
[client] egl: use eglGetPlatformDisplay(EXT) if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Jan 25, 2021
1 parent 837858c commit 9e96156
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
4 changes: 4 additions & 0 deletions client/renderers/EGL/dynprocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
7 changes: 6 additions & 1 deletion client/renderers/EGL/dynprocs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <SDL2/SDL_egl.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
{
eglGetPlatformDisplayEXT_t eglGetPlatformDisplay;
eglGetPlatformDisplayEXT_t eglGetPlatformDisplayEXT;
glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES;
};

Expand Down
54 changes: 28 additions & 26 deletions client/renderers/EGL/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9e96156

Please sign in to comment.