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

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