From df27017ba379b29605107d46a28c2b4e4941b55a Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sun, 3 Jul 2022 12:38:37 +0200 Subject: [PATCH] monitor-transform: Add helper to transform matrices Moved from `MetaShapedTexture` - it will be useful in several other places as well. Part-of: --- 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 5706ad5de..8acf8290e 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 3449c14d7..79677e8e2 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 679b6a18b..bea77c1a1 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);