diff options
author | Alexander Larsson <alexl@redhat.com> | 2012-02-03 15:51:55 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2012-02-03 15:51:55 +0100 |
commit | 610ea728b229b6710e55d6a1784b396a3839e62c (patch) | |
tree | 04c76765fa0968dc4c48f107759fa6348a2ddc1e /gtk/gtkcssimageurl.c | |
parent | 57386285fa23db6879efaccd2cfa7ed501b6056f (diff) | |
download | gtk+-610ea728b229b6710e55d6a1784b396a3839e62c.tar.gz |
Special case resource pixbuf files loading
This means we can share the pixbuf data when using GdkPixdata
images in the resource.
Diffstat (limited to 'gtk/gtkcssimageurl.c')
-rw-r--r-- | gtk/gtkcssimageurl.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c index a548d93125..3354f1981c 100644 --- a/gtk/gtkcssimageurl.c +++ b/gtk/gtkcssimageurl.c @@ -20,6 +20,8 @@ #include "config.h" +#include <string.h> + #include "gtkcssimageurlprivate.h" #include "gtkcssprovider.h" @@ -75,16 +77,32 @@ gtk_css_image_url_parse (GtkCssImage *image, if (file == NULL) return FALSE; - input = g_file_read (file, NULL, &error); - if (input == NULL) + /* We special case resources here so we can use + gdk_pixbuf_new_from_resource, which in turn has some special casing + for GdkPixdata files to avoid duplicating the memory for the pixbufs */ + if (g_file_has_uri_scheme (file, "resource")) { - _gtk_css_parser_take_error (parser, error); - return FALSE; - } - g_object_unref (file); + char *uri = g_file_get_uri (file); + char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL); + g_print ("uri: %s, resource_path: %s\n", uri, resource_path); - pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error); - g_object_unref (input); + pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error); + g_free (resource_path); + g_free (uri); + } + else + { + input = g_file_read (file, NULL, &error); + if (input == NULL) + { + _gtk_css_parser_take_error (parser, error); + return FALSE; + } + g_object_unref (file); + + pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error); + g_object_unref (input); + } if (pixbuf == NULL) { |