OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkOncePtr.h" | 8 #include "SkOncePtr.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkTime.h" | 10 #include "SkTime.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include <intrin.h> | 29 #include <intrin.h> |
30 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); | 30 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); |
31 double SkTime::GetNSecs() { | 31 double SkTime::GetNSecs() { |
32 uint64_t ticks = __rdtsc(); | 32 uint64_t ticks = __rdtsc(); |
33 return ticks * *ns_per_tick.get([]{ | 33 return ticks * *ns_per_tick.get([]{ |
34 LARGE_INTEGER khz; // The docs say this returns Hz, but it returns
KHz. | 34 LARGE_INTEGER khz; // The docs say this returns Hz, but it returns
KHz. |
35 QueryPerformanceFrequency(&khz); | 35 QueryPerformanceFrequency(&khz); |
36 return new double(1e6 / khz.QuadPart); | 36 return new double(1e6 / khz.QuadPart); |
37 }); | 37 }); |
38 } | 38 } |
39 #elif defined(__MACH__) | |
40 // TODO: fold into std::chrono when available? | |
41 #include <mach/mach_time.h> | |
42 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); | |
43 double SkTime::GetNSecs() { | |
44 uint64_t ticks = mach_absolute_time(); | |
45 return ticks * *ns_per_tick.get([]{ | |
46 mach_timebase_info_data_t timebase; | |
47 (void)mach_timebase_info(&timebase); | |
48 return new double(timebase.numer * 1.0 / timebase.denom); | |
49 }); | |
50 } | |
51 #else | 39 #else |
52 // This std::chrono code looks great on Linux and Android, | 40 // This std::chrono code looks great on Linux, Mac, and Android, |
53 // but MSVC 2013 returned mostly garbage (0ns times, etc). | 41 // but MSVC 2013 returns mostly garbage (0ns times, etc). |
| 42 // This is ostensibly fixed in MSVC 2015. |
54 #include <chrono> | 43 #include <chrono> |
55 double SkTime::GetNSecs() { | 44 double SkTime::GetNSecs() { |
56 auto now = std::chrono::high_resolution_clock::now(); | 45 auto now = std::chrono::steady_clock::now(); |
57 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); | 46 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); |
58 return ns.count(); | 47 return ns.count(); |
59 } | 48 } |
60 #endif | 49 #endif |
OLD | NEW |