diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-10-13 08:23:56 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-10-13 09:02:31 -0300 |
commit | 3dd556f8399b61b3f62b34df42f9e74a266c3acc (patch) | |
tree | 2e45c07cfadb88cec9e74fa4d662754ca3071380 | |
parent | 0730ff5b9e51ee67f2841c582c7609fc50c410ba (diff) | |
download | mutter-3dd556f8399b61b3f62b34df42f9e74a266c3acc.tar.gz |
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
-rw-r--r-- | clutter/clutter/clutter-private.h | 6 | ||||
-rw-r--r-- | 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); } } |