Merge branch 'avoid-mime-sniffing' into 'master'

Avoid mime sniffing where possible

See merge request GNOME/gtk!1400
This commit is contained in:
Matthias Clasen 2020-02-08 15:44:16 +00:00
commit f6b0e0e1c2
3 changed files with 39 additions and 2 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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,