wp_presentation: deduplicate code
This commit is contained in:
parent
68d911085a
commit
d46407a6e8
|
@ -483,8 +483,10 @@ static void presentation_handle_clock_id(void *data,
|
|||
gfx_ctx_wayland_data_t *wl = data;
|
||||
|
||||
if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_MONOTONIC_RAW)
|
||||
{
|
||||
wl->present_clock = true;
|
||||
wl->present_clock_id = (clockid_t)clock_id;
|
||||
}
|
||||
}
|
||||
|
||||
static void presentation_feedback_sync_output(void *data,
|
||||
|
@ -571,6 +573,27 @@ void wl_request_presentation_feedback(gfx_ctx_wayland_data_t *wl)
|
|||
wl_list_insert(&wl->feedbacks, &fb->link);
|
||||
}
|
||||
|
||||
void wait_for_next_frame(gfx_ctx_wayland_data_t *wl)
|
||||
{
|
||||
if (!wl->present_clock || wl->refresh_interval <= 0 || !wl->is_presented)
|
||||
return;
|
||||
|
||||
struct timespec now;
|
||||
clockid_t clock_type = (wl->present_clock_id == CLOCK_MONOTONIC ||
|
||||
wl->present_clock_id == CLOCK_MONOTONIC_RAW)
|
||||
? wl->present_clock_id
|
||||
: CLOCK_MONOTONIC;
|
||||
clock_gettime(clock_type, &now);
|
||||
int64_t current_time = now.tv_sec * 1000000LL + now.tv_nsec / 1000;
|
||||
int64_t next_frame = wl->last_ust + (wl->refresh_interval / 1000);
|
||||
|
||||
if (current_time < next_frame) {
|
||||
int64_t sleep_us = next_frame - current_time;
|
||||
const int64_t max_sleep = 1000000;
|
||||
usleep(sleep_us > max_sleep ? max_sleep : sleep_us);
|
||||
}
|
||||
}
|
||||
|
||||
static int create_shm_file(off_t size)
|
||||
{
|
||||
int fd, ret;
|
||||
|
|
|
@ -513,25 +513,6 @@ static const struct wl_callback_listener wl_surface_frame_listener = {
|
|||
.done = wl_surface_frame_done,
|
||||
};
|
||||
|
||||
static void wait_for_next_frame(gfx_ctx_wayland_data_t *wl)
|
||||
{
|
||||
if (!wl->present_clock || wl->refresh_interval <= 0 || !wl->is_presented)
|
||||
return;
|
||||
|
||||
struct timespec now;
|
||||
clockid_t clock_type = (wl->present_clock_id == CLOCK_MONOTONIC ||
|
||||
wl->present_clock_id == CLOCK_MONOTONIC_RAW)
|
||||
? wl->present_clock_id
|
||||
: CLOCK_MONOTONIC;
|
||||
int64_t current_time = now.tv_sec * 1000000LL + now.tv_nsec / 1000;
|
||||
int64_t next_frame = wl->last_ust + (wl->refresh_interval / 1000);
|
||||
|
||||
if (current_time < next_frame) {
|
||||
int64_t sleep_us = next_frame - current_time;
|
||||
usleep(sleep_us);
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_ctx_wl_swap_buffers(void *data)
|
||||
{
|
||||
#ifdef HAVE_EGL
|
||||
|
|
|
@ -256,25 +256,6 @@ static void *gfx_ctx_wl_get_context_data(void *data)
|
|||
return &wl->vk.context;
|
||||
}
|
||||
|
||||
static void wait_for_next_frame(gfx_ctx_wayland_data_t *wl)
|
||||
{
|
||||
if (!wl->present_clock || wl->refresh_interval <= 0)
|
||||
return;
|
||||
|
||||
struct timespec now;
|
||||
clockid_t clock_type = (wl->present_clock_id == CLOCK_MONOTONIC ||
|
||||
wl->present_clock_id == CLOCK_MONOTONIC_RAW)
|
||||
? wl->present_clock_id
|
||||
: CLOCK_MONOTONIC;
|
||||
int64_t current_time = now.tv_sec * 1000000LL + now.tv_nsec / 1000;
|
||||
int64_t next_frame = wl->last_ust + (wl->refresh_interval / 1000);
|
||||
|
||||
if (current_time < next_frame) {
|
||||
int64_t sleep_us = next_frame - current_time;
|
||||
usleep(sleep_us);
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_ctx_wl_swap_buffers(void *data)
|
||||
{
|
||||
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
|
||||
|
|
|
@ -268,6 +268,8 @@ void flush_wayland_fd(void *data);
|
|||
|
||||
void wl_request_presentation_feedback(gfx_ctx_wayland_data_t *wl);
|
||||
|
||||
void wait_for_next_frame(gfx_ctx_wayland_data_t *wl);
|
||||
|
||||
extern const struct wl_keyboard_listener keyboard_listener;
|
||||
|
||||
extern const struct wl_pointer_listener pointer_listener;
|
||||
|
|
Loading…
Reference in New Issue