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

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

Issue 67023003: cc: Don't double-tick unthrottled FrameRateController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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/frame_rate_controller.h" 5 #include "cc/scheduler/frame_rate_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 26 matching lines...) Expand all
37 }; 37 };
38 38
39 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 39 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
40 : client_(NULL), 40 : client_(NULL),
41 num_frames_pending_(0), 41 num_frames_pending_(0),
42 max_swaps_pending_(0), 42 max_swaps_pending_(0),
43 interval_(BeginFrameArgs::DefaultInterval()), 43 interval_(BeginFrameArgs::DefaultInterval()),
44 time_source_(timer), 44 time_source_(timer),
45 active_(false), 45 active_(false),
46 is_time_source_throttling_(true), 46 is_time_source_throttling_(true),
47 manual_tick_pending_(false),
47 task_runner_(NULL), 48 task_runner_(NULL),
48 weak_factory_(this) { 49 weak_factory_(this) {
49 time_source_client_adapter_ = 50 time_source_client_adapter_ =
50 FrameRateControllerTimeSourceAdapter::Create(this); 51 FrameRateControllerTimeSourceAdapter::Create(this);
51 time_source_->SetClient(time_source_client_adapter_.get()); 52 time_source_->SetClient(time_source_client_adapter_.get());
52 } 53 }
53 54
54 FrameRateController::FrameRateController( 55 FrameRateController::FrameRateController(
55 base::SingleThreadTaskRunner* task_runner) 56 base::SingleThreadTaskRunner* task_runner)
56 : client_(NULL), 57 : client_(NULL),
57 num_frames_pending_(0), 58 num_frames_pending_(0),
58 max_swaps_pending_(0), 59 max_swaps_pending_(0),
59 interval_(BeginFrameArgs::DefaultInterval()), 60 interval_(BeginFrameArgs::DefaultInterval()),
60 active_(false), 61 active_(false),
61 is_time_source_throttling_(false), 62 is_time_source_throttling_(false),
63 manual_tick_pending_(false),
62 task_runner_(task_runner), 64 task_runner_(task_runner),
63 weak_factory_(this) {} 65 weak_factory_(this) {}
64 66
65 FrameRateController::~FrameRateController() { 67 FrameRateController::~FrameRateController() {
66 if (is_time_source_throttling_) 68 if (is_time_source_throttling_)
67 time_source_->SetActive(false); 69 time_source_->SetActive(false);
68 } 70 }
69 71
70 BeginFrameArgs FrameRateController::SetActive(bool active) { 72 BeginFrameArgs FrameRateController::SetActive(bool active) {
71 if (active_ == active) 73 if (active_ == active)
72 return BeginFrameArgs(); 74 return BeginFrameArgs();
73 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); 75 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active);
74 active_ = active; 76 active_ = active;
75 77
76 if (is_time_source_throttling_) { 78 if (is_time_source_throttling_) {
77 base::TimeTicks missed_tick_time = time_source_->SetActive(active); 79 base::TimeTicks missed_tick_time = time_source_->SetActive(active);
78 if (!missed_tick_time.is_null()) { 80 if (!missed_tick_time.is_null()) {
79 base::TimeTicks deadline = NextTickTime(); 81 base::TimeTicks deadline = NextTickTime();
80 return BeginFrameArgs::Create( 82 return BeginFrameArgs::Create(
81 missed_tick_time, deadline + deadline_adjustment_, interval_); 83 missed_tick_time, deadline + deadline_adjustment_, interval_);
82 } 84 }
83 } else { 85 } else {
84 if (active) 86 if (active) {
85 PostManualTick(); 87 PostManualTick();
86 else 88 } else {
87 weak_factory_.InvalidateWeakPtrs(); 89 weak_factory_.InvalidateWeakPtrs();
90 manual_tick_pending_ = false;
91 }
88 } 92 }
89 93
90 return BeginFrameArgs(); 94 return BeginFrameArgs();
91 } 95 }
92 96
93 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) { 97 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) {
94 DCHECK_GE(max_swaps_pending, 0); 98 DCHECK_GE(max_swaps_pending, 0);
95 max_swaps_pending_ = max_swaps_pending; 99 max_swaps_pending_ = max_swaps_pending;
96 } 100 }
97 101
(...skipping 24 matching lines...) Expand all
122 BeginFrameArgs args = BeginFrameArgs::Create( 126 BeginFrameArgs args = BeginFrameArgs::Create(
123 frame_time, deadline + deadline_adjustment_, interval_); 127 frame_time, deadline + deadline_adjustment_, interval_);
124 client_->FrameRateControllerTick(throttled, args); 128 client_->FrameRateControllerTick(throttled, args);
125 } 129 }
126 130
127 if (!is_time_source_throttling_ && !throttled) 131 if (!is_time_source_throttling_ && !throttled)
128 PostManualTick(); 132 PostManualTick();
129 } 133 }
130 134
131 void FrameRateController::PostManualTick() { 135 void FrameRateController::PostManualTick() {
132 if (active_) { 136 if (active_ && !manual_tick_pending_) {
137 manual_tick_pending_ = true;
133 task_runner_->PostTask(FROM_HERE, 138 task_runner_->PostTask(FROM_HERE,
134 base::Bind(&FrameRateController::ManualTick, 139 base::Bind(&FrameRateController::ManualTick,
135 weak_factory_.GetWeakPtr())); 140 weak_factory_.GetWeakPtr()));
136 } 141 }
137 } 142 }
138 143
139 void FrameRateController::ManualTick() { 144 void FrameRateController::ManualTick() {
145 manual_tick_pending_ = false;
140 OnTimerTick(); 146 OnTimerTick();
141 } 147 }
142 148
143 void FrameRateController::DidSwapBuffers() { 149 void FrameRateController::DidSwapBuffers() {
144 num_frames_pending_++; 150 num_frames_pending_++;
145 } 151 }
146 152
147 void FrameRateController::DidSwapBuffersComplete() { 153 void FrameRateController::DidSwapBuffersComplete() {
148 DCHECK_GT(num_frames_pending_, 0); 154 DCHECK_GT(num_frames_pending_, 0);
149 num_frames_pending_--; 155 num_frames_pending_--;
(...skipping 13 matching lines...) Expand all
163 } 169 }
164 170
165 base::TimeTicks FrameRateController::LastTickTime() { 171 base::TimeTicks FrameRateController::LastTickTime() {
166 if (is_time_source_throttling_) 172 if (is_time_source_throttling_)
167 return time_source_->LastTickTime(); 173 return time_source_->LastTickTime();
168 174
169 return gfx::FrameTime::Now(); 175 return gfx::FrameTime::Now();
170 } 176 }
171 177
172 } // namespace cc 178 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698