diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2010-03-11 01:48:43 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2010-03-11 01:49:18 +0000 |
commit | b101c7dab8cdbf7b9321355a8d2311b2f863f011 (patch) | |
tree | 8357716b0e3bbbae3e3e2bcc8bb5fc3ea7e49fe4 /boilerplate | |
parent | ca6e4e1f91e0a90666551d2fa74cfc04484d4e80 (diff) |
gl: Add EGL interface
Enable the EGL backend for GL.
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/Makefile.win32.features | 8 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate-gl.c | 98 |
2 files changed, 106 insertions, 0 deletions
diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features index 31bd4e06..4781d8a4 100644 --- a/boilerplate/Makefile.win32.features +++ b/boilerplate/Makefile.win32.features @@ -199,6 +199,14 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_png_private) enabled_cairo_boilerplate_sources += $(cairo_boilerplate_png_sources) endif +supported_cairo_boilerplate_headers += $(cairo_boilerplate_glew_headers) +all_cairo_boilerplate_headers += $(cairo_boilerplate_glew_headers) +all_cairo_boilerplate_private += $(cairo_boilerplate_glew_private) +all_cairo_boilerplate_sources += $(cairo_boilerplate_glew_sources) +enabled_cairo_boilerplate_headers += $(cairo_boilerplate_glew_headers) +enabled_cairo_boilerplate_private += $(cairo_boilerplate_glew_private) +enabled_cairo_boilerplate_sources += $(cairo_boilerplate_glew_sources) + unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_gl_headers) all_cairo_boilerplate_headers += $(cairo_boilerplate_gl_headers) all_cairo_boilerplate_private += $(cairo_boilerplate_gl_private) diff --git a/boilerplate/cairo-boilerplate-gl.c b/boilerplate/cairo-boilerplate-gl.c index d8e40597..59de580d 100644 --- a/boilerplate/cairo-boilerplate-gl.c +++ b/boilerplate/cairo-boilerplate-gl.c @@ -237,6 +237,91 @@ _cairo_boilerplate_gl_synchronize (void *closure) cairo_gl_surface_glfinish (gltc->surface); } +#if CAIRO_HAS_EGL_FUNCTIONS +typedef struct _egl_target_closure { + EGLDisplay dpy; + EGLContext ctx; + + cairo_device_t *device; + cairo_surface_t *surface; +} egl_target_closure_t; + +static void +_cairo_boilerplate_egl_cleanup (void *closure) +{ + egl_target_closure_t *gltc = closure; + + cairo_device_finish (gltc->device); + cairo_device_destroy (gltc->device); + + eglDestroyContext (gltc->dpy, gltc->ctx); + eglMakeCurrent (gltc->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglTerminate (gltc->dpy); + + free (gltc); +} + +static cairo_surface_t * +_cairo_boilerplate_egl_create_surface (const char *name, + cairo_content_t content, + double width, + double height, + double max_width, + double max_height, + cairo_boilerplate_mode_t mode, + int id, + void **closure) +{ + egl_target_closure_t *gltc; + cairo_surface_t *surface; + int major, minor; + EGLConfig *configs; + EGLint numConfigs; + + gltc = xcalloc (1, sizeof (gl_target_closure_t)); + *closure = gltc; + + gltc->dpy = eglGetDisplay (EGL_DEFAULT_DISPLAY); + + if (! eglInitialize (gltc->dpy, &major, &minor)) { + free (gltc); + return NULL; + } + + eglGetConfigs (gltc->dpy, NULL, 0, &numConfigs); + configs = xmalloc(sizeof(*configs) *numConfigs); + eglGetConfigs (gltc->dpy, configs, numConfigs, &numConfigs); + + eglBindAPI (EGL_OPENGL_API); + + gltc->ctx = eglCreateContext (gltc->dpy, configs[0], EGL_NO_CONTEXT, NULL); + if (gltc->ctx == EGL_NO_CONTEXT) { + eglTerminate (gltc->dpy); + free (gltc); + return NULL; + } + + gltc->device = cairo_egl_device_create (gltc->dpy, gltc->ctx); + + gltc->surface = surface = cairo_gl_surface_create (gltc->device, + content, + ceil (width), + ceil (height)); + if (cairo_surface_status (surface)) + _cairo_boilerplate_egl_cleanup (gltc); + + return surface; +} + +static void +_cairo_boilerplate_egl_synchronize (void *closure) +{ + egl_target_closure_t *gltc = closure; + + cairo_gl_surface_glfinish (gltc->surface); +} +#endif + static const cairo_boilerplate_target_t targets[] = { { "gl", "gl", NULL, NULL, @@ -272,5 +357,18 @@ static const cairo_boilerplate_target_t targets[] = { _cairo_boilerplate_gl_cleanup, _cairo_boilerplate_gl_synchronize }, +#if CAIRO_HAS_EGL_FUNCTIONS + { + "egl", "gl", NULL, NULL, + CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1, + "cairo_egl_device_create", + _cairo_boilerplate_egl_create_surface, + NULL, NULL, + _cairo_boilerplate_get_image_surface, + cairo_surface_write_to_png, + _cairo_boilerplate_egl_cleanup, + _cairo_boilerplate_egl_synchronize + }, +#endif }; CAIRO_BOILERPLATE (gl, targets) |