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

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

Issue 1420923003: Revert of SkTime::GetNSecs() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months 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 | « src/animator/SkTime.cpp ('k') | src/ports/SkTime_Unix.cpp » ('j') | 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"
9 #include "SkString.h" 8 #include "SkString.h"
10 #include "SkTime.h" 9 #include "SkTime.h"
11 10
12 void SkTime::DateTime::toISO8601(SkString* dst) const { 11 void SkTime::DateTime::toISO8601(SkString* dst) const {
13 if (dst) { 12 if (dst) {
14 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); 13 int timeZoneMinutes = SkToInt(fTimeZoneMinutes);
15 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; 14 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
16 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; 15 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60;
17 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; 16 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60;
18 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", 17 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d",
19 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), 18 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth),
20 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), 19 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour),
21 static_cast<unsigned>(fMinute), 20 static_cast<unsigned>(fMinute),
22 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, 21 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours,
23 timeZoneMinutes); 22 timeZoneMinutes);
24 } 23 }
25 } 24 }
26
27 // TODO: use rdtscp when (runtime) available
28 // TODO: use std::chrono when (compile-time) available
29
30 #if defined(_MSC_VER)
31 #include <intrin.h>
32 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick);
33 double SkTime::GetNSecs() {
34 uint64_t ticks = __rdtsc();
35 return ticks * *ns_per_tick.get([]{
36 LARGE_INTEGER khz; // The docs say this returns Hz, but it returns KHz.
37 QueryPerformanceFrequency(&khz);
38 return new double(1e6 / khz.QuadPart);
39 });
40 }
41 #elif defined(__MACH__)
42 #include <mach/mach_time.h>
43 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick);
44 double SkTime::GetNSecs() {
45 uint64_t ticks = mach_absolute_time();
46 return ticks * *ns_per_tick.get([]{
47 mach_timebase_info_data_t timebase;
48 (void)mach_timebase_info(&timebase);
49 return new double(timebase.numer * 1.0 / timebase.denom);
50 });
51 }
52 #else
53 #include <time.h>
54 double SkTime::GetNSecs() {
55 struct timespec ts = {0, 0};
56 (void)clock_gettime(CLOCK_MONOTONIC, &ts);
57 return ts.tv_sec * 1e9 + ts.tv_nsec;
58 }
59 #endif
OLDNEW
« no previous file with comments | « src/animator/SkTime.cpp ('k') | src/ports/SkTime_Unix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698