Skip to content

Commit

Permalink
egl: Use EGL_KHR_surfaceless_opengl extension when available
Browse files Browse the repository at this point in the history
This lets us avoid creating a throwaway pbuffer just to make the
context current.
  • Loading branch information
Kristian Høgsberg committed Jul 29, 2010
1 parent b6fd673 commit 14639e6
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions src/cairo-egl-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ _egl_destroy (void *abstract_ctx)
eglDestroySurface (ctx->display, ctx->dummy_surface);
}

static cairo_bool_t
_egl_make_current_surfaceless(cairo_egl_context_t *ctx)
{
const char *extensions;

extensions = eglQueryString(ctx->display, EGL_EXTENSIONS);
if (!strstr(extensions, "EGL_KHR_surfaceless_opengl"))
return FALSE;
if (!eglMakeCurrent(ctx->display,
EGL_NO_SURFACE, EGL_NO_SURFACE, ctx->context))
return FALSE;

return TRUE;
}

cairo_device_t *
cairo_egl_device_create (EGLDisplay dpy, EGLContext egl)
{
Expand All @@ -141,30 +156,33 @@ cairo_egl_device_create (EGLDisplay dpy, EGLContext egl)
ctx->base.swap_buffers = _egl_swap_buffers;
ctx->base.destroy = _egl_destroy;

/* dummy surface, meh. */
eglGetConfigs (dpy, NULL, 0, &numConfigs);
configs = malloc (sizeof(*configs) *numConfigs);
if (configs == NULL) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
}
eglGetConfigs (dpy, configs, numConfigs, &numConfigs);
ctx->dummy_surface = eglCreatePbufferSurface (dpy, configs[0], attribs);
free (configs);

if (ctx->dummy_surface == NULL) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
}

if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
if (!_egl_make_current_surfaceless (ctx)) {
/* Fall back to dummy surface, meh. */
eglGetConfigs (dpy, NULL, 0, &numConfigs);
configs = malloc (sizeof(*configs) *numConfigs);
if (configs == NULL) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
}
eglGetConfigs (dpy, configs, numConfigs, &numConfigs);
ctx->dummy_surface = eglCreatePbufferSurface (dpy, configs[0], attribs);
free (configs);

if (ctx->dummy_surface == NULL) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
}

if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) {
free (ctx);
return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
}
}

status = _cairo_gl_context_init (&ctx->base);
if (unlikely (status)) {
eglDestroySurface (dpy, ctx->dummy_surface);
if (ctx->dummy_surface != EGL_NO_SURFACE)
eglDestroySurface (dpy, ctx->dummy_surface);
free (ctx);
return _cairo_gl_context_create_in_error (status);
}
Expand Down

0 comments on commit 14639e6

Please sign in to comment.