[mutter] monitor-transform: Add helper to transform matrices



commit df27017ba379b29605107d46a28c2b4e4941b55a
Author: Robert Mader <robert mader posteo de>
Date:   Sun Jul 3 12:38:37 2022 +0200

    monitor-transform: Add helper to transform matrices
    
    Moved from `MetaShapedTexture` - it will be useful
    in several other places as well.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/344>

 src/backends/meta-monitor-transform.c | 49 +++++++++++++++++++++++++++++++++++
 src/backends/meta-monitor-transform.h |  3 +++
 src/compositor/meta-shaped-texture.c  | 45 ++------------------------------
 3 files changed, 54 insertions(+), 43 deletions(-)
---
diff --git a/src/backends/meta-monitor-transform.c b/src/backends/meta-monitor-transform.c
index 5706ad5de7..8acf8290e6 100644
--- a/src/backends/meta-monitor-transform.c
+++ b/src/backends/meta-monitor-transform.c
@@ -153,3 +153,52 @@ meta_monitor_transform_transform_point (MetaMonitorTransform  transform,
       break;
     }
 }
+
+void
+meta_monitor_transform_transform_matrix (MetaMonitorTransform  transform,
+                                         graphene_matrix_t    *matrix)
+{
+  graphene_euler_t euler;
+
+  if (transform == META_MONITOR_TRANSFORM_NORMAL)
+    return;
+
+  graphene_matrix_translate (matrix,
+                             &GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0.0));
+  switch (transform)
+    {
+    case META_MONITOR_TRANSFORM_90:
+      graphene_euler_init_with_order (&euler, 0.0, 0.0, 270.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_180:
+      graphene_euler_init_with_order (&euler, 0.0, 0.0, 180.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_270:
+      graphene_euler_init_with_order (&euler, 0.0, 0.0, 90.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED:
+      graphene_euler_init_with_order (&euler, 0.0, 180.0, 0.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_90:
+      graphene_euler_init_with_order (&euler, 0.0, 180.0, 90.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_180:
+      graphene_euler_init_with_order (&euler, 0.0, 180.0, 180.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_270:
+      graphene_euler_init_with_order (&euler, 0.0, 180.0, 270.0,
+                                      GRAPHENE_EULER_ORDER_SYXZ);
+      break;
+    case META_MONITOR_TRANSFORM_NORMAL:
+      g_assert_not_reached ();
+    }
+  graphene_matrix_rotate_euler (matrix, &euler);
+  graphene_matrix_translate (matrix,
+                             &GRAPHENE_POINT3D_INIT (0.5, 0.5, 0.0));
+}
diff --git a/src/backends/meta-monitor-transform.h b/src/backends/meta-monitor-transform.h
index 3449c14d7e..79677e8e2f 100644
--- a/src/backends/meta-monitor-transform.h
+++ b/src/backends/meta-monitor-transform.h
@@ -72,4 +72,7 @@ void meta_monitor_transform_transform_point (MetaMonitorTransform  transform,
                                              int                  *out_x,
                                              int                  *out_y);
 
+void meta_monitor_transform_transform_matrix (MetaMonitorTransform  transform,
+                                              graphene_matrix_t    *matrix);
+
 #endif /* META_MONITOR_TRANSFORM_H */
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index 679b6a18b1..bea77c1a11 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -310,49 +310,8 @@ get_base_pipeline (MetaShapedTexture *stex,
         }
     }
 
-  if (stex->transform != META_MONITOR_TRANSFORM_NORMAL)
-    {
-      graphene_euler_t euler;
-
-      graphene_matrix_translate (&matrix,
-                                 &GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0.0));
-      switch (stex->transform)
-        {
-        case META_MONITOR_TRANSFORM_90:
-          graphene_euler_init_with_order (&euler, 0.0, 0.0, 270.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_180:
-          graphene_euler_init_with_order (&euler, 0.0, 0.0, 180.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_270:
-          graphene_euler_init_with_order (&euler, 0.0, 0.0, 90.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_FLIPPED:
-          graphene_euler_init_with_order (&euler, 0.0, 180.0, 0.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_FLIPPED_90:
-          graphene_euler_init_with_order (&euler, 0.0, 180.0, 90.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_FLIPPED_180:
-          graphene_euler_init_with_order (&euler, 0.0, 180.0, 180.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_FLIPPED_270:
-          graphene_euler_init_with_order (&euler, 0.0, 180.0, 270.0,
-                                          GRAPHENE_EULER_ORDER_SYXZ);
-          break;
-        case META_MONITOR_TRANSFORM_NORMAL:
-          g_assert_not_reached ();
-        }
-      graphene_matrix_rotate_euler (&matrix, &euler);
-      graphene_matrix_translate (&matrix,
-                                 &GRAPHENE_POINT3D_INIT (0.5, 0.5, 0.0));
-    }
+  meta_monitor_transform_transform_matrix (stex->transform,
+                                           &matrix);
 
   cogl_pipeline_set_layer_matrix (pipeline, 1, &matrix);
 


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