Skip to content

Commit

Permalink
egl-helpers: fix display init for x11
Browse files Browse the repository at this point in the history
When running on gtk we need X11 platform not mesa platform.
Create separate functions for mesa and x11 so we can keep
the egl #ifdef mess local to egl-helpers.c

Fixes: 0ea1523
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20170505104101.30589-4-kraxel@redhat.com
  • Loading branch information
kraxel committed May 12, 2017
1 parent 9f728c7 commit e1913db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion include/ui/egl-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc);

EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);

int qemu_egl_init_dpy(EGLNativeDisplayType dpy);
int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy);
int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy);
EGLContext qemu_egl_init_ctx(void);

#endif /* EGL_HELPERS_H */
34 changes: 26 additions & 8 deletions ui/egl-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int egl_rendernode_init(const char *rendernode)
goto err;
}

qemu_egl_init_dpy((EGLNativeDisplayType)qemu_egl_rn_gbm_dev);
qemu_egl_init_dpy_mesa((EGLNativeDisplayType)qemu_egl_rn_gbm_dev);

if (!epoxy_has_egl_extension(qemu_egl_display,
"EGL_KHR_surfaceless_context")) {
Expand Down Expand Up @@ -206,20 +206,19 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win)
* platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
* like mesa will be able to advertise these (even though it can do EGL 1.5).
*/
static EGLDisplay qemu_egl_get_display(void *native)
static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
EGLenum platform)
{
EGLDisplay dpy = EGL_NO_DISPLAY;

#ifdef EGL_MESA_platform_gbm
/* In practise any EGL 1.5 implementation would support the EXT extension */
if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) {
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT =
(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
if (getPlatformDisplayEXT) {
dpy = getPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, native, NULL);
if (getPlatformDisplayEXT && platform != 0) {
dpy = getPlatformDisplayEXT(platform, native, NULL);
}
}
#endif

if (dpy == EGL_NO_DISPLAY) {
/* fallback */
Expand All @@ -228,7 +227,8 @@ static EGLDisplay qemu_egl_get_display(void *native)
return dpy;
}

int qemu_egl_init_dpy(EGLNativeDisplayType dpy)
static int qemu_egl_init_dpy(EGLNativeDisplayType dpy,
EGLenum platform)
{
static const EGLint conf_att_gl[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
Expand All @@ -243,7 +243,7 @@ int qemu_egl_init_dpy(EGLNativeDisplayType dpy)
EGLBoolean b;
EGLint n;

qemu_egl_display = qemu_egl_get_display(dpy);
qemu_egl_display = qemu_egl_get_display(dpy, platform);
if (qemu_egl_display == EGL_NO_DISPLAY) {
error_report("egl: eglGetDisplay failed");
return -1;
Expand All @@ -270,6 +270,24 @@ int qemu_egl_init_dpy(EGLNativeDisplayType dpy)
return 0;
}

int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy)
{
#ifdef EGL_KHR_platform_x11
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR);
#else
return qemu_egl_init_dpy(dpy, 0);
#endif
}

int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy)
{
#ifdef EGL_MESA_platform_gbm
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA);
#else
return qemu_egl_init_dpy(dpy, 0);
#endif
}

EGLContext qemu_egl_init_ctx(void)
{
static const EGLint ctx_att_gl[] = {
Expand Down
2 changes: 1 addition & 1 deletion ui/gtk-egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void gtk_egl_init(void)
GdkDisplay *gdk_display = gdk_display_get_default();
Display *x11_display = gdk_x11_display_get_xdisplay(gdk_display);

if (qemu_egl_init_dpy(x11_display) < 0) {
if (qemu_egl_init_dpy_x11(x11_display) < 0) {
return;
}

Expand Down

0 comments on commit e1913db

Please sign in to comment.