hc
2023-02-14 0cc9b7c44253c93447ddf73e206fbdbb3d9f16b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From abad359b1e46a08644a50bf7156bd32b073ad385 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Mon, 15 Jun 2020 10:03:01 +0800
Subject: [PATCH 08/31] kmssink: Support setting plane zpos
 
Set env KMSSINK_PLANE_ZPOS to specify plane zpos.
Set env KMSSINK_PLANE_ON_TOP to set max zpos.
Set env KMSSINK_PLANE_ON_BOTTOM to set min zpos.
 
Default zpos is max.
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 sys/kms/gstkmssink.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
 sys/kms/gstkmssink.h |  1 +
 2 files changed, 79 insertions(+)
 
diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c
index 0cb2bb6..b84657c 100644
--- a/sys/kms/gstkmssink.c
+++ b/sys/kms/gstkmssink.c
@@ -722,6 +722,76 @@ gst_kms_sink_update_plane_properties (GstKMSSink * self)
   gst_kms_sink_update_properties (&iter, self->plane_props);
 }
 
+static void
+gst_kms_sink_configure_plane_zpos (GstKMSSink * self, gboolean restore)
+{
+  drmModeObjectPropertiesPtr props = NULL;
+  drmModePropertyPtr prop = NULL;
+  drmModeResPtr res = NULL;
+  guint64 min, max, zpos;
+  const gchar *buf;
+  gint i;
+
+  if (self->plane_id <= 0)
+    return;
+
+  if (drmSetClientCap (self->fd, DRM_CLIENT_CAP_ATOMIC, 1))
+    return;
+
+  res = drmModeGetResources (self->fd);
+  if (!res)
+    return;
+
+  props = drmModeObjectGetProperties (self->fd, self->plane_id,
+      DRM_MODE_OBJECT_PLANE);
+  if (!props)
+    goto out;
+
+  for (i = 0; i < props->count_props; i++) {
+    prop = drmModeGetProperty (self->fd, props->props[i]);
+    if (prop && !strcmp (prop->name, "ZPOS"))
+      break;
+    drmModeFreeProperty (prop);
+    prop = NULL;
+  }
+
+  if (!prop)
+    goto out;
+
+  min = prop->values[0];
+  max = prop->values[1];
+
+  if (restore) {
+    if (self->saved_zpos < 0)
+      goto out;
+
+    zpos = self->saved_zpos;
+  } else {
+    zpos = min + 1;
+
+    buf = g_getenv ("KMSSINK_PLANE_ZPOS");
+    if (buf)
+      zpos = atoi (buf);
+    else if (g_getenv ("KMSSINK_PLANE_ON_TOP"))
+      zpos = max;
+    else if (g_getenv ("KMSSINK_PLANE_ON_BOTTOM"))
+      zpos = min;
+  }
+
+  GST_INFO_OBJECT (self, "set plane zpos = %lu (%lu~%lu)", zpos, min, max);
+
+  if (self->saved_zpos < 0)
+    self->saved_zpos = props->prop_values[i];
+
+  drmModeObjectSetProperty (self->fd, self->plane_id,
+      DRM_MODE_OBJECT_PLANE, props->props[i], zpos);
+
+out:
+  drmModeFreeProperty (prop);
+  drmModeFreeObjectProperties (props);
+  drmModeFreeResources (res);
+}
+
 static gboolean
 gst_kms_sink_start (GstBaseSink * bsink)
 {
@@ -802,6 +872,8 @@ retry_find_plane:
   self->crtc_id = crtc->crtc_id;
   self->plane_id = plane->plane_id;
 
+  gst_kms_sink_configure_plane_zpos (self, FALSE);
+
   GST_INFO_OBJECT (self, "connector id = %d / crtc id = %d / plane id = %d",
       self->conn_id, self->crtc_id, self->plane_id);
 
@@ -936,6 +1008,11 @@ gst_kms_sink_stop (GstBaseSink * bsink)
   if (self->allocator)
     gst_kms_allocator_clear_cache (self->allocator);
 
+  if (self->saved_zpos >= 0) {
+    gst_kms_sink_configure_plane_zpos (self, TRUE);
+    self->saved_zpos = -1;
+  }
+
   gst_buffer_replace (&self->last_buffer, NULL);
   gst_caps_replace (&self->allowed_caps, NULL);
   gst_object_replace ((GstObject **) & self->pool, NULL);
@@ -1931,6 +2008,7 @@ gst_kms_sink_init (GstKMSSink * sink)
   sink->fd = -1;
   sink->conn_id = -1;
   sink->plane_id = -1;
+  sink->saved_zpos = -1;
   sink->can_scale = TRUE;
   gst_poll_fd_init (&sink->pollfd);
   sink->poll = gst_poll_new (TRUE);
diff --git a/sys/kms/gstkmssink.h b/sys/kms/gstkmssink.h
index 0fccfa2..45a9c08 100644
--- a/sys/kms/gstkmssink.h
+++ b/sys/kms/gstkmssink.h
@@ -53,6 +53,7 @@ struct _GstKMSSink {
   gint crtc_id;
   gint plane_id;
   guint pipe;
+  guint saved_zpos;
 
   /* crtc data */
   guint16 hdisplay, vdisplay;
-- 
2.20.1