Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: src/core/SkTime.cpp

Issue 1529603002: Revert of SkTime updates (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
39 #else 51 #else
40 // This std::chrono code looks great on Linux, Mac, and Android, 52 // This std::chrono code looks great on Linux and Android,
41 // but MSVC 2013 returns mostly garbage (0ns times, etc). 53 // but MSVC 2013 returned mostly garbage (0ns times, etc).
42 // This is ostensibly fixed in MSVC 2015.
43 #include <chrono> 54 #include <chrono>
44 double SkTime::GetNSecs() { 55 double SkTime::GetNSecs() {
45 auto now = std::chrono::steady_clock::now(); 56 auto now = std::chrono::high_resolution_clock::now();
46 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); 57 std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
47 return ns.count(); 58 return ns.count();
48 } 59 }
49 #endif 60 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698