diff options
-rw-r--r-- | gtk/PlatGTK.cxx | 40 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 41 |
2 files changed, 81 insertions, 0 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 34a33f581..7ecd1cbee 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -886,6 +886,46 @@ void Menu::Show(Point pt, Window &) { gtk_item_factory_popup(reinterpret_cast<GtkItemFactory *>(id), pt.x - 4, pt.y, 3, 0); } +static double DoublePack(glong a, glong b) { + double d; + long *lp = reinterpret_cast<glong *>(&d); + lp[0] = a; + lp[1] = b; + return d; +} + +static void DoubleUnpack(double d, glong &a, glong &b) { + long *lp = reinterpret_cast<glong *>(&d); + a = lp[0]; + b = lp[1]; +} + +static double Now() { + GTimeVal curTime; + g_get_current_time(&curTime); + return DoublePack(curTime.tv_sec, curTime.tv_usec); +} + +ElapsedTime::ElapsedTime() { + beginTime = Now(); +} + +double ElapsedTime::Duration(bool reset) { + double endTime = Now(); + GTimeVal tvStart; + DoubleUnpack(beginTime, tvStart.tv_sec, tvStart.tv_usec); + GTimeVal tvEnd; + DoubleUnpack(endTime, tvEnd.tv_sec, tvEnd.tv_usec); + double result = tvEnd.tv_sec - tvStart.tv_sec; + result *= 1000000; + result += tvEnd.tv_usec - tvStart.tv_usec; + result /= 1000000; + if (reset) { + beginTime = endTime; + } + return result; +} + ColourDesired Platform::Chrome() { return ColourDesired(0xe0, 0xe0, 0xe0); } diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 666c962cf..d227aa7a1 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -10,6 +10,7 @@ #include <ctype.h> #include <stdarg.h> #include <stdio.h> +#include <time.h> #define _WIN32_WINNT 0x0400 #include <windows.h> @@ -872,6 +873,46 @@ void Menu::Show(Point pt, Window &w) { Destroy(); } +static bool initialisedET = false; +static bool usePerformanceCounter = false; +static LARGE_INTEGER frequency; + +static double Now() { + if (usePerformanceCounter) { + LARGE_INTEGER timeVal; + ::QueryPerformanceCounter(&timeVal); + return *(reinterpret_cast<double *>(&timeVal)); + } else { + return clock(); + } +} + +ElapsedTime::ElapsedTime() { + if (!initialisedET) { + usePerformanceCounter = ::QueryPerformanceFrequency(&frequency); + initialisedET = true; + } + beginTime = Now(); +} + +double ElapsedTime::Duration(bool reset) { + double endTime = Now(); + double result; + if (usePerformanceCounter) { + LARGE_INTEGER lBegin = *(reinterpret_cast<LARGE_INTEGER *>(&beginTime)); + LARGE_INTEGER lEnd = *(reinterpret_cast<LARGE_INTEGER *>(&endTime)); + double elapsed = lEnd.QuadPart - lBegin.QuadPart; + result = elapsed / static_cast<double>(frequency.QuadPart); + } else { + double elapsed = endTime - beginTime; + result = elapsed / CLOCKS_PER_SEC; + } + if (reset) { + beginTime = endTime; + } + return result; +} + ColourDesired Platform::Chrome() { return ::GetSysColor(COLOR_3DFACE); } |