[Spice-devel] [PATCH 27/30] Remove cairo_t from cairo canvas

Alexander Larsson alexl at redhat.com
Thu Feb 18 12:58:53 PST 2010


---
 client/red_cairo_canvas.cpp |   23 ++++++++---------------
 common/cairo_canvas.c       |   16 ++++------------
 common/cairo_canvas.h       |   10 ++++------
 common/canvas_base.c        |   41 -----------------------------------------
 server/red_worker.c         |   34 ++++++++++++----------------------
 5 files changed, 28 insertions(+), 96 deletions(-)

diff --git a/client/red_cairo_canvas.cpp b/client/red_cairo_canvas.cpp
index c2496ff..87023e1 100644
--- a/client/red_cairo_canvas.cpp
+++ b/client/red_cairo_canvas.cpp
@@ -40,9 +40,7 @@ CCanvas::~CCanvas()
 void CCanvas::destroy()
 {
     if (_canvas) {
-        cairo_t *cairo = canvas_get_cairo(_canvas);
         canvas_destroy(_canvas);
-        cairo_destroy(cairo);
         _canvas = NULL;
     }
     destroy_pixmap();
@@ -90,30 +88,25 @@ void CCanvas::copy_pixels(const QRegion& region, RedDrawable* dest_dc, const Pix
 
 void CCanvas::set_mode(int width, int height, int depth, RedWindow *win)
 {
-    cairo_surface_t *cairo_surface;
-    cairo_t *cairo;
+    pixman_image_t *surface;
 
     destroy();
     create_pixmap(width, height, win);
-    cairo_surface = cairo_image_surface_create_for_data(_pixmap->get_data(), CAIRO_FORMAT_RGB24,
-                                                        width, height, _pixmap->get_stride());
-    if (cairo_surface_status(cairo_surface) != CAIRO_STATUS_SUCCESS) {
-        THROW("create surface failed, %s",
-              cairo_status_to_string(cairo_surface_status(cairo_surface)));
+    surface = pixman_image_create_bits(PIXMAN_x8r8g8b8, width, height,
+                                       (uint32_t *)_pixmap->get_data(),
+                                       _pixmap->get_stride());
+    if (surface == NULL) {
+        THROW("create surface failed, out of memory");
     }
 
-    cairo = cairo_create(cairo_surface);
-    cairo_surface_destroy(cairo_surface);
-    if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
-        THROW("create cairo failed, %s", cairo_status_to_string(cairo_status(cairo)));
-    }
-    if (!(_canvas = canvas_create(cairo, depth,
+    if (!(_canvas = canvas_create(surface, depth,
                                   &pixmap_cache().base,
                                   &palette_cache().base,
                                   &glz_decoder(),
                                   glz_decode))) {
         THROW("create canvas failed");
     }
+    pixman_image_unref (surface);
 }
 
 void CCanvas::set_access_params(unsigned long base, unsigned long max)
diff --git a/common/cairo_canvas.c b/common/cairo_canvas.c
index 46956aa..a6c82ee 100644
--- a/common/cairo_canvas.c
+++ b/common/cairo_canvas.c
@@ -30,7 +30,6 @@
 
 struct CairoCanvas {
     CanvasBase base;
-    cairo_t *cairo;
     uint32_t *private_data;
     int private_data_size;
     pixman_image_t *image;
@@ -1952,11 +1951,6 @@ void canvas_clear(CairoCanvas *canvas)
                             0);
 }
 
-cairo_t *canvas_get_cairo(CairoCanvas *canvas)
-{
-    return canvas->cairo;
-}
-
 #ifdef CAIRO_CANVAS_ACCESS_TEST
 void canvas_set_access_params(CairoCanvas *canvas, unsigned long base, unsigned long max)
 {
@@ -1980,14 +1974,14 @@ void canvas_destroy(CairoCanvas *canvas)
 static int need_init = 1;
 
 #ifdef CAIRO_CANVAS_CACHE
-CairoCanvas *canvas_create(cairo_t *cairo, int bits,
+CairoCanvas *canvas_create(pixman_image_t *image, int bits,
                            SpiceImageCache *bits_cache,
                            SpicePaletteCache *palette_cache
 #elif defined(CAIRO_CANVAS_IMAGE_CACHE)
-CairoCanvas *canvas_create(cairo_t *cairo, int bits,
+CairoCanvas *canvas_create(pixman_image_t *image, int bits,
                            SpiceImageCache *bits_cache
 #else
-CairoCanvas *canvas_create(cairo_t *cairo, 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
@@ -2028,12 +2022,10 @@ CairoCanvas *canvas_create(cairo_t *cairo, int bits
                                validate_virt
 #endif
                                );
-    canvas->cairo = cairo;
     canvas->private_data = NULL;
     canvas->private_data_size = 0;
-    cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
 
-    canvas->image = pixman_image_from_surface (cairo_get_target (cairo));
+    canvas->image = pixman_image_ref (image);
     pixman_region32_init_rect (&canvas->canvas_region,
                                0, 0,
                                pixman_image_get_width (canvas->image),
diff --git a/common/cairo_canvas.h b/common/cairo_canvas.h
index 9bd65ff..115dbb4 100644
--- a/common/cairo_canvas.h
+++ b/common/cairo_canvas.h
@@ -22,7 +22,7 @@
 #include <stdint.h>
 
 #include <spice/draw.h>
-#include "cairo.h"
+#include "pixman_utils.h"
 #include "canvas_base.h"
 #include "region.h"
 
@@ -59,17 +59,15 @@ void canvas_set_addr_delta(CairoCanvas *canvas, SPICE_ADDRESS delta);
 void canvas_set_access_params(CairoCanvas *canvas, unsigned long base, unsigned long max);
 #endif
 
-cairo_t *canvas_get_cairo(CairoCanvas *canvas);
-
 #ifdef CAIRO_CANVAS_CACHE
-CairoCanvas *canvas_create(cairo_t *cairo, int bits,
+CairoCanvas *canvas_create(pixman_image_t *image, int bits,
 			   SpiceImageCache *bits_cache,
 			   SpicePaletteCache *palette_cache
 #elif defined(CAIRO_CANVAS_IMAGE_CACHE)
-CairoCanvas *canvas_create(cairo_t *cairo, int bits,
+CairoCanvas *canvas_create(pixman_image_t *image, int bits,
 			   SpiceImageCache *bits_cache
 #else
-CairoCanvas *canvas_create(cairo_t *cairo, 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
diff --git a/common/canvas_base.c b/common/canvas_base.c
index 10e7628..409712e 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -219,47 +219,6 @@ typedef struct ATTR_PACKED DataChunk {
 
 #endif
 
-#ifdef CANVAS_USE_PIXMAN
-
-static pixman_format_code_t
-pixman_format_from_cairo_format (cairo_format_t format)
-{
-    switch (format) {
-    case CAIRO_FORMAT_A1:
-        return PIXMAN_a1;
-    case CAIRO_FORMAT_A8:
-        return PIXMAN_a8;
-    case CAIRO_FORMAT_RGB24:
-        return PIXMAN_x8r8g8b8;
-    case CAIRO_FORMAT_ARGB32:
-    default:
-        return PIXMAN_a8r8g8b8;
-    }
-}
-
-static pixman_image_t *
-pixman_image_from_surface (cairo_surface_t *surface)
-{
-  pixman_image_t *image;
-  cairo_format_t format;
-
-  format = cairo_image_surface_get_format (surface);
-
-  image = (pixman_image_t *)cairo_surface_get_user_data(surface, &pixman_data_type);
-
-  if (image)
-      return pixman_image_ref (image);
-
-  image = pixman_image_create_bits (pixman_format_from_cairo_format (format),
-                                    cairo_image_surface_get_width (surface),
-                                    cairo_image_surface_get_height (surface),
-                                    (uint32_t *)cairo_image_surface_get_data (surface),
-                                    cairo_image_surface_get_stride (surface));
-
-  return image;
-}
-#endif
-
 static inline void canvas_localize_palette(CanvasBase *canvas, SpicePalette *palette)
 {
     if (canvas->color_shift == 5) {
diff --git a/server/red_worker.c b/server/red_worker.c
index e875bd2..460efd1 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -35,7 +35,6 @@
 #include "region.h"
 #include <spice/protocol.h>
 #include "red_worker.h"
-#include "cairo.h"
 #include "cairo_canvas.h"
 #include "gl_canvas.h"
 #include "ogl_ctx.h"
@@ -7448,15 +7447,11 @@ static void red_migrate_display(RedWorker *worker)
 
 static void destroy_cairo_canvas(CairoCanvas *canvas)
 {
-    cairo_t *cairo;
-
     if (!canvas) {
         return;
     }
 
-    cairo = canvas_get_cairo(canvas);
     canvas_destroy(canvas);
-    cairo_destroy(cairo);
 }
 
 static void validate_area_nop(void *canvas, int32_t stride, uint8_t *line_0, const SpiceRect *area)
@@ -7489,25 +7484,20 @@ static void init_cairo_draw_funcs(RedWorker *worker)
 static CairoCanvas *create_cairo_context(RedWorker *worker, uint32_t width, uint32_t height,
                                          int32_t stride, uint8_t depth, void *line_0)
 {
-    cairo_surface_t *cairo_surface;
-    cairo_t *cairo;
+    CairoCanvas *canvas;
+    pixman_image_t *surface;
 
-    cairo_surface = cairo_image_surface_create_for_data(line_0,  CAIRO_FORMAT_RGB24, width, height,
-                                                        stride);
-    if (cairo_surface_status(cairo_surface) != CAIRO_STATUS_SUCCESS) {
-        red_error("create cairo surface failed, %s",
-                  cairo_status_to_string(cairo_surface_status(cairo_surface)));
-    }
-    cairo = cairo_create(cairo_surface);
-    cairo_surface_destroy(cairo_surface);
-    if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
-        red_error("create cairo failed, %s",
-                  cairo_status_to_string(cairo_status(cairo)));
+    surface = pixman_image_create_bits(PIXMAN_x8r8g8b8, width, height,
+                                       (uint32_t *)line_0,
+                                       stride);
+    if (surface == NULL) {
+        red_error("create cairo surface failed");
     }
-
-    return canvas_create(cairo, depth, &worker->image_cache.base,
-                         worker, cb_get_virt_preload_group, worker,
-                         cb_validate_virt_preload_group);
+    canvas = canvas_create(surface, depth, &worker->image_cache.base,
+                           worker, cb_get_virt_preload_group, worker,
+                           cb_validate_virt_preload_group);
+    pixman_image_unref (surface);
+    return canvas;
 }
 
 static void destroy_gl_canvas(GLCanvas *canvas)
-- 
1.6.6



More information about the Spice-devel mailing list