From 0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 8 Feb 2010 15:38:24 +0100 Subject: 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. --- client/canvas.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 7 deletions(-) (limited to 'client/canvas.h') diff --git a/client/canvas.h b/client/canvas.h index 84a654a8..3074d0d1 100644 --- a/client/canvas.h +++ b/client/canvas.h @@ -24,6 +24,7 @@ #include #include "cache.hpp" #include "shared_cache.hpp" +#include "canvas_base.h" #include "canvas_utils.h" #include "glz_decoded_image.h" #include "glz_decoder.h" @@ -52,7 +53,35 @@ public: static const char* name() { return "pixmap";} }; -typedef SharedCache PixmapCache; +class SpiceImageCacheBase; + +typedef SharedCache PixmapCache; + +class SpiceImageCacheBase { +public: + SpiceImageCache base; + + static void op_put(SpiceImageCache *c, uint64_t id, cairo_surface_t *surface) + { + PixmapCache* cache = reinterpret_cast(c); + cache->add(id, surface); + } + + static cairo_surface_t* op_get(SpiceImageCache *c, uint64_t id) + { + PixmapCache* cache = reinterpret_cast(c); + return cache->get(id); + } + + SpiceImageCacheBase() + { + static SpiceImageCacheOps cache_ops = { + op_put, + op_get + }; + base.ops = &cache_ops; + } +}; class CachedPalette { public: @@ -113,7 +142,43 @@ public: static const char* name() { return "palette";} }; -typedef Cache PaletteCache; +class SpicePaletteCacheBase; +typedef Cache PaletteCache; + +class SpicePaletteCacheBase { +public: + SpicePaletteCache base; + + static void op_put(SpicePaletteCache *c, SpicePalette *palette) + { + PaletteCache* cache = reinterpret_cast(c); + AutoRef cached_palette(new CachedPalette(palette)); + cache->add(palette->unique, *cached_palette); + } + + static SpicePalette* op_get(SpicePaletteCache *c, uint64_t id) + { + PaletteCache* cache = reinterpret_cast(c); + return cache->get(id)->palette(); + } + + static void op_release (SpicePaletteCache *c, + SpicePalette *palette) + { + CachedPalette::unref(palette); + } + + SpicePaletteCacheBase() + { + static SpicePaletteCacheOps cache_ops = { + op_put, + op_get, + op_release + }; + base.ops = &cache_ops; + } +}; + /* Lz decoder related classes */ @@ -230,11 +295,6 @@ protected: PixmapCache& pixmap_cache() { return _pixmap_cache;} PaletteCache& palette_cache() { return _palette_cache;} - static void bits_cache_put(void *opaque, uint64_t id, cairo_surface_t *surface); - static cairo_surface_t* bits_cache_get(void *opaque, uint64_t id); - static void palette_cache_put(void *opaque, SpicePalette *palette); - static SpicePalette* palette_cache_get(void *opaque, uint64_t id); - static void palette_cache_release(SpicePalette* palette); GlzDecoder& glz_decoder() {return _glz_decoder;} static void glz_decode(void *opaque, uint8_t *data, SpicePalette *plt, void *usr_data); -- cgit