Only use the tick callback mechanism on macOS

On Linux, just call the tick callback on every loop tick. This is much
simpler, and should fix the issue with screen updates sometimes getting
stuck waiting for an X11 event.

Note that this was what used to happen (global state being checked on
every loop tick) before the refactoring to use a GLFW event loop,
therefore there should be no performance regressions, though we
of course end up checking global state on every group of events on
Linux, instead of only when something of interest happens. I suspect, to
achieve the latter is going to require implementing a mutex/lock in the
main loop to avoid races, which doesn't seem worth it.
This commit is contained in:
Kovid Goyal 2019-04-27 14:40:09 +05:30
parent a320e8bc25
commit 379ec88776
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 17 deletions

13
glfw/main_loop.h vendored
View File

@ -12,10 +12,9 @@
#define GLFW_LOOP_BACKEND x11
#endif
static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE;
static GLFWbool keep_going = GLFW_FALSE;
void _glfwPlatformRequestTickCallback() {
tick_callback_requested = GLFW_TRUE;
}
void _glfwPlatformStopMainLoop(void) {
@ -25,16 +24,12 @@ void _glfwPlatformStopMainLoop(void) {
}
}
void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
keep_going = GLFW_TRUE;
tick_callback_requested = GLFW_FALSE;
while(keep_going) {
EVDBG("tick_callback_requested: %d", tick_callback_requested);
while (tick_callback_requested) {
tick_callback_requested = GLFW_FALSE;
callback(data);
}
_glfwPlatformWaitEvents();
EVDBG("loop tick");
tick_callback(data);
}
}

View File

@ -940,8 +940,7 @@ process_global_state(void *data) {
if (global_state.has_pending_closes) has_open_windows = process_pending_closes(self);
if (has_open_windows) {
if (maximum_wait >= 0) {
if (maximum_wait == 0) request_tick_callback();
else state_check_timer_enabled = true;
state_check_timer_enabled = true;
}
} else {
stop_main_loop();

View File

@ -27,6 +27,14 @@ static GLFWcursor *standard_cursor = NULL, *click_cursor = NULL, *arrow_cursor =
static void set_os_window_dpi(OSWindow *w);
static void
request_tick_callback(void) {
#ifdef __APPLE__
glfwRequestTickCallback();
#endif
}
void
update_os_window_viewport(OSWindow *window, bool notify_boss) {
int w, h, fw, fh;
@ -1128,11 +1136,6 @@ run_main_loop(tick_callback_fun cb, void* cb_data) {
glfwRunMainLoop(cb, cb_data);
}
void
request_tick_callback(void) {
glfwRequestTickCallback();
}
void
stop_main_loop(void) {
glfwStopMainLoop();

View File

@ -238,5 +238,4 @@ id_type add_main_loop_timer(double interval, bool repeats, timer_callback_fun ca
void remove_main_loop_timer(id_type timer_id);
void update_main_loop_timer(id_type timer_id, double interval, bool enabled);
void run_main_loop(tick_callback_fun, void*);
void request_tick_callback(void);
void stop_main_loop(void);