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

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

Issue 1385043002: cc: Remove SetLayerTreeHostClientReady() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@startcomp
Patch Set: sky's offline comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.SetCanStart(); \
55 state.SetVisible(true); \ 54 state.SetVisible(true); \
56 EXPECT_ACTION_UPDATE_STATE( \ 55 EXPECT_ACTION_UPDATE_STATE( \
57 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \ 56 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \
58 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 57 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
59 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \ 58 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \
60 state.SetCanDraw(true); 59 state.SetCanDraw(true);
61 60
62 namespace cc { 61 namespace cc {
63 62
64 namespace { 63 namespace {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 197 }
199 198
200 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; 199 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
201 using SchedulerStateMachine::ProactiveBeginFrameWanted; 200 using SchedulerStateMachine::ProactiveBeginFrameWanted;
202 using SchedulerStateMachine::WillCommit; 201 using SchedulerStateMachine::WillCommit;
203 }; 202 };
204 203
205 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { 204 TEST(SchedulerStateMachineTest, BeginFrameNeeded) {
206 SchedulerSettings default_scheduler_settings; 205 SchedulerSettings default_scheduler_settings;
207 StateMachine state(default_scheduler_settings); 206 StateMachine state(default_scheduler_settings);
208 state.SetCanStart();
209 state.SetVisible(true); 207 state.SetVisible(true);
210 EXPECT_ACTION_UPDATE_STATE( 208 EXPECT_ACTION_UPDATE_STATE(
211 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 209 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
213 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 211 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
214 state.SetBeginMainFrameState( 212 state.SetBeginMainFrameState(
215 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 213 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
216 214
217 // Don't request BeginFrames if we are idle. 215 // Don't request BeginFrames if we are idle.
218 state.SetNeedsRedraw(false); 216 state.SetNeedsRedraw(false);
(...skipping 28 matching lines...) Expand all
247 state.SetDeferCommits(true); 245 state.SetDeferCommits(true);
248 EXPECT_FALSE(state.BeginFrameNeeded()); 246 EXPECT_FALSE(state.BeginFrameNeeded());
249 } 247 }
250 248
251 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { 249 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) {
252 SchedulerSettings default_scheduler_settings; 250 SchedulerSettings default_scheduler_settings;
253 251
254 // If no commit needed, do nothing. 252 // If no commit needed, do nothing.
255 { 253 {
256 StateMachine state(default_scheduler_settings); 254 StateMachine state(default_scheduler_settings);
257 state.SetCanStart();
258 state.SetVisible(true); 255 state.SetVisible(true);
259 EXPECT_ACTION_UPDATE_STATE( 256 EXPECT_ACTION_UPDATE_STATE(
260 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 257 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
261 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 258 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
262 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 259 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
263 state.SetBeginMainFrameState( 260 state.SetBeginMainFrameState(
264 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 261 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
265 state.SetNeedsRedraw(false); 262 state.SetNeedsRedraw(false);
266 263
267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
268 EXPECT_FALSE(state.NeedsCommit()); 265 EXPECT_FALSE(state.NeedsCommit());
269 266
270 state.OnBeginImplFrame(); 267 state.OnBeginImplFrame();
271 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
272 269
273 state.OnBeginImplFrameDeadline(); 270 state.OnBeginImplFrameDeadline();
274 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 271 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
275 EXPECT_FALSE(state.NeedsCommit()); 272 EXPECT_FALSE(state.NeedsCommit());
276 } 273 }
277 274
278 // If commit requested but can_start is still false, do nothing. 275 // If commit requested but not visible yet, do nothing.
279 { 276 {
280 StateMachine state(default_scheduler_settings); 277 StateMachine state(default_scheduler_settings);
281 state.SetBeginMainFrameState( 278 state.SetBeginMainFrameState(
282 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 279 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
283 state.SetNeedsRedraw(false); 280 state.SetNeedsRedraw(false);
284 state.SetVisible(true);
285 state.SetNeedsBeginMainFrame(); 281 state.SetNeedsBeginMainFrame();
286 282
287 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
288 EXPECT_TRUE(state.NeedsCommit()); 284 EXPECT_TRUE(state.NeedsCommit());
289 285
290 state.OnBeginImplFrame(); 286 state.OnBeginImplFrame();
291 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 287 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
292 288
293 state.OnBeginImplFrameDeadline(); 289 state.OnBeginImplFrameDeadline();
294 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
295 EXPECT_TRUE(state.NeedsCommit()); 291 EXPECT_TRUE(state.NeedsCommit());
296 } 292 }
297 293
298 // If commit requested, begin a main frame. 294 // If commit requested, begin a main frame.
299 { 295 {
300 StateMachine state(default_scheduler_settings); 296 StateMachine state(default_scheduler_settings);
301 state.SetBeginMainFrameState( 297 state.SetBeginMainFrameState(
302 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 298 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
303 state.SetCanStart();
304 state.SetVisible(true); 299 state.SetVisible(true);
305 EXPECT_ACTION_UPDATE_STATE( 300 EXPECT_ACTION_UPDATE_STATE(
306 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 301 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
308 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 303 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
309 state.SetNeedsRedraw(false); 304 state.SetNeedsRedraw(false);
310 state.SetNeedsBeginMainFrame(); 305 state.SetNeedsBeginMainFrame();
311 306
312 // Expect nothing to happen until after OnBeginImplFrame. 307 // Expect nothing to happen until after OnBeginImplFrame.
313 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
314 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 309 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
315 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 310 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
316 EXPECT_TRUE(state.NeedsCommit()); 311 EXPECT_TRUE(state.NeedsCommit());
317 EXPECT_TRUE(state.BeginFrameNeeded()); 312 EXPECT_TRUE(state.BeginFrameNeeded());
318 313
319 state.OnBeginImplFrame(); 314 state.OnBeginImplFrame();
320 EXPECT_ACTION_UPDATE_STATE( 315 EXPECT_ACTION_UPDATE_STATE(
321 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 316 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
322 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 317 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
323 EXPECT_FALSE(state.NeedsCommit()); 318 EXPECT_FALSE(state.NeedsCommit());
324 } 319 }
325 320
326 // If commit requested and can't draw, still begin a main frame. 321 // If commit requested and can't draw, still begin a main frame.
327 { 322 {
328 StateMachine state(default_scheduler_settings); 323 StateMachine state(default_scheduler_settings);
329 state.SetBeginMainFrameState( 324 state.SetBeginMainFrameState(
330 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 325 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
331 state.SetCanStart();
332 state.SetVisible(true); 326 state.SetVisible(true);
333 EXPECT_ACTION_UPDATE_STATE( 327 EXPECT_ACTION_UPDATE_STATE(
334 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 328 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
335 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
336 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 330 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
337 state.SetNeedsRedraw(false); 331 state.SetNeedsRedraw(false);
338 state.SetNeedsBeginMainFrame(); 332 state.SetNeedsBeginMainFrame();
339 state.SetCanDraw(false); 333 state.SetCanDraw(false);
340 334
341 // Expect nothing to happen until after OnBeginImplFrame. 335 // Expect nothing to happen until after OnBeginImplFrame.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // but not visible, don't draw. 707 // but not visible, don't draw.
714 size_t num_begin_main_frame_states = 708 size_t num_begin_main_frame_states =
715 sizeof(begin_main_frame_states) / 709 sizeof(begin_main_frame_states) /
716 sizeof(SchedulerStateMachine::BeginMainFrameState); 710 sizeof(SchedulerStateMachine::BeginMainFrameState);
717 size_t num_begin_impl_frame_states = 711 size_t num_begin_impl_frame_states =
718 sizeof(all_begin_impl_frame_states) / 712 sizeof(all_begin_impl_frame_states) /
719 sizeof(SchedulerStateMachine::BeginImplFrameState); 713 sizeof(SchedulerStateMachine::BeginImplFrameState);
720 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 714 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
721 for (size_t j = 0; j < num_begin_impl_frame_states; ++j) { 715 for (size_t j = 0; j < num_begin_impl_frame_states; ++j) {
722 StateMachine state(default_scheduler_settings); 716 StateMachine state(default_scheduler_settings);
723 state.SetCanStart();
724 state.SetVisible(true); 717 state.SetVisible(true);
725 EXPECT_ACTION_UPDATE_STATE( 718 EXPECT_ACTION_UPDATE_STATE(
726 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 719 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 720 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
728 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 721 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
729 state.SetBeginMainFrameState(begin_main_frame_states[i]); 722 state.SetBeginMainFrameState(begin_main_frame_states[i]);
730 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]); 723 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]);
731 bool visible = 724 bool visible =
732 (all_begin_impl_frame_states[j] != 725 (all_begin_impl_frame_states[j] !=
733 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 726 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
734 state.SetVisible(visible); 727 state.SetVisible(visible);
735 728
736 // Case 1: needs_begin_main_frame=false 729 // Case 1: needs_begin_main_frame=false
737 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 730 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
738 state.NextAction()); 731 state.NextAction());
739 732
740 // Case 2: needs_begin_main_frame=true 733 // Case 2: needs_begin_main_frame=true
741 state.SetNeedsBeginMainFrame(); 734 state.SetNeedsBeginMainFrame();
742 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 735 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
743 state.NextAction()) 736 state.NextAction())
744 << state.AsValue()->ToString(); 737 << state.AsValue()->ToString();
745 } 738 }
746 } 739 }
747 740
748 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw 741 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
749 // except if we're ready to commit, in which case we expect a commit first. 742 // except if we're ready to commit, in which case we expect a commit first.
750 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 743 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
751 StateMachine state(default_scheduler_settings); 744 StateMachine state(default_scheduler_settings);
752 state.SetCanStart();
753 state.SetVisible(true); 745 state.SetVisible(true);
754 EXPECT_ACTION_UPDATE_STATE( 746 EXPECT_ACTION_UPDATE_STATE(
755 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 747 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
756 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 748 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
757 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 749 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
758 state.SetCanDraw(true); 750 state.SetCanDraw(true);
759 state.SetBeginMainFrameState(begin_main_frame_states[i]); 751 state.SetBeginMainFrameState(begin_main_frame_states[i]);
760 state.SetBeginImplFrameState( 752 state.SetBeginImplFrameState(
761 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 753 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
762 754
(...skipping 20 matching lines...) Expand all
783 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) { 775 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) {
784 SchedulerSettings default_scheduler_settings; 776 SchedulerSettings default_scheduler_settings;
785 777
786 size_t num_begin_main_frame_states = 778 size_t num_begin_main_frame_states =
787 sizeof(begin_main_frame_states) / 779 sizeof(begin_main_frame_states) /
788 sizeof(SchedulerStateMachine::BeginMainFrameState); 780 sizeof(SchedulerStateMachine::BeginMainFrameState);
789 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 781 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
790 // There shouldn't be any drawing regardless of BeginImplFrame. 782 // There shouldn't be any drawing regardless of BeginImplFrame.
791 for (size_t j = 0; j < 2; ++j) { 783 for (size_t j = 0; j < 2; ++j) {
792 StateMachine state(default_scheduler_settings); 784 StateMachine state(default_scheduler_settings);
793 state.SetCanStart();
794 state.SetVisible(true); 785 state.SetVisible(true);
795 EXPECT_ACTION_UPDATE_STATE( 786 EXPECT_ACTION_UPDATE_STATE(
796 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 787 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
797 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 788 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
798 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 789 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
799 state.SetBeginMainFrameState(begin_main_frame_states[i]); 790 state.SetBeginMainFrameState(begin_main_frame_states[i]);
800 state.SetVisible(false); 791 state.SetVisible(false);
801 state.SetNeedsRedraw(true); 792 state.SetNeedsRedraw(true);
802 if (j == 1) { 793 if (j == 1) {
803 state.SetBeginImplFrameState( 794 state.SetBeginImplFrameState(
(...skipping 16 matching lines...) Expand all
820 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 811 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
821 SchedulerSettings default_scheduler_settings; 812 SchedulerSettings default_scheduler_settings;
822 813
823 size_t num_begin_main_frame_states = 814 size_t num_begin_main_frame_states =
824 sizeof(begin_main_frame_states) / 815 sizeof(begin_main_frame_states) /
825 sizeof(SchedulerStateMachine::BeginMainFrameState); 816 sizeof(SchedulerStateMachine::BeginMainFrameState);
826 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 817 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
827 // There shouldn't be any drawing regardless of BeginImplFrame. 818 // There shouldn't be any drawing regardless of BeginImplFrame.
828 for (size_t j = 0; j < 2; ++j) { 819 for (size_t j = 0; j < 2; ++j) {
829 StateMachine state(default_scheduler_settings); 820 StateMachine state(default_scheduler_settings);
830 state.SetCanStart();
831 state.SetVisible(true); 821 state.SetVisible(true);
832 EXPECT_ACTION_UPDATE_STATE( 822 EXPECT_ACTION_UPDATE_STATE(
833 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 823 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
834 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 824 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
835 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 825 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
836 state.SetBeginMainFrameState(begin_main_frame_states[i]); 826 state.SetBeginMainFrameState(begin_main_frame_states[i]);
837 state.SetVisible(false); 827 state.SetVisible(false);
838 state.SetNeedsRedraw(true); 828 state.SetNeedsRedraw(true);
839 if (j == 1) 829 if (j == 1)
840 state.OnBeginImplFrame(); 830 state.OnBeginImplFrame();
841 831
842 state.SetCanDraw(false); 832 state.SetCanDraw(false);
843 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 833 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
844 state.NextAction()); 834 state.NextAction());
845 } 835 }
846 } 836 }
847 } 837 }
848 838
849 TEST(SchedulerStateMachineTest, 839 TEST(SchedulerStateMachineTest,
850 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 840 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
851 SchedulerSettings default_scheduler_settings; 841 SchedulerSettings default_scheduler_settings;
852 StateMachine state(default_scheduler_settings); 842 StateMachine state(default_scheduler_settings);
853 state.SetCanStart();
854 state.SetVisible(true); 843 state.SetVisible(true);
855 EXPECT_ACTION_UPDATE_STATE( 844 EXPECT_ACTION_UPDATE_STATE(
856 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 845 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
857 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 846 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
858 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 847 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
859 848
860 state.SetActiveTreeNeedsFirstDraw(true); 849 state.SetActiveTreeNeedsFirstDraw(true);
861 state.SetNeedsBeginMainFrame(); 850 state.SetNeedsBeginMainFrame();
862 state.SetNeedsRedraw(true); 851 state.SetNeedsRedraw(true);
863 state.SetCanDraw(false); 852 state.SetCanDraw(false);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 1177
1189 // Next BeginImplFrame should initiate second commit. 1178 // Next BeginImplFrame should initiate second commit.
1190 state.OnBeginImplFrame(); 1179 state.OnBeginImplFrame();
1191 EXPECT_ACTION_UPDATE_STATE( 1180 EXPECT_ACTION_UPDATE_STATE(
1192 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1181 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1193 } 1182 }
1194 1183
1195 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) { 1184 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) {
1196 SchedulerSettings default_scheduler_settings; 1185 SchedulerSettings default_scheduler_settings;
1197 StateMachine state(default_scheduler_settings); 1186 StateMachine state(default_scheduler_settings);
1198 state.SetCanStart();
1199 state.SetVisible(true); 1187 state.SetVisible(true);
1200 EXPECT_ACTION_UPDATE_STATE( 1188 EXPECT_ACTION_UPDATE_STATE(
1201 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1189 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1202 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1190 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1203 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1191 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1204 state.SetVisible(false); 1192 state.SetVisible(false);
1205 state.SetNeedsBeginMainFrame(); 1193 state.SetNeedsBeginMainFrame();
1206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1194 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1207 } 1195 }
1208 1196
1209 TEST(SchedulerStateMachineTest, TestNoRequestOutputSurfaceWhenInvisible) { 1197 TEST(SchedulerStateMachineTest, TestNoRequestOutputSurfaceWhenInvisible) {
1210 SchedulerSettings default_scheduler_settings; 1198 SchedulerSettings default_scheduler_settings;
1211 StateMachine state(default_scheduler_settings); 1199 StateMachine state(default_scheduler_settings);
1212 state.SetCanStart();
1213 // We should not request an OutputSurface when we are still invisible. 1200 // We should not request an OutputSurface when we are still invisible.
1214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1215 state.SetVisible(true); 1202 state.SetVisible(true);
1216 EXPECT_ACTION_UPDATE_STATE( 1203 EXPECT_ACTION_UPDATE_STATE(
1217 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1204 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1218 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1219 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1206 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1220 state.SetVisible(false); 1207 state.SetVisible(false);
1221 state.DidLoseOutputSurface(); 1208 state.DidLoseOutputSurface();
1222 state.SetNeedsBeginMainFrame(); 1209 state.SetNeedsBeginMainFrame();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 1263
1277 // We should be starting the commit now. 1264 // We should be starting the commit now.
1278 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1265 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1280 } 1267 }
1281 1268
1282 // See ThreadProxy::BeginMainFrame "EarlyOut_NoUpdates" case. 1269 // See ThreadProxy::BeginMainFrame "EarlyOut_NoUpdates" case.
1283 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) { 1270 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) {
1284 SchedulerSettings default_scheduler_settings; 1271 SchedulerSettings default_scheduler_settings;
1285 StateMachine state(default_scheduler_settings); 1272 StateMachine state(default_scheduler_settings);
1286 state.SetCanStart();
1287 state.SetVisible(true); 1273 state.SetVisible(true);
1288 EXPECT_ACTION_UPDATE_STATE( 1274 EXPECT_ACTION_UPDATE_STATE(
1289 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1275 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1276 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1291 state.DidCreateAndInitializeOutputSurface(); 1277 state.DidCreateAndInitializeOutputSurface();
1292 state.SetCanDraw(true); 1278 state.SetCanDraw(true);
1293 1279
1294 // Get into a begin frame / commit state. 1280 // Get into a begin frame / commit state.
1295 state.SetNeedsBeginMainFrame(); 1281 state.SetNeedsBeginMainFrame();
1296 state.OnBeginImplFrame(); 1282 state.OnBeginImplFrame();
(...skipping 27 matching lines...) Expand all
1324 // Verify another commit can start if requested, though. 1310 // Verify another commit can start if requested, though.
1325 state.SetNeedsBeginMainFrame(); 1311 state.SetNeedsBeginMainFrame();
1326 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1312 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1327 state.OnBeginImplFrame(); 1313 state.OnBeginImplFrame();
1328 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1314 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1329 } 1315 }
1330 1316
1331 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1317 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1332 SchedulerSettings default_scheduler_settings; 1318 SchedulerSettings default_scheduler_settings;
1333 StateMachine state(default_scheduler_settings); 1319 StateMachine state(default_scheduler_settings);
1334 state.SetCanStart();
1335 state.SetVisible(true); 1320 state.SetVisible(true);
1336 state.SetCanDraw(true); 1321 state.SetCanDraw(true);
1337 1322
1338 EXPECT_ACTION_UPDATE_STATE( 1323 EXPECT_ACTION_UPDATE_STATE(
1339 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1324 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1340 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1325 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1342 1327
1343 // Check that the first init does not SetNeedsBeginMainFrame. 1328 // Check that the first init does not SetNeedsBeginMainFrame.
1344 state.OnBeginImplFrame(); 1329 state.OnBeginImplFrame();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 TEST(SchedulerStateMachineTest, 1366 TEST(SchedulerStateMachineTest,
1382 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1367 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1383 SchedulerSettings default_scheduler_settings; 1368 SchedulerSettings default_scheduler_settings;
1384 StateMachine state(default_scheduler_settings); 1369 StateMachine state(default_scheduler_settings);
1385 SET_UP_STATE(state) 1370 SET_UP_STATE(state)
1386 1371
1387 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1372 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1388 state.NextAction()); 1373 state.NextAction());
1389 state.DidLoseOutputSurface(); 1374 state.DidLoseOutputSurface();
1390 EXPECT_EQ(state.output_surface_state(), 1375 EXPECT_EQ(state.output_surface_state(),
1391 SchedulerStateMachine::OUTPUT_SURFACE_LOST); 1376 SchedulerStateMachine::OUTPUT_SURFACE_NONE);
1392 1377
1393 EXPECT_ACTION_UPDATE_STATE( 1378 EXPECT_ACTION_UPDATE_STATE(
1394 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1379 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1395 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1380 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1396 1381
1397 // Once context recreation begins, nothing should happen. 1382 // Once context recreation begins, nothing should happen.
1398 state.OnBeginImplFrame(); 1383 state.OnBeginImplFrame();
1399 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1384 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1400 state.OnBeginImplFrameDeadline(); 1385 state.OnBeginImplFrameDeadline();
1401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1673 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1689 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1690 1675
1691 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1676 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1693 } 1678 }
1694 1679
1695 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) { 1680 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) {
1696 SchedulerSettings default_scheduler_settings; 1681 SchedulerSettings default_scheduler_settings;
1697 StateMachine state(default_scheduler_settings); 1682 StateMachine state(default_scheduler_settings);
1698 state.SetCanStart();
1699 state.SetVisible(true); 1683 state.SetVisible(true);
1700 EXPECT_ACTION_UPDATE_STATE( 1684 EXPECT_ACTION_UPDATE_STATE(
1701 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1685 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1702 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1703 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1687 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1704 1688
1705 EXPECT_FALSE(state.BeginFrameNeeded()); 1689 EXPECT_FALSE(state.BeginFrameNeeded());
1706 state.SetNeedsRedraw(true); 1690 state.SetNeedsRedraw(true);
1707 EXPECT_TRUE(state.BeginFrameNeeded()); 1691 EXPECT_TRUE(state.BeginFrameNeeded());
1708 1692
1709 state.SetVisible(false); 1693 state.SetVisible(false);
1710 EXPECT_FALSE(state.BeginFrameNeeded()); 1694 EXPECT_FALSE(state.BeginFrameNeeded());
1711 1695
1712 state.SetVisible(true); 1696 state.SetVisible(true);
1713 EXPECT_TRUE(state.BeginFrameNeeded()); 1697 EXPECT_TRUE(state.BeginFrameNeeded());
1714 } 1698 }
1715 1699
1716 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) { 1700 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) {
1717 SchedulerSettings default_scheduler_settings; 1701 SchedulerSettings default_scheduler_settings;
1718 StateMachine state(default_scheduler_settings); 1702 StateMachine state(default_scheduler_settings);
1719 state.SetCanStart();
1720 state.SetVisible(true); 1703 state.SetVisible(true);
1721 EXPECT_ACTION_UPDATE_STATE( 1704 EXPECT_ACTION_UPDATE_STATE(
1722 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1705 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1723 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1706 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1724 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1707 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1725 state.SetVisible(false); 1708 state.SetVisible(false);
1726 state.SetNeedsBeginMainFrame(); 1709 state.SetNeedsBeginMainFrame();
1727 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1710 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1728 EXPECT_FALSE(state.BeginFrameNeeded()); 1711 EXPECT_FALSE(state.BeginFrameNeeded());
1729 1712
1730 // When become visible again, the needs commit should still be pending. 1713 // When become visible again, the needs commit should still be pending.
1731 state.SetVisible(true); 1714 state.SetVisible(true);
1732 EXPECT_TRUE(state.BeginFrameNeeded()); 1715 EXPECT_TRUE(state.BeginFrameNeeded());
1733 state.OnBeginImplFrame(); 1716 state.OnBeginImplFrame();
1734 EXPECT_ACTION_UPDATE_STATE( 1717 EXPECT_ACTION_UPDATE_STATE(
1735 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1718 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1736 } 1719 }
1737 1720
1738 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1721 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1739 SchedulerSettings default_scheduler_settings; 1722 SchedulerSettings default_scheduler_settings;
1740 StateMachine state(default_scheduler_settings); 1723 StateMachine state(default_scheduler_settings);
1741 state.SetCanStart();
1742 state.SetVisible(true); 1724 state.SetVisible(true);
1743 EXPECT_ACTION_UPDATE_STATE( 1725 EXPECT_ACTION_UPDATE_STATE(
1744 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1726 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1745 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1746 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1728 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1747 state.SetVisible(false); 1729 state.SetVisible(false);
1748 state.SetBeginMainFrameState( 1730 state.SetBeginMainFrameState(
1749 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1731 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1750 state.SetNeedsBeginMainFrame(); 1732 state.SetNeedsBeginMainFrame();
1751 1733
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2095 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2114 bool commit_has_no_updates = true; 2096 bool commit_has_no_updates = true;
2115 state.WillCommit(commit_has_no_updates); 2097 state.WillCommit(commit_has_no_updates);
2116 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); 2098 EXPECT_TRUE(state.ProactiveBeginFrameWanted());
2117 state.OnBeginImplFrame(); 2099 state.OnBeginImplFrame();
2118 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2100 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2119 } 2101 }
2120 2102
2121 } // namespace 2103 } // namespace
2122 } // namespace cc 2104 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698