| 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.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void AddObserver(BeginFrameObserver* obs) override { | 222 void AddObserver(BeginFrameObserver* obs) override { |
| 223 client_->PushAction("AddObserver(this)"); | 223 client_->PushAction("AddObserver(this)"); |
| 224 BeginFrameSourceBase::AddObserver(obs); | 224 BeginFrameSourceBase::AddObserver(obs); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void RemoveObserver(BeginFrameObserver* obs) override { | 227 void RemoveObserver(BeginFrameObserver* obs) override { |
| 228 client_->PushAction("RemoveObserver(this)"); | 228 client_->PushAction("RemoveObserver(this)"); |
| 229 BeginFrameSourceBase::RemoveObserver(obs); | 229 BeginFrameSourceBase::RemoveObserver(obs); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void DidFinishFrame(BeginFrameObserver* obs) override { |
| 233 // Send a MISSED begin frame if necessary. |
| 234 if (missed_begin_frame_args_.IsValid()) { |
| 235 BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs(); |
| 236 if (!last_args.IsValid() || |
| 237 (missed_begin_frame_args_.frame_time > last_args.frame_time)) { |
| 238 obs->OnBeginFrame(missed_begin_frame_args_); |
| 239 } |
| 240 } |
| 241 } |
| 242 |
| 232 // TODO(sunnyps): Use using CallOnBeginFrame, SetBeginFrameSourcePaused. | 243 // TODO(sunnyps): Use using CallOnBeginFrame, SetBeginFrameSourcePaused. |
| 233 void TestOnBeginFrame(const BeginFrameArgs& args) { | 244 void TestOnBeginFrame(const BeginFrameArgs& args) { |
| 245 missed_begin_frame_args_ = args; |
| 246 missed_begin_frame_args_.type = BeginFrameArgs::MISSED; |
| 234 return CallOnBeginFrame(args); | 247 return CallOnBeginFrame(args); |
| 235 } | 248 } |
| 236 | 249 |
| 237 void SetPaused(bool paused) { SetBeginFrameSourcePaused(paused); } | 250 void SetPaused(bool paused) { SetBeginFrameSourcePaused(paused); } |
| 238 | 251 |
| 239 private: | 252 private: |
| 253 BeginFrameArgs missed_begin_frame_args_; |
| 240 FakeSchedulerClient* client_; | 254 FakeSchedulerClient* client_; |
| 241 }; | 255 }; |
| 242 | 256 |
| 243 class SchedulerTest : public testing::Test { | 257 class SchedulerTest : public testing::Test { |
| 244 public: | 258 public: |
| 245 SchedulerTest() | 259 SchedulerTest() |
| 246 : now_src_(new base::SimpleTestTickClock()), | 260 : now_src_(new base::SimpleTestTickClock()), |
| 247 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), | 261 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), |
| 248 fake_external_begin_frame_source_(nullptr) { | 262 fake_external_begin_frame_source_(nullptr) { |
| 249 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); | 263 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 336 |
| 323 // Check the client doesn't have any actions queued when calling this | 337 // Check the client doesn't have any actions queued when calling this |
| 324 // function. | 338 // function. |
| 325 EXPECT_NO_ACTION(client_); | 339 EXPECT_NO_ACTION(client_); |
| 326 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 340 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 327 | 341 |
| 328 // Start the initial output surface creation. | 342 // Start the initial output surface creation. |
| 329 scheduler_->SetVisible(true); | 343 scheduler_->SetVisible(true); |
| 330 scheduler_->SetCanDraw(true); | 344 scheduler_->SetCanDraw(true); |
| 331 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 345 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 332 | |
| 333 client_->Reset(); | 346 client_->Reset(); |
| 334 | 347 |
| 335 // We don't see anything happening until the first impl frame. | 348 // We don't see anything happening until the first impl frame. |
| 336 scheduler_->DidCreateAndInitializeOutputSurface(); | 349 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 337 scheduler_->SetNeedsBeginMainFrame(); | 350 scheduler_->SetNeedsBeginMainFrame(); |
| 338 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 351 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 339 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 340 client_->Reset(); | |
| 341 | 352 |
| 342 { | 353 { |
| 343 SCOPED_TRACE("Do first frame to commit after initialize."); | 354 SCOPED_TRACE("Do first frame to commit after initialize."); |
| 344 AdvanceFrame(); | 355 EXPECT_SCOPED(AdvanceFrame()); |
| 345 | 356 |
| 346 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 357 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 347 scheduler_->NotifyReadyToCommit(); | 358 scheduler_->NotifyReadyToCommit(); |
| 348 scheduler_->NotifyReadyToActivate(); | 359 scheduler_->NotifyReadyToActivate(); |
| 349 scheduler_->NotifyReadyToDraw(); | 360 scheduler_->NotifyReadyToDraw(); |
| 350 | 361 |
| 351 EXPECT_FALSE(scheduler_->CommitPending()); | 362 EXPECT_FALSE(scheduler_->CommitPending()); |
| 352 | 363 |
| 353 if (scheduler_settings_.using_synchronous_renderer_compositor) { | 364 if (scheduler_settings_.using_synchronous_renderer_compositor) { |
| 354 scheduler_->SetNeedsRedraw(); | 365 scheduler_->SetNeedsRedraw(); |
| 355 bool resourceless_software_draw = false; | 366 bool resourceless_software_draw = false; |
| 356 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 367 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 357 } else { | |
| 358 // Run the posted deadline task. | |
| 359 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 360 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 361 } | 368 } |
| 362 | |
| 363 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 364 } | 369 } |
| 365 | 370 |
| 366 client_->Reset(); | 371 client_->Reset(); |
| 367 | 372 |
| 368 { | 373 { |
| 369 SCOPED_TRACE( | 374 SCOPED_TRACE( |
| 370 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | 375 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); |
| 371 AdvanceFrame(); | 376 EXPECT_SCOPED(AdvanceFrame()); |
| 372 | 377 |
| 373 if (!scheduler_settings_.using_synchronous_renderer_compositor) { | 378 // Run the deadline or begin frame tasks if any. |
| 374 // Run the posted deadline task. | 379 task_runner_->RunPendingTasks(); |
| 375 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 376 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 377 } | |
| 378 | |
| 379 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 380 } | 380 } |
| 381 | 381 |
| 382 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 382 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 383 client_->Reset(); | 383 client_->Reset(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 bool NoNewFrame() { |
| 387 return !client_->HasAction("WillBeginImplFrame"); |
| 388 } |
| 389 |
| 386 // As this function contains EXPECT macros, to allow debugging it should be | 390 // As this function contains EXPECT macros, to allow debugging it should be |
| 387 // called inside EXPECT_SCOPED like so; | 391 // called inside EXPECT_SCOPED like so; |
| 388 // EXPECT_SCOPED(client.AdvanceFrame()); | 392 // EXPECT_SCOPED(client.AdvanceFrame()); |
| 389 void AdvanceFrame() { | 393 void AdvanceFrame() { |
| 390 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 394 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 391 "FakeSchedulerClient::AdvanceFrame"); | 395 "FakeSchedulerClient::AdvanceFrame"); |
| 392 // Consume any previous deadline first, if no deadline is currently | 396 |
| 393 // pending, ImplFrameDeadlinePending will return false straight away and we | 397 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 394 // will run no tasks. | |
| 395 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 396 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 397 | 398 |
| 398 // Send the next BeginFrame message if using an external source, otherwise | 399 // Send the next BeginFrame message if using an external source, otherwise |
| 399 // it will be already in the task queue. | 400 // it is sent automatically. |
| 400 if (scheduler_->begin_frame_source() == | 401 if (scheduler_->begin_frame_source() == |
| 401 fake_external_begin_frame_source_.get()) { | 402 fake_external_begin_frame_source_.get()) { |
| 402 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 403 // Consume deadline first. |
| 404 task_runner_->RunPendingTasks(); |
| 403 SendNextBeginFrame(); | 405 SendNextBeginFrame(); |
| 404 } | 406 } else { |
| 405 | 407 // Run until a new begin frame is posted. |
| 406 if (!scheduler_->settings().using_synchronous_renderer_compositor) { | 408 task_runner_->RunTasksWhile( |
| 407 // Then run tasks until new deadline is scheduled. | 409 base::Bind(&SchedulerTest::NoNewFrame, base::Unretained(this))); |
| 408 EXPECT_TRUE(task_runner_->RunTasksWhile( | |
| 409 client_->ImplFrameDeadlinePending(false))); | |
| 410 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 411 } | 410 } |
| 412 } | 411 } |
| 413 | 412 |
| 414 BeginFrameArgs SendNextBeginFrame() { | 413 BeginFrameArgs SendNextBeginFrame() { |
| 415 DCHECK_EQ(scheduler_->begin_frame_source(), | 414 DCHECK_EQ(scheduler_->begin_frame_source(), |
| 416 fake_external_begin_frame_source_.get()); | 415 fake_external_begin_frame_source_.get()); |
| 417 // Creep the time forward so that any BeginFrameArgs is not equal to the | 416 // Creep the time forward so that any BeginFrameArgs is not equal to the |
| 418 // last one otherwise we violate the BeginFrameSource contract. | 417 // last one otherwise we violate the BeginFrameSource contract. |
| 419 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 418 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
| 420 BeginFrameArgs args = | 419 BeginFrameArgs args = |
| (...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 EXPECT_NO_ACTION(client_); | 2193 EXPECT_NO_ACTION(client_); |
| 2195 | 2194 |
| 2196 // Activate the pending tree, which also unblocks the commit immediately | 2195 // Activate the pending tree, which also unblocks the commit immediately |
| 2197 // while we are in an idle state. | 2196 // while we are in an idle state. |
| 2198 client_->Reset(); | 2197 client_->Reset(); |
| 2199 scheduler_->NotifyReadyToActivate(); | 2198 scheduler_->NotifyReadyToActivate(); |
| 2200 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); | 2199 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); |
| 2201 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 2); | 2200 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 2); |
| 2202 } | 2201 } |
| 2203 | 2202 |
| 2204 TEST_F(SchedulerTest, BeginRetroFrame) { | 2203 TEST_F(SchedulerTest, BeginFrameWhileDeadlinePending) { |
| 2205 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2206 SetUpScheduler(true); | |
| 2207 | |
| 2208 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | |
| 2209 scheduler_->SetNeedsBeginMainFrame(); | |
| 2210 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2211 client_->Reset(); | |
| 2212 | |
| 2213 // Create a BeginFrame with a long deadline to avoid race conditions. | |
| 2214 // This is the first BeginFrame, which will be handled immediately. | |
| 2215 BeginFrameArgs args = | |
| 2216 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
| 2217 args.deadline += base::TimeDelta::FromHours(1); | |
| 2218 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2219 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 2220 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 2221 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2222 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2223 client_->Reset(); | |
| 2224 | |
| 2225 // Queue BeginFrames while we are still handling the previous BeginFrame. | |
| 2226 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2227 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2228 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2229 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2230 | |
| 2231 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | |
| 2232 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 2233 EXPECT_NO_ACTION(client_); | |
| 2234 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2235 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2236 client_->Reset(); | |
| 2237 | |
| 2238 // NotifyReadyToCommit should trigger the commit. | |
| 2239 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | |
| 2240 scheduler_->NotifyReadyToCommit(); | |
| 2241 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | |
| 2242 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2243 client_->Reset(); | |
| 2244 | |
| 2245 // NotifyReadyToActivate should trigger the activation. | |
| 2246 scheduler_->NotifyReadyToActivate(); | |
| 2247 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | |
| 2248 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2249 client_->Reset(); | |
| 2250 | |
| 2251 // BeginImplFrame should prepare the draw. | |
| 2252 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | |
| 2253 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | |
| 2254 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2255 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2256 client_->Reset(); | |
| 2257 | |
| 2258 // BeginImplFrame deadline should draw. | |
| 2259 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 2260 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | |
| 2261 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2262 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2263 client_->Reset(); | |
| 2264 | |
| 2265 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | |
| 2266 // to avoid excessive toggles. | |
| 2267 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | |
| 2268 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
| 2269 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2270 client_->Reset(); | |
| 2271 | |
| 2272 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 2273 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | |
| 2274 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | |
| 2275 client_->Reset(); | |
| 2276 } | |
| 2277 | |
| 2278 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | |
| 2279 scheduler_settings_.use_external_begin_frame_source = true; | 2204 scheduler_settings_.use_external_begin_frame_source = true; |
| 2280 SetUpScheduler(true); | 2205 SetUpScheduler(true); |
| 2281 | 2206 |
| 2282 scheduler_->SetNeedsBeginMainFrame(); | 2207 scheduler_->SetNeedsBeginMainFrame(); |
| 2208 scheduler_->SetNeedsRedraw(); |
| 2283 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2209 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2284 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2210 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2211 client_->Reset(); |
| 2285 | 2212 |
| 2286 client_->Reset(); | |
| 2287 EXPECT_SCOPED(AdvanceFrame()); | 2213 EXPECT_SCOPED(AdvanceFrame()); |
| 2288 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2214 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2289 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2215 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2290 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2216 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2217 client_->Reset(); |
| 2291 | 2218 |
| 2219 // Begin frame is skipped while deadline is pending. |
| 2220 EXPECT_SCOPED(SendNextBeginFrame()); |
| 2221 EXPECT_NO_ACTION(client_); |
| 2292 client_->Reset(); | 2222 client_->Reset(); |
| 2293 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | |
| 2294 | 2223 |
| 2224 // Finishing the previous frame causes BFS to send the begin frame again. |
| 2225 task_runner_->RunPendingTasks(); |
| 2226 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 2227 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2228 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2295 client_->Reset(); | 2229 client_->Reset(); |
| 2296 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); | 2230 |
| 2297 // This BeginFrame is queued up as a retro frame. | 2231 EXPECT_SCOPED(SendNextBeginFrame()); |
| 2298 EXPECT_NO_ACTION(client_); | 2232 EXPECT_NO_ACTION(client_); |
| 2299 // The previous deadline is still pending. | 2233 client_->Reset(); |
| 2300 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2301 | 2234 |
| 2302 client_->Reset(); | 2235 // No redraw this frame. |
| 2303 // This main frame activating should schedule the (previous) deadline to | 2236 task_runner_->RunPendingTasks(); |
| 2304 // trigger immediately. | 2237 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2305 scheduler_->NotifyReadyToCommit(); | |
| 2306 scheduler_->NotifyReadyToActivate(); | |
| 2307 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | |
| 2308 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | |
| 2309 | |
| 2310 client_->Reset(); | |
| 2311 // The deadline task should trigger causing a draw. | |
| 2312 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2313 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 2314 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | |
| 2315 | |
| 2316 // Keep animating. | |
| 2317 client_->Reset(); | |
| 2318 scheduler_->SetNeedsOneBeginImplFrame(); | |
| 2319 scheduler_->SetNeedsRedraw(); | |
| 2320 EXPECT_NO_ACTION(client_); | |
| 2321 | |
| 2322 // Let's advance to the retro frame's deadline. | |
| 2323 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks()); | |
| 2324 | |
| 2325 // The retro frame hasn't expired yet. | |
| 2326 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | |
| 2327 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | |
| 2328 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2329 | |
| 2330 // This is an immediate deadline case. | |
| 2331 client_->Reset(); | |
| 2332 task_runner().RunPendingTasks(); | |
| 2333 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2334 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | |
| 2335 } | |
| 2336 | |
| 2337 TEST_F(SchedulerTest, RetroFrameExpiresOnTime) { | |
| 2338 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2339 SetUpScheduler(true); | |
| 2340 | |
| 2341 scheduler_->SetNeedsBeginMainFrame(); | |
| 2342 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2343 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2344 | |
| 2345 client_->Reset(); | |
| 2346 EXPECT_SCOPED(AdvanceFrame()); | |
| 2347 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 2348 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 2349 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2350 | |
| 2351 client_->Reset(); | |
| 2352 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | |
| 2353 | |
| 2354 client_->Reset(); | |
| 2355 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); | |
| 2356 // This BeginFrame is queued up as a retro frame. | |
| 2357 EXPECT_NO_ACTION(client_); | |
| 2358 // The previous deadline is still pending. | |
| 2359 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2360 | |
| 2361 client_->Reset(); | |
| 2362 // This main frame activating should schedule the (previous) deadline to | |
| 2363 // trigger immediately. | |
| 2364 scheduler_->NotifyReadyToCommit(); | |
| 2365 scheduler_->NotifyReadyToActivate(); | |
| 2366 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | |
| 2367 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | |
| 2368 | |
| 2369 client_->Reset(); | |
| 2370 // The deadline task should trigger causing a draw. | |
| 2371 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2372 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 2373 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | |
| 2374 | |
| 2375 // Keep animating. | |
| 2376 client_->Reset(); | |
| 2377 scheduler_->SetNeedsOneBeginImplFrame(); | |
| 2378 scheduler_->SetNeedsRedraw(); | |
| 2379 EXPECT_NO_ACTION(client_); | |
| 2380 | |
| 2381 // Let's advance sufficiently past the retro frame's deadline. | |
| 2382 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks() + | |
| 2383 base::TimeDelta::FromMicroseconds(1)); | |
| 2384 | |
| 2385 // The retro frame should've expired. | |
| 2386 EXPECT_NO_ACTION(client_); | |
| 2387 } | |
| 2388 | |
| 2389 TEST_F(SchedulerTest, MissedFrameDoesNotExpireTooEarly) { | |
| 2390 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2391 SetUpScheduler(true); | |
| 2392 | |
| 2393 scheduler_->SetNeedsBeginMainFrame(); | |
| 2394 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2395 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2396 | |
| 2397 BeginFrameArgs missed_frame_args = | |
| 2398 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
| 2399 missed_frame_args.type = BeginFrameArgs::MISSED; | |
| 2400 | |
| 2401 // Advance to the deadline. | |
| 2402 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks()); | |
| 2403 | |
| 2404 // Missed frame is handled because it's on time. | |
| 2405 client_->Reset(); | |
| 2406 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); | |
| 2407 EXPECT_TRUE( | |
| 2408 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false))); | |
| 2409 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 2410 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 2411 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2238 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2412 } | 2239 } |
| 2413 | 2240 |
| 2414 TEST_F(SchedulerTest, MissedFrameExpiresOnTime) { | |
| 2415 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2416 SetUpScheduler(true); | |
| 2417 | |
| 2418 scheduler_->SetNeedsBeginMainFrame(); | |
| 2419 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2420 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2421 | |
| 2422 BeginFrameArgs missed_frame_args = | |
| 2423 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
| 2424 missed_frame_args.type = BeginFrameArgs::MISSED; | |
| 2425 | |
| 2426 // Advance sufficiently past the deadline. | |
| 2427 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks() + | |
| 2428 base::TimeDelta::FromMicroseconds(1)); | |
| 2429 | |
| 2430 // Missed frame is dropped because it's too late. | |
| 2431 client_->Reset(); | |
| 2432 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); | |
| 2433 EXPECT_FALSE( | |
| 2434 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false))); | |
| 2435 EXPECT_NO_ACTION(client_); | |
| 2436 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2437 } | |
| 2438 | |
| 2439 void SchedulerTest::BeginFramesNotFromClient( | 2241 void SchedulerTest::BeginFramesNotFromClient( |
| 2440 bool use_external_begin_frame_source, | 2242 bool use_external_begin_frame_source, |
| 2441 bool throttle_frame_production) { | 2243 bool throttle_frame_production) { |
| 2442 scheduler_settings_.use_external_begin_frame_source = | 2244 scheduler_settings_.use_external_begin_frame_source = |
| 2443 use_external_begin_frame_source; | 2245 use_external_begin_frame_source; |
| 2444 scheduler_settings_.throttle_frame_production = throttle_frame_production; | 2246 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 2445 SetUpScheduler(true); | 2247 SetUpScheduler(true); |
| 2446 | 2248 |
| 2447 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame | |
| 2448 // without calling SetNeedsBeginFrame. | |
| 2449 scheduler_->SetNeedsBeginMainFrame(); | |
| 2450 EXPECT_NO_ACTION(client_); | |
| 2451 client_->Reset(); | |
| 2452 | |
| 2453 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 2249 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 2454 // own BeginFrame tasks. | 2250 // own BeginFrame tasks. |
| 2455 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2251 scheduler_->SetNeedsBeginMainFrame(); |
| 2252 |
| 2253 // SyntheticBFS would have already sent a begin frame. |
| 2254 EXPECT_SCOPED(AdvanceFrame()); |
| 2456 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2255 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2457 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2256 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2458 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2257 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2459 client_->Reset(); | 2258 client_->Reset(); |
| 2460 | 2259 |
| 2461 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2260 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2462 task_runner().RunPendingTasks(); // Run posted deadline. | 2261 EXPECT_SCOPED(AdvanceFrame()); |
| 2463 EXPECT_NO_ACTION(client_); | 2262 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2464 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2263 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2465 client_->Reset(); | 2264 client_->Reset(); |
| 2466 | 2265 |
| 2467 // NotifyReadyToCommit should trigger the commit. | 2266 // NotifyReadyToCommit should trigger the commit. |
| 2468 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2267 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2469 scheduler_->NotifyReadyToCommit(); | 2268 scheduler_->NotifyReadyToCommit(); |
| 2470 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2269 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2471 client_->Reset(); | 2270 client_->Reset(); |
| 2472 | 2271 |
| 2473 // NotifyReadyToActivate should trigger the activation. | 2272 // NotifyReadyToActivate should trigger the activation. |
| 2474 scheduler_->NotifyReadyToActivate(); | 2273 scheduler_->NotifyReadyToActivate(); |
| 2475 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2274 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2476 client_->Reset(); | 2275 client_->Reset(); |
| 2477 | 2276 |
| 2478 // BeginImplFrame should prepare the draw. | |
| 2479 task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
| 2480 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | |
| 2481 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2482 client_->Reset(); | |
| 2483 | |
| 2484 // BeginImplFrame deadline should draw. | 2277 // BeginImplFrame deadline should draw. |
| 2485 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2278 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 2486 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2279 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2487 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2280 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2488 client_->Reset(); | 2281 client_->Reset(); |
| 2489 | 2282 |
| 2490 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2283 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 2491 // to avoid excessive toggles. | 2284 // to avoid excessive toggles. |
| 2492 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2285 EXPECT_SCOPED(AdvanceFrame()); |
| 2493 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2286 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2494 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2287 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2495 client_->Reset(); | 2288 client_->Reset(); |
| 2496 | 2289 |
| 2497 // Make sure SetNeedsBeginFrame isn't called on the client | 2290 // Make sure SetNeedsBeginFrame isn't called on the client |
| 2498 // when the BeginFrame is no longer needed. | 2291 // when the BeginFrame is no longer needed. |
| 2499 task_runner().RunPendingTasks(); // Run posted deadline. | 2292 task_runner_->RunPendingTasks(); |
| 2500 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 2293 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); |
| 2501 client_->Reset(); | 2294 client_->Reset(); |
| 2502 } | 2295 } |
| 2503 | 2296 |
| 2504 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 2297 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| 2505 bool use_external_begin_frame_source = false; | 2298 bool use_external_begin_frame_source = false; |
| 2506 bool throttle_frame_production = true; | 2299 bool throttle_frame_production = true; |
| 2507 BeginFramesNotFromClient(use_external_begin_frame_source, | 2300 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 2508 throttle_frame_production); | 2301 throttle_frame_production); |
| 2509 } | 2302 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2533 scheduler_->SetEstimatedParentDrawTime( | 2326 scheduler_->SetEstimatedParentDrawTime( |
| 2534 BeginFrameArgs::DefaultEstimatedParentDrawTime()); | 2327 BeginFrameArgs::DefaultEstimatedParentDrawTime()); |
| 2535 | 2328 |
| 2536 // Set the draw duration estimate to zero so that deadlines are accurate. | 2329 // Set the draw duration estimate to zero so that deadlines are accurate. |
| 2537 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); | 2330 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); |
| 2538 | 2331 |
| 2539 // To test swap ack throttling, this test disables automatic swap acks. | 2332 // To test swap ack throttling, this test disables automatic swap acks. |
| 2540 client_->SetAutomaticSwapAck(false); | 2333 client_->SetAutomaticSwapAck(false); |
| 2541 | 2334 |
| 2542 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2335 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2543 client_->Reset(); | |
| 2544 scheduler_->SetNeedsBeginMainFrame(); | 2336 scheduler_->SetNeedsBeginMainFrame(); |
| 2545 EXPECT_NO_ACTION(client_); | |
| 2546 client_->Reset(); | |
| 2547 | 2337 |
| 2548 // Trigger the first BeginImplFrame and BeginMainFrame | 2338 // Trigger the first BeginImplFrame and BeginMainFrame |
| 2549 EXPECT_SCOPED(AdvanceFrame()); | 2339 EXPECT_SCOPED(AdvanceFrame()); |
| 2550 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2340 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2551 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2341 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2552 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2342 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2553 client_->Reset(); | 2343 client_->Reset(); |
| 2554 | 2344 |
| 2555 // NotifyReadyToCommit should trigger the pending commit. | 2345 // NotifyReadyToCommit should trigger the pending commit. |
| 2556 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2346 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2783 EXPECT_NO_ACTION(client_); | 2573 EXPECT_NO_ACTION(client_); |
| 2784 | 2574 |
| 2785 client_->Reset(); | 2575 client_->Reset(); |
| 2786 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2576 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 2787 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); | 2577 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); |
| 2788 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); | 2578 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); |
| 2789 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4); | 2579 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4); |
| 2790 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4); | 2580 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4); |
| 2791 } | 2581 } |
| 2792 | 2582 |
| 2793 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | |
| 2794 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2795 SetUpScheduler(true); | |
| 2796 | |
| 2797 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | |
| 2798 scheduler_->SetNeedsBeginMainFrame(); | |
| 2799 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2800 | |
| 2801 // Create a BeginFrame with a long deadline to avoid race conditions. | |
| 2802 // This is the first BeginFrame, which will be handled immediately. | |
| 2803 client_->Reset(); | |
| 2804 BeginFrameArgs args = | |
| 2805 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
| 2806 args.deadline += base::TimeDelta::FromHours(1); | |
| 2807 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2808 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 2809 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 2810 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2811 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2812 | |
| 2813 // Queue BeginFrames while we are still handling the previous BeginFrame. | |
| 2814 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2815 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2816 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2817 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2818 | |
| 2819 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | |
| 2820 client_->Reset(); | |
| 2821 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 2822 EXPECT_NO_ACTION(client_); | |
| 2823 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2824 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2825 | |
| 2826 // NotifyReadyToCommit should trigger the commit. | |
| 2827 client_->Reset(); | |
| 2828 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | |
| 2829 scheduler_->NotifyReadyToCommit(); | |
| 2830 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | |
| 2831 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2832 | |
| 2833 // NotifyReadyToActivate should trigger the activation. | |
| 2834 client_->Reset(); | |
| 2835 scheduler_->NotifyReadyToActivate(); | |
| 2836 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | |
| 2837 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2838 | |
| 2839 client_->Reset(); | |
| 2840 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); | |
| 2841 scheduler_->DidLoseOutputSurface(); | |
| 2842 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | |
| 2843 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | |
| 2844 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | |
| 2845 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); | |
| 2846 | |
| 2847 // Posted BeginRetroFrame is aborted. | |
| 2848 client_->Reset(); | |
| 2849 task_runner().RunPendingTasks(); | |
| 2850 EXPECT_NO_ACTION(client_); | |
| 2851 } | |
| 2852 | |
| 2853 TEST_F(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | |
| 2854 scheduler_settings_.use_external_begin_frame_source = true; | |
| 2855 SetUpScheduler(true); | |
| 2856 | |
| 2857 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | |
| 2858 scheduler_->SetNeedsBeginMainFrame(); | |
| 2859 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
| 2860 | |
| 2861 // Create a BeginFrame with a long deadline to avoid race conditions. | |
| 2862 // This is the first BeginFrame, which will be handled immediately. | |
| 2863 client_->Reset(); | |
| 2864 BeginFrameArgs args = | |
| 2865 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
| 2866 args.deadline += base::TimeDelta::FromHours(1); | |
| 2867 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2868 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 2869 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 2870 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2871 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2872 | |
| 2873 // Queue BeginFrames while we are still handling the previous BeginFrame. | |
| 2874 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2875 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2876 args.frame_time += base::TimeDelta::FromSeconds(1); | |
| 2877 fake_external_begin_frame_source()->TestOnBeginFrame(args); | |
| 2878 | |
| 2879 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | |
| 2880 client_->Reset(); | |
| 2881 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 2882 EXPECT_NO_ACTION(client_); | |
| 2883 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2884 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2885 | |
| 2886 // NotifyReadyToCommit should trigger the commit. | |
| 2887 client_->Reset(); | |
| 2888 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | |
| 2889 scheduler_->NotifyReadyToCommit(); | |
| 2890 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | |
| 2891 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2892 | |
| 2893 // NotifyReadyToActivate should trigger the activation. | |
| 2894 client_->Reset(); | |
| 2895 scheduler_->NotifyReadyToActivate(); | |
| 2896 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | |
| 2897 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2898 | |
| 2899 // BeginImplFrame should prepare the draw. | |
| 2900 client_->Reset(); | |
| 2901 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | |
| 2902 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | |
| 2903 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2904 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
| 2905 | |
| 2906 client_->Reset(); | |
| 2907 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); | |
| 2908 scheduler_->DidLoseOutputSurface(); | |
| 2909 EXPECT_NO_ACTION(client_); | |
| 2910 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); | |
| 2911 | |
| 2912 // BeginImplFrame deadline should abort drawing. | |
| 2913 client_->Reset(); | |
| 2914 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
| 2915 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | |
| 2916 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | |
| 2917 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | |
| 2918 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 2919 EXPECT_FALSE(scheduler_->begin_frames_expected()); | |
| 2920 | |
| 2921 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | |
| 2922 client_->Reset(); | |
| 2923 task_runner().RunPendingTasks(); | |
| 2924 EXPECT_NO_ACTION(client_); | |
| 2925 } | |
| 2926 | |
| 2927 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 2583 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 2928 SetUpScheduler(true); | 2584 SetUpScheduler(true); |
| 2929 | 2585 |
| 2930 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2586 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2931 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2587 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2932 scheduler_->SetNeedsBeginMainFrame(); | 2588 scheduler_->SetNeedsBeginMainFrame(); |
| 2933 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2589 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2934 | 2590 |
| 2935 client_->Reset(); | |
| 2936 AdvanceFrame(); | 2591 AdvanceFrame(); |
| 2937 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2592 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2938 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2593 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2939 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2594 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2940 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2595 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2941 | 2596 |
| 2942 // NotifyReadyToCommit should trigger the commit. | 2597 // NotifyReadyToCommit should trigger the commit. |
| 2943 client_->Reset(); | 2598 client_->Reset(); |
| 2944 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2599 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2945 scheduler_->NotifyReadyToCommit(); | 2600 scheduler_->NotifyReadyToCommit(); |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3678 | 3333 |
| 3679 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3334 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3680 scheduler_->NotifyReadyToCommit(); | 3335 scheduler_->NotifyReadyToCommit(); |
| 3681 scheduler_->NotifyReadyToActivate(); | 3336 scheduler_->NotifyReadyToActivate(); |
| 3682 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 3337 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 3683 | 3338 |
| 3684 // Test changing the interval on the frame source external to the scheduler. | 3339 // Test changing the interval on the frame source external to the scheduler. |
| 3685 synthetic_frame_source_->OnUpdateVSyncParameters(now_src_->NowTicks(), | 3340 synthetic_frame_source_->OnUpdateVSyncParameters(now_src_->NowTicks(), |
| 3686 authoritative_interval); | 3341 authoritative_interval); |
| 3687 | 3342 |
| 3343 client_->Reset(); |
| 3688 EXPECT_SCOPED(AdvanceFrame()); | 3344 EXPECT_SCOPED(AdvanceFrame()); |
| 3689 | 3345 |
| 3690 // At the next BeginFrame, authoritative interval is used instead of previous | 3346 // At the next BeginFrame, authoritative interval is used instead of previous |
| 3691 // interval. | 3347 // interval. |
| 3692 EXPECT_NE(initial_interval, scheduler_->BeginImplFrameInterval()); | 3348 EXPECT_NE(initial_interval, scheduler_->BeginImplFrameInterval()); |
| 3693 EXPECT_EQ(authoritative_interval, scheduler_->BeginImplFrameInterval()); | 3349 EXPECT_EQ(authoritative_interval, scheduler_->BeginImplFrameInterval()); |
| 3694 } | 3350 } |
| 3695 | 3351 |
| 3696 TEST_F(SchedulerTest, ImplLatencyTakesPriority) { | 3352 TEST_F(SchedulerTest, ImplLatencyTakesPriority) { |
| 3697 SetUpScheduler(true); | 3353 SetUpScheduler(true); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3727 EXPECT_FALSE(scheduler_->ImplLatencyTakesPriority()); | 3383 EXPECT_FALSE(scheduler_->ImplLatencyTakesPriority()); |
| 3728 scheduler_->SetCriticalBeginMainFrameToActivateIsFast(false); | 3384 scheduler_->SetCriticalBeginMainFrameToActivateIsFast(false); |
| 3729 EXPECT_FALSE(scheduler_->ImplLatencyTakesPriority()); | 3385 EXPECT_FALSE(scheduler_->ImplLatencyTakesPriority()); |
| 3730 } | 3386 } |
| 3731 | 3387 |
| 3732 TEST_F(SchedulerTest, NoOutputSurfaceCreationWhileCommitPending) { | 3388 TEST_F(SchedulerTest, NoOutputSurfaceCreationWhileCommitPending) { |
| 3733 SetUpScheduler(true); | 3389 SetUpScheduler(true); |
| 3734 | 3390 |
| 3735 // SetNeedsBeginMainFrame should begin the frame. | 3391 // SetNeedsBeginMainFrame should begin the frame. |
| 3736 scheduler_->SetNeedsBeginMainFrame(); | 3392 scheduler_->SetNeedsBeginMainFrame(); |
| 3737 client_->Reset(); | |
| 3738 EXPECT_SCOPED(AdvanceFrame()); | 3393 EXPECT_SCOPED(AdvanceFrame()); |
| 3739 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3394 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3740 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3741 | 3396 |
| 3742 // Lose the output surface and trigger the deadline. | 3397 // Lose the output surface and trigger the deadline. |
| 3743 client_->Reset(); | 3398 client_->Reset(); |
| 3744 scheduler_->DidLoseOutputSurface(); | 3399 scheduler_->DidLoseOutputSurface(); |
| 3745 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3400 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3746 EXPECT_NO_ACTION(client_); | 3401 EXPECT_NO_ACTION(client_); |
| 3747 | 3402 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3758 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); | 3413 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); |
| 3759 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 3414 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 3760 } | 3415 } |
| 3761 | 3416 |
| 3762 TEST_F(SchedulerTest, OutputSurfaceCreationWhileCommitPending) { | 3417 TEST_F(SchedulerTest, OutputSurfaceCreationWhileCommitPending) { |
| 3763 scheduler_settings_.abort_commit_before_output_surface_creation = false; | 3418 scheduler_settings_.abort_commit_before_output_surface_creation = false; |
| 3764 SetUpScheduler(true); | 3419 SetUpScheduler(true); |
| 3765 | 3420 |
| 3766 // SetNeedsBeginMainFrame should begin the frame. | 3421 // SetNeedsBeginMainFrame should begin the frame. |
| 3767 scheduler_->SetNeedsBeginMainFrame(); | 3422 scheduler_->SetNeedsBeginMainFrame(); |
| 3768 client_->Reset(); | |
| 3769 EXPECT_SCOPED(AdvanceFrame()); | 3423 EXPECT_SCOPED(AdvanceFrame()); |
| 3770 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3424 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3771 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3425 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3772 | 3426 |
| 3773 // Lose the output surface and trigger the deadline. | 3427 // Lose the output surface and trigger the deadline. |
| 3774 client_->Reset(); | 3428 client_->Reset(); |
| 3775 scheduler_->DidLoseOutputSurface(); | 3429 scheduler_->DidLoseOutputSurface(); |
| 3776 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3430 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3777 EXPECT_NO_ACTION(client_); | 3431 EXPECT_NO_ACTION(client_); |
| 3778 | 3432 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3853 } | 3507 } |
| 3854 | 3508 |
| 3855 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3509 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3856 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3510 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3857 SMOOTHNESS_TAKES_PRIORITY, | 3511 SMOOTHNESS_TAKES_PRIORITY, |
| 3858 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3512 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3859 } | 3513 } |
| 3860 | 3514 |
| 3861 } // namespace | 3515 } // namespace |
| 3862 } // namespace cc | 3516 } // namespace cc |
| OLD | NEW |