[mutter/gbsneto/graphene: 23/31] Replace CoglQuaternion by graphene_quaternion_t



commit d71df422f35f6a0d0f2c9ace2144fbfa9814f5ed
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Feb 16 11:09:38 2019 -0200

    Replace CoglQuaternion by graphene_quaternion_t
    
    Same story, but smaller damage area. CoglQuaternion was used
    in fewer places than CoglEuler, resulting in a smaller patch.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/458

 cogl/cogl/cogl-framebuffer.c               |   2 +-
 cogl/cogl/cogl-framebuffer.h               |   5 +-
 cogl/cogl/cogl-matrix-stack-private.h      |   4 +-
 cogl/cogl/cogl-matrix-stack.c              |  29 +-
 cogl/cogl/cogl-matrix-stack.h              |   4 +-
 cogl/cogl/cogl-matrix.c                    |  39 +-
 cogl/cogl/cogl-matrix.h                    |  11 +-
 cogl/cogl/cogl-quaternion-private.h        |  44 --
 cogl/cogl/cogl-quaternion.c                | 670 -----------------------------
 cogl/cogl/cogl-quaternion.h                | 561 ------------------------
 cogl/cogl/cogl-types.h                     |   4 -
 cogl/cogl/cogl.h                           |   1 -
 cogl/cogl/cogl.symbols                     |  25 --
 cogl/cogl/meson.build                      |   3 -
 cogl/tests/conform/test-euler-quaternion.c |   4 +-
 15 files changed, 45 insertions(+), 1361 deletions(-)
---
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
index 42793574f..4231401b9 100644
--- a/cogl/cogl/cogl-framebuffer.c
+++ b/cogl/cogl/cogl-framebuffer.c
@@ -1603,7 +1603,7 @@ cogl_framebuffer_rotate (CoglFramebuffer *framebuffer,
 
 void
 cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
-                                    const CoglQuaternion *quaternion)
+                                    const graphene_quaternion_t *quaternion)
 {
   CoglMatrixStack *modelview_stack =
     _cogl_framebuffer_get_modelview_stack (framebuffer);
diff --git a/cogl/cogl/cogl-framebuffer.h b/cogl/cogl/cogl-framebuffer.h
index e10e85f51..92532893e 100644
--- a/cogl/cogl/cogl-framebuffer.h
+++ b/cogl/cogl/cogl-framebuffer.h
@@ -51,7 +51,6 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
 #include <cogl/cogl-pipeline.h>
 #include <cogl/cogl-indices.h>
 #include <cogl/cogl-bitmap.h>
-#include <cogl/cogl-quaternion.h>
 #include <cogl/cogl-texture.h>
 #include <glib-object.h>
 
@@ -365,7 +364,7 @@ cogl_framebuffer_rotate (CoglFramebuffer *framebuffer,
 /**
  * cogl_framebuffer_rotate_quaternion:
  * @framebuffer: A #CoglFramebuffer pointer
- * @quaternion: A #CoglQuaternion
+ * @quaternion: A #graphene_quaternion_t
  *
  * Multiplies the current model-view matrix by one that rotates
  * according to the rotation described by @quaternion.
@@ -375,7 +374,7 @@ cogl_framebuffer_rotate (CoglFramebuffer *framebuffer,
  */
 void
 cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
-                                    const CoglQuaternion *quaternion);
+                                    const graphene_quaternion_t *quaternion);
 
 /**
  * cogl_framebuffer_rotate_euler:
diff --git a/cogl/cogl/cogl-matrix-stack-private.h b/cogl/cogl/cogl-matrix-stack-private.h
index 68e07c41b..eab2c9b4d 100644
--- a/cogl/cogl/cogl-matrix-stack-private.h
+++ b/cogl/cogl/cogl-matrix-stack-private.h
@@ -97,9 +97,7 @@ typedef struct _CoglMatrixEntryRotateQuaternion
 {
   CoglMatrixEntry _parent_data;
 
-  /* This doesn't store an actual CoglQuaternion in order to avoid the
-   * padding */
-  float values[4];
+  graphene_quaternion_t quaternion;
 } CoglMatrixEntryRotateQuaternion;
 
 typedef struct _CoglMatrixEntryScale
diff --git a/cogl/cogl/cogl-matrix-stack.c b/cogl/cogl/cogl-matrix-stack.c
index e2e9b7d90..83d01480e 100644
--- a/cogl/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl/cogl-matrix-stack.c
@@ -182,17 +182,13 @@ cogl_matrix_stack_rotate (CoglMatrixStack *stack,
 
 void
 cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
-                                     const CoglQuaternion *quaternion)
+                                     const graphene_quaternion_t *quaternion)
 {
   CoglMatrixEntryRotateQuaternion *entry;
 
   entry = _cogl_matrix_stack_push_operation (stack,
                                              COGL_MATRIX_OP_ROTATE_QUATERNION);
-
-  entry->values[0] = quaternion->w;
-  entry->values[1] = quaternion->x;
-  entry->values[2] = quaternion->y;
-  entry->values[3] = quaternion->z;
+  graphene_quaternion_init_from_quaternion (&entry->quaternion, quaternion);
 }
 
 void
@@ -585,9 +581,7 @@ initialized:
           {
             CoglMatrixEntryRotateQuaternion *rotate =
               (CoglMatrixEntryRotateQuaternion *)children[i];
-            CoglQuaternion quaternion;
-            cogl_quaternion_init_from_array (&quaternion, rotate->values);
-            cogl_matrix_rotate_quaternion (matrix, &quaternion);
+            cogl_matrix_rotate_quaternion (matrix, &rotate->quaternion);
             continue;
           }
         case COGL_MATRIX_OP_SCALE:
@@ -987,10 +981,9 @@ cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
               (CoglMatrixEntryRotateQuaternion *)entry0;
             CoglMatrixEntryRotateQuaternion *rotate1 =
               (CoglMatrixEntryRotateQuaternion *)entry1;
-            int i;
-            for (i = 0; i < 4; i++)
-              if (rotate0->values[i] != rotate1->values[i])
-                return FALSE;
+            if (!graphene_quaternion_equal (&rotate0->quaternion,
+                                            &rotate1->quaternion))
+              return FALSE;
           }
           break;
         case COGL_MATRIX_OP_ROTATE_EULER:
@@ -1096,11 +1089,13 @@ cogl_debug_matrix_entry_print (CoglMatrixEntry *entry)
           {
             CoglMatrixEntryRotateQuaternion *rotate =
               (CoglMatrixEntryRotateQuaternion *)entry;
+            graphene_vec4_t v;
+            graphene_quaternion_to_vec4 (&rotate->quaternion, &v);
             g_print ("  ROTATE QUATERNION w=%f x=%f y=%f z=%f\n",
-                     rotate->values[0],
-                     rotate->values[1],
-                     rotate->values[2],
-                     rotate->values[3]);
+                     graphene_vec4_get_w (&v),
+                     graphene_vec4_get_x (&v),
+                     graphene_vec4_get_y (&v),
+                     graphene_vec4_get_z (&v));
             continue;
           }
         case COGL_MATRIX_OP_ROTATE_EULER:
diff --git a/cogl/cogl/cogl-matrix-stack.h b/cogl/cogl/cogl-matrix-stack.h
index 9ab4aa733..50dc9a255 100644
--- a/cogl/cogl/cogl-matrix-stack.h
+++ b/cogl/cogl/cogl-matrix-stack.h
@@ -310,14 +310,14 @@ cogl_matrix_stack_rotate (CoglMatrixStack *stack,
 /**
  * cogl_matrix_stack_rotate_quaternion:
  * @stack: A #CoglMatrixStack
- * @quaternion: A #CoglQuaternion
+ * @quaternion: A #graphene_quaternion_t
  *
  * Multiplies the current matrix by one that rotates according to the
  * rotation described by @quaternion.
  */
 void
 cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
-                                     const CoglQuaternion *quaternion);
+                                     const graphene_quaternion_t *quaternion);
 
 /**
  * cogl_matrix_stack_rotate_euler:
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index d1359c9e3..676ffe6da 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -73,11 +73,9 @@
 
 #include <cogl-util.h>
 #include <cogl-debug.h>
-#include <cogl-quaternion.h>
-#include <cogl-quaternion-private.h>
 #include <cogl-matrix.h>
 #include <cogl-matrix-private.h>
-#include <cogl-quaternion-private.h>
+#include <cogl-vector.h>
 
 #include <glib.h>
 #include <math.h>
@@ -1360,7 +1358,7 @@ cogl_matrix_rotate (CoglMatrix *matrix,
 
 void
 cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
-                               const CoglQuaternion *quaternion)
+                               const graphene_quaternion_t *quaternion)
 {
   CoglMatrix rotation_transform;
 
@@ -1737,22 +1735,25 @@ _cogl_matrix_init_from_matrix_without_inverse (CoglMatrix *matrix,
 
 static void
 _cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
-                                   const CoglQuaternion *quaternion)
+                                   const graphene_quaternion_t *quaternion)
 {
-  float qnorm = _COGL_QUATERNION_NORM (quaternion);
+  graphene_vec4_t quaternion_v;
+  graphene_quaternion_to_vec4 (quaternion, &quaternion_v);
+
+  float qnorm = graphene_quaternion_dot (quaternion, quaternion);
   float s = (qnorm > 0.0f) ? (2.0f / qnorm) : 0.0f;
-  float xs = quaternion->x * s;
-  float ys = quaternion->y * s;
-  float zs = quaternion->z * s;
-  float wx = quaternion->w * xs;
-  float wy = quaternion->w * ys;
-  float wz = quaternion->w * zs;
-  float xx = quaternion->x * xs;
-  float xy = quaternion->x * ys;
-  float xz = quaternion->x * zs;
-  float yy = quaternion->y * ys;
-  float yz = quaternion->y * zs;
-  float zz = quaternion->z * zs;
+  float xs = graphene_vec4_get_x (&quaternion_v) * s;
+  float ys = graphene_vec4_get_y (&quaternion_v) * s;
+  float zs = graphene_vec4_get_z (&quaternion_v) * s;
+  float wx = graphene_vec4_get_w (&quaternion_v) * xs;
+  float wy = graphene_vec4_get_w (&quaternion_v) * ys;
+  float wz = graphene_vec4_get_w (&quaternion_v) * zs;
+  float xx = graphene_vec4_get_x (&quaternion_v) * xs;
+  float xy = graphene_vec4_get_x (&quaternion_v) * ys;
+  float xz = graphene_vec4_get_x (&quaternion_v) * zs;
+  float yy = graphene_vec4_get_y (&quaternion_v) * ys;
+  float yz = graphene_vec4_get_y (&quaternion_v) * zs;
+  float zz = graphene_vec4_get_z (&quaternion_v) * zs;
 
   matrix->xx = 1.0f - (yy + zz);
   matrix->yx = xy + wz;
@@ -1772,7 +1773,7 @@ _cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
 
 void
 cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
-                                  const CoglQuaternion *quaternion)
+                                  const graphene_quaternion_t *quaternion)
 {
   _cogl_matrix_init_from_quaternion (matrix, quaternion);
 }
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 30af4ac7d..1eb897443 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -41,7 +41,6 @@
 #include <cogl/cogl-types.h>
 #include <cogl/cogl-macros.h>
 
-#include <cogl/cogl-quaternion.h>
 #include <glib-object.h>
 
 #include <graphene.h>
@@ -204,13 +203,13 @@ cogl_matrix_rotate (CoglMatrix *matrix,
  * @quaternion: A quaternion describing a rotation
  *
  * Multiplies @matrix with a rotation transformation described by the
- * given #CoglQuaternion.
+ * given #graphene_quaternion_t.
  *
  * Since: 2.0
  */
 void
 cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
-                               const CoglQuaternion *quaternion);
+                               const graphene_quaternion_t *quaternion);
 
 /**
  * cogl_matrix_rotate_euler:
@@ -520,13 +519,13 @@ cogl_matrix_get_array (const CoglMatrix *matrix);
 /**
  * cogl_matrix_init_from_quaternion:
  * @matrix: A 4x4 transformation matrix
- * @quaternion: A #CoglQuaternion
+ * @quaternion: A #graphene_quaternion_t
  *
- * Initializes @matrix from a #CoglQuaternion rotation.
+ * Initializes @matrix from a #graphene_quaternion_t rotation.
  */
 void
 cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
-                                  const CoglQuaternion *quaternion);
+                                  const graphene_quaternion_t *quaternion);
 
 /**
  * cogl_matrix_init_from_euler:
diff --git a/cogl/cogl/cogl-types.h b/cogl/cogl/cogl-types.h
index 6a3791c52..a3e755e22 100644
--- a/cogl/cogl/cogl-types.h
+++ b/cogl/cogl/cogl-types.h
@@ -117,10 +117,6 @@ cogl_handle_unref (CoglHandle handle);
  * between cogl-matrix.h and cogl-quaterion.h */
 typedef struct _CoglMatrix      CoglMatrix;
 
-/* Same as above we forward declared CoglQuaternion to avoid
- * circular dependencies. */
-typedef struct _CoglQuaternion CoglQuaternion;
-
 /**
  * CoglAngle:
  *
diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h
index 3b8f19714..b251b8950 100644
--- a/cogl/cogl/cogl.h
+++ b/cogl/cogl/cogl.h
@@ -103,7 +103,6 @@
 #include <cogl/cogl-buffer.h>
 #include <cogl/cogl-pixel-buffer.h>
 #include <cogl/cogl-vector.h>
-#include <cogl/cogl-quaternion.h>
 #include <cogl/cogl-texture-2d.h>
 #include <cogl/cogl-texture-2d-gl.h>
 #include <cogl/cogl-texture-rectangle.h>
diff --git a/cogl/cogl/cogl.symbols b/cogl/cogl/cogl.symbols
index b67d14de4..d3f1f5daa 100644
--- a/cogl/cogl/cogl.symbols
+++ b/cogl/cogl/cogl.symbols
@@ -749,31 +749,6 @@ cogl_push_gles2_context
 cogl_push_matrix
 cogl_push_source
 
-cogl_quaternion_copy
-cogl_quaternion_dot_product
-cogl_quaternion_equal
-cogl_quaternion_free
-#ifdef COGL_HAS_GTYPE_SUPPORT
-cogl_quaternion_get_gtype
-#endif
-cogl_quaternion_get_rotation_angle
-cogl_quaternion_get_rotation_axis
-cogl_quaternion_init
-cogl_quaternion_init_from_angle_vector
-cogl_quaternion_init_from_array
-cogl_quaternion_init_from_euler
-cogl_quaternion_init_from_x_rotation
-cogl_quaternion_init_from_y_rotation
-cogl_quaternion_init_from_z_rotation
-cogl_quaternion_init_identity
-cogl_quaternion_invert
-cogl_quaternion_multiply
-cogl_quaternion_nlerp
-cogl_quaternion_normalize
-cogl_quaternion_pow
-cogl_quaternion_slerp
-cogl_quaternion_squad
-
 cogl_read_pixels
 cogl_read_pixels_flags_get_type
 
diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build
index d6111ca4b..2aa3c0ce2 100644
--- a/cogl/cogl/meson.build
+++ b/cogl/cogl/meson.build
@@ -112,7 +112,6 @@ cogl_nonintrospected_headers = [
   'cogl-frame-info.h',
   'cogl-vector.h',
   'cogl-output.h',
-  'cogl-quaternion.h',
   'cogl-matrix-stack.h',
   'cogl-poll.h',
   'cogl-texture-3d.h',
@@ -268,8 +267,6 @@ cogl_sources = [
   'cogl-primitive.c',
   'cogl-matrix.c',
   'cogl-vector.c',
-  'cogl-quaternion-private.h',
-  'cogl-quaternion.c',
   'cogl-matrix-private.h',
   'cogl-matrix-stack.c',
   'cogl-matrix-stack-private.h',
diff --git a/cogl/tests/conform/test-euler-quaternion.c b/cogl/tests/conform/test-euler-quaternion.c
index 8aa413a19..eb23f1218 100644
--- a/cogl/tests/conform/test-euler-quaternion.c
+++ b/cogl/tests/conform/test-euler-quaternion.c
@@ -39,7 +39,7 @@ void
 test_euler_quaternion (void)
 {
   graphene_euler_t euler;
-  CoglQuaternion quaternion;
+  graphene_quaternion_t quaternion;
   CoglMatrix matrix_a, matrix_b;
 
   /* Try doing the rotation with three separate rotations */
@@ -56,7 +56,7 @@ test_euler_quaternion (void)
   COMPARE_MATRICES (&matrix_a, &matrix_b);
 
   /* Try converting the euler to a matrix via a quaternion */
-  cogl_quaternion_init_from_euler (&quaternion, &euler);
+  graphene_quaternion_init_from_euler (&quaternion, &euler);
   memset (&matrix_b, 0, sizeof (matrix_b));
   cogl_matrix_init_from_quaternion (&matrix_b, &quaternion);
   COMPARE_MATRICES (&matrix_a, &matrix_b);


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