From 67c12236e6521c854f384fd013efb7619c1d7e17 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 8 Feb 2024 08:53:34 +1100 Subject: [PATCH] GHOST/WIN32: remove start time offset from getMilliSeconds This isn't necessary and has been removed from macOS & X11, Wayland never did this. Besides removing the offset GetTickCount() has been replaced by GetTickCount64 to prevent 32bit rollover when high resolution timers aren't supported. Ref !117618 --- intern/ghost/intern/GHOST_SystemWin32.cc | 29 ++++++------------------ intern/ghost/intern/GHOST_SystemWin32.hh | 11 --------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc index 226a144585a..36f36e14f0d 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cc +++ b/intern/ghost/intern/GHOST_SystemWin32.cc @@ -135,8 +135,7 @@ static void initRawInput() typedef BOOL(API *GHOST_WIN32_EnableNonClientDpiScaling)(HWND); -GHOST_SystemWin32::GHOST_SystemWin32() - : m_hasPerformanceCounter(false), m_freq(0), m_start(0), m_lfstart(0) +GHOST_SystemWin32::GHOST_SystemWin32() : m_hasPerformanceCounter(false), m_freq(0) { m_displayManager = new GHOST_DisplayManagerWin32(); GHOST_ASSERT(m_displayManager, "GHOST_SystemWin32::GHOST_SystemWin32(): m_displayManager==0\n"); @@ -178,22 +177,17 @@ GHOST_SystemWin32::~GHOST_SystemWin32() uint64_t GHOST_SystemWin32::performanceCounterToMillis(__int64 perf_ticks) const { /* Calculate the time passed since system initialization. */ - __int64 delta = (perf_ticks - m_start) * 1000; + __int64 delta = perf_ticks * 1000; uint64_t t = uint64_t(delta / m_freq); return t; } -uint64_t GHOST_SystemWin32::tickCountToMillis(__int64 ticks) const -{ - return ticks - m_lfstart; -} - uint64_t GHOST_SystemWin32::getMilliSeconds() const { /* Hardware does not support high resolution timers. We will use GetTickCount instead then. */ if (!m_hasPerformanceCounter) { - return tickCountToMillis(::GetTickCount()); + return ::GetTickCount64(); } /* Retrieve current count */ @@ -204,10 +198,9 @@ uint64_t GHOST_SystemWin32::getMilliSeconds() const } /** - * Returns the number of milliseconds since the start of the Blender process to the time of the - * last message, using the high frequency timer if available. This should be used instead of - * getMilliSeconds when you need the time a message was delivered versus collected, so for all - * event creation that are in response to receiving a Windows message. + * Returns the message time, compatible with the time value from #getMilliSeconds. + * This should be used instead of #getMilliSeconds when you need the time a message was delivered + * versus collected, so for all event creation that are in response to receiving a Windows message. */ static uint64_t getMessageTime(GHOST_SystemWin32 *system) { @@ -219,7 +212,7 @@ static uint64_t getMessageTime(GHOST_SystemWin32 *system) t_delta -= int64_t(UINT32_MAX) + 1; } - /* Return message time as 64-bit milliseconds since Blender start. */ + /* Return message time as 64-bit milliseconds with the delta applied. */ return system->getMilliSeconds() + t_delta; } @@ -575,16 +568,8 @@ GHOST_TSuccess GHOST_SystemWin32::init() SetProcessDPIAware(); initRawInput(); - m_lfstart = ::GetTickCount(); /* Determine whether this system has a high frequency performance counter. */ m_hasPerformanceCounter = ::QueryPerformanceFrequency((LARGE_INTEGER *)&m_freq) == TRUE; - if (m_hasPerformanceCounter) { - GHOST_PRINT("GHOST_SystemWin32::init: High Frequency Performance Timer available\n"); - ::QueryPerformanceCounter((LARGE_INTEGER *)&m_start); - } - else { - GHOST_PRINT("GHOST_SystemWin32::init: High Frequency Performance Timer not available\n"); - } if (success) { WNDCLASSW wc = {0}; diff --git a/intern/ghost/intern/GHOST_SystemWin32.hh b/intern/ghost/intern/GHOST_SystemWin32.hh index e61709f1788..5d6f7a752c3 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.hh +++ b/intern/ghost/intern/GHOST_SystemWin32.hh @@ -60,13 +60,6 @@ class GHOST_SystemWin32 : public GHOST_System { */ uint64_t performanceCounterToMillis(__int64 perf_ticks) const; - /** - * This method converts system ticks into milliseconds since the start of the - * Blender process. - * \return The number of milliseconds since the start of the Blender process. - */ - uint64_t tickCountToMillis(__int64 ticks) const; - /** * Returns the system time. * Returns the number of milliseconds since the start of the Blender process. @@ -476,10 +469,6 @@ class GHOST_SystemWin32 : public GHOST_System { bool m_hasPerformanceCounter; /** High frequency timer variable. */ __int64 m_freq; - /** High frequency timer variable. */ - __int64 m_start; - /** Low frequency timer variable. */ - __int64 m_lfstart; /** AltGr on current keyboard layout. */ bool m_hasAltGr; /** Language identifier. */