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 /client | |
parent | 7537acd630e8973c92bb769b56d78836372b30c2 (diff) | |
download | spice-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')
-rw-r--r-- | client/canvas.cpp | 30 | ||||
-rw-r--r-- | client/canvas.h | 74 | ||||
-rw-r--r-- | client/red_cairo_canvas.cpp | 5 | ||||
-rw-r--r-- | client/red_gdi_canvas.cpp | 6 | ||||
-rw-r--r-- | client/red_gl_canvas.cpp | 9 |
5 files changed, 73 insertions, 51 deletions
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<PixmapCache*>(opaque); - cache->add(id, surface); -} - -cairo_surface_t* Canvas::bits_cache_get(void *opaque, uint64_t id) -{ - PixmapCache* cache = static_cast<PixmapCache*>(opaque); - return cache->get(id); -} - -void Canvas::palette_cache_put(void *opaque, SpicePalette *palette) -{ - PaletteCache* cache = static_cast<PaletteCache*>(opaque); - AutoRef<CachedPalette> 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<PaletteCache*>(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<GlzDecoder*>(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 <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); 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"); |