[Bf-blender-cvs] [21ae323dbf2] master: Cleanup: avoid redundant float/int conversions in BLF
Campbell Barton
noreply at git.blender.org
Wed Apr 13 05:08:40 CEST 2022
Commit: 21ae323dbf28b4e0049e68153fe1a310ccf5ebef
Author: Campbell Barton
Date: Wed Apr 13 12:45:41 2022 +1000
Branches: master
https://developer.blender.org/rB21ae323dbf28b4e0049e68153fe1a310ccf5ebef
Cleanup: avoid redundant float/int conversions in BLF
Internally many offsets for BLF were integers but exposed as floats,
since these are used in pixel-space, many callers were converging them
back to integers. Simplify logic by using ints.
===================================================================
M source/blender/blenfont/BLF_api.h
M source/blender/blenfont/intern/blf.c
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenfont/intern/blf_glyph.c
M source/blender/blenfont/intern/blf_internal.h
M source/blender/blenfont/intern/blf_internal_types.h
M source/blender/blenfont/intern/blf_thumbs.c
M source/blender/blenkernel/intern/image.cc
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_style.cc
M source/blender/editors/interface/interface_widgets.c
M source/blender/editors/space_file/file_draw.c
M source/blender/editors/util/ed_draw.c
M source/blender/sequencer/intern/effects.c
===================================================================
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 058b0f120f7..e5e2b1711b1 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -109,7 +109,7 @@ typedef bool (*BLF_GlyphBoundsFn)(const char *str,
size_t str_step_ofs,
const struct rcti *glyph_step_bounds,
int glyph_advance_x,
- const struct rctf *glyph_bounds,
+ const struct rcti *glyph_bounds,
const int glyph_bearing[2],
void *user_data);
@@ -151,9 +151,9 @@ size_t BLF_width_to_rstrlen(
void BLF_boundbox_ex(int fontid,
const char *str,
size_t str_len,
- struct rctf *box,
+ struct rcti *box,
struct ResultBLF *r_info) ATTR_NONNULL(2);
-void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rctf *box) ATTR_NONNULL();
+void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rcti *box) ATTR_NONNULL();
/**
* The next both function return the width and height
@@ -173,9 +173,9 @@ float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_R
* Return dimensions of the font without any sample text.
*/
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
-float BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
-float BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
-float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
+int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
+int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
+int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
/**
* The following function return the width and height of the string, but
@@ -195,7 +195,7 @@ float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT;
* have to be enable/disable using BLF_enable/disable.
*/
void BLF_rotation(int fontid, float angle);
-void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax);
+void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
void BLF_wordwrap(int fontid, int wrap_width);
#if BLF_BLUR_ENABLE
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 2b5a2cdf606..a944ab332bd 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -342,9 +342,9 @@ void BLF_position(int fontid, float x, float y, float z)
}
}
- font->pos[0] = x;
- font->pos[1] = y;
- font->pos[2] = z;
+ font->pos[0] = round_fl_to_int(x);
+ font->pos[1] = round_fl_to_int(y);
+ font->pos[2] = round_fl_to_int(z);
}
}
@@ -488,7 +488,7 @@ static void blf_draw_gl__start(FontBLF *font)
GPU_matrix_mul(font->m);
}
- GPU_matrix_translate_3fv(font->pos);
+ GPU_matrix_translate_3f(font->pos[0], font->pos[1], font->pos[2]);
if (font->flags & BLF_ASPECT) {
GPU_matrix_scale_3fv(font->aspect);
@@ -589,9 +589,10 @@ size_t BLF_width_to_strlen(
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
- ret = blf_font_width_to_strlen(font, str, str_len, width / xa, r_width);
+ int width_result;
+ ret = blf_font_width_to_strlen(font, str, str_len, width / xa, &width_result);
if (r_width) {
- *r_width *= xa;
+ *r_width = (float)width_result * xa;
}
return ret;
}
@@ -610,9 +611,10 @@ size_t BLF_width_to_rstrlen(
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
- ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, r_width);
+ int width_result;
+ ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, &width_result);
if (r_width) {
- *r_width *= xa;
+ *r_width = (float)width_result * xa;
}
return ret;
}
@@ -624,7 +626,7 @@ size_t BLF_width_to_rstrlen(
}
void BLF_boundbox_ex(
- int fontid, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
+ int fontid, const char *str, const size_t str_len, rcti *r_box, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
@@ -640,7 +642,7 @@ void BLF_boundbox_ex(
}
}
-void BLF_boundbox(int fontid, const char *str, const size_t str_len, rctf *r_box)
+void BLF_boundbox(int fontid, const char *str, const size_t str_len, rcti *r_box)
{
BLF_boundbox_ex(fontid, str, str_len, r_box, NULL);
}
@@ -716,7 +718,7 @@ int BLF_height_max(int fontid)
return 0;
}
-float BLF_width_max(int fontid)
+int BLF_width_max(int fontid)
{
FontBLF *font = blf_get(fontid);
@@ -724,10 +726,10 @@ float BLF_width_max(int fontid)
return blf_font_width_max(font);
}
- return 0.0f;
+ return 0;
}
-float BLF_descender(int fontid)
+int BLF_descender(int fontid)
{
FontBLF *font = blf_get(fontid);
@@ -735,10 +737,10 @@ float BLF_descender(int fontid)
return blf_font_descender(font);
}
- return 0.0f;
+ return 0;
}
-float BLF_ascender(int fontid)
+int BLF_ascender(int fontid)
{
FontBLF *font = blf_get(fontid);
@@ -758,7 +760,7 @@ void BLF_rotation(int fontid, float angle)
}
}
-void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
+void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
{
FontBLF *font = blf_get(fontid);
@@ -889,7 +891,7 @@ void BLF_state_print(int fontid)
printf(" name: '%s'\n", font->name);
printf(" size: %f\n", font->size);
printf(" dpi: %u\n", font->dpi);
- printf(" pos: %.6f %.6f %.6f\n", UNPACK3(font->pos));
+ printf(" pos: %d %d %d\n", UNPACK3(font->pos));
printf(" aspect: (%d) %.6f %.6f %.6f\n",
(font->flags & BLF_ROTATION) != 0,
UNPACK3(font->aspect));
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index e5d7cb05408..16d4c46589d 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -138,12 +138,12 @@ void blf_batch_draw_begin(FontBLF *font)
if (simple_shader) {
/* Offset is applied to each glyph. */
- g_batch.ofs[0] = floorf(font->pos[0]);
- g_batch.ofs[1] = floorf(font->pos[1]);
+ g_batch.ofs[0] = font->pos[0];
+ g_batch.ofs[1] = font->pos[1];
}
else {
/* Offset is baked in modelview mat. */
- zero_v2(g_batch.ofs);
+ zero_v2_int(g_batch.ofs);
}
if (g_batch.active) {
@@ -425,8 +425,8 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
ft_pix pen_y)
{
GlyphBLF *g, *g_prev = NULL;
- ft_pix pen_x = ft_pix_from_float(font->pos[0]);
- ft_pix pen_y_basis = ft_pix_from_float(font->pos[1]) + pen_y;
+ ft_pix pen_x = ft_pix_from_int(font->pos[0]);
+ ft_pix pen_y_basis = ft_pix_from_int(font->pos[1]) + pen_y;
size_t i = 0;
/* buffer specific vars */
@@ -586,7 +586,7 @@ static bool blf_font_width_to_strlen_glyph_process(
}
size_t blf_font_width_to_strlen(
- FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
+ FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
{
GlyphBLF *g, *g_prev;
ft_pix pen_x;
@@ -606,7 +606,7 @@ size_t blf_font_width_to_strlen(
}
if (r_width) {
- *r_width = (float)ft_pix_to_int(width_new);
+ *r_width = ft_pix_to_int(width_new);
}
blf_glyph_cache_release(font);
@@ -614,7 +614,7 @@ size_t blf_font_width_to_strlen(
}
size_t blf_font_width_to_rstrlen(
- FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
+ FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
{
GlyphBLF *g, *g_prev;
ft_pix pen_x, width_new;
@@ -622,7 +622,6 @@ size_t blf_font_width_to_rstrlen(
const char *s, *s_prev;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- const int width_i = (int)width;
i = BLI_strnlen(str, str_len);
s = BLI_str_find_prev_char_utf8(&str[i], str);
@@ -643,13 +642,13 @@ size_t blf_font_width_to_rstrlen(
BLI_assert(i_tmp == i);
}
- if (blf_font_width_to_strlen_glyph_process(font, g_prev, g, &pen_x, width_i)) {
+ if (blf_font_width_to_strlen_glyph_process(font, g_prev, g, &pen_x, width)) {
break;
}
}
if (r_width) {
- *r_width = (float)ft_pix_to_int(width_new);
+ *r_width = ft_pix_to_int(width_new);
}
blf_glyph_cache_release(font);
@@ -666,7 +665,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
const size_t str_len,
- rctf *box,
+ rcti *box,
struct ResultBLF *r_info,
ft_pix pen_y)
{
@@ -718,10 +717,10 @@ static void blf_font_boundbox_ex(FontBLF *font,
box_ymax = 0;
}
- box->xmin = (float)ft_pix_to_int_floor(box_xmin);
- box->xmax = (float)ft_pix_to_int_ceil(box_xmax);
- box->ymin = (float)ft_pix_to_int_floor(box_ymin);
- box->ymax = (float)ft_pix_to_int_ceil(box_ymax);
+ box->xmin = ft_pix_to_int_floor(box_xmin);
+ box->xmax = ft_pix_to_int_ceil(box_xmax);
+ box->ymin = ft_pix_to_int_floor(box_ymin);
+ box->ymax = ft_pix_to_int_ceil(box_ymax);
if (r_info) {
r_info->lines = 1;
@@ -729,7 +728,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
}
}
void blf_font_boundbox(
- FontBLF *font, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
+ FontBLF *font, const char *str, const size_t str_len, rcti *r_box, struct ResultBLF *r_info)
{
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
blf_font_boundbox_ex(font, gc, str, str_len, r_box, r_info, 0);
@@ -744,7 +743,7 @@ void blf_font_width_and_height(FontBLF *font,
struct ResultBLF *r_info)
{
float xa, ya;
- rctf box;
+ rcti box;
if (font->flags & BLF_ASPECT) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list