From 2fc6a8bbd2c0605e989d02a08c7c0e04b08918eb Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Mon, 18 Sep 2023 15:02:32 +0200
Subject: [PATCH] backend-pipewire, libweston: Extract
weston_output_finish_frame_from_timer()
Extract the finish frame timestamp code and the call to
weston_output_finish_frame() into a new helper function
weston_output_finish_frame_from_timer() that can be reused
by the other timer driven backends sharing the same logic.
Signed-off-by: Philipp Zabel
---
libweston/backend-pipewire/pipewire.c | 19 +------------------
libweston/backend.h | 2 ++
libweston/compositor.c | 27 +++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/libweston/backend-pipewire/pipewire.c b/libweston/backend-pipewire/pipewire.c
index 61e98516..cc338da5 100644
--- a/libweston/backend-pipewire/pipewire.c
+++ b/libweston/backend-pipewire/pipewire.c
@@ -249,10 +249,6 @@ static int
finish_frame_handler(void *data)
{
struct pipewire_output *output = data;
- int refresh_nsec = millihz_to_nsec(output->base.current_mode->refresh);
- struct timespec ts;
- struct timespec now;
- int64_t delta;
/*
* Skip weston_output_finish_frame() if the repaint state machine was
@@ -261,20 +257,7 @@ finish_frame_handler(void *data)
if (output->base.repaint_status != REPAINT_AWAITING_COMPLETION)
return 1;
- /*
- * The timer only has msec precision, but if the approximately hit our
- * target, report an exact time stamp by adding to the previous frame
- * time.
- */
- timespec_add_nsec(&ts,&output->base.frame_time, refresh_nsec);
-
- /* If we are more than 1.5 ms late, report the current time instead. */
- weston_compositor_read_presentation_clock(output->base.compositor, &now);
- delta = timespec_sub_to_nsec(&now, &ts);
- if (delta > 1500000)
- ts = now;
-
- weston_output_finish_frame(&output->base, &ts, 0);
+ weston_output_finish_frame_from_timer(&output->base);
return 1;
}
diff --git a/libweston/backend.h b/libweston/backend.h
index da295b1c..46ad2885 100644
--- a/libweston/backend.h
+++ b/libweston/backend.h
@@ -197,6 +197,8 @@ weston_output_get_hdr_metadata_type1(const struct weston_output *output);
void
weston_output_arm_frame_timer(struct weston_output *output,
struct wl_event_source *frame_timer);
+void
+weston_output_finish_frame_from_timer(struct weston_output *output);
/* weston_seat */
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 81466a11..61b5c910 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -9764,3 +9764,30 @@ weston_output_arm_frame_timer(struct weston_output *output,
wl_event_source_timer_update(frame_timer,
DIV_ROUND_UP(delay_nsec, 1000000));
}
+
+/** Helper to call weston_output_finish_frame() from frame timer callbacks
+ *
+ * \param output The output to call weston_output_finish_frame() for.
+ */
+WL_EXPORT void
+weston_output_finish_frame_from_timer(struct weston_output *output)
+{
+ int refresh_nsec = millihz_to_nsec(output->current_mode->refresh);
+ struct timespec ts;
+ struct timespec now;
+ int delta;
+
+ /* The timer only has msec precision, but if we approximately hit our
+ * target, report an exact time stamp by adding to the previous frame
+ * time.
+ */
+ timespec_add_nsec(&ts, &output->frame_time, refresh_nsec);
+
+ /* If we are more than 1.5 ms late, report the current time instead. */
+ weston_compositor_read_presentation_clock(output->compositor, &now);
+ delta = (int)timespec_sub_to_nsec(&now, &ts);
+ if (delta > 1500000)
+ ts = now;
+
+ weston_output_finish_frame(output, &ts, 0);
+}