Commit cbee96ac authored by Cosimo Cecchi's avatar Cosimo Cecchi

file: keep scaled thumbnail in cache

Or we'll constantly re-scale it every time a client asks for the icon.
parent 01bea94e
......@@ -3467,6 +3467,11 @@ thumbnail_done (NautilusDirectory *directory,
g_object_unref (file->details->thumbnail);
file->details->thumbnail = NULL;
}
if (file->details->scaled_thumbnail) {
g_object_unref (file->details->scaled_thumbnail);
file->details->scaled_thumbnail = NULL;
}
if (pixbuf) {
if (tried_original) {
thumb_mtime = file->details->mtime;
......
......@@ -91,7 +91,10 @@ struct NautilusFileDetails
char *thumbnail_path;
GdkPixbuf *thumbnail;
time_t thumbnail_mtime;
GdkPixbuf *scaled_thumbnail;
double thumbnail_scale;
GList *mime_list; /* If this is a directory, the list of MIME types in it. */
/* Info you might get from a link (.desktop, .directory or nautilus link) */
......
......@@ -804,6 +804,10 @@ finalize (GObject *object)
if (file->details->thumbnail) {
g_object_unref (file->details->thumbnail);
}
if (file->details->scaled_thumbnail) {
g_object_unref (file->details->scaled_thumbnail);
}
if (file->details->mount) {
g_signal_handlers_disconnect_by_func (file->details->mount, file_mount_unmounted, file);
g_object_unref (file->details->mount);
......@@ -4297,17 +4301,26 @@ nautilus_file_get_icon (NautilusFile *file,
thumb_scale = (double) NAUTILUS_ICON_SIZE_SMALLEST / s;
}
scaled_pixbuf = gdk_pixbuf_scale_simple (raw_pixbuf,
MAX (w * thumb_scale, 1),
MAX (h * thumb_scale, 1),
GDK_INTERP_BILINEAR);
/* We don't want frames around small icons */
if (!gdk_pixbuf_get_has_alpha (raw_pixbuf) || s >= 128 * scale) {
if (nautilus_is_video_file (file))
nautilus_ui_frame_video (&scaled_pixbuf);
else
nautilus_ui_frame_image (&scaled_pixbuf);
if (file->details->thumbnail_scale == thumb_scale &&
file->details->scaled_thumbnail != NULL) {
scaled_pixbuf = file->details->scaled_thumbnail;
} else {
scaled_pixbuf = gdk_pixbuf_scale_simple (raw_pixbuf,
MAX (w * thumb_scale, 1),
MAX (h * thumb_scale, 1),
GDK_INTERP_BILINEAR);
/* We don't want frames around small icons */
if (!gdk_pixbuf_get_has_alpha (raw_pixbuf) || s >= 128 * scale) {
if (nautilus_is_video_file (file))
nautilus_ui_frame_video (&scaled_pixbuf);
else
nautilus_ui_frame_image (&scaled_pixbuf);
}
g_clear_object (&file->details->scaled_thumbnail);
file->details->scaled_thumbnail = scaled_pixbuf;
file->details->thumbnail_scale = thumb_scale;
}
g_object_unref (raw_pixbuf);
......@@ -4327,9 +4340,7 @@ nautilus_file_get_icon (NautilusFile *file,
DEBUG ("Returning thumbnailed image, at size %d %d",
(int) (w * thumb_scale), (int) (h * thumb_scale));
icon = nautilus_icon_info_new_for_pixbuf (scaled_pixbuf, scale);
g_object_unref (scaled_pixbuf);
return icon;
return nautilus_icon_info_new_for_pixbuf (scaled_pixbuf, scale);
} else if (file->details->thumbnail_path == NULL &&
file->details->can_read &&
!file->details->is_thumbnailing &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment