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
This commit is contained in:
Georges Basile Stavracas Neto 2020-10-13 08:23:56 -03:00
parent 5a58ccbece
commit 8809ee9e26
2 changed files with 16 additions and 10 deletions

View File

@ -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)
{

View File

@ -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);
}
}