summarylogtreecommitdiffstats
path: root/0004-compositor-drm-Gracefully-handle-vblank-and-flip-inv.patch
blob: 88b5b578c44f67ded0e75b7d6e18bc19683c46c0 (plain)
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 36ff0ce74aa22e633e0e3821f04cbeea4c25f927 Mon Sep 17 00:00:00 2001
From: "Miguel A. Vico" <mvicomoya@nvidia.com>
Date: Tue, 1 Mar 2016 22:19:14 +0100
Subject: [PATCH 4/6] compositor-drm: Gracefully handle vblank and flip invalid
 timestamps
X-NVConfidentiality: public

Instant query for vblank timestamp may always fail, resulting in
never scheduling a full repaint in drm_output_start_repaint_loop().

Additionally, timestamp provided in page_flip_handler() may also be
invalid.

This change makes both drm_output_start_repaint_loop() and
page_flip_handler() to schedule a full repaint in any of the
situations above.

Signed-off-by: Miguel A Vico Moya <mvicomoya@nvidia.com>
Reviewed-by: Andy Ritger <aritger@nvidia.com>
---
 libweston/compositor-drm.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index f1c5d73a..b9eb2883 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -4,6 +4,7 @@
  * Copyright © 2017, 2018 Collabora, Ltd.
  * Copyright © 2017, 2018 General Electric Company
  * Copyright (c) 2018 DisplayLink (UK) Ltd.
+ * Copyright © 2016-2019 NVIDIA Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -1939,6 +1940,19 @@ drm_output_update_complete(struct drm_output *output, uint32_t flags,
 
 	ts.tv_sec = sec;
 	ts.tv_nsec = usec * 1000;
+
+	/* Zero timestamp means failure to get valid timestamp, so
+	 * immediately finish frame
+	 *
+	 * FIXME: Driver should never return an invalid page flip
+	 *        timestamp */
+	if (ts.tv_sec == 0 && ts.tv_nsec == 0) {
+		weston_compositor_read_presentation_clock(
+						output->base.compositor,
+						&ts);
+		flags = WP_PRESENTATION_FEEDBACK_INVALID;
+	}
+
 	weston_output_finish_frame(&output->base, &ts, flags);
 
 	/* We can't call this from frame_notify, because the output's
@@ -3018,8 +3032,16 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
 	vbl.request.type |= drm_waitvblank_pipe(output);
 	ret = drmWaitVBlank(backend->drm.fd, &vbl);
 
-	/* Error ret or zero timestamp means failure to get valid timestamp */
-	if ((ret == 0) && (vbl.reply.tval_sec > 0 || vbl.reply.tval_usec > 0)) {
+	if (ret) {
+		/* Immediate query failed. It may always fail so we'll never get
+		 * a valid timestamp to update msc and call into finish frame.
+		 * Hence, jump to finish frame here.
+		 */
+		goto finish_frame;
+	}
+
+	/* Zero timestamp means failure to get valid timestamp */
+	if (vbl.reply.tval_sec > 0 || vbl.reply.tval_usec > 0) {
 		ts.tv_sec = vbl.reply.tval_sec;
 		ts.tv_nsec = vbl.reply.tval_usec * 1000;
 
@@ -3040,7 +3062,7 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
 		}
 	}
 
-	/* Immediate query didn't provide valid timestamp.
+	/* Immediate query succeeded, but didn't provide valid timestamp.
 	 * Use pageflip fallback.
 	 */
 
-- 
2.21.0