| Index: src/core/SkTime.cpp
|
| diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp
|
| index fa6c04447de0ade9f8bfaf927151215d6eec85ec..86a0685c70af27703490024f15bf80ff5aef5152 100644
|
| --- a/src/core/SkTime.cpp
|
| +++ b/src/core/SkTime.cpp
|
| @@ -5,6 +5,7 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| +#include "SkOncePtr.h"
|
| #include "SkString.h"
|
| #include "SkTime.h"
|
|
|
| @@ -22,3 +23,38 @@ void SkTime::DateTime::toISO8601(SkString* dst) const {
|
| timeZoneMinutes);
|
| }
|
| }
|
| +
|
| +#if defined(_MSC_VER)
|
| + // TODO: try std::chrono again with MSVC 2015?
|
| + #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__)
|
| + // TODO: fold into std::chrono when available?
|
| + #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
|
| + // This std::chrono code looks great on Linux and Android,
|
| + // but MSVC 2013 returned mostly garbage (0ns times, etc).
|
| + #include <chrono>
|
| + double SkTime::GetNSecs() {
|
| + auto now = std::chrono::high_resolution_clock::now();
|
| + std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
|
| + return ns.count();
|
| + }
|
| +#endif
|
|
|