diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2013-11-14 15:01:58 -0800 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2013-11-14 15:05:50 -0800 |
| commit | 392d1a830bbebf5a4bc56d93f27a05a06e46efa7 (patch) | |
| tree | 7cc43522575b246162c930c67bdbbcf30b641eb2 /src | |
| parent | 5ce15170a6ef08d0ef96653fa27b0b550d4068f0 (diff) | |
Factor out some temporary variables, using graphics_state directly
Diffstat (limited to 'src')
| -rw-r--r-- | src/surface-glx.cpp | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/src/surface-glx.cpp b/src/surface-glx.cpp index 3c0000c..a8548ac 100644 --- a/src/surface-glx.cpp +++ b/src/surface-glx.cpp @@ -6,6 +6,7 @@ struct graphics_state { Display *dpy; Window window; + GLXContext glx_context; }; @@ -26,6 +27,8 @@ cairo_surface_t * create_source_surface_glx (int width, int height) { struct graphics_state *state; + cairo_device_t *cairo_device; + cairo_surface_t *cairo_surface; int rgba_attribs[] = { GLX_RGBA, @@ -37,61 +40,56 @@ create_source_surface_glx (int width, int height) None }; XVisualInfo *visinfo; - GLXContext ctx; - cairo_device_t *device; - cairo_surface_t *surface; - Display *dpy; XSetWindowAttributes xattr; - Window window; - dpy = XOpenDisplay (NULL); - if (dpy == NULL) { + state = (graphics_state*) malloc (sizeof (struct graphics_state)); + 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 (dpy, DefaultScreen (dpy), rgba_attribs); + visinfo = glXChooseVisual (state->dpy, DefaultScreen (state->dpy), rgba_attribs); if (visinfo == NULL) { warnx ("Failed to create RGBA and double-buffered visuals\n"); - XCloseDisplay (dpy); + XCloseDisplay (state->dpy); return NULL; } - xattr.colormap = XCreateColormap (dpy, RootWindow (dpy, visinfo->screen), + xattr.colormap = XCreateColormap (state->dpy, + RootWindow (state->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); + 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); - ctx = glXCreateContext (dpy, visinfo, NULL, True); + state->glx_context = glXCreateContext (state->dpy, visinfo, NULL, True); XFree (visinfo); - if (ctx == NULL) { + if (state->glx_context == NULL) { warnx ("Could not create glx context\n"); - XCloseDisplay (dpy); + XCloseDisplay (state->dpy); return NULL; } - state = (graphics_state*) malloc (sizeof (struct graphics_state)); - if (!state) { - warnx ("Out of memory\n"); - XCloseDisplay (dpy); - 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_device = cairo_glx_device_create (state->dpy, state->glx_context); + cairo_gl_device_set_thread_aware (cairo_device, 0); + cairo_surface = cairo_gl_surface_create_for_window (cairo_device, + state->window, + width, + height); + if (cairo_device_set_user_data (cairo_device, (cairo_user_data_key_t *) cleanup, state, cleanup)) @@ -101,7 +99,7 @@ create_source_surface_glx (int width, int height) return NULL; } - cairo_device_destroy (device); + cairo_device_destroy (cairo_device); - return surface; + return cairo_surface; } |