gsk/gl/renderjob: Decompose matrix for 3D transforms
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sat, 1 Apr 2023 14:38:22 +0000 (11:38 -0300)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Apr 2023 06:58:17 +0000 (08:58 +0200)
While this can be more expensive, it's also correct.

gsk/gl/gskglrenderjob.c

index 9aa5123cdcf773bb9c99742403181c224439fb74..863d1efd316a67b1f6bf05e96429770d2be74b7d 100644 (file)
@@ -563,23 +563,21 @@ extract_matrix_metadata (GskGLRenderModelview *modelview)
     case GSK_TRANSFORM_CATEGORY_ANY:
     case GSK_TRANSFORM_CATEGORY_3D:
       {
-        graphene_vec3_t col1;
-        graphene_vec3_t col2;
-
-        /* TODO: 90% sure this is incorrect. But we should never hit this code
-         * path anyway. */
-        graphene_vec3_init (&col1,
-                            graphene_matrix_get_value (&modelview->matrix, 0, 0),
-                            graphene_matrix_get_value (&modelview->matrix, 1, 0),
-                            graphene_matrix_get_value (&modelview->matrix, 2, 0));
-
-        graphene_vec3_init (&col2,
-                            graphene_matrix_get_value (&modelview->matrix, 0, 1),
-                            graphene_matrix_get_value (&modelview->matrix, 1, 1),
-                            graphene_matrix_get_value (&modelview->matrix, 2, 1));
-
-        modelview->scale_x = graphene_vec3_length (&col1);
-        modelview->scale_y = graphene_vec3_length (&col2);
+        graphene_quaternion_t rotation;
+        graphene_vec4_t perspective;
+        graphene_vec3_t translation;
+        graphene_vec3_t scale;
+        graphene_vec3_t shear;
+
+        graphene_matrix_decompose (&modelview->matrix,
+                                   &translation,
+                                   &scale,
+                                   &rotation,
+                                   &shear,
+                                   &perspective);
+
+        modelview->scale_x = graphene_vec3_get_x (&scale);
+        modelview->scale_y = graphene_vec3_get_y (&scale);
         modelview->dx = 0;
         modelview->dy = 0;
       }