[Bf-blender-cvs] [9e3f86e34a6] asset-browser: Fall back to single threaded preview creation if ID can't do it thread-safe

Julian Eisel noreply at git.blender.org
Sat Nov 14 00:35:21 CET 2020


Commit: 9e3f86e34a66a46bc3c3e01e639a90748526ac92
Author: Julian Eisel
Date:   Fri Nov 13 18:21:36 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB9e3f86e34a66a46bc3c3e01e639a90748526ac92

Fall back to single threaded preview creation if ID can't do it thread-safe

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

M	source/blender/blenkernel/BKE_icons.h
M	source/blender/blenkernel/intern/icons.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/render/render_preview.c

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

diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
index 7a34d4557b8..7b418dc288a 100644
--- a/source/blender/blenkernel/BKE_icons.h
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -131,6 +131,8 @@ void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size)
 struct PreviewImage **BKE_previewimg_id_get_p(const struct ID *id);
 struct PreviewImage *BKE_previewimg_id_get(const struct ID *id);
 
+bool BKE_previewimg_id_supports_jobs(const struct ID *id);
+
 /* free the preview image belonging to the id */
 void BKE_previewimg_id_free(struct ID *id);
 
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 9f6bbb4fbb7..aa03b22b443 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -370,6 +370,11 @@ PreviewImage *BKE_previewimg_id_ensure(ID *id)
   return NULL;
 }
 
+bool BKE_previewimg_id_supports_jobs(const ID *id)
+{
+  return ELEM(GS(id->name), ID_OB, ID_MA, ID_TE, ID_LA, ID_WO, ID_IM, ID_BR);
+}
+
 PreviewImage *BKE_previewimg_cached_get(const char *name)
 {
   return BLI_ghash_lookup(gCachedPreviews, name);
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index f52d05daff4..8220e1b17a0 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1384,8 +1384,12 @@ void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool bi
   }
 }
 
-/* only called when icon has changed */
-/* only call with valid pointer from UI_icon_draw */
+/**
+ * * Only call with valid pointer from UI_icon_draw.
+ * * Only called when icon has changed.
+ *
+ * Note that if an ID doesn't support jobs for preview creation, \a use_job will be ignored.
+ */
 static void icon_set_image(const bContext *C,
                            Scene *scene,
                            ID *id,
@@ -1408,7 +1412,7 @@ static void icon_set_image(const bContext *C,
   const bool delay = prv_img->rect[size] != NULL;
   icon_create_rect(prv_img, size);
 
-  if (use_job) {
+  if (use_job && BKE_previewimg_id_supports_jobs(id)) {
     /* Job (background) version */
     ED_preview_icon_job(
         C, prv_img, id, prv_img->rect[size], prv_img->w[size], prv_img->h[size], delay);
@@ -1937,6 +1941,9 @@ static void ui_id_preview_image_render_size(
   }
 }
 
+/**
+ * Note that if an ID doesn't support jobs for preview creation, \a use_job will be ignored.
+ */
 void UI_icon_render_id(const bContext *C, Scene *scene, ID *id, const bool big, const bool use_job)
 {
   PreviewImage *pi = BKE_previewimg_id_ensure(id);
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index 3ad8fcb4f3d..64194a5ddd2 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -354,13 +354,15 @@ static ID *duplicate_ids(ID *id, bool allow_failure)
     case ID_TE:
     case ID_LA:
     case ID_WO: {
+      BLI_assert(BKE_previewimg_id_supports_jobs(id));
       ID *id_copy = BKE_id_copy_ex(
           NULL, id, NULL, LIB_ID_CREATE_LOCAL | LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
       return id_copy;
     }
+    /* These support threading, but don't need duplicating. */
     case ID_IM:
     case ID_BR:
-    case ID_SCR:
+      BLI_assert(BKE_previewimg_id_supports_jobs(id));
       return NULL;
     default:
       if (!allow_failure) {
@@ -1557,6 +1559,8 @@ void ED_preview_shader_job(const bContext *C,
   Scene *scene = CTX_data_scene(C);
   short id_type = GS(id->name);
 
+  BLI_assert(BKE_previewimg_id_supports_jobs(id));
+
   /* Use workspace render only for buttons Window,
    * since the other previews are related to the datablock. */



More information about the Bf-blender-cvs mailing list