[mutter/gbsneto/graphene-matrix: 23/50] cogl/matrix: Remove cached inverse and flags




commit f58907d0d7d06257b6745783efaf1665329ff066
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Sep 11 14:41:53 2020 -0300

    cogl/matrix: Remove cached inverse and flags
    
    Remove the cached inverse, and dirty flags, and typedef CoglMatrix to
    graphene_matrix_t itself. I preverved the type for this commit to help
    reducing the commit size, next commits will remove the CoglMatrix type.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439

 cogl/cogl/cogl-matrix.c | 86 ++++---------------------------------------------
 cogl/cogl/cogl-matrix.h |  3 --
 2 files changed, 6 insertions(+), 83 deletions(-)
---
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index c2086d4615..4f71dee006 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -47,21 +47,12 @@ COGL_GTYPE_DEFINE_BOXED (Matrix, matrix,
                          cogl_matrix_copy,
                          cogl_matrix_free);
 
-enum CoglMatrixFlags
-{
-  COGL_MATRIX_FLAG_NONE = 0,
-  COGL_MATRIX_FLAG_SINGULAR = 1 << 0,
-  COGL_MATRIX_FLAG_DIRTY_INVERSE = 1 << 1,
-};
-
 void
 cogl_matrix_multiply (CoglMatrix *result,
                      const CoglMatrix *a,
                      const CoglMatrix *b)
 {
   graphene_matrix_multiply (&b->m, &a->m, &result->m);
-  result->flags = a->flags | b->flags | COGL_MATRIX_FLAG_DIRTY_INVERSE;
-
   _COGL_MATRIX_DEBUG_PRINT (result);
 }
 
@@ -69,11 +60,6 @@ void
 _cogl_matrix_prefix_print (const char *prefix, const CoglMatrix *matrix)
 {
   graphene_matrix_print (&matrix->m);
-  g_print ("%sInverse: \n", prefix);
-  if (!(matrix->flags & COGL_MATRIX_FLAG_DIRTY_INVERSE))
-    graphene_matrix_print (&matrix->inv);
-  else
-    g_print ("%s  - not available\n", prefix);
 }
 
 /*
@@ -101,7 +87,8 @@ cogl_debug_matrix_print (const CoglMatrix *matrix)
 #define SCALE 1000.F
 
 static inline gboolean
-calculate_inverse (CoglMatrix *matrix)
+calculate_inverse (const CoglMatrix *matrix,
+                   CoglMatrix       *inverse)
 {
   graphene_matrix_t scaled;
   graphene_matrix_t m;
@@ -113,50 +100,20 @@ calculate_inverse (CoglMatrix *matrix)
   graphene_matrix_init_from_matrix (&m, &matrix->m);
   graphene_matrix_multiply (&m, &scaled, &m);
 
-  invertible = graphene_matrix_inverse (&m, &matrix->inv);
+  invertible = graphene_matrix_inverse (&m, &inverse->m);
 
   if (invertible)
-    graphene_matrix_multiply (&scaled, &matrix->inv, &matrix->inv);
+    graphene_matrix_multiply (&scaled, &inverse->m, &inverse->m);
   else
-    graphene_matrix_init_identity (&matrix->inv);
+    graphene_matrix_init_identity (&inverse->m);
 
   return invertible;
 }
 
-static gboolean
-_cogl_matrix_update_inverse (CoglMatrix *matrix)
-{
-  if (matrix->flags & COGL_MATRIX_FLAG_DIRTY_INVERSE)
-    {
-      if (calculate_inverse (matrix))
-        matrix->flags &= ~COGL_MATRIX_FLAG_SINGULAR;
-      else
-        matrix->flags |= COGL_MATRIX_FLAG_SINGULAR;
-
-      matrix->flags &= ~COGL_MATRIX_FLAG_DIRTY_INVERSE;
-    }
-
-  if (matrix->flags & COGL_MATRIX_FLAG_SINGULAR)
-    return FALSE;
-  else
-    return TRUE;
-}
-
 gboolean
 cogl_matrix_get_inverse (const CoglMatrix *matrix, CoglMatrix *inverse)
 {
-  if (_cogl_matrix_update_inverse ((CoglMatrix *)matrix))
-    {
-      graphene_matrix_init_from_matrix (&inverse->m, &matrix->inv);
-      graphene_matrix_init_from_matrix (&inverse->inv, &matrix->m);
-      inverse->flags = COGL_MATRIX_FLAG_NONE;
-      return TRUE;
-    }
-  else
-    {
-      cogl_matrix_init_identity (inverse);
-      return FALSE;
-    }
+  return calculate_inverse (matrix, inverse);
 }
 
 void
@@ -168,16 +125,11 @@ cogl_matrix_rotate (CoglMatrix *matrix,
 {
   graphene_matrix_t rotation;
   graphene_vec3_t axis;
-  unsigned long flags;
-
-  flags = matrix->flags;
 
   graphene_vec3_init (&axis, x, y, z);
   graphene_matrix_init_rotate (&rotation, angle, &axis);
   graphene_matrix_multiply (&rotation, &matrix->m, &matrix->m);
 
-  matrix->flags = flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
-
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -201,9 +153,6 @@ cogl_matrix_frustum (CoglMatrix *matrix,
                      float       z_far)
 {
   graphene_matrix_t frustum;
-  unsigned long flags;
-
-  flags = matrix->flags;
 
   graphene_matrix_init_frustum (&frustum,
                                 left, right,
@@ -211,9 +160,6 @@ cogl_matrix_frustum (CoglMatrix *matrix,
                                 z_near, z_far);
   graphene_matrix_multiply (&frustum, &matrix->m, &matrix->m);
 
-  flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
-  matrix->flags = flags;
-
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -246,9 +192,6 @@ cogl_matrix_orthographic (CoglMatrix *matrix,
                           float far)
 {
   graphene_matrix_t ortho;
-  unsigned long flags;
-
-  flags = matrix->flags;
 
   graphene_matrix_init_ortho (&ortho,
                               left, right,
@@ -256,8 +199,6 @@ cogl_matrix_orthographic (CoglMatrix *matrix,
                               near, far);
   graphene_matrix_multiply (&ortho, &matrix->m, &matrix->m);
 
-  matrix->flags = flags | COGL_MATRIX_FLAG_DIRTY_INVERSE;
-
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -268,15 +209,10 @@ cogl_matrix_scale (CoglMatrix *matrix,
                   float sz)
 {
   graphene_matrix_t scale;
-  unsigned long flags;
-
-  flags = matrix->flags;
 
   graphene_matrix_init_scale (&scale, sx, sy, sz);
   graphene_matrix_multiply (&scale, &matrix->m, &matrix->m);
 
-  matrix->flags = flags | COGL_MATRIX_FLAG_DIRTY_INVERSE;
-
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -291,7 +227,6 @@ cogl_matrix_translate (CoglMatrix *matrix,
   graphene_matrix_init_translate (&translation,
                                   &GRAPHENE_POINT3D_INIT (x, y, z));
   graphene_matrix_multiply (&translation, &matrix->m, &matrix->m);
-  matrix->flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -300,7 +235,6 @@ void
 cogl_matrix_init_identity (CoglMatrix *matrix)
 {
   graphene_matrix_init_identity (&matrix->m);
-  matrix->flags = COGL_MATRIX_FLAG_DIRTY_INVERSE;
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -311,8 +245,6 @@ cogl_matrix_init_translation (CoglMatrix *matrix,
                               float       tz)
 {
   graphene_matrix_init_translate (&matrix->m, &GRAPHENE_POINT3D_INIT (tx, ty, tz));
-  matrix->flags = COGL_MATRIX_FLAG_DIRTY_INVERSE;
-
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -330,7 +262,6 @@ static void
 _cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array)
 {
   graphene_matrix_init_from_float (&matrix->m, array);
-  matrix->flags = COGL_MATRIX_FLAG_DIRTY_INVERSE;
 }
 
 void
@@ -352,7 +283,6 @@ _cogl_matrix_init_from_matrix_without_inverse (CoglMatrix *matrix,
                                                const CoglMatrix *src)
 {
   graphene_matrix_init_from_matrix (&matrix->m, &src->m);
-  matrix->flags = src->flags | COGL_MATRIX_FLAG_DIRTY_INVERSE;
 }
 
 void
@@ -739,7 +669,6 @@ cogl_matrix_look_at (CoglMatrix *matrix,
   graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z);
 
   graphene_matrix_init_look_at (&look_at.m, &eye, &center, &up);
-  look_at.flags = COGL_MATRIX_FLAG_DIRTY_INVERSE;
 
   cogl_matrix_multiply (matrix, matrix, &look_at);
 }
@@ -770,7 +699,6 @@ cogl_matrix_skew_xy (CoglMatrix *matrix,
   graphene_matrix_skew_xy (&skew, factor);
   graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
 
-  matrix->flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -784,7 +712,6 @@ cogl_matrix_skew_xz (CoglMatrix *matrix,
   graphene_matrix_skew_xz (&skew, factor);
   graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
 
-  matrix->flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -798,7 +725,6 @@ cogl_matrix_skew_yz (CoglMatrix *matrix,
   graphene_matrix_skew_yz (&skew, factor);
   graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
 
-  matrix->flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 347584dfe5..ed3924cbf0 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -82,9 +82,6 @@ struct _CoglMatrix
 {
   /*< private >*/
   graphene_matrix_t m;
-
-  graphene_matrix_t COGL_PRIVATE (inv);
-  unsigned long  COGL_PRIVATE (flags);
 };
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]