Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-11-24 13:20:35 +0300
committerJulian Eisel <julian@blender.org>2021-11-24 13:20:35 +0300
commitcd818fd081f54dbb33ca8f994dd4d127ae79f883 (patch)
treed9dd442ba9b4257c5150b666eba97ed300b88f82 /source/blender/editors/render/render_preview.c
parent785503a7e4d12fce8cab2b7d99456f40b2c3b1e2 (diff)
Assets: Sanitize threaded preview creation with undo
Basically, this fixes disappearing previews when editing asset metadata or performing undo/redo actions. The preview generation in a background job will eventually modify ID data, but the undo push was done prior to that. So obviously, an undo then would mean the preview is lost. This patch makes it so undo/redo will regenerate the preview, if the preview rendering was invoked but not finished in the undone/redone state. The preview flag PRV_UNFINISHED wasn't entirely what we needed. So I had to change it to a slightly different flag, with different semantics.
Diffstat (limited to 'source/blender/editors/render/render_preview.c')
-rw-r--r--source/blender/editors/render/render_preview.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index 0cc944436b2..25353dc30fe 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -103,6 +103,8 @@
#include "ED_view3d.h"
#include "ED_view3d_offscreen.h"
+#include "UI_interface_icons.h"
+
#ifndef NDEBUG
/* Used for database init assert(). */
# include "BLI_threads.h"
@@ -1948,4 +1950,45 @@ void ED_preview_kill_jobs(wmWindowManager *wm, Main *UNUSED(bmain))
}
}
+typedef struct PreviewRestartQueueEntry {
+ struct PreviewRestartQueueEntry *next, *prev;
+
+ enum eIconSizes size;
+ ID *id;
+} PreviewRestartQueueEntry;
+
+static ListBase /* #PreviewRestartQueueEntry */ G_restart_previews_queue;
+
+void ED_preview_restart_queue_free(void)
+{
+ BLI_freelistN(&G_restart_previews_queue);
+}
+
+void ED_preview_restart_queue_add(ID *id, enum eIconSizes size)
+{
+ PreviewRestartQueueEntry *queue_entry = MEM_mallocN(sizeof(*queue_entry), __func__);
+ queue_entry->size = size;
+ queue_entry->id = id;
+ BLI_addtail(&G_restart_previews_queue, queue_entry);
+}
+
+void ED_preview_restart_queue_work(const bContext *C)
+{
+ LISTBASE_FOREACH_MUTABLE (PreviewRestartQueueEntry *, queue_entry, &G_restart_previews_queue) {
+ PreviewImage *preview = BKE_previewimg_id_get(queue_entry->id);
+ if (!preview) {
+ continue;
+ }
+ if (preview->flag[queue_entry->size] & PRV_USER_EDITED) {
+ /* Don't touch custom previews. */
+ continue;
+ }
+
+ BKE_previewimg_clear_single(preview, queue_entry->size);
+ UI_icon_render_id(C, NULL, queue_entry->id, queue_entry->size, true);
+
+ BLI_freelinkN(&G_restart_previews_queue, queue_entry);
+ }
+}
+
/** \} */