summaryrefslogtreecommitdiffstatsci
path: root/src/surface-glx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/surface-glx.cpp')
-rw-r--r--src/surface-glx.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/surface-glx.cpp b/src/surface-glx.cpp
index 383aa4c..3c0000c 100644
--- a/src/surface-glx.cpp
+++ b/src/surface-glx.cpp
@@ -4,8 +4,8 @@
#include <cairo-gl.h>
struct graphics_state {
- Display *dpy;
-
+ Display *dpy;
+ Window window;
GLXContext glx_context;
};
@@ -15,6 +15,8 @@ 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);
@@ -23,6 +25,8 @@ cleanup (void *data)
cairo_surface_t *
create_source_surface_glx (int width, int height)
{
+ struct graphics_state *state;
+
int rgba_attribs[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
@@ -34,10 +38,11 @@ create_source_surface_glx (int width, int height)
};
XVisualInfo *visinfo;
GLXContext ctx;
- struct graphics_state *state;
cairo_device_t *device;
cairo_surface_t *surface;
Display *dpy;
+ XSetWindowAttributes xattr;
+ Window window;
dpy = XOpenDisplay (NULL);
if (dpy == NULL) {
@@ -47,11 +52,21 @@ create_source_surface_glx (int width, int height)
visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);
if (visinfo == NULL) {
- warnx ("Failed to choose glx visual\n");
+ warnx ("Failed to create RGBA and double-buffered visuals\n");
XCloseDisplay (dpy);
return NULL;
}
+ xattr.colormap = XCreateColormap (dpy, RootWindow (dpy, visinfo->screen),
+ visinfo->visual, AllocNone);
+ xattr.border_pixel = 0;
+ window = XCreateWindow (dpy, DefaultRootWindow (dpy), 100, 50,
+ width, height, 0, visinfo->depth,
+ InputOutput, visinfo->visual,
+ CWBorderPixel | CWColormap,
+ &xattr);
+ XMapWindow (dpy, window);
+
ctx = glXCreateContext (dpy, visinfo, NULL, True);
XFree (visinfo);
@@ -68,8 +83,14 @@ create_source_surface_glx (int width, int height)
return NULL;
}
state->dpy = dpy;
+ state->window = window;
state->glx_context = ctx;
device = cairo_glx_device_create (dpy, ctx);
+ cairo_gl_device_set_thread_aware (device, 0);
+ surface = cairo_gl_surface_create_for_window (device,
+ window,
+ width,
+ height);
if (cairo_device_set_user_data (device,
(cairo_user_data_key_t *) cleanup,
state,
@@ -80,9 +101,6 @@ create_source_surface_glx (int width, int height)
return NULL;
}
- surface = cairo_gl_surface_create (device,
- CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
cairo_device_destroy (device);
return surface;