[nautilus] file: keep scaled thumbnail in cache
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] file: keep scaled thumbnail in cache
- Date: Mon, 1 Sep 2014 22:36:46 +0000 (UTC)
commit cbee96ac593dd35f4e10d88085e4feec2c569a9b
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Aug 30 19:26:38 2014 -0700
file: keep scaled thumbnail in cache
Or we'll constantly re-scale it every time a client asks for the icon.
libnautilus-private/nautilus-directory-async.c | 5 +++
libnautilus-private/nautilus-file-private.h | 5 ++-
libnautilus-private/nautilus-file.c | 39 +++++++++++++++--------
3 files changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/libnautilus-private/nautilus-directory-async.c b/libnautilus-private/nautilus-directory-async.c
index 251081f..afc41b2 100644
--- a/libnautilus-private/nautilus-directory-async.c
+++ b/libnautilus-private/nautilus-directory-async.c
@@ -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;
diff --git a/libnautilus-private/nautilus-file-private.h b/libnautilus-private/nautilus-file-private.h
index 28a4601..5dd41ba 100644
--- a/libnautilus-private/nautilus-file-private.h
+++ b/libnautilus-private/nautilus-file-private.h
@@ -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) */
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 80137be..466023e 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -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 &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]