diff options
author | 2015-12-14 10:54:24 -0800 | |
---|---|---|
committer | 2015-12-14 10:54:24 -0800 | |
commit | 4e4155df100b77d11bd14591c7716743369fde9b (patch) | |
tree | 1e30510bf87e19c3cc960534c43688b1b6297097 /src/core/SkTime.cpp | |
parent | 023bda0d836834eb1f98ceec15b169a492ab78ad (diff) |
Revert of SkTime updates (patchset #2 id:20001 of https://codereview.chromium.org/1521293002/ )
Reason for revert:
linux Canary builder has no std::steady_clock. Weird...
Original issue's description:
> SkTime updates
>
> 1) Use steady_clock instead of high_resolution_clock. If we don't have a
> guarantee of monotonicity, it's pretty much useless for timing things.
>
> 2) Implement Mac/iOS with <chrono> too. This was waiting on C++11 library support.
>
> Both high_resolution_clock and steady_clock are (still) busted on MSVC 2013,
> so no change there.
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/6a20871e5aeaa7e61f3348694bf436af16f824b9
TBR=herb@google.com,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1529603002
Diffstat (limited to 'src/core/SkTime.cpp')
-rw-r--r-- | src/core/SkTime.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp index 16f66161a7..86a0685c70 100644 --- a/src/core/SkTime.cpp +++ b/src/core/SkTime.cpp @@ -36,13 +36,24 @@ void SkTime::DateTime::toISO8601(SkString* dst) const { 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, Mac, and Android, - // but MSVC 2013 returns mostly garbage (0ns times, etc). - // This is ostensibly fixed in MSVC 2015. + // 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::steady_clock::now(); + auto now = std::chrono::high_resolution_clock::now(); std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); return ns.count(); } |