Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorNicholas Rishel <nicholas_rishel>2020-03-27 20:02:03 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-04-08 13:25:40 +0300
commit4e4bf241c8a08d4f083e36eed9fe3938ef4301f2 (patch)
tree05947ddc86d96b323b60a3252b09322b1fd4c2d9 /intern
parentc43473e88415db1b62f9fa225baa23ca344cace8 (diff)
Cleanup: add utility functions for milliseconds conversion
Ref D6675
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp26
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.h16
2 files changed, 35 insertions, 7 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 25a825dbb6a..12226be10ab 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -184,7 +184,8 @@ typedef enum MONITOR_DPI_TYPE {
typedef HRESULT(API *GHOST_WIN32_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
typedef BOOL(API *GHOST_WIN32_EnableNonClientDpiScaling)(HWND);
-GHOST_SystemWin32::GHOST_SystemWin32() : m_hasPerformanceCounter(false), m_freq(0), m_start(0)
+GHOST_SystemWin32::GHOST_SystemWin32()
+ : m_hasPerformanceCounter(false), m_freq(0), m_start(0), m_lfstart(0)
{
m_displayManager = new GHOST_DisplayManagerWin32();
GHOST_ASSERT(m_displayManager, "GHOST_SystemWin32::GHOST_SystemWin32(): m_displayManager==0\n");
@@ -223,22 +224,32 @@ GHOST_SystemWin32::~GHOST_SystemWin32()
toggleConsole(1);
}
+GHOST_TUns64 GHOST_SystemWin32::performanceCounterToMillis(__int64 perf_ticks) const
+{
+ // Calculate the time passed since system initialization.
+ __int64 delta = (perf_ticks - m_start) * 1000;
+
+ GHOST_TUns64 t = (GHOST_TUns64)(delta / m_freq);
+ return t;
+}
+
+GHOST_TUns64 GHOST_SystemWin32::tickCountToMillis(__int64 ticks) const
+{
+ return ticks - m_lfstart;
+}
+
GHOST_TUns64 GHOST_SystemWin32::getMilliSeconds() const
{
// Hardware does not support high resolution timers. We will use GetTickCount instead then.
if (!m_hasPerformanceCounter) {
- return ::GetTickCount();
+ return tickCountToMillis(::GetTickCount());
}
// Retrieve current count
__int64 count = 0;
::QueryPerformanceCounter((LARGE_INTEGER *)&count);
- // Calculate the time passed since system initialization.
- __int64 delta = 1000 * (count - m_start);
-
- GHOST_TUns64 t = (GHOST_TUns64)(delta / m_freq);
- return t;
+ return performanceCounterToMillis(count);
}
GHOST_TUns8 GHOST_SystemWin32::getNumDisplays() const
@@ -570,6 +581,7 @@ GHOST_TSuccess GHOST_SystemWin32::init()
FreeLibrary(user32);
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) {
diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h
index 27f23e00ae7..14ee1f38ecd 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.h
+++ b/intern/ghost/intern/GHOST_SystemWin32.h
@@ -66,6 +66,20 @@ class GHOST_SystemWin32 : public GHOST_System {
***************************************************************************************/
/**
+ * This method converts performance counter measurements into milliseconds since the start of the
+ * system process.
+ * \return The number of milliseconds since the start of the system process.
+ */
+ GHOST_TUns64 performanceCounterToMillis(__int64 perf_ticks) const;
+
+ /**
+ * This method converts system ticks into milliseconds since the start of the
+ * system process.
+ * \return The number of milliseconds since the start of the system process.
+ */
+ GHOST_TUns64 tickCountToMillis(__int64 ticks) const;
+
+ /**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* This overloaded method uses the high frequency timer if available.
@@ -426,6 +440,8 @@ class GHOST_SystemWin32 : public GHOST_System {
__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. */