1From 4ef522b7ff6679bc41cb799b77c209770d1b8067 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Tue, 18 Jul 2023 09:42:32 +0800
4Subject: [PATCH 95/95] compositor: Delay DPMS-ON to finsih_frame()
5
6To make sure that the new frame is ready when turning on outputs.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 include/libweston/libweston.h |  1 +
11 libweston/backend-drm/drm.c   |  4 +---
12 libweston/compositor.c        | 21 ++++++++++++++++++++-
13 3 files changed, 22 insertions(+), 4 deletions(-)
14
15diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
16index 06a9ab9..2fda659 100644
17--- a/include/libweston/libweston.h
18+++ b/include/libweston/libweston.h
19@@ -574,6 +574,7 @@ struct weston_output {
20 	void (*detach_head)(struct weston_output *output,
21 			    struct weston_head *head);
22
23+	bool pending_active;
24 	bool unavailable;
25 	bool freezing;
26
27diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
28index 658e2c3..e410fe9 100644
29--- a/libweston/backend-drm/drm.c
30+++ b/libweston/backend-drm/drm.c
31@@ -3862,9 +3862,7 @@ config_handle_output(struct drm_backend *b, const char *name,
32 				continue;
33
34 			output->base.freezing = false;
35-
36-			if (!output->virtual)
37-				drm_set_dpms(&output->base, WESTON_DPMS_ON);
38+			output->base.pending_active = 1;
39
40 			weston_output_damage(&output->base);
41 		} else if (!strncmp(config, "down-scale=",
42diff --git a/libweston/compositor.c b/libweston/compositor.c
43index 24f4f36..24099c5 100644
44--- a/libweston/compositor.c
45+++ b/libweston/compositor.c
46@@ -3659,6 +3659,13 @@ weston_output_finish_frame(struct weston_output *output,
47 	struct timespec vblank_monotonic;
48 	int64_t msec_rel;
49
50+	/* Delayed DPMS-ON to avoid showing old frame */
51+	if (output->pending_active) {
52+		output->pending_active = false;
53+		if (output->set_dpms)
54+			output->set_dpms(output, WESTON_DPMS_ON);
55+	}
56+
57 	/*
58 	 * If timestamp of latest vblank is given, it must always go forwards.
59 	 * If not given, INVALID flag must be set.
60@@ -5546,9 +5553,21 @@ weston_compositor_dpms(struct weston_compositor *compositor,
61 {
62 	struct weston_output *output;
63
64-	wl_list_for_each(output, &compositor->output_list, link)
65+	wl_list_for_each(output, &compositor->output_list, link) {
66+		/**
67+		 * Delay to weston_output_finish_frame() to avoid showing
68+		 * old frame
69+		 */
70+		if (state == WESTON_DPMS_ON) {
71+			output->pending_active = true;
72+			weston_output_damage(output);
73+			continue;
74+		}
75+		output->pending_active = false;
76+
77 		if (output->set_dpms)
78 			output->set_dpms(output, state);
79+	}
80 }
81
82 /** Restores the compositor to active status
83--
842.20.1
85
86