summaryrefslogtreecommitdiffstatsci
path: root/src/cairo-glx.cpp
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2013-11-27 16:41:29 -0800
committerBryce Harrington <b.harrington@samsung.com>2013-11-27 17:57:10 -0800
commit365615ba981fe42df9c7ae5d3e5f9b4afd3d3f0a (patch)
tree954e2762c40208ebc3c0129b13b58ead092582d2 /src/cairo-glx.cpp
parent0e456412a299c62b1a7468851cf2305b9702ccc4 (diff)
Generalize the GLX code and refactor for skia to reuse
Diffstat (limited to 'src/cairo-glx.cpp')
-rw-r--r--src/cairo-glx.cpp68
1 files changed, 8 insertions, 60 deletions
diff --git a/src/cairo-glx.cpp b/src/cairo-glx.cpp
index 8465269..a5b0a2d 100644
--- a/src/cairo-glx.cpp
+++ b/src/cairo-glx.cpp
@@ -3,83 +3,31 @@
#include <cairo.h>
#include <cairo-gl.h>
-struct graphics_state {
- Display *dpy;
- Window window;
-
- GLXContext glx_context;
-};
+#include "glx.h"
static void
cleanup (void *data)
{
- struct graphics_state *state = (graphics_state*)data;
-
- glXDestroyContext (state->dpy, state->glx_context);
-
- XDestroyWindow (state->dpy, state->window);
- XCloseDisplay (state->dpy);
-
- free (state);
+ glx_state_t *state = (glx_state_t*)data;
+ destroyGLXContextAndWindow(state);
+ free(state);
}
cairo_surface_t *
create_cairo_surface_glx (int width, int height)
{
- struct graphics_state *state;
+ glx_state_t *state;
cairo_device_t *cairo_device;
cairo_surface_t *cairo_surface;
- 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;
- XSetWindowAttributes xattr;
-
- state = (graphics_state*) malloc (sizeof (struct graphics_state));
+ state = (glx_state_t*) malloc (sizeof (glx_state_t));
if (!state) {
warnx ("Out of memory\n");
return NULL;
}
- state->dpy = XOpenDisplay (NULL);
- if (state->dpy == NULL) {
- warnx ("Failed to open display: %s\n", XDisplayName (0));
- return NULL;
- }
-
- visinfo = glXChooseVisual (state->dpy, DefaultScreen (state->dpy), rgba_attribs);
- if (visinfo == NULL) {
- warnx ("Failed to create RGBA and double-buffered visuals\n");
- XCloseDisplay (state->dpy);
- return NULL;
- }
-
- xattr.colormap = XCreateColormap (state->dpy,
- RootWindow (state->dpy, visinfo->screen),
- visinfo->visual, AllocNone);
- xattr.border_pixel = 0;
- state->window = XCreateWindow (state->dpy,
- DefaultRootWindow (state->dpy),
- 100, 50,
- width, height, 0, visinfo->depth,
- InputOutput, visinfo->visual,
- CWBorderPixel | CWColormap,
- &xattr);
- XMapWindow (state->dpy, state->window);
-
- state->glx_context = glXCreateContext (state->dpy, visinfo, NULL, True);
- XFree (visinfo);
-
- if (state->glx_context == NULL) {
- warnx ("Could not create glx context\n");
- XCloseDisplay (state->dpy);
+ if (!createGLXContextAndWindow(state, width, height)) {
+ warnx ("Could not create GLX context and window\n");
return NULL;
}