Blame SOURCES/0001-kms-Allow-passing-framebuffer-damage-metadata.patch

5c9faf
From af0460d0cedd5a66b2110ab2a99e67c647e7b6fb Mon Sep 17 00:00:00 2001
5c9faf
From: Piotr Lopatka <piotr.lopatka@gmail.com>
5c9faf
Date: Fri, 3 Sep 2021 19:39:12 +0100
5c9faf
Subject: [PATCH 1/2] kms: Allow passing framebuffer damage metadata
5c9faf
5c9faf
This commit adds support to atomic KMS backend for optional plane property
5c9faf
prop_fb_damage_clips. Some drivers (e.g. EVDI) take advantage of this
5c9faf
property and process only updated regions of the screen instead of
5c9faf
processing the full frame. This can save system resources.
5c9faf
5c9faf
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1879>
5c9faf
---
5c9faf
 .../native/meta-kms-impl-device-atomic.c      | 28 +++++++++++++++
5c9faf
 src/backends/native/meta-kms-plane-private.h  |  1 +
5c9faf
 src/backends/native/meta-kms-plane.c          |  5 +++
5c9faf
 src/backends/native/meta-kms-update-private.h |  7 ++++
5c9faf
 src/backends/native/meta-kms-update.c         | 35 +++++++++++++++++++
5c9faf
 src/backends/native/meta-kms-update.h         |  4 +++
5c9faf
 6 files changed, 80 insertions(+)
5c9faf
5c9faf
diff --git a/src/backends/native/meta-kms-impl-device-atomic.c b/src/backends/native/meta-kms-impl-device-atomic.c
5c9faf
index 8e41207ee14..674a24902bd 100644
5c9faf
--- a/src/backends/native/meta-kms-impl-device-atomic.c
5c9faf
+++ b/src/backends/native/meta-kms-impl-device-atomic.c
5c9faf
@@ -416,6 +416,8 @@ process_plane_assignment (MetaKmsImplDevice  *impl_device,
5c9faf
   MetaKmsPlaneAssignment *plane_assignment = update_entry;
5c9faf
   MetaKmsPlane *plane = plane_assignment->plane;
5c9faf
   MetaDrmBuffer *buffer;
5c9faf
+  MetaKmsFbDamage *fb_damage;
5c9faf
+  uint32_t prop_id;
5c9faf
 
5c9faf
   buffer = plane_assignment->buffer;
5c9faf
 
5c9faf
@@ -539,6 +541,32 @@ process_plane_assignment (MetaKmsImplDevice  *impl_device,
5c9faf
         return FALSE;
5c9faf
     }
5c9faf
 
5c9faf
+  fb_damage = plane_assignment->fb_damage;
5c9faf
+  if (fb_damage &&
5c9faf
+      meta_kms_plane_get_prop_id (plane,
5c9faf
+                                  META_KMS_PLANE_PROP_FB_DAMAGE_CLIPS_ID))
5c9faf
+    {
5c9faf
+      meta_topic (META_DEBUG_KMS,
5c9faf
+                  "[atomic] Setting %d damage clips on %u",
5c9faf
+                  fb_damage->n_rects,
5c9faf
+                  meta_kms_plane_get_id (plane));
5c9faf
+
5c9faf
+      prop_id = store_new_blob (impl_device,
5c9faf
+                                blob_ids,
5c9faf
+                                fb_damage->rects,
5c9faf
+                                fb_damage->n_rects *
5c9faf
+                                sizeof (struct drm_mode_rect),
5c9faf
+                                error);
5c9faf
+      if (!prop_id)
5c9faf
+        return FALSE;
5c9faf
+
5c9faf
+      if (!add_plane_property (impl_device,
5c9faf
+                               plane, req,
5c9faf
+                               META_KMS_PLANE_PROP_FB_DAMAGE_CLIPS_ID,
5c9faf
+                               prop_id,
5c9faf
+                               error))
5c9faf
+        return FALSE;
5c9faf
+    }
5c9faf
   return TRUE;
5c9faf
 }
5c9faf
 
5c9faf
diff --git a/src/backends/native/meta-kms-plane-private.h b/src/backends/native/meta-kms-plane-private.h
5c9faf
index 92f9cfcc9aa..f735c8da8f6 100644
5c9faf
--- a/src/backends/native/meta-kms-plane-private.h
5c9faf
+++ b/src/backends/native/meta-kms-plane-private.h
5c9faf
@@ -41,6 +41,7 @@ typedef enum _MetaKmsPlaneProp
5c9faf
   META_KMS_PLANE_PROP_CRTC_H,
5c9faf
   META_KMS_PLANE_PROP_FB_ID,
5c9faf
   META_KMS_PLANE_PROP_CRTC_ID,
5c9faf
+  META_KMS_PLANE_PROP_FB_DAMAGE_CLIPS_ID,
5c9faf
   META_KMS_PLANE_N_PROPS
5c9faf
 } MetaKmsPlaneProp;
5c9faf
 
5c9faf
diff --git a/src/backends/native/meta-kms-plane.c b/src/backends/native/meta-kms-plane.c
5c9faf
index 73fab7d8f80..3cb58764ff3 100644
5c9faf
--- a/src/backends/native/meta-kms-plane.c
5c9faf
+++ b/src/backends/native/meta-kms-plane.c
5c9faf
@@ -446,6 +446,11 @@ init_properties (MetaKmsPlane            *plane,
5c9faf
           .name = "CRTC_ID",
5c9faf
           .type = DRM_MODE_PROP_OBJECT,
5c9faf
         },
5c9faf
+      [META_KMS_PLANE_PROP_FB_DAMAGE_CLIPS_ID] =
5c9faf
+        {
5c9faf
+          .name = "FB_DAMAGE_CLIPS",
5c9faf
+          .type = DRM_MODE_PROP_BLOB,
5c9faf
+        },
5c9faf
     }
5c9faf
   };
5c9faf
 
5c9faf
diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h
5c9faf
index 22491ece2d5..c89622d09a5 100644
5c9faf
--- a/src/backends/native/meta-kms-update-private.h
5c9faf
+++ b/src/backends/native/meta-kms-update-private.h
5c9faf
@@ -34,6 +34,12 @@ typedef struct _MetaKmsFeedback
5c9faf
   GError *error;
5c9faf
 } MetaKmsFeedback;
5c9faf
 
5c9faf
+typedef struct _MetaKmsFbDamage
5c9faf
+{
5c9faf
+  struct drm_mode_rect *rects;
5c9faf
+  int n_rects;
5c9faf
+} MetaKmsFbDamage;
5c9faf
+
5c9faf
 typedef struct _MetaKmsPlaneAssignment
5c9faf
 {
5c9faf
   MetaKmsUpdate *update;
5c9faf
@@ -43,6 +49,7 @@ typedef struct _MetaKmsPlaneAssignment
5c9faf
   MetaFixed16Rectangle src_rect;
5c9faf
   MetaRectangle dst_rect;
5c9faf
   MetaKmsAssignPlaneFlag flags;
5c9faf
+  MetaKmsFbDamage *fb_damage;
5c9faf
 
5c9faf
   uint64_t rotation;
5c9faf
 
5c9faf
diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c
5c9faf
index be6eaefcc2c..71e5b423fb7 100644
5c9faf
--- a/src/backends/native/meta-kms-update.c
5c9faf
+++ b/src/backends/native/meta-kms-update.c
5c9faf
@@ -129,9 +129,17 @@ meta_kms_feedback_get_error (const MetaKmsFeedback *feedback)
5c9faf
   return feedback->error;
5c9faf
 }
5c9faf
 
5c9faf
+static void
5c9faf
+meta_kms_fb_damage_free (MetaKmsFbDamage *fb_damage)
5c9faf
+{
5c9faf
+  g_free (fb_damage->rects);
5c9faf
+  g_free (fb_damage);
5c9faf
+}
5c9faf
+
5c9faf
 static void
5c9faf
 meta_kms_plane_assignment_free (MetaKmsPlaneAssignment *plane_assignment)
5c9faf
 {
5c9faf
+  g_clear_pointer (&plane_assignment->fb_damage, meta_kms_fb_damage_free);
5c9faf
   g_free (plane_assignment);
5c9faf
 }
5c9faf
 
5c9faf
@@ -456,6 +464,33 @@ meta_kms_update_set_custom_page_flip (MetaKmsUpdate             *update,
5c9faf
   update->custom_page_flip = custom_page_flip;
5c9faf
 }
5c9faf
 
5c9faf
+void
5c9faf
+meta_kms_plane_assignment_set_fb_damage (MetaKmsPlaneAssignment *plane_assignment,
5c9faf
+                                         const int              *rectangles,
5c9faf
+                                         int                     n_rectangles)
5c9faf
+{
5c9faf
+  MetaKmsFbDamage *fb_damage;
5c9faf
+  struct drm_mode_rect *mode_rects;
5c9faf
+  int i;
5c9faf
+
5c9faf
+  mode_rects = g_new0 (struct drm_mode_rect, n_rectangles);
5c9faf
+  for (i = 0; i < n_rectangles; ++i)
5c9faf
+    {
5c9faf
+      mode_rects[i].x1 = rectangles[i * 4];
5c9faf
+      mode_rects[i].y1 = rectangles[i * 4 + 1];
5c9faf
+      mode_rects[i].x2 = mode_rects[i].x1 + rectangles[i * 4 + 2];
5c9faf
+      mode_rects[i].y2 = mode_rects[i].y1 + rectangles[i * 4 + 3];
5c9faf
+    }
5c9faf
+
5c9faf
+  fb_damage = g_new0 (MetaKmsFbDamage, 1);
5c9faf
+  *fb_damage = (MetaKmsFbDamage) {
5c9faf
+    .rects = mode_rects,
5c9faf
+    .n_rects = n_rectangles,
5c9faf
+  };
5c9faf
+
5c9faf
+  plane_assignment->fb_damage = fb_damage;
5c9faf
+}
5c9faf
+
5c9faf
 void
5c9faf
 meta_kms_plane_assignment_set_rotation (MetaKmsPlaneAssignment *plane_assignment,
5c9faf
                                         uint64_t                rotation)
5c9faf
diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h
5c9faf
index 4a6a8bb4373..e63b6d8711d 100644
5c9faf
--- a/src/backends/native/meta-kms-update.h
5c9faf
+++ b/src/backends/native/meta-kms-update.h
5c9faf
@@ -115,6 +115,10 @@ void meta_kms_update_set_crtc_gamma (MetaKmsUpdate  *update,
5c9faf
                                      const uint16_t *green,
5c9faf
                                      const uint16_t *blue);
5c9faf
 
5c9faf
+void meta_kms_plane_assignment_set_fb_damage (MetaKmsPlaneAssignment *plane_assignment,
5c9faf
+                                              const int              *rectangles,
5c9faf
+                                              int                     n_rectangles);
5c9faf
+
5c9faf
 MetaKmsPlaneAssignment * meta_kms_update_assign_plane (MetaKmsUpdate          *update,
5c9faf
                                                        MetaKmsCrtc            *crtc,
5c9faf
                                                        MetaKmsPlane           *plane,
5c9faf
-- 
5c9faf
2.36.1
5c9faf