[sapwood] finally pass a cairo_t* into sapwood_pixmap_render_rects
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] finally pass a cairo_t* into sapwood_pixmap_render_rects
- Date: Fri, 13 Aug 2010 11:41:17 +0000 (UTC)
commit 20cd1725e7f16c4e2a0d65aaf4a8f276915a216f
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Aug 13 12:46:50 2010 +0200
finally pass a cairo_t* into sapwood_pixmap_render_rects
* engine/sapwood-pixmap.c,
* engine/sapwood-pixmap.h: receive a cairo_t* instead of a GdkDrawable
* engine/theme-pixbuf.c,
* tests/test-sapwood-pixmap.c: update calls to match the new API
engine/sapwood-pixmap.c | 13 +++++--------
engine/sapwood-pixmap.h | 7 ++++---
engine/theme-pixbuf.c | 31 ++++++++++++++++++-------------
tests/test-sapwood-pixmap.c | 20 ++++++++++++++++----
4 files changed, 43 insertions(+), 28 deletions(-)
---
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index 2fab323..16477fb 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -270,7 +270,7 @@ sapwood_pixmap_get_pixmap (SapwoodPixmap *self,
/*
* sapwood_pixmap_render_rects_internal:
* @self: a #SapwoodPixmap
- * @drawable: the #GdkDrawable to draw to
+ * @cr: the #cairo_t context to draw to
* @draw_x: the horizontal offset on @drawable in pixels
* @draw_y: the vertical offset on @drawable in pixels
* @mask: a #cairo_surface_t mask to paint @self's bitmask to and to use when the 1-bit transparency should be honored
@@ -460,7 +460,7 @@ sapwood_crop_pixmap (cairo_surface_t* surface,
void
sapwood_pixmap_render_rects (SapwoodPixmap* self,
GType widget_type,
- GdkDrawable *draw,
+ cairo_t * cr,
gint draw_x,
gint draw_y,
gint width,
@@ -477,13 +477,10 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
cairo_surface_t* tmp;
gboolean need_tmp_mask = FALSE;
cairo_t * tmp_cr;
- cairo_t * cr;
gint n;
gint tmp_width;
gint tmp_height;
- cr = gdk_cairo_create (draw);
-
/* Don't even try to scale down shape masks (should never be useful, and
* implementing would add some complexity.) Areas larger than the pixmap
* can be tiled fine.
@@ -491,7 +488,6 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
if (mask_required || (width >= self->width && height >= self->height))
{
sapwood_pixmap_render_rects_internal (self, cr, draw_x, draw_y, mask, mask_x, mask_y, mask_required, clip_rect, n_rect, rect);
- cairo_destroy (cr);
return;
}
@@ -515,7 +511,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
if (need_tmp_mask)
{
- GdkPixmap* tmp_mask = gdk_pixmap_new (draw, tmp_width, tmp_height, 1);
+ GdkPixmap* tmp_mask = gdk_pixmap_new (NULL, tmp_width, tmp_height, 1);
cairo_t* mask_cr = gdk_cairo_create (tmp_mask);
cairo_set_operator (mask_cr, CAIRO_OPERATOR_CLEAR);
@@ -530,6 +526,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
tmp_cr = cairo_create (tmp);
sapwood_pixmap_render_rects_internal (self, tmp_cr, 0, 0, mask_surface, 0, 0, mask_required, NULL, n_rect, rect);
+ cairo_save (cr);
/* finally, render downscaled at draw_x,draw_y */
if (clip_rect)
{
@@ -576,7 +573,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
cairo_paint (cr);
/* clean up */
- cairo_destroy (cr);
+ cairo_restore (cr);
if (mask_surface)
{
cairo_surface_destroy (mask_surface);
diff --git a/engine/sapwood-pixmap.h b/engine/sapwood-pixmap.h
index 015c55f..03ab9bb 100644
--- a/engine/sapwood-pixmap.h
+++ b/engine/sapwood-pixmap.h
@@ -1,5 +1,6 @@
/* GTK+ Sapwood Engine
- * Copyright (C) 2005 Nokia Corporation
+ * Copyright (C) 2005 Nokia Corporation
+ * Copyright (C) 2010 Sven Herzberg
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -56,8 +57,8 @@ void sapwood_pixmap_get_pixmap (SapwoodPixmap *self,
GdkBitmap **ret_pixmask) G_GNUC_INTERNAL;
void sapwood_pixmap_render_rects (SapwoodPixmap* self,
- GType widget_type,
- GdkDrawable *draw,
+ GType widget_type,
+ cairo_t * cr,
gint draw_x,
gint draw_y,
gint width,
diff --git a/engine/theme-pixbuf.c b/engine/theme-pixbuf.c
index 549fdf3..25095db 100644
--- a/engine/theme-pixbuf.c
+++ b/engine/theme-pixbuf.c
@@ -284,17 +284,19 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
gint width,
gint height)
{
- gint dest_x[4], dest_y[4];
- SapwoodPixmap *pixmap;
- gint pixbuf_width;
- gint pixbuf_height;
- gint draw_width;
- gint draw_height;
- SapwoodRect rect[9];
- gint n_rect;
- gint mask_x;
- gint mask_y;
- gboolean mask_required;
+ SapwoodPixmap* pixmap;
+ SapwoodRect rect[9];
+ gboolean mask_required;
+ cairo_t * cr;
+ gint dest_x[4];
+ gint dest_y[4];
+ gint pixbuf_width;
+ gint pixbuf_height;
+ gint draw_width;
+ gint draw_height;
+ gint n_rect;
+ gint mask_x;
+ gint mask_y;
if (width <= 0 || height <= 0)
return FALSE;
@@ -304,6 +306,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
pixmap = theme_pixbuf_get_pixmap (theme_pb);
+ cr = gdk_cairo_create (window);
if (theme_pb->stretch)
{
cairo_surface_t* mask_surface = NULL;
@@ -412,7 +415,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
mask_surface = sapwood_create_surface (mask);
sapwood_pixmap_render_rects (pixmap, widget_type,
- window, x, y, width, height,
+ cr, x, y, width, height,
mask_surface, mask_x, mask_y, mask_required,
clip_rect, n_rect, rect);
cairo_surface_destroy (mask_surface);
@@ -451,7 +454,7 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
mask_surface = sapwood_create_surface (mask);
sapwood_pixmap_render_rects (pixmap, widget_type,
- window, x, y, draw_width, draw_height,
+ cr, x, y, draw_width, draw_height,
mask_surface, mask_x, mask_y, FALSE,
clip_rect, 1, rect);
@@ -460,9 +463,11 @@ theme_pixbuf_render (ThemePixbuf *theme_pb,
}
else /* tile? */
{
+ cairo_destroy (cr);
return FALSE;
}
+ cairo_destroy (cr);
return TRUE;
}
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
index 5bfcbe8..92c6f85 100644
--- a/tests/test-sapwood-pixmap.c
+++ b/tests/test-sapwood-pixmap.c
@@ -38,6 +38,7 @@ test_larger (void)
GdkDrawable * drawable = NULL;
GdkPixbuf * result;
GdkPixbuf * expected;
+ cairo_t * cr;
GError * error = NULL;
char abspath[PATH_MAX + 1];
int code;
@@ -73,9 +74,11 @@ test_larger (void)
gdk_error_trap_push ();
+ cr = gdk_cairo_create (drawable);
+ g_test_queue_destroy ((GFreeFunc) cairo_destroy, cr);
sapwood_pixmap_render_rects (pixmap,
GTK_TYPE_BUTTON,
- drawable,
+ cr,
0, 0,
200, 200,
NULL,
@@ -118,6 +121,7 @@ test_larger_masked (void)
GdkPixbuf * result;
GdkPixbuf * expected;
GdkBitmap * mask;
+ cairo_t * cr;
GError * error = NULL;
char abspath[PATH_MAX + 1];
int code;
@@ -158,9 +162,11 @@ test_larger_masked (void)
gdk_error_trap_push ();
+ cr = gdk_cairo_create (drawable);
+ g_test_queue_destroy ((GFreeFunc) cairo_destroy, cr);
sapwood_pixmap_render_rects (pixmap,
GTK_TYPE_BUTTON,
- drawable,
+ cr,
0, 0,
200, 200,
mask_surface,
@@ -203,6 +209,7 @@ test_larger_masked_offset (void)
GdkPixbuf * result;
GdkPixbuf * expected;
GdkBitmap * mask;
+ cairo_t * cr;
GError * error = NULL;
char abspath[PATH_MAX + 1];
int code;
@@ -243,9 +250,11 @@ test_larger_masked_offset (void)
gdk_error_trap_push ();
+ cr = gdk_cairo_create (drawable);
+ g_test_queue_destroy ((GFreeFunc) cairo_destroy, cr);
sapwood_pixmap_render_rects (pixmap,
GTK_TYPE_BUTTON,
- drawable,
+ cr,
0, 0,
200, 200,
mask_surface,
@@ -289,6 +298,7 @@ test_crop (void)
GdkPixbuf * result;
GdkPixbuf * expected;
GdkBitmap * mask;
+ cairo_t * cr;
GError * error = NULL;
char abspath[PATH_MAX + 1];
int code;
@@ -329,9 +339,11 @@ test_crop (void)
gdk_error_trap_push ();
+ cr = gdk_cairo_create (drawable);
+ g_test_queue_destroy ((GFreeFunc) cairo_destroy, cr);
sapwood_pixmap_render_rects (pixmap,
GTK_TYPE_BUTTON,
- drawable,
+ cr,
0, 0,
50, 50,
mask_surface,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]