[mutter/gbsneto/graphene-matrix: 74/104] cogl/matrix: Add graphene_matrix_t utility function




commit bad353a79d9dae614d2a9ecc85b44e7bfce276cf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Sep 11 09:33:43 2020 -0300

    cogl/matrix: Add graphene_matrix_t utility function
    
    CoglMatrix doesn't have a 1:1 mapping of graphene functions, and
    sometimes it's just not worth adding wrappers over it. It is easier
    to expose the internal graphene_matrix_t and let callers use it
    directly.
    
    Add new cogl_matrix_get_graphene_matrix() helper function, and
    simplify Clutter's matrix progress function.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439

 clutter/clutter/clutter-cogl.c | 14 +++++---------
 cogl/cogl/cogl-matrix.c        |  6 ++++++
 cogl/cogl/cogl-matrix.h        | 12 ++++++++++++
 3 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/clutter/clutter/clutter-cogl.c b/clutter/clutter/clutter-cogl.c
index 9663f904db..c36f726045 100644
--- a/clutter/clutter/clutter-cogl.c
+++ b/clutter/clutter/clutter-cogl.c
@@ -37,18 +37,14 @@ cogl_matrix_progress (const GValue *a,
 {
   const CoglMatrix *matrix1 = g_value_get_boxed (a);
   const CoglMatrix *matrix2 = g_value_get_boxed (b);
-  graphene_matrix_t m1, m2, interpolated;
+  graphene_matrix_t interpolated;
   CoglMatrix res;
-  float fm1[16];
-  float fm2[16];
   float v[16];
 
-  cogl_matrix_to_float (matrix1, fm1);
-  cogl_matrix_to_float (matrix2, fm2);
-
-  graphene_matrix_init_from_float (&m1, fm1);
-  graphene_matrix_init_from_float (&m2, fm2);
-  graphene_matrix_interpolate (&m1, &m2, progress, &interpolated);
+  graphene_matrix_interpolate (cogl_matrix_get_graphene_matrix (matrix1),
+                               cogl_matrix_get_graphene_matrix (matrix2),
+                               progress,
+                               &interpolated);
   graphene_matrix_to_float (&interpolated, v);
 
   cogl_matrix_init_from_array (&res, v);
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 22152b27be..242ed4a7e3 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -808,3 +808,9 @@ cogl_matrix_skew_yz (CoglMatrix *matrix,
   matrix->flags |= COGL_MATRIX_FLAG_DIRTY_INVERSE;
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
+
+const graphene_matrix_t *
+cogl_matrix_get_graphene_matrix (const CoglMatrix *matrix)
+{
+  return &matrix->m;
+}
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 4a3d6156e9..347584dfe5 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -777,6 +777,18 @@ COGL_EXPORT void
 cogl_matrix_skew_yz (CoglMatrix *matrix,
                      float       factor);
 
+/**
+ * cogl_matrix_get_graphene_matrix:
+ * @matrix: a #CoglMatrix
+ *
+ * Retrieves the internal #graphene_matrix_t of @matrix. It should not
+ * be modified, and must be considered read-only.
+ *
+ * Returns: (transfer none): a #graphene_matrix_t
+ */
+COGL_EXPORT const graphene_matrix_t *
+cogl_matrix_get_graphene_matrix (const CoglMatrix *matrix);
+
 G_END_DECLS
 
 #endif /* __COGL_MATRIX_H */


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