From 67cc60cbda29d3b0ad19aad6cdae88f25346f3b3 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Tue, 8 Sep 2020 16:40:54 +0800 Subject: [PATCH] clutter: Align all screen transformations to 1/256th of a stage unit. So as to eliminate floating point precision errors that creep in during matrix operations. 1/256th is chosen as a reasonable maximum resolution to cover any realistic fractional scaling factor. Floats can represent such a fraction losslessly because it is a small power of 2. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1403 https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1429 --- clutter/clutter/clutter-util.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c index 6e59889a8..d386b1db8 100644 --- a/clutter/clutter/clutter-util.c +++ b/clutter/clutter/clutter-util.c @@ -47,6 +47,8 @@ #define MTX_GL_SCALE_Y(y,w,v1,v2) ((v1) - (((((y) / (w)) + 1.0f) / 2.0f) * (v1)) + (v2)) #define MTX_GL_SCALE_Z(z,w,v1,v2) (MTX_GL_SCALE_X ((z), (w), (v1), (v2))) +#define ROUND_TO_256THS(x) (roundf ((x) * 256) / 256) + void _clutter_util_fully_transform_vertices (const CoglMatrix *modelview, const CoglMatrix *projection, @@ -99,10 +101,14 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview, ClutterVertex4 vertex_tmp = vertices_tmp[i]; graphene_point3d_t *vertex_out = &vertices_out[i]; /* Finally translate from OpenGL coords to window coords */ - vertex_out->x = MTX_GL_SCALE_X (vertex_tmp.x, vertex_tmp.w, - viewport[2], viewport[0]); - vertex_out->y = MTX_GL_SCALE_Y (vertex_tmp.y, vertex_tmp.w, - viewport[3], viewport[1]); + vertex_out->x = ROUND_TO_256THS (MTX_GL_SCALE_X (vertex_tmp.x, + vertex_tmp.w, + viewport[2], + viewport[0])); + vertex_out->y = ROUND_TO_256THS (MTX_GL_SCALE_Y (vertex_tmp.y, + vertex_tmp.w, + viewport[3], + viewport[1])); } }