Commit c8a59a6f authored by Cosimo Cecchi's avatar Cosimo Cecchi

all: avoid boxed structs copying where possible

Use the GtkStyleContext accessors for boxed properties where possible,
to reduce allocations.

https://bugzilla.gnome.org/show_bug.cgi?id=650420
parent 61e49e15
......@@ -1627,24 +1627,21 @@ _gtk_button_paint (GtkButton *button,
gint child_displacement_x;
gint child_displacement_y;
gboolean displace_focus;
GtkBorder *border;
GtkBorder border;
gtk_style_context_get_style (context,
"child-displacement-y", &child_displacement_y,
"child-displacement-x", &child_displacement_x,
"displace-focus", &displace_focus,
NULL);
gtk_style_context_get (context, state,
"border-width", &border,
NULL);
gtk_style_context_get_border (context, state, &border);
if (interior_focus)
{
x += border->left + focus_pad;
y += border->top + focus_pad;
width -= (2 * focus_pad) + border->left + border->right;
height -= (2 * focus_pad) + border->top + border->bottom;
x += border.left + focus_pad;
y += border.top + focus_pad;
width -= (2 * focus_pad) + border.left + border.right;
height -= (2 * focus_pad) + border.top + border.bottom;
}
else
{
......@@ -1662,8 +1659,6 @@ _gtk_button_paint (GtkButton *button,
gtk_render_focus (context, cr,
x, y, width, height);
gtk_border_free (border);
}
gtk_style_context_restore (context);
......
......@@ -1282,17 +1282,13 @@ gtk_combo_box_state_flags_changed (GtkWidget *widget,
{
GtkStyleContext *context;
GtkStateFlags state;
GdkRGBA *color;
GdkRGBA color;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_background_color (context, state, &color);
gtk_style_context_get (context, state,
"background-color", &color,
NULL);
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
gdk_rgba_free (color);
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
}
}
......@@ -1374,17 +1370,14 @@ gtk_combo_box_style_updated (GtkWidget *widget)
if (priv->tree_view && priv->cell_view)
{
GtkStyleContext *context;
GdkRGBA *color;
context = gtk_widget_get_style_context (widget);
gtk_style_context_get (context, 0,
"background-color", &color,
NULL);
GtkStateFlags state;
GdkRGBA color;
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view),
color);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_background_color (context, state, &color);
gdk_rgba_free (color);
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
}
child = gtk_bin_get_child (GTK_BIN (combo_box));
......@@ -3292,17 +3285,13 @@ gtk_combo_box_list_setup (GtkComboBox *combo_box)
{
GtkStyleContext *context;
GtkStateFlags state;
GdkRGBA *color;
GdkRGBA color;
context = gtk_widget_get_style_context (widget);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_background_color (context, state, &color);
gtk_style_context_get (context, state,
"background-color", &color,
NULL);
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
gdk_rgba_free (color);
gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
priv->box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
......
......@@ -4144,7 +4144,7 @@ gtk_label_draw (GtkWidget *widget,
if (priv->text && (*priv->text != '\0'))
{
GdkRGBA *bg_color, *fg_color;
GdkRGBA bg_color, fg_color;
get_layout_location (label, &x, &y);
......@@ -4192,23 +4192,18 @@ gtk_label_draw (GtkWidget *widget,
if (gtk_widget_has_focus (widget))
state |= GTK_STATE_FLAG_FOCUSED;
gtk_style_context_get (context, state,
"background-color", &bg_color,
"color", &fg_color,
NULL);
gtk_style_context_get_color (context, state, &fg_color);
gtk_style_context_get_background_color (context, state, &bg_color);
gdk_cairo_set_source_rgba (cr, bg_color);
gdk_cairo_set_source_rgba (cr, &bg_color);
cairo_paint (cr);
gdk_cairo_set_source_rgba (cr, fg_color);
gdk_cairo_set_source_rgba (cr, &fg_color);
cairo_move_to (cr, x, y);
_gtk_pango_fill_layout (cr, priv->layout);
cairo_restore (cr);
cairo_region_destroy (clip);
gdk_rgba_free (bg_color);
gdk_rgba_free (fg_color);
}
else if (info)
{
......@@ -4230,7 +4225,7 @@ gtk_label_draw (GtkWidget *widget,
if (active_link)
{
GdkRGBA *bg_color;
GdkRGBA bg_color;
range[0] = active_link->start;
range[1] = active_link->end;
......@@ -4256,11 +4251,9 @@ gtk_label_draw (GtkWidget *widget,
else
state = GTK_STATE_FLAG_PRELIGHT;
gtk_style_context_get (context, state,
"background-color", &bg_color,
NULL);
gtk_style_context_get_background_color (context, state, &bg_color);
gdk_cairo_set_source_rgba (cr, bg_color);
gdk_cairo_set_source_rgba (cr, &bg_color);
cairo_paint (cr);
gdk_cairo_set_source_color (cr, text_color);
......@@ -4269,7 +4262,6 @@ gtk_label_draw (GtkWidget *widget,
gdk_color_free (link_color);
gdk_color_free (visited_link_color);
gdk_rgba_free (bg_color);
cairo_restore (cr);
}
......
......@@ -398,25 +398,22 @@ gtk_menu_bar_size_request (GtkWidget *widget,
if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
{
GtkStyleContext *context;
GtkBorder *border;
GtkBorder border;
context = gtk_widget_get_style_context (widget);
gtk_style_context_get (context, 0,
"border-width", &border,
NULL);
gtk_style_context_get_border (context, gtk_widget_get_state_flags (widget),
&border);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
*minimum += border->left + border->right;
*natural += border->left + border->right;
*minimum += border.left + border.right;
*natural += border.left + border.right;
}
else
{
*minimum += border->top + border->bottom;
*natural += border->top + border->bottom;
*minimum += border.top + border.bottom;
*natural += border.top + border.bottom;
}
gtk_border_free (border);
}
}
......@@ -503,19 +500,16 @@ gtk_menu_bar_size_allocate (GtkWidget *widget,
if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
{
GtkStyleContext *context;
GtkBorder *border;
GtkBorder border;
context = gtk_widget_get_style_context (widget);
gtk_style_context_get (context, 0,
"border-width", &border,
NULL);
remaining_space.x += border->left;
remaining_space.y += border->top;
remaining_space.width -= border->left + border->right;
remaining_space.height -= border->top + border->bottom;
gtk_style_context_get_border (context, gtk_widget_get_state_flags (widget),
&border);
gtk_border_free (border);
remaining_space.x += border.left;
remaining_space.y += border.top;
remaining_space.width -= border.left + border.right;
remaining_space.height -= border.top + border.bottom;
}
requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
......
......@@ -685,7 +685,7 @@ gtk_style_update_from_context (GtkStyle *style)
{
GtkStylePrivate *priv;
GtkStateType state;
GtkBorder *padding;
GtkBorder padding;
gint i;
priv = GTK_STYLE_GET_PRIVATE (style);
......@@ -721,16 +721,11 @@ gtk_style_update_from_context (GtkStyle *style)
gtk_style_context_get (priv->context, 0,
"font", &style->font_desc,
"padding", &padding,
NULL);
gtk_style_context_get_padding (priv->context, 0, &padding);
if (padding)
{
style->xthickness = padding->left;
style->ythickness = padding->top;
gtk_border_free (padding);
}
style->xthickness = padding.left;
style->ythickness = padding.top;
for (i = 0; i < 5; i++)
{
......
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