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

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

Issue 1265023005: cc: Add SchedulerStateMachine::DidDraw and use for forced draws (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WillDidAction0
Patch Set: Sunny's comments Created 5 years 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.cc ('k') | no next file » | 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_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
9 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 22 matching lines...) Expand all
33 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ 33 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \
34 << state.AsValue()->ToString() 34 << state.AsValue()->ToString()
35 35
36 #define EXPECT_ACTION_UPDATE_STATE(action) \ 36 #define EXPECT_ACTION_UPDATE_STATE(action) \
37 EXPECT_ACTION(action); \ 37 EXPECT_ACTION(action); \
38 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 38 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
39 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 39 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
40 EXPECT_IMPL_FRAME_STATE( \ 40 EXPECT_IMPL_FRAME_STATE( \
41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ 41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
42 } \ 42 } \
43 WillPerformAction(&state, action); \ 43 PerformAction(&state, action); \
44 if (action == SchedulerStateMachine::ACTION_NONE) { \ 44 if (action == SchedulerStateMachine::ACTION_NONE) { \
45 if (state.begin_impl_frame_state() == \ 45 if (state.begin_impl_frame_state() == \
46 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 46 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
47 state.OnBeginImplFrameDeadlinePending(); \ 47 state.OnBeginImplFrameDeadlinePending(); \
48 if (state.begin_impl_frame_state() == \ 48 if (state.begin_impl_frame_state() == \
49 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 49 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
50 state.OnBeginImplFrameIdle(); \ 50 state.OnBeginImplFrameIdle(); \
51 } 51 }
52 52
53 #define SET_UP_STATE(state) \ 53 #define SET_UP_STATE(state) \
54 state.SetVisible(true); \ 54 state.SetVisible(true); \
55 EXPECT_ACTION_UPDATE_STATE( \ 55 EXPECT_ACTION_UPDATE_STATE( \
56 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \ 56 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \
57 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 57 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
58 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \ 58 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \
59 state.SetCanDraw(true); 59 state.SetCanDraw(true);
60 60
61 namespace cc { 61 namespace cc {
62 62
63 namespace { 63 namespace {
64 64
65 void WillPerformAction(SchedulerStateMachine* sm,
66 SchedulerStateMachine::Action action) {
67 switch (action) {
68 case SchedulerStateMachine::ACTION_NONE:
69 return;
70
71 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
72 sm->WillActivate();
73 return;
74
75 case SchedulerStateMachine::ACTION_ANIMATE:
76 sm->WillAnimate();
77 return;
78
79 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
80 sm->WillSendBeginMainFrame();
81 return;
82
83 case SchedulerStateMachine::ACTION_COMMIT: {
84 bool commit_has_no_updates = false;
85 sm->WillCommit(commit_has_no_updates);
86 return;
87 }
88
89 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED:
90 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
91 bool did_request_swap = true;
92 sm->WillDraw(did_request_swap);
93 return;
94 }
95
96 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: {
97 bool did_request_swap = false;
98 sm->WillDraw(did_request_swap);
99 return;
100 }
101
102 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
103 sm->WillBeginOutputSurfaceCreation();
104 return;
105
106 case SchedulerStateMachine::ACTION_PREPARE_TILES:
107 sm->WillPrepareTiles();
108 return;
109
110 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE:
111 sm->WillInvalidateOutputSurface();
112 return;
113 }
114 }
115
116 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 65 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
117 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 66 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
118 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
119 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
120 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 69 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, };
121 70
122 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = { 71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
123 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE, 72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE,
124 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT, 73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT,
125 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED, 74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED,
126 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT, 75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT,
127 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION, 76 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION,
128 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW}; 77 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW};
129 78
130 // Exposes the protected state fields of the SchedulerStateMachine for testing 79 // Exposes the protected state fields of the SchedulerStateMachine for testing
131 class StateMachine : public SchedulerStateMachine { 80 class StateMachine : public SchedulerStateMachine {
132 public: 81 public:
133 explicit StateMachine(const SchedulerSettings& scheduler_settings) 82 explicit StateMachine(const SchedulerSettings& scheduler_settings)
134 : SchedulerStateMachine(scheduler_settings) {} 83 : SchedulerStateMachine(scheduler_settings),
84 draw_result_for_test_(DRAW_SUCCESS) {}
135 85
136 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { 86 void CreateAndInitializeOutputSurfaceWithActivatedCommit() {
137 DidCreateAndInitializeOutputSurface(); 87 DidCreateAndInitializeOutputSurface();
138 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 88 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
139 } 89 }
140 90
141 void SetBeginMainFrameState(BeginMainFrameState cs) { 91 void SetBeginMainFrameState(BeginMainFrameState cs) {
142 begin_main_frame_state_ = cs; 92 begin_main_frame_state_ = cs;
143 } 93 }
144 BeginMainFrameState BeginMainFrameState() const { 94 BeginMainFrameState BeginMainFrameState() const {
(...skipping 21 matching lines...) Expand all
166 } 116 }
167 117
168 bool NeedsCommit() const { return needs_begin_main_frame_; } 118 bool NeedsCommit() const { return needs_begin_main_frame_; }
169 119
170 void SetNeedsAnimateForTest(bool needs_animate) { 120 void SetNeedsAnimateForTest(bool needs_animate) {
171 needs_animate_ = needs_animate; 121 needs_animate_ = needs_animate;
172 } 122 }
173 123
174 void SetNeedsRedraw(bool needs_redraw) { needs_redraw_ = needs_redraw; } 124 void SetNeedsRedraw(bool needs_redraw) { needs_redraw_ = needs_redraw; }
175 125
126 void SetDrawResultForTest(DrawResult draw_result) {
127 draw_result_for_test_ = draw_result;
128 }
129 DrawResult draw_result_for_test() { return draw_result_for_test_; }
130
176 void SetNeedsForcedRedrawForTimeout(bool b) { 131 void SetNeedsForcedRedrawForTimeout(bool b) {
177 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 132 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
178 active_tree_needs_first_draw_ = true; 133 active_tree_needs_first_draw_ = true;
179 } 134 }
180 bool NeedsForcedRedrawForTimeout() const { 135 bool NeedsForcedRedrawForTimeout() const {
181 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 136 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
182 } 137 }
183 138
184 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { 139 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
185 active_tree_needs_first_draw_ = needs_first_draw; 140 active_tree_needs_first_draw_ = needs_first_draw;
186 } 141 }
187 142
188 bool CanDraw() const { return can_draw_; } 143 bool CanDraw() const { return can_draw_; }
189 bool Visible() const { return visible_; } 144 bool Visible() const { return visible_; }
190 145
191 bool PendingActivationsShouldBeForced() const { 146 bool PendingActivationsShouldBeForced() const {
192 return SchedulerStateMachine::PendingActivationsShouldBeForced(); 147 return SchedulerStateMachine::PendingActivationsShouldBeForced();
193 } 148 }
194 149
195 void SetHasPendingTree(bool has_pending_tree) { 150 void SetHasPendingTree(bool has_pending_tree) {
196 has_pending_tree_ = has_pending_tree; 151 has_pending_tree_ = has_pending_tree;
197 } 152 }
198 153
199 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; 154 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
200 using SchedulerStateMachine::ProactiveBeginFrameWanted; 155 using SchedulerStateMachine::ProactiveBeginFrameWanted;
201 using SchedulerStateMachine::WillCommit; 156 using SchedulerStateMachine::WillCommit;
157
158 protected:
159 DrawResult draw_result_for_test_;
202 }; 160 };
203 161
162 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) {
163 switch (action) {
164 case SchedulerStateMachine::ACTION_NONE:
165 return;
166
167 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
168 sm->WillActivate();
169 return;
170
171 case SchedulerStateMachine::ACTION_ANIMATE:
172 sm->WillAnimate();
173 return;
174
175 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
176 sm->WillSendBeginMainFrame();
177 return;
178
179 case SchedulerStateMachine::ACTION_COMMIT: {
180 bool commit_has_no_updates = false;
181 sm->WillCommit(commit_has_no_updates);
182 return;
183 }
184
185 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED:
186 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
187 sm->WillDraw();
188 sm->DidDraw(sm->draw_result_for_test());
189 return;
190 }
191
192 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: {
193 sm->AbortDrawAndSwap();
194 return;
195 }
196
197 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
198 sm->WillBeginOutputSurfaceCreation();
199 return;
200
201 case SchedulerStateMachine::ACTION_PREPARE_TILES:
202 sm->WillPrepareTiles();
203 return;
204
205 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE:
206 sm->WillInvalidateOutputSurface();
207 return;
208 }
209 }
210
204 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { 211 TEST(SchedulerStateMachineTest, BeginFrameNeeded) {
205 SchedulerSettings default_scheduler_settings; 212 SchedulerSettings default_scheduler_settings;
206 StateMachine state(default_scheduler_settings); 213 StateMachine state(default_scheduler_settings);
207 state.SetVisible(true); 214 state.SetVisible(true);
208 EXPECT_ACTION_UPDATE_STATE( 215 EXPECT_ACTION_UPDATE_STATE(
209 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 216 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
211 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 218 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
212 state.SetBeginMainFrameState( 219 state.SetBeginMainFrameState(
213 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 220 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
400 EXPECT_ACTION_UPDATE_STATE( 407 EXPECT_ACTION_UPDATE_STATE(
401 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 408 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
402 state.DidSwapBuffers(); 409 state.DidSwapBuffers();
403 state.DidSwapBuffersComplete(); 410 state.DidSwapBuffersComplete();
404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 411 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
405 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 412 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
406 } 413 }
407 414
408 TEST(SchedulerStateMachineTest, 415 TEST(SchedulerStateMachineTest,
409 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 416 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) {
410 SchedulerSettings default_scheduler_settings; 417 SchedulerSettings default_scheduler_settings;
411 StateMachine state(default_scheduler_settings); 418 StateMachine state(default_scheduler_settings);
412 SET_UP_STATE(state) 419 SET_UP_STATE(state)
413 state.SetNeedsRedraw(true); 420 state.SetNeedsRedraw(true);
414 EXPECT_TRUE(state.RedrawPending()); 421 EXPECT_TRUE(state.RedrawPending());
415 EXPECT_TRUE(state.BeginFrameNeeded()); 422 EXPECT_TRUE(state.BeginFrameNeeded());
423
424 // Start a frame.
416 state.OnBeginImplFrame(); 425 state.OnBeginImplFrame();
417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 426 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
418 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
428 state.OnBeginImplFrameDeadlinePending();
429 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
430 EXPECT_FALSE(state.CommitPending());
431
432 // Failing a draw triggers request for a new BeginMainFrame.
419 state.OnBeginImplFrameDeadline(); 433 state.OnBeginImplFrameDeadline();
420 434 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
421 // We're drawing now.
422 EXPECT_ACTION_UPDATE_STATE( 435 EXPECT_ACTION_UPDATE_STATE(
423 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 436 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
424 state.DidSwapBuffers(); 437 EXPECT_ACTION_UPDATE_STATE(
425 state.DidSwapBuffersComplete(); 438 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
439 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
440 state.OnBeginImplFrameIdle();
426 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 441 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
427 442
428 EXPECT_FALSE(state.RedrawPending()); 443 // It's okay to attempt more draws just in case additional raster
429 EXPECT_FALSE(state.CommitPending()); 444 // finishes and the requested commit wasn't actually necessary.
430 445 EXPECT_TRUE(state.CommitPending());
431 // Failing the draw makes us require a commit. 446 EXPECT_TRUE(state.RedrawPending());
432 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
433 state.OnBeginImplFrame(); 447 state.OnBeginImplFrame();
434 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
450 state.OnBeginImplFrameDeadlinePending();
451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
452 state.OnBeginImplFrameDeadline();
453 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
435 EXPECT_ACTION_UPDATE_STATE( 454 EXPECT_ACTION_UPDATE_STATE(
436 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 455 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
437 EXPECT_TRUE(state.RedrawPending()); 456 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
438 EXPECT_TRUE(state.CommitPending()); 457 state.OnBeginImplFrameIdle();
458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
439 } 459 }
440 460
441 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 461 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) {
442 SchedulerSettings default_scheduler_settings; 462 SchedulerSettings default_scheduler_settings;
443 StateMachine state(default_scheduler_settings); 463 StateMachine state(default_scheduler_settings);
444 SET_UP_STATE(state) 464 SET_UP_STATE(state)
445 state.SetNeedsRedraw(true); 465 state.SetNeedsRedraw(true);
446 EXPECT_TRUE(state.RedrawPending()); 466 EXPECT_TRUE(state.RedrawPending());
447 EXPECT_TRUE(state.BeginFrameNeeded()); 467 EXPECT_TRUE(state.BeginFrameNeeded());
448 468
469 // Start a frame.
449 state.OnBeginImplFrame(); 470 state.OnBeginImplFrame();
450 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 472 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
473 state.OnBeginImplFrameDeadlinePending();
474 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
475 EXPECT_FALSE(state.CommitPending());
476
477 // Failing a draw triggers because of high res tiles missing
478 // request for a new BeginMainFrame.
452 state.OnBeginImplFrameDeadline(); 479 state.OnBeginImplFrameDeadline();
480 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
481 EXPECT_ACTION_UPDATE_STATE(
482 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
483 EXPECT_ACTION_UPDATE_STATE(
484 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
485 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
486 state.OnBeginImplFrameIdle();
487 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
488
489 // It doesn't request a draw until we get a new commit though.
490 EXPECT_TRUE(state.CommitPending());
491 EXPECT_FALSE(state.RedrawPending());
492 state.OnBeginImplFrame();
493 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
494 state.OnBeginImplFrameDeadlinePending();
495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
496 state.OnBeginImplFrameDeadline();
497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
498 state.OnBeginImplFrameIdle();
499 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
500
501 // Finish the commit and activation.
502 state.NotifyBeginMainFrameStarted();
503 state.NotifyReadyToCommit();
504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
505 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
506 state.NotifyReadyToActivate();
507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
509 EXPECT_TRUE(state.RedrawPending());
510
511 // Verify we draw with the new frame.
512 state.OnBeginImplFrame();
513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
514 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
515 state.OnBeginImplFrameDeadlinePending();
516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
517 state.OnBeginImplFrameDeadline();
518 state.SetDrawResultForTest(DRAW_SUCCESS);
453 EXPECT_ACTION_UPDATE_STATE( 519 EXPECT_ACTION_UPDATE_STATE(
454 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 520 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
455 state.DidSwapBuffers(); 521 state.DidSwapBuffers();
456 state.DidSwapBuffersComplete();
457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 522 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
458 EXPECT_FALSE(state.RedrawPending()); 523 state.OnBeginImplFrameIdle();
459 EXPECT_FALSE(state.CommitPending()); 524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
460
461 // Missing high res content requires a commit (but not a redraw)
462 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
463 state.OnBeginImplFrame();
464 EXPECT_ACTION_UPDATE_STATE(
465 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
466 EXPECT_FALSE(state.RedrawPending());
467 EXPECT_TRUE(state.CommitPending());
468 } 525 }
469 526
470 TEST(SchedulerStateMachineTest, 527 TEST(SchedulerStateMachineTest,
471 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
472 SchedulerSettings default_scheduler_settings;
473 StateMachine state(default_scheduler_settings);
474 SET_UP_STATE(state)
475 state.SetNeedsRedraw(true);
476 EXPECT_TRUE(state.RedrawPending());
477 EXPECT_TRUE(state.BeginFrameNeeded());
478 state.OnBeginImplFrame();
479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
481 state.OnBeginImplFrameDeadline();
482
483 // We're drawing now.
484 EXPECT_ACTION_UPDATE_STATE(
485 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
486 state.DidSwapBuffers();
487 state.DidSwapBuffersComplete();
488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
489 EXPECT_FALSE(state.RedrawPending());
490 EXPECT_FALSE(state.CommitPending());
491
492 // While still in the same BeginMainFrame callback on the main thread,
493 // set needs redraw again. This should not redraw.
494 state.SetNeedsRedraw(true);
495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
496
497 // Failing the draw for animation checkerboards makes us require a commit.
498 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
499 state.OnBeginImplFrame();
500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
501 EXPECT_ACTION_UPDATE_STATE(
502 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
503 EXPECT_TRUE(state.RedrawPending());
504 }
505
506 TEST(SchedulerStateMachineTest,
507 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 528 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
508 SchedulerSettings scheduler_settings; 529 SchedulerSettings scheduler_settings;
509 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1; 530 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1;
510 StateMachine state(scheduler_settings); 531 StateMachine state(scheduler_settings);
511 SET_UP_STATE(state) 532 SET_UP_STATE(state)
512 533
513 // Start a commit. 534 // Start a commit.
514 state.SetNeedsBeginMainFrame(); 535 state.SetNeedsBeginMainFrame();
515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
516 state.OnBeginImplFrame(); 537 state.OnBeginImplFrame();
517 EXPECT_ACTION_UPDATE_STATE( 538 EXPECT_ACTION_UPDATE_STATE(
518 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 539 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
519 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 540 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
520 EXPECT_TRUE(state.CommitPending()); 541 EXPECT_TRUE(state.CommitPending());
521 542
522 // Then initiate a draw. 543 // Then initiate a draw that fails.
523 state.SetNeedsRedraw(true); 544 state.SetNeedsRedraw(true);
524 state.OnBeginImplFrameDeadline(); 545 state.OnBeginImplFrameDeadline();
525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 546 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
547 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
526 EXPECT_ACTION_UPDATE_STATE( 548 EXPECT_ACTION_UPDATE_STATE(
527 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 549 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
528
529 // Fail the draw.
530 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
532 EXPECT_TRUE(state.BeginFrameNeeded()); 551 EXPECT_TRUE(state.BeginFrameNeeded());
533 EXPECT_TRUE(state.RedrawPending()); 552 EXPECT_TRUE(state.RedrawPending());
534 // But the commit is ongoing.
535 EXPECT_TRUE(state.CommitPending()); 553 EXPECT_TRUE(state.CommitPending());
536 554
537 // Finish the commit. Note, we should not yet be forcing a draw, but should 555 // Finish the commit. Note, we should not yet be forcing a draw, but should
538 // continue the commit as usual. 556 // continue the commit as usual.
539 state.NotifyBeginMainFrameStarted(); 557 state.NotifyBeginMainFrameStarted();
540 state.NotifyReadyToCommit(); 558 state.NotifyReadyToCommit();
541 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
542 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 560 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
543 EXPECT_TRUE(state.RedrawPending()); 561 EXPECT_TRUE(state.RedrawPending());
544 562
545 // Activate so we're ready for a new main frame. 563 // Activate so we're ready for a new main frame.
546 state.NotifyReadyToActivate(); 564 state.NotifyReadyToActivate();
547 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
548 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 566 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
549 EXPECT_TRUE(state.RedrawPending()); 567 EXPECT_TRUE(state.RedrawPending());
550 568
551 // The redraw should be forced at the end of the next BeginImplFrame. 569 // The redraw should be forced at the end of the next BeginImplFrame.
552 state.OnBeginImplFrame(); 570 state.OnBeginImplFrame();
553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 571 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
554 EXPECT_ACTION_UPDATE_STATE( 572 EXPECT_ACTION_UPDATE_STATE(
555 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 573 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 574 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
557 state.OnBeginImplFrameDeadline(); 575 state.OnBeginImplFrameDeadline();
576 state.SetDrawResultForTest(DRAW_SUCCESS);
558 EXPECT_ACTION_UPDATE_STATE( 577 EXPECT_ACTION_UPDATE_STATE(
559 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 578 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
560 state.DidSwapBuffers(); 579 state.DidSwapBuffers();
580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
561 state.DidSwapBuffersComplete(); 581 state.DidSwapBuffersComplete();
582 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
562 } 583 }
563 584
564 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 585 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
565 SchedulerSettings scheduler_settings; 586 SchedulerSettings scheduler_settings;
566 int draw_limit = 1; 587 int draw_limit = 2;
567 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 588 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced =
568 draw_limit; 589 draw_limit;
569 StateMachine state(scheduler_settings); 590 StateMachine state(scheduler_settings);
570 SET_UP_STATE(state) 591 SET_UP_STATE(state)
571 592
572 // Start a commit. 593 // Start a commit.
573 state.SetNeedsBeginMainFrame(); 594 state.SetNeedsBeginMainFrame();
574 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
575 state.OnBeginImplFrame(); 596 state.OnBeginImplFrame();
576 EXPECT_ACTION_UPDATE_STATE( 597 EXPECT_ACTION_UPDATE_STATE(
577 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 598 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 599 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
579 EXPECT_TRUE(state.CommitPending()); 600 EXPECT_TRUE(state.CommitPending());
580 601
581 // Then initiate a draw. 602 // Then initiate a draw.
582 state.SetNeedsRedraw(true); 603 state.SetNeedsRedraw(true);
583 state.OnBeginImplFrameDeadline(); 604 state.OnBeginImplFrameDeadline();
584 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 605 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
585 EXPECT_ACTION_UPDATE_STATE( 606 EXPECT_ACTION_UPDATE_STATE(
586 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 607 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
587 608
588 // Fail the draw enough times to force a redraw, 609 // Fail the draw enough times to force a redraw.
589 // then once more for good measure. 610 for (int i = 0; i < draw_limit; ++i) {
590 for (int i = 0; i < draw_limit + 1; ++i) 611 state.SetNeedsRedraw(true);
591 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 612 state.OnBeginImplFrame();
592 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
614 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
615 state.OnBeginImplFrameDeadlinePending();
616 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
617 state.OnBeginImplFrameDeadline();
618 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
619 EXPECT_ACTION_UPDATE_STATE(
620 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
622 state.OnBeginImplFrameIdle();
623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
624 }
625
593 EXPECT_TRUE(state.BeginFrameNeeded()); 626 EXPECT_TRUE(state.BeginFrameNeeded());
594 EXPECT_TRUE(state.RedrawPending()); 627 EXPECT_TRUE(state.RedrawPending());
595 // But the commit is ongoing. 628 // But the commit is ongoing.
596 EXPECT_TRUE(state.CommitPending()); 629 EXPECT_TRUE(state.CommitPending());
597 EXPECT_TRUE(state.ForcedRedrawState() == 630 EXPECT_TRUE(state.ForcedRedrawState() ==
598 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 631 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
599 632
600 state.NotifyBeginMainFrameStarted(); 633 state.NotifyBeginMainFrameStarted();
601 state.NotifyReadyToCommit(); 634 state.NotifyReadyToCommit();
602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 635 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
603 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
604 EXPECT_TRUE(state.RedrawPending()); 637 EXPECT_TRUE(state.RedrawPending());
605 EXPECT_FALSE(state.CommitPending()); 638 EXPECT_FALSE(state.CommitPending());
606 639
607 // Now force redraw should be in waiting for activation 640 // Now force redraw should be in waiting for activation
608 EXPECT_TRUE(state.ForcedRedrawState() == 641 EXPECT_TRUE(state.ForcedRedrawState() ==
609 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION); 642 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION);
610 643
611 // After failing additional draws, we should still be in a forced 644 // After failing additional draws, we should still be in a forced
612 // redraw, but not back in WAITING_FOR_COMMIT. 645 // redraw, but not back in WAITING_FOR_COMMIT.
613 for (int i = 0; i < draw_limit + 1; ++i) 646 for (int i = 0; i < draw_limit; ++i) {
614 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 647 state.SetNeedsRedraw(true);
648 state.OnBeginImplFrame();
649 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
650 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
651 state.OnBeginImplFrameDeadlinePending();
652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
653 state.OnBeginImplFrameDeadline();
654 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
655 EXPECT_ACTION_UPDATE_STATE(
656 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
657 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
658 state.OnBeginImplFrameIdle();
659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
660 }
615 EXPECT_TRUE(state.RedrawPending()); 661 EXPECT_TRUE(state.RedrawPending());
616 EXPECT_TRUE(state.ForcedRedrawState() == 662 EXPECT_TRUE(state.ForcedRedrawState() ==
617 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION); 663 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION);
618 } 664 }
619 665
620 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 666 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
621 SchedulerSettings default_scheduler_settings; 667 SchedulerSettings default_scheduler_settings;
622 StateMachine state(default_scheduler_settings); 668 StateMachine state(default_scheduler_settings);
623 SET_UP_STATE(state) 669 SET_UP_STATE(state)
624 670
625 // Start a draw. 671 // Start a draw.
626 state.SetNeedsRedraw(true); 672 state.SetNeedsRedraw(true);
627 EXPECT_TRUE(state.BeginFrameNeeded()); 673 EXPECT_TRUE(state.BeginFrameNeeded());
628 state.OnBeginImplFrame(); 674 state.OnBeginImplFrame();
629 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 675 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 676 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
631 state.OnBeginImplFrameDeadline(); 677 state.OnBeginImplFrameDeadline();
632 EXPECT_TRUE(state.RedrawPending()); 678 EXPECT_TRUE(state.RedrawPending());
679 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
633 EXPECT_ACTION_UPDATE_STATE( 680 EXPECT_ACTION_UPDATE_STATE(
634 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 681 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
635 682
636 // Failing the draw for animation checkerboards makes us require a commit. 683 // Failing the draw for animation checkerboards makes us require a commit.
637 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
638 EXPECT_ACTION_UPDATE_STATE( 684 EXPECT_ACTION_UPDATE_STATE(
639 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 685 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
641 EXPECT_TRUE(state.RedrawPending()); 687 EXPECT_TRUE(state.RedrawPending());
642 688
643 // We should not be trying to draw again now, but we have a commit pending. 689 // We should not be trying to draw again now, but we have a commit pending.
644 EXPECT_TRUE(state.BeginFrameNeeded()); 690 EXPECT_TRUE(state.BeginFrameNeeded());
645 state.OnBeginImplFrame(); 691 state.OnBeginImplFrame();
646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
648 694
649 // We should try to draw again at the end of the next BeginImplFrame on 695 // We should try to draw again at the end of the next BeginImplFrame on
650 // the impl thread. 696 // the impl thread.
651 state.OnBeginImplFrameDeadline(); 697 state.OnBeginImplFrameDeadline();
698 state.SetDrawResultForTest(DRAW_SUCCESS);
652 EXPECT_ACTION_UPDATE_STATE( 699 EXPECT_ACTION_UPDATE_STATE(
653 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 700 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
654 state.DidSwapBuffers(); 701 state.DidSwapBuffers();
655 state.DidSwapBuffersComplete(); 702 state.DidSwapBuffersComplete();
656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 703 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
657 } 704 }
658 705
659 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 706 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
660 SchedulerSettings default_scheduler_settings; 707 SchedulerSettings default_scheduler_settings;
661 StateMachine state(default_scheduler_settings); 708 StateMachine state(default_scheduler_settings);
662 SET_UP_STATE(state) 709 SET_UP_STATE(state)
663 state.SetNeedsRedraw(true); 710 state.SetNeedsRedraw(true);
664 711
665 // Draw the first frame. 712 // Draw the first frame.
666 EXPECT_TRUE(state.BeginFrameNeeded()); 713 EXPECT_TRUE(state.BeginFrameNeeded());
667 state.OnBeginImplFrame(); 714 state.OnBeginImplFrame();
668 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 716 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
670 717
671 state.OnBeginImplFrameDeadline(); 718 state.OnBeginImplFrameDeadline();
672 EXPECT_ACTION_UPDATE_STATE( 719 EXPECT_ACTION_UPDATE_STATE(
673 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 720 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
674 state.DidSwapBuffers(); 721 state.DidSwapBuffers();
675 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
676 state.DidSwapBuffersComplete(); 722 state.DidSwapBuffersComplete();
677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 723 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
678 724
679 // Before the next BeginImplFrame, set needs redraw again. 725 // Before the next BeginImplFrame, set needs redraw again.
680 // This should not redraw until the next BeginImplFrame. 726 // This should not redraw until the next BeginImplFrame.
681 state.SetNeedsRedraw(true); 727 state.SetNeedsRedraw(true);
682 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 728 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
683 729
684 // Move to another frame. This should now draw. 730 // Move to another frame. This should now draw.
685 EXPECT_TRUE(state.BeginFrameNeeded()); 731 EXPECT_TRUE(state.BeginFrameNeeded());
686 state.OnBeginImplFrame(); 732 state.OnBeginImplFrame();
687 733
688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 734 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
689 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 735 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
690 736
691 state.OnBeginImplFrameDeadline(); 737 state.OnBeginImplFrameDeadline();
692 EXPECT_ACTION_UPDATE_STATE( 738 EXPECT_ACTION_UPDATE_STATE(
693 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 739 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
694 state.DidSwapBuffers(); 740 state.DidSwapBuffers();
695 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
696 state.DidSwapBuffersComplete(); 741 state.DidSwapBuffersComplete();
697 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 742 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
698 743
699 // We just swapped, so we should proactively request another BeginImplFrame. 744 // We just swapped, so we should proactively request another BeginImplFrame.
700 EXPECT_TRUE(state.BeginFrameNeeded()); 745 EXPECT_TRUE(state.BeginFrameNeeded());
701 } 746 }
702 747
703 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { 748 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
704 SchedulerSettings default_scheduler_settings; 749 SchedulerSettings default_scheduler_settings;
705 750
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 EXPECT_ACTION_UPDATE_STATE( 969 EXPECT_ACTION_UPDATE_STATE(
925 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 970 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
926 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 971 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
927 972
928 state.OnBeginImplFrameDeadline(); 973 state.OnBeginImplFrameDeadline();
929 974
930 EXPECT_TRUE(state.active_tree_needs_first_draw()); 975 EXPECT_TRUE(state.active_tree_needs_first_draw());
931 EXPECT_ACTION_UPDATE_STATE( 976 EXPECT_ACTION_UPDATE_STATE(
932 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 977 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
933 state.DidSwapBuffers(); 978 state.DidSwapBuffers();
934 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
935 state.DidSwapBuffersComplete(); 979 state.DidSwapBuffersComplete();
936 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 980 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
937 } 981 }
938 982
939 TEST(SchedulerStateMachineTest, TestFullCycle) { 983 TEST(SchedulerStateMachineTest, TestFullCycle) {
940 SchedulerSettings default_scheduler_settings; 984 SchedulerSettings default_scheduler_settings;
941 StateMachine state(default_scheduler_settings); 985 StateMachine state(default_scheduler_settings);
942 SET_UP_STATE(state) 986 SET_UP_STATE(state)
943 987
944 // Start clean and set commit. 988 // Start clean and set commit.
(...skipping 24 matching lines...) Expand all
969 1013
970 // Expect to do nothing until BeginImplFrame deadline 1014 // Expect to do nothing until BeginImplFrame deadline
971 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1015 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
972 1016
973 // At BeginImplFrame deadline, draw. 1017 // At BeginImplFrame deadline, draw.
974 state.OnBeginImplFrameDeadline(); 1018 state.OnBeginImplFrameDeadline();
975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1019 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
976 EXPECT_ACTION_UPDATE_STATE( 1020 EXPECT_ACTION_UPDATE_STATE(
977 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1021 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
978 state.DidSwapBuffers(); 1022 state.DidSwapBuffers();
979 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
980 state.DidSwapBuffersComplete(); 1023 state.DidSwapBuffersComplete();
981 1024
982 // Should be synchronized, no draw needed, no action needed. 1025 // Should be synchronized, no draw needed, no action needed.
983 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1026 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
984 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1027 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
985 EXPECT_FALSE(state.needs_redraw()); 1028 EXPECT_FALSE(state.needs_redraw());
986 } 1029 }
987 1030
988 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { 1031 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) {
989 SchedulerSettings default_scheduler_settings; 1032 SchedulerSettings default_scheduler_settings;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 // Haven't draw since last commit, do not begin new main frame. 1151 // Haven't draw since last commit, do not begin new main frame.
1109 state.OnBeginImplFrame(); 1152 state.OnBeginImplFrame();
1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1111 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1154 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1112 1155
1113 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame. 1156 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
1114 state.OnBeginImplFrameDeadline(); 1157 state.OnBeginImplFrameDeadline();
1115 EXPECT_ACTION_UPDATE_STATE( 1158 EXPECT_ACTION_UPDATE_STATE(
1116 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1159 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1117 state.DidSwapBuffers(); 1160 state.DidSwapBuffers();
1118 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1119 state.DidSwapBuffersComplete(); 1161 state.DidSwapBuffersComplete();
1120 1162
1121 // Now will be able to start main frame. 1163 // Now will be able to start main frame.
1122 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1164 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1123 EXPECT_FALSE(state.needs_redraw()); 1165 EXPECT_FALSE(state.needs_redraw());
1124 EXPECT_ACTION_UPDATE_STATE( 1166 EXPECT_ACTION_UPDATE_STATE(
1125 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1167 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1126 } 1168 }
1127 1169
1128 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1170 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 1202
1161 // Expect to do nothing until BeginImplFrame deadline. 1203 // Expect to do nothing until BeginImplFrame deadline.
1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1204 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1163 1205
1164 // At BeginImplFrame deadline, draw. 1206 // At BeginImplFrame deadline, draw.
1165 state.OnBeginImplFrameDeadline(); 1207 state.OnBeginImplFrameDeadline();
1166 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1167 EXPECT_ACTION_UPDATE_STATE( 1209 EXPECT_ACTION_UPDATE_STATE(
1168 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1210 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1169 state.DidSwapBuffers(); 1211 state.DidSwapBuffers();
1170 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1171 state.DidSwapBuffersComplete(); 1212 state.DidSwapBuffersComplete();
1172 1213
1173 // Should be synchronized, no draw needed, no action needed. 1214 // Should be synchronized, no draw needed, no action needed.
1174 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1175 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1216 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1176 EXPECT_FALSE(state.needs_redraw()); 1217 EXPECT_FALSE(state.needs_redraw());
1177 1218
1178 // Next BeginImplFrame should initiate second commit. 1219 // Next BeginImplFrame should initiate second commit.
1179 state.OnBeginImplFrame(); 1220 state.OnBeginImplFrame();
1180 EXPECT_ACTION_UPDATE_STATE( 1221 EXPECT_ACTION_UPDATE_STATE(
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2172 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2132 bool commit_has_no_updates = true; 2173 bool commit_has_no_updates = true;
2133 state.WillCommit(commit_has_no_updates); 2174 state.WillCommit(commit_has_no_updates);
2134 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); 2175 EXPECT_TRUE(state.ProactiveBeginFrameWanted());
2135 state.OnBeginImplFrame(); 2176 state.OnBeginImplFrame();
2136 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2177 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2137 } 2178 }
2138 2179
2139 } // namespace 2180 } // namespace
2140 } // namespace cc 2181 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698