Parallelize thumbnail loading
GLib makes this easy. They should all be local, and fast to access, so the CPU is the limit.
This commit is contained in:
parent
972bd80fa5
commit
3299cbf825
@ -561,6 +561,14 @@ rescale_thumbnail(cairo_surface_t *thumbnail)
|
|||||||
return scaled;
|
return scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
entry_add_thumbnail(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
||||||
|
{
|
||||||
|
Entry *self = data;
|
||||||
|
self->thumbnail =
|
||||||
|
rescale_thumbnail(fastiv_io_lookup_thumbnail(self->filename));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fastiv_browser_load(FastivBrowser *self, const char *path)
|
fastiv_browser_load(FastivBrowser *self, const char *path)
|
||||||
{
|
{
|
||||||
@ -577,15 +585,17 @@ fastiv_browser_load(FastivBrowser *self, const char *path)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
gchar *subpath = g_build_filename(path, filename, NULL);
|
gchar *subpath = g_build_filename(path, filename, NULL);
|
||||||
g_array_append_val(self->entries,
|
g_array_append_val(
|
||||||
((Entry){
|
self->entries, ((Entry) {.thumbnail = NULL, .filename = subpath}));
|
||||||
.thumbnail =
|
|
||||||
rescale_thumbnail(fastiv_io_lookup_thumbnail(subpath)),
|
|
||||||
.filename = subpath,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
g_dir_close(dir);
|
g_dir_close(dir);
|
||||||
|
|
||||||
|
GThreadPool *pool = g_thread_pool_new(
|
||||||
|
entry_add_thumbnail, NULL, g_get_num_processors(), FALSE, NULL);
|
||||||
|
for (guint i = 0; i < self->entries->len; i++)
|
||||||
|
g_thread_pool_push(pool, &g_array_index(self->entries, Entry, i), NULL);
|
||||||
|
g_thread_pool_free(pool, FALSE, TRUE);
|
||||||
|
|
||||||
// TODO(p): Sort the entries.
|
// TODO(p): Sort the entries.
|
||||||
gtk_widget_queue_resize(GTK_WIDGET(self));
|
gtk_widget_queue_resize(GTK_WIDGET(self));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user