1From d452ad4bc7d66b15884e3e82762e1bd3046da54d Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Thu, 28 Oct 2021 12:47:09 +0800
4Subject: [PATCH 54/93] HACK: Use negative value for dynamic repaint window
5
6Support using negative value for a vblank based dynamic repaint window:
7When negative, repaint-window = vblank-duration - abs(repaint-window)
8
9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
10---
11 compositor/main.c      | 2 +-
12 libweston/compositor.c | 9 ++++++++-
13 2 files changed, 9 insertions(+), 2 deletions(-)
14
15diff --git a/compositor/main.c b/compositor/main.c
16index efd861b..e57d26a 100644
17--- a/compositor/main.c
18+++ b/compositor/main.c
19@@ -1116,7 +1116,7 @@ weston_compositor_init_config(struct weston_compositor *ec,
20 	s = weston_config_get_section(config, "core", NULL, NULL);
21 	weston_config_section_get_int(s, "repaint-window", &repaint_msec,
22 				      ec->repaint_msec);
23-	if (repaint_msec < -10 || repaint_msec > 1000) {
24+	if (repaint_msec < -1000 || repaint_msec > 1000) {
25 		weston_log("Invalid repaint_window value in config: %d\n",
26 			   repaint_msec);
27 	} else {
28diff --git a/libweston/compositor.c b/libweston/compositor.c
29index 2ea1967..ff07e40 100644
30--- a/libweston/compositor.c
31+++ b/libweston/compositor.c
32@@ -3665,10 +3665,17 @@ weston_output_finish_frame(struct weston_output *output,
33
34 	output->frame_time = *stamp;
35
36-	timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec);
37+	/* HACK: Use negative value for dynamic repaint window */
38+	if (compositor->repaint_msec > 0)
39+		timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec);
40+
41 	timespec_add_msec(&output->next_repaint, &output->next_repaint,
42 			  -compositor->repaint_msec);
43 	msec_rel = timespec_sub_to_msec(&output->next_repaint, &now);
44+	if (msec_rel < 0) {
45+		output->next_repaint = now;
46+		msec_rel = 0;
47+	}
48
49 	if (msec_rel < -1000 || msec_rel > 1000) {
50 		static bool warned;
51--
522.20.1
53
54