diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39bbdcd0..74e58eab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,8 +15,8 @@ if (_GLFW_COCOA) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h posix_tls.h) set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_gamma.c - cocoa_init.m cocoa_monitor.m cocoa_time.c cocoa_window.m - iokit_joystick.m posix_tls.c) + cocoa_init.m cocoa_monitor.m cocoa_window.m + iokit_joystick.m mach_time.c posix_tls.c) elseif (_GLFW_WIN32) set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h winmm_joystick.h) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 7a7f5bab..8d9c0abd 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -49,6 +49,7 @@ typedef void* id; #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns +#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns @@ -76,11 +77,6 @@ typedef struct _GLFWwindowNS //------------------------------------------------------------------------ typedef struct _GLFWlibraryNS { - struct { - double base; - double resolution; - } timer; - CGEventSourceRef eventSource; id delegate; id autoreleasePool; @@ -112,6 +108,16 @@ typedef struct _GLFWcursorNS } _GLFWcursorNS; +//------------------------------------------------------------------------ +// Platform-specific time structure +//------------------------------------------------------------------------ +typedef struct _GLFWtimeNS +{ + double base; + double resolution; +} _GLFWtimeNS; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/internal.h b/src/internal.h index 0c11e8ad..53023525 100644 --- a/src/internal.h +++ b/src/internal.h @@ -349,6 +349,8 @@ struct _GLFWlibrary _GLFW_PLATFORM_LIBRARY_WINDOW_STATE; // This is defined in the context API's platform.h _GLFW_PLATFORM_LIBRARY_OPENGL_STATE; + // This is defined in the platform's time.h + _GLFW_PLATFORM_LIBRARY_TIME_STATE; // This is defined in the platform's joystick.h _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE; // This is defined in the platform's tls.h diff --git a/src/cocoa_time.c b/src/mach_time.c similarity index 86% rename from src/cocoa_time.c rename to src/mach_time.c index 0ecb4c13..59916bb4 100644 --- a/src/cocoa_time.c +++ b/src/mach_time.c @@ -48,8 +48,8 @@ void _glfwInitTimer(void) mach_timebase_info_data_t info; mach_timebase_info(&info); - _glfw.ns.timer.resolution = (double) info.numer / (info.denom * 1.0e9); - _glfw.ns.timer.base = getRawTime(); + _glfw.ns_time.resolution = (double) info.numer / (info.denom * 1.0e9); + _glfw.ns_time.base = getRawTime(); } @@ -59,13 +59,13 @@ void _glfwInitTimer(void) double _glfwPlatformGetTime(void) { - return (double) (getRawTime() - _glfw.ns.timer.base) * - _glfw.ns.timer.resolution; + return (double) (getRawTime() - _glfw.ns_time.base) * + _glfw.ns_time.resolution; } void _glfwPlatformSetTime(double time) { - _glfw.ns.timer.base = getRawTime() - - (uint64_t) (time / _glfw.ns.timer.resolution); + _glfw.ns_time.base = getRawTime() - + (uint64_t) (time / _glfw.ns_time.resolution); } diff --git a/src/posix_time.c b/src/posix_time.c index 31c6824a..53ea7949 100644 --- a/src/posix_time.c +++ b/src/posix_time.c @@ -35,7 +35,7 @@ static uint64_t getRawTime(void) { #if defined(CLOCK_MONOTONIC) - if (_GLFW_POSIX_TIME_CONTEXT.monotonic) + if (_glfw.posix_time.monotonic) { struct timespec ts; @@ -66,16 +66,16 @@ void _glfwInitTimer(void) if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - _GLFW_POSIX_TIME_CONTEXT.monotonic = GL_TRUE; - _GLFW_POSIX_TIME_CONTEXT.resolution = 1e-9; + _glfw.posix_time.monotonic = GL_TRUE; + _glfw.posix_time.resolution = 1e-9; } else #endif { - _GLFW_POSIX_TIME_CONTEXT.resolution = 1e-6; + _glfw.posix_time.resolution = 1e-6; } - _GLFW_POSIX_TIME_CONTEXT.base = getRawTime(); + _glfw.posix_time.base = getRawTime(); } @@ -85,13 +85,13 @@ void _glfwInitTimer(void) double _glfwPlatformGetTime(void) { - return (double) (getRawTime() - _GLFW_POSIX_TIME_CONTEXT.base) * - _GLFW_POSIX_TIME_CONTEXT.resolution; + return (double) (getRawTime() - _glfw.posix_time.base) * + _glfw.posix_time.resolution; } void _glfwPlatformSetTime(double time) { - _GLFW_POSIX_TIME_CONTEXT.base = getRawTime() - - (uint64_t) (time / _GLFW_POSIX_TIME_CONTEXT.resolution); + _glfw.posix_time.base = getRawTime() - + (uint64_t) (time / _glfw.posix_time.resolution); } diff --git a/src/posix_time.h b/src/posix_time.h index c7230dd1..1a7aab8a 100644 --- a/src/posix_time.h +++ b/src/posix_time.h @@ -28,6 +28,8 @@ #ifndef _posix_time_h_ #define _posix_time_h_ +#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time + #include typedef struct _GLFWtimePOSIX diff --git a/src/wayland_platform.h b/src/wayland_platform.h index 1ea68a31..7ea371ff 100644 --- a/src/wayland_platform.h +++ b/src/wayland_platform.h @@ -36,10 +36,8 @@ #error "The Wayland backend depends on EGL platform support" #endif -#include "linux_joystick.h" - -#define _GLFW_POSIX_TIME_CONTEXT _glfw.wl.timer #include "posix_time.h" +#include "linux_joystick.h" #define _GLFW_EGL_NATIVE_WINDOW window->wl.native #define _GLFW_EGL_NATIVE_DISPLAY _glfw.wl.display @@ -74,7 +72,6 @@ typedef struct _GLFWlibraryWayland int monitorsCount; int monitorsSize; - _GLFWtimePOSIX timer; } _GLFWlibraryWayland; typedef struct _GLFWmonitorWayland diff --git a/src/win32_platform.h b/src/win32_platform.h index 154eb601..4af3bc36 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -167,6 +167,7 @@ typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32 +#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32 @@ -203,13 +204,6 @@ typedef struct _GLFWlibraryWin32 DWORD foregroundLockTimeout; char* clipboardString; - // Timer data - struct { - GLboolean hasPC; - double resolution; - unsigned __int64 base; - } timer; - #ifndef _GLFW_NO_DLOAD_WINMM // winmm.dll struct { @@ -259,6 +253,18 @@ typedef struct _GLFWcursorWin32 } _GLFWcursorWin32; +//------------------------------------------------------------------------ +// Platform-specific time structure +//------------------------------------------------------------------------ +typedef struct _GLFWtimeWin32 +{ + GLboolean hasPC; + double resolution; + unsigned __int64 base; + +} _GLFWtimeWin32; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/win32_time.c b/src/win32_time.c index 4331119b..5f7adf8f 100644 --- a/src/win32_time.c +++ b/src/win32_time.c @@ -32,7 +32,7 @@ // static unsigned __int64 getRawTime(void) { - if (_glfw.win32.timer.hasPC) + if (_glfw.win32_time.hasPC) { unsigned __int64 time; QueryPerformanceCounter((LARGE_INTEGER*) &time); @@ -55,16 +55,16 @@ void _glfwInitTimer(void) if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) { - _glfw.win32.timer.hasPC = GL_TRUE; - _glfw.win32.timer.resolution = 1.0 / (double) frequency; + _glfw.win32_time.hasPC = GL_TRUE; + _glfw.win32_time.resolution = 1.0 / (double) frequency; } else { - _glfw.win32.timer.hasPC = GL_FALSE; - _glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms + _glfw.win32_time.hasPC = GL_FALSE; + _glfw.win32_time.resolution = 0.001; // winmm resolution is 1 ms } - _glfw.win32.timer.base = getRawTime(); + _glfw.win32_time.base = getRawTime(); } @@ -74,13 +74,13 @@ void _glfwInitTimer(void) double _glfwPlatformGetTime(void) { - return (double) (getRawTime() - _glfw.win32.timer.base) * - _glfw.win32.timer.resolution; + return (double) (getRawTime() - _glfw.win32_time.base) * + _glfw.win32_time.resolution; } void _glfwPlatformSetTime(double time) { - _glfw.win32.timer.base = getRawTime() - - (unsigned __int64) (time / _glfw.win32.timer.resolution); + _glfw.win32_time.base = getRawTime() - + (unsigned __int64) (time / _glfw.win32_time.resolution); } diff --git a/src/x11_platform.h b/src/x11_platform.h index b8b0bb86..0f493b1d 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -62,9 +62,7 @@ #error "No supported context creation API selected" #endif -#define _GLFW_POSIX_TIME_CONTEXT _glfw.x11.timer #include "posix_time.h" - #include "linux_joystick.h" #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 x11 @@ -204,8 +202,6 @@ typedef struct _GLFWlibraryX11 int exposure; } saver; - _GLFWtimePOSIX timer; - struct { char* string; } selection;