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

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

Issue 723713003: cc: Add SetChildrenNeedBeginFrames() & SendBeginFramesToChildren() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 6 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/test/fake_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 base::MessageLoop::current()->RunUntilIdle(); 81 base::MessageLoop::current()->RunUntilIdle();
82 } 82 }
83 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } 83 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; }
84 84
85 private: 85 private:
86 bool on_battery_power_impl_; 86 bool on_battery_power_impl_;
87 }; 87 };
88 88
89 FakeSchedulerClient() 89 FakeSchedulerClient()
90 : automatic_swap_ack_(true), 90 : automatic_swap_ack_(true),
91 begin_frame_is_sent_to_children_(false),
91 now_src_(TestNowSource::Create()), 92 now_src_(TestNowSource::Create()),
92 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), 93 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)),
93 fake_external_begin_frame_source_(nullptr), 94 fake_external_begin_frame_source_(nullptr),
94 fake_power_monitor_source_(new FakePowerMonitorSource), 95 fake_power_monitor_source_(new FakePowerMonitorSource),
95 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( 96 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>(
96 fake_power_monitor_source_)), 97 fake_power_monitor_source_)),
97 scheduler_(nullptr) { 98 scheduler_(nullptr) {
98 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() 99 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval()
99 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); 100 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100));
100 // Fail if we need to run 100 tasks in a row. 101 // Fail if we need to run 100 tasks in a row.
101 task_runner_->SetRunTaskLimit(100); 102 task_runner_->SetRunTaskLimit(100);
102 Reset(); 103 Reset();
103 } 104 }
104 105
105 void Reset() { 106 void Reset() {
106 actions_.clear(); 107 actions_.clear();
107 states_.clear(); 108 states_.clear();
108 draw_will_happen_ = true; 109 draw_will_happen_ = true;
109 swap_will_happen_if_draw_happens_ = true; 110 swap_will_happen_if_draw_happens_ = true;
110 num_draws_ = 0; 111 num_draws_ = 0;
111 log_anticipated_draw_time_change_ = false; 112 log_anticipated_draw_time_change_ = false;
113 begin_frame_is_sent_to_children_ = false;
112 } 114 }
113 115
114 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { 116 TestScheduler* CreateScheduler(const SchedulerSettings& settings) {
115 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; 117 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source;
116 if (settings.use_external_begin_frame_source && 118 if (settings.use_external_begin_frame_source &&
117 settings.throttle_frame_production) { 119 settings.throttle_frame_production) {
118 fake_external_begin_frame_source.reset( 120 fake_external_begin_frame_source.reset(
119 new FakeExternalBeginFrameSource(this)); 121 new FakeExternalBeginFrameSource(this));
120 fake_external_begin_frame_source_ = 122 fake_external_begin_frame_source_ =
121 fake_external_begin_frame_source.get(); 123 fake_external_begin_frame_source.get();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } 261 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); }
260 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { 262 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override {
261 return base::TimeDelta(); 263 return base::TimeDelta();
262 } 264 }
263 base::TimeDelta CommitToActivateDurationEstimate() override { 265 base::TimeDelta CommitToActivateDurationEstimate() override {
264 return base::TimeDelta(); 266 return base::TimeDelta();
265 } 267 }
266 268
267 void DidBeginImplFrameDeadline() override {} 269 void DidBeginImplFrameDeadline() override {}
268 270
271 void SendBeginFramesToChildren(const BeginFrameArgs& args) override {
272 begin_frame_is_sent_to_children_ = true;
273 }
274
269 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { 275 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) {
270 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, 276 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback,
271 base::Unretained(this), 277 base::Unretained(this),
272 state); 278 state);
273 } 279 }
274 280
281 bool begin_frame_is_sent_to_children() const {
282 return begin_frame_is_sent_to_children_;
283 }
284
275 protected: 285 protected:
276 bool ImplFrameDeadlinePendingCallback(bool state) { 286 bool ImplFrameDeadlinePendingCallback(bool state) {
277 return scheduler_->BeginImplFrameDeadlinePending() == state; 287 return scheduler_->BeginImplFrameDeadlinePending() == state;
278 } 288 }
279 289
280 bool draw_will_happen_; 290 bool draw_will_happen_;
281 bool swap_will_happen_if_draw_happens_; 291 bool swap_will_happen_if_draw_happens_;
282 bool automatic_swap_ack_; 292 bool automatic_swap_ack_;
283 int num_draws_; 293 int num_draws_;
284 bool log_anticipated_draw_time_change_; 294 bool log_anticipated_draw_time_change_;
295 bool begin_frame_is_sent_to_children_;
285 base::TimeTicks posted_begin_impl_frame_deadline_; 296 base::TimeTicks posted_begin_impl_frame_deadline_;
286 std::vector<const char*> actions_; 297 std::vector<const char*> actions_;
287 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; 298 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_;
288 scoped_refptr<TestNowSource> now_src_; 299 scoped_refptr<TestNowSource> now_src_;
289 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; 300 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
290 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; 301 FakeExternalBeginFrameSource* fake_external_begin_frame_source_;
291 FakePowerMonitorSource* fake_power_monitor_source_; 302 FakePowerMonitorSource* fake_power_monitor_source_;
292 base::PowerMonitor power_monitor_; 303 base::PowerMonitor power_monitor_;
293 scoped_ptr<TestScheduler> scheduler_; 304 scoped_ptr<TestScheduler> scheduler_;
294 }; 305 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 scheduler->SetCanStart(); 347 scheduler->SetCanStart();
337 scheduler->SetVisible(true); 348 scheduler->SetVisible(true);
338 scheduler->SetCanDraw(true); 349 scheduler->SetCanDraw(true);
339 350
340 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 351 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
341 client.Reset(); 352 client.Reset();
342 scheduler->DidCreateAndInitializeOutputSurface(); 353 scheduler->DidCreateAndInitializeOutputSurface();
343 EXPECT_NO_ACTION(client); 354 EXPECT_NO_ACTION(client);
344 } 355 }
345 356
357 TEST(SchedulerTest, SendBeginFramesToChildren) {
358 FakeSchedulerClient client;
359 SchedulerSettings scheduler_settings;
360 scheduler_settings.use_external_begin_frame_source = true;
361 scheduler_settings.forward_begin_frames_to_children = true;
362 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
363 scheduler->SetCanStart();
364 scheduler->SetVisible(true);
365 scheduler->SetCanDraw(true);
366
367 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
368 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
369
370 client.Reset();
371 EXPECT_FALSE(client.begin_frame_is_sent_to_children());
372 scheduler->SetNeedsCommit();
373 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
374 client.Reset();
375
376 scheduler->SetChildrenNeedBeginFrames(true);
377
378 client.AdvanceFrame();
379 EXPECT_TRUE(client.begin_frame_is_sent_to_children());
380 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
381 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
382 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
383 EXPECT_TRUE(client.needs_begin_frames());
384 client.Reset();
385 }
386
346 TEST(SchedulerTest, RequestCommit) { 387 TEST(SchedulerTest, RequestCommit) {
347 FakeSchedulerClient client; 388 FakeSchedulerClient client;
348 SchedulerSettings scheduler_settings; 389 SchedulerSettings scheduler_settings;
349 scheduler_settings.use_external_begin_frame_source = true; 390 scheduler_settings.use_external_begin_frame_source = true;
350 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 391 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
351 scheduler->SetCanStart(); 392 scheduler->SetCanStart();
352 scheduler->SetVisible(true); 393 scheduler->SetVisible(true);
353 scheduler->SetCanDraw(true); 394 scheduler->SetCanDraw(true);
354 395
355 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 396 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 2128
2088 // Deadline task is pending 2129 // Deadline task is pending
2089 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2130 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2090 client.task_runner().RunPendingTasks(); 2131 client.task_runner().RunPendingTasks();
2091 // Deadline task runs immediately 2132 // Deadline task runs immediately
2092 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2133 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
2093 } 2134 }
2094 2135
2095 } // namespace 2136 } // namespace
2096 } // namespace cc 2137 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/test/fake_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698