forked from AuroraMiddleware/gtk
css image: Use GdkTexture api directly
No need to load a pixbuf anymore, we can just directly create textures.
This commit is contained in:
parent
44a3f6bb41
commit
acf58063a7
@ -31,7 +31,7 @@ static GtkCssImage *
|
|||||||
gtk_css_image_url_load_image (GtkCssImageUrl *url,
|
gtk_css_image_url_load_image (GtkCssImageUrl *url,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkTexture *texture;
|
||||||
GError *local_error = NULL;
|
GError *local_error = NULL;
|
||||||
GFileInputStream *input;
|
GFileInputStream *input;
|
||||||
|
|
||||||
@ -46,25 +46,17 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url,
|
|||||||
char *uri = g_file_get_uri (url->file);
|
char *uri = g_file_get_uri (url->file);
|
||||||
char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
|
char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
|
||||||
|
|
||||||
pixbuf = gdk_pixbuf_new_from_resource (resource_path, &local_error);
|
texture = gdk_texture_new_from_resource (resource_path);
|
||||||
|
|
||||||
g_free (resource_path);
|
g_free (resource_path);
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
input = g_file_read (url->file, NULL, &local_error);
|
texture = gdk_texture_new_from_file (url->file, &local_error);
|
||||||
if (input != NULL)
|
|
||||||
{
|
|
||||||
pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &local_error);
|
|
||||||
g_object_unref (input);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pixbuf = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixbuf == NULL)
|
if (texture == NULL)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
@ -75,16 +67,14 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url,
|
|||||||
GTK_CSS_PROVIDER_ERROR,
|
GTK_CSS_PROVIDER_ERROR,
|
||||||
GTK_CSS_PROVIDER_ERROR_FAILED,
|
GTK_CSS_PROVIDER_ERROR_FAILED,
|
||||||
"Error loading image '%s': %s", uri, local_error->message);
|
"Error loading image '%s': %s", uri, local_error->message);
|
||||||
g_error_free (local_error);
|
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
url->loaded_image = gtk_css_image_surface_new (NULL);
|
|
||||||
return url->loaded_image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
url->loaded_image = gtk_css_image_surface_new_for_pixbuf (pixbuf);
|
url->loaded_image = gtk_css_image_surface_new (texture);
|
||||||
g_object_unref (pixbuf);
|
|
||||||
|
g_clear_pointer (&texture);
|
||||||
|
g_clear_error (&local_error);
|
||||||
|
|
||||||
return url->loaded_image;
|
return url->loaded_image;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user