Skip to content

Commit

Permalink
thumbnails: generate/load thumbnails on visible items only, and drop
Browse files Browse the repository at this point in the history
background loading.

Views load much more quickly when delaying any thumbnail processing
until all items are fully loaded.

An attempt is made to load 'ahead' and 'behind' the visible range,
but in the list view, the current api does not allow scanning for
rows 'above' the current view position, only below.  As a result,
scrolling a view down in the list view will reveal icons that have
already been queued to load their thumbnail, but scrolling up will
not.  This behavior works properly in the icon views in both
directions.
  • Loading branch information
mtwebster committed May 20, 2020
1 parent 6ae5ef8 commit bb049a4
Show file tree
Hide file tree
Showing 17 changed files with 392 additions and 109 deletions.
5 changes: 3 additions & 2 deletions libnemo-private/nemo-directory-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ lacks_btime (NemoFile *file)
static gboolean
lacks_filesystem_info (NemoFile *file)
{
return !file->details->filesystem_info_is_up_to_date;
return nemo_file_is_directory (file) && !file->details->filesystem_info_is_up_to_date;
}

static gboolean
Expand Down Expand Up @@ -1692,7 +1692,8 @@ lacks_extension_info (NemoFile *file)
static gboolean
lacks_thumbnail (NemoFile *file)
{
return nemo_file_should_show_thumbnail (file) &&
return file->details->load_thumb &&
nemo_file_should_show_thumbnail (file) &&
file->details->thumbnail_path != NULL &&
!file->details->thumbnail_is_up_to_date;
}
Expand Down
5 changes: 4 additions & 1 deletion libnemo-private/nemo-file-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct NemoFileDetails

eel_ref_str name;

gchar *cached_uri;

/* File info: */
GFileType type;

Expand Down Expand Up @@ -221,7 +223,8 @@ struct NemoFileDetails

eel_boolean_bit filesystem_readonly : 1;
eel_boolean_bit filesystem_use_preview : 2; /* GFilesystemPreviewType */
eel_boolean_bit filesystem_info_is_up_to_date : 1;
eel_boolean_bit filesystem_info_is_up_to_date : 1;
eel_boolean_bit load_thumb : 1;

NemoFilePinning pinning;

Expand Down
42 changes: 35 additions & 7 deletions libnemo-private/nemo-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ nemo_file_clear_info (NemoFile *file)
file->details->ctime = 0;
file->details->btime = 0;
file->details->trash_time = 0;
file->details->load_thumb = FALSE;
g_free (file->details->symlink_name);
file->details->symlink_name = NULL;
eel_ref_str_unref (file->details->mime_type);
Expand Down Expand Up @@ -564,7 +565,7 @@ nemo_file_new_from_filename (NemoDirectory *directory,
file->details->name = eel_ref_str_new (filename);

#ifdef NEMO_FILE_DEBUG_REF
DEBUG_REF_PRINTF("%10p ref'd", file);
DEBUG_REF_PRINTF("%10p ref'd\n", file);
#endif

return file;
Expand Down Expand Up @@ -676,7 +677,7 @@ nemo_file_new_from_info (NemoDirectory *directory,
update_info_and_name (file, info);

#ifdef NEMO_FILE_DEBUG_REF
DEBUG_REF_PRINTF("%10p ref'd", file);
DEBUG_REF_PRINTF("%10p ref'd\n", file);
#endif

return file;
Expand Down Expand Up @@ -865,6 +866,8 @@ finalize (GObject *object)
metadata_hash_free (file->details->metadata);
}

g_free (file->details->cached_uri);

G_OBJECT_CLASS (nemo_file_parent_class)->finalize (object);
}

Expand All @@ -877,7 +880,7 @@ nemo_file_ref (NemoFile *file)
g_return_val_if_fail (NEMO_IS_FILE (file), NULL);

#ifdef NEMO_FILE_DEBUG_REF
DEBUG_REF_PRINTF("%10p ref'd", file);
DEBUG_REF_PRINTF("%10p ref'd\n", file);
#endif

return g_object_ref (file);
Expand All @@ -893,7 +896,7 @@ nemo_file_unref (NemoFile *file)
g_return_if_fail (NEMO_IS_FILE (file));

#ifdef NEMO_FILE_DEBUG_REF
DEBUG_REF_PRINTF("%10p unref'd", file);
DEBUG_REF_PRINTF("%10p unref'd\n", file);
#endif

g_object_unref (file);
Expand Down Expand Up @@ -1639,6 +1642,18 @@ nemo_file_get_uri (NemoFile *file)
return uri;
}

const char *
nemo_file_peek_uri (NemoFile *file)
{
g_return_val_if_fail (NEMO_IS_FILE (file), NULL);

if (file->details->cached_uri == NULL) {
file->details->cached_uri = nemo_file_get_uri (file);
}

return file->details->cached_uri;
}

/* Return the actual path associated with the passed-in file. */
char *
nemo_file_get_path (NemoFile *file)
Expand Down Expand Up @@ -4342,6 +4357,12 @@ nemo_file_delete_thumbnail (NemoFile *file)
}
}

gboolean
nemo_file_has_loaded_thumbnail (NemoFile *file)
{
return file->details->thumbnail_is_up_to_date;
}

static void
prepend_icon_name (const char *name,
GThemedIcon *icon)
Expand Down Expand Up @@ -4636,7 +4657,7 @@ nemo_file_get_icon (NemoFile *file,
DEBUG ("Called file_get_icon(), at size %d, force thumbnail %d", size,
flags & NEMO_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE);

if (flags & NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS &&
if ((flags & NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS) &&
nemo_file_should_show_thumbnail (file)) {

if (flags & NEMO_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE) {
Expand Down Expand Up @@ -4727,12 +4748,12 @@ nemo_file_get_icon (NemoFile *file,
!file->details->is_thumbnailing &&
!file->details->thumbnailing_failed) {
if (nemo_can_thumbnail (file)) {
nemo_create_thumbnail (file, get_throttle_count (file));
nemo_create_thumbnail (file, get_throttle_count (file), TRUE);
}
}
}

if (file->details->is_thumbnailing &&
if (file->details->thumbnail_path == NULL && nemo_can_thumbnail (file) &&
flags & NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS)
gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
else
Expand Down Expand Up @@ -8019,6 +8040,13 @@ nemo_file_invalidate_extension_info_internal (NemoFile *file)
nemo_module_get_extensions_for_type (NEMO_TYPE_INFO_PROVIDER);
}

void
nemo_file_set_load_thumb (NemoFile *file,
gboolean load_thumb)
{
file->details->load_thumb = load_thumb;
}

void
nemo_file_invalidate_attributes_internal (NemoFile *file,
NemoFileAttributes file_attributes)
Expand Down
4 changes: 3 additions & 1 deletion libnemo-private/nemo-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const char * nemo_file_peek_name (NemoFile
GFile * nemo_file_get_location (NemoFile *file);
char * nemo_file_get_description (NemoFile *file);
char * nemo_file_get_uri (NemoFile *file);
const char * nemo_file_peek_uri (NemoFile *file);
char * nemo_file_get_path (NemoFile *file);
char * nemo_file_get_uri_scheme (NemoFile *file);
NemoFile * nemo_file_get_parent (NemoFile *file);
Expand Down Expand Up @@ -240,6 +241,7 @@ NemoRequestStatus nemo_file_get_deep_counts (NemoFile
gboolean force);
gboolean nemo_file_should_show_thumbnail (NemoFile *file);
void nemo_file_delete_thumbnail (NemoFile *file);
gboolean nemo_file_has_loaded_thumbnail (NemoFile *file);
gboolean nemo_file_should_show_directory_item_count (NemoFile *file);
gboolean nemo_file_should_show_type (NemoFile *file);
GList * nemo_file_get_keywords (NemoFile *file);
Expand Down Expand Up @@ -521,7 +523,7 @@ void nemo_file_set_is_desktop_orphan (NemoFile *file, gboolean is_d

gboolean nemo_file_get_pinning (NemoFile *file);
void nemo_file_set_pinning (NemoFile *file, gboolean pin);

void nemo_file_set_load_thumb (NemoFile *file, gboolean load_thumb);
/* Debugging */
void nemo_file_dump (NemoFile *file);

Expand Down
Loading

0 comments on commit bb049a4

Please sign in to comment.