From d552b3c0c01cac7f64a2864a0c2ada4b56ffdaf8 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 20 Jan 2022 18:21:57 +0100 Subject: Fix file/asset thumbnails causing constant stream of notifiers The thumbnail caching continuously sends `ND_SPACE_FILE_PREVIEW` notifiers via a timer. But this timer was never ended properly after thumbnails are fully loaded into the cache. Wouldn't actually cause a refresh or redraw, send and process the notifiers. I already tried to avoid this for the asset view template, but apparently that wasn't working correctly. For the File/Asset Browser I never applied that fix to avoid possible regressions before the release. --- source/blender/editors/space_file/file_draw.c | 3 ++- source/blender/editors/space_file/filelist.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 9f18f6d1443..14c786e5dea 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -906,7 +906,8 @@ void file_draw_list(const bContext *C, ARegion *region) * since it's filelist_file_cache_block() and filelist_cache_previews_update() * which controls previews task. */ { - const bool previews_running = filelist_cache_previews_running(files); + const bool previews_running = filelist_cache_previews_running(files) && + !filelist_cache_previews_done(files); // printf("%s: preview task: %d\n", __func__, previews_running); if (previews_running && !sfile->previews_timer) { sfile->previews_timer = WM_event_add_timer_notifier( diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index b5eb7905fd8..2d31e8030a4 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -339,7 +339,10 @@ typedef struct FileListEntryCache { /* Previews handling. */ TaskPool *previews_pool; ThreadQueue *previews_done; - size_t previews_todo_count; + /** Counter for previews that are not fully loaded and ready to display yet. So includes all + * previews either in `previews_pool` or `previews_done`. #filelist_cache_previews_update() makes + * previews in `preview_done` ready for display, so the counter is decremented there. */ + int previews_todo_count; } FileListEntryCache; /* FileListCache.flags */ @@ -1647,7 +1650,6 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat preview_taskdata->preview = NULL; BLI_thread_queue_push(cache->previews_done, preview); - atomic_fetch_and_sub_z(&cache->previews_todo_count, 1); // printf("%s: End (%d)...\n", __func__, threadid); } @@ -1689,6 +1691,7 @@ static void filelist_cache_previews_clear(FileListEntryCache *cache) } MEM_freeN(preview); } + cache->previews_todo_count = 0; } } @@ -1759,7 +1762,6 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry preview->icon_id = BKE_icon_imbuf_create(imbuf); } BLI_thread_queue_push(cache->previews_done, preview); - atomic_fetch_and_sub_z(&cache->previews_todo_count, 1); } else { if (entry->redirection_path) { @@ -1780,6 +1782,7 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry true, filelist_cache_preview_freef); } + cache->previews_todo_count++; } static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size) @@ -2693,6 +2696,7 @@ bool filelist_cache_previews_update(FileList *filelist) } MEM_freeN(preview); + cache->previews_todo_count--; } return changed; @@ -2714,7 +2718,7 @@ bool filelist_cache_previews_done(FileList *filelist) } return (cache->previews_pool == NULL) || (cache->previews_done == NULL) || - (cache->previews_todo_count == (size_t)BLI_thread_queue_len(cache->previews_done)); + (cache->previews_todo_count == 0); } /* would recognize .blend as well */ -- cgit v1.2.3