Add pixman_image_t referencing the cairo_canvas bits

This references the same data as the cairo surface and can be used
for drawing to the surface using direct pixman calls instead.
This commit is contained in:
Alexander Larsson 2010-02-08 12:14:45 +01:00
parent 60a189f250
commit 79d8c5c6a4
2 changed files with 45 additions and 0 deletions

View File

@ -17,16 +17,19 @@
*/
#include "cairo_canvas.h"
#define CANVAS_USE_PIXMAN
#include "canvas_base.c"
#include "rop3.h"
#include "rect.h"
#include "region.h"
#include "pixman_utils.h"
struct CairoCanvas {
CanvasBase base;
cairo_t *cairo;
uint32_t *private_data;
int private_data_size;
pixman_image_t *image;
};
static void canvas_set_path(CairoCanvas *canvas, void *addr)
@ -1581,6 +1584,7 @@ void canvas_destroy(CairoCanvas *canvas)
if (!canvas) {
return;
}
pixman_image_unref(canvas->image);
canvas_base_destroy(&canvas->base);
if (canvas->private_data) {
free(canvas->private_data);
@ -1654,6 +1658,9 @@ CairoCanvas *canvas_create(cairo_t *cairo, int bits
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));
return canvas;
}

View File

@ -26,6 +26,7 @@
#include "quic.h"
#include "lz.h"
#include "canvas_base.h"
#include "pixman_utils.h"
#include "canvas_utils.h"
#include "rect.h"
@ -214,6 +215,43 @@ 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_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)
{