hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
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
From 357c3b9e9002cf455ffec22db8c79f0dc3f98f9d Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 27 Apr 2022 15:17:39 +0800
Subject: [PATCH 61/74] backend-drm: Stop disabling unused CRTCs by default
 
So that we can launch multiple weston instances for different monitors.
 
Set env "WESTON_DRM_MASTER" to take charge of all CRTCs again.
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 libweston/backend-drm/drm-internal.h | 1 +
 libweston/backend-drm/drm.c          | 7 +++++++
 libweston/backend-drm/kms.c          | 6 +++---
 3 files changed, 11 insertions(+), 3 deletions(-)
 
diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h
index 9543f1b..8035826 100644
--- a/libweston/backend-drm/drm-internal.h
+++ b/libweston/backend-drm/drm-internal.h
@@ -340,6 +340,7 @@ struct drm_backend {
     int64_t last_resize_ms;
     int64_t resize_freeze_ms;
 
+    bool master;
     bool single_head;
     bool head_fallback;
     bool head_fallback_all;
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
index ff41669..ed28956 100644
--- a/libweston/backend-drm/drm.c
+++ b/libweston/backend-drm/drm.c
@@ -2251,6 +2251,9 @@ drm_output_detach_crtc(struct drm_output *output)
     /* Force resetting unused CRTCs */
     b->state_invalid = true;
     output->state_invalid = true;
+
+    /* HACK: Do it here rather than in the kms.c for drm-master config */
+    drmModeSetCrtc(b->drm.fd, crtc->crtc_id, 0, 0, 0, NULL, 0, NULL);
 }
 
 static int
@@ -4120,6 +4123,10 @@ drm_backend_create(struct weston_compositor *compositor,
     if (b == NULL)
         return NULL;
 
+    buf = getenv("WESTON_DRM_MASTER");
+    if (buf && buf[0] == '1')
+        b->master = true;
+
     buf = getenv("WESTON_DRM_SINGLE_HEAD");
     if (buf && buf[0] == '1')
         b->single_head = true;
diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c
index 82247fb..37da3f6 100644
--- a/libweston/backend-drm/kms.c
+++ b/libweston/backend-drm/kms.c
@@ -1190,7 +1190,7 @@ drm_pending_state_apply_atomic(struct drm_pending_state *pending_state,
         break;
     }
 
-    if (b->state_invalid) {
+    if (b->state_invalid && b->master) {
         struct weston_head *head_base;
         struct drm_head *head;
         struct drm_crtc *crtc;
@@ -1388,7 +1388,7 @@ drm_pending_state_apply(struct drm_pending_state *pending_state)
         return drm_pending_state_apply_atomic(pending_state,
                               DRM_STATE_APPLY_ASYNC);
 
-    if (b->state_invalid) {
+    if (b->state_invalid && b->master) {
         /* If we need to reset all our state (e.g. because we've
          * just started, or just been VT-switched in), explicitly
          * disable all the CRTCs we aren't using. This also disables
@@ -1455,7 +1455,7 @@ drm_pending_state_apply_sync(struct drm_pending_state *pending_state)
         return drm_pending_state_apply_atomic(pending_state,
                               DRM_STATE_APPLY_SYNC);
 
-    if (b->state_invalid) {
+    if (b->state_invalid && b->master) {
         /* If we need to reset all our state (e.g. because we've
          * just started, or just been VT-switched in), explicitly
          * disable all the CRTCs we aren't using. This also disables
-- 
2.20.1