From 7283c5c22fa649f029090150883cafd0e4ac1c2f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 11 Mar 2024 17:39:32 -0400 Subject: [PATCH] gsk: Avoid some roundf calls It seems that gcc has a hard time using intrinsics for round, so help it out by using floor (x + .5). --- gsk/gpu/gskgpunodeprocessor.c | 12 ++++++------ gsk/gskprivate.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index a049cad379..4c28f33af6 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -3043,15 +3043,15 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self, /* Force glyph_origin.y to be device pixel aligned. * The hinter expects that. */ - glyph_origin.x = roundf (glyph_origin.x * scale * 4); + glyph_origin.x = floor (glyph_origin.x * scale * 4 + .5); flags = ((int) glyph_origin.x & 3); glyph_origin.x = 0.25 * inv_scale * glyph_origin.x; - glyph_origin.y = roundf (glyph_origin.y * scale) * inv_scale; + glyph_origin.y = floor (glyph_origin.y * scale + .5) * inv_scale; } else if (glyph_align) { - glyph_origin.x = roundf (glyph_origin.x * scale * 4); - glyph_origin.y = roundf (glyph_origin.y * scale * 4); + glyph_origin.x = floor (glyph_origin.x * scale * 4 + .5); + glyph_origin.y = floor (glyph_origin.y * scale * 4 + .5); flags = ((int) glyph_origin.x & 3) | (((int) glyph_origin.y & 3) << 2); glyph_origin.x = 0.25 * inv_scale * glyph_origin.x; @@ -3059,8 +3059,8 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self, } else { - glyph_origin.x = roundf (glyph_origin.x * scale) * inv_scale; - glyph_origin.y = roundf (glyph_origin.y * scale) * inv_scale; + glyph_origin.x = floor (glyph_origin.x * scale + .5) * inv_scale; + glyph_origin.y = floor (glyph_origin.y * scale + .5) * inv_scale; flags = 0; } diff --git a/gsk/gskprivate.c b/gsk/gskprivate.c index 2005032aa8..c3f45fc58e 100644 --- a/gsk/gskprivate.c +++ b/gsk/gskprivate.c @@ -53,7 +53,7 @@ gsk_get_scaled_font (PangoFont *font, FcPattern *pattern; double dpi; - key = (int) roundf (scale * PANGO_SCALE); + key = (int) floor (scale * PANGO_SCALE + .5); fonts = (GHashTable *) g_object_get_data (G_OBJECT (font), "gsk-scaled-fonts"); @@ -76,7 +76,7 @@ gsk_get_scaled_font (PangoFont *font, if (pango_font_description_get_size_is_absolute (desc)) pango_font_description_set_absolute_size (desc, size * scale); else - pango_font_description_set_size (desc, (int) roundf (size * scale)); + pango_font_description_set_size (desc, (int) floor (size * scale + .5)); fontmap = pango_font_get_font_map (font); context = pango_font_map_create_context (fontmap);