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

Unified Diff: ui/gfx/frame_time.h

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {}
+};
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698