1From 1c0baf5e1507fbccab3bd3e523ae61df461d7bfc Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Fri, 3 Jul 2020 10:20:40 +0800
4Subject: [PATCH 27/93] Support holding display for the first app
5
6Use '-w' or '--warm-up' to enable it.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 compositor/main.c             |  5 +++++
11 include/libweston/libweston.h |  2 ++
12 libweston/compositor.c        | 30 ++++++++++++++++++++++++++++++
13 3 files changed, 37 insertions(+)
14
15diff --git a/compositor/main.c b/compositor/main.c
16index d65f8aa..987c8f9 100644
17--- a/compositor/main.c
18+++ b/compositor/main.c
19@@ -677,6 +677,7 @@ usage(int error_code)
20 		"  -f, --flight-rec-scopes=SCOPE\n\t\t\tSpecify log scopes to "
21 			"subscribe to.\n\t\t\tCan specify multiple scopes, "
22 			"each followed by comma\n"
23+		"  -w, --warm-up\t\tHold display for the first app\n"
24 		"  -h, --help\t\tThis help message\n\n");
25
26 #if defined(BUILD_DRM_COMPOSITOR)
27@@ -3581,6 +3582,8 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
28 	bool wait_for_debugger = false;
29 	struct wl_protocol_logger *protologger = NULL;
30
31+	bool warm_up = false;
32+
33 	const struct weston_option core_options[] = {
34 		{ WESTON_OPTION_STRING, "backend", 'B', &backend },
35 		{ WESTON_OPTION_STRING, "shell", 0, &shell },
36@@ -3599,6 +3602,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
37 		{ WESTON_OPTION_BOOLEAN, "debug", 0, &debug_protocol },
38 		{ WESTON_OPTION_STRING, "logger-scopes", 'l', &log_scopes },
39 		{ WESTON_OPTION_STRING, "flight-rec-scopes", 'f', &flight_rec_scopes },
40+		{ WESTON_OPTION_BOOLEAN, "warm-up", 'w', &warm_up },
41 	};
42
43 	wl_list_init(&wet.layoutput_list);
44@@ -3785,6 +3789,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
45 	wet.compositor->idle_time = idle_time;
46 	wet.compositor->default_pointer_grab = NULL;
47 	wet.compositor->exit = handle_exit;
48+	wet.compositor->warm_up = warm_up;
49
50 	weston_compositor_log_capabilities(wet.compositor);
51
52diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
53index a41ffba..bf8e20a 100644
54--- a/include/libweston/libweston.h
55+++ b/include/libweston/libweston.h
56@@ -1340,6 +1340,8 @@ struct weston_compositor {
57
58 	enum weston_output_flow output_flow;
59 	struct weston_output *prefer_output;
60+
61+	bool warm_up;
62 };
63
64 struct weston_solid_buffer_values {
65diff --git a/libweston/compositor.c b/libweston/compositor.c
66index 3da5f18..8ca0c27 100644
67--- a/libweston/compositor.c
68+++ b/libweston/compositor.c
69@@ -179,6 +179,24 @@ weston_compositor_is_static_layer(struct weston_layer *layer)
70 	}
71 }
72
73+static bool
74+weston_compositor_is_system_layer(struct weston_layer *layer)
75+{
76+	if (!layer)
77+		return false;
78+
79+	switch (layer->position) {
80+	case WESTON_LAYER_POSITION_BACKGROUND:
81+	case WESTON_LAYER_POSITION_UI:
82+	case WESTON_LAYER_POSITION_LOCK:
83+	case WESTON_LAYER_POSITION_CURSOR:
84+	case WESTON_LAYER_POSITION_FADE:
85+		return true;
86+	default:
87+		return false;
88+	}
89+}
90+
91 /** Send wl_output events for mode and scale changes
92  *
93  * \param head Send on all resources bound to this head.
94@@ -3234,7 +3252,14 @@ weston_compositor_build_view_list(struct weston_compositor *compositor,
95 	wl_list_init(&compositor->view_list);
96
97 	wl_list_for_each(layer, &compositor->layer_list, link) {
98+		bool system_layer = weston_compositor_is_system_layer(layer);
99+
100 		wl_list_for_each(view, &layer->view_list.link, layer_link.link) {
101+			if (compositor->warm_up && !system_layer) {
102+				weston_log("seeing the first app\n");
103+				compositor->warm_up = false;
104+			}
105+
106 			view_list_add(compositor, view, output);
107 		}
108 	}
109@@ -3290,6 +3315,11 @@ weston_output_repaint(struct weston_output *output)
110 	/* Rebuild the surface list and update surface transforms up front. */
111 	weston_compositor_build_view_list(ec, output);
112
113+	if (ec->warm_up) {
114+		weston_log("holding display for the first app...\n");
115+		return -1;
116+	}
117+
118 	/* Find the highest protection desired for an output */
119 	wl_list_for_each(pnode, &output->paint_node_z_order_list,
120 			 z_order_link) {
121--
1222.20.1
123
124