diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2013-12-18 15:39:37 -0800 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2013-12-18 15:39:37 -0800 |
| commit | 599030c8fe3b60e9b23d6dab5e62122c8331ef6f (patch) | |
| tree | 855f90b650aa636ccc0473d808276638f8ce25f3 /src | |
| parent | efdd7f7835e281cea9d6955696593361b5067c21 (diff) | |
Make destructors called explicitly rather than through callbacks
While Cairo has callback support for the destructor, there's not an
analogous way to do this with Skia, so instead of trying to be clever
let's just build explicit destruction in.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/cairo-egl.cpp | 27 | ||||
| -rw-r--r-- | src/cairo-glx.cpp | 26 | ||||
| -rw-r--r-- | src/cairo-image.cpp | 37 | ||||
| -rw-r--r-- | src/caskbench.cpp | 22 | ||||
| -rw-r--r-- | src/egl.cpp | 8 | ||||
| -rw-r--r-- | src/egl.h | 1 | ||||
| -rw-r--r-- | src/glx.cpp | 8 | ||||
| -rw-r--r-- | src/glx.h | 1 | ||||
| -rw-r--r-- | src/image.cpp | 11 | ||||
| -rw-r--r-- | src/image.h | 13 | ||||
| -rw-r--r-- | src/skia-egl.cpp | 34 | ||||
| -rw-r--r-- | src/skia-glx.cpp | 35 | ||||
| -rw-r--r-- | src/skia-image.cpp | 10 |
14 files changed, 119 insertions, 115 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e4da78..8ade285 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ file(GLOB caskbench_SOURCES caskbench.cpp + image.cpp cairo-image.cpp skia-image.cpp diff --git a/src/cairo-egl.cpp b/src/cairo-egl.cpp index 4144405..5435a10 100644 --- a/src/cairo-egl.cpp +++ b/src/cairo-egl.cpp @@ -8,18 +8,11 @@ #include "egl.h" -static void -cleanup (void *data) -{ - egl_state_t *state = (egl_state_t*)data; - destroyEGLContextAndWindow (state); - free (state); -} +static egl_state_t *state; cairo_surface_t * create_cairo_surface_egl (int width, int height) { - egl_state_t *state; cairo_device_t *cairo_device; cairo_surface_t *cairo_surface; @@ -30,7 +23,7 @@ create_cairo_surface_egl (int width, int height) } if (!createEGLContextAndWindow(state, width, height)) { - cleanup(state); + cleanup_state_egl(state); return NULL; } @@ -40,17 +33,13 @@ create_cairo_surface_egl (int width, int height) state->egl_surface, width, height); - if (cairo_device_set_user_data (cairo_device, - (cairo_user_data_key_t *) cleanup, - state, - cleanup)) - { - warnx ("Failed to setup cleanup callback closure\n"); - cleanup (state); - return NULL; - } - cairo_device_destroy (cairo_device); return cairo_surface; } + +void +destroy_cairo_egl(void) +{ + cleanup_state_egl(state); +} diff --git a/src/cairo-glx.cpp b/src/cairo-glx.cpp index a684d09..4c6fffc 100644 --- a/src/cairo-glx.cpp +++ b/src/cairo-glx.cpp @@ -5,18 +5,11 @@ #include "glx.h" -static void -cleanup (void *data) -{ - glx_state_t *state = (glx_state_t*)data; - destroyGLXContextAndWindow(state); - free(state); -} +static glx_state_t *state; cairo_surface_t * create_cairo_surface_glx (int width, int height) { - glx_state_t *state; cairo_device_t *cairo_device; cairo_surface_t *cairo_surface; @@ -28,6 +21,7 @@ create_cairo_surface_glx (int width, int height) if (!createGLXContextAndWindow(state, width, height)) { warnx ("Could not create GLX context and window\n"); + cleanup_state_glx(state); return NULL; } @@ -37,17 +31,13 @@ create_cairo_surface_glx (int width, int height) state->window, width, height); - if (cairo_device_set_user_data (cairo_device, - (cairo_user_data_key_t *) cleanup, - state, - cleanup)) - { - warnx ("Failed to setup cleanup callback closure\n"); - cleanup (state); - return NULL; - } - cairo_device_destroy (cairo_device); return cairo_surface; } + +void +destroy_cairo_glx(void) +{ + cleanup_state_glx(state); +} diff --git a/src/cairo-image.cpp b/src/cairo-image.cpp index 98fe05f..7c47ac8 100644 --- a/src/cairo-image.cpp +++ b/src/cairo-image.cpp @@ -3,30 +3,16 @@ #include <cairo.h> #include <cairo-gl.h> -struct graphics_state { - Display *dpy; - Window window; -}; +#include "image.h" -static void -cleanup (void *data) -{ - struct graphics_state *state = (graphics_state*)data; - - /* - XDestroyWindow (state->dpy, state->window); - XCloseDisplay (state->dpy); - */ - free (state); -} +static image_state_t *state; cairo_surface_t * create_cairo_surface_image (int width, int height) { - struct graphics_state *state; cairo_surface_t *cairo_surface; - state = (graphics_state*) malloc (sizeof (struct graphics_state)); + state = (image_state_t*) malloc (sizeof (image_state_t)); if (!state) { warnx ("Out of memory\n"); return NULL; @@ -44,15 +30,12 @@ create_cairo_surface_image (int width, int height) width, height); - if (cairo_surface_set_user_data (cairo_surface, - (cairo_user_data_key_t *) cleanup, - state, - cleanup)) - { - warnx ("Failed to setup cleanup callback closure\n"); - cleanup (state); - return NULL; - } - return cairo_surface; } + +void +destroy_cairo_image(void) +{ + cleanup_state_image(state); +} + diff --git a/src/caskbench.cpp b/src/caskbench.cpp index aadb475..0191768 100644 --- a/src/caskbench.cpp +++ b/src/caskbench.cpp @@ -42,21 +42,33 @@ typedef struct _caskbench_result { // Backend-specific graphics initialization cairo_surface_t * create_cairo_surface_image (int width, int height); +void +destroy_cairo_image(); SkBaseDevice * create_skia_device_image (int width, int height); +void +destroy_skia_image(); #ifdef HAVE_CAIRO_GL_H cairo_surface_t * create_cairo_surface_glx (int width, int height); +void +destroy_cairo_glx(); +void +destroy_skia_glx(); #endif #ifdef HAVE_GLES3_H cairo_surface_t * create_cairo_surface_egl (int width, int height); +void +destroy_cairo_egl(); SkBaseDevice * create_skia_device_egl (int width, int height); +void +destroy_skia_egl(); #endif void @@ -245,6 +257,8 @@ main (int argc, char *argv[]) caskbench_context_t context; caskbench_result_t result; SkPaint skia_paint; + void (*destroy_cairo)(void); + void (*destroy_skia)(void); context.size = opt.size; context.canvas_width = 800; @@ -257,11 +271,15 @@ main (int argc, char *argv[]) context.canvas_height); context.skia_device = create_skia_device_image ( context.canvas_width, context.canvas_height); + destroy_cairo = destroy_cairo_image; + destroy_skia = destroy_skia_image; #ifdef HAVE_CAIRO_GL_H } else if (!strncmp(opt.surface_type, "glx", 3)) { context.cairo_surface = create_cairo_surface_glx ( context.canvas_width, context.canvas_height); + destroy_cairo = destroy_cairo_glx; + destroy_skia = destroy_skia_glx; #endif #ifdef HAVE_GLES3_H @@ -270,6 +288,8 @@ main (int argc, char *argv[]) context.canvas_height); context.skia_device = create_skia_device_egl ( context.canvas_width, context.canvas_height); + destroy_cairo = destroy_cairo_egl; + destroy_skia = destroy_skia_egl; #endif } @@ -378,6 +398,8 @@ main (int argc, char *argv[]) delete context.skia_device; cairo_destroy(context.cairo_cr); cairo_surface_destroy(context.cairo_surface); + destroy_skia(); + destroy_cairo(); } if (opt.output_file) { diff --git a/src/egl.cpp b/src/egl.cpp index 82ba9cd..992d431 100644 --- a/src/egl.cpp +++ b/src/egl.cpp @@ -93,3 +93,11 @@ destroyEGLContextAndWindow (egl_state_t *state) XCloseDisplay (state->dpy); } } + +void +cleanup_state_egl(void *data) +{ + egl_state_t *state = (egl_state_t*)data; + destroyEGLContextAndWindow(state); + free(state); +} @@ -12,5 +12,6 @@ typedef struct { bool createEGLContextAndWindow(egl_state_t *state, int width, int height); void destroyEGLContextAndWindow(egl_state_t *state); +void cleanup_state_egl(void *data); #endif // __EGL_H__ diff --git a/src/glx.cpp b/src/glx.cpp index 4a18876..42a22ed 100644 --- a/src/glx.cpp +++ b/src/glx.cpp @@ -66,3 +66,11 @@ destroyGLXContextAndWindow (glx_state_t *state) XCloseDisplay (state->dpy); } } + +void +cleanup_state_glx (void *data) +{ + glx_state_t *state = (glx_state_t*)data; + destroyGLXContextAndWindow(state); + free(state); +} @@ -14,5 +14,6 @@ typedef struct { bool createGLXContextAndWindow(glx_state_t *state, int width, int height); void destroyGLXContextAndWindow(glx_state_t *state); +void cleanup_state_glx(void *state); #endif // __EGL_H__ diff --git a/src/image.cpp b/src/image.cpp new file mode 100644 index 0000000..b0bef53 --- /dev/null +++ b/src/image.cpp @@ -0,0 +1,11 @@ +#include <err.h> +#include <stdlib.h> + +#include "image.h" + +void +cleanup_state_image (void *data) +{ + image_state_t *state = (image_state_t*)data; + free(state); +} diff --git a/src/image.h b/src/image.h new file mode 100644 index 0000000..5fbb4a6 --- /dev/null +++ b/src/image.h @@ -0,0 +1,13 @@ +#ifndef __EGL_H__ // -*- mode: c++ -*- +#define __EGL_H__ + +#include <X11/Xlib.h> + +typedef struct { + Display *dpy; + Window window; +} image_state_t; + +void cleanup_state_image(void *data); + +#endif // __EGL_H__ diff --git a/src/skia-egl.cpp b/src/skia-egl.cpp index 15caed5..1b3fe16 100644 --- a/src/skia-egl.cpp +++ b/src/skia-egl.cpp @@ -11,19 +11,11 @@ #include "egl.h" -static void -cleanup (void *data) -{ - egl_state_t *state = (egl_state_t*)data; - destroyEGLContextAndWindow (state); - free (state); -} +static egl_state_t *state; SkBaseDevice * create_skia_device_egl (int width, int height) { - egl_state_t *state; - GrBackendRenderTargetDesc desc; GrContext* ctx; GrRenderTarget* target; @@ -36,7 +28,7 @@ create_skia_device_egl (int width, int height) } if (!createEGLContextAndWindow(state, width, height)) { - cleanup(state); + cleanup_state_egl(state); return NULL; } @@ -54,21 +46,11 @@ create_skia_device_egl (int width, int height) target = ctx->wrapBackendRenderTarget(desc); device = new SkGpuDevice(ctx, target); - - /* TODO: Set cleanup routine to get called - - if (cairo_device_set_user_data (cairo_device, - (cairo_user_data_key_t *) cleanup, - state, - cleanup)) - { - warnx ("Failed to setup cleanup callback closure\n"); - cleanup (state); - return NULL; - } - - cairo_device_destroy (cairo_device); - */ - return device; } + +void +destroy_skia_egl(void) +{ + cleanup_state_egl(state); +} diff --git a/src/skia-glx.cpp b/src/skia-glx.cpp index 33ac276..fc273c0 100644 --- a/src/skia-glx.cpp +++ b/src/skia-glx.cpp @@ -8,19 +8,11 @@ #include "glx.h" -static void -cleanup (void *data) -{ - glx_state_t *state = (glx_state_t*)data; - destroyGLXContextAndWindow(state); - free(state); -} +static glx_state_t *state; SkBaseDevice * create_skia_device_glx (int width, int height) { - glx_state_t *state; - GrBackendRenderTargetDesc desc; GrContext* ctx; GrRenderTarget* target; @@ -28,12 +20,13 @@ create_skia_device_glx (int width, int height) state = (glx_state_t*) malloc (sizeof (glx_state_t)); if (!state) { - warnx ("Out of memory\n"); + warnx("Out of memory\n"); return NULL; } if (!createGLXContextAndWindow(state, width, height)) { - warnx ("Could not create GLX context and window\n"); + warnx("Could not create GLX context and window\n"); + cleanup_state_glx(state); return NULL; } @@ -49,19 +42,11 @@ create_skia_device_glx (int width, int height) target = ctx->wrapBackendRenderTarget(desc); device = new SkGpuDevice(ctx, target); - /* - if (cairo_device_set_user_data (cairo_device, - (cairo_user_data_key_t *) cleanup, - state, - cleanup)) - { - warnx ("Failed to setup cleanup callback closure\n"); - cleanup (state); - return NULL; - } - - cairo_device_destroy (cairo_device); - */ - return device; } + +void +destroy_skia_glx(void) +{ + cleanup_state_glx(state); +} diff --git a/src/skia-image.cpp b/src/skia-image.cpp index d2fbf33..da0dbc9 100644 --- a/src/skia-image.cpp +++ b/src/skia-image.cpp @@ -2,6 +2,10 @@ #include <stdlib.h> #include <SkBitmapDevice.h> +#include "image.h" + +static image_state_t *state; + SkBaseDevice * create_skia_device_image (int width, int height) { @@ -11,3 +15,9 @@ create_skia_device_image (int width, int height) skia_bitmap.allocPixels(); return new SkBitmapDevice (skia_bitmap); } + +void +destroy_skia_image(void) +{ + cleanup_state_image(state); +} |