Commit 8e032622 authored by Alexander Larsson's avatar Alexander Larsson

box-shadow: For top/bottom and left/right parts, repeat a single line

Since these part really are the same in all of the x or y direction
and we don't blur in that direction we can just blur one line and
repeat it during drawing.

https://bugzilla.gnome.org/show_bug.cgi?id=746468
parent 967cb562
......@@ -32,7 +32,8 @@ G_BEGIN_DECLS
typedef enum {
GTK_BLUR_NONE = 0,
GTK_BLUR_X = 1<<0,
GTK_BLUR_Y = 1<<1
GTK_BLUR_Y = 1<<1,
GTK_BLUR_REPEAT = 1<<2
} GtkBlurFlags;
void _gtk_cairo_blur_surface (cairo_surface_t *surface,
......
......@@ -328,6 +328,14 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
radius = _gtk_css_number_value_get (shadow->radius, 0);
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
if (blur_flags & GTK_BLUR_REPEAT)
{
if (!blur_x)
clip_rect.width = 1;
if (!blur_y)
clip_rect.height = 1;
}
/* Create a larger surface to center the blur. */
surface = cairo_surface_create_similar_image (cairo_get_target (cr),
CAIRO_FORMAT_A8,
......@@ -350,6 +358,20 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
return blur_cr;
}
void
mask_surface_repeat (cairo_t *cr,
cairo_surface_t *surface)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cairo_mask (cr, pattern);
cairo_pattern_destroy (pattern);
}
static cairo_t *
gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
cairo_t *cr,
......@@ -370,7 +392,10 @@ gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
_gtk_cairo_blur_surface (surface, radius, blur_flags);
gdk_cairo_set_source_rgba (original_cr, _gtk_css_rgba_value_get_rgba (shadow->color));
cairo_mask_surface (original_cr, surface, 0, 0);
if (blur_flags & GTK_BLUR_REPEAT)
mask_surface_repeat (original_cr, surface);
else
cairo_mask_surface (original_cr, surface, 0, 0);
cairo_destroy (cr);
......@@ -740,7 +765,7 @@ _gtk_css_shadow_value_paint_box (const GtkCssValue *shadow,
/* Then the sides */
for (i = 0; i < 4; i++)
{
GtkBlurFlags blur_flags = 0;
GtkBlurFlags blur_flags = GTK_BLUR_REPEAT;
if (i == GTK_CSS_TOP || i == GTK_CSS_BOTTOM)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment