aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-10-23 07:02:06 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-10-23 07:02:06 -0700
commit33eefcd58bffc35355382dd7b1b79a02b99f8c6c (patch)
treebcf4043e0b109154d9d5ae2deabe2a205880762d /src/core
parent3b5b7845428a94402c1984c175ecce83cc963c21 (diff)
SkTime::GetNSecs()
- Move high-precision wall timers from tools/timer to SkTime. - Implement SkTime::GetMSecs() in terms of SkTime::GetNSecs(). - Delete unused tools/timer code. I have no idea what's going on there in src/animator. I don't intend to investigate. BUG=skia: Committed: https://skia.googlesource.com/skia/+/70084cbc16ee8162649f2601377feb6e49de0217 CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link-Trybot Committed: https://skia.googlesource.com/skia/+/a1840d50e29fd95e4df2d1168fe54c34c2a5c30c Committed: https://skia.googlesource.com/skia/+/38a88e4c0c28a7be981aac7bb4a198ad95a62a63 Review URL: https://codereview.chromium.org/1422513003
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkTime.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp
index fa6c04447d..86a0685c70 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