diff --git a/src/compositor-drm.c b/src/compositor-drm.c index 9e42a8b4..43197a87 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -1396,10 +1396,6 @@ drm_compositor_create_gl_renderer(struct drm_compositor *ec) { EGLint format; - if (gl_renderer->supports(&ec->base, "gbm") < 0) { - return -1; - } - format = ec->format; if (gl_renderer->create(&ec->base, EGL_PLATFORM_GBM_KHR, (void *) ec->gbm, gl_renderer->opaque_attribs, &format) < 0) { diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c index b71affb8..bac6b87d 100644 --- a/src/compositor-fbdev.c +++ b/src/compositor-fbdev.c @@ -868,7 +868,8 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], goto out_launcher; } - if (gl_renderer->create(&compositor->base, 0, EGL_DEFAULT_DISPLAY, + if (gl_renderer->create(&compositor->base, NO_EGL_PLATFORM, + EGL_DEFAULT_DISPLAY, gl_renderer->opaque_attribs, NULL) < 0) { weston_log("gl_renderer_create failed.\n"); diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c index ca747c40..7e59ecd5 100644 --- a/src/compositor-wayland.c +++ b/src/compositor-wayland.c @@ -1962,12 +1962,7 @@ wayland_compositor_create(struct wl_display *display, int use_pixman, } if (!c->use_pixman) { - if (gl_renderer->supports(&c->base, "wayland") < 0) { - weston_log("No support for " - "EGL_{KHR,EXT,MESA}_platform_wayland; " - "falling back to pixman.\n"); - c->use_pixman = 1; - } else if (gl_renderer->create(&c->base, + if (gl_renderer->create(&c->base, EGL_PLATFORM_WAYLAND_KHR, c->parent.wl_display, gl_renderer->alpha_attribs, diff --git a/src/compositor-x11.c b/src/compositor-x11.c index 731b37c2..9792ac6d 100644 --- a/src/compositor-x11.c +++ b/src/compositor-x11.c @@ -1492,9 +1492,6 @@ init_gl_renderer(struct x11_compositor *c) if (!gl_renderer) return -1; - if (gl_renderer->supports(&c->base, "x11") < 0) - return -1; - ret = gl_renderer->create(&c->base, EGL_PLATFORM_X11_KHR, (void *) c->dpy, gl_renderer->opaque_attribs, NULL); diff --git a/src/gl-renderer.c b/src/gl-renderer.c index d4e8f1ef..2c36a8dd 100644 --- a/src/gl-renderer.c +++ b/src/gl-renderer.c @@ -2240,6 +2240,21 @@ gl_renderer_supports(struct weston_compositor *ec, return -1; } +static const char * +platform_to_extension(EGLenum platform) +{ + switch (platform) { + case EGL_PLATFORM_GBM_KHR: + return "gbm"; + case EGL_PLATFORM_WAYLAND_KHR: + return "wayland"; + case EGL_PLATFORM_X11_KHR: + return "x11"; + default: + assert(0 && "bad EGL platform enum"); + } +} + static int gl_renderer_create(struct weston_compositor *ec, EGLenum platform, void *native_window, const EGLint *attribs, @@ -2247,6 +2262,14 @@ gl_renderer_create(struct weston_compositor *ec, EGLenum platform, { struct gl_renderer *gr; EGLint major, minor; + int supports = 0; + + if (platform) { + supports = gl_renderer_supports( + ec, platform_to_extension(platform)); + if (supports < 0) + return -1; + } gr = zalloc(sizeof *gr); if (gr == NULL) @@ -2261,26 +2284,34 @@ gl_renderer_create(struct weston_compositor *ec, EGLenum platform, gr->base.surface_get_content_size = gl_renderer_surface_get_content_size; gr->base.surface_copy_content = gl_renderer_surface_copy_content; + gr->egl_display = NULL; #ifdef EGL_EXT_platform_base - if (!get_platform_display) { - get_platform_display = - (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); - } + /* the platform extension is supported */ + if (supports) { + if (!get_platform_display) { + get_platform_display = (void *) eglGetProcAddress( + "eglGetPlatformDisplayEXT"); + } - if (get_platform_display && platform) { - gr->egl_display = - get_platform_display(platform, native_window, - NULL); - } else { + /* also wrap this in the supports check because + * eglGetProcAddress can return non-NULL and still not + * support the feature at runtime, so ensure the + * appropriate extension checks have been done. */ + if (get_platform_display && platform) { + gr->egl_display = get_platform_display(platform, + native_window, + NULL); + } + } #endif + + if (!gr->egl_display) { weston_log("warning: either no EGL_EXT_platform_base " "support or specific platform support; " "falling back to eglGetDisplay.\n"); gr->egl_display = eglGetDisplay(native_window); -#ifdef EGL_EXT_platform_base } -#endif if (gr->egl_display == EGL_NO_DISPLAY) { weston_log("failed to create display\n"); @@ -2493,7 +2524,6 @@ WL_EXPORT struct gl_renderer_interface gl_renderer_interface = { .opaque_attribs = gl_renderer_opaque_attribs, .alpha_attribs = gl_renderer_alpha_attribs, - .supports = gl_renderer_supports, .create = gl_renderer_create, .display = gl_renderer_display, .output_create = gl_renderer_output_create, diff --git a/src/gl-renderer.h b/src/gl-renderer.h index 2434fddc..4208bf12 100644 --- a/src/gl-renderer.h +++ b/src/gl-renderer.h @@ -53,6 +53,8 @@ typedef intptr_t EGLNativeWindowType; #define EGL_PLATFORM_X11_KHR 0x31D5 #endif +#define NO_EGL_PLATFORM 0 + enum gl_renderer_border_side { GL_RENDERER_BORDER_TOP = 0, GL_RENDERER_BORDER_LEFT = 1, @@ -64,9 +66,6 @@ struct gl_renderer_interface { const EGLint *opaque_attribs; const EGLint *alpha_attribs; - int (*supports)(struct weston_compositor *ec, - const char *extension_suffix); - int (*create)(struct weston_compositor *ec, EGLenum platform, void *native_window,