diff options
author | Diego Borghetti <bdiego@gmail.com> | 2010-04-22 14:56:45 +0400 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2010-04-22 14:56:45 +0400 |
commit | a56b72fd82e5de17ad0f688857c31cf3a9623ea1 (patch) | |
tree | 496997dd98d65a3c14f70e7a8928870b6654b45a /source/blender/editors/interface | |
parent | c8c22d2cf65504443574961cea0ec1773c18735e (diff) |
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 8 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 80 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 36 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 15 |
6 files changed, 71 insertions, 74 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 1267a1c1737..d639b881fe6 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -230,7 +230,7 @@ static void ui_text_bounds_block(uiBlock *block, float offset) //int transopts= ui_translate_buttons(); //if(bt->type==TEX || bt->type==IDPOIN) transopts= 0; - j= BLF_width(bt->drawstr); + j= BLF_width(style->widget.uifont_id, bt->drawstr); if(j > i) i = j; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 8aeca23a188..c444ef253d5 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1165,7 +1165,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho uiStyleFontSet(fstyle); if (fstyle->kerning==1) /* for BLF_width */ - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); origstr= MEM_callocN(sizeof(char)*data->maxlen, "ui_textedit origstr"); @@ -1188,7 +1188,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho while (i > 0) { i--; - if (BLF_width(origstr+i) > (startx - x)*0.25) break; // 0.25 == scale factor for less sensitivity + if (BLF_width(fstyle->uifont_id, origstr+i) > (startx - x)*0.25) break; // 0.25 == scale factor for less sensitivity } but->ofs = i; but->pos = but->ofs; @@ -1200,7 +1200,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho but->pos= strlen(origstr)-but->ofs; /* XXX does not take zoom level into account */ - while (aspect*startx + aspect*BLF_width(origstr+but->ofs) > x) { + while (aspect*startx + aspect*BLF_width(fstyle->uifont_id, origstr+but->ofs) > x) { if (but->pos <= 0) break; but->pos--; origstr[but->pos+but->ofs] = 0; @@ -1210,7 +1210,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho } if (fstyle->kerning == 1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); MEM_freeN(origstr); } diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index ce3fe61b2f9..102b7e342b3 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -453,10 +453,10 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->fstyle.align= UI_STYLE_TEXT_CENTER; uiStyleFontSet(&data->fstyle); - h= BLF_height(data->lines[0]); + h= BLF_height(data->fstyle.uifont_id, data->lines[0]); for(a=0, fontw=0, fonth=0; a<data->totline; a++) { - w= BLF_width(data->lines[a]); + w= BLF_width(data->fstyle.uifont_id, data->lines[a]); fontw= MAX2(fontw, w); fonth += (a == 0)? h: h+5; } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index aaebdf5693a..e3317e5598f 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -147,34 +147,34 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str) uiStyleFontSet(fs); - height= BLF_height("2"); /* correct offset is on baseline, the j is below that */ + height= BLF_height(fs->uifont_id, "2"); /* correct offset is on baseline, the j is below that */ yofs= floor( 0.5f*(rect->ymax - rect->ymin - height)); if(fs->align==UI_STYLE_TEXT_CENTER) - xofs= floor( 0.5f*(rect->xmax - rect->xmin - BLF_width(str))); + xofs= floor( 0.5f*(rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str))); else if(fs->align==UI_STYLE_TEXT_RIGHT) - xofs= rect->xmax - rect->xmin - BLF_width(str) - 1; + xofs= rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str) - 1; /* clip is very strict, so we give it some space */ - BLF_clipping(rect->xmin-1, rect->ymin-4, rect->xmax+1, rect->ymax+4); - BLF_enable(BLF_CLIPPING); - BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f); + BLF_clipping(fs->uifont_id, rect->xmin-1, rect->ymin-4, rect->xmax+1, rect->ymax+4); + BLF_enable(fs->uifont_id, BLF_CLIPPING); + BLF_position(fs->uifont_id, rect->xmin+xofs, rect->ymin+yofs, 0.0f); if (fs->shadow) { - BLF_enable(BLF_SHADOW); - BLF_shadow(fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha); - BLF_shadow_offset(fs->shadx, fs->shady); + BLF_enable(fs->uifont_id, BLF_SHADOW); + BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha); + BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady); } if (fs->kerning == 1) - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); - BLF_draw(str); - BLF_disable(BLF_CLIPPING); + BLF_draw(fs->uifont_id, str); + BLF_disable(fs->uifont_id, BLF_CLIPPING); if (fs->shadow) - BLF_disable(BLF_SHADOW); + BLF_disable(fs->uifont_id, BLF_SHADOW); if (fs->kerning == 1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); } /* drawn same as above, but at 90 degree angle */ @@ -187,7 +187,7 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, char *str) uiStyleFontSet(fs); - height= BLF_height("2"); /* correct offset is on baseline, the j is below that */ + height= BLF_height(fs->uifont_id, "2"); /* correct offset is on baseline, the j is below that */ /* becomes x-offset when rotated */ xofs= floor( 0.5f*(rect->ymax - rect->ymin - height)) + 1; @@ -195,7 +195,7 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, char *str) /* rotate counter-clockwise for now (assumes left-to-right language)*/ xofs+= height; - yofs= BLF_width(str) + 5; + yofs= BLF_width(fs->uifont_id, str) + 5; angle= 90.0f; /* translate rect to vertical */ @@ -206,29 +206,29 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, char *str) /* clip is very strict, so we give it some space */ /* clipping is done without rotation, so make rect big enough to contain both positions */ - BLF_clipping(txtrect.xmin-1, txtrect.ymin-yofs-xofs-4, rect->xmax+1, rect->ymax+4); - BLF_enable(BLF_CLIPPING); - BLF_position(txtrect.xmin+xofs, txtrect.ymax-yofs, 0.0f); + BLF_clipping(fs->uifont_id, txtrect.xmin-1, txtrect.ymin-yofs-xofs-4, rect->xmax+1, rect->ymax+4); + BLF_enable(fs->uifont_id, BLF_CLIPPING); + BLF_position(fs->uifont_id, txtrect.xmin+xofs, txtrect.ymax-yofs, 0.0f); - BLF_enable(BLF_ROTATION); - BLF_rotation(angle); + BLF_enable(fs->uifont_id, BLF_ROTATION); + BLF_rotation(fs->uifont_id, angle); if (fs->shadow) { - BLF_enable(BLF_SHADOW); - BLF_shadow(fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha); - BLF_shadow_offset(fs->shadx, fs->shady); + BLF_enable(fs->uifont_id, BLF_SHADOW); + BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha); + BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady); } if (fs->kerning == 1) - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); - BLF_draw(str); - BLF_disable(BLF_ROTATION); - BLF_disable(BLF_CLIPPING); + BLF_draw(fs->uifont_id, str); + BLF_disable(fs->uifont_id, BLF_ROTATION); + BLF_disable(fs->uifont_id, BLF_CLIPPING); if (fs->shadow) - BLF_disable(BLF_SHADOW); + BLF_disable(fs->uifont_id, BLF_SHADOW); if (fs->kerning == 1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); } /* ************** helpers ************************ */ @@ -241,13 +241,13 @@ int UI_GetStringWidth(char *str) int width; if (fstyle->kerning==1) /* for BLF_width */ - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); uiStyleFontSet(fstyle); - width= BLF_width(str); + width= BLF_width(fstyle->uifont_id, str); if (fstyle->kerning==1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); return width; } @@ -258,8 +258,8 @@ void UI_DrawString(float x, float y, char *str) uiStyle *style= U.uistyles.first; uiStyleFontSet(&style->widget); - BLF_position(x, y, 0.0f); - BLF_draw(str); + BLF_position(style->widget.uifont_id, x, y, 0.0f); + BLF_draw(style->widget.uifont_id, str); } /* ************** init exit ************************ */ @@ -299,14 +299,13 @@ void uiStyleInit(void) printf("uiStyleInit error, no fonts available\n"); } else { - BLF_set(font->blf_id); /* ? just for speed to initialize? * Yes, this build the glyph cache and create * the texture. */ - BLF_size(11, U.dpi); - BLF_size(12, U.dpi); - BLF_size(14, U.dpi); + BLF_size(font->blf_id, 11, U.dpi); + BLF_size(font->blf_id, 12, U.dpi); + BLF_size(font->blf_id, 14, U.dpi); } } @@ -319,7 +318,6 @@ void uiStyleFontSet(uiFontStyle *fs) { uiFont *font= uifont_to_blfont(fs->uifont_id); - BLF_set(font->blf_id); - BLF_size(fs->points, U.dpi); + BLF_size(font->blf_id, fs->points, U.dpi); } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index dac689ca933..558cdb798c2 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -813,15 +813,15 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) uiStyleFontSet(fstyle); if (fstyle->kerning==1) /* for BLF_width */ - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); - but->strwidth= BLF_width(but->drawstr); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr); but->ofs= 0; while(but->strwidth > okwidth ) { but->ofs++; - but->strwidth= BLF_width(but->drawstr+but->ofs); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); /* textbut exception */ if(but->editstr && but->pos != -1) { @@ -842,7 +842,7 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) } if (fstyle->kerning==1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); } static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) @@ -856,9 +856,9 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) uiStyleFontSet(fstyle); if (fstyle->kerning==1) /* for BLF_width */ - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); - but->strwidth= BLF_width(but->drawstr); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr); but->ofs= 0; /* find the space after ':' separator */ @@ -873,7 +873,7 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) memmove(cp2-1, cp2, strlen(cp2)+1); cp2--; - but->strwidth= BLF_width(but->drawstr+but->ofs); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); if(but->strwidth < 10) break; } @@ -882,7 +882,7 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) while ((but->strwidth > okwidth) && (but->ofs < 2)) { but->ofs++; - but->strwidth= BLF_width(but->drawstr+but->ofs); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); if(but->strwidth < 10) break; } @@ -895,12 +895,12 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) but->drawstr[ pos-1 ] = 0; pos--; - but->strwidth= BLF_width(but->drawstr+but->ofs); + but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); if(but->strwidth < 10) break; } if (fstyle->kerning==1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); } @@ -917,7 +917,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b fstyle->align= UI_STYLE_TEXT_CENTER; if (fstyle->kerning==1) /* for BLF_width */ - BLF_enable(BLF_KERNING_DEFAULT); + BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); /* text button selection and cursor */ if(but->editstr && but->pos != -1) { @@ -935,7 +935,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b ch= but->drawstr[selsta_tmp]; but->drawstr[selsta_tmp]= 0; - selsta_draw = BLF_width(but->drawstr+but->ofs); + selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); but->drawstr[selsta_tmp]= ch; } else @@ -944,7 +944,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b ch= but->drawstr[selend_tmp]; but->drawstr[selend_tmp]= 0; - selwidth_draw = BLF_width(but->drawstr+but->ofs); + selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs); but->drawstr[selend_tmp]= ch; @@ -959,7 +959,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b ch= but->drawstr[pos]; but->drawstr[pos]= 0; - t= BLF_width(but->drawstr+but->ofs) / but->aspect; + t= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs) / but->aspect; but->drawstr[pos]= ch; } @@ -971,7 +971,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } if (fstyle->kerning == 1) - BLF_disable(BLF_KERNING_DEFAULT); + BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); // ui_rasterpos_safe(x, y, but->aspect); // if(but->type==IDPOIN) transopts= 0; // no translation, of course! @@ -2839,7 +2839,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconid, cpoin= strchr(name, '|'); if(cpoin) { *cpoin= 0; - rect->xmax -= BLF_width(cpoin+1) + 10; + rect->xmax -= BLF_width(fstyle->uifont_id, cpoin+1) + 10; } glColor3ubv((unsigned char*)wt->wcol.text); @@ -2882,8 +2882,8 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconi glColor3ubv((unsigned char*)wt->wcol.text_sel); trect.xmin += 0; - trect.xmax = trect.xmin + BLF_width(name) + 10; + trect.xmax = trect.xmin + BLF_width(fstyle->uifont_id, name) + 10; trect.ymin += 10; - trect.ymax = trect.ymin + BLF_height(name); + trect.ymax = trect.ymin + BLF_height(fstyle->uifont_id, name); uiStyleFontDraw(fstyle, &trect, name); } diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index d41317f7078..5e8cab7c4b3 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1702,8 +1702,9 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* draw vertical steps */ if (dfac > 0.0f) { - BLF_default_rotation(90.0f); - + BLF_rotation_default(90.0f); + BLF_enable_default(BLF_ROTATION); + for (; fac < vert.ymax-10; fac+= dfac, val += grid->dy) { /* make prints look nicer for scrollers */ @@ -1713,7 +1714,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v scroll_printstr(vs, scene, (float)(vert.xmax)-2.0f, fac, val, grid->powery, vs->yunits, 'v'); } - BLF_default_rotation(0.0f); + BLF_disable_default(BLF_ROTATION); } } } @@ -2053,12 +2054,10 @@ void UI_view2d_text_cache_draw(ARegion *ar) yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28"))); if(yofs<1) yofs= 1; - BLF_clipping(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4); - BLF_enable(BLF_CLIPPING); - + BLF_clipping_default(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4); + BLF_enable_default(BLF_CLIPPING); BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str); - - BLF_disable(BLF_CLIPPING); + BLF_disable_default(BLF_CLIPPING); } } |