summaryrefslogtreecommitdiffstats
path: root/client/canvas.h
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2011-09-18 14:52:04 +0300
committerYonit Halperin <yhalperi@redhat.com>2011-11-02 11:30:21 +0200
commitf22caf9aee2aa64313468b04efa615e2e1c7f8b3 (patch)
treef34d73c8f99b8eef51c43378617411fd5def8353 /client/canvas.h
parent76966571748efa32a706d21830349ab2431aa4e6 (diff)
downloadspice-f22caf9aee2aa64313468b04efa615e2e1c7f8b3.tar.gz
spice-f22caf9aee2aa64313468b04efa615e2e1c7f8b3.tar.xz
spice-f22caf9aee2aa64313468b04efa615e2e1c7f8b3.zip
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
Diffstat (limited to 'client/canvas.h')
-rw-r--r--client/canvas.h152
1 files changed, 14 insertions, 138 deletions
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 <map>
enum CanvasType {
CANVAS_TYPE_INVALID,
@@ -38,102 +39,6 @@ enum CanvasType {
CANVAS_TYPE_GDI,
};
-template <class T, int HASH_SIZE, class Base = EmptyBase>
-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<SpiceCanvas, 1024, SpiceImageSurfacesBase> CSurfaces;
-
-class SpiceImageSurfacesBase {
-public:
- SpiceImageSurfaces base;
-
- static void op_put(SpiceImageSurfaces *c, uint32_t surface_id, SpiceCanvas *surface)
- {
- CSurfaces* cache = reinterpret_cast<CSurfaces*>(c);
- cache->add(surface_id, surface);
- }
-
- static SpiceCanvas* op_get(SpiceImageSurfaces *s, uint32_t surface_id)
- {
- CSurfaces* cache = reinterpret_cast<CSurfaces*>(s);
- return cache->get(surface_id);
- }
-
- static void op_del(SpiceImageSurfaces *c, uint32_t surface_id)
- {
- CSurfaces* cache = reinterpret_cast<CSurfaces*>(c);
- cache->remove(surface_id);
- }
-
- SpiceImageSurfacesBase()
- {
- static SpiceImageSurfacesOps cache_ops = {
- op_get
- };
- base.ops = &cache_ops;
- }
-};
-
-class Canvas;
-
-typedef CHash<Canvas, 1024, SpiceImageSurfacesBase> CCanvases;
class CachedPalette {
public:
@@ -399,10 +266,20 @@ public:
}
};
+class Canvas;
+
+typedef std::map<uint32_t, Canvas*> 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;