From 48abf8153428c988f0740b5515beb4ecab18d837 Mon Sep 17 00:00:00 2001 From: "boliu@chromium.org" Date: Thu, 20 Mar 2014 17:41:59 +0000 Subject: [PATCH] cc: Pass task runner to scheduler Use explicit task runner to post BeginImplFrameDeadline and PollForAnticipatedDrawTriggers calls. Removed PostBeginImplFrameDeadline on the client since it's no longer needed. And fixed up tests. BUG=348796 Review URL: https://codereview.chromium.org/203233002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258326 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/scheduler/scheduler.cc | 23 ++++-- cc/scheduler/scheduler.h | 16 ++-- cc/scheduler/scheduler_unittest.cc | 127 ++++++++++++++++++----------- cc/trees/thread_proxy.cc | 14 +--- cc/trees/thread_proxy.h | 2 - 5 files changed, 107 insertions(+), 75 deletions(-) diff --git a/cc/scheduler/scheduler.cc b/cc/scheduler/scheduler.cc index 18b85a3d0945f1..ce80784c638429 100644 --- a/cc/scheduler/scheduler.cc +++ b/cc/scheduler/scheduler.cc @@ -14,12 +14,15 @@ namespace cc { -Scheduler::Scheduler(SchedulerClient* client, - const SchedulerSettings& scheduler_settings, - int layer_tree_host_id) +Scheduler::Scheduler( + SchedulerClient* client, + const SchedulerSettings& scheduler_settings, + int layer_tree_host_id, + const scoped_refptr& impl_task_runner) : settings_(scheduler_settings), client_(client), layer_tree_host_id_(layer_tree_host_id), + impl_task_runner_(impl_task_runner), last_set_needs_begin_impl_frame_(false), state_machine_(scheduler_settings), inside_process_scheduled_actions_(false), @@ -178,7 +181,7 @@ void Scheduler::SetupNextBeginImplFrameIfNeeded() { poll_for_draw_triggers_closure_.Reset( base::Bind(&Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr())); - base::MessageLoop::current()->PostDelayedTask( + impl_task_runner_->PostDelayedTask( FROM_HERE, poll_for_draw_triggers_closure_.callback(), last_begin_impl_frame_args_.interval); @@ -202,8 +205,8 @@ void Scheduler::SetupNextBeginImplFrameIfNeeded() { advance_commit_state_timer_.IsRunning()) { if (needs_advance_commit_state_timer && last_begin_impl_frame_args_.IsValid()) { - // Since we'd rather get a BeginImplFrame by the normally mechanism, we set - // the interval to twice the interval from the previous frame. + // Since we'd rather get a BeginImplFrame by the normal mechanism, we + // set the interval to twice the interval from the previous frame. advance_commit_state_timer_.Start( FROM_HERE, last_begin_impl_frame_args_.interval * 2, @@ -281,8 +284,12 @@ void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { begin_impl_frame_deadline_closure_.Reset( base::Bind(&Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr())); - client_->PostBeginImplFrameDeadline( - begin_impl_frame_deadline_closure_.callback(), deadline); + + base::TimeDelta delta = deadline - gfx::FrameTime::Now(); + if (delta <= base::TimeDelta()) + delta = base::TimeDelta(); + impl_task_runner_->PostDelayedTask( + FROM_HERE, begin_impl_frame_deadline_closure_.callback(), delta); } void Scheduler::OnBeginImplFrameDeadline() { diff --git a/cc/scheduler/scheduler.h b/cc/scheduler/scheduler.h index 5470f72fd04042..7d577b0187ac33 100644 --- a/cc/scheduler/scheduler.h +++ b/cc/scheduler/scheduler.h @@ -39,8 +39,6 @@ class SchedulerClient { virtual base::TimeDelta DrawDurationEstimate() = 0; virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; - virtual void PostBeginImplFrameDeadline(const base::Closure& closure, - base::TimeTicks deadline) = 0; virtual void DidBeginImplFrameDeadline() = 0; protected: @@ -52,9 +50,10 @@ class CC_EXPORT Scheduler { static scoped_ptr Create( SchedulerClient* client, const SchedulerSettings& scheduler_settings, - int layer_tree_host_id) { - return make_scoped_ptr( - new Scheduler(client, scheduler_settings, layer_tree_host_id)); + int layer_tree_host_id, + const scoped_refptr& impl_task_runner) { + return make_scoped_ptr(new Scheduler( + client, scheduler_settings, layer_tree_host_id, impl_task_runner)); } virtual ~Scheduler(); @@ -99,6 +98,9 @@ class CC_EXPORT Scheduler { bool MainThreadIsInHighLatencyMode() const { return state_machine_.MainThreadIsInHighLatencyMode(); } + bool BeginImplFrameDeadlinePending() const { + return !begin_impl_frame_deadline_closure_.IsCancelled(); + } bool WillDrawIfNeeded() const; @@ -123,7 +125,8 @@ class CC_EXPORT Scheduler { private: Scheduler(SchedulerClient* client, const SchedulerSettings& scheduler_settings, - int layer_tree_host_id); + int layer_tree_host_id, + const scoped_refptr& impl_task_runner); base::TimeTicks AdjustedBeginImplFrameDeadline() const; void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); @@ -142,6 +145,7 @@ class CC_EXPORT Scheduler { const SchedulerSettings settings_; SchedulerClient* client_; int layer_tree_host_id_; + scoped_refptr impl_task_runner_; bool last_set_needs_begin_impl_frame_; BeginFrameArgs last_begin_impl_frame_args_; diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc index fcd73a86d295b7..f4027bf4a112fd 100644 --- a/cc/scheduler/scheduler_unittest.cc +++ b/cc/scheduler/scheduler_unittest.cc @@ -62,7 +62,8 @@ class FakeSchedulerClient : public SchedulerClient { } Scheduler* CreateScheduler(const SchedulerSettings& settings) { - scheduler_ = Scheduler::Create(this, settings, 0); + scheduler_ = + Scheduler::Create(this, settings, 0, base::MessageLoopProxy::current()); return scheduler_.get(); } @@ -177,13 +178,6 @@ class FakeSchedulerClient : public SchedulerClient { return base::TimeDelta(); } - virtual void PostBeginImplFrameDeadline(const base::Closure& closure, - base::TimeTicks deadline) OVERRIDE { - actions_.push_back("PostBeginImplFrameDeadlineTask"); - states_.push_back(scheduler_->StateAsValue().release()); - posted_begin_impl_frame_deadline_ = deadline; - } - virtual void DidBeginImplFrameDeadline() OVERRIDE {} protected: @@ -231,8 +225,8 @@ TEST(SchedulerTest, RequestCommit) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -240,6 +234,7 @@ TEST(SchedulerTest, RequestCommit) { // BeginImplFrame. scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -252,7 +247,8 @@ TEST(SchedulerTest, RequestCommit) { // BeginImplFrame should prepare the draw. scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -260,13 +256,15 @@ TEST(SchedulerTest, RequestCommit) { scheduler->OnBeginImplFrameDeadline(); EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) // to avoid excessive toggles. scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); @@ -293,9 +291,8 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_EQ(client.num_actions_(), 2); - EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); - EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask")); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -308,12 +305,13 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { // Finish the first commit. scheduler->NotifyBeginMainFrameStarted(); scheduler->NotifyReadyToCommit(); - EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // Because we just swapped, the Scheduler should also request the next // BeginImplFrame from the OutputSurface. @@ -323,21 +321,21 @@ TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { // Since another commit is needed, the next BeginImplFrame should initiate // the second commit. scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_EQ(client.num_actions_(), 2); - EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); - EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask")); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); // Finishing the commit before the deadline should post a new deadline task // to trigger the deadline early. scheduler->NotifyBeginMainFrameStarted(); scheduler->NotifyReadyToCommit(); - EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -367,20 +365,24 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", 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_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(client.needs_begin_impl_frame()); @@ -399,10 +401,12 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { // No draw happens since the textures are acquired by the main thread. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(scheduler->RedrawPending()); EXPECT_TRUE(client.needs_begin_impl_frame()); @@ -412,15 +416,15 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); // Commit will release the texture. client.Reset(); scheduler->NotifyBeginMainFrameStarted(); scheduler->NotifyReadyToCommit(); - EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(scheduler->RedrawPending()); // Now we can draw again after the commit happens. @@ -428,13 +432,15 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { scheduler->OnBeginImplFrameDeadline(); EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", 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_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); @@ -463,8 +469,8 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); @@ -489,7 +495,8 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { // No implicit commit is expected. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); @@ -497,17 +504,20 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { EXPECT_ACTION( "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); EXPECT_ACTION("SetNeedsBeginImplFrame", 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_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); EXPECT_FALSE(client.needs_begin_impl_frame()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // The impl thread need an explicit commit from the main thread to lock // the textures. @@ -518,15 +528,15 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); // Trigger the commit, which will trigger the deadline task early. scheduler->NotifyBeginMainFrameStarted(); scheduler->NotifyReadyToCommit(); - EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(client.needs_begin_impl_frame()); client.Reset(); @@ -535,6 +545,7 @@ TEST(SchedulerTest, TextureAcquisitionCollision) { EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); EXPECT_TRUE(client.needs_begin_impl_frame()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); } @@ -574,8 +585,8 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { // for a new frame in order to escape a deadlock. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); - EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); + EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); } class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { @@ -931,7 +942,8 @@ TEST(SchedulerTest, ManageTiles) { // the deadline task. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); // On the deadline, he actions should have occured in the right order. client.Reset(); @@ -943,6 +955,7 @@ TEST(SchedulerTest, ManageTiles) { client.ActionIndex("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(scheduler->ManageTilesPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // Request a draw. We don't need a ManageTiles yet. client.Reset(); @@ -956,7 +969,8 @@ TEST(SchedulerTest, ManageTiles) { // the deadline task. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); // Draw. The draw will trigger SetNeedsManageTiles, and // then the ManageTiles action will be triggered after the Draw. @@ -970,14 +984,17 @@ TEST(SchedulerTest, ManageTiles) { client.ActionIndex("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(scheduler->ManageTilesPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // We need a BeginImplFrame where we don't swap to go idle. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_EQ(0, client.num_draws()); // Now trigger a ManageTiles outside of a draw. We will then need @@ -992,12 +1009,14 @@ TEST(SchedulerTest, ManageTiles) { // BeginImplFrame. There will be no draw, only ManageTiles. client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); EXPECT_EQ(0, client.num_draws()); EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); } // Test that ManageTiles only happens once per frame. If an external caller @@ -1016,7 +1035,8 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { scheduler->SetNeedsRedraw(); client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(scheduler->ManageTilesPending()); scheduler->DidManageTiles(); // An explicit ManageTiles. @@ -1029,13 +1049,15 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(scheduler->ManageTilesPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // Next frame without DidManageTiles should ManageTiles with draw. scheduler->SetNeedsManageTiles(); scheduler->SetNeedsRedraw(); client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); @@ -1046,6 +1068,7 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { client.ActionIndex("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(scheduler->ManageTilesPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles // If we get another DidManageTiles within the same frame, we should @@ -1055,7 +1078,8 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { scheduler->SetNeedsRedraw(); client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(scheduler->ManageTilesPending()); @@ -1065,6 +1089,7 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // If we get another DidManageTiles, we should not ManageTiles on the next // frame. This verifies we don't alternate calling ManageTiles once and twice. @@ -1075,7 +1100,8 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { scheduler->SetNeedsRedraw(); client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); EXPECT_TRUE(scheduler->ManageTilesPending()); @@ -1085,13 +1111,15 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); // Next frame without DidManageTiles should ManageTiles with draw. scheduler->SetNeedsManageTiles(); scheduler->SetNeedsRedraw(); client.Reset(); scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); - EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); + EXPECT_EQ(client.num_actions_(), 0); + EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); client.Reset(); scheduler->OnBeginImplFrameDeadline(); @@ -1102,6 +1130,7 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { client.ActionIndex("ScheduledActionManageTiles")); EXPECT_FALSE(scheduler->RedrawPending()); EXPECT_FALSE(scheduler->ManageTilesPending()); + EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles } diff --git a/cc/trees/thread_proxy.cc b/cc/trees/thread_proxy.cc index 5ac7a797751f6e..0008f0e4783b7a 100644 --- a/cc/trees/thread_proxy.cc +++ b/cc/trees/thread_proxy.cc @@ -1383,14 +1383,6 @@ base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { return impl().timing_history.CommitToActivateDurationEstimate(); } -void ThreadProxy::PostBeginImplFrameDeadline(const base::Closure& closure, - base::TimeTicks deadline) { - base::TimeDelta delta = deadline - gfx::FrameTime::Now(); - if (delta <= base::TimeDelta()) - delta = base::TimeDelta(); - Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); -} - void ThreadProxy::DidBeginImplFrameDeadline() { impl().layer_tree_host_impl->ResetCurrentFrameTimeForNextFrame(); } @@ -1478,8 +1470,10 @@ void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { settings.using_synchronous_renderer_compositor; scheduler_settings.throttle_frame_production = settings.throttle_frame_production; - impl().scheduler = - Scheduler::Create(this, scheduler_settings, impl().layer_tree_host_id); + impl().scheduler = Scheduler::Create(this, + scheduler_settings, + impl().layer_tree_host_id, + ImplThreadTaskRunner()); impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); diff --git a/cc/trees/thread_proxy.h b/cc/trees/thread_proxy.h index 680a448cca3228..c0203af10538a6 100644 --- a/cc/trees/thread_proxy.h +++ b/cc/trees/thread_proxy.h @@ -116,8 +116,6 @@ class ThreadProxy : public Proxy, virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; - virtual void PostBeginImplFrameDeadline(const base::Closure& closure, - base::TimeTicks deadline) OVERRIDE; virtual void DidBeginImplFrameDeadline() OVERRIDE; // ResourceUpdateControllerClient implementation