After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 733416 - image: support scale factor when loading from GResource
image: support scale factor when loading from GResource
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 733417
 
 
Reported: 2014-07-19 20:07 UTC by Cosimo Cecchi
Modified: 2014-07-29 08:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
image: support scale factor when loading from GResource (3.50 KB, patch)
2014-07-19 20:07 UTC, Cosimo Cecchi
reviewed Details | Review
image: support scale factor when loading from GResource and file (4.52 KB, patch)
2014-07-23 04:48 UTC, Cosimo Cecchi
needs-work Details | Review
iconhelper: reset original pixbuf scale on clear (829 bytes, patch)
2014-07-23 04:48 UTC, Cosimo Cecchi
committed Details | Review
image: support scale factor when loading from GResource and file (4.73 KB, patch)
2014-07-26 14:49 UTC, Cosimo Cecchi
committed Details | Review

Description Cosimo Cecchi 2014-07-19 20:07:19 UTC
This fixes one of the few places where we don't support scale factor in GtkImage.
See attached patch.
Comment 1 Cosimo Cecchi 2014-07-19 20:07:22 UTC
Created attachment 281200 [details] [review]
image: support scale factor when loading from GResource

Currently, when loading an image from a GResource we don't take the
scale factor of the display into consideration, and let GtkIconHelper
scale it accordingly.
While this in general works for non-scalable images, we can take
advantage of the native loader's scaling for e.g. SVG images, and load
them at the right scale factor automatically.
This is achieved by switching to a pixbuf loader instead of using the
native function.
Comment 2 Cosimo Cecchi 2014-07-19 20:16:43 UTC
See the blocked g-c-c bug for why I wrote this.

I decided not to touch the code path g-c-c is currently using to load those images (https://git.gnome.org/browse/gtk+/tree/gtk/gtkbuilder.c#n2026) because at the time that property is loaded, there's no knowledge in the builder about how the pixbuf will be used.

Finally, a similar change could be written for gtk_image_new_from_file, but I first want to validate this approach.
Comment 3 Matthias Clasen 2014-07-20 05:24:52 UTC
Review of attachment 281200 [details] [review]:

::: gtk/gtkimage.c
@@ +943,3 @@
+  image_set = TRUE;
+  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (image));
+  _gtk_icon_helper_set_pixbuf_scale (priv->icon_helper, scale_factor);

One thing I wonder about: You set the pixbuf scale to some value here, but not when calling gtk_icon_helper_set_pixbuf in other places, so the scale will stick around.

Maybe it would be better to have a combined

gtk_icon_helper_set_pixbuf_with_scale ?

@@ +954,3 @@
+  g_object_unref (loader);
+
+ out:

I think out: needs to be before g_object_unref (loader), or you'll leak the loader in the error caess.

@@ +958,3 @@
+    gtk_image_set_from_icon_name (image,
+				  "image-missing",
+				  DEFAULT_ICON_SIZE);

I'm increasingly putting things like this just on one line:

 gtk_image_set_from_icon_name (image, "image-missing", DEFAULT_ICON_SIZE);
Comment 4 Matthias Clasen 2014-07-20 05:26:05 UTC
The general idea looks right to me, anyway.
Comment 5 Cosimo Cecchi 2014-07-23 04:48:33 UTC
Created attachment 281450 [details] [review]
image: support scale factor when loading from GResource and file

Currently, when loading an image from a GResource or file we don't take
the scale factor of the display into consideration, and let
GtkIconHelper scale it accordingly.
While this in general works for non-scalable images, we can take
advantage of the native loader's scaling for e.g. SVG images, and load
them at the right scale factor automatically.
This is achieved by switching to a pixbuf loader instead of using the
native function.
Comment 6 Cosimo Cecchi 2014-07-23 04:48:41 UTC
Created attachment 281451 [details] [review]
iconhelper: reset original pixbuf scale on clear

Avoids a previously set value for a different image to accidentally
stick around.
Comment 7 Cosimo Cecchi 2014-07-23 15:56:51 UTC
Review of attachment 281450 [details] [review]:

::: gtk/gtkimage.c
@@ +830,3 @@
+  format = gdk_pixbuf_loader_get_format (loader);
+  if (!gdk_pixbuf_format_is_scalable (format))
+{

Hmm on second thought I think this won't do the right thing, because we still set the pixbuf scale factor in this case. I will rework later.
Comment 8 Cosimo Cecchi 2014-07-26 14:49:55 UTC
Created attachment 281775 [details] [review]
image: support scale factor when loading from GResource and file

--

This should work in all cases.
Comment 9 Matthias Clasen 2014-07-29 08:08:57 UTC
Review of attachment 281451 [details] [review]:

sure
Comment 10 Matthias Clasen 2014-07-29 08:13:13 UTC
Review of attachment 281775 [details] [review]:

looks good
Comment 11 Cosimo Cecchi 2014-07-29 08:19:34 UTC
Attachment 281451 [details] pushed as 09a36b1 - iconhelper: reset original pixbuf scale on clear
Attachment 281775 [details] pushed as 7e425f3 - image: support scale factor when loading from GResource and file