diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/animator/SkTime.cpp | 18 | ||||
-rw-r--r-- | src/core/SkTime.cpp | 35 | ||||
-rw-r--r-- | src/ports/SkTime_Unix.cpp | 7 | ||||
-rw-r--r-- | src/ports/SkTime_win.cpp | 11 |
4 files changed, 36 insertions, 35 deletions
diff --git a/src/animator/SkTime.cpp b/src/animator/SkTime.cpp index 560ccd2fc8..a4e035bd1e 100644 --- a/src/animator/SkTime.cpp +++ b/src/animator/SkTime.cpp @@ -28,6 +28,15 @@ void SkTime::GetDateTime(DateTime* t) { } } +SkMSec SkTime::GetMSecs() { +#ifdef SK_DEBUG + if (gForceTickCount != (SkMSec) -1) { + return gForceTickCount; + } +#endif + return ::GetTickCount(); +} + #elif defined(xSK_BUILD_FOR_MAC) #include <time.h> @@ -49,4 +58,13 @@ void SkTime::GetDateTime(DateTime* t) { } } +SkMSec SkTime::GetMSecs() { + UnsignedWide wide; + ::Microseconds(&wide); + + int64_t s = ((int64_t)wide.hi << 32) | wide.lo; + s = (s + 500) / 1000; // rounded divide + return (SkMSec)s; +} + #endif diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp index 03970aa824..fa6c04447d 100644 --- a/src/core/SkTime.cpp +++ b/src/core/SkTime.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "SkOncePtr.h" #include "SkString.h" #include "SkTime.h" @@ -23,37 +22,3 @@ void SkTime::DateTime::toISO8601(SkString* dst) const { timeZoneMinutes); } } - -// TODO: use rdtscp when (runtime) available -// TODO: use std::chrono when (compile-time) available - -#if defined(_MSC_VER) - #include <intrin.h> - SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); - double SkTime::GetNSecs() { - uint64_t ticks = __rdtsc(); - return ticks * *ns_per_tick.get([]{ - LARGE_INTEGER khz; // The docs say this returns Hz, but it returns KHz. - QueryPerformanceFrequency(&khz); - return new double(1e6 / khz.QuadPart); - }); - } -#elif defined(__MACH__) - #include <mach/mach_time.h> - SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); - double SkTime::GetNSecs() { - uint64_t ticks = mach_absolute_time(); - return ticks * *ns_per_tick.get([]{ - mach_timebase_info_data_t timebase; - (void)mach_timebase_info(&timebase); - return new double(timebase.numer * 1.0 / timebase.denom); - }); - } -#else - #include <time.h> - double SkTime::GetNSecs() { - struct timespec ts = {0, 0}; - (void)clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1e9 + ts.tv_nsec; - } -#endif diff --git a/src/ports/SkTime_Unix.cpp b/src/ports/SkTime_Unix.cpp index 1ea3b8fbd0..ec96bb8a90 100644 --- a/src/ports/SkTime_Unix.cpp +++ b/src/ports/SkTime_Unix.cpp @@ -34,3 +34,10 @@ void SkTime::GetDateTime(DateTime* dt) dt->fSecond = SkToU8(tstruct->tm_sec); } } + +SkMSec SkTime::GetMSecs() +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds +} diff --git a/src/ports/SkTime_win.cpp b/src/ports/SkTime_win.cpp index 2bd5062c3c..19f4695a86 100644 --- a/src/ports/SkTime_win.cpp +++ b/src/ports/SkTime_win.cpp @@ -39,3 +39,14 @@ void SkTime::GetDateTime(DateTime* dt) dt->fSecond = SkToU8(st.wSecond); } } + +SkMSec SkTime::GetMSecs() +{ + FILETIME ft; + LARGE_INTEGER li; + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + __int64 t = li.QuadPart; /* In 100-nanosecond intervals */ + return (SkMSec)(t / 10000); /* In milliseconds */ +} |