diff options
Diffstat (limited to 'src/caskbench.cpp')
| -rw-r--r-- | src/caskbench.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/src/caskbench.cpp b/src/caskbench.cpp index 0bd6f7e..d0f5ff6 100644 --- a/src/caskbench.cpp +++ b/src/caskbench.cpp @@ -6,6 +6,7 @@ #include <err.h> #include <cairo.h> +#include <cairo-gl.h> #include <SkBitmap.h> #include <SkBitmapDevice.h> @@ -101,8 +102,6 @@ process_options(caskbench_options_t *opt, int argc, char *argv[]) {NULL} }; - assert(opt); - // Initialize options opt->dry_run = 0; opt->iterations = 64; @@ -156,6 +155,84 @@ randomize_color(cairo_t *cr) cairo_set_source_rgba (cr, red, green, blue, alpha); } +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); +} + +static cairo_surface_t * +create_source_surface_glx (int size) +{ + 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, + size, size); + cairo_device_destroy (device); + + return surface; +} + int main (int argc, char *argv[]) { @@ -177,6 +254,7 @@ main (int argc, char *argv[]) // Setup caskbench_context_t context; caskbench_result_t result; + // TODO: Set up a gl surface cairo_surface_t *cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 800, 80); SkBitmap bitmap; |