mirror of https://github.com/encounter/SDL.git
wayland: Avoid busy waiting for vsync
This commit is contained in:
parent
791d9d3ff6
commit
092a20d945
|
@ -130,14 +130,28 @@ Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
|
||||||
struct wl_display *display = ((SDL_VideoData *)_this->driverdata)->display;
|
struct wl_display *display = ((SDL_VideoData *)_this->driverdata)->display;
|
||||||
SDL_VideoDisplay *sdldisplay = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *sdldisplay = SDL_GetDisplayForWindow(window);
|
||||||
const Uint32 max_wait = SDL_GetTicks() + (10000 / sdldisplay->current_mode.refresh_rate); /* ~10 frames, so we'll progress even if throttled to zero. */
|
const Uint32 max_wait = SDL_GetTicks() + (10000 / sdldisplay->current_mode.refresh_rate); /* ~10 frames, so we'll progress even if throttled to zero. */
|
||||||
while ((SDL_AtomicGet(&data->swap_interval_ready) == 0) && (!SDL_TICKS_PASSED(SDL_GetTicks(), max_wait))) {
|
while (SDL_AtomicGet(&data->swap_interval_ready) == 0) {
|
||||||
|
Uint32 now;
|
||||||
|
|
||||||
/* !!! FIXME: this is just the crucial piece of Wayland_PumpEvents */
|
/* !!! FIXME: this is just the crucial piece of Wayland_PumpEvents */
|
||||||
WAYLAND_wl_display_flush(display);
|
WAYLAND_wl_display_flush(display);
|
||||||
if (SDL_IOReady(WAYLAND_wl_display_get_fd(display), SDL_FALSE, 0)) {
|
if (WAYLAND_wl_display_dispatch_pending(display) > 0) {
|
||||||
WAYLAND_wl_display_dispatch(display);
|
/* We dispatched some pending events. Check if the frame callback happened. */
|
||||||
} else {
|
continue;
|
||||||
WAYLAND_wl_display_dispatch_pending(display);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now = SDL_GetTicks();
|
||||||
|
if (SDL_TICKS_PASSED(now, max_wait)) {
|
||||||
|
/* Timeout expired */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_IOReady(WAYLAND_wl_display_get_fd(display), SDL_FALSE, max_wait - now) <= 0) {
|
||||||
|
/* Error or timeout expired without any events for us */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
WAYLAND_wl_display_dispatch(display);
|
||||||
}
|
}
|
||||||
SDL_AtomicSet(&data->swap_interval_ready, 0);
|
SDL_AtomicSet(&data->swap_interval_ready, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue