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

Side by Side Diff: webkit/renderer/compositor_bindings/webkit_time.cc

Issue 192433002: Creating utility for converting TimeTicks to WebKit double and use it in the Chrome compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworking webkit_time, adding other users. Created 6 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/renderer/compositor_bindings/webkit_time.h"
6
7 #include <limits>
8
9 #include "base/float_util.h"
10 #include "base/logging.h"
11
12 namespace webkit {
13
14 // WebKit uses a double in seconds for representing monotonic_time.
15
16 base::TimeTicks FromWebKitMonotonicTime(double monotonic_time) {
17 double d_microseconds =
18 monotonic_time * static_cast<double>(base::Time::kMicrosecondsPerSecond);
19
20 // We should never have a monotonic time value of zero
21 if (monotonic_time == 0 || d_microseconds == 0) {
22 DCHECK(false);
23 return base::TimeTicks();
24 }
25
26 DCHECK(!base::IsNaN(d_microseconds));
27 DCHECK(base::IsFinite(d_microseconds));
28
29 DCHECK(d_microseconds >=
30 static_cast<double>(std::numeric_limits<int64>::min()) &&
31 d_microseconds <=
32 static_cast<double>(std::numeric_limits<int64>::max()));
33
34 return base::TimeTicks::FromInternalValue(static_cast<int64>(d_microseconds));
35 }
36
37 // A double only has 53 bits of precision and can not represent the full range
38 // of an int64 used in base::TimeTicks
39 double ToWebKitMonotonicTime(base::TimeTicks monotonic_time) {
40 // We should never be sending a null TimeTicks to WebKit
41 if (monotonic_time.is_null()) {
42 DCHECK(false);
43 return 0;
44 }
45
46 int64 ticks = monotonic_time.ToInternalValue();
47 DCHECK(ticks >= -powf(2, 53) && ticks <= powf(2, 53));
48
49 return (static_cast<double>(ticks) /
50 static_cast<double>(base::Time::kMicrosecondsPerSecond));
51 }
52
53 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698