Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-07-16 05:09:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-07-16 05:12:19 +0400
commit1ae11f71ff6f076ebc428dc949c5b2a0339aa1e4 (patch)
treedfe24749a400a55862d4f2287c6fe60f5d1fca48 /source
parentdfe1b9b7a727d5d4cf998a89153aad9f3f6fde55 (diff)
BLF: avoid float/int conversion drawing glyphs
also use UNLIKELY for error cases
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenfont/intern/blf_font.c36
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c1
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h2
3 files changed, 21 insertions, 18 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 2bdae87dc83..4891c332c87 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -186,9 +186,9 @@ void blf_font_draw(FontBLF *font, const char *str, size_t len)
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
@@ -196,7 +196,7 @@ void blf_font_draw(FontBLF *font, const char *str, size_t len)
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
g_prev = g;
}
}
@@ -224,7 +224,7 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len)
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
g_prev = g;
}
}
@@ -244,9 +244,9 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
/* do not return this loop if clipped, we want every character tested */
@@ -303,9 +303,9 @@ void blf_font_buffer(FontBLF *font, const char *str)
while (str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
@@ -415,7 +415,7 @@ void blf_font_buffer(FontBLF *font, const char *str)
}
}
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
g_prev = g;
}
}
@@ -438,14 +438,14 @@ size_t blf_font_width_to_strlen(FontBLF *font, const char *str, size_t len, floa
while ((i_prev = i), (width_new = pen_x), ((i < len) && str[i])) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
if (width_i < pen_x) {
break;
@@ -501,14 +501,14 @@ size_t blf_font_width_to_rstrlen(FontBLF *font, const char *str, size_t len, flo
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
width_accum[width_accum_ofs][0] = (int)i;
width_accum[width_accum_ofs][1] = pen_x;
@@ -570,9 +570,9 @@ void blf_font_boundbox(FontBLF *font, const char *str, size_t len, rctf *box)
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == BLI_UTF8_ERR)
+ if (UNLIKELY(c == BLI_UTF8_ERR))
break;
- if (g == NULL)
+ if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
@@ -588,7 +588,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, size_t len, rctf *box)
if (gbox.xmax > box->xmax) box->xmax = gbox.xmax;
if (gbox.ymax > box->ymax) box->ymax = gbox.ymax;
- pen_x += (int)g->advance;
+ pen_x += g->advance_i;
g_prev = g;
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 7c3cfa30e16..bfb42f69077 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -279,6 +279,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
}
g->advance = ((float)slot->advance.x) / 64.0f;
+ g->advance_i = (int)g->advance;
g->pos_x = (float)slot->bitmap_left;
g->pos_y = (float)slot->bitmap_top;
g->pitch = slot->bitmap.pitch;
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index c64b7e974e7..da756d65483 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -99,6 +99,8 @@ typedef struct GlyphBLF {
/* advance size. */
float advance;
+ /* avoid conversion to int while drawing */
+ int advance_i;
/* texture id where this glyph is store. */
GLuint tex;