diff options
author | Julian Eisel <julian@blender.org> | 2020-12-14 15:21:58 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-12-15 19:03:45 +0300 |
commit | 9363132c8601ebca6d89168e09bb10f81d6cb03a (patch) | |
tree | 59afa11ef38f56060f1d4c7a35bf23adab31424d /source/blender/editors/render | |
parent | c25e0310497f5228bd04992d6bcd84481d0b0c5b (diff) |
Asset System: Various changes to previews in preparation for Asset Browser
* Support defining (not necessarily rendering) icons in threads. Needed so the
File Browser can expose file previews with an icon-id to scripts.
** For that, ported `icons.c` to C++, to be able to use scope based mutex locks
(cleaner & safer code). Had to do some cleanups and minor refactoring for
that.
* Added support for ImBuf icons, as a decent way for icons to hold the file
preview buffers.
* Tag previews as "unfinished" while they render in a thread, for the File
Browser to dynamically load previews as they get finished.
* Better handle cases where threaded preview generation is requested, but the
ID type doesn't support it (fallback to single threaded). This is for general
sanity of the code (as in, safety and cleanness)
* Enabled asset notifier for custom preview loading operator, was just disabled
because `NC_ASSET` wasn't defined in master yet.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9719
Reviewed by: Bastien Montagne, Brecht Van Lommel
Diffstat (limited to 'source/blender/editors/render')
-rw-r--r-- | source/blender/editors/render/render_preview.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 3c103f28d93..579fd86077e 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, const 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) { @@ -1374,6 +1376,24 @@ static void other_id_types_preview_render(IconPreview *ip, shader_preview_free(sp); } +/* exported functions */ + +/** + * Find the index to map \a icon_size to data in \a preview_image. + */ +static int icon_previewimg_size_index_get(const IconPreviewSize *icon_size, + const PreviewImage *preview_image) +{ + for (int i = 0; i < NUM_ICON_SIZES; i++) { + if ((preview_image->w[i] == icon_size->sizex) && (preview_image->h[i] == icon_size->sizey)) { + return i; + } + } + + BLI_assert(!"The searched icon size does not match any in the preview image"); + return -1; +} + static void icon_preview_startjob_all_sizes(void *customdata, short *stop, short *do_update, @@ -1398,6 +1418,13 @@ static void icon_preview_startjob_all_sizes(void *customdata, continue; } +#ifndef NDEBUG + { + int size_index = icon_previewimg_size_index_get(cur_size, prv); + BLI_assert(!BKE_previewimg_is_finished(prv, size_index)); + } +#endif + if (ip->id && ELEM(GS(ip->id->name), ID_OB)) { /* Much simpler than the ShaderPreview mess used for other ID types. */ object_preview_render(ip, cur_size); @@ -1460,6 +1487,12 @@ static void icon_preview_endjob(void *customdata) if (ip->owner) { PreviewImage *prv_img = ip->owner; prv_img->tag &= ~PRV_TAG_DEFFERED_RENDERING; + + LISTBASE_FOREACH (IconPreviewSize *, icon_size, &ip->sizes) { + int size_index = icon_previewimg_size_index_get(icon_size, prv_img); + BKE_previewimg_finish(prv_img, size_index); + } + if (prv_img->tag & PRV_TAG_DEFFERED_DELETE) { BLI_assert(prv_img->tag & PRV_TAG_DEFFERED); BKE_previewimg_deferred_release(prv_img); @@ -1576,6 +1609,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. */ |