From f22caf9aee2aa64313468b04efa615e2e1c7f8b3 Mon Sep 17 00:00:00 2001 From: Yonit Halperin Date: Sun, 18 Sep 2011 14:52:04 +0300 Subject: client: rewrite surfaces cache use std::map instead of a specific template (CHash). There is no need for special template. Moreover, using std::map will allow easy iteration over the surfaces. (cherry picked from commit fcb3b4ce5231218bcf949da4270bd85a2cfb3535 branch 0.8) Conflicts: client/display_channel.cpp --- client/canvas.h | 152 ++++++-------------------------------------------------- 1 file changed, 14 insertions(+), 138 deletions(-) (limited to 'client/canvas.h') diff --git a/client/canvas.h b/client/canvas.h index 0b8f2b65..a9cdecd9 100644 --- a/client/canvas.h +++ b/client/canvas.h @@ -30,6 +30,7 @@ #include "glz_decoder.h" #include "jpeg_decoder.h" #include "zlib_decoder.h" +#include enum CanvasType { CANVAS_TYPE_INVALID, @@ -38,102 +39,6 @@ enum CanvasType { CANVAS_TYPE_GDI, }; -template -class CHash : public Base { -public: - CHash() - { - memset(_hash, 0, sizeof(_hash)); - } - - ~CHash() - { - } - - void add(uint32_t id, T* data) - { - Item** item = &_hash[key(id)]; - - while (*item) { - PANIC_ON((*item)->id == id); - item = &(*item)->next; - } - *item = new Item(id, data); - } - - bool is_present(uint32_t id) - { - Item* item = _hash[key(id)]; - - for (;;) { - if (!item) { - return false; - } - - if (item->id != id) { - item = item->next; - continue; - } - - return true; - } - } - - T* get(uint32_t id) - { - Item* item = _hash[key(id)]; - - for (;;) { - PANIC_ON(!item); - - if (item->id != id) { - item = item->next; - continue; - } - - return item->data; - } - } - - void remove(uint32_t id) - { - Item** item = &_hash[key(id)]; - - while (*item) { - if ((*item)->id == id) { - Item *rm_item = *item; - *item = rm_item->next; - delete rm_item; - return; - } - item = &(*item)->next; - } - THROW("id %lu, not found", id); - } - -private: - inline uint32_t key(uint32_t id) {return id % HASH_SIZE;} - -private: - class Item { - public: - Item(uint32_t in_id, T* data) - : id (in_id) - , next (NULL) - , data (data) {} - - ~Item() - { - } - - uint64_t id; - Item* next; - T* data; - }; - - Item* _hash[HASH_SIZE]; -}; - class PixmapCacheTreat { public: static inline pixman_image_t *get(pixman_image_t *surf) @@ -200,44 +105,6 @@ public: } }; -class SpiceImageSurfacesBase; - -typedef CHash CSurfaces; - -class SpiceImageSurfacesBase { -public: - SpiceImageSurfaces base; - - static void op_put(SpiceImageSurfaces *c, uint32_t surface_id, SpiceCanvas *surface) - { - CSurfaces* cache = reinterpret_cast(c); - cache->add(surface_id, surface); - } - - static SpiceCanvas* op_get(SpiceImageSurfaces *s, uint32_t surface_id) - { - CSurfaces* cache = reinterpret_cast(s); - return cache->get(surface_id); - } - - static void op_del(SpiceImageSurfaces *c, uint32_t surface_id) - { - CSurfaces* cache = reinterpret_cast(c); - cache->remove(surface_id); - } - - SpiceImageSurfacesBase() - { - static SpiceImageSurfacesOps cache_ops = { - op_get - }; - base.ops = &cache_ops; - } -}; - -class Canvas; - -typedef CHash CCanvases; class CachedPalette { public: @@ -399,10 +266,20 @@ public: } }; +class Canvas; + +typedef std::map SurfacesCanvasesMap; + +class SurfacesCache: public SpiceImageSurfaces, public SurfacesCanvasesMap { +public: + SurfacesCache(); + bool exist(uint32_t surface_id); +}; + class Canvas { public: Canvas(PixmapCache& bits_cache, PaletteCache& palette_cache, - GlzDecoderWindow &glz_decoder_window, CSurfaces& csurfaces); + GlzDecoderWindow &glz_decoder_window, SurfacesCache& csurfaces); virtual ~Canvas(); virtual void copy_pixels(const QRegion& region, RedDrawable* dc, @@ -442,7 +319,7 @@ protected: PixmapCache& pixmap_cache() { return _pixmap_cache;} PaletteCache& palette_cache() { return _palette_cache;} - CSurfaces& csurfaces() { return _csurfaces; } + SurfacesCache& surfaces_cache() { return _surfaces_cache;} GlzDecoder& glz_decoder() {return _glz_decoder;} JpegDecoder& jpeg_decoder() { return _jpeg_decoder;} @@ -453,7 +330,6 @@ private: protected: SpiceCanvas* _canvas; - CSurfaces _surfaces; private: PixmapCache& _pixmap_cache; @@ -466,7 +342,7 @@ private: JpegDecoder _jpeg_decoder; ZlibDecoder _zlib_decoder; - CSurfaces& _csurfaces; + SurfacesCache& _surfaces_cache; unsigned long _base; unsigned long _max; -- cgit