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

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

Issue 1774323003: Allow cc::Scheduler begin frame source to be changed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheduler_always_external
Patch Set: Add early out Created 4 years, 9 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 | « cc/scheduler/scheduler.cc ('k') | cc/test/scheduler_test_common.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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 now_src_->Advance(base::TimeDelta::FromMilliseconds(100)); 250 now_src_->Advance(base::TimeDelta::FromMilliseconds(100));
251 // Fail if we need to run 100 tasks in a row. 251 // Fail if we need to run 100 tasks in a row.
252 task_runner_->SetRunTaskLimit(100); 252 task_runner_->SetRunTaskLimit(100);
253 } 253 }
254 254
255 ~SchedulerTest() override {} 255 ~SchedulerTest() override {}
256 256
257 protected: 257 protected:
258 TestScheduler* CreateScheduler() { 258 TestScheduler* CreateScheduler() {
259 BeginFrameSource* frame_source; 259 BeginFrameSource* frame_source;
260 unthrottled_frame_source_ = TestBackToBackBeginFrameSource::Create(
261 now_src_.get(), task_runner_.get());
262 fake_external_begin_frame_source_.reset(
263 new FakeExternalBeginFrameSource(client_.get()));
264 synthetic_frame_source_ = TestSyntheticBeginFrameSource::Create(
265 now_src_.get(), task_runner_.get(), BeginFrameArgs::DefaultInterval());
260 if (!scheduler_settings_.throttle_frame_production) { 266 if (!scheduler_settings_.throttle_frame_production) {
261 unthrottled_frame_source_ = TestBackToBackBeginFrameSource::Create(
262 now_src_.get(), task_runner_.get());
263 frame_source = unthrottled_frame_source_.get(); 267 frame_source = unthrottled_frame_source_.get();
264 } else if (scheduler_settings_.use_external_begin_frame_source) { 268 } else if (scheduler_settings_.use_external_begin_frame_source) {
265 fake_external_begin_frame_source_.reset(
266 new FakeExternalBeginFrameSource(client_.get()));
267 frame_source = fake_external_begin_frame_source_.get(); 269 frame_source = fake_external_begin_frame_source_.get();
268 } else { 270 } else {
269 synthetic_frame_source_ = TestSyntheticBeginFrameSource::Create(
270 now_src_.get(), task_runner_.get(),
271 BeginFrameArgs::DefaultInterval());
272 frame_source = synthetic_frame_source_.get(); 271 frame_source = synthetic_frame_source_.get();
273 } 272 }
274 273
275 scoped_ptr<FakeCompositorTimingHistory> fake_compositor_timing_history = 274 scoped_ptr<FakeCompositorTimingHistory> fake_compositor_timing_history =
276 FakeCompositorTimingHistory::Create( 275 FakeCompositorTimingHistory::Create(
277 scheduler_settings_.using_synchronous_renderer_compositor); 276 scheduler_settings_.using_synchronous_renderer_compositor);
278 fake_compositor_timing_history_ = fake_compositor_timing_history.get(); 277 fake_compositor_timing_history_ = fake_compositor_timing_history.get();
279 278
280 scheduler_.reset( 279 scheduler_.reset(
281 new TestScheduler(now_src_.get(), client_.get(), scheduler_settings_, 0, 280 new TestScheduler(now_src_.get(), client_.get(), scheduler_settings_, 0,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), 388 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"),
390 "FakeSchedulerClient::AdvanceFrame"); 389 "FakeSchedulerClient::AdvanceFrame");
391 // Consume any previous deadline first, if no deadline is currently 390 // Consume any previous deadline first, if no deadline is currently
392 // pending, ImplFrameDeadlinePending will return false straight away and we 391 // pending, ImplFrameDeadlinePending will return false straight away and we
393 // will run no tasks. 392 // will run no tasks.
394 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 393 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true));
395 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 394 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
396 395
397 // Send the next BeginFrame message if using an external source, otherwise 396 // Send the next BeginFrame message if using an external source, otherwise
398 // it will be already in the task queue. 397 // it will be already in the task queue.
399 if (scheduler_->settings().use_external_begin_frame_source && 398 if (scheduler_->begin_frame_source() ==
400 scheduler_->FrameProductionThrottled()) { 399 fake_external_begin_frame_source_.get()) {
401 EXPECT_TRUE(scheduler_->begin_frames_expected()); 400 EXPECT_TRUE(scheduler_->begin_frames_expected());
402 SendNextBeginFrame(); 401 SendNextBeginFrame();
403 } 402 }
404 403
405 if (!scheduler_->settings().using_synchronous_renderer_compositor) { 404 if (!scheduler_->settings().using_synchronous_renderer_compositor) {
406 // Then run tasks until new deadline is scheduled. 405 // Then run tasks until new deadline is scheduled.
407 EXPECT_TRUE(task_runner_->RunTasksWhile( 406 EXPECT_TRUE(task_runner_->RunTasksWhile(
408 client_->ImplFrameDeadlinePending(false))); 407 client_->ImplFrameDeadlinePending(false)));
409 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 408 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
410 } 409 }
411 } 410 }
412 411
413 BeginFrameArgs SendNextBeginFrame() { 412 BeginFrameArgs SendNextBeginFrame() {
414 DCHECK(scheduler_->settings().use_external_begin_frame_source); 413 DCHECK_EQ(scheduler_->begin_frame_source(),
414 fake_external_begin_frame_source_.get());
415 // Creep the time forward so that any BeginFrameArgs is not equal to the 415 // Creep the time forward so that any BeginFrameArgs is not equal to the
416 // last one otherwise we violate the BeginFrameSource contract. 416 // last one otherwise we violate the BeginFrameSource contract.
417 now_src_->Advance(BeginFrameArgs::DefaultInterval()); 417 now_src_->Advance(BeginFrameArgs::DefaultInterval());
418 BeginFrameArgs args = 418 BeginFrameArgs args =
419 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); 419 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src());
420 fake_external_begin_frame_source_->TestOnBeginFrame(args); 420 fake_external_begin_frame_source_->TestOnBeginFrame(args);
421 return args; 421 return args;
422 } 422 }
423 423
424 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { 424 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const {
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3048 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 3048 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3049 3049
3050 client_->Reset(); 3050 client_->Reset();
3051 fake_external_begin_frame_source_->SetPaused(true); 3051 fake_external_begin_frame_source_->SetPaused(true);
3052 task_runner().RunPendingTasks(); // Run posted deadline. 3052 task_runner().RunPendingTasks(); // Run posted deadline.
3053 3053
3054 // Sync tree should be forced to activate. 3054 // Sync tree should be forced to activate.
3055 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); 3055 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
3056 } 3056 }
3057 3057
3058 // Tests to ensure frame sources can be successfully changed while drawing.
3059 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) {
3060 scheduler_settings_.use_external_begin_frame_source = true;
3061 SetUpScheduler(true);
3062
3063 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
3064 scheduler_->SetNeedsRedraw();
3065 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3066 client_->Reset();
3067
3068 EXPECT_SCOPED(AdvanceFrame());
3069 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1);
3070 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3071 EXPECT_TRUE(scheduler_->begin_frames_expected());
3072 client_->Reset();
3073 task_runner().RunPendingTasks(); // Run posted deadline.
3074 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
3075 scheduler_->SetNeedsRedraw();
3076
3077 // Switch to an unthrottled frame source.
3078 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get());
3079 client_->Reset();
3080
3081 // Unthrottled frame source will immediately begin a new frame.
3082 task_runner().RunPendingTasks(); // Run posted BeginFrame.
3083 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1);
3084 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3085 client_->Reset();
3086
3087 // If we don't swap on the deadline, we wait for the next BeginFrame.
3088 task_runner().RunPendingTasks(); // Run posted deadline.
3089 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
3090 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
3091 client_->Reset();
3092 }
3093
3094 // Tests to ensure frame sources can be successfully changed while a frame
3095 // deadline is pending.
3096 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) {
3097 scheduler_settings_.use_external_begin_frame_source = true;
3098 SetUpScheduler(true);
3099
3100 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
3101 scheduler_->SetNeedsRedraw();
3102 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3103 client_->Reset();
3104
3105 EXPECT_SCOPED(AdvanceFrame());
3106 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
3107
3108 // Switch to an unthrottled frame source before the frame deadline is hit.
3109 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get());
3110 client_->Reset();
3111
3112 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3113 EXPECT_TRUE(scheduler_->begin_frames_expected());
3114 client_->Reset();
3115
3116 task_runner().RunPendingTasks(); // Run posted deadline.
3117 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
3118 client_->Reset();
3119
3120 // Unthrottled frame source will immediately begin a new frame.
3121 task_runner().RunPendingTasks(); // Run BeginFrame.
3122 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
3123 scheduler_->SetNeedsRedraw();
3124 client_->Reset();
3125
3126 task_runner().RunPendingTasks(); // Run posted deadline.
3127 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
3128 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
3129 client_->Reset();
3130 }
3131
3132 // Tests to ensure that the active frame source can successfully be changed from
3133 // unthrottled to throttled.
3134 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) {
3135 scheduler_settings_.throttle_frame_production = false;
3136 scheduler_settings_.use_external_begin_frame_source = true;
3137 SetUpScheduler(true);
3138
3139 scheduler_->SetNeedsRedraw();
3140 EXPECT_NO_ACTION(client_);
3141 client_->Reset();
3142
3143 task_runner().RunPendingTasks(); // Run posted BeginFrame.
3144 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1);
3145 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3146 client_->Reset();
3147
3148 task_runner().RunPendingTasks(); // Run posted deadline.
3149 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
3150 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
3151 client_->Reset();
3152
3153 // Switch to a throttled frame source.
3154 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get());
3155 client_->Reset();
3156
3157 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
3158 scheduler_->SetNeedsRedraw();
3159 task_runner().RunPendingTasks();
3160 EXPECT_NO_ACTION(client_);
3161 client_->Reset();
3162
3163 EXPECT_SCOPED(AdvanceFrame());
3164 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1);
3165 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3166 EXPECT_TRUE(scheduler_->begin_frames_expected());
3167 client_->Reset();
3168 task_runner().RunPendingTasks(); // Run posted deadline.
3169 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
3170 }
3171
3172 // This test maskes sure that switching a frame source when not observing
3173 // such as when not visible also works.
3174 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) {
3175 scheduler_settings_.use_external_begin_frame_source = true;
3176 SetUpScheduler(true);
3177
3178 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame.
3179 scheduler_->SetNeedsBeginMainFrame();
3180 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3181 client_->Reset();
3182
3183 // Begin new frame.
3184 EXPECT_SCOPED(AdvanceFrame());
3185 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks());
3186 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3187 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
3188
3189 client_->Reset();
3190 scheduler_->NotifyReadyToCommit();
3191 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
3192
3193 client_->Reset();
3194 scheduler_->NotifyReadyToActivate();
3195 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
3196
3197 // Scheduler loses output surface, and stops waiting for ready to draw signal.
3198 client_->Reset();
3199 scheduler_->DidLoseOutputSurface();
3200 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
3201 task_runner().RunPendingTasks();
3202 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
3203 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3);
3204 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
3205
3206 // Changing begin frame source doesn't do anything.
3207 // The unthrottled source doesn't print Add/RemoveObserver like the fake one.
3208 client_->Reset();
3209 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get());
3210 EXPECT_NO_ACTION(client_);
3211
3212 client_->Reset();
3213 scheduler_->DidCreateAndInitializeOutputSurface();
3214 EXPECT_NO_ACTION(client_);
3215
3216 client_->Reset();
3217 scheduler_->SetNeedsBeginMainFrame();
3218 EXPECT_NO_ACTION(client_);
3219
3220 client_->Reset();
3221 EXPECT_SCOPED(AdvanceFrame());
3222 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3223 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
3224 }
3225
3058 // Tests to ensure that we send a BeginMainFrameNotExpectedSoon when expected. 3226 // Tests to ensure that we send a BeginMainFrameNotExpectedSoon when expected.
3059 TEST_F(SchedulerTest, SendBeginMainFrameNotExpectedSoon) { 3227 TEST_F(SchedulerTest, SendBeginMainFrameNotExpectedSoon) {
3060 scheduler_settings_.use_external_begin_frame_source = true; 3228 scheduler_settings_.use_external_begin_frame_source = true;
3061 SetUpScheduler(true); 3229 SetUpScheduler(true);
3062 3230
3063 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. 3231 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame.
3064 scheduler_->SetNeedsBeginMainFrame(); 3232 scheduler_->SetNeedsBeginMainFrame();
3065 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 3233 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3066 client_->Reset(); 3234 client_->Reset();
3067 3235
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 } 3799 }
3632 3800
3633 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { 3801 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) {
3634 EXPECT_FALSE(BeginMainFrameOnCriticalPath( 3802 EXPECT_FALSE(BeginMainFrameOnCriticalPath(
3635 SMOOTHNESS_TAKES_PRIORITY, 3803 SMOOTHNESS_TAKES_PRIORITY,
3636 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); 3804 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration));
3637 } 3805 }
3638 3806
3639 } // namespace 3807 } // namespace
3640 } // namespace cc 3808 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.cc ('k') | cc/test/scheduler_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698