| OLD | NEW |
| 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) \ |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Failing the draw makes us require a commit. | 200 // Failing the draw makes us require a commit. |
| 201 state.DidDrawIfPossibleCompleted( | 201 state.DidDrawIfPossibleCompleted( |
| 202 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 202 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 203 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 203 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 204 EXPECT_ACTION_UPDATE_STATE( | 204 EXPECT_ACTION_UPDATE_STATE( |
| 205 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 205 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 206 EXPECT_TRUE(state.RedrawPending()); | 206 EXPECT_TRUE(state.RedrawPending()); |
| 207 EXPECT_TRUE(state.CommitPending()); | 207 EXPECT_TRUE(state.CommitPending()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResDoesNothing) { | 210 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { |
| 211 SchedulerSettings default_scheduler_settings; | 211 SchedulerSettings default_scheduler_settings; |
| 212 StateMachine state(default_scheduler_settings); | 212 StateMachine state(default_scheduler_settings); |
| 213 state.SetCanStart(); | 213 state.SetCanStart(); |
| 214 state.UpdateState(state.NextAction()); | 214 state.UpdateState(state.NextAction()); |
| 215 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 215 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 216 state.SetVisible(true); | 216 state.SetVisible(true); |
| 217 state.SetCanDraw(true); | 217 state.SetCanDraw(true); |
| 218 state.SetNeedsRedraw(true); | 218 state.SetNeedsRedraw(true); |
| 219 EXPECT_TRUE(state.RedrawPending()); | 219 EXPECT_TRUE(state.RedrawPending()); |
| 220 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 220 EXPECT_TRUE(state.BeginImplFrameNeeded()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 231 // Missing high res content requires a commit (but not a redraw) | 231 // Missing high res content requires a commit (but not a redraw) |
| 232 state.DidDrawIfPossibleCompleted( | 232 state.DidDrawIfPossibleCompleted( |
| 233 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); | 233 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); |
| 234 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 234 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 235 EXPECT_ACTION_UPDATE_STATE( | 235 EXPECT_ACTION_UPDATE_STATE( |
| 236 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 236 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 237 EXPECT_FALSE(state.RedrawPending()); | 237 EXPECT_FALSE(state.RedrawPending()); |
| 238 EXPECT_TRUE(state.CommitPending()); | 238 EXPECT_TRUE(state.CommitPending()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST(SchedulerStateMachineTest, TestFailedDrawForOtherReasonsDoesNothing) { |
| 242 SchedulerSettings default_scheduler_settings; |
| 243 StateMachine state(default_scheduler_settings); |
| 244 state.SetCanStart(); |
| 245 state.UpdateState(state.NextAction()); |
| 246 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 247 state.SetVisible(true); |
| 248 state.SetCanDraw(true); |
| 249 state.SetNeedsRedraw(true); |
| 250 EXPECT_TRUE(state.RedrawPending()); |
| 251 EXPECT_TRUE(state.BeginImplFrameNeeded()); |
| 252 |
| 253 DrawSwapReadbackResult::DrawResult aborts[] = { |
| 254 DrawSwapReadbackResult::DRAW_ABORTED_CANT_READBACK, |
| 255 DrawSwapReadbackResult::DRAW_ABORTED_CONTEXT_LOST, |
| 256 DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW, }; |
| 257 for (size_t i = 0; i < arraysize(aborts); ++i) { |
| 258 state.SetNeedsRedraw(true); |
| 259 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 260 |
| 261 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 262 state.OnBeginImplFrameDeadline(); |
| 263 EXPECT_ACTION_UPDATE_STATE( |
| 264 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 266 EXPECT_FALSE(state.RedrawPending()); |
| 267 EXPECT_FALSE(state.CommitPending()); |
| 268 |
| 269 state.DidDrawIfPossibleCompleted(aborts[i]); |
| 270 EXPECT_FALSE(state.RedrawPending()); |
| 271 EXPECT_FALSE(state.CommitPending()); |
| 272 } |
| 273 } |
| 274 |
| 241 TEST(SchedulerStateMachineTest, | 275 TEST(SchedulerStateMachineTest, |
| 242 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { | 276 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { |
| 243 SchedulerSettings default_scheduler_settings; | 277 SchedulerSettings default_scheduler_settings; |
| 244 StateMachine state(default_scheduler_settings); | 278 StateMachine state(default_scheduler_settings); |
| 245 state.SetCanStart(); | 279 state.SetCanStart(); |
| 246 state.UpdateState(state.NextAction()); | 280 state.UpdateState(state.NextAction()); |
| 247 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 281 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 248 | 282 |
| 249 state.SetVisible(true); | 283 state.SetVisible(true); |
| 250 state.SetCanDraw(true); | 284 state.SetCanDraw(true); |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1820 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1787 | 1821 |
| 1788 // The deadline is not triggered early until we enter prefer smoothness mode. | 1822 // The deadline is not triggered early until we enter prefer smoothness mode. |
| 1789 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1823 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1790 state.SetSmoothnessTakesPriority(true); | 1824 state.SetSmoothnessTakesPriority(true); |
| 1791 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1825 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1792 } | 1826 } |
| 1793 | 1827 |
| 1794 } // namespace | 1828 } // namespace |
| 1795 } // namespace cc | 1829 } // namespace cc |
| OLD | NEW |