[mutter/gbsneto/graphene: 100/109] Replace CoglEuler by graphene_euler_t



commit 4a4a423182d46d16aa17449fa24c3312eda33fee
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Feb 16 09:41:43 2019 -0200

    Replace CoglEuler by graphene_euler_t
    
    As the first step into removing Cogl types that are covered by
    Graphene, remove CoglEuler and replace it by graphene_euler_t.
    
    This is a mostly straightforward replacement, except that the
    naming conventions changed a bit. Cogl uses "heading" for the
    Y axis, "pitch" for the X axis, and "roll" for the Z axis, and
    graphene uses the axis themselves. That means the 1st and 2nd
    arguments need to be swapped.
    
    Also adapt the matrix stack to store a graphene_euler_t in the
    rotation node -- that simplifies the code a bit as well.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/458

 cogl/cogl/cogl-euler.c                     | 196 ---------------------
 cogl/cogl/cogl-euler.h                     | 265 -----------------------------
 cogl/cogl/cogl-framebuffer.c               |   2 +-
 cogl/cogl/cogl-framebuffer.h               |   7 +-
 cogl/cogl/cogl-matrix-stack-private.h      |   6 +-
 cogl/cogl/cogl-matrix-stack.c              |  26 +--
 cogl/cogl/cogl-matrix-stack.h              |   5 +-
 cogl/cogl/cogl-matrix.c                    |  10 +-
 cogl/cogl/cogl-matrix.h                    |  12 +-
 cogl/cogl/cogl-quaternion.c                |  15 +-
 cogl/cogl/cogl-quaternion.h                |   7 +-
 cogl/cogl/cogl-types.h                     |   6 +-
 cogl/cogl/cogl.h                           |   3 +-
 cogl/cogl/cogl.symbols                     |  13 --
 cogl/cogl/meson.build                      |   2 -
 cogl/meson.build                           |   2 +-
 cogl/tests/conform/test-euler-quaternion.c |   4 +-
 src/compositor/meta-shaped-texture.c       |  23 ++-
 18 files changed, 61 insertions(+), 543 deletions(-)
---
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
index bd8a7fa42..42793574f 100644
--- a/cogl/cogl/cogl-framebuffer.c
+++ b/cogl/cogl/cogl-framebuffer.c
@@ -1616,7 +1616,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
 
 void
 cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer,
-                               const CoglEuler *euler)
+                               const graphene_euler_t *euler)
 {
   CoglMatrixStack *modelview_stack =
     _cogl_framebuffer_get_modelview_stack (framebuffer);
diff --git a/cogl/cogl/cogl-framebuffer.h b/cogl/cogl/cogl-framebuffer.h
index 48a77e1ed..5ba4cd8ac 100644
--- a/cogl/cogl/cogl-framebuffer.h
+++ b/cogl/cogl/cogl-framebuffer.h
@@ -52,10 +52,11 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
 #include <cogl/cogl-indices.h>
 #include <cogl/cogl-bitmap.h>
 #include <cogl/cogl-quaternion.h>
-#include <cogl/cogl-euler.h>
 #include <cogl/cogl-texture.h>
 #include <glib-object.h>
 
+#include <graphene.h>
+
 G_BEGIN_DECLS
 
 /**
@@ -379,7 +380,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
 /**
  * cogl_framebuffer_rotate_euler:
  * @framebuffer: A #CoglFramebuffer pointer
- * @euler: A #CoglEuler
+ * @euler: A #graphene_euler_t
  *
  * Multiplies the current model-view matrix by one that rotates
  * according to the rotation described by @euler.
@@ -389,7 +390,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
  */
 void
 cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer,
-                               const CoglEuler *euler);
+                               const graphene_euler_t *euler);
 
 /**
  * cogl_framebuffer_transform:
diff --git a/cogl/cogl/cogl-matrix-stack-private.h b/cogl/cogl/cogl-matrix-stack-private.h
index dec789b8a..f510d97d7 100644
--- a/cogl/cogl/cogl-matrix-stack-private.h
+++ b/cogl/cogl/cogl-matrix-stack-private.h
@@ -90,11 +90,7 @@ typedef struct _CoglMatrixEntryRotateEuler
 {
   CoglMatrixEntry _parent_data;
 
-  /* This doesn't store an actual CoglEuler in order to avoid the
-   * padding */
-  float heading;
-  float pitch;
-  float roll;
+  graphene_euler_t euler;
 } CoglMatrixEntryRotateEuler;
 
 typedef struct _CoglMatrixEntryRotateQuaternion
diff --git a/cogl/cogl/cogl-matrix-stack.c b/cogl/cogl/cogl-matrix-stack.c
index b058f1962..e2e9b7d90 100644
--- a/cogl/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl/cogl-matrix-stack.c
@@ -196,17 +196,14 @@ cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
 }
 
 void
-cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack,
-                                 const CoglEuler *euler)
+cogl_matrix_stack_rotate_euler (CoglMatrixStack        *stack,
+                                const graphene_euler_t *euler)
 {
   CoglMatrixEntryRotateEuler *entry;
 
   entry = _cogl_matrix_stack_push_operation (stack,
                                              COGL_MATRIX_OP_ROTATE_EULER);
-
-  entry->heading = euler->heading;
-  entry->pitch = euler->pitch;
-  entry->roll = euler->roll;
+  graphene_euler_init_from_euler (&entry->euler, euler);
 }
 
 void
@@ -580,13 +577,8 @@ initialized:
           {
             CoglMatrixEntryRotateEuler *rotate =
               (CoglMatrixEntryRotateEuler *)children[i];
-            CoglEuler euler;
-            cogl_euler_init (&euler,
-                             rotate->heading,
-                             rotate->pitch,
-                             rotate->roll);
             cogl_matrix_rotate_euler (matrix,
-                                      &euler);
+                                      &rotate->euler);
             continue;
           }
         case COGL_MATRIX_OP_ROTATE_QUATERNION:
@@ -1008,9 +1000,7 @@ cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
             CoglMatrixEntryRotateEuler *rotate1 =
               (CoglMatrixEntryRotateEuler *)entry1;
 
-            if (rotate0->heading != rotate1->heading ||
-                rotate0->pitch != rotate1->pitch ||
-                rotate0->roll != rotate1->roll)
+            if (!graphene_euler_equal (&rotate0->euler, &rotate1->euler))
               return FALSE;
           }
           break;
@@ -1118,9 +1108,9 @@ cogl_debug_matrix_entry_print (CoglMatrixEntry *entry)
             CoglMatrixEntryRotateEuler *rotate =
               (CoglMatrixEntryRotateEuler *)entry;
             g_print ("  ROTATE EULER heading=%f pitch=%f roll=%f\n",
-                     rotate->heading,
-                     rotate->pitch,
-                     rotate->roll);
+                     graphene_euler_get_y (&rotate->euler),
+                     graphene_euler_get_x (&rotate->euler),
+                     graphene_euler_get_z (&rotate->euler));
             continue;
           }
         case COGL_MATRIX_OP_SCALE:
diff --git a/cogl/cogl/cogl-matrix-stack.h b/cogl/cogl/cogl-matrix-stack.h
index 4be9f59c2..9ab4aa733 100644
--- a/cogl/cogl/cogl-matrix-stack.h
+++ b/cogl/cogl/cogl-matrix-stack.h
@@ -42,6 +42,7 @@
 #include "cogl-matrix.h"
 #include "cogl-context.h"
 
+#include <graphene.h>
 
 /**
  * SECTION:cogl-matrix-stack
@@ -321,14 +322,14 @@ cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
 /**
  * cogl_matrix_stack_rotate_euler:
  * @stack: A #CoglMatrixStack
- * @euler: A #CoglEuler
+ * @euler: A #graphene_euler_t
  *
  * Multiplies the current matrix by one that rotates according to the
  * rotation described by @euler.
  */
 void
 cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack,
-                                const CoglEuler *euler);
+                                const graphene_euler_t *euler);
 
 /**
  * cogl_matrix_stack_multiply:
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 6ae9c6755..d1359c9e3 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -1370,7 +1370,7 @@ cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
 
 void
 cogl_matrix_rotate_euler (CoglMatrix *matrix,
-                          const CoglEuler *euler)
+                          const graphene_euler_t *euler)
 {
   CoglMatrix rotation_transform;
 
@@ -1779,12 +1779,12 @@ cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
 
 void
 cogl_matrix_init_from_euler (CoglMatrix *matrix,
-                             const CoglEuler *euler)
+                             const graphene_euler_t *euler)
 {
   /* Convert angles to radians */
-  float heading_rad = euler->heading / 180.0f * G_PI;
-  float pitch_rad = euler->pitch / 180.0f * G_PI;
-  float roll_rad = euler->roll / 180.0f * G_PI;
+  float heading_rad = graphene_euler_get_y (euler) / 180.0f * G_PI;
+  float pitch_rad = graphene_euler_get_x (euler) / 180.0f * G_PI;
+  float roll_rad = graphene_euler_get_z (euler) / 180.0f * G_PI;
   /* Pre-calculate the sin and cos */
   float sin_heading = sinf (heading_rad);
   float cos_heading = cosf (heading_rad);
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 6d8ddb433..30af4ac7d 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -44,6 +44,8 @@
 #include <cogl/cogl-quaternion.h>
 #include <glib-object.h>
 
+#include <graphene.h>
+
 G_BEGIN_DECLS
 
 /**
@@ -216,13 +218,13 @@ cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
  * @euler: A euler describing a rotation
  *
  * Multiplies @matrix with a rotation transformation described by the
- * given #CoglEuler.
+ * given #graphene_euler_t.
  *
  * Since: 2.0
  */
 void
 cogl_matrix_rotate_euler (CoglMatrix *matrix,
-                          const CoglEuler *euler);
+                          const graphene_euler_t *euler);
 
 /**
  * cogl_matrix_translate:
@@ -529,13 +531,13 @@ cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
 /**
  * cogl_matrix_init_from_euler:
  * @matrix: A 4x4 transformation matrix
- * @euler: A #CoglEuler
+ * @euler: A #graphene_euler_t
  *
- * Initializes @matrix from a #CoglEuler rotation.
+ * Initializes @matrix from a #graphene_euler_t rotation.
  */
 void
 cogl_matrix_init_from_euler (CoglMatrix *matrix,
-                             const CoglEuler *euler);
+                             const graphene_euler_t *euler);
 
 /**
  * cogl_matrix_equal:
diff --git a/cogl/cogl/cogl-quaternion.c b/cogl/cogl/cogl-quaternion.c
index e4fc4644c..36d507c19 100644
--- a/cogl/cogl/cogl-quaternion.c
+++ b/cogl/cogl/cogl-quaternion.c
@@ -46,7 +46,6 @@
 #include <cogl-quaternion-private.h>
 #include <cogl-matrix.h>
 #include <cogl-vector.h>
-#include <cogl-euler.h>
 #include "cogl-gtype-private.h"
 
 #include <string.h>
@@ -200,24 +199,24 @@ cogl_quaternion_init_from_z_rotation (CoglQuaternion *quaternion,
 
 void
 cogl_quaternion_init_from_euler (CoglQuaternion *quaternion,
-                                 const CoglEuler *euler)
+                                 const graphene_euler_t *euler)
 {
   /* NB: We are using quaternions to represent an axis (a), angle (𝜃) pair
    * in this form:
    * [w=cos(𝜃/2) ( x=sin(𝜃/2)*a.x, y=sin(𝜃/2)*a.y, z=sin(𝜃/2)*a.x )]
    */
   float sin_heading =
-    sinf (euler->heading * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    sinf (graphene_euler_get_y (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
   float sin_pitch =
-    sinf (euler->pitch * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    sinf (graphene_euler_get_x (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
   float sin_roll =
-    sinf (euler->roll * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    sinf (graphene_euler_get_z (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
   float cos_heading =
-    cosf (euler->heading * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    cosf (graphene_euler_get_y (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
   float cos_pitch =
-    cosf (euler->pitch * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    cosf (graphene_euler_get_x (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
   float cos_roll =
-    cosf (euler->roll * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
+    cosf (graphene_euler_get_z (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
 
   quaternion->w =
     cos_heading * cos_pitch * cos_roll +
diff --git a/cogl/cogl/cogl-quaternion.h b/cogl/cogl/cogl-quaternion.h
index 6e8db6bf8..c6c6d504e 100644
--- a/cogl/cogl/cogl-quaternion.h
+++ b/cogl/cogl/cogl-quaternion.h
@@ -36,6 +36,8 @@
 #ifndef __COGL_QUATERNION_H__
 #define __COGL_QUATERNION_H__
 
+#include <graphene.h>
+
 #include <cogl/cogl-types.h>
 #include <cogl/cogl-vector.h>
 
@@ -57,7 +59,6 @@ G_BEGIN_DECLS
  * .
  */
 #include <cogl/cogl-vector.h>
-#include <cogl/cogl-euler.h>
 
 #include <glib-object.h>
 
@@ -269,13 +270,13 @@ cogl_quaternion_init_from_z_rotation (CoglQuaternion *quaternion,
 /**
  * cogl_quaternion_init_from_euler:
  * @quaternion: A #CoglQuaternion
- * @euler: A #CoglEuler with which to initialize the quaternion
+ * @euler: A #graphene_euler_t with which to initialize the quaternion
  *
  * Since: 2.0
  */
 void
 cogl_quaternion_init_from_euler (CoglQuaternion *quaternion,
-                                 const CoglEuler *euler);
+                                 const graphene_euler_t *euler);
 
 /**
  * cogl_quaternion_init_from_quaternion:
diff --git a/cogl/cogl/cogl-types.h b/cogl/cogl/cogl-types.h
index 655d2882e..81a6ea478 100644
--- a/cogl/cogl/cogl-types.h
+++ b/cogl/cogl/cogl-types.h
@@ -114,17 +114,13 @@ void
 cogl_handle_unref (CoglHandle handle);
 
 /* We forward declare this in cogl-types to avoid circular dependencies
- * between cogl-matrix.h, cogl-euler.h and cogl-quaterion.h */
+ * 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;
 
-/* Same as above we forward declared CoglEuler to avoid
- * circular dependencies. */
-typedef struct _CoglEuler CoglEuler;
-
 /**
  * CoglAngle:
  *
diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h
index 565ea289a..3b8f19714 100644
--- a/cogl/cogl/cogl.h
+++ b/cogl/cogl/cogl.h
@@ -42,6 +42,8 @@
 #define __COGL_MUST_UNDEF_COGL_H_INSIDE__
 #endif
 
+#include <graphene.h>
+
 /* We currently keep gtype integration delimited in case we eventually
  * want to split it out into a separate utility library when Cogl
  * becomes a standalone project. (like cairo-gobject.so)
@@ -101,7 +103,6 @@
 #include <cogl/cogl-buffer.h>
 #include <cogl/cogl-pixel-buffer.h>
 #include <cogl/cogl-vector.h>
-#include <cogl/cogl-euler.h>
 #include <cogl/cogl-quaternion.h>
 #include <cogl/cogl-texture-2d.h>
 #include <cogl/cogl-texture-2d-gl.h>
diff --git a/cogl/cogl/cogl.symbols b/cogl/cogl/cogl.symbols
index 6036e2eda..b67d14de4 100644
--- a/cogl/cogl/cogl.symbols
+++ b/cogl/cogl/cogl.symbols
@@ -203,19 +203,6 @@ cogl_error_copy
 cogl_error_free
 cogl_error_matches
 
-cogl_euler_copy
-cogl_euler_equal
-cogl_euler_free
-#ifdef COGL_HAS_GTYPE_SUPPORT
-cogl_euler_get_gtype
-#endif
-cogl_euler_init
-cogl_euler_init_from_matrix
-#if 0
-/* not yet implemented */
-cogl_euler_init_from_quaternion
-#endif
-
 cogl_features_available
 cogl_feature_flags_get_type
 cogl_fence_closure_get_user_data
diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build
index 64d00a493..bd741c749 100644
--- a/cogl/cogl/meson.build
+++ b/cogl/cogl/meson.build
@@ -114,7 +114,6 @@ cogl_nonintrospected_headers = [
   'cogl-primitive.h',
   'cogl-frame-info.h',
   'cogl-vector.h',
-  'cogl-euler.h',
   'cogl-output.h',
   'cogl-quaternion.h',
   'cogl-matrix-stack.h',
@@ -270,7 +269,6 @@ cogl_sources = [
   'cogl-primitive.c',
   'cogl-matrix.c',
   'cogl-vector.c',
-  'cogl-euler.c',
   'cogl-quaternion-private.h',
   'cogl-quaternion.c',
   'cogl-matrix-private.h',
diff --git a/cogl/meson.build b/cogl/meson.build
index 3d359a2fe..cc32e9f7f 100644
--- a/cogl/meson.build
+++ b/cogl/meson.build
@@ -24,13 +24,13 @@ cogl_mutter_config_h = configure_file(
 cogl_pkg_deps = [
   glib_dep,
   gobject_dep,
+  graphene_dep,
 ]
 
 cogl_pkg_private_deps = [
   cairo_dep,
   gmodule_no_export_dep,
   gdk_pixbuf_dep,
-  graphene_dep,
   #uprof_dep,
 ]
 
diff --git a/cogl/tests/conform/test-euler-quaternion.c b/cogl/tests/conform/test-euler-quaternion.c
index 312667162..8aa413a19 100644
--- a/cogl/tests/conform/test-euler-quaternion.c
+++ b/cogl/tests/conform/test-euler-quaternion.c
@@ -38,7 +38,7 @@
 void
 test_euler_quaternion (void)
 {
-  CoglEuler euler;
+  graphene_euler_t euler;
   CoglQuaternion quaternion;
   CoglMatrix matrix_a, matrix_b;
 
@@ -49,7 +49,7 @@ test_euler_quaternion (void)
   cogl_matrix_rotate (&matrix_a, 50.0f, 0.0f, 0.0f, 1.0f);
 
   /* And try the same rotation with a euler */
-  cogl_euler_init (&euler, -30, 40, 50);
+  graphene_euler_init_with_order (&euler, 40, -30, 50, GRAPHENE_EULER_ORDER_YXZ);
   cogl_matrix_init_from_euler (&matrix_b, &euler);
 
   /* Verify that the matrices are approximately the same */
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index d64e214e5..37ca1b1e7 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -341,32 +341,39 @@ get_base_pipeline (MetaShapedTexture *stex,
 
   if (stex->transform != META_MONITOR_TRANSFORM_NORMAL)
     {
+      graphene_euler_t euler;
       CoglMatrix matrix;
-      CoglEuler euler;
 
       cogl_matrix_init_translation (&matrix, 0.5, 0.5, 0.0);
       switch (stex->transform)
         {
         case META_MONITOR_TRANSFORM_90:
-          cogl_euler_init (&euler, 0.0, 0.0, 90.0);
+          graphene_euler_init_with_order (&euler, 0.0, 0.0, 90.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_180:
-          cogl_euler_init (&euler, 0.0, 0.0, 180.0);
+          graphene_euler_init_with_order (&euler, 0.0, 0.0, 180.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_270:
-          cogl_euler_init (&euler, 0.0, 0.0, 270.0);
+          graphene_euler_init_with_order (&euler, 0.0, 0.0, 270.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_FLIPPED:
-          cogl_euler_init (&euler, 180.0, 0.0, 0.0);
+          graphene_euler_init_with_order (&euler, 0.0, 180.0, 0.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_FLIPPED_90:
-          cogl_euler_init (&euler, 0.0, 180.0, 90.0);
+          graphene_euler_init_with_order (&euler, 180.0, 0.0, 90.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_FLIPPED_180:
-          cogl_euler_init (&euler, 180.0, 0.0, 180.0);
+          graphene_euler_init_with_order (&euler, 0.0, 180.0, 180.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_FLIPPED_270:
-          cogl_euler_init (&euler, 0.0, 180.0, 270.0);
+          graphene_euler_init_with_order (&euler, 180.0, 0.0, 270.0,
+                                          GRAPHENE_EULER_ORDER_YXZ);
           break;
         case META_MONITOR_TRANSFORM_NORMAL:
           g_assert_not_reached ();


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