[Spice-devel] [PATCH 1/8] Make canvas Glz decoder integration nicer

alexl at redhat.com alexl at redhat.com
Mon Mar 8 09:33:52 PST 2010


From: Alexander Larsson <alexl at redhat.com>

We use a dynamic interface similar to e.g. SpiceImageCache instead
of passing both function and opaque
---
 client/canvas.cpp           |    7 -------
 client/canvas.h             |    1 -
 client/glz_decoder.cpp      |   14 ++++++++++++++
 client/glz_decoder.h        |    6 ++++--
 client/red_cairo_canvas.cpp |    3 +--
 client/red_gdi_canvas.cpp   |    3 +--
 client/red_gl_canvas.cpp    |    3 +--
 common/cairo_canvas.c       |    5 ++---
 common/cairo_canvas.h       |    2 +-
 common/canvas_base.c        |   13 ++++++-------
 common/canvas_base.h        |   14 ++++++++++++--
 common/gdi_canvas.c         |    5 ++---
 common/gdi_canvas.h         |    3 +--
 common/gl_canvas.c          |    5 ++---
 common/gl_canvas.h          |    2 +-
 15 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/client/canvas.cpp b/client/canvas.cpp
index 24ebd01..516a874 100644
--- a/client/canvas.cpp
+++ b/client/canvas.cpp
@@ -212,10 +212,3 @@ void Canvas::draw_stroke(SpiceMsgDisplayDrawStroke& stroke, int size)
     localalize_attr(stroke.data.attr);
     draw_stroke(&stroke.base.box, &stroke.base.clip, &stroke.data);
 }
-
-void Canvas::glz_decode(void *opaque, uint8_t *data, SpicePalette *plt, void *usr_data)
-{
-    GlzDecoder* decoder = static_cast<GlzDecoder*>(opaque);
-    decoder->decode(data, plt, usr_data);
-}
-
diff --git a/client/canvas.h b/client/canvas.h
index 79400cc..2f12263 100644
--- a/client/canvas.h
+++ b/client/canvas.h
@@ -295,7 +295,6 @@ protected:
     PaletteCache& palette_cache() { return _palette_cache;}
 
     GlzDecoder& glz_decoder() {return _glz_decoder;}
-    static void glz_decode(void *opaque, uint8_t *data, SpicePalette *plt, void *usr_data);
 
 private:
     void access_test(void* ptr, size_t size);
diff --git a/client/glz_decoder.cpp b/client/glz_decoder.cpp
index 0453aaa..30eecc1 100644
--- a/client/glz_decoder.cpp
+++ b/client/glz_decoder.cpp
@@ -1,3 +1,4 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 /*
    Copyright (C) 2009 Red Hat, Inc.
 
@@ -19,12 +20,25 @@
 #include "glz_decoder_config.h"
 #include "glz_decoder.h"
 
+static void op_decode (SpiceGlzDecoder *decoder,
+                       uint8_t *data,
+                       SpicePalette *plt,
+                       void *usr_data)
+{
+    GlzDecoder* _decoder = static_cast<GlzDecoder*>(decoder);
+    _decoder->decode(data, plt, usr_data);
+}
+
 GlzDecoder::GlzDecoder(GlzDecoderWindow &images_window,
                        GlzDecodeHandler &usr_handler, GlzDecoderDebug &debug_calls)
     : _images_window (images_window)
     , _usr_handler (usr_handler)
     , _debug_calls (debug_calls)
 {
+    static SpiceGlzDecoderOps decoder_ops = {
+        op_decode,
+    };
+    ops = &decoder_ops;
 }
 
 GlzDecoder::~GlzDecoder()
diff --git a/client/glz_decoder.h b/client/glz_decoder.h
index c2afa54..2b797d8 100644
--- a/client/glz_decoder.h
+++ b/client/glz_decoder.h
@@ -1,3 +1,4 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 /*
    Copyright (C) 2009 Red Hat, Inc.
 
@@ -21,6 +22,7 @@
 #include "lz_common.h"
 #include "glz_decoder_config.h"
 #include "glz_decoder_window.h"
+#include "canvas_base.h"
 #include <spice/draw.h>
 
 
@@ -47,9 +49,9 @@ public:
     This class implements the lz decoding algorithm
 */
 
-class GlzDecoder {
+class GlzDecoder : public SpiceGlzDecoder
+{
 public:
-
     GlzDecoder(GlzDecoderWindow &images_window, GlzDecodeHandler &usr_handler,
                GlzDecoderDebug &debug_calls);
     virtual ~GlzDecoder();
diff --git a/client/red_cairo_canvas.cpp b/client/red_cairo_canvas.cpp
index 87023e1..97277fb 100644
--- a/client/red_cairo_canvas.cpp
+++ b/client/red_cairo_canvas.cpp
@@ -102,8 +102,7 @@ void CCanvas::set_mode(int width, int height, int depth, RedWindow *win)
     if (!(_canvas = canvas_create(surface, depth,
                                   &pixmap_cache().base,
                                   &palette_cache().base,
-                                  &glz_decoder(),
-                                  glz_decode))) {
+                                  &glz_decoder()))) {
         THROW("create canvas failed");
     }
     pixman_image_unref (surface);
diff --git a/client/red_gdi_canvas.cpp b/client/red_gdi_canvas.cpp
index 671fe82..efdf5d4 100644
--- a/client/red_gdi_canvas.cpp
+++ b/client/red_gdi_canvas.cpp
@@ -92,8 +92,7 @@ void GDICanvas::set_mode(int width, int height, int depth)
                                       &_pixmap->get_mutex(),
                                       depth, &pixmap_cache().base,
                                       &palette_cache().base,
-                                      &glz_decoder(),
-                                      glz_decode))) {
+                                      &glz_decoder()))) {
         THROW("create canvas failed");
     }
 }
diff --git a/client/red_gl_canvas.cpp b/client/red_gl_canvas.cpp
index 6598425..76dabc7 100644
--- a/client/red_gl_canvas.cpp
+++ b/client/red_gl_canvas.cpp
@@ -99,8 +99,7 @@ void GCanvas::set_mode(int width, int height, int depth, RedWindow *win,
     if (!(_canvas = gl_canvas_create(NULL, width, height, depth,
                                      &pixmap_cache().base,
                                      &palette_cache().base,
-                                     &glz_decoder(),
-                                     glz_decode))) {
+                                     &glz_decoder()))) {
         THROW("create canvas failed");
     }
 }
diff --git a/common/cairo_canvas.c b/common/cairo_canvas.c
index addb3d4..ed815d1 100644
--- a/common/cairo_canvas.c
+++ b/common/cairo_canvas.c
@@ -2156,7 +2156,7 @@ CairoCanvas *canvas_create(pixman_image_t *image, int bits,
 CairoCanvas *canvas_create(pixman_image_t *image, int bits
 #endif
 #ifdef USE_GLZ
-                            , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                            , SpiceGlzDecoder *glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                            , void *get_virt_opaque, get_virt_fn_t get_virt,
@@ -2183,8 +2183,7 @@ CairoCanvas *canvas_create(pixman_image_t *image, int bits
 #endif
 #ifdef USE_GLZ
                                ,
-                               glz_decoder_opaque,
-                               glz_decode
+                               glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                                ,
diff --git a/common/cairo_canvas.h b/common/cairo_canvas.h
index 205c62c..390c61c 100644
--- a/common/cairo_canvas.h
+++ b/common/cairo_canvas.h
@@ -70,7 +70,7 @@ CairoCanvas *canvas_create(pixman_image_t *image, int bits,
 CairoCanvas *canvas_create(pixman_image_t *image, int bits
 #endif
 #ifdef USE_GLZ
-                           , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                           , SpiceGlzDecoder *glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                            , void *get_virt_opaque, get_virt_fn_t get_virt,
diff --git a/common/canvas_base.c b/common/canvas_base.c
index 23039eb..8bac592 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -154,8 +154,7 @@ typedef struct LzData {
 } LzData;
 
 typedef struct GlzData {
-    void                  *decoder_opaque;
-    glz_decode_fn_t decode;
+    SpiceGlzDecoder *decoder;
     LzDecodeUsrData decode_data;
 } GlzData;
 
@@ -623,8 +622,9 @@ static pixman_image_t *canvas_get_glz(CanvasBase *canvas, LZImage *image)
 #ifdef WIN32
     canvas->glz_data.decode_data.dc = canvas->dc;
 #endif
-    canvas->glz_data.decode(canvas->glz_data.decoder_opaque, image->lz_rgb.data, NULL,
-                            &canvas->glz_data.decode_data);
+    canvas->glz_data.decoder->ops->decode(canvas->glz_data.decoder,
+                                          image->lz_rgb.data, NULL,
+                                          &canvas->glz_data.decode_data);
     /* global_decode calls alloc_lz_image, which sets canvas->glz_data.surface */
     return (canvas->glz_data.decode_data.out_surface);
 }
@@ -1547,7 +1547,7 @@ static int canvas_base_init(CanvasBase *canvas, int depth,
 static int canvas_base_init(CanvasBase *canvas, int depth
 #endif
 #ifdef USE_GLZ
-                            , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                            , SpiceGlzDecoder *glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                            , void *get_virt_opaque, get_virt_fn_t get_virt,
@@ -1584,8 +1584,7 @@ static int canvas_base_init(CanvasBase *canvas, int depth
     }
 #endif
 #ifdef USE_GLZ
-    canvas->glz_data.decoder_opaque = glz_decoder_opaque;
-    canvas->glz_data.decode = glz_decode;
+    canvas->glz_data.decoder = glz_decoder;
 #endif
 
     if (depth == 16) {
diff --git a/common/canvas_base.h b/common/canvas_base.h
index 78ece62..7796245 100644
--- a/common/canvas_base.h
+++ b/common/canvas_base.h
@@ -26,6 +26,7 @@
 
 typedef struct _SpiceImageCache SpiceImageCache;
 typedef struct _SpicePaletteCache SpicePaletteCache;
+typedef struct _SpiceGlzDecoder SpiceGlzDecoder;
 
 typedef struct {
     void (*put)(SpiceImageCache *cache,
@@ -52,8 +53,17 @@ struct _SpicePaletteCache {
   SpicePaletteCacheOps *ops;
 };
 
-typedef void (*glz_decode_fn_t)(void *glz_decoder_opaque, uint8_t *data,
-                                SpicePalette *plt, void *usr_data);
+typedef struct {
+    void (*decode)(SpiceGlzDecoder *decoder,
+                   uint8_t *data,
+                   SpicePalette *plt,
+                   void *usr_data);
+} SpiceGlzDecoderOps;
+
+struct _SpiceGlzDecoder {
+  SpiceGlzDecoderOps *ops;
+};
+
 #ifndef CAIRO_CANVAS_NO_CHUNKS
 typedef void *(*get_virt_fn_t)(void *get_virt_opaque, unsigned long addr, uint32_t add_size);
 typedef void (*validate_virt_fn_t)(void *validate_virt_opaque, unsigned long virt,
diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
index ae477db..c4750a8 100644
--- a/common/gdi_canvas.c
+++ b/common/gdi_canvas.c
@@ -1708,7 +1708,7 @@ GdiCanvas *gdi_canvas_create(HDC dc, int bits,
 GdiCanvas *gdi_canvas_create(HDC dc, int bits
 #endif
 #ifdef USE_GLZ
-                            , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                            , SpiceGlzDecoder *glz_decoder
 #endif
                             )
 {
@@ -1731,8 +1731,7 @@ GdiCanvas *gdi_canvas_create(HDC dc, int bits
 #endif
 #ifdef USE_GLZ
                                ,
-                               glz_decoder_opaque,
-                               glz_decode
+                               glz_decoder
 #endif
                                );
     canvas->dc = dc;
diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h
index d9b8d21..12082d8 100644
--- a/common/gdi_canvas.h
+++ b/common/gdi_canvas.h
@@ -62,8 +62,7 @@ void gdi_canvas_set_access_params(GdiCanvas *canvas, unsigned long base, unsigne
 GdiCanvas *gdi_canvas_create(HDC dc, class Mutex *lock, int bits,
                              SpiceImageCache *bits_cache,
                              SpicePaletteCache *palette_cache,
-                             void *glz_decoder_opaque,
-                             glz_decode_fn_t glz_decode);
+                             SpiceGlzDecoder *glz_decoder);
 
 void gdi_canvas_destroy(GdiCanvas *canvas);
 
diff --git a/common/gl_canvas.c b/common/gl_canvas.c
index 076090e..6b5eda9 100644
--- a/common/gl_canvas.c
+++ b/common/gl_canvas.c
@@ -812,7 +812,7 @@ GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth,
 GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth
 #endif
 #ifdef USE_GLZ
-                           , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                           , SpiceGlzDecoder *glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                            , void *get_virt_opaque, get_virt_fn_t get_virt,
@@ -845,8 +845,7 @@ GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth
 #endif
 #ifdef USE_GLZ
                                ,
-                               glz_decoder_opaque,
-                               glz_decode
+                               glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                                ,
diff --git a/common/gl_canvas.h b/common/gl_canvas.h
index 39b2792..1c57340 100644
--- a/common/gl_canvas.h
+++ b/common/gl_canvas.h
@@ -65,7 +65,7 @@ GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth,
 GLCanvas *gl_canvas_create(void *usr_data, int width, int height, int depth
 #endif
 #ifdef USE_GLZ
-                           , void *glz_decoder_opaque, glz_decode_fn_t glz_decode
+                           , SpiceGlzDecoder *glz_decoder
 #endif
 #ifndef CAIRO_CANVAS_NO_CHUNKS
                            , void *get_virt_opaque, get_virt_fn_t get_virt,
-- 
1.6.6



More information about the Spice-devel mailing list