Compare commits

..

2 Commits

Author SHA1 Message Date
69d45fea44
Use a GQueue for thumbnailing
It's mildly less awkward to use, and fixes one complexity issue.
2022-08-09 16:22:27 +02:00
4697a56760
Use cleaner paths when looking up thumbnails 2022-08-09 13:55:17 +02:00
2 changed files with 17 additions and 22 deletions

View File

@ -85,7 +85,7 @@ struct _FivBrowser {
Thumbnailer *thumbnailers; ///< Parallelized thumbnailers
size_t thumbnailers_len; ///< Thumbnailers array size
GList *thumbnailers_queue; ///< Queued up Entry pointers
GQueue thumbnailers_queue; ///< Queued up Entry pointers
GdkCursor *pointer; ///< Cached pointer cursor
cairo_pattern_t *glow; ///< CAIRO_FORMAT_A8 mask for corners
@ -597,10 +597,7 @@ thumbnailer_reprocess_entry(FivBrowser *self, GBytes *output, Entry *entry)
if ((flags & FIV_IO_SERIALIZE_LOW_QUALITY)) {
cairo_surface_set_user_data(entry->thumbnail, &fiv_thumbnail_key_lq,
(void *) (intptr_t) 1, NULL);
// TODO(p): Improve complexity; this will iterate the whole linked list.
self->thumbnailers_queue =
g_list_append(self->thumbnailers_queue, entry);
g_queue_push_tail(&self->thumbnailers_queue, entry);
}
// This choice of mtime favours unnecessary thumbnail reloading
@ -663,14 +660,9 @@ thumbnailer_next(Thumbnailer *t)
{
// TODO(p): Try to keep the minions alive (stdout will be a problem).
FivBrowser *self = t->self;
GList *link = self->thumbnailers_queue;
if (!link)
if (!(t->target = g_queue_pop_head(&self->thumbnailers_queue)))
return FALSE;
t->target = link->data;
self->thumbnailers_queue =
g_list_delete_link(self->thumbnailers_queue, self->thumbnailers_queue);
// Case analysis:
// - We haven't found any thumbnail for the entry at all
// (and it has a symbolic icon as a result):
@ -706,8 +698,7 @@ thumbnailer_next(Thumbnailer *t)
static void
thumbnailers_abort(FivBrowser *self)
{
g_list_free(self->thumbnailers_queue);
self->thumbnailers_queue = NULL;
g_queue_clear(&self->thumbnailers_queue);
for (size_t i = 0; i < self->thumbnailers_len; i++) {
Thumbnailer *t = self->thumbnailers + i;
@ -729,17 +720,20 @@ thumbnailers_start(FivBrowser *self)
if (!self->model)
return;
GList *missing = NULL, *lq = NULL;
for (guint i = self->entries->len; i--; ) {
GQueue lq = G_QUEUE_INIT;
for (guint i = 0; i < self->entries->len; i++) {
Entry *entry = &g_array_index(self->entries, Entry, i);
if (entry->icon)
missing = g_list_prepend(missing, entry);
g_queue_push_tail(&self->thumbnailers_queue, entry);
else if (cairo_surface_get_user_data(
entry->thumbnail, &fiv_thumbnail_key_lq))
lq = g_list_prepend(lq, entry);
g_queue_push_tail(&lq, entry);
}
while (!g_queue_is_empty(&lq)) {
g_queue_push_tail_link(
&self->thumbnailers_queue, g_queue_pop_head_link(&lq));
}
self->thumbnailers_queue = g_list_concat(missing, lq);
for (size_t i = 0; i < self->thumbnailers_len; i++) {
if (!thumbnailer_next(self->thumbnailers + i))
break;
@ -1706,6 +1700,7 @@ fiv_browser_init(FivBrowser *self)
g_malloc0_n(self->thumbnailers_len, sizeof *self->thumbnailers);
for (size_t i = 0; i < self->thumbnailers_len; i++)
self->thumbnailers[i].self = self;
g_queue_init(&self->thumbnailers_queue);
set_item_size(self, FIV_THUMBNAIL_SIZE_NORMAL);
self->glow_padded = cairo_pattern_create_rgba(0, 0, 0, 0);

View File

@ -657,8 +657,8 @@ fiv_thumbnail_lookup(const char *uri, gint64 mtime_msec, FivThumbnailSize size)
use = FIV_THUMBNAIL_SIZE_MAX - i;
const char *name = fiv_thumbnail_sizes[use].thumbnail_spec_name;
gchar *wide =
g_strdup_printf("%s/wide-%s/%s.webp", thumbnails_dir, name, sum);
gchar *wide = g_strconcat(thumbnails_dir, G_DIR_SEPARATOR_S "wide-",
name, G_DIR_SEPARATOR_S, sum, ".webp", NULL);
result = read_wide_thumbnail(wide, uri, mtime_msec / 1000, &error);
if (error) {
g_debug("%s: %s", wide, error->message);
@ -673,8 +673,8 @@ fiv_thumbnail_lookup(const char *uri, gint64 mtime_msec, FivThumbnailSize size)
break;
}
gchar *path =
g_strdup_printf("%s/%s/%s.png", thumbnails_dir, name, sum);
gchar *path = g_strconcat(thumbnails_dir, G_DIR_SEPARATOR_S,
name, G_DIR_SEPARATOR_S, sum, ".png", NULL);
result = read_png_thumbnail(path, uri, mtime_msec / 1000, &error);
if (error) {
g_debug("%s: %s", path, error->message);