[Spice-devel] [PATCH 5/8] Move canvas_region and group_start/end to canvas_base
alexl at redhat.com
alexl at redhat.com
Mon Mar 8 09:33:56 PST 2010
From: Alexander Larsson <alexl at redhat.com>
---
client/red_gdi_canvas.cpp | 2 +-
common/cairo_canvas.c | 37 +++++--------------------------------
common/canvas_base.c | 41 ++++++++++++++++++++++++++++++++++++++++-
common/gdi_canvas.c | 6 ++++--
common/gdi_canvas.h | 3 ++-
common/gl_canvas.c | 7 ++++++-
6 files changed, 58 insertions(+), 38 deletions(-)
diff --git a/client/red_gdi_canvas.cpp b/client/red_gdi_canvas.cpp
index a623e64..9f38dfb 100644
--- a/client/red_gdi_canvas.cpp
+++ b/client/red_gdi_canvas.cpp
@@ -80,7 +80,7 @@ void GDICanvas::set_mode(int width, int height, int depth)
{
destroy();
create_pixmap(width, height);
- if (!(_canvas = gdi_canvas_create(_pixmap->get_dc(),
+ if (!(_canvas = gdi_canvas_create(width, height, _pixmap->get_dc(),
&_pixmap->get_mutex(),
depth, &pixmap_cache().base,
&palette_cache().base,
diff --git a/common/cairo_canvas.c b/common/cairo_canvas.c
index 426643e..2c5b0d7 100644
--- a/common/cairo_canvas.c
+++ b/common/cairo_canvas.c
@@ -34,7 +34,6 @@ struct CairoCanvas {
uint32_t *private_data;
int private_data_size;
pixman_image_t *image;
- pixman_region32_t canvas_region;
};
typedef enum {
@@ -211,7 +210,7 @@ static void canvas_clip_pixman(CairoCanvas *canvas,
pixman_region32_t *dest_region,
SpiceClip *clip)
{
- pixman_region32_intersect(dest_region, dest_region, &canvas->canvas_region);
+ pixman_region32_intersect(dest_region, dest_region, &canvas->base.canvas_region);
switch (clip->type) {
case SPICE_CLIP_TYPE_NONE:
@@ -2109,29 +2108,6 @@ static void canvas_read_bits(SpiceCanvas *spice_canvas, uint8_t *dest, int dest_
}
}
-static void canvas_group_start(SpiceCanvas *spice_canvas, QRegion *region)
-{
- CairoCanvas *canvas = (CairoCanvas *)spice_canvas;
- pixman_region32_fini(&canvas->canvas_region);
- /* Make sure we always clip to canvas size */
- pixman_region32_init_rect(&canvas->canvas_region,
- 0, 0,
- pixman_image_get_width (canvas->image),
- pixman_image_get_height (canvas->image));
-
- pixman_region32_intersect(&canvas->canvas_region, &canvas->canvas_region, region);
-}
-
-static void canvas_group_end(SpiceCanvas *spice_canvas)
-{
- CairoCanvas *canvas = (CairoCanvas *)spice_canvas;
- pixman_region32_fini(&canvas->canvas_region);
- pixman_region32_init_rect(&canvas->canvas_region,
- 0, 0,
- pixman_image_get_width(canvas->image),
- pixman_image_get_height(canvas->image));
-}
-
static void canvas_clear(SpiceCanvas *spice_canvas)
{
CairoCanvas *canvas = (CairoCanvas *)spice_canvas;
@@ -2187,7 +2163,10 @@ SpiceCanvas *canvas_create(pixman_image_t *image, int bits
return NULL;
}
memset(canvas, 0, sizeof(CairoCanvas));
- init_ok = canvas_base_init(&canvas->base, &cairo_canvas_ops, bits
+ init_ok = canvas_base_init(&canvas->base, &cairo_canvas_ops,
+ pixman_image_get_width (image),
+ pixman_image_get_height (image),
+ bits
#ifdef CAIRO_CANVAS_CACHE
, bits_cache
, palette_cache
@@ -2203,10 +2182,6 @@ SpiceCanvas *canvas_create(pixman_image_t *image, int bits
canvas->private_data_size = 0;
canvas->image = pixman_image_ref(image);
- pixman_region32_init_rect(&canvas->canvas_region,
- 0, 0,
- pixman_image_get_width (canvas->image),
- pixman_image_get_height (canvas->image));
return (SpiceCanvas *)canvas;
}
@@ -2235,8 +2210,6 @@ void cairo_canvas_init() //unsafe global function
cairo_canvas_ops.put_image = canvas_put_image;
cairo_canvas_ops.clear = canvas_clear;
cairo_canvas_ops.read_bits = canvas_read_bits;
- cairo_canvas_ops.group_start = canvas_group_start;
- cairo_canvas_ops.group_end = canvas_group_end;
cairo_canvas_ops.set_access_params = canvas_set_access_params;
cairo_canvas_ops.destroy = canvas_destroy;
diff --git a/common/canvas_base.c b/common/canvas_base.c
index 2a94607..4bf2be7 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -184,6 +184,10 @@ typedef struct CanvasBase {
unsigned long max;
#endif
+ int width;
+ int height;
+ pixman_region32_t canvas_region;
+
#if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE)
SpiceImageCache *bits_cache;
#endif
@@ -1578,6 +1582,31 @@ void *spice_canvas_get_usr_data(SpiceCanvas *spice_canvas)
}
#endif
+static void canvas_base_group_start(SpiceCanvas *spice_canvas, QRegion *region)
+{
+ CanvasBase *canvas = (CanvasBase *)spice_canvas;
+ pixman_region32_fini(&canvas->canvas_region);
+
+ /* Make sure we always clip to canvas size */
+ pixman_region32_init_rect(&canvas->canvas_region,
+ 0, 0,
+ canvas->width,
+ canvas->height);
+
+ pixman_region32_intersect(&canvas->canvas_region, &canvas->canvas_region, region);
+}
+
+static void canvas_base_group_end(SpiceCanvas *spice_canvas)
+{
+ CanvasBase *canvas = (CanvasBase *)spice_canvas;
+ pixman_region32_fini(&canvas->canvas_region);
+ pixman_region32_init_rect(&canvas->canvas_region,
+ 0, 0,
+ canvas->width,
+ canvas->height);
+}
+
+
static void unimplemented_op(SpiceCanvas *canvas)
{
PANIC("unimplemented canvas operation");
@@ -1592,9 +1621,13 @@ inline static void canvas_base_init_ops(SpiceCanvasOps *ops)
for (i = 0; i < sizeof(SpiceCanvasOps) / sizeof(void *); i++) {
ops_cast[i] = (void *) unimplemented_op;
}
+
+ ops->group_start = canvas_base_group_start;
+ ops->group_end = canvas_base_group_end;
}
-static int canvas_base_init(CanvasBase *canvas, SpiceCanvasOps *ops, int depth
+static int canvas_base_init(CanvasBase *canvas, SpiceCanvasOps *ops,
+ int width, int height, int depth
#ifdef CAIRO_CANVAS_CACHE
, SpiceImageCache *bits_cache
, SpicePaletteCache *palette_cache
@@ -1643,6 +1676,12 @@ static int canvas_base_init(CanvasBase *canvas, SpiceCanvasOps *ops, int depth
canvas->color_mask = 0xff;
}
+ canvas->width = width;
+ canvas->height = height;
+ pixman_region32_init_rect(&canvas->canvas_region,
+ 0, 0,
+ canvas->width,
+ canvas->height);
#if defined(CAIRO_CANVAS_CACHE) || defined(CAIRO_CANVAS_IMAGE_CACHE)
canvas->bits_cache = bits_cache;
diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
index 4d5bc9d..54d6094 100644
--- a/common/gdi_canvas.c
+++ b/common/gdi_canvas.c
@@ -1716,7 +1716,8 @@ static void gdi_canvas_destroy(SpiceCanvas *spice_canvas)
static int need_init = 1;
static SpiceCanvasOps gdi_canvas_ops;
-SpiceCanvas *gdi_canvas_create(HDC dc, Mutex* lock, int bits
+SpiceCanvas *gdi_canvas_create(int width, int height,
+ HDC dc, Mutex* lock, int bits
#ifdef CAIRO_CANVAS_CACHE
, SpiceImageCache *bits_cache
, SpicePaletteCache *palette_cache
@@ -1733,7 +1734,8 @@ SpiceCanvas *gdi_canvas_create(HDC dc, Mutex* lock, int bits
return NULL;
}
memset(canvas, 0, sizeof(GdiCanvas));
- init_ok = canvas_base_init(&canvas->base, &gdi_canvas_ops, bits
+ init_ok = canvas_base_init(&canvas->base, &gdi_canvas_ops,
+ width, height, bits
#ifdef CAIRO_CANVAS_CACHE
,bits_cache
,palette_cache
diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h
index b3dc605..8b8f847 100644
--- a/common/gdi_canvas.h
+++ b/common/gdi_canvas.h
@@ -33,7 +33,8 @@ typedef struct {
uint8_t *pixels;
} GdiImage;
-SpiceCanvas *gdi_canvas_create(HDC dc, class Mutex *lock, int bits,
+SpiceCanvas *gdi_canvas_create(int width, int height,
+ HDC dc, class Mutex *lock, int bits,
SpiceImageCache *bits_cache,
SpicePaletteCache *palette_cache,
SpiceGlzDecoder *glz_decoder);
diff --git a/common/gl_canvas.c b/common/gl_canvas.c
index 99f14f5..c3c9388 100644
--- a/common/gl_canvas.c
+++ b/common/gl_canvas.c
@@ -738,6 +738,8 @@ static void gl_canvas_group_start(SpiceCanvas *spice_canvas, QRegion *region)
int num_rect;
pixman_box32_t *rects;
+ canvas_base_group_start(spice_canvas, region);
+
rects = pixman_region32_rectangles(region, &num_rect);
glc_rects = (GLCRect *)malloc(num_rect * sizeof(GLCRect));
@@ -803,6 +805,8 @@ static void gl_canvas_put_image(SpiceCanvas *spice_canvas, const SpiceRect *dest
static void gl_canvas_group_end(SpiceCanvas *spice_canvas)
{
GLCanvas *canvas = (GLCanvas *)spice_canvas;
+
+ canvas_base_group_end(spice_canvas);
glc_clear_mask(canvas->glc, GLC_MASK_B);
}
@@ -842,7 +846,8 @@ SpiceCanvas *gl_canvas_create(int width, int height, int depth
goto error_1;
}
canvas->private_data = NULL;
- init_ok = canvas_base_init(&canvas->base, &gl_canvas_ops, depth
+ init_ok = canvas_base_init(&canvas->base, &gl_canvas_ops,
+ width, height, depth
#ifdef CAIRO_CANVAS_CACHE
, bits_cache
, palette_cache
--
1.6.6
More information about the Spice-devel
mailing list