Special case resource pixbuf files loading
This means we can share the pixbuf data when using GdkPixdata images in the resource.
This commit is contained in:
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "gtkcssimageurlprivate.h"
|
#include "gtkcssimageurlprivate.h"
|
||||||
|
|
||||||
#include "gtkcssprovider.h"
|
#include "gtkcssprovider.h"
|
||||||
@ -75,6 +77,21 @@ gtk_css_image_url_parse (GtkCssImage *image,
|
|||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
/* 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"))
|
||||||
|
{
|
||||||
|
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_resource (resource_path, &error);
|
||||||
|
g_free (resource_path);
|
||||||
|
g_free (uri);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
input = g_file_read (file, NULL, &error);
|
input = g_file_read (file, NULL, &error);
|
||||||
if (input == NULL)
|
if (input == NULL)
|
||||||
{
|
{
|
||||||
@ -85,6 +102,7 @@ gtk_css_image_url_parse (GtkCssImage *image,
|
|||||||
|
|
||||||
pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
|
pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
|
||||||
g_object_unref (input);
|
g_object_unref (input);
|
||||||
|
}
|
||||||
|
|
||||||
if (pixbuf == NULL)
|
if (pixbuf == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user