themingbackground: Restructure code some more

Move variable initialization outside the first code with side effects.
This allows adding some more early returns, including one for code that
used to trigger g_return_if_fail() in certain corner cases.
This commit is contained in:
Benjamin Otte 2012-10-27 01:39:30 +02:00
parent ce56248930
commit ccaf1c2c67

View File

@ -154,16 +154,9 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
double image_width, image_height;
double width, height;
if (layer->image == NULL
|| layer->image_rect.width <= 0
|| layer->image_rect.height <= 0)
if (layer->image == NULL)
return;
cairo_save (cr);
_gtk_rounded_box_path (&layer->clip_box, cr);
cairo_clip (cr);
pos = _gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_POSITION), layer->idx);
repeat = _gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_REPEAT), layer->idx);
hrepeat = _gtk_css_background_repeat_value_get_x (repeat);
@ -171,6 +164,9 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
width = layer->image_rect.width;
height = layer->image_rect.height;
if (width <= 0 || height <= 0)
return;
_gtk_css_bg_size_value_compute_size (_gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_SIZE), layer->idx),
layer->image,
width,
@ -178,12 +174,22 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
&image_width,
&image_height);
if (image_width <= 0 || image_height <= 0)
return;
/* optimization */
if (image_width == width)
hrepeat = GTK_CSS_REPEAT_STYLE_NO_REPEAT;
if (image_height == height)
vrepeat = GTK_CSS_REPEAT_STYLE_NO_REPEAT;
cairo_save (cr);
_gtk_rounded_box_path (&layer->clip_box, cr);
cairo_clip (cr);
cairo_translate (cr, layer->image_rect.x, layer->image_rect.y);
if (hrepeat == GTK_CSS_REPEAT_STYLE_NO_REPEAT && vrepeat == GTK_CSS_REPEAT_STYLE_NO_REPEAT)
@ -301,6 +307,7 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
cairo_fill (cr);
}
cairo_restore (cr);
}