Index: webkit/renderer/compositor_bindings/webkit_time.cc |
diff --git a/webkit/renderer/compositor_bindings/webkit_time.cc b/webkit/renderer/compositor_bindings/webkit_time.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..acc0a8562c2bd45ec7376f888a01d6818f9dd6c9 |
--- /dev/null |
+++ b/webkit/renderer/compositor_bindings/webkit_time.cc |
@@ -0,0 +1,53 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/renderer/compositor_bindings/webkit_time.h" |
+ |
+#include <limits> |
+ |
+#include "base/float_util.h" |
+#include "base/logging.h" |
+ |
+namespace webkit { |
+ |
+// WebKit uses a double in seconds for representing monotonic_time. |
+ |
+base::TimeTicks FromWebKitMonotonicTime(double monotonic_time) { |
+ double d_microseconds = |
+ monotonic_time * static_cast<double>(base::Time::kMicrosecondsPerSecond); |
+ |
+ // We should never have a monotonic time value of zero |
+ if (monotonic_time == 0 || d_microseconds == 0) { |
+ DCHECK(false); |
+ return base::TimeTicks(); |
+ } |
+ |
+ DCHECK(!base::IsNaN(d_microseconds)); |
+ DCHECK(base::IsFinite(d_microseconds)); |
+ |
+ DCHECK(d_microseconds >= |
+ static_cast<double>(std::numeric_limits<int64>::min()) && |
+ d_microseconds <= |
+ static_cast<double>(std::numeric_limits<int64>::max())); |
+ |
+ return base::TimeTicks::FromInternalValue(static_cast<int64>(d_microseconds)); |
+} |
+ |
+// A double only has 53 bits of precision and can not represent the full range |
+// of an int64 used in base::TimeTicks |
+double ToWebKitMonotonicTime(base::TimeTicks monotonic_time) { |
+ // We should never be sending a null TimeTicks to WebKit |
+ if (monotonic_time.is_null()) { |
+ DCHECK(false); |
+ return 0; |
+ } |
+ |
+ int64 ticks = monotonic_time.ToInternalValue(); |
+ DCHECK(ticks >= -powf(2, 53) && ticks <= powf(2, 53)); |
+ |
+ return (static_cast<double>(ticks) / |
+ static_cast<double>(base::Time::kMicrosecondsPerSecond)); |
+} |
+ |
+} // namespace webkit |