forked from bartvdbraak/blender
Ensure mat/tex/etc. previews are generated/saved in .blend files when enabled in userprefs.
Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D970
This commit is contained in:
parent
3f05797333
commit
820b6b3731
@ -72,6 +72,7 @@ void ED_preview_init_dbase(void);
|
|||||||
void ED_preview_free_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_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_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);
|
void ED_preview_kill_jobs(struct wmWindowManager *wm, struct Main *bmain);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#define __UI_INTERFACE_ICONS_H__
|
#define __UI_INTERFACE_ICONS_H__
|
||||||
|
|
||||||
struct bContext;
|
struct bContext;
|
||||||
|
struct ID;
|
||||||
struct Image;
|
struct Image;
|
||||||
struct ImBuf;
|
struct ImBuf;
|
||||||
struct World;
|
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_width(int icon_id);
|
||||||
int UI_icon_get_height(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(float x, float y, int icon_id);
|
||||||
void UI_icon_draw_preview(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);
|
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect);
|
||||||
|
@ -931,7 +931,7 @@ static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
|
|||||||
|
|
||||||
/* only called when icon has changed */
|
/* only called when icon has changed */
|
||||||
/* only call with valid pointer from UI_icon_draw */
|
/* 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 (!prv_img) {
|
||||||
if (G.debug & G_DEBUG)
|
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);
|
icon_create_rect(prv_img, size);
|
||||||
|
|
||||||
ED_preview_icon_job(C, prv_img, id, prv_img->rect[size],
|
if (use_job) {
|
||||||
prv_img->w[size], prv_img->h[size]);
|
/* 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)
|
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 */
|
if ((pi->changed[size] || !pi->rect[size])) { /* changed only ever set by dynamic icons */
|
||||||
/* create the rect if necessary */
|
/* 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;
|
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);
|
PreviewImage *pi = BKE_previewimg_get(id);
|
||||||
|
|
||||||
if (pi) {
|
if (pi) {
|
||||||
if (big)
|
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
|
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
|
/* check if rect needs to be created; changed
|
||||||
* only set by dynamic icons */
|
* only set by dynamic icons */
|
||||||
if ((pi->changed[i] || !pi->rect[i])) {
|
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;
|
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 */
|
case ID_LA: /* fall through */
|
||||||
iconid = BKE_icon_getid(id);
|
iconid = BKE_icon_getid(id);
|
||||||
/* checks if not exists, or changed */
|
/* checks if not exists, or changed */
|
||||||
ui_id_icon_render(C, id, big);
|
UI_id_icon_render(C, id, big, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1098,6 +1098,26 @@ static void icon_preview_free(void *customdata)
|
|||||||
MEM_freeN(ip);
|
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)
|
void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *rect, int sizex, int sizey)
|
||||||
{
|
{
|
||||||
wmJob *wm_job;
|
wmJob *wm_job;
|
||||||
|
@ -101,6 +101,7 @@
|
|||||||
#include "GHOST_Path-api.h"
|
#include "GHOST_Path-api.h"
|
||||||
|
|
||||||
#include "UI_interface.h"
|
#include "UI_interface.h"
|
||||||
|
#include "UI_interface_icons.h"
|
||||||
#include "UI_view2d.h"
|
#include "UI_view2d.h"
|
||||||
|
|
||||||
#include "GPU_draw.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.
|
* \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) */
|
/* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */
|
||||||
if ((U.flag & USER_SAVE_PREVIEWS) && BLI_thread_is_main()) {
|
if ((U.flag & USER_SAVE_PREVIEWS) && BLI_thread_is_main()) {
|
||||||
ibuf_thumb = blend_file_thumb(CTX_data_scene(C), CTX_wm_screen(C), &thumb);
|
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);
|
BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);
|
||||||
|
Loading…
Reference in New Issue
Block a user