themingengine: Don't modify pattern

Instead, scale/unscale the cairo_t.
This commit is contained in:
Benjamin Otte 2011-06-09 04:50:12 +02:00
parent 9affa9fc4d
commit 88026c5073

View File

@ -1490,32 +1490,6 @@ _cairo_uneven_frame (cairo_t *cr,
SIDE_ALL); SIDE_ALL);
} }
/* Set the appropriate matrix for
* patterns coming from the style context
*/
static void
style_pattern_set_matrix (cairo_pattern_t *pattern,
gdouble width,
gdouble height)
{
cairo_matrix_t matrix;
gint w, h;
if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SURFACE)
{
cairo_surface_t *surface;
cairo_pattern_get_surface (pattern, &surface);
w = cairo_image_surface_get_width (surface);
h = cairo_image_surface_get_height (surface);
}
else
w = h = 1;
cairo_matrix_init_scale (&matrix, (gdouble) w / width, (gdouble) h / height);
cairo_pattern_set_matrix (pattern, &matrix);
}
static void static void
render_background_internal (GtkThemingEngine *engine, render_background_internal (GtkThemingEngine *engine,
cairo_t *cr, cairo_t *cr,
@ -1537,7 +1511,6 @@ render_background_internal (GtkThemingEngine *engine,
gint border_width; gint border_width;
GtkBorderStyle border_style; GtkBorderStyle border_style;
gdouble mat_w, mat_h; gdouble mat_w, mat_h;
cairo_matrix_t identity;
/* Use unmodified size for pattern scaling */ /* Use unmodified size for pattern scaling */
mat_w = width; mat_w = width;
@ -1545,8 +1518,6 @@ render_background_internal (GtkThemingEngine *engine,
flags = gtk_theming_engine_get_state (engine); flags = gtk_theming_engine_get_state (engine);
cairo_matrix_init_identity (&identity);
gtk_theming_engine_get_background_color (engine, flags, &bg_color); gtk_theming_engine_get_background_color (engine, flags, &bg_color);
gtk_theming_engine_get_border (engine, flags, &border); gtk_theming_engine_get_border (engine, flags, &border);
@ -1703,12 +1674,11 @@ render_background_internal (GtkThemingEngine *engine,
0, 0, width, height, 0, 0, width, height,
SIDE_ALL); SIDE_ALL);
style_pattern_set_matrix (other_pattern, mat_w, mat_h); cairo_scale (cr, mat_w, mat_h);
cairo_set_source (cr, other_pattern); cairo_set_source (cr, other_pattern);
cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
cairo_fill_preserve (cr); cairo_fill_preserve (cr);
cairo_pattern_set_matrix (other_pattern, &identity);
/* Set alpha for posterior drawing /* Set alpha for posterior drawing
* of the target pattern * of the target pattern
*/ */
@ -1789,8 +1759,9 @@ render_background_internal (GtkThemingEngine *engine,
SIDE_ALL); SIDE_ALL);
if (pattern) if (pattern)
{ {
style_pattern_set_matrix (pattern, mat_w, mat_h); cairo_scale (cr, mat_w, mat_h);
cairo_set_source (cr, pattern); cairo_set_source (cr, pattern);
cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
} }
else else
gdk_cairo_set_source_rgba (cr, &bg_color); gdk_cairo_set_source_rgba (cr, &bg_color);
@ -1826,10 +1797,7 @@ render_background_internal (GtkThemingEngine *engine,
} }
if (pattern) if (pattern)
{ cairo_pattern_destroy (pattern);
cairo_pattern_set_matrix (pattern, &identity);
cairo_pattern_destroy (pattern);
}
cairo_restore (cr); cairo_restore (cr);
} }