clutter: Use graphene_matrix_inverse()

Instead of our own implementation that upscales, then downscales back,
use graphene_matrix_inverse() directly. This is possible after switching
to a z-near value that doesn't have problems with float precision.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1489
This commit is contained in:
Georges Basile Stavracas Neto 2020-10-11 13:30:25 -03:00
parent 78c648f947
commit 1f99395d20
5 changed files with 6 additions and 58 deletions

View File

@ -3165,9 +3165,8 @@ ensure_valid_actor_transform (ClutterActor *actor)
graphene_matrix_init_identity (&priv->transform);
CLUTTER_ACTOR_GET_CLASS (actor)->apply_transform (actor, &priv->transform);
priv->has_inverse_transform =
cogl_graphene_matrix_get_inverse (&priv->transform,
&priv->inverse_transform);
priv->has_inverse_transform = graphene_matrix_inverse (&priv->transform,
&priv->inverse_transform);
priv->transform_valid = TRUE;
}

View File

@ -2068,8 +2068,8 @@ clutter_stage_set_perspective (ClutterStage *stage,
priv->perspective.aspect,
priv->perspective.z_near,
priv->perspective.z_far);
cogl_graphene_matrix_get_inverse (&priv->projection,
&priv->inverse_projection);
graphene_matrix_inverse (&priv->projection,
&priv->inverse_projection);
_clutter_stage_dirty_projection (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));

View File

@ -274,38 +274,3 @@ cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix,
n_points);
}
}
gboolean
cogl_graphene_matrix_get_inverse (const graphene_matrix_t *matrix,
graphene_matrix_t *inverse)
{
graphene_matrix_t scaled;
graphene_matrix_t m;
gboolean invertible;
float pivot = G_MAXFLOAT;
float v[16];
float scale;
graphene_matrix_init_from_matrix (&m, matrix);
graphene_matrix_to_float (&m, v);
pivot = MIN (pivot, v[0]);
pivot = MIN (pivot, v[5]);
pivot = MIN (pivot, v[10]);
pivot = MIN (pivot, v[15]);
scale = 1.f / pivot;
graphene_matrix_init_scale (&scaled, scale, scale, scale);
/* Float precision is a limiting factor */
graphene_matrix_multiply (&m, &scaled, &m);
invertible = graphene_matrix_inverse (&m, inverse);
if (invertible)
graphene_matrix_multiply (&scaled, inverse, inverse);
else
graphene_matrix_init_identity (inverse);
return invertible;
}

View File

@ -163,22 +163,6 @@ cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix,
void *points_out,
int n_points);
/**
* cogl_graphene_matrix_get_inverse:
* @matrix: A 4x4 transformation matrix
* @inverse: (out): The destination for a 4x4 inverse transformation matrix
*
* Gets the inverse transform of a given matrix and uses it to initialize
* a new #graphene_matrix_t.
*
* Return value: %TRUE if the inverse was successfully calculated or %FALSE
* for degenerate transformations that can't be inverted (in this case the
* @inverse matrix will simply be initialized with the identity matrix)
*/
COGL_EXPORT gboolean
cogl_graphene_matrix_get_inverse (const graphene_matrix_t *matrix,
graphene_matrix_t *inverse);
G_END_DECLS
#endif /* COGL_GRAPHENE_H */

View File

@ -358,9 +358,9 @@ cogl_matrix_stack_get_inverse (CoglMatrixStack *stack,
graphene_matrix_t *internal = cogl_matrix_stack_get (stack, &matrix);
if (internal)
return cogl_graphene_matrix_get_inverse (internal, inverse);
return graphene_matrix_inverse (internal, inverse);
else
return cogl_graphene_matrix_get_inverse (&matrix, inverse);
return graphene_matrix_inverse (&matrix, inverse);
}
/* In addition to writing the stack matrix into the give @matrix