[mutter] backends/native: Use MetaKmsPlaneRotation in plane updates



commit 4e3f3842a1211e8b4274afdadcb2820e25ce6628
Author: Sebastian Wick <sebastian wick redhat com>
Date:   Wed Apr 20 22:54:27 2022 +0200

    backends/native: Use MetaKmsPlaneRotation in plane updates
    
    The ImplDeviceAtomic converts the MetaKmsPlaneRotation back to the
    concrete KMS value. The MetaMonitorTransform is always directly
    converted to a MetaKmsPlaneRotation.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2379>

 src/backends/native/meta-kms-connector-private.h  |   4 +
 src/backends/native/meta-kms-connector.c          |   9 ++
 src/backends/native/meta-kms-crtc-private.h       |   4 +
 src/backends/native/meta-kms-crtc.c               |   9 ++
 src/backends/native/meta-kms-impl-device-atomic.c |  25 +++--
 src/backends/native/meta-kms-plane-private.h      |   4 +
 src/backends/native/meta-kms-plane.c              | 124 +++++++++++++---------
 src/backends/native/meta-kms-update-private.h     |   6 +-
 src/backends/native/meta-kms-update.c             |   2 +-
 9 files changed, 124 insertions(+), 63 deletions(-)
---
diff --git a/src/backends/native/meta-kms-connector-private.h 
b/src/backends/native/meta-kms-connector-private.h
index 3dd2b84407..f4d3bbf143 100644
--- a/src/backends/native/meta-kms-connector-private.h
+++ b/src/backends/native/meta-kms-connector-private.h
@@ -97,6 +97,10 @@ uint32_t meta_kms_connector_get_prop_id (MetaKmsConnector     *connector,
 const char * meta_kms_connector_get_prop_name (MetaKmsConnector     *connector,
                                                MetaKmsConnectorProp  prop);
 
+uint64_t meta_kms_connector_get_prop_drm_value (MetaKmsConnector     *connector,
+                                                MetaKmsConnectorProp  prop,
+                                                uint64_t              value);
+
 MetaKmsUpdateChanges meta_kms_connector_update_state (MetaKmsConnector *connector,
                                                       drmModeRes       *drm_resources);
 
diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c
index 7cd66f6f0c..36d7960310 100644
--- a/src/backends/native/meta-kms-connector.c
+++ b/src/backends/native/meta-kms-connector.c
@@ -94,6 +94,15 @@ meta_kms_connector_get_prop_name (MetaKmsConnector     *connector,
   return connector->prop_table.props[prop].name;
 }
 
+uint64_t
+meta_kms_connector_get_prop_drm_value (MetaKmsConnector     *connector,
+                                       MetaKmsConnectorProp  property,
+                                       uint64_t              value)
+{
+  MetaKmsProp *prop = &connector->prop_table.props[property];
+  return meta_kms_prop_convert_value (prop, value);
+}
+
 uint32_t
 meta_kms_connector_get_connector_type (MetaKmsConnector *connector)
 {
diff --git a/src/backends/native/meta-kms-crtc-private.h b/src/backends/native/meta-kms-crtc-private.h
index 65bda3f10b..0efb3e71b4 100644
--- a/src/backends/native/meta-kms-crtc-private.h
+++ b/src/backends/native/meta-kms-crtc-private.h
@@ -51,4 +51,8 @@ uint32_t meta_kms_crtc_get_prop_id (MetaKmsCrtc     *crtc,
 const char * meta_kms_crtc_get_prop_name (MetaKmsCrtc     *crtc,
                                           MetaKmsCrtcProp  prop);
 
+uint64_t meta_kms_crtc_get_prop_drm_value (MetaKmsCrtc     *crtc,
+                                           MetaKmsCrtcProp  prop,
+                                           uint64_t         value);
+
 #endif /* META_KMS_CRTC_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-crtc.c b/src/backends/native/meta-kms-crtc.c
index cd8f570f10..c5bab91bbc 100644
--- a/src/backends/native/meta-kms-crtc.c
+++ b/src/backends/native/meta-kms-crtc.c
@@ -86,6 +86,15 @@ meta_kms_crtc_get_prop_name (MetaKmsCrtc     *crtc,
   return crtc->prop_table.props[prop].name;
 }
 
+uint64_t
+meta_kms_crtc_get_prop_drm_value (MetaKmsCrtc     *crtc,
+                                  MetaKmsCrtcProp  property,
+                                  uint64_t         value)
+{
+  MetaKmsProp *prop = &crtc->prop_table.props[property];
+  return meta_kms_prop_convert_value (prop, value);
+}
+
 gboolean
 meta_kms_crtc_is_active (MetaKmsCrtc *crtc)
 {
diff --git a/src/backends/native/meta-kms-impl-device-atomic.c 
b/src/backends/native/meta-kms-impl-device-atomic.c
index 73dd8e6971..36cf6c39da 100644
--- a/src/backends/native/meta-kms-impl-device-atomic.c
+++ b/src/backends/native/meta-kms-impl-device-atomic.c
@@ -114,6 +114,8 @@ add_connector_property (MetaKmsImplDevice     *impl_device,
       return FALSE;
     }
 
+  value = meta_kms_connector_get_prop_drm_value (connector, prop, value);
+
   meta_topic (META_DEBUG_KMS,
               "[atomic] Setting connector %u (%s) property '%s' (%u) to %"
               G_GUINT64_FORMAT,
@@ -165,15 +167,17 @@ process_connector_update (MetaKmsImplDevice  *impl_device,
       if (!add_connector_property (impl_device,
                                    connector, req,
                                    META_KMS_CONNECTOR_PROP_UNDERSCAN,
-                                   1,
+                                   META_KMS_CONNECTOR_UNDERSCAN_ON,
                                    error))
         return FALSE;
+
       if (!add_connector_property (impl_device,
                                    connector, req,
                                    META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER,
                                    connector_update->underscanning.hborder,
                                    error))
         return FALSE;
+
       if (!add_connector_property (impl_device,
                                    connector, req,
                                    META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER,
@@ -191,7 +195,7 @@ process_connector_update (MetaKmsImplDevice  *impl_device,
       if (!add_connector_property (impl_device,
                                    connector, req,
                                    META_KMS_CONNECTOR_PROP_UNDERSCAN,
-                                   0,
+                                   META_KMS_CONNECTOR_UNDERSCAN_OFF,
                                    error))
         return FALSE;
     }
@@ -207,7 +211,9 @@ process_connector_update (MetaKmsImplDevice  *impl_device,
       if (!add_connector_property (impl_device,
                                    connector, req,
                                    META_KMS_CONNECTOR_PROP_PRIVACY_SCREEN_SW_STATE,
-                                   connector_update->privacy_screen.is_enabled,
+                                   connector_update->privacy_screen.is_enabled ?
+                                     META_KMS_CONNECTOR_PRIVACY_SCREEN_ENABLED :
+                                     META_KMS_CONNECTOR_PRIVACY_SCREEN_DISABLED,
                                    error))
         return FALSE;
     }
@@ -235,6 +241,8 @@ add_crtc_property (MetaKmsImplDevice  *impl_device,
       return FALSE;
     }
 
+  value = meta_kms_crtc_get_prop_drm_value (crtc, prop, value);
+
   meta_topic (META_DEBUG_KMS,
               "[atomic] Setting CRTC %u (%s) property '%s' (%u) to %"
               G_GUINT64_FORMAT,
@@ -364,6 +372,8 @@ add_plane_property (MetaKmsImplDevice  *impl_device,
       return FALSE;
     }
 
+  value = meta_kms_plane_get_prop_drm_value (plane, prop, value);
+
   switch (meta_kms_plane_get_prop_internal_type (plane, prop))
     {
     case META_KMS_PROP_TYPE_RAW:
@@ -546,17 +556,14 @@ process_plane_assignment (MetaKmsImplDevice  *impl_device,
   if (plane_assignment->rotation)
     {
       meta_topic (META_DEBUG_KMS,
-                  "[atomic] Setting plane (%u, %s) rotation to %"
-                  G_GUINT64_FORMAT,
+                  "[atomic] Setting plane (%u, %s) rotation to %u",
                   meta_kms_plane_get_id (plane),
                   meta_kms_impl_device_get_path (impl_device),
                   plane_assignment->rotation);
 
-      if (!add_plane_property (impl_device,
-                               plane, req,
+      if (!add_plane_property (impl_device, plane, req,
                                META_KMS_PLANE_PROP_ROTATION,
-                               plane_assignment->rotation,
-                               error))
+                               plane_assignment->rotation, error))
         return FALSE;
     }
 
diff --git a/src/backends/native/meta-kms-plane-private.h b/src/backends/native/meta-kms-plane-private.h
index 7dcb7f0c04..c5bfa6fa1f 100644
--- a/src/backends/native/meta-kms-plane-private.h
+++ b/src/backends/native/meta-kms-plane-private.h
@@ -81,6 +81,10 @@ uint32_t meta_kms_plane_get_prop_id (MetaKmsPlane     *plane,
 const char * meta_kms_plane_get_prop_name (MetaKmsPlane     *plane,
                                            MetaKmsPlaneProp  prop);
 
+uint64_t meta_kms_plane_get_prop_drm_value (MetaKmsPlane     *plane,
+                                            MetaKmsPlaneProp  prop,
+                                            uint64_t          value);
+
 MetaKmsPropType meta_kms_plane_get_prop_internal_type (MetaKmsPlane     *plane,
                                                        MetaKmsPlaneProp  prop);
 
diff --git a/src/backends/native/meta-kms-plane.c b/src/backends/native/meta-kms-plane.c
index ad4f46f005..47e45ee23b 100644
--- a/src/backends/native/meta-kms-plane.c
+++ b/src/backends/native/meta-kms-plane.c
@@ -47,8 +47,7 @@ struct _MetaKmsPlane
 
   uint32_t possible_crtcs;
 
-  uint32_t rotation_map[META_MONITOR_N_TRANSFORMS];
-  uint32_t all_hw_transforms;
+  MetaKmsPlaneRotation rotations;
 
   /*
    * primary plane's supported formats and maybe modifiers
@@ -105,15 +104,59 @@ meta_kms_plane_get_prop_internal_type (MetaKmsPlane     *plane,
   return plane->prop_table.props[prop].internal_type;
 }
 
+uint64_t
+meta_kms_plane_get_prop_drm_value (MetaKmsPlane     *plane,
+                                   MetaKmsPlaneProp  property,
+                                   uint64_t          value)
+{
+  MetaKmsProp *prop = &plane->prop_table.props[property];
+  return meta_kms_prop_convert_value (prop, value);
+}
+
 void
 meta_kms_plane_update_set_rotation (MetaKmsPlane           *plane,
                                     MetaKmsPlaneAssignment *plane_assignment,
                                     MetaMonitorTransform    transform)
 {
+  MetaKmsPlaneRotation kms_rotation = 0;
+
   g_return_if_fail (meta_kms_plane_is_transform_handled (plane, transform));
 
-  meta_kms_plane_assignment_set_rotation (plane_assignment,
-                                          plane->rotation_map[transform]);
+  switch (transform)
+    {
+    case META_MONITOR_TRANSFORM_NORMAL:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_0;
+      break;
+    case META_MONITOR_TRANSFORM_90:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_90;
+      break;
+    case META_MONITOR_TRANSFORM_180:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_180;
+      break;
+    case META_MONITOR_TRANSFORM_270:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_270;
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_0 |
+                     META_KMS_PLANE_ROTATION_REFLECT_X;
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_90:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_90 |
+                     META_KMS_PLANE_ROTATION_REFLECT_X;
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_180:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_180 |
+                     META_KMS_PLANE_ROTATION_REFLECT_X;
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_270:
+      kms_rotation = META_KMS_PLANE_ROTATION_ROTATE_270 |
+                     META_KMS_PLANE_ROTATION_REFLECT_X;
+      break;
+    default:
+      g_assert_not_reached ();
+    }
+
+  meta_kms_plane_assignment_set_rotation (plane_assignment, kms_rotation);
 }
 
 gboolean
@@ -123,23 +166,29 @@ meta_kms_plane_is_transform_handled (MetaKmsPlane         *plane,
   switch (transform)
     {
     case META_MONITOR_TRANSFORM_NORMAL:
+      return plane->rotations & META_KMS_PLANE_ROTATION_ROTATE_0;
     case META_MONITOR_TRANSFORM_180:
+      return plane->rotations & META_KMS_PLANE_ROTATION_ROTATE_180;
     case META_MONITOR_TRANSFORM_FLIPPED:
+      return plane->rotations & (META_KMS_PLANE_ROTATION_ROTATE_0 |
+                                 META_KMS_PLANE_ROTATION_REFLECT_X);
     case META_MONITOR_TRANSFORM_FLIPPED_180:
-      break;
+      return plane->rotations & (META_KMS_PLANE_ROTATION_ROTATE_180 |
+                                 META_KMS_PLANE_ROTATION_REFLECT_X);
+    /*
+     * Deny these transforms as testing shows that they don't work
+     * anyway, e.g. due to the wrong buffer modifiers. They might as well be
+     * less optimal due to the complexity dealing with rotation at scan-out,
+     * potentially resulting in higher power consumption.
+     */
     case META_MONITOR_TRANSFORM_90:
     case META_MONITOR_TRANSFORM_270:
     case META_MONITOR_TRANSFORM_FLIPPED_90:
     case META_MONITOR_TRANSFORM_FLIPPED_270:
-      /*
-       * Blacklist these transforms as testing shows that they don't work
-       * anyway, e.g. due to the wrong buffer modifiers. They might as well be
-       * less optimal due to the complexity dealing with rotation at scan-out,
-       * potentially resulting in higher power consumption.
-       */
       return FALSE;
     }
-  return plane->all_hw_transforms & (1 << transform);
+
+  return FALSE;
 }
 
 GArray *
@@ -189,44 +238,6 @@ meta_kms_plane_is_usable_with (MetaKmsPlane *plane,
   return !!(plane->possible_crtcs & (1 << meta_kms_crtc_get_idx (crtc)));
 }
 
-static void
-update_rotations (MetaKmsPlane *plane)
-{
-  MetaKmsProp *prop;
-  MetaKmsPlaneRotation rotation;
-
-  prop = &plane->prop_table.props[META_KMS_PLANE_PROP_ROTATION];
-  rotation = prop->value;
-
-  if (rotation & META_KMS_PLANE_ROTATION_ROTATE_0)
-    {
-      plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_NORMAL;
-      plane->rotation_map[META_MONITOR_TRANSFORM_NORMAL] =
-        1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_0].value;
-    }
-
-  if (rotation & META_KMS_PLANE_ROTATION_ROTATE_90)
-    {
-      plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_90;
-      plane->rotation_map[META_MONITOR_TRANSFORM_90] =
-        1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_90].value;
-    }
-
-  if (rotation & META_KMS_PLANE_ROTATION_ROTATE_180)
-    {
-      plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_180;
-      plane->rotation_map[META_MONITOR_TRANSFORM_180] =
-        1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_180].value;
-    }
-
-  if (rotation & META_KMS_PLANE_ROTATION_ROTATE_270)
-    {
-      plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_270;
-      plane->rotation_map[META_MONITOR_TRANSFORM_270] =
-        1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_270].value;
-    }
-}
-
 static inline uint32_t *
 drm_formats_ptr (struct drm_format_modifier_blob *blob)
 {
@@ -369,6 +380,19 @@ update_legacy_formats (MetaKmsPlane *plane,
     }
 }
 
+static void
+update_rotations (MetaKmsPlane *plane)
+{
+  unsigned int i;
+  MetaKmsProp *rotation = &plane->prop_table.props[META_KMS_PLANE_PROP_ROTATION];
+
+  for (i = 0; i < rotation->num_enum_values; i++)
+    {
+      if (rotation->enum_values[i].valid)
+        plane->rotations |= rotation->enum_values[i].bitmask;
+    }
+}
+
 static MetaKmsUpdateChanges
 meta_kms_plane_read_state (MetaKmsPlane            *plane,
                            MetaKmsImplDevice       *impl_device,
diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h
index a613cbc5d6..9dab7c133c 100644
--- a/src/backends/native/meta-kms-update-private.h
+++ b/src/backends/native/meta-kms-update-private.h
@@ -23,6 +23,7 @@
 #include <glib.h>
 #include <stdint.h>
 
+#include "backends/native/meta-kms-plane-private.h"
 #include "backends/native/meta-kms-types.h"
 #include "backends/native/meta-kms-update.h"
 
@@ -50,8 +51,7 @@ typedef struct _MetaKmsPlaneAssignment
   MetaRectangle dst_rect;
   MetaKmsAssignPlaneFlag flags;
   MetaKmsFbDamage *fb_damage;
-
-  uint64_t rotation;
+  MetaKmsPlaneRotation rotation;
 
   struct {
     gboolean is_valid;
@@ -133,7 +133,7 @@ META_EXPORT_TEST
 MetaKmsDevice * meta_kms_update_get_device (MetaKmsUpdate *update);
 
 void meta_kms_plane_assignment_set_rotation (MetaKmsPlaneAssignment *plane_assignment,
-                                             uint64_t                rotation);
+                                             MetaKmsPlaneRotation    rotation);
 
 META_EXPORT_TEST
 MetaKmsPlaneAssignment * meta_kms_update_get_primary_plane_assignment (MetaKmsUpdate *update,
diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c
index 53fc92eb86..042714d0aa 100644
--- a/src/backends/native/meta-kms-update.c
+++ b/src/backends/native/meta-kms-update.c
@@ -497,7 +497,7 @@ meta_kms_plane_assignment_set_fb_damage (MetaKmsPlaneAssignment *plane_assignmen
 
 void
 meta_kms_plane_assignment_set_rotation (MetaKmsPlaneAssignment *plane_assignment,
-                                        uint64_t                rotation)
+                                        MetaKmsPlaneRotation    rotation)
 {
   g_assert (!meta_kms_update_is_locked (plane_assignment->update));
   g_warn_if_fail (rotation);


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