[sapwood] change the GdkBitmap to a cairo_surface_t
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] change the GdkBitmap to a cairo_surface_t
- Date: Fri, 13 Aug 2010 11:41:22 +0000 (UTC)
commit 68fb551d7fb0c0ce4ea43f1976634e13378ca71d
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Aug 13 13:14:32 2010 +0200
change the GdkBitmap to a cairo_surface_t
* engine/sapwood-pixmap-priv.h,
* engine/sapwood-pixmap.c,
* engine/sapwood-pixmap.h: change the GdkBitmap for the mask into a
cairo_surface_t (to slowly bug gradually reduce the dependency on GDK)
* engine/theme-pixbuf.c,
* tests/test-sapwood-pixmap.c: updated calls to the new API
* sapwood/sapwood-cairo.c,
* sapwood/sapwood-cairo.h: add a function which creates a
cairo_surface_t from a GdkDrawable (which takes over the ownership
of the drawable)
engine/sapwood-pixmap-priv.h | 5 ++-
engine/sapwood-pixmap.c | 47 ++++++++++++++++++++++-------------------
engine/sapwood-pixmap.h | 19 +++++++++--------
engine/theme-pixbuf.c | 6 ++--
sapwood/sapwood-cairo.c | 17 +++++++++++---
sapwood/sapwood-cairo.h | 3 +-
tests/test-sapwood-pixmap.c | 8 +++---
7 files changed, 60 insertions(+), 45 deletions(-)
---
diff --git a/engine/sapwood-pixmap-priv.h b/engine/sapwood-pixmap-priv.h
index 7f04678..4a2d5bb 100644
--- a/engine/sapwood-pixmap-priv.h
+++ b/engine/sapwood-pixmap-priv.h
@@ -26,12 +26,13 @@
#include "sapwood-pixmap.h"
-struct _SapwoodPixmap {
+struct _SapwoodPixmap
+{
guint32 id;
gint width;
gint height;
GdkPixmap *pixmap[3][3];
- GdkBitmap *pixmask[3][3];
+ cairo_surface_t* masks[3][3];
};
#endif /* !SAPWOOD_PIXMAP_PRIV_H */
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index 16477fb..8c4f78b 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -133,8 +133,8 @@ sapwood_pixmap_get_for_file (const char *filename,
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
- GdkPixmap *pixmap = NULL;
- GdkBitmap *pixmask = NULL;
+ cairo_surface_t* mask = NULL;
+ GdkPixmap * pixmap = NULL;
int xerror;
if (rep.pixmap[i][j])
@@ -158,7 +158,10 @@ sapwood_pixmap_get_for_file (const char *filename,
if (rep.pixmask[i][j])
{
+ GdkBitmap* pixmask;
+
gdk_error_trap_push ();
+
pixmask = gdk_pixmap_foreign_new (rep.pixmask[i][j]);
if (sapwood_debug_xtraps)
@@ -166,21 +169,24 @@ sapwood_pixmap_get_for_file (const char *filename,
if ((xerror = gdk_error_trap_pop ()) || !pixmask)
{
- g_warning ("%s: pixmask[%d][%d]: gdk_pixmap_foreign_new(%x) failed, X error = %d",
+ g_warning ("%s: pixmask[%d][%d]: gdk_pixmap_foreign_new(%x) failed, X error = %d",
g_basename (filename), i, j, rep.pixmask[i][j], xerror);
if (pixmask)
g_object_unref (pixmask);
- pixmask = NULL;
}
+ else
+ {
+ mask = sapwood_create_surface_and_unref (pixmask);
+ }
}
- if (pixmask && !pixmap)
+ if (mask && !pixmap)
{
g_warning ("%s: pixmask[%d][%d]: no pixmap", g_basename (filename), i, j);
}
- self->pixmap[i][j] = pixmap;
- self->pixmask[i][j] = pixmask;
+ self->pixmap[i][j] = pixmap;
+ self->masks[i][j] = mask;
}
return self;
@@ -224,11 +230,8 @@ sapwood_pixmap_free (SapwoodPixmap *self)
display = gdk_drawable_get_display (self->pixmap[i][j]);
g_object_unref (self->pixmap[i][j]);
- if (self->pixmask[i][j])
- g_object_unref (self->pixmask[i][j]);
-
- self->pixmap[i][j] = NULL;
- self->pixmask[i][j] = NULL;
+ if (self->masks[i][j])
+ cairo_surface_destroy (self->masks[i][j]);
}
/* need to make sure all our operations are processed before the pixmaps
@@ -237,7 +240,7 @@ sapwood_pixmap_free (SapwoodPixmap *self)
gdk_display_sync (display);
pixbuf_proto_unref_pixmap (self->id);
- g_free (self);
+ g_free (self); /* FIXME: use g_slice() at least */
}
gboolean
@@ -257,14 +260,14 @@ sapwood_pixmap_get_geometry (SapwoodPixmap *self,
}
void
-sapwood_pixmap_get_pixmap (SapwoodPixmap *self,
- gint x,
- gint y,
- GdkPixmap **pixmap,
- GdkBitmap **pixmask)
+sapwood_pixmap_get_pixmap (SapwoodPixmap * self,
+ gint x,
+ gint y,
+ GdkPixmap **pixmap,
+ cairo_surface_t**out_mask)
{
*pixmap = self->pixmap[y][x];
- *pixmask = self->pixmask[y][x];
+ *out_mask = self->masks[y][x];
}
/*
@@ -325,9 +328,9 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap * self,
else
area = *dest;
- if (rect[n].pixmap && rect[n].pixmask)
+ if (rect[n].pixmap && rect[n].mask)
{
- gdk_cairo_set_source_pixmap (mask_cr, rect[n].pixmask, area.x, area.y);
+ cairo_set_source_surface (mask_cr, rect[n].mask, area.x, area.y);
cairo_pattern_set_extend (cairo_get_source (mask_cr), CAIRO_EXTEND_REPEAT);
gdk_cairo_rectangle (mask_cr, &area);
cairo_fill (mask_cr);
@@ -497,7 +500,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
SapwoodRect *r = &rect[n];
r->dest.x -= draw_x;
r->dest.y -= draw_y;
- if (r->pixmap && r->pixmask)
+ if (r->pixmap && r->mask)
need_tmp_mask = TRUE;
}
diff --git a/engine/sapwood-pixmap.h b/engine/sapwood-pixmap.h
index 03ab9bb..d13a627 100644
--- a/engine/sapwood-pixmap.h
+++ b/engine/sapwood-pixmap.h
@@ -28,14 +28,15 @@
G_BEGIN_DECLS
-/* opaque */
+typedef struct _SapwoodRect SapwoodRect;
typedef struct _SapwoodPixmap SapwoodPixmap;
-typedef struct {
+struct _SapwoodRect
+{
GdkPixmap *pixmap;
- GdkPixmap *pixmask;
+ cairo_surface_t* mask;
GdkRectangle dest;
-} SapwoodRect;
+};
SapwoodPixmap *sapwood_pixmap_get_for_file (const char *filename,
int border_left,
@@ -50,11 +51,11 @@ gboolean sapwood_pixmap_get_geometry (SapwoodPixmap *self,
gint *width,
gint *height) G_GNUC_INTERNAL;
-void sapwood_pixmap_get_pixmap (SapwoodPixmap *self,
- gint x,
- gint y,
- GdkPixmap **ret_pixmap,
- GdkBitmap **ret_pixmask) G_GNUC_INTERNAL;
+void sapwood_pixmap_get_pixmap (SapwoodPixmap * self,
+ gint x,
+ gint y,
+ GdkPixmap **ret_pixmap,
+ cairo_surface_t**out_mask) G_GNUC_INTERNAL;
void sapwood_pixmap_render_rects (SapwoodPixmap* self,
GType widget_type,
diff --git a/engine/theme-pixbuf.c b/engine/theme-pixbuf.c
index 25095db..1126064 100644
--- a/engine/theme-pixbuf.c
+++ b/engine/theme-pixbuf.c
@@ -330,7 +330,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
#define RENDER_COMPONENT(X,Y) do { \
sapwood_pixmap_get_pixmap (pixmap, X, Y, &rect[n_rect].pixmap, \
- &rect[n_rect].pixmask); \
+ &rect[n_rect].mask); \
\
rect[n_rect].dest.x = dest_x[X]; \
rect[n_rect].dest.y = dest_y[Y]; \
@@ -433,7 +433,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
y += (height - draw_height) / 2;
sapwood_pixmap_get_pixmap (pixmap, 1, 1,
- &rect[0].pixmap, &rect[0].pixmask);
+ &rect[0].pixmap, &rect[0].mask);
rect[0].dest.x = x;
rect[0].dest.y = y;
rect[0].dest.width = pixbuf_width;
@@ -442,7 +442,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
/* need to ensure mask is available if the pixmap has one */
mask_x = x;
mask_y = y;
- if (rect[0].pixmask && !mask)
+ if (rect[0].mask && !mask)
{
mask = gdk_pixmap_new (NULL, pixbuf_width, pixbuf_height, 1);
mask_x = 0;
diff --git a/sapwood/sapwood-cairo.c b/sapwood/sapwood-cairo.c
index 669d773..ea3a65c 100644
--- a/sapwood/sapwood-cairo.c
+++ b/sapwood/sapwood-cairo.c
@@ -1,7 +1,4 @@
-/* This file is part of ...
- *
- * AUTHORS
- * Sven Herzberg <set the EMAIL_ADDRESS environment variable>
+/* This file is part of sapwood
*
* Copyright (C) 2010 Sven Herzberg
*
@@ -23,6 +20,8 @@
#include "sapwood-cairo.h"
+static cairo_user_data_key_t sapwood_surface_user_data;
+
cairo_surface_t*
sapwood_create_surface (GdkDrawable* drawable)
{
@@ -37,4 +36,14 @@ sapwood_create_surface (GdkDrawable* drawable)
return result;
}
+cairo_surface_t*
+sapwood_create_surface_and_unref (GdkDrawable* drawable)
+{
+ cairo_surface_t* result = sapwood_create_surface (drawable);
+
+ cairo_surface_set_user_data (result, &sapwood_surface_user_data,
+ drawable, g_object_unref);
+
+ return result;
+}
/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
diff --git a/sapwood/sapwood-cairo.h b/sapwood/sapwood-cairo.h
index cd0d02a..17f381e 100644
--- a/sapwood/sapwood-cairo.h
+++ b/sapwood/sapwood-cairo.h
@@ -26,7 +26,8 @@
G_BEGIN_DECLS
-cairo_surface_t* sapwood_create_surface (GdkDrawable* drawable);
+cairo_surface_t* sapwood_create_surface (GdkDrawable* drawable);
+cairo_surface_t* sapwood_create_surface_and_unref (GdkDrawable* drawable);
G_END_DECLS
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
index 92c6f85..49c1096 100644
--- a/tests/test-sapwood-pixmap.c
+++ b/tests/test-sapwood-pixmap.c
@@ -62,7 +62,7 @@ test_larger (void)
int row = i / 3;
sapwood_pixmap_get_pixmap (pixmap, col, row,
- &rects[i].pixmap, &rects[i].pixmask);
+ &rects[i].pixmap, &rects[i].mask);
rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -145,7 +145,7 @@ test_larger_masked (void)
int row = i / 3;
sapwood_pixmap_get_pixmap (pixmap, col, row,
- &rects[i].pixmap, &rects[i].pixmask);
+ &rects[i].pixmap, &rects[i].mask);
rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -233,7 +233,7 @@ test_larger_masked_offset (void)
int row = i / 3;
sapwood_pixmap_get_pixmap (pixmap, col, row,
- &rects[i].pixmap, &rects[i].pixmask);
+ &rects[i].pixmap, &rects[i].mask);
rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -322,7 +322,7 @@ test_crop (void)
int row = i / 3;
sapwood_pixmap_get_pixmap (pixmap, col, row,
- &rects[i].pixmap, &rects[i].pixmask);
+ &rects[i].pixmap, &rects[i].mask);
rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 70 - 16;
rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 70 - 16;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]