diff options
author | Alexander Larsson <alexl@redhat.com> | 2010-02-08 15:38:24 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2010-02-23 14:43:20 +0100 |
commit | 0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3 (patch) | |
tree | 7e4ce72080519d7d55df6f3dadc63b6784c0856b /common | |
parent | 7537acd630e8973c92bb769b56d78836372b30c2 (diff) |
Turn image and palette cache into c style dynamic interface
Instead of passing a bunch of function pointer and an opaque
pointer we make a real type and add a vtable pointer to it.
This means we can simplify all the canvas constructors, etc.
Diffstat (limited to 'common')
-rw-r--r-- | common/cairo_canvas.c | 27 | ||||
-rw-r--r-- | common/cairo_canvas.h | 12 | ||||
-rw-r--r-- | common/canvas_base.c | 45 | ||||
-rw-r--r-- | common/canvas_base.h | 36 | ||||
-rw-r--r-- | common/gdi_canvas.c | 22 | ||||
-rw-r--r-- | common/gdi_canvas.h | 6 | ||||
-rw-r--r-- | common/gl_canvas.c | 26 | ||||
-rw-r--r-- | common/gl_canvas.h | 13 |
8 files changed, 71 insertions, 116 deletions
diff --git a/common/cairo_canvas.c b/common/cairo_canvas.c index c40693b..4b8c305 100644 --- a/common/cairo_canvas.c +++ b/common/cairo_canvas.c @@ -438,7 +438,7 @@ static cairo_surface_t *canvas_get_invers_image(CairoCanvas *canvas, SPICE_ADDRE } #endif case SPICE_IMAGE_TYPE_FROM_CACHE: - surface = canvas->base.bits_cache_get(canvas->base.bits_cache_opaque, descriptor->id); + surface = canvas->base.bits_cache->ops->get(canvas->base.bits_cache, descriptor->id); break; case SPICE_IMAGE_TYPE_BITMAP: { SpiceBitmapImage *bitmap = (SpiceBitmapImage *)descriptor; @@ -465,7 +465,7 @@ static cairo_surface_t *canvas_get_invers_image(CairoCanvas *canvas, SPICE_ADDRE } if (cache_me) { - canvas->base.bits_cache_put(canvas->base.bits_cache_opaque, descriptor->id, surface); + canvas->base.bits_cache->ops->put(canvas->base.bits_cache, descriptor->id, surface); } invers = canvas_handle_inverse_user_data(surface); @@ -1596,15 +1596,11 @@ static int need_init = 1; #ifdef CAIRO_CANVAS_CACHE CairoCanvas *canvas_create(cairo_t *cairo, int bits, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) CairoCanvas *canvas_create(cairo_t *cairo, int bits, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get + SpiceImageCache *bits_cache #else CairoCanvas *canvas_create(cairo_t *cairo, int bits #endif @@ -1626,18 +1622,11 @@ CairoCanvas *canvas_create(cairo_t *cairo, int bits memset(canvas, 0, sizeof(CairoCanvas)); #ifdef CAIRO_CANVAS_CACHE init_ok = canvas_base_init(&canvas->base, bits, - bits_cache_opaque, - bits_cache_put, - bits_cache_get, - palette_cache_opaque, - palette_cache_put, - palette_cache_get, - palette_cache_release + bits_cache, + palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) init_ok = canvas_base_init(&canvas->base, bits, - bits_cache_opaque, - bits_cache_put, - bits_cache_get + bits_cache #else init_ok = canvas_base_init(&canvas->base, bits #endif diff --git a/common/cairo_canvas.h b/common/cairo_canvas.h index bf6ff90..b0c0820 100644 --- a/common/cairo_canvas.h +++ b/common/cairo_canvas.h @@ -62,14 +62,12 @@ void canvas_set_access_params(CairoCanvas *canvas, unsigned long base, unsigned cairo_t *canvas_get_cairo(CairoCanvas *canvas); #ifdef CAIRO_CANVAS_CACHE -CairoCanvas *canvas_create(cairo_t *cairo, int bits, void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release +CairoCanvas *canvas_create(cairo_t *cairo, int bits, + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) -CairoCanvas *canvas_create(cairo_t *cairo, int bits, void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get +CairoCanvas *canvas_create(cairo_t *cairo, int bits, + SpiceImageCache *bits_cache #else CairoCanvas *canvas_create(cairo_t *cairo, int bits #endif diff --git a/common/canvas_base.c b/common/canvas_base.c index ebb9846..0ddbaf4 100644 --- a/common/canvas_base.c +++ b/common/canvas_base.c @@ -171,15 +171,10 @@ typedef struct CanvasBase { #endif #if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE) - void *bits_cache_opaque; - bits_cache_put_fn_t bits_cache_put; - bits_cache_get_fn_t bits_cache_get; + SpiceImageCache *bits_cache; #endif #ifdef CAIRO_CANVAS_CACHE - void *palette_cache_opaque; - palette_cache_put_fn_t palette_cache_put; - palette_cache_get_fn_t palette_cache_get; - palette_cache_release_fn_t palette_cache_release; + SpicePaletteCache *palette_cache; #endif #ifdef WIN32 HDC dc; @@ -535,13 +530,13 @@ static inline SpicePalette *canvas_get_palett(CanvasBase *canvas, SPICE_ADDRESS } if (flags & SPICE_BITMAP_FLAGS_PAL_FROM_CACHE) { - palette = canvas->palette_cache_get(canvas->palette_cache_opaque, base_palette); + palette = canvas->palette_cache->ops->get(canvas->palette_cache, base_palette); } else if (flags & SPICE_BITMAP_FLAGS_PAL_CACHE_ME) { palette = (SpicePalette *)SPICE_GET_ADDRESS(base_palette); access_test(canvas, palette, sizeof(SpicePalette)); access_test(canvas, palette, sizeof(SpicePalette) + palette->num_ents * sizeof(uint32_t)); canvas_localize_palette(canvas, palette); - canvas->palette_cache_put(canvas->palette_cache_opaque, palette); + canvas->palette_cache->ops->put(canvas->palette_cache, palette); } else { palette = (SpicePalette *)SPICE_GET_ADDRESS(base_palette); canvas_localize_palette(canvas, palette); @@ -716,7 +711,7 @@ static cairo_surface_t *canvas_get_bits(CanvasBase *canvas, SpiceBitmap *bitmap) surface = canvas_bitmap_to_surface(canvas, bitmap, palette); if (palette && (bitmap->flags & SPICE_BITMAP_FLAGS_PAL_FROM_CACHE)) { - canvas->palette_cache_release(palette); + canvas->palette_cache->ops->release(canvas->palette_cache, palette); } return surface; @@ -851,7 +846,7 @@ static cairo_surface_t *canvas_get_image(CanvasBase *canvas, SPICE_ADDRESS addr) } #endif case SPICE_IMAGE_TYPE_FROM_CACHE: - return canvas->bits_cache_get(canvas->bits_cache_opaque, descriptor->id); + return canvas->bits_cache->ops->get(canvas->bits_cache, descriptor->id); case SPICE_IMAGE_TYPE_BITMAP: { SpiceBitmapImage *bitmap = (SpiceBitmapImage *)descriptor; access_test(canvas, descriptor, sizeof(SpiceBitmapImage)); @@ -863,7 +858,7 @@ static cairo_surface_t *canvas_get_image(CanvasBase *canvas, SPICE_ADDRESS addr) } if (descriptor->flags & SPICE_IMAGE_FLAGS_CACHE_ME) { - canvas->bits_cache_put(canvas->bits_cache_opaque, descriptor->id, surface); + canvas->bits_cache->ops->put(canvas->bits_cache, descriptor->id, surface); #ifdef DEBUG_DUMP_SURFACE dump_surface(surface, 1); #endif @@ -1163,7 +1158,7 @@ static cairo_surface_t *canvas_get_mask(CanvasBase *canvas, SpiceQMask *mask) } #if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE) case SPICE_IMAGE_TYPE_FROM_CACHE: - surface = canvas->bits_cache_get(canvas->bits_cache_opaque, descriptor->id); + surface = canvas->bits_cache->ops->get(canvas->bits_cache, descriptor->id); is_invers = 0; break; #endif @@ -1173,7 +1168,7 @@ static cairo_surface_t *canvas_get_mask(CanvasBase *canvas, SpiceQMask *mask) #if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE) if (cache_me) { - canvas->bits_cache_put(canvas->bits_cache_opaque, descriptor->id, surface); + canvas->bits_cache->ops->put(canvas->bits_cache, descriptor->id, surface); } if (need_invers && !is_invers) { // surface is in cache @@ -1570,18 +1565,11 @@ static void canvas_base_destroy(CanvasBase *canvas) #ifdef CAIRO_CANVAS_CACHE static int canvas_base_init(CanvasBase *canvas, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, - palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) static int canvas_base_init(CanvasBase *canvas, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get + SpiceImageCache *bits_cache #else static int canvas_base_init(CanvasBase *canvas, int depth #endif @@ -1637,15 +1625,10 @@ static int canvas_base_init(CanvasBase *canvas, int depth #if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE) - canvas->bits_cache_opaque = bits_cache_opaque; - canvas->bits_cache_put = bits_cache_put; - canvas->bits_cache_get = bits_cache_get; + canvas->bits_cache = bits_cache; #endif #ifdef CAIRO_CANVAS_CACHE - canvas->palette_cache_opaque = palette_cache_opaque; - canvas->palette_cache_put = palette_cache_put; - canvas->palette_cache_get = palette_cache_get; - canvas->palette_cache_release = palette_cache_release; + canvas->palette_cache = palette_cache; #endif #ifdef WIN32 diff --git a/common/canvas_base.h b/common/canvas_base.h index 15cf869..cc75087 100644 --- a/common/canvas_base.h +++ b/common/canvas_base.h @@ -24,15 +24,33 @@ #include "lz.h" #include <spice/draw.h> -#if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE) -typedef void (*bits_cache_put_fn_t)(void *bits_cache_opaque, uint64_t id, cairo_surface_t *surface); -typedef cairo_surface_t *(*bits_cache_get_fn_t)(void *bits_cache_opaque, uint64_t id); -#endif -#ifdef CAIRO_CANVAS_CACHE -typedef void (*palette_cache_put_fn_t)(void *palette_cache_opaque, SpicePalette *palette); -typedef SpicePalette *(*palette_cache_get_fn_t)(void *palette_cache_opaque, uint64_t id); -typedef void (*palette_cache_release_fn_t)(SpicePalette *palette); -#endif +typedef struct _SpiceImageCache SpiceImageCache; +typedef struct _SpicePaletteCache SpicePaletteCache; + +typedef struct { + void (*put)(SpiceImageCache *cache, + uint64_t id, + cairo_surface_t *surface); + cairo_surface_t *(*get)(SpiceImageCache *cache, + uint64_t id); +} SpiceImageCacheOps; + +struct _SpiceImageCache { + SpiceImageCacheOps *ops; +}; + +typedef struct { + void (*put)(SpicePaletteCache *cache, + SpicePalette *palette); + SpicePalette *(*get)(SpicePaletteCache *cache, + uint64_t id); + void (*release)(SpicePaletteCache *cache, + SpicePalette *palette); +} SpicePaletteCacheOps; + +struct _SpicePaletteCache { + SpicePaletteCacheOps *ops; +}; typedef void (*glz_decode_fn_t)(void *glz_decoder_opaque, uint8_t *data, SpicePalette *plt, void *usr_data); diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c index 9e29cb8..bc9f8b2 100644 --- a/common/gdi_canvas.c +++ b/common/gdi_canvas.c @@ -1696,14 +1696,11 @@ static int need_init = 1; #ifdef CAIRO_CANVAS_CACHE GdiCanvas *gdi_canvas_create(HDC dc, Mutex* lock, int bits, void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) GdiCanvas *gdi_canvas_create(HDC dc, int bits, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get + SpiceImageCache *bits_cache #else GdiCanvas *gdi_canvas_create(HDC dc, int bits #endif @@ -1721,18 +1718,11 @@ GdiCanvas *gdi_canvas_create(HDC dc, int bits memset(canvas, 0, sizeof(GdiCanvas)); #ifdef CAIRO_CANVAS_CACHE init_ok = canvas_base_init(&canvas->base, bits, - bits_cache_opaque, - bits_cache_put, - bits_cache_get, - palette_cache_opaque, - palette_cache_put, - palette_cache_get, - palette_cache_release + bits_cache, + palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) init_ok = gdi_canvas_base_init(&canvas->base, bits, - bits_cache_opaque, - bits_cache_put, - bits_cache_get + bits_cache #else init_ok = gdi_canvas_base_init(&canvas->base, bits #endif diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h index 606e71e..18a4843 100644 --- a/common/gdi_canvas.h +++ b/common/gdi_canvas.h @@ -60,10 +60,8 @@ void gdi_canvas_set_access_params(GdiCanvas *canvas, unsigned long base, unsigne GdiCanvas *gdi_canvas_create(HDC dc, class Mutex *lock, int bits, void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release, + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache void *glz_decoder_opaque, glz_decode_fn_t glz_decode); diff --git a/common/gl_canvas.c b/common/gl_canvas.c index 124bcfe..329d97b 100644 --- a/common/gl_canvas.c +++ b/common/gl_canvas.c @@ -787,18 +787,11 @@ static int need_init = 1; #ifdef CAIRO_CANVAS_CACHE GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, - palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get + SpiceImageCache *bits_cache #else GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth #endif @@ -826,18 +819,11 @@ GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth canvas->private_data = NULL; #ifdef CAIRO_CANVAS_CACHE init_ok = canvas_base_init(&canvas->base, depth, - bits_cache_opaque, - bits_cache_put, - bits_cache_get, - palette_cache_opaque, - palette_cache_put, - palette_cache_get, - palette_cache_release + bits_cache, + palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) init_ok = canvas_base_init(&canvas->base, depth, - bits_cache_opaque, - bits_cache_put, - bits_cache_get + bits_cache #else init_ok = canvas_base_init(&canvas->base, depth #endif diff --git a/common/gl_canvas.h b/common/gl_canvas.h index 74c8913..794b1ea 100644 --- a/common/gl_canvas.h +++ b/common/gl_canvas.h @@ -56,18 +56,11 @@ void *gl_canvas_get_usr_data(GLCanvas *canvas); #ifdef CAIRO_CANVAS_CACHE GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get, - void *palette_cache_opaque, - palette_cache_put_fn_t palette_cache_put, - palette_cache_get_fn_t palette_cache_get, - palette_cache_release_fn_t palette_cache_release + SpiceImageCache *bits_cache, + SpicePaletteCache *palette_cache #elif defined(CAIRO_CANVAS_IMAGE_CACHE) GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth, - void *bits_cache_opaque, - bits_cache_put_fn_t bits_cache_put, - bits_cache_get_fn_t bits_cache_get + SpiceImageCache *bits_cache #else GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth #endif |