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.cpp | 30 ------------------ client/canvas.h | 74 ++++++++++++++++++++++++++++++++++++++++----- client/red_cairo_canvas.cpp | 5 ++- client/red_gdi_canvas.cpp | 6 ++-- client/red_gl_canvas.cpp | 9 ++---- 5 files changed, 73 insertions(+), 51 deletions(-) (limited to 'client') diff --git a/client/canvas.cpp b/client/canvas.cpp index 04b0ce67..24ebd01b 100644 --- a/client/canvas.cpp +++ b/client/canvas.cpp @@ -213,36 +213,6 @@ void Canvas::draw_stroke(SpiceMsgDisplayDrawStroke& stroke, int size) draw_stroke(&stroke.base.box, &stroke.base.clip, &stroke.data); } -void Canvas::bits_cache_put(void *opaque, uint64_t id, cairo_surface_t *surface) -{ - PixmapCache* cache = static_cast(opaque); - cache->add(id, surface); -} - -cairo_surface_t* Canvas::bits_cache_get(void *opaque, uint64_t id) -{ - PixmapCache* cache = static_cast(opaque); - return cache->get(id); -} - -void Canvas::palette_cache_put(void *opaque, SpicePalette *palette) -{ - PaletteCache* cache = static_cast(opaque); - AutoRef cached_palette(new CachedPalette(palette)); - cache->add(palette->unique, *cached_palette); -} - -SpicePalette* Canvas::palette_cache_get(void *opaque, uint64_t id) -{ - PaletteCache* cache = static_cast(opaque); - return cache->get(id)->palette(); -} - -void Canvas::palette_cache_release(SpicePalette* palette) -{ - CachedPalette::unref(palette); -} - void Canvas::glz_decode(void *opaque, uint8_t *data, SpicePalette *plt, void *usr_data) { GlzDecoder* decoder = static_cast(opaque); 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); diff --git a/client/red_cairo_canvas.cpp b/client/red_cairo_canvas.cpp index 08880ea9..80a89b75 100644 --- a/client/red_cairo_canvas.cpp +++ b/client/red_cairo_canvas.cpp @@ -99,9 +99,8 @@ void CCanvas::set_mode(int width, int height, int depth, RedWindow *win) THROW("create cairo failed, %s", cairo_status_to_string(cairo_status(cairo))); } if (!(_canvas = canvas_create(cairo, depth, - &pixmap_cache(), bits_cache_put, bits_cache_get, - &palette_cache(), palette_cache_put, palette_cache_get, - palette_cache_release, + &pixmap_cache().base, + &palette_cache().base, &glz_decoder(), glz_decode))) { THROW("create canvas failed"); diff --git a/client/red_gdi_canvas.cpp b/client/red_gdi_canvas.cpp index 8e50a066..e30845e8 100644 --- a/client/red_gdi_canvas.cpp +++ b/client/red_gdi_canvas.cpp @@ -81,10 +81,8 @@ void GDICanvas::set_mode(int width, int height, int depth) create_pixmap(width, height); if (!(_canvas = gdi_canvas_create(_pixmap->get_dc(), &_pixmap->get_mutex(), - depth, &pixmap_cache(), bits_cache_put, - bits_cache_get, &palette_cache(), - palette_cache_put, palette_cache_get, - palette_cache_release, + depth, &pixmap_cache().base, + &palette_cache().base, &glz_decoder(), glz_decode))) { THROW("create canvas failed"); diff --git a/client/red_gl_canvas.cpp b/client/red_gl_canvas.cpp index 830de035..43bf4249 100644 --- a/client/red_gl_canvas.cpp +++ b/client/red_gl_canvas.cpp @@ -87,13 +87,8 @@ void GCanvas::set_mode(int width, int height, int depth, RedWindow *win, create_pixmap(width, height, win, rendertype); if (!(_canvas = gl_canvas_create(NULL, width, height, depth, - &pixmap_cache(), - bits_cache_put, - bits_cache_get, - &palette_cache(), - palette_cache_put, - palette_cache_get, - palette_cache_release, + &pixmap_cache().base, + &palette_cache().base, &glz_decoder(), glz_decode))) { THROW("create canvas failed"); -- cgit