OLD | NEW |
(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 |
OLD | NEW |