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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_FRAME_TIME_H 5 #ifndef UI_GFX_FRAME_TIME_H
6 #define UI_GFX_FRAME_TIME_H 6 #define UI_GFX_FRAME_TIME_H
7 7
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 9
10 namespace gfx { 10 namespace gfx {
11 11
12 // FrameTime::Now() should be used to get timestamps with a timebase that 12 // FractionalFrameTime should be used for getting the current timestamp in
13 // is consistent across the graphics stack. 13 // the same timebase as FrameTime and for representing things like deadlines,
14 namespace FrameTime { 14 // which may not occur exactly on a frame boundary.
15 static base::TimeTicks Now() { 15 class FractionalFrameTime {
16 if (base::TimeTicks::IsHighResNowFastAndReliable()) 16 public:
17 return base::TimeTicks::HighResNow(); 17 FractionalFrameTime() : ticks_(0) {
18 return base::TimeTicks::Now();
19 } 18 }
20 19
21 static bool TimestampsAreHighRes() { 20 static FractionalFrameTime Now() {
22 return base::TimeTicks::IsHighResNowFastAndReliable(); 21 if (base::TimeTicks::IsHighResNowFastAndReliable())
22 return FractionalFrameTime(
23 base::TimeTicks::HighResNow().ToInternalValue());
24 return FractionalFrameTime(base::TimeTicks::Now().ToInternalValue());
23 } 25 }
24 } 26
27 // Returns true if this object has not been initialized.
28 bool is_null() const {
29 return ticks_ == 0;
30 }
31
32 double Unsafe_InSecondsF() {
33 return static_cast<double>(ticks_) / base::Time::kMicrosecondsPerSecond;
34 }
35
36 double Unsafe_InMillisecondsF() const {
37 return static_cast<double>(ticks_) /
38 base::Time::kMicrosecondsPerMillisecond;
39 }
40
41 FractionalFrameTime& operator=(FractionalFrameTime other) {
42 ticks_ = other.ticks_;
43 return *this;
44 }
45
46 // Compute the difference between two times.
47 base::TimeDelta operator-(FractionalFrameTime other) const {
48 DCHECK(!other.is_null()) << "Please do not convert time to a float.";
49 return base::TimeDelta::FromInternalValue(ticks_ - other.ticks_);
50 }
51
52 // Modify by some time delta.
53 FractionalFrameTime& operator+=(base::TimeDelta delta) {
54 ticks_ += delta.ToInternalValue();
55 return *this;
56 }
57 FractionalFrameTime& operator-=(base::TimeDelta delta) {
58 ticks_ -= delta.ToInternalValue();
59 return *this;
60 }
61
62 // Return a new FractionalFrameTime modified by some delta.
63 FractionalFrameTime operator+(base::TimeDelta delta) const {
64 return FrameTime(ticks_ + delta.ToInternalValue());
65 }
66 FractionalFrameTime operator-(base::TimeDelta delta) const {
67 return FrameTime(ticks_ - delta.ToInternalValue());
68 }
69
70 // Comparison operators
71 bool operator==(FractionalFrameTime other) const {
72 return ticks_ == other.ticks_;
73 }
74 bool operator!=(FractionalFrameTime other) const {
75 return ticks_ != other.ticks_;
76 }
77 bool operator<(FractionalFrameTime other) const {
78 return ticks_ < other.ticks_;
79 }
80 bool operator<=(FractionalFrameTime other) const {
81 return ticks_ <= other.ticks_;
82 }
83 bool operator>(FractionalFrameTime other) const {
84 return ticks_ > other.ticks_;
85 }
86 bool operator>=(FractionalFrameTime other) const {
87 return ticks_ >= other.ticks_;
88 }
89
90 protected:
91 // Tick count in microseconds.
92 int64 ticks_;
93
94 // Please use Now() to create a new object. This is for internal use.
95 // Ticks is in microseconds.
96 explicit FractionalFrameTime(int64 ticks) : ticks_(ticks) {
97 }
98 };
99
100 // FrameTime should be used to represent an actual frame time.
101 // If animations are using anything other than a FrameTime, there
brianderson 2013/10/17 18:42:20 *there is something wrong.
102 class FrameTime : public FractionalFrameTime {
103 public:
104 FrameTime Unsafe_CreateFromFractionalTime(FractionalFrameTime src) {
105 return FrameTime(src.ticks_);
106 }
107
108 FrameTime Unsafe_CreateFromTimeTicks(base::TimeTicks time_ticks) {
109 return FractionalFrameTime(time_ticks.ToInternalValue());
110 }
111
112 protected:
113 explicit FractionalFrameTime(int64 ticks)
114 : ticks_(ticks) {}
115 };
25 116
26 } 117 }
27 118
28 #endif // UI_GFX_FRAME_TIME_H 119 #endif // UI_GFX_FRAME_TIME_H
OLDNEW
« 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