diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2013-11-14 12:22:06 -0800 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2013-11-14 12:30:58 -0800 |
| commit | cc9e2372e887273a608fdb54b885b58f2743bf46 (patch) | |
| tree | 9ea53ade89e8122ad3d940f149b1c6c678ff6d86 /src/surface-glx.cpp | |
| parent | d2d46205e5494e1c74548a837219b46348864683 (diff) | |
Split out glx surface creation to its own file
Diffstat (limited to 'src/surface-glx.cpp')
| -rw-r--r-- | src/surface-glx.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/surface-glx.cpp b/src/surface-glx.cpp new file mode 100644 index 0000000..8285f5c --- /dev/null +++ b/src/surface-glx.cpp @@ -0,0 +1,81 @@ +#include <stdlib.h> +#include <cairo.h> +#include <cairo-gl.h> + +struct closure { + Display *dpy; + GLXContext ctx; +}; + +static void +cleanup (void *data) +{ + struct closure *arg = (closure*)data; + + glXDestroyContext (arg->dpy, arg->ctx); + XCloseDisplay (arg->dpy); + + free (arg); +} + +cairo_surface_t * +create_source_surface_glx (int width, int height) +{ + int rgba_attribs[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_ALPHA_SIZE, 1, + GLX_DOUBLEBUFFER, + None + }; + XVisualInfo *visinfo; + GLXContext ctx; + struct closure *arg; + cairo_device_t *device; + cairo_surface_t *surface; + Display *dpy; + + dpy = XOpenDisplay (NULL); + if (dpy == NULL) + return NULL; + + visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs); + if (visinfo == NULL) { + XCloseDisplay (dpy); + return NULL; + } + + ctx = glXCreateContext (dpy, visinfo, NULL, True); + XFree (visinfo); + + if (ctx == NULL) { + XCloseDisplay (dpy); + return NULL; + } + + arg = (closure*) malloc (sizeof (struct closure)); + if (!arg) { + XCloseDisplay (dpy); + return NULL; + } + arg->dpy = dpy; + arg->ctx = ctx; + device = cairo_glx_device_create (dpy, ctx); + if (cairo_device_set_user_data (device, + (cairo_user_data_key_t *) cleanup, + arg, + cleanup)) + { + cleanup (arg); + return NULL; + } + + surface = cairo_gl_surface_create (device, + CAIRO_CONTENT_COLOR_ALPHA, + width, height); + cairo_device_destroy (device); + + return surface; +} |