summaryrefslogtreecommitdiffstats
path: root/client/canvas.h
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-02-08 15:38:24 +0100
committerAlexander Larsson <alexl@redhat.com>2010-02-23 14:43:20 +0100
commit0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3 (patch)
tree7e4ce72080519d7d55df6f3dadc63b6784c0856b /client/canvas.h
parent7537acd630e8973c92bb769b56d78836372b30c2 (diff)
downloadspice-0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3.tar.gz
spice-0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3.tar.xz
spice-0b0342ee7ece8ea5a811cfb05c70f03ca4e3bde3.zip
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 'client/canvas.h')
-rw-r--r--client/canvas.h74
1 files changed, 67 insertions, 7 deletions
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 <spice/protocol.h>
#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<cairo_surface_t, PixmapCacheTreat, 1024> PixmapCache;
+class SpiceImageCacheBase;
+
+typedef SharedCache<cairo_surface_t, PixmapCacheTreat, 1024, SpiceImageCacheBase> PixmapCache;
+
+class SpiceImageCacheBase {
+public:
+ SpiceImageCache base;
+
+ static void op_put(SpiceImageCache *c, uint64_t id, cairo_surface_t *surface)
+ {
+ PixmapCache* cache = reinterpret_cast<PixmapCache*>(c);
+ cache->add(id, surface);
+ }
+
+ static cairo_surface_t* op_get(SpiceImageCache *c, uint64_t id)
+ {
+ PixmapCache* cache = reinterpret_cast<PixmapCache*>(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<CachedPalette, PaletteCacheTreat, 1024> PaletteCache;
+class SpicePaletteCacheBase;
+typedef Cache<CachedPalette, PaletteCacheTreat, 1024, SpicePaletteCacheBase> PaletteCache;
+
+class SpicePaletteCacheBase {
+public:
+ SpicePaletteCache base;
+
+ static void op_put(SpicePaletteCache *c, SpicePalette *palette)
+ {
+ PaletteCache* cache = reinterpret_cast<PaletteCache*>(c);
+ AutoRef<CachedPalette> cached_palette(new CachedPalette(palette));
+ cache->add(palette->unique, *cached_palette);
+ }
+
+ static SpicePalette* op_get(SpicePaletteCache *c, uint64_t id)
+ {
+ PaletteCache* cache = reinterpret_cast<PaletteCache*>(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);