Chromium Code Reviews| Index: ui/gfx/frame_time.h |
| diff --git a/ui/gfx/frame_time.h b/ui/gfx/frame_time.h |
| index 1ab0a67beee002a6ab6876944d1474fcf780efd0..bb1faa984862c25828627a37188554e0aac337a5 100644 |
| --- a/ui/gfx/frame_time.h |
| +++ b/ui/gfx/frame_time.h |
| @@ -9,19 +9,110 @@ |
| namespace gfx { |
| -// FrameTime::Now() should be used to get timestamps with a timebase that |
| -// is consistent across the graphics stack. |
| -namespace FrameTime { |
| - static base::TimeTicks Now() { |
| +// FractionalFrameTime should be used for getting the current timestamp in |
| +// the same timebase as FrameTime and for representing things like deadlines, |
| +// which may not occur exactly on a frame boundary. |
| +class FractionalFrameTime { |
| + public: |
| + FractionalFrameTime() : ticks_(0) { |
| + } |
| + |
| + static FractionalFrameTime Now() { |
| if (base::TimeTicks::IsHighResNowFastAndReliable()) |
| - return base::TimeTicks::HighResNow(); |
| - return base::TimeTicks::Now(); |
| + return FractionalFrameTime( |
| + base::TimeTicks::HighResNow().ToInternalValue()); |
| + return FractionalFrameTime(base::TimeTicks::Now().ToInternalValue()); |
| } |
| - static bool TimestampsAreHighRes() { |
| - return base::TimeTicks::IsHighResNowFastAndReliable(); |
| + // Returns true if this object has not been initialized. |
| + bool is_null() const { |
| + return ticks_ == 0; |
| } |
| -} |
| + |
| + double Unsafe_InSecondsF() { |
| + return static_cast<double>(ticks_) / base::Time::kMicrosecondsPerSecond; |
| + } |
| + |
| + double Unsafe_InMillisecondsF() const { |
| + return static_cast<double>(ticks_) / |
| + base::Time::kMicrosecondsPerMillisecond; |
| + } |
| + |
| + FractionalFrameTime& operator=(FractionalFrameTime other) { |
| + ticks_ = other.ticks_; |
| + return *this; |
| + } |
| + |
| + // Compute the difference between two times. |
| + base::TimeDelta operator-(FractionalFrameTime other) const { |
| + DCHECK(!other.is_null()) << "Please do not convert time to a float."; |
| + return base::TimeDelta::FromInternalValue(ticks_ - other.ticks_); |
| + } |
| + |
| + // Modify by some time delta. |
| + FractionalFrameTime& operator+=(base::TimeDelta delta) { |
| + ticks_ += delta.ToInternalValue(); |
| + return *this; |
| + } |
| + FractionalFrameTime& operator-=(base::TimeDelta delta) { |
| + ticks_ -= delta.ToInternalValue(); |
| + return *this; |
| + } |
| + |
| + // Return a new FractionalFrameTime modified by some delta. |
| + FractionalFrameTime operator+(base::TimeDelta delta) const { |
| + return FrameTime(ticks_ + delta.ToInternalValue()); |
| + } |
| + FractionalFrameTime operator-(base::TimeDelta delta) const { |
| + return FrameTime(ticks_ - delta.ToInternalValue()); |
| + } |
| + |
| + // Comparison operators |
| + bool operator==(FractionalFrameTime other) const { |
| + return ticks_ == other.ticks_; |
| + } |
| + bool operator!=(FractionalFrameTime other) const { |
| + return ticks_ != other.ticks_; |
| + } |
| + bool operator<(FractionalFrameTime other) const { |
| + return ticks_ < other.ticks_; |
| + } |
| + bool operator<=(FractionalFrameTime other) const { |
| + return ticks_ <= other.ticks_; |
| + } |
| + bool operator>(FractionalFrameTime other) const { |
| + return ticks_ > other.ticks_; |
| + } |
| + bool operator>=(FractionalFrameTime other) const { |
| + return ticks_ >= other.ticks_; |
| + } |
| + |
| + protected: |
| + // Tick count in microseconds. |
| + int64 ticks_; |
| + |
| + // Please use Now() to create a new object. This is for internal use. |
| + // Ticks is in microseconds. |
| + explicit FractionalFrameTime(int64 ticks) : ticks_(ticks) { |
| + } |
| +}; |
| + |
| +// FrameTime should be used to represent an actual frame time. |
| +// If animations are using anything other than a FrameTime, there |
|
brianderson
2013/10/17 18:42:20
*there is something wrong.
|
| +class FrameTime : public FractionalFrameTime { |
| + public: |
| + FrameTime Unsafe_CreateFromFractionalTime(FractionalFrameTime src) { |
| + return FrameTime(src.ticks_); |
| + } |
| + |
| + FrameTime Unsafe_CreateFromTimeTicks(base::TimeTicks time_ticks) { |
| + return FractionalFrameTime(time_ticks.ToInternalValue()); |
| + } |
| + |
| + protected: |
| + explicit FractionalFrameTime(int64 ticks) |
| + : ticks_(ticks) {} |
| +}; |
| } |