gl-renderer: call supports() automatically in create()

This means compositors don't need to call supports() manually and
create() will just return -1 in the failure case as before. This also
means we can deal with the case of eglGetProcAddress returning
non-NULL but not actually being available at runtime.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Jonny Lamb 10 years ago committed by Pekka Paalanen
parent ace6920912
commit 74eed31108
  1. 4
      src/compositor-drm.c
  2. 3
      src/compositor-fbdev.c
  3. 7
      src/compositor-wayland.c
  4. 3
      src/compositor-x11.c
  5. 46
      src/gl-renderer.c
  6. 5
      src/gl-renderer.h

@ -1396,10 +1396,6 @@ drm_compositor_create_gl_renderer(struct drm_compositor *ec)
{ {
EGLint format; EGLint format;
if (gl_renderer->supports(&ec->base, "gbm") < 0) {
return -1;
}
format = ec->format; format = ec->format;
if (gl_renderer->create(&ec->base, EGL_PLATFORM_GBM_KHR, (void *) ec->gbm, if (gl_renderer->create(&ec->base, EGL_PLATFORM_GBM_KHR, (void *) ec->gbm,
gl_renderer->opaque_attribs, &format) < 0) { gl_renderer->opaque_attribs, &format) < 0) {

@ -868,7 +868,8 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
goto out_launcher; 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, gl_renderer->opaque_attribs,
NULL) < 0) { NULL) < 0) {
weston_log("gl_renderer_create failed.\n"); weston_log("gl_renderer_create failed.\n");

@ -1962,12 +1962,7 @@ wayland_compositor_create(struct wl_display *display, int use_pixman,
} }
if (!c->use_pixman) { if (!c->use_pixman) {
if (gl_renderer->supports(&c->base, "wayland") < 0) { if (gl_renderer->create(&c->base,
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,
EGL_PLATFORM_WAYLAND_KHR, EGL_PLATFORM_WAYLAND_KHR,
c->parent.wl_display, c->parent.wl_display,
gl_renderer->alpha_attribs, gl_renderer->alpha_attribs,

@ -1492,9 +1492,6 @@ init_gl_renderer(struct x11_compositor *c)
if (!gl_renderer) if (!gl_renderer)
return -1; 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, ret = gl_renderer->create(&c->base, EGL_PLATFORM_X11_KHR, (void *) c->dpy,
gl_renderer->opaque_attribs, NULL); gl_renderer->opaque_attribs, NULL);

@ -2240,6 +2240,21 @@ gl_renderer_supports(struct weston_compositor *ec,
return -1; 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 static int
gl_renderer_create(struct weston_compositor *ec, EGLenum platform, gl_renderer_create(struct weston_compositor *ec, EGLenum platform,
void *native_window, const EGLint *attribs, void *native_window, const EGLint *attribs,
@ -2247,6 +2262,14 @@ gl_renderer_create(struct weston_compositor *ec, EGLenum platform,
{ {
struct gl_renderer *gr; struct gl_renderer *gr;
EGLint major, minor; 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); gr = zalloc(sizeof *gr);
if (gr == NULL) if (gr == NULL)
@ -2261,26 +2284,34 @@ gl_renderer_create(struct weston_compositor *ec, EGLenum platform,
gr->base.surface_get_content_size = gr->base.surface_get_content_size =
gl_renderer_surface_get_content_size; gl_renderer_surface_get_content_size;
gr->base.surface_copy_content = gl_renderer_surface_copy_content; gr->base.surface_copy_content = gl_renderer_surface_copy_content;
gr->egl_display = NULL;
#ifdef EGL_EXT_platform_base #ifdef EGL_EXT_platform_base
/* the platform extension is supported */
if (supports) {
if (!get_platform_display) { if (!get_platform_display) {
get_platform_display = get_platform_display = (void *) eglGetProcAddress(
(void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); "eglGetPlatformDisplayEXT");
} }
/* 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) { if (get_platform_display && platform) {
gr->egl_display = gr->egl_display = get_platform_display(platform,
get_platform_display(platform, native_window, native_window,
NULL); NULL);
} else { }
}
#endif #endif
if (!gr->egl_display) {
weston_log("warning: either no EGL_EXT_platform_base " weston_log("warning: either no EGL_EXT_platform_base "
"support or specific platform support; " "support or specific platform support; "
"falling back to eglGetDisplay.\n"); "falling back to eglGetDisplay.\n");
gr->egl_display = eglGetDisplay(native_window); gr->egl_display = eglGetDisplay(native_window);
#ifdef EGL_EXT_platform_base
} }
#endif
if (gr->egl_display == EGL_NO_DISPLAY) { if (gr->egl_display == EGL_NO_DISPLAY) {
weston_log("failed to create display\n"); 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, .opaque_attribs = gl_renderer_opaque_attribs,
.alpha_attribs = gl_renderer_alpha_attribs, .alpha_attribs = gl_renderer_alpha_attribs,
.supports = gl_renderer_supports,
.create = gl_renderer_create, .create = gl_renderer_create,
.display = gl_renderer_display, .display = gl_renderer_display,
.output_create = gl_renderer_output_create, .output_create = gl_renderer_output_create,

@ -53,6 +53,8 @@ typedef intptr_t EGLNativeWindowType;
#define EGL_PLATFORM_X11_KHR 0x31D5 #define EGL_PLATFORM_X11_KHR 0x31D5
#endif #endif
#define NO_EGL_PLATFORM 0
enum gl_renderer_border_side { enum gl_renderer_border_side {
GL_RENDERER_BORDER_TOP = 0, GL_RENDERER_BORDER_TOP = 0,
GL_RENDERER_BORDER_LEFT = 1, GL_RENDERER_BORDER_LEFT = 1,
@ -64,9 +66,6 @@ struct gl_renderer_interface {
const EGLint *opaque_attribs; const EGLint *opaque_attribs;
const EGLint *alpha_attribs; const EGLint *alpha_attribs;
int (*supports)(struct weston_compositor *ec,
const char *extension_suffix);
int (*create)(struct weston_compositor *ec, int (*create)(struct weston_compositor *ec,
EGLenum platform, EGLenum platform,
void *native_window, void *native_window,

Loading…
Cancel
Save