forked from AuroraMiddleware/gtk
Avoid mime sniffing where possible
When we are loading symbolic pngs or svgs, we know that we need to the png or svg loader, so there is no need to go through (surprisingly expensive) mime sniffing to find the right loader.
This commit is contained in:
parent
55b60f6da9
commit
2f17ab3ce7
@ -79,11 +79,13 @@ GdkPixbuf *gtk_make_symbolic_pixbuf_from_resource (const char *path,
|
||||
int height,
|
||||
double scale,
|
||||
GError **error);
|
||||
GdkTexture *gtk_load_symbolic_texture_from_file (GFile *file);
|
||||
GdkTexture *gtk_make_symbolic_texture_from_file (GFile *file,
|
||||
int width,
|
||||
int height,
|
||||
double scale,
|
||||
GError **error);
|
||||
GdkTexture *gtk_load_symbolic_texture_from_resource (const char *data);
|
||||
GdkTexture *gtk_make_symbolic_texture_from_resource (const char *path,
|
||||
int width,
|
||||
int height,
|
||||
|
@ -109,7 +109,7 @@ gtk_css_image_recolor_load_texture (GtkCssImageRecolor *recolor,
|
||||
char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
|
||||
|
||||
if (g_str_has_suffix (uri, ".symbolic.png"))
|
||||
recolor->texture = gdk_texture_new_from_resource (resource_path);
|
||||
recolor->texture = gtk_load_symbolic_texture_from_resource (resource_path);
|
||||
else
|
||||
recolor->texture = gtk_make_symbolic_texture_from_resource (resource_path, 0, 0, 1.0, NULL);
|
||||
|
||||
@ -118,7 +118,7 @@ gtk_css_image_recolor_load_texture (GtkCssImageRecolor *recolor,
|
||||
else
|
||||
{
|
||||
if (g_str_has_suffix (uri, ".symbolic.png"))
|
||||
recolor->texture = gdk_texture_new_from_file (recolor->file, NULL);
|
||||
recolor->texture = gtk_load_symbolic_texture_from_file (recolor->file);
|
||||
else
|
||||
recolor->texture = gtk_make_symbolic_texture_from_file (recolor->file, 0, 0, 1.0, NULL);
|
||||
}
|
||||
|
@ -560,6 +560,19 @@ gtk_make_symbolic_pixbuf_from_file (GFile *file,
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
GdkTexture *
|
||||
gtk_load_symbolic_texture_from_resource (const char *path)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkTexture *texture;
|
||||
|
||||
pixbuf = _gdk_pixbuf_new_from_resource (path, "png", NULL);
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
GdkTexture *
|
||||
gtk_make_symbolic_texture_from_resource (const char *path,
|
||||
int width,
|
||||
@ -580,6 +593,28 @@ gtk_make_symbolic_texture_from_resource (const char *path,
|
||||
return texture;
|
||||
}
|
||||
|
||||
GdkTexture *
|
||||
gtk_load_symbolic_texture_from_file (GFile *file)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkTexture *texture;
|
||||
GInputStream *stream;
|
||||
|
||||
stream = G_INPUT_STREAM (g_file_read (file, NULL, NULL));
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
||||
pixbuf = _gdk_pixbuf_new_from_stream (stream, "png", NULL, NULL);
|
||||
g_object_unref (stream);
|
||||
if (pixbuf == NULL)
|
||||
return NULL;
|
||||
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
GdkTexture *
|
||||
gtk_make_symbolic_texture_from_file (GFile *file,
|
||||
int width,
|
||||
|
Loading…
Reference in New Issue
Block a user