Bugfix #25446 (and todo item)

The icons for materials were always lagging or not updating
at all. I also found it suspicious slow... 
It appeared that the icons now store a "mip level", where for
every change in Materials 2 render jobs for icons were started,
one for 32x32 pix, one for 96x96. The latter was cancelling out
the first job almost always.

Also made preview renders detect size, to set amount of tiles
to be rendered. Small icons use 1 part, larger previews 16 now.

All in all, behaves much smoother now! But, will also update
the thread Jobs manager to allow "delayed jobs" like for icons,
these are aggressively put as first in the jobs list.
This commit is contained in:
2011-01-02 19:46:32 +00:00
parent 5d6c76c6a3
commit 05cfe50436
4 changed files with 30 additions and 16 deletions

View File

@@ -85,7 +85,8 @@ void free_material(Material *ma)
BKE_free_animdata((ID *)ma);
BKE_previewimg_free(&ma->preview);
if(ma->preview)
BKE_previewimg_free(&ma->preview);
BKE_icon_delete((struct ID*)ma);
ma->id.icon_id = 0;
@@ -250,7 +251,7 @@ Material *localize_material(Material *ma)
if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview);
man->preview = NULL;
if(ma->nodetree) {
man->nodetree= ntreeLocalize(ma->nodetree);

View File

@@ -1957,7 +1957,7 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, const char *propname,
/************************* List Template **************************/
static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon)
static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int big)
{
ID *id= NULL;
int icon;
@@ -1978,7 +1978,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon)
/* get icon from ID */
if(id) {
icon= ui_id_icon_get(C, id, 1);
icon= ui_id_icon_get(C, id, big);
if(icon)
return icon;
@@ -2007,7 +2007,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
sub= uiLayoutRow(overlap, 0);
/* retrieve icon and name */
icon= list_item_icon_get(C, itemptr, rnaicon);
icon= list_item_icon_get(C, itemptr, rnaicon, 0);
if(icon == ICON_NULL || icon == ICON_DOT)
icon= 0;
@@ -2152,7 +2152,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
if(i == 9)
row= uiLayoutRow(col, 0);
icon= list_item_icon_get(C, &itemptr, rnaicon);
icon= list_item_icon_get(C, &itemptr, rnaicon, 1);
but= uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
@@ -2176,7 +2176,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
if(found) {
/* create button */
name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
icon= list_item_icon_get(C, &itemptr, rnaicon);
icon= list_item_icon_get(C, &itemptr, rnaicon, 0);
uiItemL(row, (name)? name: "", icon);
if(name)

View File

@@ -347,6 +347,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
sce= pr_main->scene.first;
if(sce) {
/* this flag tells render to not execute depsgraph or ipos etc */
sce->r.scemode |= R_PREVIEWBUTS;
/* set world always back, is used now */
@@ -358,9 +359,17 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
}
sce->r.color_mgt_flag = scene->r.color_mgt_flag;
/* prevent overhead for small renders and icons (32) */
if(id && sp->sizex < 40)
sce->r.xparts= sce->r.yparts= 1;
else
sce->r.xparts= sce->r.yparts= 4;
/* exception: don't color manage texture previews or icons */
if((id && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT;
if((id && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
sce->r.alphamode= R_ALPHAPREMUL;
else
@@ -380,7 +389,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
init_render_material(mat, 0, NULL); /* call that retrieves mode_l */
end_render_material(mat);
/* turn on raytracing if needed */
if(mat->mode_l & MA_RAYMIRROR)
sce->r.mode |= R_RAYTRACE;
@@ -601,7 +610,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r
sbuts->preview= 0;
ok= 0;
}
if(ok==0) {
ED_preview_shader_job(C, sa, id, parent, slot, newx, newy, PR_BUTS_RENDER);
}
@@ -937,7 +946,7 @@ static void shader_preview_draw(void *spv, RenderResult *UNUSED(rr), volatile st
static int shader_preview_break(void *spv)
{
ShaderPreview *sp= spv;
return *(sp->stop);
}
@@ -962,7 +971,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
short idtype= GS(id->name);
char name[32];
int sizex;
/* get the stuff from the builtin preview dbase */
sce= preview_prepare_scene(sp->scene, id, idtype, sp); // XXX sizex
if(sce==NULL) return;
@@ -1021,6 +1030,8 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
/* handle results */
if(sp->pr_method==PR_ICON_RENDER) {
char *rct= (char *)(sp->pr_rect + 32*16 + 16);
if(sp->pr_rect)
RE_ResultGet32(re, sp->pr_rect);
}
@@ -1231,7 +1242,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r
sp->pr_method= PR_ICON_RENDER;
sp->pr_rect= rect;
sp->id = id;
/* setup job */
WM_jobs_customdata(steve, sp, shader_preview_free);
WM_jobs_timer(steve, 0.1, NC_MATERIAL, NC_MATERIAL);

View File

@@ -283,6 +283,7 @@ void WM_jobs_start(wmWindowManager *wm, wmJob *steve)
if(steve->running) {
/* signal job to end and restart */
steve->stop= 1;
// printf("job started a running job, ending... %s\n", steve->name);
}
else {
if(steve->customdata && steve->startjob) {
@@ -304,10 +305,10 @@ void WM_jobs_start(wmWindowManager *wm, wmJob *steve)
steve->ready= 0;
steve->progress= 0.0;
// printf("job started: %s\n", steve->name);
BLI_init_threads(&steve->threads, do_job_thread, 1);
BLI_insert_thread(&steve->threads, steve);
// printf("job started: %s\n", steve->name);
}
/* restarted job has timer already */
@@ -431,8 +432,8 @@ void wm_jobs_timer(const bContext *C, wmWindowManager *wm, wmTimer *wt)
steve->run_customdata= NULL;
steve->run_free= NULL;
// if(steve->stop) printf("job stopped\n");
// else printf("job finished\n");
// if(steve->stop) printf("job ready but stopped %s\n", steve->name);
// else printf("job finished %s\n", steve->name);
steve->running= 0;
BLI_end_threads(&steve->threads);
@@ -444,6 +445,7 @@ void wm_jobs_timer(const bContext *C, wmWindowManager *wm, wmTimer *wt)
/* new job added for steve? */
if(steve->customdata) {
// printf("job restarted with new data %s\n", steve->name);
WM_jobs_start(wm, steve);
}
else {