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 "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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 { | 195 { |
196 StateMachine state(default_scheduler_settings); | 196 StateMachine state(default_scheduler_settings); |
197 state.SetCanStart(); | 197 state.SetCanStart(); |
198 EXPECT_ACTION_UPDATE_STATE( | 198 EXPECT_ACTION_UPDATE_STATE( |
199 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) | 199 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) |
200 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 200 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
201 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 201 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
202 state.SetNeedsRedraw(false); | 202 state.SetNeedsRedraw(false); |
203 state.SetVisible(true); | 203 state.SetVisible(true); |
204 | 204 |
205 EXPECT_FALSE(state.BeginFrameNeeded()); | 205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 206 EXPECT_FALSE(state.NeedsCommit()); |
206 | 207 |
| 208 state.OnBeginImplFrame(); |
207 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
208 EXPECT_FALSE(state.BeginFrameNeeded()); | |
209 state.OnBeginImplFrame(); | |
210 | 210 |
| 211 state.OnBeginImplFrameDeadline(); |
211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
212 state.OnBeginImplFrameDeadline(); | 213 EXPECT_FALSE(state.NeedsCommit()); |
213 } | 214 } |
214 | 215 |
215 // If commit requested but can_start is still false, do nothing. | 216 // If commit requested but can_start is still false, do nothing. |
216 { | 217 { |
217 StateMachine state(default_scheduler_settings); | 218 StateMachine state(default_scheduler_settings); |
218 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 219 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
219 state.SetNeedsRedraw(false); | 220 state.SetNeedsRedraw(false); |
220 state.SetVisible(true); | 221 state.SetVisible(true); |
221 state.SetNeedsCommit(); | 222 state.SetNeedsCommit(); |
222 | 223 |
223 EXPECT_FALSE(state.BeginFrameNeeded()); | 224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 225 EXPECT_TRUE(state.NeedsCommit()); |
224 | 226 |
225 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
226 EXPECT_FALSE(state.BeginFrameNeeded()); | |
227 state.OnBeginImplFrame(); | 227 state.OnBeginImplFrame(); |
228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 229 |
229 state.OnBeginImplFrameDeadline(); | 230 state.OnBeginImplFrameDeadline(); |
| 231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 232 EXPECT_TRUE(state.NeedsCommit()); |
230 } | 233 } |
231 | 234 |
232 // If commit requested, begin a main frame. | 235 // If commit requested, begin a main frame. |
233 { | 236 { |
234 StateMachine state(default_scheduler_settings); | 237 StateMachine state(default_scheduler_settings); |
235 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 238 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
236 state.SetCanStart(); | 239 state.SetCanStart(); |
237 state.UpdateState(state.NextAction()); | 240 state.UpdateState(state.NextAction()); |
238 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 241 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
239 state.SetNeedsRedraw(false); | 242 state.SetNeedsRedraw(false); |
240 state.SetVisible(true); | 243 state.SetVisible(true); |
241 state.SetNeedsCommit(); | 244 state.SetNeedsCommit(); |
242 | 245 |
243 EXPECT_TRUE(state.BeginFrameNeeded()); | |
244 | |
245 // Expect nothing to happen until after OnBeginImplFrame. | 246 // Expect nothing to happen until after OnBeginImplFrame. |
| 247 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
246 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); | 248 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); |
247 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 249 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
248 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); | 250 EXPECT_TRUE(state.NeedsCommit()); |
| 251 EXPECT_TRUE(state.BeginFrameNeeded()); |
249 | 252 |
250 state.OnBeginImplFrame(); | 253 state.OnBeginImplFrame(); |
251 EXPECT_ACTION_UPDATE_STATE( | 254 EXPECT_ACTION_UPDATE_STATE( |
252 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 255 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 256 EXPECT_COMMIT_STATE( |
| 257 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); |
| 258 EXPECT_FALSE(state.NeedsCommit()); |
253 } | 259 } |
254 | 260 |
255 // If commit requested and can't draw, still begin a main frame. | 261 // If commit requested and can't draw, still begin a main frame. |
256 { | 262 { |
257 StateMachine state(default_scheduler_settings); | 263 StateMachine state(default_scheduler_settings); |
258 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 264 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
259 state.SetCanStart(); | 265 state.SetCanStart(); |
260 state.UpdateState(state.NextAction()); | 266 state.UpdateState(state.NextAction()); |
261 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 267 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
262 state.SetNeedsRedraw(false); | 268 state.SetNeedsRedraw(false); |
263 state.SetVisible(true); | 269 state.SetVisible(true); |
264 state.SetNeedsCommit(); | 270 state.SetNeedsCommit(); |
265 state.SetCanDraw(false); | 271 state.SetCanDraw(false); |
266 | 272 |
267 EXPECT_TRUE(state.BeginFrameNeeded()); | |
268 | |
269 // Expect nothing to happen until after OnBeginImplFrame. | 273 // Expect nothing to happen until after OnBeginImplFrame. |
| 274 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
270 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); | 275 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); |
271 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 276 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
272 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); | 277 EXPECT_TRUE(state.BeginFrameNeeded()); |
273 | 278 |
274 state.OnBeginImplFrame(); | 279 state.OnBeginImplFrame(); |
275 EXPECT_ACTION_UPDATE_STATE( | 280 EXPECT_ACTION_UPDATE_STATE( |
276 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 281 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
277 } | |
278 | |
279 // Begin the frame, make sure needs_commit and commit_state update correctly. | |
280 { | |
281 StateMachine state(default_scheduler_settings); | |
282 state.SetCanStart(); | |
283 state.UpdateState(state.NextAction()); | |
284 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
285 state.SetVisible(true); | |
286 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
287 EXPECT_COMMIT_STATE( | 282 EXPECT_COMMIT_STATE( |
288 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | 283 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); |
289 EXPECT_FALSE(state.NeedsCommit()); | 284 EXPECT_FALSE(state.NeedsCommit()); |
290 } | 285 } |
291 } | 286 } |
292 | 287 |
293 // Explicitly test main_frame_before_activation_enabled = true | 288 // Explicitly test main_frame_before_activation_enabled = true |
294 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { | 289 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { |
295 SchedulerSettings scheduler_settings; | 290 SchedulerSettings scheduler_settings; |
296 scheduler_settings.main_frame_before_activation_enabled = true; | 291 scheduler_settings.main_frame_before_activation_enabled = true; |
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); | 1974 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); |
1980 bool commit_has_no_updates = true; | 1975 bool commit_has_no_updates = true; |
1981 state.UpdateStateOnCommit(commit_has_no_updates); | 1976 state.UpdateStateOnCommit(commit_has_no_updates); |
1982 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); | 1977 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); |
1983 state.OnBeginImplFrame(); | 1978 state.OnBeginImplFrame(); |
1984 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); | 1979 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); |
1985 } | 1980 } |
1986 | 1981 |
1987 } // namespace | 1982 } // namespace |
1988 } // namespace cc | 1983 } // namespace cc |
OLD | NEW |