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 <p.zabel@pengutronix.de>
This commit is contained in:
Philipp Zabel 2023-09-18 15:02:32 +02:00 committed by Marius Vlad
parent fd10c92d69
commit 2fc6a8bbd2
3 changed files with 30 additions and 18 deletions

View file

@ -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;
}

View file

@ -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 */

View file

@ -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);
}