Chromium Code Reviews| Index: cc/scheduler/scheduler_unittest.cc |
| diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc |
| index f4027bf4a112fdea5eee4b2138fc928d1ea5b38f..b87e9dec58ea272569155fb075aecd6b56b180cc 100644 |
| --- a/cc/scheduler/scheduler_unittest.cc |
| +++ b/cc/scheduler/scheduler_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/memory/scoped_vector.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| +#include "base/test/test_simple_task_runner.h" |
| #include "base/time/time.h" |
| #include "cc/test/scheduler_test_common.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -31,19 +32,10 @@ |
| namespace cc { |
| namespace { |
| -void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { |
| - scheduler->DidCreateAndInitializeOutputSurface(); |
| - scheduler->SetNeedsCommit(); |
| - scheduler->NotifyBeginMainFrameStarted(); |
| - scheduler->NotifyReadyToCommit(); |
| - // Go through the motions to draw the commit. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - // We need another BeginImplFrame so Scheduler calls |
| - // SetNeedsBeginImplFrame(false). |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| -} |
| +class FakeSchedulerClient; |
| + |
| +void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| + FakeSchedulerClient* client); |
| class FakeSchedulerClient : public SchedulerClient { |
| public: |
| @@ -62,8 +54,8 @@ class FakeSchedulerClient : public SchedulerClient { |
| } |
| Scheduler* CreateScheduler(const SchedulerSettings& settings) { |
| - scheduler_ = |
| - Scheduler::Create(this, settings, 0, base::MessageLoopProxy::current()); |
| + task_runner_ = new base::TestSimpleTaskRunner; |
| + scheduler_ = Scheduler::Create(this, settings, 0, task_runner_); |
| return scheduler_.get(); |
| } |
| @@ -81,6 +73,8 @@ class FakeSchedulerClient : public SchedulerClient { |
| return posted_begin_impl_frame_deadline_; |
| } |
| + base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } |
| + |
| int ActionIndex(const char* action) const { |
| for (size_t i = 0; i < actions_.size(); i++) |
| if (!strcmp(actions_[i], action)) |
| @@ -100,11 +94,15 @@ class FakeSchedulerClient : public SchedulerClient { |
| } |
| // SchedulerClient implementation. |
| - virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE { |
| - actions_.push_back("SetNeedsBeginImplFrame"); |
| + virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
| + actions_.push_back("SetNeedsBeginFrame"); |
| states_.push_back(scheduler_->StateAsValue().release()); |
| needs_begin_impl_frame_ = enable; |
| } |
| + virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
| + actions_.push_back("WillBeginImplFrame"); |
| + states_.push_back(scheduler_->StateAsValue().release()); |
| + } |
| virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| states_.push_back(scheduler_->StateAsValue().release()); |
| @@ -190,8 +188,33 @@ class FakeSchedulerClient : public SchedulerClient { |
| std::vector<const char*> actions_; |
| ScopedVector<base::Value> states_; |
| scoped_ptr<Scheduler> scheduler_; |
| + scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
|
brianderson
2014/04/02 16:57:50
I added an test task runner so we can make sure th
|
| }; |
| +void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| + FakeSchedulerClient* client) { |
| + scheduler->DidCreateAndInitializeOutputSurface(); |
| + scheduler->SetNeedsCommit(); |
| + scheduler->NotifyBeginMainFrameStarted(); |
| + scheduler->NotifyReadyToCommit(); |
| + // Go through the motions to draw the commit. |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + |
| + // Run the posted deadline task. |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + client->task_runner().RunPendingTasks(); |
| + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| + |
| + // We need another BeginImplFrame so Scheduler calls |
| + // SetNeedsBeginFrame(false). |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + |
| + // Run the posted deadline task. |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + client->task_runner().RunPendingTasks(); |
| + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| +} |
| + |
| TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| FakeSchedulerClient client; |
| SchedulerSettings default_scheduler_settings; |
| @@ -215,25 +238,26 @@ TEST(SchedulerTest, RequestCommit) { |
| scheduler->SetCanDraw(true); |
| EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| client.Reset(); |
| scheduler->SetNeedsCommit(); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| // If we don't swap on the deadline, we need to request another |
| // BeginImplFrame. |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| @@ -246,29 +270,29 @@ TEST(SchedulerTest, RequestCommit) { |
| client.Reset(); |
| // BeginImplFrame should prepare the draw. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| // BeginImplFrame deadline should draw. |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| - // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) |
| + // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| // to avoid excessive toggles. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| } |
| @@ -282,16 +306,17 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| scheduler->SetCanDraw(true); |
| EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| // SetNeedsCommit should begin the frame. |
| scheduler->SetNeedsCommit(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| @@ -308,20 +333,20 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| // Because we just swapped, the Scheduler should also request the next |
| // BeginImplFrame from the OutputSurface. |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| - |
| // Since another commit is needed, the next BeginImplFrame should initiate |
| // the second commit. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| @@ -332,17 +357,17 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| // On the next BeginImplFrame, verify we go back to a quiescent state and |
| // no longer request BeginImplFrames. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| } |
| @@ -356,32 +381,32 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| scheduler->SetCanDraw(true); |
| EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| scheduler->SetNeedsRedraw(); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| @@ -395,17 +420,17 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| client.Reset(); |
| scheduler->SetNeedsRedraw(); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // No draw happens since the textures are acquired by the main thread. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| @@ -415,8 +440,9 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| EXPECT_EQ(0, client.num_actions_()); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| // Commit will release the texture. |
| @@ -429,21 +455,21 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| // Now we can draw again after the commit happens. |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // Make sure we stop requesting BeginImplFrames if we don't swap. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| } |
| @@ -456,11 +482,11 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { |
| scheduler->SetCanDraw(true); |
| EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| scheduler->SetNeedsCommit(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| client.Reset(); |
| scheduler->SetMainThreadNeedsLayerTextures(); |
| @@ -468,16 +494,17 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { |
| "ScheduledActionAcquireLayerTexturesForMainThread", client); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| // Although the compositor cannot draw because textures are locked by main |
| - // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of |
| + // thread, we continue requesting SetNeedsBeginFrame in anticipation of |
| // the unlock. |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| @@ -494,28 +521,28 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { |
| // No implicit commit is expected. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| EXPECT_ACTION( |
| "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 2, 3); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // The compositor should not draw because textures are locked by main |
| // thread. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| @@ -523,12 +550,13 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { |
| // the textures. |
| client.Reset(); |
| scheduler->SetNeedsCommit(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| @@ -541,9 +569,9 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { |
| client.Reset(); |
| // Verify we draw on the next BeginImplFrame deadline |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| - EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| @@ -562,8 +590,8 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| scheduler->DidCreateAndInitializeOutputSurface(); |
| scheduler->SetNeedsCommit(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| scheduler->NotifyBeginMainFrameStarted(); |
| scheduler->NotifyReadyToCommit(); |
| scheduler->SetMainThreadNeedsLayerTextures(); |
| @@ -584,8 +612,9 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| // compositor is waiting for first draw should result in a request |
| // for a new frame in order to escape a deadlock. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| } |
| @@ -624,7 +653,7 @@ TEST(SchedulerTest, RequestRedrawInsideDraw) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| scheduler->SetNeedsRedraw(); |
| @@ -632,22 +661,22 @@ TEST(SchedulerTest, RequestRedrawInsideDraw) { |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| EXPECT_EQ(0, client.num_draws()); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| // swap. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| @@ -661,7 +690,7 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| client.SetDrawWillHappen(false); |
| @@ -672,8 +701,8 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| EXPECT_EQ(0, client.num_draws()); |
| // Fail the draw. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| // We have a commit pending and the draw failed, and we didn't lose the redraw |
| @@ -683,8 +712,8 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // Fail the draw again. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_TRUE(scheduler->CommitPending()); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| @@ -692,8 +721,8 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| // Draw successfully. |
| client.SetDrawWillHappen(true); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(3, client.num_draws()); |
| EXPECT_TRUE(scheduler->CommitPending()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| @@ -743,7 +772,7 @@ TEST(SchedulerTest, RequestCommitInsideDraw) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| EXPECT_FALSE(client.needs_begin_impl_frame()); |
| @@ -753,17 +782,17 @@ TEST(SchedulerTest, RequestCommitInsideDraw) { |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| client.SetNeedsCommitOnNextDraw(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| client.SetNeedsCommitOnNextDraw(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(scheduler->CommitPending()); |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| scheduler->NotifyBeginMainFrameStarted(); |
| scheduler->NotifyReadyToCommit(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| @@ -772,8 +801,8 @@ TEST(SchedulerTest, RequestCommitInsideDraw) { |
| // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| // swap. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| EXPECT_FALSE(scheduler->CommitPending()); |
| @@ -788,7 +817,7 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| client.SetDrawWillHappen(false); |
| @@ -799,8 +828,8 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| EXPECT_EQ(0, client.num_draws()); |
| // Fail the draw. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| // We have a commit pending and the draw failed, and we didn't lose the commit |
| @@ -810,8 +839,9 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| EXPECT_TRUE(client.needs_begin_impl_frame()); |
| // Fail the draw again. |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| EXPECT_TRUE(scheduler->CommitPending()); |
| EXPECT_TRUE(scheduler->RedrawPending()); |
| @@ -819,8 +849,8 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| // Draw successfully. |
| client.SetDrawWillHappen(true); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(3, client.num_draws()); |
| EXPECT_TRUE(scheduler->CommitPending()); |
| EXPECT_FALSE(scheduler->RedrawPending()); |
| @@ -834,7 +864,7 @@ TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| scheduler->SetNeedsRedraw(); |
| @@ -844,8 +874,8 @@ TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| // Draw successfully, this starts a new frame. |
| client.SetNeedsCommitOnNextDraw(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| scheduler->SetNeedsRedraw(); |
| @@ -855,8 +885,8 @@ TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| // Fail to draw, this should not start a frame. |
| client.SetDrawWillHappen(false); |
| client.SetNeedsCommitOnNextDraw(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(2, client.num_draws()); |
| } |
| @@ -924,7 +954,7 @@ TEST(SchedulerTest, ManageTiles) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| // Request both draw and manage tiles. ManageTiles shouldn't |
| // be trigged until BeginImplFrame. |
| @@ -941,13 +971,13 @@ TEST(SchedulerTest, ManageTiles) { |
| // We have no immediate actions to perform, so the BeginImplFrame should post |
| // the deadline task. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| // On the deadline, he actions should have occured in the right order. |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -968,15 +998,15 @@ TEST(SchedulerTest, ManageTiles) { |
| // We have no immediate actions to perform, so the BeginImplFrame should post |
| // the deadline task. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| // Draw. The draw will trigger SetNeedsManageTiles, and |
| // then the ManageTiles action will be triggered after the Draw. |
| // Afterwards, neither a draw nor ManageTiles are pending. |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -988,12 +1018,12 @@ TEST(SchedulerTest, ManageTiles) { |
| // We need a BeginImplFrame where we don't swap to go idle. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| - EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_EQ(0, client.num_draws()); |
| @@ -1008,11 +1038,11 @@ TEST(SchedulerTest, ManageTiles) { |
| // BeginImplFrame. There will be no draw, only ManageTiles. |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(0, client.num_draws()); |
| EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1028,14 +1058,14 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| // If DidManageTiles during a frame, then ManageTiles should not occur again. |
| scheduler->SetNeedsManageTiles(); |
| scheduler->SetNeedsRedraw(); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(scheduler->ManageTilesPending()); |
| @@ -1043,7 +1073,7 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| EXPECT_FALSE(scheduler->ManageTilesPending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1055,12 +1085,12 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| scheduler->SetNeedsManageTiles(); |
| scheduler->SetNeedsRedraw(); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1077,14 +1107,14 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| scheduler->SetNeedsManageTiles(); |
| scheduler->SetNeedsRedraw(); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(scheduler->ManageTilesPending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1099,14 +1129,14 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| scheduler->SetNeedsManageTiles(); |
| scheduler->SetNeedsRedraw(); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| EXPECT_TRUE(scheduler->ManageTilesPending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1117,12 +1147,12 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| scheduler->SetNeedsManageTiles(); |
| scheduler->SetNeedsRedraw(); |
| client.Reset(); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| - EXPECT_EQ(client.num_actions_(), 0); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| client.Reset(); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(1, client.num_draws()); |
| EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| @@ -1141,12 +1171,11 @@ TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| scheduler->SetCanStart(); |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| client.Reset(); |
| - BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); |
| scheduler->SetNeedsRedraw(); |
| - scheduler->BeginImplFrame(impl_frame_args); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| // The deadline should be zero since there is no work other than drawing |
| // pending. |
| @@ -1196,15 +1225,15 @@ void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, |
| scheduler->SetVisible(true); |
| scheduler->SetCanDraw(true); |
| scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
| - InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| // Impl thread hits deadline before commit finishes. |
| client.Reset(); |
| scheduler->SetNeedsCommit(); |
| EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| scheduler->NotifyBeginMainFrameStarted(); |
| scheduler->NotifyReadyToCommit(); |
| @@ -1214,9 +1243,9 @@ void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, |
| client.Reset(); |
| scheduler->SetNeedsCommit(); |
| EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| - scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| + scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
| should_send_begin_main_frame); |
| EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| @@ -1249,15 +1278,6 @@ TEST(SchedulerTest, NotSkipMainFrameInPreferSmoothnessMode) { |
| MainFrameInHighLatencyMode(1, 1, true, true); |
| } |
| -void SpinForMillis(int millis) { |
| - base::RunLoop run_loop; |
| - base::MessageLoop::current()->PostDelayedTask( |
| - FROM_HERE, |
| - run_loop.QuitClosure(), |
| - base::TimeDelta::FromMilliseconds(millis)); |
| - run_loop.Run(); |
| -} |
| - |
| TEST(SchedulerTest, PollForCommitCompletion) { |
| // Since we are simulating a long commit, set up a client with draw duration |
| // estimates that prevent skipping main frames to get to low latency mode. |
| @@ -1280,11 +1300,14 @@ TEST(SchedulerTest, PollForCommitCompletion) { |
| scheduler->NotifyBeginMainFrameStarted(); |
| scheduler->NotifyReadyToCommit(); |
| scheduler->SetNeedsRedraw(); |
| - BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); |
| - const int interval = 1; |
| - impl_frame_args.interval = base::TimeDelta::FromMilliseconds(interval); |
| - scheduler->BeginImplFrame(impl_frame_args); |
| - scheduler->OnBeginImplFrameDeadline(); |
| + BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting(); |
| + const int interval = 1000; |
| + frame_args.interval = base::TimeDelta::FromMilliseconds(interval); |
| + scheduler->BeginFrame(frame_args); |
| + |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| // At this point, we've drawn a frame. Start another commit, but hold off on |
| // the NotifyReadyToCommit for now. |
| @@ -1298,9 +1321,10 @@ TEST(SchedulerTest, PollForCommitCompletion) { |
| // Does three iterations to make sure that the timer is properly repeating. |
| for (int i = 0; i < 3; ++i) { |
| - // Wait for 2x the frame interval to match |
| - // Scheduler::advance_commit_state_timer_'s rate. |
| - SpinForMillis(interval * 2); |
| + EXPECT_GT(client.task_runner().NextPendingTaskDelay(), base::TimeDelta()); |
| + EXPECT_LT(client.task_runner().NextPendingTaskDelay(), |
| + frame_args.interval * 2); |
| + client.task_runner().RunPendingTasks(); |
| EXPECT_GT(client.num_actions_(), actions_so_far); |
| EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| "DidAnticipatedDrawTimeChange"); |
| @@ -1308,5 +1332,82 @@ TEST(SchedulerTest, PollForCommitCompletion) { |
| } |
| } |
| +TEST(SchedulerTest, BeginRetroFrame) { |
| + FakeSchedulerClient client; |
| + SchedulerSettings scheduler_settings; |
| + Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| + scheduler->SetCanStart(); |
| + scheduler->SetVisible(true); |
| + scheduler->SetCanDraw(true); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| + |
| + // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| + client.Reset(); |
| + scheduler->SetNeedsCommit(); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| + client.Reset(); |
| + |
| + // Create a BeginFrame with a long deadline to avoid race conditions. |
| + // This is the first BeginFrame, which will be handled immediately. |
| + BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); |
| + args.deadline += base::TimeDelta::FromHours(1); |
| + scheduler->BeginFrame(args); |
| + |
| + EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| + EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| + |
| + // Queue BeginFrames while we are still handling the previous BeginFrame. |
| + args.frame_time += base::TimeDelta::FromSeconds(1); |
| + scheduler->BeginFrame(args); |
| + args.frame_time += base::TimeDelta::FromSeconds(1); |
| + scheduler->BeginFrame(args); |
| + |
| + // If we don't swap on the deadline, we need to request another |
| + // BeginImplFrame. |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| + |
| + // NotifyReadyToCommit should trigger the commit. |
| + scheduler->NotifyBeginMainFrameStarted(); |
| + scheduler->NotifyReadyToCommit(); |
| + EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| + |
| + // BeginImplFrame should prepare the draw. |
| + client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| + |
| + // BeginImplFrame deadline should draw. |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| + EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| + EXPECT_TRUE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| + |
| + // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| + // to avoid excessive toggles. |
| + client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| + EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| + client.Reset(); |
| + |
| + client.task_runner().RunPendingTasks(); // Run posted deadline. |
| + EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| + EXPECT_FALSE(client.needs_begin_impl_frame()); |
| + client.Reset(); |
| +} |
| + |
| } // namespace |
| } // namespace cc |