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

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

Issue 23907006: cc: Allow sending BeginMainFrame before draw or activation (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedDeadline3
Patch Set: Do not start commit before draw for UI compositor Created 6 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
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_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 10 #define EXPECT_ACTION_UPDATE_STATE(action) \
11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \
12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
14 if (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW == \
15 state.CommitState() && \
16 SchedulerStateMachine::OUTPUT_SURFACE_ACTIVE != \
17 state.output_surface_state()) \
18 return; \
19 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 14 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \
20 state.begin_impl_frame_state()) \ 15 state.begin_impl_frame_state()) \
21 << *state.AsValue(); \ 16 << *state.AsValue(); \
22 } \ 17 } \
23 state.UpdateState(action); \ 18 state.UpdateState(action); \
24 if (action == SchedulerStateMachine::ACTION_NONE) { \ 19 if (action == SchedulerStateMachine::ACTION_NONE) { \
25 if (state.begin_impl_frame_state() == \ 20 if (state.begin_impl_frame_state() == \
26 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 21 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
27 state.OnBeginImplFrameDeadlinePending(); \ 22 state.OnBeginImplFrameDeadlinePending(); \
28 if (state.begin_impl_frame_state() == \ 23 if (state.begin_impl_frame_state() == \
29 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 24 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
30 state.OnBeginImplFrameIdle(); \ 25 state.OnBeginImplFrameIdle(); \
31 } 26 }
32 27
33 namespace cc { 28 namespace cc {
34 29
35 namespace { 30 namespace {
36 31
37 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 32 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
38 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 33 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
39 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 34 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
40 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 35 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 36 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, };
42 37
43 const SchedulerStateMachine::CommitState all_commit_states[] = { 38 const SchedulerStateMachine::CommitState all_commit_states[] = {
44 SchedulerStateMachine::COMMIT_STATE_IDLE, 39 SchedulerStateMachine::COMMIT_STATE_IDLE,
45 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 40 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
46 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 41 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, };
47 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, };
48 42
49 // Exposes the protected state fields of the SchedulerStateMachine for testing 43 // Exposes the protected state fields of the SchedulerStateMachine for testing
50 class StateMachine : public SchedulerStateMachine { 44 class StateMachine : public SchedulerStateMachine {
51 public: 45 public:
52 explicit StateMachine(const SchedulerSettings& scheduler_settings) 46 explicit StateMachine(const SchedulerSettings& scheduler_settings)
53 : SchedulerStateMachine(scheduler_settings) {} 47 : SchedulerStateMachine(scheduler_settings) {}
54 48
55 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { 49 void CreateAndInitializeOutputSurfaceWithActivatedCommit() {
56 DidCreateAndInitializeOutputSurface(); 50 DidCreateAndInitializeOutputSurface();
57 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 51 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
(...skipping 19 matching lines...) Expand all
77 } 71 }
78 72
79 SynchronousReadbackState readback_state() const { return readback_state_; } 73 SynchronousReadbackState readback_state() const { return readback_state_; }
80 74
81 bool NeedsCommit() const { return needs_commit_; } 75 bool NeedsCommit() const { return needs_commit_; }
82 76
83 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 77 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
84 78
85 void SetNeedsForcedRedrawForTimeout(bool b) { 79 void SetNeedsForcedRedrawForTimeout(bool b) {
86 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 80 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
87 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 81 active_tree_needs_first_draw_ = true;
88 } 82 }
89 bool NeedsForcedRedrawForTimeout() const { 83 bool NeedsForcedRedrawForTimeout() const {
90 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 84 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
91 } 85 }
92 86
93 void SetNeedsForcedRedrawForReadback() { 87 void SetNeedsForcedRedrawForReadback() {
94 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 88 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
95 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 89 active_tree_needs_first_draw_ = true;
96 } 90 }
97 91
98 bool NeedsForcedRedrawForReadback() const { 92 bool NeedsForcedRedrawForReadback() const {
99 return readback_state_ != READBACK_STATE_IDLE; 93 return readback_state_ != READBACK_STATE_IDLE;
100 } 94 }
101 95
102 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { 96 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
103 active_tree_needs_first_draw_ = needs_first_draw; 97 active_tree_needs_first_draw_ = needs_first_draw;
104 } 98 }
105 99
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 state.UpdateState(state.NextAction()); 171 state.UpdateState(state.NextAction());
178 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 172 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
179 state.SetVisible(true); 173 state.SetVisible(true);
180 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 174 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
181 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 175 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
182 state.CommitState()); 176 state.CommitState());
183 EXPECT_FALSE(state.NeedsCommit()); 177 EXPECT_FALSE(state.NeedsCommit());
184 } 178 }
185 } 179 }
186 180
181 // start_commit_before_draw_enabled = false
182 // This is enabled by default.
danakj 2014/03/05 19:52:43 Can you reword this, I'm not sure if it's saying s
183 TEST(SchedulerStateMachineTest, StartCommitBeforeDrawDisabled) {
brianderson 2014/03/05 00:30:48 I went ahead and added this test to make sure we e
184 SchedulerSettings scheduler_settings;
185 scheduler_settings.impl_side_painting = true;
186 scheduler_settings.start_commit_before_draw_enabled = false;
187 StateMachine state(scheduler_settings);
188 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
189 state.SetCanStart();
190 state.UpdateState(state.NextAction());
191 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
192 state.SetNeedsRedraw(false);
193 state.SetVisible(true);
194 state.SetCanDraw(true);
195 state.SetNeedsCommit();
196
197 EXPECT_TRUE(state.BeginImplFrameNeeded());
198
199 // Commit to the pending tree.
200 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
201 EXPECT_ACTION_UPDATE_STATE(
202 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
204 state.FinishCommit();
205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
207 EXPECT_EQ(state.CommitState(),
208 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
209
210 state.OnBeginImplFrameDeadline();
211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
212 EXPECT_EQ(state.CommitState(),
213 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
214
215 // Verify that the next commit doesn't start until the previous
216 // commit has been drawn.
217 state.SetNeedsCommit();
218 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
220
221 // Verify NotifyReadyToActivate unblocks activation, draw, and
222 // commit in that order.
223 state.NotifyReadyToActivate();
224 EXPECT_ACTION_UPDATE_STATE(
225 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
226 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
227 EXPECT_EQ(state.CommitState(),
228 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
229
230 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
231 state.OnBeginImplFrameDeadline();
232 EXPECT_ACTION_UPDATE_STATE(
233 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
234 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
235 EXPECT_ACTION_UPDATE_STATE(
236 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
237 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
238 EXPECT_EQ(state.CommitState(),
239 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
240
241 state.FinishCommit();
242 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
243 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
244 EXPECT_EQ(state.CommitState(),
245 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
246 }
247
248 // start_commit_before_activate_enabled = true
249 // This is disabled by default.
250 TEST(SchedulerStateMachineTest, StartCommitBeforeActivateEnabled) {
251 SchedulerSettings scheduler_settings;
252 scheduler_settings.impl_side_painting = true;
253 scheduler_settings.start_commit_before_activate_enabled = true;
254 StateMachine state(scheduler_settings);
255 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
256 state.SetCanStart();
257 state.UpdateState(state.NextAction());
258 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
259 state.SetNeedsRedraw(false);
260 state.SetVisible(true);
261 state.SetCanDraw(true);
262 state.SetNeedsCommit();
263
264 EXPECT_TRUE(state.BeginImplFrameNeeded());
265
266 // Commit to the pending tree.
267 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
268 EXPECT_ACTION_UPDATE_STATE(
269 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
270 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
271 state.FinishCommit();
272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
274 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
275
276 state.OnBeginImplFrameDeadline();
277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
278
279 // Verify that the next commit starts while there is still a pending tree.
280 state.SetNeedsCommit();
281 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
282 EXPECT_ACTION_UPDATE_STATE(
283 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
285
286 // Verify the pending commit doesn't overwrite the pending
287 // tree until the pending tree has been activated.
288 state.FinishCommit();
289 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
290
291 // Verify NotifyReadyToActivate unblocks activation, draw, and
292 // commit in that order.
293 state.NotifyReadyToActivate();
294 EXPECT_ACTION_UPDATE_STATE(
295 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
296 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
297
298 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
299 state.OnBeginImplFrameDeadline();
300 EXPECT_ACTION_UPDATE_STATE(
301 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
304 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
305 }
306
187 TEST(SchedulerStateMachineTest, 307 TEST(SchedulerStateMachineTest,
188 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 308 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
189 SchedulerSettings default_scheduler_settings; 309 SchedulerSettings default_scheduler_settings;
190 StateMachine state(default_scheduler_settings); 310 StateMachine state(default_scheduler_settings);
191 state.SetCanStart(); 311 state.SetCanStart();
192 state.UpdateState(state.NextAction()); 312 state.UpdateState(state.NextAction());
193 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 313 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
194 state.SetVisible(true); 314 state.SetVisible(true);
195 state.SetCanDraw(true); 315 state.SetCanDraw(true);
196 state.SetNeedsRedraw(true); 316 state.SetNeedsRedraw(true);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 400
281 // Failing the draw for animation checkerboards makes us require a commit. 401 // Failing the draw for animation checkerboards makes us require a commit.
282 state.DidDrawIfPossibleCompleted( 402 state.DidDrawIfPossibleCompleted(
283 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 403 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
284 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 404 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
285 EXPECT_ACTION_UPDATE_STATE( 405 EXPECT_ACTION_UPDATE_STATE(
286 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 406 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
287 EXPECT_TRUE(state.RedrawPending()); 407 EXPECT_TRUE(state.RedrawPending());
288 } 408 }
289 409
290 TEST(SchedulerStateMachineTest, 410 void TestFailedDrawsEventuallyForceDrawAfterNextCommit(
291 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { 411 bool start_commit_before_draw_enabled) {
292 SchedulerSettings scheduler_settings; 412 SchedulerSettings scheduler_settings;
413 scheduler_settings.start_commit_before_draw_enabled =
414 start_commit_before_draw_enabled;
293 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 415 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
294 StateMachine state(scheduler_settings); 416 StateMachine state(scheduler_settings);
295 state.SetCanStart(); 417 state.SetCanStart();
296 state.UpdateState(state.NextAction()); 418 state.UpdateState(state.NextAction());
297 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 419 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
298 state.SetVisible(true); 420 state.SetVisible(true);
299 state.SetCanDraw(true); 421 state.SetCanDraw(true);
300 422
301 // Start a commit. 423 // Start a commit.
302 state.SetNeedsCommit(); 424 state.SetNeedsCommit();
(...skipping 21 matching lines...) Expand all
324 446
325 // Finish the commit. Note, we should not yet be forcing a draw, but should 447 // Finish the commit. Note, we should not yet be forcing a draw, but should
326 // continue the commit as usual. 448 // continue the commit as usual.
327 state.FinishCommit(); 449 state.FinishCommit();
328 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 450 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
330 EXPECT_TRUE(state.RedrawPending()); 452 EXPECT_TRUE(state.RedrawPending());
331 453
332 // The redraw should be forced at the end of the next BeginImplFrame. 454 // The redraw should be forced at the end of the next BeginImplFrame.
333 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 455 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
456 if (start_commit_before_draw_enabled) {
457 EXPECT_ACTION_UPDATE_STATE(
458 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
459 }
334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
335 state.OnBeginImplFrameDeadline(); 461 state.OnBeginImplFrameDeadline();
336 EXPECT_ACTION_UPDATE_STATE( 462 EXPECT_ACTION_UPDATE_STATE(
337 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 463 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
338 } 464 }
339 465
466 TEST(SchedulerStateMachineTest,
467 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
468 bool start_commit_before_draw_enabled = false;
469 TestFailedDrawsEventuallyForceDrawAfterNextCommit(
470 start_commit_before_draw_enabled);
471 }
472
473 TEST(SchedulerStateMachineTest,
474 TestFailedDrawsEventuallyForceDrawAfterNextCommit_CommitBeforeDraw) {
475 bool start_commit_before_draw_enabled = true;
476 TestFailedDrawsEventuallyForceDrawAfterNextCommit(
477 start_commit_before_draw_enabled);
478 }
479
340 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 480 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
341 SchedulerSettings scheduler_settings; 481 SchedulerSettings scheduler_settings;
342 int draw_limit = 1; 482 int draw_limit = 1;
343 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 483 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ =
344 draw_limit; 484 draw_limit;
345 scheduler_settings.impl_side_painting = true; 485 scheduler_settings.impl_side_painting = true;
346 StateMachine state(scheduler_settings); 486 StateMachine state(scheduler_settings);
347 state.SetCanStart(); 487 state.SetCanStart();
348 state.UpdateState(state.NextAction()); 488 state.UpdateState(state.NextAction());
349 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 489 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 state.NextAction()); 650 state.NextAction());
511 651
512 // Case 2: needs_commit=true 652 // Case 2: needs_commit=true
513 state.SetNeedsCommit(); 653 state.SetNeedsCommit();
514 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 654 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
515 state.NextAction()) 655 state.NextAction())
516 << *state.AsValue(); 656 << *state.AsValue();
517 } 657 }
518 } 658 }
519 659
520 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw or 660 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
521 // SetNeedsForcedRedrawForReadback have been called... except if we're 661 // except if we're ready to commit, in which case we expect a commit first.
522 // ready to commit, in which case we expect a commit first. 662 // SetNeedsForcedRedrawForReadback should take precedence over all and
663 // issue a readback.
523 for (size_t i = 0; i < num_commit_states; ++i) { 664 for (size_t i = 0; i < num_commit_states; ++i) {
524 for (size_t j = 0; j < 2; ++j) { 665 for (size_t j = 0; j < 2; ++j) {
525 bool request_readback = j; 666 bool request_readback = j;
526 667
527 // Skip invalid states
528 if (request_readback &&
529 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW !=
530 all_commit_states[i]))
531 continue;
532
533 StateMachine state(default_scheduler_settings); 668 StateMachine state(default_scheduler_settings);
534 state.SetCanStart(); 669 state.SetCanStart();
535 state.UpdateState(state.NextAction()); 670 state.UpdateState(state.NextAction());
536 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 671 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
537 state.SetCanDraw(true); 672 state.SetCanDraw(true);
538 state.SetCommitState(all_commit_states[i]); 673 state.SetCommitState(all_commit_states[i]);
539 state.SetBeginImplFrameState( 674 state.SetBeginImplFrameState(
540 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 675 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
541 if (request_readback) { 676 if (request_readback) {
542 state.SetNeedsForcedRedrawForReadback(); 677 state.SetNeedsForcedRedrawForReadback();
543 } else { 678 } else {
544 state.SetNeedsRedraw(true); 679 state.SetNeedsRedraw(true);
545 state.SetVisible(true); 680 state.SetVisible(true);
546 } 681 }
547 682
548 SchedulerStateMachine::Action expected_action; 683 SchedulerStateMachine::Action expected_action;
549 if (all_commit_states[i] == 684 if (request_readback) {
550 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 685 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
686 } else if (all_commit_states[i] ==
687 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
551 expected_action = SchedulerStateMachine::ACTION_COMMIT; 688 expected_action = SchedulerStateMachine::ACTION_COMMIT;
552 } else if (request_readback) {
553 if (all_commit_states[i] ==
554 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
555 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
556 else
557 expected_action = SchedulerStateMachine::ACTION_NONE;
558 } else { 689 } else {
559 expected_action = 690 expected_action =
560 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 691 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
561 } 692 }
562 693
563 // Case 1: needs_commit=false. 694 // Case 1: needs_commit=false.
564 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 695 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
565 << *state.AsValue(); 696 << *state.AsValue();
566 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 697 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
567 698
568 // Case 2: needs_commit=true. 699 // Case 2: needs_commit=true.
569 state.SetNeedsCommit(); 700 state.SetNeedsCommit();
570 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 701 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
571 << *state.AsValue(); 702 << *state.AsValue();
572 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 703 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
573 } 704 }
574 } 705 }
575 } 706 }
576 707
577 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 708 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
578 SchedulerSettings default_scheduler_settings; 709 SchedulerSettings default_scheduler_settings;
579 710
580 size_t num_commit_states = 711 size_t num_commit_states =
581 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 712 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
582 for (size_t i = 0; i < num_commit_states; ++i) { 713 for (size_t i = 0; i < num_commit_states; ++i) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 } 764 }
634 765
635 TEST(SchedulerStateMachineTest, 766 TEST(SchedulerStateMachineTest,
636 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 767 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
637 SchedulerSettings default_scheduler_settings; 768 SchedulerSettings default_scheduler_settings;
638 StateMachine state(default_scheduler_settings); 769 StateMachine state(default_scheduler_settings);
639 state.SetCanStart(); 770 state.SetCanStart();
640 state.UpdateState(state.NextAction()); 771 state.UpdateState(state.NextAction());
641 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 772 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
642 773
643 state.SetCommitState(
644 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
645 state.SetActiveTreeNeedsFirstDraw(true); 774 state.SetActiveTreeNeedsFirstDraw(true);
646 state.SetNeedsCommit(); 775 state.SetNeedsCommit();
647 state.SetNeedsRedraw(true); 776 state.SetNeedsRedraw(true);
648 state.SetVisible(true); 777 state.SetVisible(true);
649 state.SetCanDraw(false); 778 state.SetCanDraw(false);
650 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 779 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 780 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
652 EXPECT_ACTION_UPDATE_STATE( 781 EXPECT_ACTION_UPDATE_STATE(
653 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 782 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
655 state.FinishCommit(); 784 state.FinishCommit();
656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 785 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
657 state.OnBeginImplFrameDeadline(); 786 state.OnBeginImplFrameDeadline();
658 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 787 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 788 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
660 } 789 }
661 790
662 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { 791 void TestsetNeedsCommitIsNotLost(bool start_commit_before_draw_enabled) {
danakj 2014/03/05 19:52:43 s/TestsetNeeds/TestSetNeeds/g Looks like that s g
663 SchedulerSettings default_scheduler_settings; 792 SchedulerSettings scheduler_settings;
664 StateMachine state(default_scheduler_settings); 793 scheduler_settings.start_commit_before_draw_enabled =
794 start_commit_before_draw_enabled;
795 StateMachine state(scheduler_settings);
665 state.SetCanStart(); 796 state.SetCanStart();
666 state.UpdateState(state.NextAction()); 797 state.UpdateState(state.NextAction());
667 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 798 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
668 state.SetNeedsCommit(); 799 state.SetNeedsCommit();
669 state.SetVisible(true); 800 state.SetVisible(true);
670 state.SetCanDraw(true); 801 state.SetCanDraw(true);
671 802
672 EXPECT_TRUE(state.BeginImplFrameNeeded()); 803 EXPECT_TRUE(state.BeginImplFrameNeeded());
673 804
674 // Begin the frame. 805 // Begin the frame.
(...skipping 30 matching lines...) Expand all
705 state.OnBeginImplFrameIdle(); 836 state.OnBeginImplFrameIdle();
706 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 837 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
707 state.begin_impl_frame_state()); 838 state.begin_impl_frame_state());
708 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 839 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
709 840
710 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 841 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
711 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 842 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
712 state.begin_impl_frame_state()); 843 state.begin_impl_frame_state());
713 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 844 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
714 845
715 // Commit and make sure we draw on next BeginImplFrame 846 // Finish the commit, then make sure we start the next commit immediately
847 // and draw on the next BeginImplFrame.
716 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 848 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
849 if (start_commit_before_draw_enabled) {
850 EXPECT_ACTION_UPDATE_STATE(
851 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
852 }
717 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
854
718 state.OnBeginImplFrameDeadline(); 855 state.OnBeginImplFrameDeadline();
719 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 856
720 state.CommitState()); 857 EXPECT_TRUE(state.active_tree_needs_first_draw());
721 EXPECT_ACTION_UPDATE_STATE( 858 EXPECT_ACTION_UPDATE_STATE(
722 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 859 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
723 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 860 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
861 if (!start_commit_before_draw_enabled) {
862 EXPECT_ACTION_UPDATE_STATE(
863 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
864 }
865 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
866 }
724 867
725 // Verify that another commit will start immediately after draw. 868 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) {
726 EXPECT_ACTION_UPDATE_STATE( 869 bool start_commit_before_draw_enabled = false;
727 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 870 TestsetNeedsCommitIsNotLost(start_commit_before_draw_enabled);
728 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 871 }
872
873 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost_CommitBeforeDraw) {
874 bool start_commit_before_draw_enabled = true;
875 TestsetNeedsCommitIsNotLost(start_commit_before_draw_enabled);
729 } 876 }
730 877
731 TEST(SchedulerStateMachineTest, TestFullCycle) { 878 TEST(SchedulerStateMachineTest, TestFullCycle) {
732 SchedulerSettings default_scheduler_settings; 879 SchedulerSettings default_scheduler_settings;
733 StateMachine state(default_scheduler_settings); 880 StateMachine state(default_scheduler_settings);
734 state.SetCanStart(); 881 state.SetCanStart();
735 state.UpdateState(state.NextAction()); 882 state.UpdateState(state.NextAction());
736 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 883 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
737 state.SetVisible(true); 884 state.SetVisible(true);
738 state.SetCanDraw(true); 885 state.SetCanDraw(true);
(...skipping 10 matching lines...) Expand all
749 EXPECT_FALSE(state.NeedsCommit()); 896 EXPECT_FALSE(state.NeedsCommit());
750 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 897 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
751 898
752 // Tell the scheduler the frame finished. 899 // Tell the scheduler the frame finished.
753 state.FinishCommit(); 900 state.FinishCommit();
754 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 901 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
755 state.CommitState()); 902 state.CommitState());
756 903
757 // Commit. 904 // Commit.
758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 905 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
759 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 906 EXPECT_TRUE(state.active_tree_needs_first_draw());
760 state.CommitState());
761 EXPECT_TRUE(state.needs_redraw()); 907 EXPECT_TRUE(state.needs_redraw());
762 908
763 // Expect to do nothing until BeginImplFrame deadline 909 // Expect to do nothing until BeginImplFrame deadline
764 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
765 911
766 // At BeginImplFrame deadline, draw. 912 // At BeginImplFrame deadline, draw.
767 state.OnBeginImplFrameDeadline(); 913 state.OnBeginImplFrameDeadline();
768 EXPECT_ACTION_UPDATE_STATE( 914 EXPECT_ACTION_UPDATE_STATE(
769 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 915 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
770 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 916 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 29 matching lines...) Expand all
800 state.SetNeedsCommit(); 946 state.SetNeedsCommit();
801 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 947 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
802 948
803 // Tell the scheduler the frame finished. 949 // Tell the scheduler the frame finished.
804 state.FinishCommit(); 950 state.FinishCommit();
805 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 951 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
806 state.CommitState()); 952 state.CommitState());
807 953
808 // First commit. 954 // First commit.
809 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 955 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
810 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 956 EXPECT_TRUE(state.active_tree_needs_first_draw());
811 state.CommitState());
812 EXPECT_TRUE(state.needs_redraw()); 957 EXPECT_TRUE(state.needs_redraw());
813 958
814 // Expect to do nothing until BeginImplFrame deadline. 959 // Expect to do nothing until BeginImplFrame deadline.
815 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 960 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
816 961
817 // At BeginImplFrame deadline, draw. 962 // At BeginImplFrame deadline, draw.
818 state.OnBeginImplFrameDeadline(); 963 state.OnBeginImplFrameDeadline();
819 EXPECT_ACTION_UPDATE_STATE( 964 EXPECT_ACTION_UPDATE_STATE(
820 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 965 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
821 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 966 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // Ask for another draw. Expect nothing happens. 1233 // Ask for another draw. Expect nothing happens.
1089 state.SetNeedsRedraw(true); 1234 state.SetNeedsRedraw(true);
1090 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1235 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1091 1236
1092 // Finish the frame, and commit. 1237 // Finish the frame, and commit.
1093 state.FinishCommit(); 1238 state.FinishCommit();
1094 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1095 1240
1096 // We will abort the draw when the output surface is lost if we are 1241 // We will abort the draw when the output surface is lost if we are
1097 // waiting for the first draw to unblock the main thread. 1242 // waiting for the first draw to unblock the main thread.
1098 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1243 EXPECT_TRUE(state.active_tree_needs_first_draw());
1099 state.CommitState());
1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1244 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1101 1245
1102 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1246 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1103 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1247 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1104 state.begin_impl_frame_state()); 1248 state.begin_impl_frame_state());
1105 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1249 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1106 state.NextAction()); 1250 state.NextAction());
1107 1251
1108 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1252 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1109 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1253 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 state.DidLoseOutputSurface(); 1294 state.DidLoseOutputSurface();
1151 1295
1152 // Ask for another draw and also set needs commit. Expect nothing happens. 1296 // Ask for another draw and also set needs commit. Expect nothing happens.
1153 state.SetNeedsRedraw(true); 1297 state.SetNeedsRedraw(true);
1154 state.SetNeedsCommit(); 1298 state.SetNeedsCommit();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1156 1300
1157 // Finish the frame, and commit. 1301 // Finish the frame, and commit.
1158 state.FinishCommit(); 1302 state.FinishCommit();
1159 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1160 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1304 EXPECT_TRUE(state.active_tree_needs_first_draw());
1161 state.CommitState());
1162 1305
1163 // Because the output surface is missing, we expect the draw to abort. 1306 // Because the output surface is missing, we expect the draw to abort.
1164 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1165 1308
1166 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1309 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1167 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1310 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1168 state.begin_impl_frame_state()); 1311 state.begin_impl_frame_state());
1169 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1312 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1170 state.NextAction()); 1313 state.NextAction());
1171 1314
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 state.SetCanStart(); 1352 state.SetCanStart();
1210 state.UpdateState(state.NextAction()); 1353 state.UpdateState(state.NextAction());
1211 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1354 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1212 state.SetVisible(true); 1355 state.SetVisible(true);
1213 state.SetCanDraw(true); 1356 state.SetCanDraw(true);
1214 1357
1215 // Cause a lost context lost. 1358 // Cause a lost context lost.
1216 state.DidLoseOutputSurface(); 1359 state.DidLoseOutputSurface();
1217 1360
1218 // Ask a forced redraw for readback and verify it ocurrs. 1361 // Ask a forced redraw for readback and verify it ocurrs.
1219 state.SetCommitState(
1220 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1221 state.SetNeedsForcedRedrawForReadback(); 1362 state.SetNeedsForcedRedrawForReadback();
1222 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1363 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1225 1366
1226 // Forced redraws for readbacks need to be followed by a new commit 1367 // Forced redraws for readbacks need to be followed by a new commit
1227 // to replace the readback commit. 1368 // to replace the readback commit.
1228 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1369 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1229 state.CommitState()); 1370 state.CommitState());
1230 state.FinishCommit(); 1371 state.FinishCommit();
1231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1232 1373
1233 // We don't yet have an output surface, so we the draw and swap should abort. 1374 // We don't yet have an output surface, so we the draw and swap should abort.
1234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1375 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1235 1376
1236 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1377 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1237 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1378 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1238 1379
1239 state.OnBeginImplFrameDeadline(); 1380 state.OnBeginImplFrameDeadline();
1240 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1381 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1241 1382
1242 state.OnBeginImplFrameIdle(); 1383 state.OnBeginImplFrameIdle();
1243 EXPECT_ACTION_UPDATE_STATE( 1384 EXPECT_ACTION_UPDATE_STATE(
1244 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1385 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1245 1386
1246 // Ask a readback and verify it occurs. 1387 // Ask a readback and verify it occurs.
1247 state.SetCommitState(
1248 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1249 state.SetNeedsForcedRedrawForReadback(); 1388 state.SetNeedsForcedRedrawForReadback();
1250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1251 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1252 } 1391 }
1253 1392
1254 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1393 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1255 SchedulerSettings default_scheduler_settings; 1394 SchedulerSettings default_scheduler_settings;
1256 StateMachine state(default_scheduler_settings); 1395 StateMachine state(default_scheduler_settings);
1257 state.SetCanStart(); 1396 state.SetCanStart();
1258 state.UpdateState(state.NextAction()); 1397 state.UpdateState(state.NextAction());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 state.UpdateState(state.NextAction()); 1486 state.UpdateState(state.NextAction());
1348 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1487 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1349 state.SetVisible(false); 1488 state.SetVisible(false);
1350 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1489 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1351 state.SetNeedsCommit(); 1490 state.SetNeedsCommit();
1352 1491
1353 state.FinishCommit(); 1492 state.FinishCommit();
1354 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1493 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1355 state.UpdateState(state.NextAction()); 1494 state.UpdateState(state.NextAction());
1356 1495
1357 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1496 EXPECT_TRUE(state.active_tree_needs_first_draw());
1358 state.CommitState());
1359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1360 } 1498 }
1361 1499
1362 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { 1500 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1363 SchedulerSettings default_scheduler_settings; 1501 SchedulerSettings default_scheduler_settings;
1364 StateMachine state(default_scheduler_settings); 1502 StateMachine state(default_scheduler_settings);
1365 state.SetCanStart(); 1503 state.SetCanStart();
1366 state.UpdateState(state.NextAction()); 1504 state.UpdateState(state.NextAction());
1367 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1505 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1368 state.SetVisible(false); 1506 state.SetVisible(false);
1369 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1507 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1370 state.SetNeedsForcedCommitForReadback(); 1508 state.SetNeedsForcedCommitForReadback();
1371 1509
1372 // The commit for readback interupts the normal commit. 1510 // The commit for readback interupts the normal commit.
1373 state.FinishCommit(); 1511 state.FinishCommit();
1374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1375 1513
1376 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1514 EXPECT_TRUE(state.active_tree_needs_first_draw());
1377 state.CommitState());
1378 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1379 1516
1380 // When the readback interrupts the normal commit, we should not get 1517 // When the readback interrupts the normal commit, we should not get
1381 // another BeginMainFrame when the readback completes. 1518 // another BeginMainFrame when the readback completes.
1382 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1519 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1383 state.NextAction()); 1520 state.NextAction());
1384 1521
1385 // The normal commit can then proceed. 1522 // The normal commit can then proceed.
1386 state.FinishCommit(); 1523 state.FinishCommit();
1387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 // Schedule a readback, commit it, draw it. 1572 // Schedule a readback, commit it, draw it.
1436 state.SetNeedsForcedCommitForReadback(); 1573 state.SetNeedsForcedCommitForReadback();
1437 EXPECT_ACTION_UPDATE_STATE( 1574 EXPECT_ACTION_UPDATE_STATE(
1438 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1575 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1439 state.FinishCommit(); 1576 state.FinishCommit();
1440 1577
1441 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1578 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1442 state.CommitState()); 1579 state.CommitState());
1443 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1444 1581
1445 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1582 EXPECT_TRUE(state.active_tree_needs_first_draw());
1446 state.CommitState());
1447 1583
1448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1584 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1449 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1585 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1450 1586
1451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1587 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1452 1588
1453 // Should be waiting for the normal BeginMainFrame. 1589 // Should be waiting for the normal BeginMainFrame.
1454 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1590 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1455 state.CommitState()); 1591 state.CommitState());
1456 } 1592 }
(...skipping 14 matching lines...) Expand all
1471 // Schedule a readback, commit it, draw it. 1607 // Schedule a readback, commit it, draw it.
1472 state.SetNeedsForcedCommitForReadback(); 1608 state.SetNeedsForcedCommitForReadback();
1473 EXPECT_ACTION_UPDATE_STATE( 1609 EXPECT_ACTION_UPDATE_STATE(
1474 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1610 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1476 state.FinishCommit(); 1612 state.FinishCommit();
1477 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1613 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1478 state.CommitState()); 1614 state.CommitState());
1479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1480 1616
1481 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1617 EXPECT_TRUE(state.active_tree_needs_first_draw());
1482 state.CommitState());
1483 1618
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1485 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1620 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1487 1622
1488 // Should be waiting for the normal BeginMainFrame. 1623 // Should be waiting for the normal BeginMainFrame.
1489 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1624 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1490 state.CommitState()) 1625 state.CommitState())
1491 << *state.AsValue(); 1626 << *state.AsValue();
1492 } 1627 }
(...skipping 12 matching lines...) Expand all
1505 1640
1506 state.SetNeedsForcedCommitForReadback(); 1641 state.SetNeedsForcedCommitForReadback();
1507 EXPECT_ACTION_UPDATE_STATE( 1642 EXPECT_ACTION_UPDATE_STATE(
1508 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1643 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1509 state.FinishCommit(); 1644 state.FinishCommit();
1510 1645
1511 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1646 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1512 state.CommitState()); 1647 state.CommitState());
1513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1648 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1514 1649
1515 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1650 EXPECT_TRUE(state.active_tree_needs_first_draw());
1516 state.CommitState());
1517 1651
1518 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1519 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1653 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1521 1655
1522 // Should be waiting for BeginMainFrame. 1656 // Should be waiting for BeginMainFrame.
1523 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1657 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1524 state.CommitState()) 1658 state.CommitState())
1525 << *state.AsValue(); 1659 << *state.AsValue();
1526 1660
(...skipping 19 matching lines...) Expand all
1546 state.UpdateState(state.NextAction()); 1680 state.UpdateState(state.NextAction());
1547 1681
1548 state.SetNeedsForcedCommitForReadback(); 1682 state.SetNeedsForcedCommitForReadback();
1549 state.UpdateState(state.NextAction()); 1683 state.UpdateState(state.NextAction());
1550 state.FinishCommit(); 1684 state.FinishCommit();
1551 1685
1552 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1686 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1553 state.CommitState()); 1687 state.CommitState());
1554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1555 1689
1556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1690 EXPECT_TRUE(state.active_tree_needs_first_draw());
1557 state.CommitState());
1558 1691
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1560 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1693 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1561 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1562 } 1695 }
1563 1696
1564 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1697 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1565 SchedulerSettings default_scheduler_settings; 1698 SchedulerSettings default_scheduler_settings;
1566 StateMachine state(default_scheduler_settings); 1699 StateMachine state(default_scheduler_settings);
1567 state.SetCanStart(); 1700 state.SetCanStart();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1841 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1709 1842
1710 // The deadline is not triggered early until we enter prefer smoothness mode. 1843 // The deadline is not triggered early until we enter prefer smoothness mode.
1711 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1844 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1712 state.SetSmoothnessTakesPriority(true); 1845 state.SetSmoothnessTakesPriority(true);
1713 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1846 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1714 } 1847 }
1715 1848
1716 } // namespace 1849 } // namespace
1717 } // namespace cc 1850 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698