diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h index 0227ae3e85a..32fa641e3ae 100644 --- a/source/blender/editors/include/ED_render.h +++ b/source/blender/editors/include/ED_render.h @@ -72,6 +72,7 @@ void ED_preview_init_dbase(void); void ED_preview_free_dbase(void); void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, struct ID *parent, struct MTex *slot, int sizex, int sizey, int method); +void ED_preview_icon_render(const struct bContext *C, void *owner, struct ID *id, unsigned int *rect, int sizex, int sizey); void ED_preview_icon_job(const struct bContext *C, void *owner, struct ID *id, unsigned int *rect, int sizex, int sizey); void ED_preview_kill_jobs(struct wmWindowManager *wm, struct Main *bmain); diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h index 6104505ef58..2ba3d309aa7 100644 --- a/source/blender/editors/include/UI_interface_icons.h +++ b/source/blender/editors/include/UI_interface_icons.h @@ -33,6 +33,7 @@ #define __UI_INTERFACE_ICONS_H__ struct bContext; +struct ID; struct Image; struct ImBuf; struct World; @@ -63,6 +64,8 @@ void UI_icons_init(int first_dyn_id); int UI_icon_get_width(int icon_id); int UI_icon_get_height(int icon_id); +void UI_id_icon_render(const struct bContext *C, struct ID *id, const bool big, const bool use_job); + void UI_icon_draw(float x, float y, int icon_id); void UI_icon_draw_preview(float x, float y, int icon_id); void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index cb5a26b1be3..bebc515df8e 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -931,7 +931,7 @@ static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size) /* only called when icon has changed */ /* only call with valid pointer from UI_icon_draw */ -static void icon_set_image(const bContext *C, ID *id, PreviewImage *prv_img, enum eIconSizes size) +static void icon_set_image(const bContext *C, ID *id, PreviewImage *prv_img, enum eIconSizes size, const bool use_job) { if (!prv_img) { if (G.debug & G_DEBUG) @@ -941,8 +941,14 @@ static void icon_set_image(const bContext *C, ID *id, PreviewImage *prv_img, enu icon_create_rect(prv_img, size); - ED_preview_icon_job(C, prv_img, id, prv_img->rect[size], - prv_img->w[size], prv_img->h[size]); + if (use_job) { + /* Job (background) version */ + ED_preview_icon_job(C, prv_img, id, prv_img->rect[size], prv_img->w[size], prv_img->h[size]); + } + else { + /* Immediate version */ + ED_preview_icon_render(C, prv_img, id, prv_img->rect[size], prv_img->w[size], prv_img->h[size]); + } } PreviewImage *UI_icon_to_preview(int icon_id) @@ -1149,25 +1155,25 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al } } -static void ui_id_preview_image_render_size(const bContext *C, ID *id, PreviewImage *pi, int size) +static void ui_id_preview_image_render_size(const bContext *C, ID *id, PreviewImage *pi, int size, const bool use_job) { if ((pi->changed[size] || !pi->rect[size])) { /* changed only ever set by dynamic icons */ /* create the rect if necessary */ - icon_set_image(C, id, pi, size); + icon_set_image(C, id, pi, size, use_job); pi->changed[size] = 0; } } -static void ui_id_icon_render(const bContext *C, ID *id, const bool big) +void UI_id_icon_render(const bContext *C, ID *id, const bool big, const bool use_job) { PreviewImage *pi = BKE_previewimg_get(id); if (pi) { if (big) - ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW); /* bigger preview size */ + ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW, use_job); /* bigger preview size */ else - ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON); /* icon size */ + ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON, use_job); /* icon size */ } } @@ -1183,7 +1189,7 @@ static void ui_id_brush_render(const bContext *C, ID *id) /* check if rect needs to be created; changed * only set by dynamic icons */ if ((pi->changed[i] || !pi->rect[i])) { - icon_set_image(C, id, pi, i); + icon_set_image(C, id, pi, i, false); pi->changed[i] = 0; } } @@ -1259,7 +1265,7 @@ int ui_id_icon_get(const bContext *C, ID *id, const bool big) case ID_LA: /* fall through */ iconid = BKE_icon_getid(id); /* checks if not exists, or changed */ - ui_id_icon_render(C, id, big); + UI_id_icon_render(C, id, big, true); break; default: break; diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index b36e4e22f01..8833d76fde2 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -1098,6 +1098,26 @@ static void icon_preview_free(void *customdata) MEM_freeN(ip); } +void ED_preview_icon_render(const bContext *C, void *UNUSED(owner), ID *id, unsigned int *rect, int sizex, int sizey) +{ + IconPreview ip = {0}; + short stop = false, update = false; + float progress = 0.0f; + + /* customdata for preview thread */ + ip.scene = CTX_data_scene(C); + ip.owner = id; + ip.id = id; + + icon_preview_add_size(&ip, rect, sizex, sizey); + + icon_preview_startjob_all_sizes(&ip, &stop, &update, &progress); + + icon_preview_endjob(&ip); + + BLI_freelistN(&ip.sizes); +} + void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *rect, int sizex, int sizey) { wmJob *wm_job; diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index c1c31f6795d..622e86a8e02 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -101,6 +101,7 @@ #include "GHOST_Path-api.h" #include "UI_interface.h" +#include "UI_interface_icons.h" #include "UI_view2d.h" #include "GPU_draw.h" @@ -894,6 +895,23 @@ bool write_crash_blend(void) } } +static void wm_ensure_previews(bContext *C, Main *mainvar) +{ + ListBase *lb[] = {&mainvar->mat, &mainvar->tex, &mainvar->image, &mainvar->world, &mainvar->lamp, NULL}; + ID *id; + int i; + + for (i = 0; lb[i]; i++) { + for (id = lb[i]->first; id; id = id->next) { + /* Only preview non-library datablocks, lib ones do not pertain to this .blend file! */ + if (!id->lib) { + UI_id_icon_render(C, id, false, false); + UI_id_icon_render(C, id, true, false); + } + } + } +} + /** * \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way. */ @@ -938,6 +956,8 @@ int wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList * /* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */ if ((U.flag & USER_SAVE_PREVIEWS) && BLI_thread_is_main()) { ibuf_thumb = blend_file_thumb(CTX_data_scene(C), CTX_wm_screen(C), &thumb); + + wm_ensure_previews(C, G.main); } BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);