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

Side by Side Diff: cc/scheduler/delay_based_time_source.cc

Issue 2150533004: cc: Send all begin frames using a PostTask. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheduler_unittest_no_deadline
Patch Set: Created 4 years, 5 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
OLDNEW
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 #include "cc/output/begin_frame_args.h"
18 18
19 namespace cc { 19 namespace cc {
20 20
21 // The following methods correspond to the DelayBasedTimeSource that uses 21 // The following methods correspond to the DelayBasedTimeSource that uses
22 // the base::TimeTicks::Now as the timebase. 22 // the base::TimeTicks::Now as the timebase.
23 DelayBasedTimeSource::DelayBasedTimeSource( 23 DelayBasedTimeSource::DelayBasedTimeSource(
24 base::SingleThreadTaskRunner* task_runner) 24 base::SingleThreadTaskRunner* task_runner,
25 : client_(nullptr), 25 base::TickClock* clock)
26 : task_runner_(task_runner),
27 clock_(clock),
28 client_(nullptr),
26 active_(false), 29 active_(false),
27 timebase_(base::TimeTicks()), 30 timebase_(base::TimeTicks()),
28 interval_(BeginFrameArgs::DefaultInterval()), 31 interval_(BeginFrameArgs::DefaultInterval()),
29 last_tick_time_(base::TimeTicks() - interval_), 32 last_tick_time_(base::TimeTicks() - interval_),
30 next_tick_time_(base::TimeTicks()), 33 next_tick_time_(base::TimeTicks()),
31 task_runner_(task_runner),
32 weak_factory_(this) {} 34 weak_factory_(this) {}
33 35
34 DelayBasedTimeSource::~DelayBasedTimeSource() {} 36 DelayBasedTimeSource::~DelayBasedTimeSource() {}
35 37
36 void DelayBasedTimeSource::SetActive(bool active) { 38 void DelayBasedTimeSource::SetActive(bool active) {
37 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active); 39 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active);
38 40
39 if (active == active_) 41 if (active == active_)
40 return; 42 return;
41 43
42 active_ = active; 44 active_ = active;
43 45
44 if (active_) { 46 if (active_) {
45 PostNextTickTask(Now()); 47 PostNextTickTask(Now());
46 } else { 48 } else {
47 last_tick_time_ = base::TimeTicks(); 49 last_tick_time_ = base::TimeTicks();
48 next_tick_time_ = base::TimeTicks(); 50 next_tick_time_ = base::TimeTicks();
49 tick_closure_.Cancel(); 51 tick_closure_.Cancel();
50 } 52 }
51 } 53 }
52 54
53 base::TimeDelta DelayBasedTimeSource::Interval() const { 55 base::TimeDelta DelayBasedTimeSource::Interval() const {
54 return interval_; 56 return interval_;
55 } 57 }
56 58
57 bool DelayBasedTimeSource::Active() const { return active_; } 59 base::TimeTicks DelayBasedTimeSource::Now() {
60 return clock_ ? clock_->NowTicks() : base::TimeTicks::Now();
brianderson 2016/07/13 21:14:49 DefaultTickClock?
61 }
62
63 bool DelayBasedTimeSource::Active() const {
64 return active_;
65 }
58 66
59 base::TimeTicks DelayBasedTimeSource::LastTickTime() const { 67 base::TimeTicks DelayBasedTimeSource::LastTickTime() const {
60 return last_tick_time_; 68 return last_tick_time_;
61 } 69 }
62 70
63 base::TimeTicks DelayBasedTimeSource::NextTickTime() const { 71 base::TimeTicks DelayBasedTimeSource::NextTickTime() const {
64 return next_tick_time_; 72 return next_tick_time_;
65 } 73 }
66 74
67 void DelayBasedTimeSource::OnTimerTick() { 75 void DelayBasedTimeSource::OnTimerTick() {
(...skipping 11 matching lines...) Expand all
79 void DelayBasedTimeSource::SetClient(DelayBasedTimeSourceClient* client) { 87 void DelayBasedTimeSource::SetClient(DelayBasedTimeSourceClient* client) {
80 client_ = client; 88 client_ = client;
81 } 89 }
82 90
83 void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase, 91 void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase,
84 base::TimeDelta interval) { 92 base::TimeDelta interval) {
85 interval_ = interval; 93 interval_ = interval;
86 timebase_ = timebase; 94 timebase_ = timebase;
87 } 95 }
88 96
89 base::TimeTicks DelayBasedTimeSource::Now() const {
90 return base::TimeTicks::Now();
91 }
92
93 // This code tries to achieve an average tick rate as close to interval_ as 97 // This code tries to achieve an average tick rate as close to interval_ as
94 // possible. To do this, it has to deal with a few basic issues: 98 // possible. To do this, it has to deal with a few basic issues:
95 // 1. PostDelayedTask can delay only at a millisecond granularity. So, 16.666 99 // 1. PostDelayedTask can delay only at a millisecond granularity. So, 16.666
96 // has to posted as 16 or 17. 100 // has to posted as 16 or 17.
97 // 2. A delayed task may come back a bit late (a few ms), or really late 101 // 2. A delayed task may come back a bit late (a few ms), or really late
98 // (frames later) 102 // (frames later)
99 // 103 //
100 // The basic idea with this scheduler here is to keep track of where we *want* 104 // The basic idea with this scheduler here is to keep track of where we *want*
101 // to run in tick_target_. We update this with the exact interval. 105 // to run in tick_target_. We update this with the exact interval.
102 // 106 //
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (next_tick_time_ == now) 156 if (next_tick_time_ == now)
153 next_tick_time_ += interval_; 157 next_tick_time_ += interval_;
154 DCHECK_GT(next_tick_time_, now); 158 DCHECK_GT(next_tick_time_, now);
155 } 159 }
156 tick_closure_.Reset(base::Bind(&DelayBasedTimeSource::OnTimerTick, 160 tick_closure_.Reset(base::Bind(&DelayBasedTimeSource::OnTimerTick,
157 weak_factory_.GetWeakPtr())); 161 weak_factory_.GetWeakPtr()));
158 task_runner_->PostDelayedTask(FROM_HERE, tick_closure_.callback(), 162 task_runner_->PostDelayedTask(FROM_HERE, tick_closure_.callback(),
159 next_tick_time_ - now); 163 next_tick_time_ - now);
160 } 164 }
161 165
162 std::string DelayBasedTimeSource::TypeString() const {
163 return "DelayBasedTimeSource";
164 }
165
166 void DelayBasedTimeSource::AsValueInto( 166 void DelayBasedTimeSource::AsValueInto(
167 base::trace_event::TracedValue* state) const { 167 base::trace_event::TracedValue* state) const {
168 state->SetString("type", TypeString());
169 state->SetDouble("last_tick_time_us", LastTickTime().ToInternalValue()); 168 state->SetDouble("last_tick_time_us", LastTickTime().ToInternalValue());
170 state->SetDouble("next_tick_time_us", NextTickTime().ToInternalValue()); 169 state->SetDouble("next_tick_time_us", NextTickTime().ToInternalValue());
171 state->SetDouble("interval_us", interval_.InMicroseconds()); 170 state->SetDouble("interval_us", interval_.InMicroseconds());
172 state->SetDouble("timebase_us", timebase_.ToInternalValue()); 171 state->SetDouble("timebase_us", timebase_.ToInternalValue());
173 state->SetBoolean("active", active_); 172 state->SetBoolean("active", active_);
174 } 173 }
175 174
176 } // namespace cc 175 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698