Create callback only when needed, and correct brace style.
This commit is contained in:
parent
155d2c9ada
commit
dd4148773d
|
@ -528,38 +528,44 @@ static void gfx_ctx_wl_swap_buffers(void *data)
|
||||||
|
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;
|
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;
|
||||||
|
struct wl_callback *cb;
|
||||||
|
|
||||||
struct wl_callback *cb = wl_surface_frame(wl->surface);
|
if (max_swapchain_images <= 2)
|
||||||
|
{
|
||||||
if (max_swapchain_images <= 2) {
|
|
||||||
/* Set Wayland frame callback. */
|
/* Set Wayland frame callback. */
|
||||||
|
cb = wl_surface_frame(wl->surface);
|
||||||
wl_callback_add_listener(cb, &wl_surface_frame_listener, wl);
|
wl_callback_add_listener(cb, &wl_surface_frame_listener, wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
egl_swap_buffers(&wl->egl);
|
egl_swap_buffers(&wl->egl);
|
||||||
|
|
||||||
if (max_swapchain_images <= 2) {
|
if (max_swapchain_images <= 2)
|
||||||
|
{
|
||||||
/* Wait for the frame callback we set earlier. */
|
/* Wait for the frame callback we set earlier. */
|
||||||
struct pollfd pollfd = {.fd = wl->input.fd, .events = POLLIN};
|
struct pollfd pollfd = {.fd = wl->input.fd, .events = POLLIN};
|
||||||
uint64_t deadline = cpu_features_get_time_usec() + 50000;
|
uint64_t deadline = cpu_features_get_time_usec() + 50000;
|
||||||
wl->swap_complete = false;
|
wl->swap_complete = false;
|
||||||
|
|
||||||
while (!wl->swap_complete) {
|
while (!wl->swap_complete)
|
||||||
|
{
|
||||||
uint64_t current_time = cpu_features_get_time_usec();
|
uint64_t current_time = cpu_features_get_time_usec();
|
||||||
if (current_time >= deadline) {
|
if (current_time >= deadline)
|
||||||
|
{
|
||||||
/* Deadline met. */
|
/* Deadline met. */
|
||||||
wl_callback_destroy(cb);
|
wl_callback_destroy(cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t remaining_time = deadline - current_time;
|
uint64_t remaining_time = deadline - current_time;
|
||||||
int ret = (wl_display_dispatch_pending(wl->input.dpy));
|
int ret = (wl_display_dispatch_pending(wl->input.dpy));
|
||||||
if (ret == 0) {
|
if (ret == 0)
|
||||||
|
{
|
||||||
ret = wl_display_prepare_read(wl->input.dpy);
|
ret = wl_display_prepare_read(wl->input.dpy);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
continue; /* Retry dispatch_pending. */
|
continue; /* Retry dispatch_pending. */
|
||||||
|
|
||||||
ret = poll(&pollfd, 1, remaining_time / 1000);
|
ret = poll(&pollfd, 1, remaining_time / 1000);
|
||||||
if (ret <= 0) {
|
if (ret <= 0)
|
||||||
|
{
|
||||||
/* Timeout met, or polling error. */
|
/* Timeout met, or polling error. */
|
||||||
wl_display_cancel_read(wl->input.dpy);
|
wl_display_cancel_read(wl->input.dpy);
|
||||||
wl_callback_destroy(cb);
|
wl_callback_destroy(cb);
|
||||||
|
|
Loading…
Reference in New Issue