OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 #include "cc/scheduler/delay_based_time_source.h" | 5 #include "cc/scheduler/delay_based_time_source.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
17 #include "cc/output/begin_frame_args.h" | |
17 | 18 |
18 namespace cc { | 19 namespace cc { |
19 | 20 |
20 // The following methods correspond to the DelayBasedTimeSource that uses | 21 // The following methods correspond to the DelayBasedTimeSource that uses |
21 // the base::TimeTicks::Now as the timebase. | 22 // the base::TimeTicks::Now as the timebase. |
22 DelayBasedTimeSource::DelayBasedTimeSource( | 23 DelayBasedTimeSource::DelayBasedTimeSource( |
23 base::TimeDelta interval, | |
24 base::SingleThreadTaskRunner* task_runner) | 24 base::SingleThreadTaskRunner* task_runner) |
25 : client_(nullptr), | 25 : client_(nullptr), |
26 active_(false), | 26 active_(false), |
27 timebase_(base::TimeTicks()), | 27 timebase_(base::TimeTicks()), |
28 interval_(interval), | 28 interval_(BeginFrameArgs::DefaultInterval()), |
29 last_tick_time_(base::TimeTicks() - interval), | 29 last_tick_time_(base::TimeTicks() - interval_), |
30 next_tick_time_(base::TimeTicks()), | 30 next_tick_time_(base::TimeTicks()), |
31 task_runner_(task_runner), | 31 task_runner_(task_runner), |
32 weak_factory_(this) { | 32 weak_factory_(this) {} |
33 DCHECK_GT(interval, base::TimeDelta()); | |
34 } | |
35 | 33 |
36 DelayBasedTimeSource::~DelayBasedTimeSource() {} | 34 DelayBasedTimeSource::~DelayBasedTimeSource() {} |
37 | 35 |
38 void DelayBasedTimeSource::SetActive(bool active) { | 36 void DelayBasedTimeSource::SetActive(bool active) { |
39 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active); | 37 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active); |
40 | 38 |
41 if (active == active_) | 39 if (active == active_) |
42 return; | 40 return; |
43 | 41 |
44 active_ = active; | 42 active_ = active; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 if (client_) | 75 if (client_) |
78 client_->OnTimerTick(); | 76 client_->OnTimerTick(); |
79 } | 77 } |
80 | 78 |
81 void DelayBasedTimeSource::SetClient(DelayBasedTimeSourceClient* client) { | 79 void DelayBasedTimeSource::SetClient(DelayBasedTimeSourceClient* client) { |
82 client_ = client; | 80 client_ = client; |
83 } | 81 } |
84 | 82 |
85 void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase, | 83 void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase, |
86 base::TimeDelta interval) { | 84 base::TimeDelta interval) { |
87 DCHECK_GT(interval, base::TimeDelta()); | 85 // DCHECK_GT(interval, base::TimeDelta()); |
enne (OOO)
2016/06/14 23:13:44
??
danakj
2016/06/14 23:15:24
It must be deleted, we support 0 now. Yay
| |
88 interval_ = interval; | 86 interval_ = interval; |
89 timebase_ = timebase; | 87 timebase_ = timebase; |
90 } | 88 } |
91 | 89 |
92 base::TimeTicks DelayBasedTimeSource::Now() const { | 90 base::TimeTicks DelayBasedTimeSource::Now() const { |
93 return base::TimeTicks::Now(); | 91 return base::TimeTicks::Now(); |
94 } | 92 } |
95 | 93 |
96 // This code tries to achieve an average tick rate as close to interval_ as | 94 // This code tries to achieve an average tick rate as close to interval_ as |
97 // possible. To do this, it has to deal with a few basic issues: | 95 // possible. To do this, it has to deal with a few basic issues: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 // now=18 tick_target=16.667 new_target=33.333 --> | 139 // now=18 tick_target=16.667 new_target=33.333 --> |
142 // tick(), PostDelayedTask(floor(33.333-18)) --> PostDelayedTask(15) | 140 // tick(), PostDelayedTask(floor(33.333-18)) --> PostDelayedTask(15) |
143 // This brings us back to 18+15 = 33, which was where we would have been if the | 141 // This brings us back to 18+15 = 33, which was where we would have been if the |
144 // task hadn't been late. | 142 // task hadn't been late. |
145 // | 143 // |
146 // For the really late delay, we we move to the next logical tick. The timebase | 144 // For the really late delay, we we move to the next logical tick. The timebase |
147 // is not reset. | 145 // is not reset. |
148 // now=37 tick_target=16.667 new_target=50.000 --> | 146 // now=37 tick_target=16.667 new_target=50.000 --> |
149 // tick(), PostDelayedTask(floor(50.000-37)) --> PostDelayedTask(13) | 147 // tick(), PostDelayedTask(floor(50.000-37)) --> PostDelayedTask(13) |
150 void DelayBasedTimeSource::PostNextTickTask(base::TimeTicks now) { | 148 void DelayBasedTimeSource::PostNextTickTask(base::TimeTicks now) { |
151 next_tick_time_ = now.SnappedToNextTick(timebase_, interval_); | 149 if (interval_.is_zero()) { |
152 if (next_tick_time_ == now) | 150 next_tick_time_ = now; |
153 next_tick_time_ += interval_; | 151 } else { |
154 DCHECK_GT(next_tick_time_, now); | 152 next_tick_time_ = now.SnappedToNextTick(timebase_, interval_); |
153 if (next_tick_time_ == now) | |
154 next_tick_time_ += interval_; | |
155 DCHECK_GT(next_tick_time_, now); | |
156 } | |
155 tick_closure_.Reset(base::Bind(&DelayBasedTimeSource::OnTimerTick, | 157 tick_closure_.Reset(base::Bind(&DelayBasedTimeSource::OnTimerTick, |
156 weak_factory_.GetWeakPtr())); | 158 weak_factory_.GetWeakPtr())); |
157 task_runner_->PostDelayedTask(FROM_HERE, tick_closure_.callback(), | 159 task_runner_->PostDelayedTask(FROM_HERE, tick_closure_.callback(), |
158 next_tick_time_ - now); | 160 next_tick_time_ - now); |
159 } | 161 } |
160 | 162 |
161 std::string DelayBasedTimeSource::TypeString() const { | 163 std::string DelayBasedTimeSource::TypeString() const { |
162 return "DelayBasedTimeSource"; | 164 return "DelayBasedTimeSource"; |
163 } | 165 } |
164 | 166 |
165 void DelayBasedTimeSource::AsValueInto( | 167 void DelayBasedTimeSource::AsValueInto( |
166 base::trace_event::TracedValue* state) const { | 168 base::trace_event::TracedValue* state) const { |
167 state->SetString("type", TypeString()); | 169 state->SetString("type", TypeString()); |
168 state->SetDouble("last_tick_time_us", LastTickTime().ToInternalValue()); | 170 state->SetDouble("last_tick_time_us", LastTickTime().ToInternalValue()); |
169 state->SetDouble("next_tick_time_us", NextTickTime().ToInternalValue()); | 171 state->SetDouble("next_tick_time_us", NextTickTime().ToInternalValue()); |
170 state->SetDouble("interval_us", interval_.InMicroseconds()); | 172 state->SetDouble("interval_us", interval_.InMicroseconds()); |
171 state->SetDouble("timebase_us", timebase_.ToInternalValue()); | 173 state->SetDouble("timebase_us", timebase_.ToInternalValue()); |
172 state->SetBoolean("active", active_); | 174 state->SetBoolean("active", active_); |
173 } | 175 } |
174 | 176 |
175 } // namespace cc | 177 } // namespace cc |
OLD | NEW |