Commit 6276b9cd authored by Matthias Clasen's avatar Matthias Clasen

image: Optimize non-resize changes

Suggested by Owen in

https://bugzilla.gnome.org/show_bug.cgi?id=613833
parent bece876f
......@@ -928,14 +928,20 @@ gtk_image_set_from_file (GtkImage *image,
GtkImagePrivate *priv;
GdkPixbufAnimation *anim;
gint scale_factor;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
priv = image->priv;
g_object_freeze_notify (G_OBJECT (image));
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (filename == NULL)
{
......@@ -948,9 +954,7 @@ gtk_image_set_from_file (GtkImage *image,
if (anim == NULL)
{
gtk_image_set_from_icon_name (image,
"image-missing",
DEFAULT_ICON_SIZE);
gtk_image_set_from_icon_name (image, "image-missing", DEFAULT_ICON_SIZE);
g_object_thaw_notify (G_OBJECT (image));
return;
}
......@@ -971,7 +975,16 @@ gtk_image_set_from_file (GtkImage *image,
g_object_unref (anim);
priv->filename = g_strdup (filename);
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_thaw_notify (G_OBJECT (image));
}
......@@ -1008,9 +1021,7 @@ gtk_image_set_from_resource (GtkImage *image,
if (animation == NULL)
{
gtk_image_set_from_icon_name (image,
"image-missing",
DEFAULT_ICON_SIZE);
gtk_image_set_from_icon_name (image, "image-missing", DEFAULT_ICON_SIZE);
g_object_thaw_notify (G_OBJECT (image));
return;
}
......@@ -1044,22 +1055,36 @@ gtk_image_set_from_pixbuf (GtkImage *image,
GdkPixbuf *pixbuf)
{
GtkImagePrivate *priv;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (pixbuf == NULL ||
GDK_IS_PIXBUF (pixbuf));
g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
priv = image->priv;
g_object_freeze_notify (G_OBJECT (image));
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (pixbuf != NULL)
_gtk_icon_helper_set_pixbuf (priv->icon_helper, pixbuf);
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_notify (G_OBJECT (image), "pixbuf");
g_object_thaw_notify (G_OBJECT (image));
}
......@@ -1159,6 +1184,9 @@ gtk_image_set_from_animation (GtkImage *image,
GdkPixbufAnimation *animation)
{
GtkImagePrivate *priv;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (animation == NULL ||
......@@ -1171,7 +1199,10 @@ gtk_image_set_from_animation (GtkImage *image,
if (animation)
g_object_ref (animation);
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (animation != NULL)
{
......@@ -1180,7 +1211,16 @@ gtk_image_set_from_animation (GtkImage *image,
}
g_object_notify (G_OBJECT (image), "pixbuf-animation");
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_thaw_notify (G_OBJECT (image));
}
......@@ -1201,6 +1241,9 @@ gtk_image_set_from_icon_name (GtkImage *image,
{
GtkImagePrivate *priv;
gchar *new_name;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
......@@ -1209,7 +1252,11 @@ gtk_image_set_from_icon_name (GtkImage *image,
g_object_freeze_notify (G_OBJECT (image));
new_name = g_strdup (icon_name);
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (new_name)
{
......@@ -1219,7 +1266,16 @@ gtk_image_set_from_icon_name (GtkImage *image,
g_object_notify (G_OBJECT (image), "icon-name");
g_object_notify (G_OBJECT (image), "icon-size");
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_thaw_notify (G_OBJECT (image));
}
......@@ -1239,6 +1295,9 @@ gtk_image_set_from_gicon (GtkImage *image,
GtkIconSize size)
{
GtkImagePrivate *priv;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
......@@ -1249,7 +1308,10 @@ gtk_image_set_from_gicon (GtkImage *image,
if (icon)
g_object_ref (icon);
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (icon)
{
......@@ -1259,7 +1321,16 @@ gtk_image_set_from_gicon (GtkImage *image,
g_object_notify (G_OBJECT (image), "gicon");
g_object_notify (G_OBJECT (image), "icon-size");
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_thaw_notify (G_OBJECT (image));
}
......@@ -1277,6 +1348,9 @@ gtk_image_set_from_surface (GtkImage *image,
cairo_surface_t *surface)
{
GtkImagePrivate *priv;
gint old_width, old_height;
gint new_width, new_height;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_IMAGE (image));
......@@ -1287,7 +1361,10 @@ gtk_image_set_from_surface (GtkImage *image,
if (surface)
cairo_surface_reference (surface);
gtk_image_clear (image);
context = gtk_widget_get_style_context (GTK_WIDGET (image));
_gtk_icon_helper_get_size (priv->icon_helper, context, &old_width, &old_height);
gtk_image_reset (image);
if (surface)
{
......@@ -1296,7 +1373,16 @@ gtk_image_set_from_surface (GtkImage *image,
}
g_object_notify (G_OBJECT (image), "surface");
_gtk_icon_helper_get_size (priv->icon_helper, context, &new_width, &new_height);
if (gtk_widget_get_visible (GTK_WIDGET (image)))
{
if (old_width != new_width || old_height != new_height)
gtk_widget_queue_resize (GTK_WIDGET (image));
else
gtk_widget_queue_draw (GTK_WIDGET (image));
}
g_object_thaw_notify (G_OBJECT (image));
}
......
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