From 8809ee9e26430262c22c8551e42fb9cb7caf3424 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 13 Oct 2020 08:23:56 -0300 Subject: [PATCH] clutter/util: Generalize ROUND_TO_256THS It'll be reused in other bits of the Clutter codebase. Move it to an inline function in clutter-private.h https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1489 --- clutter/clutter/clutter-private.h | 6 ++++++ clutter/clutter/clutter-util.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h index a504b74ba..594a73b86 100644 --- a/clutter/clutter/clutter-private.h +++ b/clutter/clutter/clutter-private.h @@ -268,6 +268,12 @@ gboolean _clutter_run_progress_function (GType gtype, void clutter_timeline_cancel_delay (ClutterTimeline *timeline); +static inline void +clutter_round_to_256ths (float *f) +{ + *f = roundf ((*f) * 256) / 256; +} + static inline int64_t us (int64_t us) { diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c index f598332c8..5f7fab0e1 100644 --- a/clutter/clutter/clutter-util.c +++ b/clutter/clutter/clutter-util.c @@ -47,8 +47,6 @@ #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) - typedef struct { float x; @@ -108,14 +106,16 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *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 = 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])); + 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]); + clutter_round_to_256ths (&vertex_out->x); + clutter_round_to_256ths (&vertex_out->y); } }