[Bf-blender-cvs] [80469a7675a] asset-browser-poselib: Prevent preview loading from triggering continuous redraws

Julian Eisel noreply at git.blender.org
Wed Mar 31 13:10:02 CEST 2021


Commit: 80469a7675af80e82a6815bc13f7cdfb06275f50
Author: Julian Eisel
Date:   Wed Mar 31 13:05:14 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rB80469a7675af80e82a6815bc13f7cdfb06275f50

Prevent preview loading from triggering continuous redraws

The preview rendering notifiers would be continuously sent, causing
continuous redraws. In the File Browser that also happens (and I don't
think it's intentionaly) although it causes refreshes there that don't
do much and there won't be redraws unless necessary. Correcting this may
cause issues, so better to do it separately.

Issue is that the previews were fetched using the BLI_task API, and a
timer was started to send notifiers continuously. But there was nothing
to check if the tasks were done, so that the timer could be stopped.

===================================================================

M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h

===================================================================

diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index 7c892f0b7dd..c2be9f6e2d9 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -278,7 +278,8 @@ void AssetList::ensurePreviewsJob(bContext *C)
   filelist_cache_previews_update(files);
 
   {
-    const bool previews_running = filelist_cache_previews_running(files);
+    const bool previews_running = filelist_cache_previews_running(files) &&
+                                  !filelist_cache_previews_done(files);
     if (previews_running) {
       previews_timer_.ensureRunning(C);
     }
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 76bfb34c809..8f4f1af3ba6 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -335,6 +335,7 @@ typedef struct FileListEntryCache {
   /* Previews handling. */
   TaskPool *previews_pool;
   ThreadQueue *previews_done;
+  size_t previews_todo_count;
 } FileListEntryCache;
 
 /* FileListCache.flags */
@@ -1529,6 +1530,7 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat
     /* That way task freeing function won't free th preview, since it does not own it anymore. */
     atomic_cas_ptr((void **)&preview_taskdata->preview, 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);
@@ -1555,6 +1557,7 @@ static void filelist_cache_preview_ensure_running(FileListEntryCache *cache)
   if (!cache->previews_pool) {
     cache->previews_pool = BLI_task_pool_create_background(cache, TASK_PRIORITY_LOW);
     cache->previews_done = BLI_thread_queue_init();
+    cache->previews_todo_count = 0;
 
     IMB_thumb_locks_acquire();
   }
@@ -1588,6 +1591,7 @@ static void filelist_cache_previews_free(FileListEntryCache *cache)
     BLI_task_pool_free(cache->previews_pool);
     cache->previews_pool = NULL;
     cache->previews_done = NULL;
+    cache->previews_todo_count = 0;
 
     IMB_thumb_locks_release();
   }
@@ -1631,6 +1635,7 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
                        preview_taskdata,
                        true,
                        filelist_cache_preview_freef);
+    atomic_fetch_and_add_z(&cache->previews_todo_count, 1);
   }
 }
 
@@ -1655,6 +1660,8 @@ static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size)
   cache->size = cache_size;
   cache->flags = FLC_IS_INIT;
 
+  cache->previews_todo_count = 0;
+
   /* We cannot translate from non-main thread, so init translated strings once from here. */
   IMB_thumb_ensure_translations();
 }
@@ -2392,7 +2399,8 @@ void filelist_cache_previews_set(FileList *filelist, const bool use_previews)
   if (use_previews && (filelist->flags & FL_IS_READY)) {
     cache->flags |= FLC_PREVIEWS_ACTIVE;
 
-    BLI_assert((cache->previews_pool == NULL) && (cache->previews_done == NULL));
+    BLI_assert((cache->previews_pool == NULL) && (cache->previews_done == NULL) &&
+               (cache->previews_todo_count == 0));
 
     //      printf("%s: Init Previews...\n", __func__);
 
@@ -2465,6 +2473,18 @@ bool filelist_cache_previews_running(FileList *filelist)
   return (cache->previews_pool != NULL);
 }
 
+bool filelist_cache_previews_done(FileList *filelist)
+{
+  FileListEntryCache *cache = &filelist->filelist_cache;
+  if ((cache->flags & FLC_PREVIEWS_ACTIVE) == 0) {
+    /* There are no previews. */
+    return false;
+  }
+
+  return (cache->previews_pool == NULL) || (cache->previews_done == NULL) ||
+         (cache->previews_todo_count == (size_t)BLI_thread_queue_len(cache->previews_done));
+}
+
 /* would recognize .blend as well */
 static bool file_is_blend_backup(const char *str)
 {
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index 403222f826f..bd1626b0879 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -150,6 +150,7 @@ int filelist_readjob_running(struct FileList *filelist, struct wmWindowManager *
 bool filelist_cache_previews_update(struct FileList *filelist);
 void filelist_cache_previews_set(struct FileList *filelist, const bool use_previews);
 bool filelist_cache_previews_running(struct FileList *filelist);
+bool filelist_cache_previews_done(struct FileList *filelist);
 
 #ifdef __cplusplus
 }



More information about the Bf-blender-cvs mailing list