From e31deedc993f8f396b20c2d8542ecfdad277a879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 16 Jul 2021 13:53:31 +0200 Subject: [PATCH] Make timer init part of platform API This is part of runtime platform selection because the null backend needs the timer implementation for the current OS. --- src/cocoa_init.m | 2 -- src/cocoa_platform.h | 2 -- src/cocoa_time.c | 11 ++--------- src/init.c | 4 +++- src/internal.h | 1 + src/null_init.c | 1 - src/posix_time.c | 11 ++--------- src/posix_time.h | 3 --- src/win32_init.c | 2 -- src/win32_platform.h | 2 -- src/win32_time.c | 11 ++--------- src/wl_init.c | 2 -- src/x11_init.c | 2 -- 13 files changed, 10 insertions(+), 44 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index d12f3427..a41667b0 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -547,8 +547,6 @@ int _glfwPlatformInit(void) if (!initializeTIS()) return GLFW_FALSE; - _glfwInitTimerNS(); - _glfwPollMonitorsNS(); if (![[NSRunningApplication currentApplication] isFinishedLaunching]) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index f9e80766..1ebf2c65 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -191,8 +191,6 @@ typedef struct _GLFWtimerNS } _GLFWtimerNS; -void _glfwInitTimerNS(void); - void _glfwPollMonitorsNS(void); void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); diff --git a/src/cocoa_time.c b/src/cocoa_time.c index 4bf646c8..c2bf8eda 100644 --- a/src/cocoa_time.c +++ b/src/cocoa_time.c @@ -32,12 +32,10 @@ ////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// +////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -// Initialise timer -// -void _glfwInitTimerNS(void) +void _glfwPlatformInitTimer(void) { mach_timebase_info_data_t info; mach_timebase_info(&info); @@ -45,11 +43,6 @@ void _glfwInitTimerNS(void) _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; } - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - uint64_t _glfwPlatformGetTimerValue(void) { return mach_absolute_time(); diff --git a/src/init.c b/src/init.c index a9f9a54d..f74b497d 100644 --- a/src/init.c +++ b/src/init.c @@ -340,9 +340,11 @@ GLFWAPI int glfwInit(void) _glfwInitGamepadMappings(); - _glfw.initialized = GLFW_TRUE; + _glfwPlatformInitTimer(); _glfw.timer.offset = _glfwPlatformGetTimerValue(); + _glfw.initialized = GLFW_TRUE; + glfwDefaultWindowHints(); return GLFW_TRUE; } diff --git a/src/internal.h b/src/internal.h index 0a9a965a..47f779e0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -644,6 +644,7 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode); void _glfwPlatformUpdateGamepadGUID(char* guid); const char* _glfwPlatformGetMappingName(void); +void _glfwPlatformInitTimer(void); uint64_t _glfwPlatformGetTimerValue(void); uint64_t _glfwPlatformGetTimerFrequency(void); diff --git a/src/null_init.c b/src/null_init.c index d72b06bf..d2968fc1 100644 --- a/src/null_init.c +++ b/src/null_init.c @@ -38,7 +38,6 @@ int _glfwPlatformInit(void) { - _glfwInitTimerPOSIX(); _glfwPollMonitorsNull(); return GLFW_TRUE; diff --git a/src/posix_time.c b/src/posix_time.c index b47a0b13..f134be47 100644 --- a/src/posix_time.c +++ b/src/posix_time.c @@ -34,12 +34,10 @@ ////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// +////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -// Initialise timer -// -void _glfwInitTimerPOSIX(void) +void _glfwPlatformInitTimer(void) { _glfw.timer.posix.clock = CLOCK_REALTIME; _glfw.timer.posix.frequency = 1000000000; @@ -51,11 +49,6 @@ void _glfwInitTimerPOSIX(void) #endif } - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - uint64_t _glfwPlatformGetTimerValue(void) { struct timespec ts; diff --git a/src/posix_time.h b/src/posix_time.h index cc7ba990..6fd15b06 100644 --- a/src/posix_time.h +++ b/src/posix_time.h @@ -39,6 +39,3 @@ typedef struct _GLFWtimerPOSIX uint64_t frequency; } _GLFWtimerPOSIX; - -void _glfwInitTimerPOSIX(void); - diff --git a/src/win32_init.c b/src/win32_init.c index c5370230..b871806e 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -576,8 +576,6 @@ int _glfwPlatformInit(void) if (!createHelperWindow()) return GLFW_FALSE; - _glfwInitTimerWin32(); - _glfwPollMonitorsWin32(); return GLFW_TRUE; } diff --git a/src/win32_platform.h b/src/win32_platform.h index 500da470..715026eb 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -445,8 +445,6 @@ BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build); void _glfwInputErrorWin32(int error, const char* description); void _glfwUpdateKeyNamesWin32(void); -void _glfwInitTimerWin32(void); - void _glfwPollMonitorsWin32(void); void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor); diff --git a/src/win32_time.c b/src/win32_time.c index 721b0d0d..2b1cbf0d 100644 --- a/src/win32_time.c +++ b/src/win32_time.c @@ -31,12 +31,10 @@ ////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// +////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -// Initialise timer -// -void _glfwInitTimerWin32(void) +void _glfwPlatformInitTimer(void) { uint64_t frequency; @@ -52,11 +50,6 @@ void _glfwInitTimerWin32(void) } } - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - uint64_t _glfwPlatformGetTimerValue(void) { if (_glfw.timer.win32.hasPC) diff --git a/src/wl_init.c b/src/wl_init.c index 2c73a7a9..5893970a 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -1227,8 +1227,6 @@ int _glfwPlatformInit(void) // Sync so we got all initial output events wl_display_roundtrip(_glfw.wl.display); - _glfwInitTimerPOSIX(); - _glfw.wl.timerfd = -1; if (_glfw.wl.seatVersion >= 4) _glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); diff --git a/src/x11_init.c b/src/x11_init.c index 5a5154cc..e4cb09de 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -1381,8 +1381,6 @@ int _glfwPlatformInit(void) NULL); } - _glfwInitTimerPOSIX(); - _glfwPollMonitorsX11(); return GLFW_TRUE; }