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 Thumbnailer *thumbnailers; ///< Parallelized thumbnailers
size_t thumbnailers_len; ///< Thumbnailers array size 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 GdkCursor *pointer; ///< Cached pointer cursor
cairo_pattern_t *glow; ///< CAIRO_FORMAT_A8 mask for corners 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)) { if ((flags & FIV_IO_SERIALIZE_LOW_QUALITY)) {
cairo_surface_set_user_data(entry->thumbnail, &fiv_thumbnail_key_lq, cairo_surface_set_user_data(entry->thumbnail, &fiv_thumbnail_key_lq,
(void *) (intptr_t) 1, NULL); (void *) (intptr_t) 1, NULL);
g_queue_push_tail(&self->thumbnailers_queue, entry);
// TODO(p): Improve complexity; this will iterate the whole linked list.
self->thumbnailers_queue =
g_list_append(self->thumbnailers_queue, entry);
} }
// This choice of mtime favours unnecessary thumbnail reloading // 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). // TODO(p): Try to keep the minions alive (stdout will be a problem).
FivBrowser *self = t->self; FivBrowser *self = t->self;
GList *link = self->thumbnailers_queue; if (!(t->target = g_queue_pop_head(&self->thumbnailers_queue)))
if (!link)
return FALSE; return FALSE;
t->target = link->data;
self->thumbnailers_queue =
g_list_delete_link(self->thumbnailers_queue, self->thumbnailers_queue);
// Case analysis: // Case analysis:
// - We haven't found any thumbnail for the entry at all // - We haven't found any thumbnail for the entry at all
// (and it has a symbolic icon as a result): // (and it has a symbolic icon as a result):
@ -706,8 +698,7 @@ thumbnailer_next(Thumbnailer *t)
static void static void
thumbnailers_abort(FivBrowser *self) thumbnailers_abort(FivBrowser *self)
{ {
g_list_free(self->thumbnailers_queue); g_queue_clear(&self->thumbnailers_queue);
self->thumbnailers_queue = NULL;
for (size_t i = 0; i < self->thumbnailers_len; i++) { for (size_t i = 0; i < self->thumbnailers_len; i++) {
Thumbnailer *t = self->thumbnailers + i; Thumbnailer *t = self->thumbnailers + i;
@ -729,17 +720,20 @@ thumbnailers_start(FivBrowser *self)
if (!self->model) if (!self->model)
return; return;
GList *missing = NULL, *lq = NULL; GQueue lq = G_QUEUE_INIT;
for (guint i = self->entries->len; i--; ) { for (guint i = 0; i < self->entries->len; i++) {
Entry *entry = &g_array_index(self->entries, Entry, i); Entry *entry = &g_array_index(self->entries, Entry, i);
if (entry->icon) if (entry->icon)
missing = g_list_prepend(missing, entry); g_queue_push_tail(&self->thumbnailers_queue, entry);
else if (cairo_surface_get_user_data( else if (cairo_surface_get_user_data(
entry->thumbnail, &fiv_thumbnail_key_lq)) 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++) { for (size_t i = 0; i < self->thumbnailers_len; i++) {
if (!thumbnailer_next(self->thumbnailers + i)) if (!thumbnailer_next(self->thumbnailers + i))
break; break;
@ -1706,6 +1700,7 @@ fiv_browser_init(FivBrowser *self)
g_malloc0_n(self->thumbnailers_len, sizeof *self->thumbnailers); g_malloc0_n(self->thumbnailers_len, sizeof *self->thumbnailers);
for (size_t i = 0; i < self->thumbnailers_len; i++) for (size_t i = 0; i < self->thumbnailers_len; i++)
self->thumbnailers[i].self = self; self->thumbnailers[i].self = self;
g_queue_init(&self->thumbnailers_queue);
set_item_size(self, FIV_THUMBNAIL_SIZE_NORMAL); set_item_size(self, FIV_THUMBNAIL_SIZE_NORMAL);
self->glow_padded = cairo_pattern_create_rgba(0, 0, 0, 0); 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; use = FIV_THUMBNAIL_SIZE_MAX - i;
const char *name = fiv_thumbnail_sizes[use].thumbnail_spec_name; const char *name = fiv_thumbnail_sizes[use].thumbnail_spec_name;
gchar *wide = gchar *wide = g_strconcat(thumbnails_dir, G_DIR_SEPARATOR_S "wide-",
g_strdup_printf("%s/wide-%s/%s.webp", thumbnails_dir, name, sum); name, G_DIR_SEPARATOR_S, sum, ".webp", NULL);
result = read_wide_thumbnail(wide, uri, mtime_msec / 1000, &error); result = read_wide_thumbnail(wide, uri, mtime_msec / 1000, &error);
if (error) { if (error) {
g_debug("%s: %s", wide, error->message); g_debug("%s: %s", wide, error->message);
@ -673,8 +673,8 @@ fiv_thumbnail_lookup(const char *uri, gint64 mtime_msec, FivThumbnailSize size)
break; break;
} }
gchar *path = gchar *path = g_strconcat(thumbnails_dir, G_DIR_SEPARATOR_S,
g_strdup_printf("%s/%s/%s.png", thumbnails_dir, name, sum); name, G_DIR_SEPARATOR_S, sum, ".png", NULL);
result = read_png_thumbnail(path, uri, mtime_msec / 1000, &error); result = read_png_thumbnail(path, uri, mtime_msec / 1000, &error);
if (error) { if (error) {
g_debug("%s: %s", path, error->message); g_debug("%s: %s", path, error->message);