diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-07-14 17:41:05 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-08-04 12:37:36 +0000 |
commit | 399c965b6064c440ddcf4015f5f8e9d131c7a0a6 (patch) | |
tree | 6b06b60ff365abef0e13b3503d593a0df48d20e8 /chromium/cc/scheduler | |
parent | 7366110654eec46f21b6824f302356426f48cd74 (diff) | |
download | qtwebengine-chromium-399c965b6064c440ddcf4015f5f8e9d131c7a0a6.tar.gz |
BASELINE: Update Chromium to 52.0.2743.76 and Ninja to 1.7.1
Change-Id: I382f51b959689505a60f8b707255ecb344f7d8b4
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/cc/scheduler')
17 files changed, 350 insertions, 579 deletions
diff --git a/chromium/cc/scheduler/begin_frame_source.cc b/chromium/cc/scheduler/begin_frame_source.cc index a0cf3627ea7..bf717470c7e 100644 --- a/chromium/cc/scheduler/begin_frame_source.cc +++ b/chromium/cc/scheduler/begin_frame_source.cc @@ -48,14 +48,6 @@ void BeginFrameObserverBase::OnBeginFrame(const BeginFrameArgs& args) { } } -void BeginFrameObserverBase::AsValueInto( - base::trace_event::TracedValue* dict) const { - dict->BeginDictionary("last_begin_frame_args_"); - last_begin_frame_args_.AsValueInto(dict); - dict->EndDictionary(); - dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); -} - // BeginFrameSourceBase ------------------------------------------------------ BeginFrameSourceBase::BeginFrameSourceBase() : paused_(false), inside_as_value_into_(false) {} @@ -90,8 +82,8 @@ void BeginFrameSourceBase::CallOnBeginFrame(const BeginFrameArgs& args) { DEBUG_FRAMES("BeginFrameSourceBase::CallOnBeginFrame", "num observers", observers_.size(), "args", args.AsValue()); std::set<BeginFrameObserver*> observers(observers_); - for (auto& it : observers) - it->OnBeginFrame(args); + for (BeginFrameObserver* obs : observers) + obs->OnBeginFrame(args); } void BeginFrameSourceBase::SetBeginFrameSourcePaused(bool paused) { @@ -99,31 +91,8 @@ void BeginFrameSourceBase::SetBeginFrameSourcePaused(bool paused) { return; paused_ = paused; std::set<BeginFrameObserver*> observers(observers_); - for (auto& it : observers) - it->OnBeginFrameSourcePausedChanged(paused_); -} - -// Tracing support -void BeginFrameSourceBase::AsValueInto( - base::trace_event::TracedValue* dict) const { - // As the observer might try to trace the source, prevent an infinte loop - // from occuring. - if (inside_as_value_into_) { - dict->SetString("observer", "<loop detected>"); - return; - } - - { - base::AutoReset<bool> prevent_loops( - const_cast<bool*>(&inside_as_value_into_), true); - dict->BeginArray("observers"); - for (const auto& it : observers_) { - dict->BeginDictionary(); - it->AsValueInto(dict); - dict->EndDictionary(); - } - dict->EndArray(); - } + for (BeginFrameObserver* obs : observers) + obs->OnBeginFrameSourcePausedChanged(paused_); } // BackToBackBeginFrameSource -------------------------------------------- @@ -142,49 +111,52 @@ base::TimeTicks BackToBackBeginFrameSource::Now() { // BeginFrameSourceBase support void BackToBackBeginFrameSource::AddObserver(BeginFrameObserver* obs) { - DCHECK(observers_.empty()) - << "BackToBackBeginFrameSource only supports a single observer"; BeginFrameSourceBase::AddObserver(obs); + pending_begin_frame_observers_.insert(obs); + PostPendingBeginFramesTask(); } -void BackToBackBeginFrameSource::OnNeedsBeginFramesChanged( - bool needs_begin_frames) { - if (needs_begin_frames) { - PostBeginFrame(); - } else { +void BackToBackBeginFrameSource::RemoveObserver(BeginFrameObserver* obs) { + BeginFrameSourceBase::RemoveObserver(obs); + pending_begin_frame_observers_.erase(obs); + if (pending_begin_frame_observers_.empty()) begin_frame_task_.Cancel(); +} + +void BackToBackBeginFrameSource::DidFinishFrame(BeginFrameObserver* obs, + size_t remaining_frames) { + BeginFrameSourceBase::DidFinishFrame(obs, remaining_frames); + if (remaining_frames == 0 && observers_.find(obs) != observers_.end()) { + pending_begin_frame_observers_.insert(obs); + PostPendingBeginFramesTask(); } } -void BackToBackBeginFrameSource::PostBeginFrame() { +void BackToBackBeginFrameSource::PostPendingBeginFramesTask() { DCHECK(needs_begin_frames()); - begin_frame_task_.Reset(base::Bind(&BackToBackBeginFrameSource::BeginFrame, - weak_factory_.GetWeakPtr())); - task_runner_->PostTask(FROM_HERE, begin_frame_task_.callback()); + DCHECK(!pending_begin_frame_observers_.empty()); + if (begin_frame_task_.IsCancelled()) { + begin_frame_task_.Reset( + base::Bind(&BackToBackBeginFrameSource::SendPendingBeginFrames, + weak_factory_.GetWeakPtr())); + task_runner_->PostTask(FROM_HERE, begin_frame_task_.callback()); + } } -void BackToBackBeginFrameSource::BeginFrame() { +void BackToBackBeginFrameSource::SendPendingBeginFrames() { DCHECK(needs_begin_frames()); DCHECK(!begin_frame_task_.IsCancelled()); begin_frame_task_.Cancel(); + base::TimeTicks now = Now(); BeginFrameArgs args = BeginFrameArgs::Create( BEGINFRAME_FROM_HERE, now, now + BeginFrameArgs::DefaultInterval(), BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); - CallOnBeginFrame(args); -} -void BackToBackBeginFrameSource::DidFinishFrame(size_t remaining_frames) { - BeginFrameSourceBase::DidFinishFrame(remaining_frames); - if (needs_begin_frames() && remaining_frames == 0) - PostBeginFrame(); -} - -// Tracing support -void BackToBackBeginFrameSource::AsValueInto( - base::trace_event::TracedValue* dict) const { - dict->SetString("type", "BackToBackBeginFrameSource"); - BeginFrameSourceBase::AsValueInto(dict); + std::set<BeginFrameObserver*> pending_observers; + pending_observers.swap(pending_begin_frame_observers_); + for (BeginFrameObserver* obs : pending_observers) + obs->OnBeginFrame(args); } // SyntheticBeginFrameSource --------------------------------------------- @@ -197,7 +169,7 @@ SyntheticBeginFrameSource::SyntheticBeginFrameSource( } SyntheticBeginFrameSource::SyntheticBeginFrameSource( - scoped_ptr<DelayBasedTimeSource> time_source) + std::unique_ptr<DelayBasedTimeSource> time_source) : time_source_(std::move(time_source)) { time_source_->SetClient(this); } @@ -205,9 +177,19 @@ SyntheticBeginFrameSource::SyntheticBeginFrameSource( SyntheticBeginFrameSource::~SyntheticBeginFrameSource() {} void SyntheticBeginFrameSource::OnUpdateVSyncParameters( - base::TimeTicks new_vsync_timebase, - base::TimeDelta new_vsync_interval) { - time_source_->SetTimebaseAndInterval(new_vsync_timebase, new_vsync_interval); + base::TimeTicks timebase, + base::TimeDelta interval) { + if (!authoritative_interval_.is_zero()) + interval = authoritative_interval_; + + last_timebase_ = timebase; + time_source_->SetTimebaseAndInterval(timebase, interval); +} + +void SyntheticBeginFrameSource::SetAuthoritativeVSyncInterval( + base::TimeDelta interval) { + authoritative_interval_ = interval; + OnUpdateVSyncParameters(last_timebase_, interval); } BeginFrameArgs SyntheticBeginFrameSource::CreateBeginFrameArgs( @@ -252,15 +234,4 @@ void SyntheticBeginFrameSource::OnTimerTick() { } } -// Tracing support -void SyntheticBeginFrameSource::AsValueInto( - base::trace_event::TracedValue* dict) const { - dict->SetString("type", "SyntheticBeginFrameSource"); - BeginFrameSourceBase::AsValueInto(dict); - - dict->BeginDictionary("time_source"); - time_source_->AsValueInto(dict); - dict->EndDictionary(); -} - } // namespace cc diff --git a/chromium/cc/scheduler/begin_frame_source.h b/chromium/cc/scheduler/begin_frame_source.h index fb0c8c3f40c..cb23667a274 100644 --- a/chromium/cc/scheduler/begin_frame_source.h +++ b/chromium/cc/scheduler/begin_frame_source.h @@ -61,9 +61,6 @@ class CC_EXPORT BeginFrameObserver { virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0; virtual void OnBeginFrameSourcePausedChanged(bool paused) = 0; - - // Tracing support - virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; }; // Simple base class which implements a BeginFrameObserver which checks the @@ -87,9 +84,6 @@ class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver { void OnBeginFrame(const BeginFrameArgs& args) override; const BeginFrameArgs& LastUsedBeginFrameArgs() const override; - // Outputs last_begin_frame_args_ - void AsValueInto(base::trace_event::TracedValue* dict) const override; - protected: // Subclasses should override this method! // Return true if the given argument is (or will be) used. @@ -119,16 +113,13 @@ class CC_EXPORT BeginFrameSource { // processing (rather than toggling SetNeedsBeginFrames every frame). It is // used by systems like the BackToBackFrameSource to make sure only one frame // is pending at a time. - virtual void DidFinishFrame(size_t remaining_frames) = 0; + virtual void DidFinishFrame(BeginFrameObserver* obs, + size_t remaining_frames) = 0; // Add/Remove an observer from the source. When no observers are added the BFS // should shut down its timers, disable vsync, etc. virtual void AddObserver(BeginFrameObserver* obs) = 0; virtual void RemoveObserver(BeginFrameObserver* obs) = 0; - - // Tracing support - Recommend (but not required) to call this implementation - // in any override. - virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; }; // Simple base class which implements a BeginFrameSource. @@ -136,21 +127,16 @@ class CC_EXPORT BeginFrameSource { // - Implement the pure virtual (Set)NeedsBeginFrames methods from // BeginFrameSource. // - Use the CallOnBeginFrame method to call to the observer(s). -// - Recommended (but not required) to call BeginFrameSourceBase::AsValueInto -// in their own AsValueInto implementation. class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { public: ~BeginFrameSourceBase() override; // BeginFrameSource - void DidFinishFrame(size_t remaining_frames) override {} + void DidFinishFrame(BeginFrameObserver* obs, + size_t remaining_frames) override {} void AddObserver(BeginFrameObserver* obs) override; void RemoveObserver(BeginFrameObserver* obs) override; - // Tracing support - Recommend (but not required) to call this implementation - // in any override. - void AsValueInto(base::trace_event::TracedValue* dict) const override; - protected: BeginFrameSourceBase(); @@ -183,23 +169,20 @@ class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { ~BackToBackBeginFrameSource() override; // BeginFrameSource - void DidFinishFrame(size_t remaining_frames) override; - - // BeginFrameSourceBase void AddObserver(BeginFrameObserver* obs) override; - void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; - - // Tracing - void AsValueInto(base::trace_event::TracedValue* dict) const override; + void RemoveObserver(BeginFrameObserver* obs) override; + void DidFinishFrame(BeginFrameObserver* obs, + size_t remaining_frames) override; protected: virtual base::TimeTicks Now(); // Now overridable for testing base::SingleThreadTaskRunner* task_runner_; base::CancelableClosure begin_frame_task_; + std::set<BeginFrameObserver*> pending_begin_frame_observers_; - void PostBeginFrame(); - void BeginFrame(); + void PostPendingBeginFramesTask(); + void SendPendingBeginFrames(); private: base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; @@ -215,19 +198,18 @@ class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, base::TimeDelta initial_vsync_interval); explicit SyntheticBeginFrameSource( - scoped_ptr<DelayBasedTimeSource> time_source); + std::unique_ptr<DelayBasedTimeSource> time_source); ~SyntheticBeginFrameSource() override; - void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, - base::TimeDelta new_vsync_interval); + void OnUpdateVSyncParameters(base::TimeTicks timebase, + base::TimeDelta interval); + // This overrides any past or future interval from updating vsync parameters. + void SetAuthoritativeVSyncInterval(base::TimeDelta interval); // BeginFrameSourceBase void AddObserver(BeginFrameObserver* obs) override; void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; - // Tracing - void AsValueInto(base::trace_event::TracedValue* dict) const override; - // DelayBasedTimeSourceClient void OnTimerTick() override; @@ -235,7 +217,9 @@ class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, BeginFrameArgs::BeginFrameArgsType type); - scoped_ptr<DelayBasedTimeSource> time_source_; + std::unique_ptr<DelayBasedTimeSource> time_source_; + base::TimeTicks last_timebase_; + base::TimeDelta authoritative_interval_; private: DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); diff --git a/chromium/cc/scheduler/begin_frame_source_unittest.cc b/chromium/cc/scheduler/begin_frame_source_unittest.cc index 37b0a639b15..fbeba81732a 100644 --- a/chromium/cc/scheduler/begin_frame_source_unittest.cc +++ b/chromium/cc/scheduler/begin_frame_source_unittest.cc @@ -6,6 +6,7 @@ #include <stdint.h> +#include "base/memory/ptr_util.h" #include "base/test/test_simple_task_runner.h" #include "cc/test/begin_frame_args_test.h" #include "cc/test/begin_frame_source_test.h" @@ -172,38 +173,6 @@ TEST(BeginFrameSourceBaseTest, MultipleObservers) { source.RemoveObserver(&obs2); } -class LoopingBeginFrameObserver : public BeginFrameObserverBase { - public: - BeginFrameSource* source_; - - void AsValueInto(base::trace_event::TracedValue* dict) const override { - dict->SetString("type", "LoopingBeginFrameObserver"); - dict->BeginDictionary("source"); - source_->AsValueInto(dict); - dict->EndDictionary(); - } - - protected: - // BeginFrameObserverBase - bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override { - return true; - } - - void OnBeginFrameSourcePausedChanged(bool paused) override {} -}; - -TEST(BeginFrameSourceBaseTest, DetectAsValueIntoLoop) { - LoopingBeginFrameObserver obs; - FakeBeginFrameSource source; - - obs.source_ = &source; - source.AddObserver(&obs); - - scoped_ptr<base::trace_event::TracedValue> state( - new base::trace_event::TracedValue()); - source.AsValueInto(state.get()); -} - // BackToBackBeginFrameSource testing ----------------------------------------- class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource { public: @@ -223,10 +192,10 @@ class BackToBackBeginFrameSourceTest : public ::testing::Test { static const int64_t kDeadline; static const int64_t kInterval; - scoped_ptr<base::SimpleTestTickClock> now_src_; + std::unique_ptr<base::SimpleTestTickClock> now_src_; scoped_refptr<OrderedSimpleTaskRunner> task_runner_; - scoped_ptr<TestBackToBackBeginFrameSource> source_; - scoped_ptr<MockBeginFrameObserver> obs_; + std::unique_ptr<TestBackToBackBeginFrameSource> source_; + std::unique_ptr<MockBeginFrameObserver> obs_; void SetUp() override { now_src_.reset(new base::SimpleTestTickClock()); @@ -235,7 +204,8 @@ class BackToBackBeginFrameSourceTest : public ::testing::Test { make_scoped_refptr(new OrderedSimpleTaskRunner(now_src_.get(), false)); source_.reset( new TestBackToBackBeginFrameSource(now_src_.get(), task_runner_.get())); - obs_ = make_scoped_ptr(new ::testing::StrictMock<MockBeginFrameObserver>()); + obs_ = + base::WrapUnique(new ::testing::StrictMock<MockBeginFrameObserver>()); } void TearDown() override { obs_.reset(); } @@ -256,7 +226,7 @@ TEST_F(BackToBackBeginFrameSourceTest, AddObserverSendsBeginFrame) { EXPECT_BEGIN_FRAME_USED(*obs_, 1100, 1100 + kDeadline, kInterval); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); task_runner_->RunPendingTasks(); } @@ -268,7 +238,7 @@ TEST_F(BackToBackBeginFrameSourceTest, task_runner_->RunPendingTasks(); source_->RemoveObserver(obs_.get()); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); EXPECT_FALSE(task_runner_->HasPendingTasks()); } @@ -281,7 +251,7 @@ TEST_F(BackToBackBeginFrameSourceTest, task_runner_->RunPendingTasks(); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); source_->RemoveObserver(obs_.get()); EXPECT_TRUE(task_runner_->HasPendingTasks()); @@ -303,7 +273,7 @@ TEST_F(BackToBackBeginFrameSourceTest, source_->AddObserver(obs_.get()); now_src_->Advance(base::TimeDelta::FromMicroseconds(10)); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); now_src_->Advance(base::TimeDelta::FromMicroseconds(10)); EXPECT_BEGIN_FRAME_USED(*obs_, 1130, 1130 + kDeadline, kInterval); @@ -319,7 +289,7 @@ TEST_F(BackToBackBeginFrameSourceTest, task_runner_->RunPendingTasks(); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); now_src_->Advance(base::TimeDelta::FromMicroseconds(10)); source_->RemoveObserver(obs_.get()); @@ -338,7 +308,7 @@ TEST_F(BackToBackBeginFrameSourceTest, DidFinishFrameNoObserver) { EXPECT_BEGIN_FRAME_SOURCE_PAUSED(*obs_, false); source_->AddObserver(obs_.get()); source_->RemoveObserver(obs_.get()); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); EXPECT_FALSE(task_runner_->RunPendingTasks()); } @@ -350,15 +320,15 @@ TEST_F(BackToBackBeginFrameSourceTest, DidFinishFrameRemainingFrames) { now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(3); + source_->DidFinishFrame(obs_.get(), 3); EXPECT_FALSE(task_runner_->HasPendingTasks()); - source_->DidFinishFrame(2); + source_->DidFinishFrame(obs_.get(), 2); EXPECT_FALSE(task_runner_->HasPendingTasks()); - source_->DidFinishFrame(1); + source_->DidFinishFrame(obs_.get(), 1); EXPECT_FALSE(task_runner_->HasPendingTasks()); EXPECT_BEGIN_FRAME_USED(*obs_, 1100, 1100 + kDeadline, kInterval); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); EXPECT_EQ(base::TimeDelta(), task_runner_->DelayToNextTaskTime()); task_runner_->RunPendingTasks(); } @@ -370,16 +340,16 @@ TEST_F(BackToBackBeginFrameSourceTest, DidFinishFrameMultipleCallsIdempotent) { task_runner_->RunPendingTasks(); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); - source_->DidFinishFrame(0); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); + source_->DidFinishFrame(obs_.get(), 0); + source_->DidFinishFrame(obs_.get(), 0); EXPECT_BEGIN_FRAME_USED(*obs_, 1100, 1100 + kDeadline, kInterval); task_runner_->RunPendingTasks(); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); - source_->DidFinishFrame(0); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); + source_->DidFinishFrame(obs_.get(), 0); + source_->DidFinishFrame(obs_.get(), 0); EXPECT_BEGIN_FRAME_USED(*obs_, 1200, 1200 + kDeadline, kInterval); task_runner_->RunPendingTasks(); } @@ -391,7 +361,7 @@ TEST_F(BackToBackBeginFrameSourceTest, DelayInPostedTaskProducesCorrectFrame) { task_runner_->RunPendingTasks(); now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); - source_->DidFinishFrame(0); + source_->DidFinishFrame(obs_.get(), 0); now_src_->Advance(base::TimeDelta::FromMicroseconds(50)); EXPECT_BEGIN_FRAME_USED(*obs_, 1150, 1150 + kDeadline, kInterval); @@ -399,13 +369,72 @@ TEST_F(BackToBackBeginFrameSourceTest, DelayInPostedTaskProducesCorrectFrame) { task_runner_->RunPendingTasks(); } +TEST_F(BackToBackBeginFrameSourceTest, MultipleObserversSynchronized) { + StrictMock<MockBeginFrameObserver> obs1, obs2; + + EXPECT_BEGIN_FRAME_SOURCE_PAUSED(obs1, false); + source_->AddObserver(&obs1); + EXPECT_BEGIN_FRAME_SOURCE_PAUSED(obs2, false); + source_->AddObserver(&obs2); + + EXPECT_BEGIN_FRAME_USED(obs1, 1000, 1000 + kDeadline, kInterval); + EXPECT_BEGIN_FRAME_USED(obs2, 1000, 1000 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); + source_->DidFinishFrame(&obs1, 0); + source_->DidFinishFrame(&obs2, 0); + EXPECT_BEGIN_FRAME_USED(obs1, 1100, 1100 + kDeadline, kInterval); + EXPECT_BEGIN_FRAME_USED(obs2, 1100, 1100 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); + source_->DidFinishFrame(&obs1, 0); + source_->DidFinishFrame(&obs2, 0); + EXPECT_TRUE(task_runner_->HasPendingTasks()); + source_->RemoveObserver(&obs1); + source_->RemoveObserver(&obs2); + task_runner_->RunPendingTasks(); +} + +TEST_F(BackToBackBeginFrameSourceTest, MultipleObserversInterleaved) { + StrictMock<MockBeginFrameObserver> obs1, obs2; + + EXPECT_BEGIN_FRAME_SOURCE_PAUSED(obs1, false); + source_->AddObserver(&obs1); + EXPECT_BEGIN_FRAME_USED(obs1, 1000, 1000 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); + EXPECT_BEGIN_FRAME_SOURCE_PAUSED(obs2, false); + source_->AddObserver(&obs2); + EXPECT_BEGIN_FRAME_USED(obs2, 1100, 1100 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); + source_->DidFinishFrame(&obs1, 0); + EXPECT_BEGIN_FRAME_USED(obs1, 1200, 1200 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + source_->DidFinishFrame(&obs1, 0); + source_->RemoveObserver(&obs1); + + now_src_->Advance(base::TimeDelta::FromMicroseconds(100)); + source_->DidFinishFrame(&obs2, 0); + EXPECT_BEGIN_FRAME_USED(obs2, 1300, 1300 + kDeadline, kInterval); + task_runner_->RunPendingTasks(); + + source_->DidFinishFrame(&obs2, 0); + source_->RemoveObserver(&obs2); +} + // SyntheticBeginFrameSource testing ------------------------------------------ class SyntheticBeginFrameSourceTest : public ::testing::Test { public: - scoped_ptr<base::SimpleTestTickClock> now_src_; + std::unique_ptr<base::SimpleTestTickClock> now_src_; scoped_refptr<OrderedSimpleTaskRunner> task_runner_; - scoped_ptr<TestSyntheticBeginFrameSource> source_; - scoped_ptr<MockBeginFrameObserver> obs_; + std::unique_ptr<TestSyntheticBeginFrameSource> source_; + std::unique_ptr<MockBeginFrameObserver> obs_; void SetUp() override { now_src_.reset(new base::SimpleTestTickClock()); @@ -415,7 +444,7 @@ class SyntheticBeginFrameSourceTest : public ::testing::Test { source_.reset(new TestSyntheticBeginFrameSource( now_src_.get(), task_runner_.get(), base::TimeDelta::FromMicroseconds(10000))); - obs_ = make_scoped_ptr(new MockBeginFrameObserver()); + obs_ = base::WrapUnique(new MockBeginFrameObserver()); } void TearDown() override { obs_.reset(); } @@ -478,6 +507,33 @@ TEST_F(SyntheticBeginFrameSourceTest, VSyncChanges) { task_runner_->RunUntilTime(base::TimeTicks::FromInternalValue(60000)); } +TEST_F(SyntheticBeginFrameSourceTest, AuthoritativeVSyncChanges) { + task_runner_->SetAutoAdvanceNowToPendingTasks(true); + source_->OnUpdateVSyncParameters(base::TimeTicks::FromInternalValue(500), + base::TimeDelta::FromMicroseconds(10000)); + EXPECT_BEGIN_FRAME_SOURCE_PAUSED(*obs_, false); + EXPECT_BEGIN_FRAME_USED_MISSED(*obs_, 500, 10500, 10000); + source_->AddObserver(obs_.get()); + + EXPECT_BEGIN_FRAME_USED(*obs_, 10500, 20500, 10000); + EXPECT_BEGIN_FRAME_USED(*obs_, 20500, 30500, 10000); + task_runner_->RunUntilTime(base::TimeTicks::FromInternalValue(20501)); + + // This will keep the same timebase, so 500, 9999 + source_->SetAuthoritativeVSyncInterval( + base::TimeDelta::FromMicroseconds(9999)); + EXPECT_BEGIN_FRAME_USED(*obs_, 30500, 40496, 9999); + EXPECT_BEGIN_FRAME_USED(*obs_, 40496, 50495, 9999); + task_runner_->RunUntilTime(base::TimeTicks::FromInternalValue(40497)); + + // Change the vsync params, but the new interval will be ignored. + source_->OnUpdateVSyncParameters(base::TimeTicks::FromInternalValue(400), + base::TimeDelta::FromMicroseconds(1)); + EXPECT_BEGIN_FRAME_USED(*obs_, 50495, 60394, 9999); + EXPECT_BEGIN_FRAME_USED(*obs_, 60394, 70393, 9999); + task_runner_->RunUntilTime(base::TimeTicks::FromInternalValue(60395)); +} + TEST_F(SyntheticBeginFrameSourceTest, MultipleObservers) { StrictMock<MockBeginFrameObserver> obs1, obs2; diff --git a/chromium/cc/scheduler/begin_frame_tracker.cc b/chromium/cc/scheduler/begin_frame_tracker.cc index 20e2c39376d..dc18beaa4d3 100644 --- a/chromium/cc/scheduler/begin_frame_tracker.cc +++ b/chromium/cc/scheduler/begin_frame_tracker.cc @@ -23,7 +23,7 @@ void BeginFrameTracker::Start(BeginFrameArgs new_args) { new_args.frame_time.ToInternalValue(), location_string_); // Trace this specific begin frame tracker Start/Finish times. - TRACE_EVENT_ASYNC_BEGIN2( + TRACE_EVENT_COPY_ASYNC_BEGIN2( TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), location_string_.c_str(), new_args.frame_time.ToInternalValue(), "new args", new_args.AsValue(), "current args", current_args_.AsValue()); @@ -54,9 +54,9 @@ const BeginFrameArgs& BeginFrameTracker::Current() const { void BeginFrameTracker::Finish() { DCHECK(!HasFinished()) << "Tried to finish an already finished frame"; current_finished_at_ = base::TimeTicks::Now(); - TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), - location_string_.c_str(), - current_args_.frame_time.ToInternalValue()); + TRACE_EVENT_COPY_ASYNC_END0( + TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), + location_string_.c_str(), current_args_.frame_time.ToInternalValue()); } const BeginFrameArgs& BeginFrameTracker::Last() const { diff --git a/chromium/cc/scheduler/compositor_timing_history.cc b/chromium/cc/scheduler/compositor_timing_history.cc index 9d5a5844e5c..793ad101ec9 100644 --- a/chromium/cc/scheduler/compositor_timing_history.cc +++ b/chromium/cc/scheduler/compositor_timing_history.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <stdint.h> +#include "base/memory/ptr_util.h" #include "base/metrics/histogram.h" #include "base/trace_event/trace_event.h" #include "cc/debug/rendering_stats_instrumentation.h" @@ -381,21 +382,21 @@ CompositorTimingHistory::CompositorTimingHistory( CompositorTimingHistory::~CompositorTimingHistory() { } -scoped_ptr<CompositorTimingHistory::UMAReporter> +std::unique_ptr<CompositorTimingHistory::UMAReporter> CompositorTimingHistory::CreateUMAReporter(UMACategory category) { switch (category) { case RENDERER_UMA: - return make_scoped_ptr(new RendererUMAReporter); + return base::WrapUnique(new RendererUMAReporter); break; case BROWSER_UMA: - return make_scoped_ptr(new BrowserUMAReporter); + return base::WrapUnique(new BrowserUMAReporter); break; case NULL_UMA: - return make_scoped_ptr(new NullUMAReporter); + return base::WrapUnique(new NullUMAReporter); break; } NOTREACHED(); - return make_scoped_ptr<CompositorTimingHistory::UMAReporter>(nullptr); + return base::WrapUnique<CompositorTimingHistory::UMAReporter>(nullptr); } void CompositorTimingHistory::AsValueInto( diff --git a/chromium/cc/scheduler/compositor_timing_history.h b/chromium/cc/scheduler/compositor_timing_history.h index fc07c619ec5..d85078606a9 100644 --- a/chromium/cc/scheduler/compositor_timing_history.h +++ b/chromium/cc/scheduler/compositor_timing_history.h @@ -5,8 +5,9 @@ #ifndef CC_SCHEDULER_COMPOSITOR_TIMING_HISTORY_H_ #define CC_SCHEDULER_COMPOSITOR_TIMING_HISTORY_H_ +#include <memory> + #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "cc/base/rolling_time_delta_history.h" namespace base { @@ -85,7 +86,7 @@ class CC_EXPORT CompositorTimingHistory { bool ShouldReportUma() const; - static scoped_ptr<UMAReporter> CreateUMAReporter(UMACategory category); + static std::unique_ptr<UMAReporter> CreateUMAReporter(UMACategory category); virtual base::TimeTicks Now() const; bool using_synchronous_renderer_compositor_; @@ -125,7 +126,7 @@ class CC_EXPORT CompositorTimingHistory { base::TimeTicks draw_start_time_; base::TimeTicks swap_start_time_; - scoped_ptr<UMAReporter> uma_reporter_; + std::unique_ptr<UMAReporter> uma_reporter_; RenderingStatsInstrumentation* rendering_stats_instrumentation_; private: diff --git a/chromium/cc/scheduler/compositor_timing_history_unittest.cc b/chromium/cc/scheduler/compositor_timing_history_unittest.cc index f57d44340c5..8bbe93d999c 100644 --- a/chromium/cc/scheduler/compositor_timing_history_unittest.cc +++ b/chromium/cc/scheduler/compositor_timing_history_unittest.cc @@ -43,7 +43,7 @@ class CompositorTimingHistoryTest : public testing::Test { base::TimeTicks Now() { return now_; } protected: - scoped_ptr<RenderingStatsInstrumentation> rendering_stats_; + std::unique_ptr<RenderingStatsInstrumentation> rendering_stats_; TestCompositorTimingHistory timing_history_; base::TimeTicks now_; }; diff --git a/chromium/cc/scheduler/delay_based_time_source.h b/chromium/cc/scheduler/delay_based_time_source.h index 1be9d9b5a0e..be9e5c4b5d2 100644 --- a/chromium/cc/scheduler/delay_based_time_source.h +++ b/chromium/cc/scheduler/delay_based_time_source.h @@ -5,11 +5,12 @@ #ifndef CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ +#include <memory> #include <string> #include "base/cancelable_callback.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" +#include "base/memory/ptr_util.h" #include "base/memory/weak_ptr.h" #include "base/values.h" #include "cc/base/cc_export.h" @@ -35,10 +36,10 @@ class CC_EXPORT DelayBasedTimeSourceClient { // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. class CC_EXPORT DelayBasedTimeSource { public: - static scoped_ptr<DelayBasedTimeSource> Create( + static std::unique_ptr<DelayBasedTimeSource> Create( base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { - return make_scoped_ptr(new DelayBasedTimeSource(interval, task_runner)); + return base::WrapUnique(new DelayBasedTimeSource(interval, task_runner)); } virtual ~DelayBasedTimeSource(); diff --git a/chromium/cc/scheduler/delay_based_time_source_unittest.cc b/chromium/cc/scheduler/delay_based_time_source_unittest.cc index 0acee34efef..7a6d0876aad 100644 --- a/chromium/cc/scheduler/delay_based_time_source_unittest.cc +++ b/chromium/cc/scheduler/delay_based_time_source_unittest.cc @@ -22,7 +22,7 @@ TEST(DelayBasedTimeSourceTest, TaskPostedAndTickCalled) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); @@ -40,7 +40,7 @@ TEST(DelayBasedTimeSourceTest, TickNotCalledWithTaskPosted) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -54,7 +54,7 @@ TEST(DelayBasedTimeSourceTest, StartTwiceEnqueuesOneTask) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -68,7 +68,7 @@ TEST(DelayBasedTimeSourceTest, StartWhenRunningDoesntTick) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -85,7 +85,7 @@ TEST(DelayBasedTimeSourceTest, NextDelaySaneWhenExactlyOnRequestedTime) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -106,7 +106,7 @@ TEST(DelayBasedTimeSourceTest, NextDelaySaneWhenSlightlyAfterRequestedTime) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -129,7 +129,7 @@ TEST(DelayBasedTimeSourceTest, scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -151,7 +151,7 @@ TEST(DelayBasedTimeSourceTest, scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -173,7 +173,7 @@ TEST(DelayBasedTimeSourceTest, NextDelaySaneWhenHalfAfterRequestedTime) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -193,7 +193,7 @@ TEST(DelayBasedTimeSourceTest, JitteryRuntimeWithFutureTimebases) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -304,7 +304,7 @@ TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); @@ -329,7 +329,7 @@ TEST(DelayBasedTimeSourceTest, TestDeactivateWhilePending) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); timer->SetActive(true); // Should post a task. @@ -344,7 +344,7 @@ TEST(DelayBasedTimeSourceTest, TestDeactivateAndReactivateBeforeNextTickTime) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); @@ -369,7 +369,7 @@ TEST(DelayBasedTimeSourceTest, TestDeactivateAndReactivateAfterNextTickTime) { scoped_refptr<base::TestSimpleTaskRunner> task_runner = new base::TestSimpleTaskRunner; FakeDelayBasedTimeSourceClient client; - scoped_ptr<FakeDelayBasedTimeSource> timer = + std::unique_ptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); timer->SetClient(&client); diff --git a/chromium/cc/scheduler/scheduler.cc b/chromium/cc/scheduler/scheduler.cc index 3fb8b3b13de..6696c29afae 100644 --- a/chromium/cc/scheduler/scheduler.cc +++ b/chromium/cc/scheduler/scheduler.cc @@ -8,6 +8,7 @@ #include "base/auto_reset.h" #include "base/logging.h" +#include "base/memory/ptr_util.h" #include "base/profiler/scoped_tracker.h" #include "base/single_thread_task_runner.h" #include "base/trace_event/trace_event.h" @@ -26,16 +27,16 @@ const base::TimeDelta kDeadlineFudgeFactor = base::TimeDelta::FromMicroseconds(1000); } -scoped_ptr<Scheduler> Scheduler::Create( +std::unique_ptr<Scheduler> Scheduler::Create( SchedulerClient* client, const SchedulerSettings& settings, int layer_tree_host_id, base::SingleThreadTaskRunner* task_runner, BeginFrameSource* begin_frame_source, - scoped_ptr<CompositorTimingHistory> compositor_timing_history) { - return make_scoped_ptr(new Scheduler(client, settings, layer_tree_host_id, - task_runner, begin_frame_source, - std::move(compositor_timing_history))); + std::unique_ptr<CompositorTimingHistory> compositor_timing_history) { + return base::WrapUnique(new Scheduler(client, settings, layer_tree_host_id, + task_runner, begin_frame_source, + std::move(compositor_timing_history))); } Scheduler::Scheduler( @@ -44,7 +45,7 @@ Scheduler::Scheduler( int layer_tree_host_id, base::SingleThreadTaskRunner* task_runner, BeginFrameSource* begin_frame_source, - scoped_ptr<CompositorTimingHistory> compositor_timing_history) + std::unique_ptr<CompositorTimingHistory> compositor_timing_history) : settings_(settings), client_(client), layer_tree_host_id_(layer_tree_host_id), @@ -289,11 +290,6 @@ bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { BeginFrameArgs adjusted_args(args); adjusted_args.deadline -= EstimatedParentDrawTime(); - // Deliver BeginFrames to children. - // TODO(brianderson): Move this responsibility to the DisplayScheduler. - if (state_machine_.children_need_begin_frames()) - client_->SendBeginFramesToChildren(adjusted_args); - if (settings_.using_synchronous_renderer_compositor) { BeginImplFrameSynchronous(adjusted_args); return true; @@ -327,11 +323,6 @@ bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { return true; } -void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { - state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); - ProcessScheduledActions(); -} - void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); ProcessScheduledActions(); @@ -384,7 +375,7 @@ void Scheduler::BeginRetroFrame() { "BeginFrameArgs", begin_retro_frame_args_.front().AsValue()); begin_retro_frame_args_.pop_front(); if (begin_frame_source_) - begin_frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); + begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); } if (begin_retro_frame_args_.empty()) { @@ -478,15 +469,11 @@ void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", TRACE_EVENT_SCOPE_THREAD); if (begin_frame_source_) - begin_frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); + begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); return; } BeginImplFrame(adjusted_args); - - // The deadline will be scheduled in ProcessScheduledActions. - state_machine_.OnBeginImplFrameDeadlinePending(); - ProcessScheduledActions(); } void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { @@ -511,7 +498,7 @@ void Scheduler::FinishImplFrame() { client_->DidFinishImplFrame(); if (begin_frame_source_) - begin_frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); + begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); begin_impl_frame_tracker_.Finish(); } @@ -741,32 +728,16 @@ void Scheduler::ProcessScheduledActions() { SetupNextBeginFrameIfNeeded(); } -scoped_ptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() - const { - scoped_ptr<base::trace_event::TracedValue> state( +std::unique_ptr<base::trace_event::ConvertableToTraceFormat> +Scheduler::AsValue() const { + std::unique_ptr<base::trace_event::TracedValue> state( new base::trace_event::TracedValue()); - AsValueInto(state.get()); - return std::move(state); -} - -void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { base::TimeTicks now = Now(); state->BeginDictionary("state_machine"); - state_machine_.AsValueInto(state); + state_machine_.AsValueInto(state.get()); state->EndDictionary(); - // Only trace frame sources when explicitly enabled - http://crbug.com/420607 - bool frame_tracing_enabled = false; - TRACE_EVENT_CATEGORY_GROUP_ENABLED( - TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), - &frame_tracing_enabled); - if (frame_tracing_enabled && begin_frame_source_) { - state->BeginDictionary("begin_frame_source_"); - begin_frame_source_->AsValueInto(state); - state->EndDictionary(); - } - state->BeginDictionary("scheduler_state"); state->SetBoolean("throttle_frame_production_", settings_.throttle_frame_production); @@ -784,7 +755,7 @@ void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { SchedulerStateMachine::ActionToString(inside_action_)); state->BeginDictionary("begin_impl_frame_args"); - begin_impl_frame_tracker_.AsValueInto(now, state); + begin_impl_frame_tracker_.AsValueInto(now, state.get()); state->EndDictionary(); state->SetString("begin_impl_frame_deadline_mode_", @@ -793,8 +764,10 @@ void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { state->EndDictionary(); state->BeginDictionary("compositor_timing_history"); - compositor_timing_history_->AsValueInto(state); + compositor_timing_history_->AsValueInto(state.get()); state->EndDictionary(); + + return std::move(state); } void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { diff --git a/chromium/cc/scheduler/scheduler.h b/chromium/cc/scheduler/scheduler.h index 6672de44352..017307eb5f9 100644 --- a/chromium/cc/scheduler/scheduler.h +++ b/chromium/cc/scheduler/scheduler.h @@ -6,11 +6,11 @@ #define CC_SCHEDULER_SCHEDULER_H_ #include <deque> +#include <memory> #include <string> #include "base/cancelable_callback.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/time/time.h" #include "cc/base/cc_export.h" #include "cc/output/begin_frame_args.h" @@ -46,7 +46,6 @@ class SchedulerClient { virtual void ScheduledActionPrepareTiles() = 0; virtual void ScheduledActionInvalidateOutputSurface() = 0; virtual void DidFinishImplFrame() = 0; - virtual void SendBeginFramesToChildren(const BeginFrameArgs& args) = 0; virtual void SendBeginMainFrameNotExpectedSoon() = 0; protected: @@ -55,13 +54,13 @@ class SchedulerClient { class CC_EXPORT Scheduler : public BeginFrameObserverBase { public: - static scoped_ptr<Scheduler> Create( + static std::unique_ptr<Scheduler> Create( SchedulerClient* client, const SchedulerSettings& scheduler_settings, int layer_tree_host_id, base::SingleThreadTaskRunner* task_runner, BeginFrameSource* begin_frame_source, - scoped_ptr<CompositorTimingHistory> compositor_timing_history); + std::unique_ptr<CompositorTimingHistory> compositor_timing_history); ~Scheduler() override; @@ -135,10 +134,8 @@ class CC_EXPORT Scheduler : public BeginFrameObserverBase { void SetDeferCommits(bool defer_commits); - scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; - void AsValueInto(base::trace_event::TracedValue* value) const override; + std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; - void SetChildrenNeedBeginFrames(bool children_need_begin_frames); void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); const BeginFrameSource* begin_frame_source() const { @@ -151,7 +148,7 @@ class CC_EXPORT Scheduler : public BeginFrameObserverBase { int layer_tree_host_id, base::SingleThreadTaskRunner* task_runner, BeginFrameSource* begin_frame_source, - scoped_ptr<CompositorTimingHistory> compositor_timing_history); + std::unique_ptr<CompositorTimingHistory> compositor_timing_history); // Virtual for testing. virtual base::TimeTicks Now() const; @@ -166,7 +163,7 @@ class CC_EXPORT Scheduler : public BeginFrameObserverBase { BeginFrameSource* begin_frame_source_; bool observing_begin_frame_source_; - scoped_ptr<CompositorTimingHistory> compositor_timing_history_; + std::unique_ptr<CompositorTimingHistory> compositor_timing_history_; base::TimeDelta estimated_parent_draw_time_; std::deque<BeginFrameArgs> begin_retro_frame_args_; diff --git a/chromium/cc/scheduler/scheduler_settings.cc b/chromium/cc/scheduler/scheduler_settings.cc index 79576acc1a4..6f174fa1ba9 100644 --- a/chromium/cc/scheduler/scheduler_settings.cc +++ b/chromium/cc/scheduler/scheduler_settings.cc @@ -24,9 +24,9 @@ SchedulerSettings::SchedulerSettings(const SchedulerSettings& other) = default; SchedulerSettings::~SchedulerSettings() {} -scoped_ptr<base::trace_event::ConvertableToTraceFormat> +std::unique_ptr<base::trace_event::ConvertableToTraceFormat> SchedulerSettings::AsValue() const { - scoped_ptr<base::trace_event::TracedValue> state( + std::unique_ptr<base::trace_event::TracedValue> state( new base::trace_event::TracedValue()); state->SetBoolean("use_external_begin_frame_source", use_external_begin_frame_source); diff --git a/chromium/cc/scheduler/scheduler_settings.h b/chromium/cc/scheduler/scheduler_settings.h index 2f07b30ad54..bc047179444 100644 --- a/chromium/cc/scheduler/scheduler_settings.h +++ b/chromium/cc/scheduler/scheduler_settings.h @@ -5,8 +5,9 @@ #ifndef CC_SCHEDULER_SCHEDULER_SETTINGS_H_ #define CC_SCHEDULER_SCHEDULER_SETTINGS_H_ +#include <memory> + #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "base/time/time.h" #include "base/values.h" #include "cc/base/cc_export.h" @@ -37,7 +38,7 @@ class CC_EXPORT SchedulerSettings { int maximum_number_of_failed_draws_before_draw_is_forced; base::TimeDelta background_frame_interval; - scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; + std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; }; } // namespace cc diff --git a/chromium/cc/scheduler/scheduler_state_machine.cc b/chromium/cc/scheduler/scheduler_state_machine.cc index 266f8870b56..438447cdfdd 100644 --- a/chromium/cc/scheduler/scheduler_state_machine.cc +++ b/chromium/cc/scheduler/scheduler_state_machine.cc @@ -55,7 +55,6 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) critical_begin_main_frame_to_activate_is_fast_(true), main_thread_missed_last_deadline_(false), skip_next_begin_main_frame_to_reduce_latency_(false), - children_need_begin_frames_(false), defer_commits_(false), video_needs_begin_frames_(false), last_commit_had_no_updates_(false), @@ -86,8 +85,6 @@ const char* SchedulerStateMachine::BeginImplFrameStateToString( switch (state) { case BEGIN_IMPL_FRAME_STATE_IDLE: return "BEGIN_IMPL_FRAME_STATE_IDLE"; - case BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING: - return "BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING"; case BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME: return "BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME"; case BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE: @@ -189,9 +186,9 @@ const char* SchedulerStateMachine::ActionToString(Action action) { return "???"; } -scoped_ptr<base::trace_event::ConvertableToTraceFormat> +std::unique_ptr<base::trace_event::ConvertableToTraceFormat> SchedulerStateMachine::AsValue() const { - scoped_ptr<base::trace_event::TracedValue> state( + std::unique_ptr<base::trace_event::TracedValue> state( new base::trace_event::TracedValue()); AsValueInto(state.get()); return std::move(state); @@ -256,7 +253,6 @@ void SchedulerStateMachine::AsValueInto( main_thread_missed_last_deadline_); state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", skip_next_begin_main_frame_to_reduce_latency_); - state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); state->SetBoolean("defer_commits", defer_commits_); state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); @@ -415,18 +411,6 @@ bool SchedulerStateMachine::CouldSendBeginMainFrame() const { return true; } -bool SchedulerStateMachine::SendingBeginMainFrameMightCauseDeadlock() const { - // NPAPI is the only case where the UI thread makes synchronous calls to the - // Renderer main thread. During that synchronous call, we may not get a - // SwapAck for the UI thread, which may prevent BeginMainFrame's from - // completing if there's enough back pressure. If the BeginMainFrame can't - // make progress, the Renderer can't service the UI thread's synchronous call - // and we have deadlock. - // This returns true if there's too much backpressure to finish a commit - // if we were to initiate a BeginMainFrame. - return has_pending_tree_ && active_tree_needs_first_draw_ && SwapThrottled(); -} - bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { if (!CouldSendBeginMainFrame()) return false; @@ -463,9 +447,6 @@ bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { // We need a new commit for the forced redraw. This honors the // single commit per interval because the result will be swapped to screen. - // TODO(brianderson): Remove this or move it below the - // SendingBeginMainFrameMightCauseDeadlock check since we want to avoid - // ever returning true from this method if we might cause deadlock. if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) return true; @@ -473,10 +454,6 @@ bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { if (!HasInitializedOutputSurface()) return false; - // Make sure the BeginMainFrame can finish eventually if we start it. - if (SendingBeginMainFrameMightCauseDeadlock()) - return false; - if (!settings_.main_frame_while_swap_throttled_enabled) { // SwapAck throttle the BeginMainFrames unless we just swapped to // potentially improve impl-thread latency over main-thread throughput. @@ -537,7 +514,7 @@ bool SchedulerStateMachine::ShouldInvalidateOutputSurface() const { return false; // Invalidations are only performed inside a BeginFrame. - if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) + if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) return false; // TODO(sunnyps): needs_prepare_tiles_ is needed here because PrepareTiles is @@ -582,7 +559,11 @@ void SchedulerStateMachine::WillSendBeginMainFrame() { } void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { + DCHECK(!has_pending_tree_ || + (settings_.main_frame_before_activation_enabled && + commit_has_no_updates)); commit_count_++; + last_commit_had_no_updates_ = commit_has_no_updates; if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; @@ -590,11 +571,12 @@ void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION; } - // If the commit was aborted, then there is no pending tree. - has_pending_tree_ = !commit_has_no_updates; - - wait_for_ready_to_draw_ = - !commit_has_no_updates && settings_.commit_to_active_tree; + if (!commit_has_no_updates) { + // Pending tree only exists if commit had updates. + has_pending_tree_ = true; + pending_tree_is_ready_for_activation_ = false; + wait_for_ready_to_draw_ = settings_.commit_to_active_tree; + } // Update state related to forced draws. if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { @@ -604,27 +586,11 @@ void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { } // Update the output surface state. - DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { - if (has_pending_tree_) { - output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; - } else { - output_surface_state_ = OUTPUT_SURFACE_ACTIVE; - } - } - - // Update state if there's no updates heading for the active tree, but we need - // to do a forced draw. - if (commit_has_no_updates && - forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { - DCHECK(!has_pending_tree_); - needs_redraw_ = true; + output_surface_state_ = has_pending_tree_ + ? OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION + : OUTPUT_SURFACE_ACTIVE; } - - // This post-commit work is common to both completed and aborted commits. - pending_tree_is_ready_for_activation_ = false; - - last_commit_had_no_updates_ = commit_has_no_updates; } void SchedulerStateMachine::WillActivate() { @@ -765,10 +731,6 @@ void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { skip_next_begin_main_frame_to_reduce_latency_ = true; } -bool SchedulerStateMachine::BeginFrameRequiredForChildren() const { - return children_need_begin_frames_; -} - bool SchedulerStateMachine::BeginFrameNeededForVideo() const { return video_needs_begin_frames_; } @@ -783,13 +745,8 @@ bool SchedulerStateMachine::BeginFrameNeeded() const { if (!visible_) return false; - return (BeginFrameRequiredForAction() || BeginFrameRequiredForChildren() || - BeginFrameNeededForVideo() || ProactiveBeginFrameWanted()); -} - -void SchedulerStateMachine::SetChildrenNeedBeginFrames( - bool children_need_begin_frames) { - children_need_begin_frames_ = children_need_begin_frames; + return BeginFrameRequiredForAction() || BeginFrameNeededForVideo() || + ProactiveBeginFrameWanted(); } void SchedulerStateMachine::SetVideoNeedsBeginFrames( @@ -860,7 +817,7 @@ bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { } void SchedulerStateMachine::OnBeginImplFrame() { - begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; + begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; current_frame_number_++; last_commit_had_no_updates_ = false; @@ -877,10 +834,6 @@ void SchedulerStateMachine::OnBeginImplFrame() { prepare_tiles_funnel_--; } -void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { - begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; -} - void SchedulerStateMachine::OnBeginImplFrameDeadline() { begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; diff --git a/chromium/cc/scheduler/scheduler_state_machine.h b/chromium/cc/scheduler/scheduler_state_machine.h index f1872fe62d0..e89edddd6ec 100644 --- a/chromium/cc/scheduler/scheduler_state_machine.h +++ b/chromium/cc/scheduler/scheduler_state_machine.h @@ -5,10 +5,10 @@ #ifndef CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ #define CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ +#include <memory> #include <string> #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/output/begin_frame_args.h" #include "cc/scheduler/commit_earlyout_reason.h" @@ -59,11 +59,8 @@ class CC_EXPORT SchedulerStateMachine { // Note: BeginImplFrameState does not cycle through these states in a fixed // order on all platforms. It's up to the scheduler to set these correctly. - // TODO(sunnyps): Rename the states to IDLE, ANIMATE, WAITING_FOR_DEADLINE and - // DRAW. enum BeginImplFrameState { BEGIN_IMPL_FRAME_STATE_IDLE, - BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; @@ -129,7 +126,7 @@ class CC_EXPORT SchedulerStateMachine { }; static const char* ActionToString(Action action); - scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; + std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; void AsValueInto(base::trace_event::TracedValue* dict) const; Action NextAction() const; @@ -153,7 +150,6 @@ class CC_EXPORT SchedulerStateMachine { // The scheduler will not draw more than once in a given BeginImplFrame // callback nor send more than one BeginMainFrame message. void OnBeginImplFrame(); - void OnBeginImplFrameDeadlinePending(); // Indicates that the scheduler has entered the draw phase. The scheduler // will not draw more than once in a single draw phase. // TODO(sunnyps): Rename OnBeginImplFrameDeadline to OnDraw or similar. @@ -272,17 +268,11 @@ class CC_EXPORT SchedulerStateMachine { void SetDeferCommits(bool defer_commits); - void SetChildrenNeedBeginFrames(bool children_need_begin_frames); - bool children_need_begin_frames() const { - return children_need_begin_frames_; - } - void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); bool video_needs_begin_frames() const { return video_needs_begin_frames_; } protected: bool BeginFrameRequiredForAction() const; - bool BeginFrameRequiredForChildren() const; bool BeginFrameNeededForVideo() const; bool ProactiveBeginFrameWanted() const; @@ -292,9 +282,6 @@ class CC_EXPORT SchedulerStateMachine { // TODO(sunnyps): Rename this to ShouldAbortCurrentFrame or similar. bool PendingActivationsShouldBeForced() const; - // TODO(brianderson): Remove this once NPAPI support is removed. - bool SendingBeginMainFrameMightCauseDeadlock() const; - bool ShouldBeginOutputSurfaceCreation() const; bool ShouldDraw() const; bool ShouldActivatePendingTree() const; @@ -353,7 +340,6 @@ class CC_EXPORT SchedulerStateMachine { bool critical_begin_main_frame_to_activate_is_fast_; bool main_thread_missed_last_deadline_; bool skip_next_begin_main_frame_to_reduce_latency_; - bool children_need_begin_frames_; bool defer_commits_; bool video_needs_begin_frames_; bool last_commit_had_no_updates_; diff --git a/chromium/cc/scheduler/scheduler_state_machine_unittest.cc b/chromium/cc/scheduler/scheduler_state_machine_unittest.cc index ee88bfc1efd..8f86c3d213e 100644 --- a/chromium/cc/scheduler/scheduler_state_machine_unittest.cc +++ b/chromium/cc/scheduler/scheduler_state_machine_unittest.cc @@ -45,9 +45,6 @@ PerformAction(&state, action); \ if (action == SchedulerStateMachine::ACTION_NONE) { \ if (state.begin_impl_frame_state() == \ - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ - state.OnBeginImplFrameDeadlinePending(); \ - if (state.begin_impl_frame_state() == \ SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ state.OnBeginImplFrameIdle(); \ } @@ -66,7 +63,6 @@ namespace { const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; @@ -149,6 +145,7 @@ class StateMachine : public SchedulerStateMachine { return SchedulerStateMachine::PendingActivationsShouldBeForced(); } + bool has_pending_tree() const { return has_pending_tree_; } void SetHasPendingTree(bool has_pending_tree) { has_pending_tree_ = has_pending_tree; } @@ -426,8 +423,6 @@ TEST(SchedulerStateMachineTest, // Start a frame. state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); EXPECT_FALSE(state.CommitPending()); // Failing a draw triggers request for a new BeginMainFrame. @@ -447,8 +442,6 @@ TEST(SchedulerStateMachineTest, EXPECT_TRUE(state.RedrawPending()); state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameDeadline(); state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); EXPECT_ACTION_UPDATE_STATE( @@ -469,8 +462,6 @@ TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { // Start a frame. state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); EXPECT_FALSE(state.CommitPending()); // Failing a draw triggers because of high res tiles missing @@ -490,8 +481,6 @@ TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { EXPECT_FALSE(state.RedrawPending()); state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameDeadline(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameIdle(); @@ -510,8 +499,6 @@ TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { // Verify we draw with the new frame. state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameDeadline(); state.SetDrawResultForTest(DRAW_SUCCESS); EXPECT_ACTION_UPDATE_STATE( @@ -606,8 +593,6 @@ TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { state.SetNeedsRedraw(true); state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameDeadline(); state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); EXPECT_ACTION_UPDATE_STATE( @@ -624,25 +609,12 @@ TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { EXPECT_TRUE(state.ForcedRedrawState() == SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); - state.NotifyBeginMainFrameStarted(); - state.NotifyReadyToCommit(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - EXPECT_TRUE(state.RedrawPending()); - EXPECT_FALSE(state.CommitPending()); - - // Now force redraw should be in waiting for activation - EXPECT_TRUE(state.ForcedRedrawState() == - SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION); - // After failing additional draws, we should still be in a forced - // redraw, but not back in WAITING_FOR_COMMIT. + // redraw, but not back in IDLE. for (int i = 0; i < draw_limit; ++i) { state.SetNeedsRedraw(true); state.OnBeginImplFrame(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); - state.OnBeginImplFrameDeadlinePending(); - EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); state.OnBeginImplFrameDeadline(); state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); EXPECT_ACTION_UPDATE_STATE( @@ -653,7 +625,7 @@ TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { } EXPECT_TRUE(state.RedrawPending()); EXPECT_TRUE(state.ForcedRedrawState() == - SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION); + SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); } TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { @@ -922,11 +894,6 @@ TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { // Expect to commit regardless of BeginImplFrame state. EXPECT_IMPL_FRAME_STATE( - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING); - EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); - - state.OnBeginImplFrameDeadlinePending(); - EXPECT_IMPL_FRAME_STATE( SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); @@ -941,7 +908,7 @@ TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { state.OnBeginImplFrame(); EXPECT_IMPL_FRAME_STATE( - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING); + SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); // Finish the commit and activate, then make sure we start the next commit @@ -1043,6 +1010,7 @@ TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) { SchedulerSettings scheduler_settings; scheduler_settings.commit_to_active_tree = true; + scheduler_settings.main_frame_before_activation_enabled = false; StateMachine state(scheduler_settings); SET_UP_STATE(state) @@ -1066,9 +1034,65 @@ TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) { EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); } +TEST(SchedulerStateMachineTest, AbortedMainFrameDoesNotResetPendingTree) { + SchedulerSettings scheduler_settings; + scheduler_settings.main_frame_before_activation_enabled = true; + StateMachine state(scheduler_settings); + SET_UP_STATE(state); + + // Perform a commit so that we have an active tree. + state.SetNeedsBeginMainFrame(); + state.OnBeginImplFrame(); + EXPECT_ACTION_UPDATE_STATE( + SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + state.NotifyBeginMainFrameStarted(); + state.NotifyReadyToCommit(); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + EXPECT_TRUE(state.has_pending_tree()); + state.OnBeginImplFrameDeadline(); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + + // Ask for another commit but abort it. Verify that we didn't reset pending + // tree state. + state.SetNeedsBeginMainFrame(); + state.OnBeginImplFrame(); + EXPECT_ACTION_UPDATE_STATE( + SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + EXPECT_TRUE(state.has_pending_tree()); + state.NotifyBeginMainFrameStarted(); + state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + EXPECT_TRUE(state.has_pending_tree()); + state.OnBeginImplFrameDeadline(); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + + // Ask for another commit that doesn't abort. + state.SetNeedsBeginMainFrame(); + state.OnBeginImplFrame(); + EXPECT_ACTION_UPDATE_STATE( + SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + state.NotifyBeginMainFrameStarted(); + state.NotifyReadyToCommit(); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + EXPECT_TRUE(state.has_pending_tree()); + + // Verify that commit is delayed until the pending tree is activated. + state.NotifyReadyToActivate(); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); + EXPECT_FALSE(state.has_pending_tree()); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); + EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); + EXPECT_TRUE(state.has_pending_tree()); +} + TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) { SchedulerSettings scheduler_settings; scheduler_settings.commit_to_active_tree = true; + scheduler_settings.main_frame_before_activation_enabled = false; StateMachine state(scheduler_settings); SET_UP_STATE(state) @@ -1562,11 +1586,6 @@ TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { state.OnBeginImplFrame(); EXPECT_IMPL_FRAME_STATE( - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING); - EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); - - state.OnBeginImplFrameDeadlinePending(); - EXPECT_IMPL_FRAME_STATE( SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); @@ -1624,11 +1643,6 @@ TEST(SchedulerStateMachineTest, state.OnBeginImplFrame(); EXPECT_IMPL_FRAME_STATE( - SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING); - EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); - - state.OnBeginImplFrameDeadlinePending(); - EXPECT_IMPL_FRAME_STATE( SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); @@ -2060,16 +2074,6 @@ TEST(SchedulerStateMachineTest, EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); } -TEST(SchedulerStateMachineTest, TestForwardBeginFramesToChildren) { - SchedulerSettings settings; - StateMachine state(settings); - SET_UP_STATE(state) - - EXPECT_FALSE(state.BeginFrameNeeded()); - state.SetChildrenNeedBeginFrames(true); - EXPECT_TRUE(state.BeginFrameNeeded()); -} - TEST(SchedulerStateMachineTest, TestDeferCommit) { SchedulerSettings settings; StateMachine state(settings); @@ -2125,7 +2129,6 @@ TEST(SchedulerStateMachineTest, NoOutputSurfaceCreationWhileCommitPending) { // Trigger the deadline and ensure that the scheduler does not trigger any // actions until we receive a response for the pending commit. - state.OnBeginImplFrameDeadlinePending(); state.OnBeginImplFrameDeadline(); state.OnBeginImplFrameIdle(); EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); @@ -2161,7 +2164,6 @@ TEST(SchedulerStateMachineTest, OutputSurfaceCreationWhileCommitPending) { EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); // Cycle through the frame stages to clear the scheduler state. - state.OnBeginImplFrameDeadlinePending(); state.OnBeginImplFrameDeadline(); state.OnBeginImplFrameIdle(); diff --git a/chromium/cc/scheduler/scheduler_unittest.cc b/chromium/cc/scheduler/scheduler_unittest.cc index 75652c793cb..751c9649e49 100644 --- a/chromium/cc/scheduler/scheduler_unittest.cc +++ b/chromium/cc/scheduler/scheduler_unittest.cc @@ -10,6 +10,7 @@ #include <vector> #include "base/logging.h" +#include "base/memory/ptr_util.h" #include "base/message_loop/message_loop.h" #include "base/numerics/safe_conversions.h" #include "base/run_loop.h" @@ -66,7 +67,6 @@ class FakeSchedulerClient : public SchedulerClient { draw_will_happen_ = true; swap_will_happen_if_draw_happens_ = true; num_draws_ = 0; - begin_frame_args_sent_to_children_ = BeginFrameArgs(); last_begin_main_frame_args_ = BeginFrameArgs(); } @@ -165,10 +165,6 @@ class FakeSchedulerClient : public SchedulerClient { states_.push_back(scheduler_->AsValue()); } - void SendBeginFramesToChildren(const BeginFrameArgs& args) override { - begin_frame_args_sent_to_children_ = args; - } - void SendBeginMainFrameNotExpectedSoon() override { PushAction("SendBeginMainFrameNotExpectedSoon"); } @@ -179,14 +175,6 @@ class FakeSchedulerClient : public SchedulerClient { state); } - bool begin_frame_is_sent_to_children() const { - return begin_frame_args_sent_to_children_.IsValid(); - } - - const BeginFrameArgs& begin_frame_args_sent_to_children() const { - return begin_frame_args_sent_to_children_; - } - void PushAction(const char* description) { actions_.push_back(description); states_.push_back(scheduler_->AsValue()); @@ -203,11 +191,11 @@ class FakeSchedulerClient : public SchedulerClient { bool swap_will_happen_if_draw_happens_; bool automatic_swap_ack_; int num_draws_; - BeginFrameArgs begin_frame_args_sent_to_children_; BeginFrameArgs last_begin_main_frame_args_; base::TimeTicks posted_begin_impl_frame_deadline_; std::vector<const char*> actions_; - std::vector<scoped_ptr<base::trace_event::ConvertableToTraceFormat>> states_; + std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> + states_; TestScheduler* scheduler_; }; @@ -271,8 +259,8 @@ class SchedulerTest : public testing::Test { frame_source = synthetic_frame_source_.get(); } - scoped_ptr<FakeCompositorTimingHistory> fake_compositor_timing_history = - FakeCompositorTimingHistory::Create( + std::unique_ptr<FakeCompositorTimingHistory> + fake_compositor_timing_history = FakeCompositorTimingHistory::Create( scheduler_settings_.using_synchronous_renderer_compositor); fake_compositor_timing_history_ = fake_compositor_timing_history.get(); @@ -295,10 +283,10 @@ class SchedulerTest : public testing::Test { } void SetUpScheduler(bool initSurface) { - SetUpScheduler(make_scoped_ptr(new FakeSchedulerClient), initSurface); + SetUpScheduler(base::WrapUnique(new FakeSchedulerClient), initSurface); } - void SetUpScheduler(scoped_ptr<FakeSchedulerClient> client, + void SetUpScheduler(std::unique_ptr<FakeSchedulerClient> client, bool initSurface) { client_ = std::move(client); if (initSurface) @@ -437,14 +425,15 @@ class SchedulerTest : public testing::Test { ScrollHandlerState scroll_handler_state, base::TimeDelta durations); - scoped_ptr<base::SimpleTestTickClock> now_src_; + std::unique_ptr<base::SimpleTestTickClock> now_src_; scoped_refptr<OrderedSimpleTaskRunner> task_runner_; - scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source_; - scoped_ptr<TestSyntheticBeginFrameSource> synthetic_frame_source_; - scoped_ptr<TestBackToBackBeginFrameSource> unthrottled_frame_source_; + std::unique_ptr<FakeExternalBeginFrameSource> + fake_external_begin_frame_source_; + std::unique_ptr<TestSyntheticBeginFrameSource> synthetic_frame_source_; + std::unique_ptr<TestBackToBackBeginFrameSource> unthrottled_frame_source_; SchedulerSettings scheduler_settings_; - scoped_ptr<FakeSchedulerClient> client_; - scoped_ptr<TestScheduler> scheduler_; + std::unique_ptr<FakeSchedulerClient> client_; + std::unique_ptr<TestScheduler> scheduler_; FakeCompositorTimingHistory* fake_compositor_timing_history_; }; @@ -460,69 +449,6 @@ TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { EXPECT_NO_ACTION(client_); } -TEST_F(SchedulerTest, SendBeginFramesToChildren) { - scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(true); - - EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); - scheduler_->SetNeedsBeginMainFrame(); - EXPECT_SINGLE_ACTION("AddObserver(this)", client_); - EXPECT_TRUE(scheduler_->begin_frames_expected()); - - scheduler_->SetChildrenNeedBeginFrames(true); - - client_->Reset(); - EXPECT_SCOPED(AdvanceFrame()); - EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); - EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); - EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); - EXPECT_TRUE(scheduler_->begin_frames_expected()); -} - -TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { - scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(true); - - EXPECT_FALSE(scheduler_->begin_frames_expected()); - scheduler_->SetChildrenNeedBeginFrames(true); - EXPECT_SINGLE_ACTION("AddObserver(this)", client_); - EXPECT_TRUE(scheduler_->begin_frames_expected()); - - client_->Reset(); - EXPECT_SCOPED(AdvanceFrame()); - EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); -} - -TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { - // Set up client with specified estimates. - scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(true); - - fake_compositor_timing_history_ - ->SetBeginMainFrameStartToCommitDurationEstimate( - base::TimeDelta::FromMilliseconds(2)); - fake_compositor_timing_history_->SetCommitToReadyToActivateDurationEstimate( - base::TimeDelta::FromMilliseconds(4)); - fake_compositor_timing_history_->SetDrawDurationEstimate( - base::TimeDelta::FromMilliseconds(1)); - - EXPECT_FALSE(scheduler_->begin_frames_expected()); - scheduler_->SetChildrenNeedBeginFrames(true); - EXPECT_SINGLE_ACTION("AddObserver(this)", client_); - EXPECT_TRUE(scheduler_->begin_frames_expected()); - - client_->Reset(); - - BeginFrameArgs frame_args = - CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); - fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); - - EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); - EXPECT_EQ(client_->begin_frame_args_sent_to_children().deadline, - frame_args.deadline); -} - TEST_F(SchedulerTest, VideoNeedsBeginFrames) { scheduler_settings_.use_external_begin_frame_source = true; SetUpScheduler(true); @@ -784,7 +710,7 @@ TEST_F(SchedulerTest, RequestRedrawInsideDraw) { SchedulerClientThatsetNeedsDrawInsideDraw* client = new SchedulerClientThatsetNeedsDrawInsideDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); client->SetRequestRedrawsInsideDraw(true); scheduler_->SetNeedsRedraw(); @@ -820,7 +746,7 @@ TEST_F(SchedulerTest, RequestRedrawInsideFailedDraw) { SchedulerClientThatsetNeedsDrawInsideDraw* client = new SchedulerClientThatsetNeedsDrawInsideDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); client->SetRequestRedrawsInsideDraw(true); client->SetDrawWillHappen(false); @@ -896,7 +822,7 @@ TEST_F(SchedulerTest, RequestCommitInsideDraw) { new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); EXPECT_FALSE(client->needs_begin_frames()); scheduler_->SetNeedsRedraw(); @@ -938,7 +864,7 @@ TEST_F(SchedulerTest, RequestCommitInsideFailedDraw) { SchedulerClientThatsetNeedsDrawInsideDraw* client = new SchedulerClientThatsetNeedsDrawInsideDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); client->SetDrawWillHappen(false); @@ -981,7 +907,7 @@ TEST_F(SchedulerTest, NoSwapWhenDrawFails) { SchedulerClientThatSetNeedsBeginMainFrameInsideDraw* client = new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); scheduler_->SetNeedsRedraw(); EXPECT_TRUE(scheduler_->RedrawPending()); @@ -1019,7 +945,7 @@ TEST_F(SchedulerTest, PrepareTiles) { SchedulerClientNeedsPrepareTilesInDraw* client = new SchedulerClientNeedsPrepareTilesInDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); // Request both draw and prepare tiles. PrepareTiles shouldn't // be trigged until BeginImplFrame. @@ -1229,8 +1155,8 @@ TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { } TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { - scoped_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = - make_scoped_ptr(new SchedulerClientNeedsPrepareTilesInDraw); + std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = + base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); scheduler_settings_.use_external_begin_frame_source = true; SetUpScheduler(std::move(client), true); @@ -1265,7 +1191,7 @@ TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { SchedulerClientNeedsPrepareTilesInDraw* client = new SchedulerClientNeedsPrepareTilesInDraw; scheduler_settings_.use_external_begin_frame_source = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); scheduler_->SetNeedsRedraw(); EXPECT_SCOPED(AdvanceFrame()); @@ -1280,7 +1206,7 @@ TEST_F(SchedulerTest, WaitForReadyToDrawDoNotPostDeadline) { new SchedulerClientNeedsPrepareTilesInDraw; scheduler_settings_.use_external_begin_frame_source = true; scheduler_settings_.commit_to_active_tree = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. scheduler_->SetNeedsBeginMainFrame(); @@ -1320,7 +1246,7 @@ TEST_F(SchedulerTest, WaitForReadyToDrawCancelledWhenLostOutputSurface) { new SchedulerClientNeedsPrepareTilesInDraw; scheduler_settings_.use_external_begin_frame_source = true; scheduler_settings_.commit_to_active_tree = true; - SetUpScheduler(make_scoped_ptr(client), true); + SetUpScheduler(base::WrapUnique(client), true); // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. scheduler_->SetNeedsBeginMainFrame(); @@ -2053,84 +1979,6 @@ TEST_F( EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); } -TEST_F(SchedulerTest, - Deadlock_NoBeginMainFrameWhileSwapTrottledAndPipelineFull) { - // NPAPI plugins on Windows block the Browser UI thread on the Renderer main - // thread. This prevents the scheduler from receiving any pending swap acks. - - // This particular test makes sure we do not send a BeginMainFrame while - // swap trottled and we have a pending tree and active tree that - // still needs to be drawn for the first time. - - scheduler_settings_.use_external_begin_frame_source = true; - scheduler_settings_.main_frame_while_swap_throttled_enabled = true; - scheduler_settings_.main_frame_before_activation_enabled = true; - SetUpScheduler(true); - - // Disables automatic swap acks so this test can force swap ack throttling - // to simulate a blocked Browser ui thread. - client_->SetAutomaticSwapAck(false); - - // Start a new commit in main-thread high latency mode and hold off on - // activation. - client_->Reset(); - EXPECT_FALSE(scheduler_->CommitPending()); - scheduler_->SetNeedsBeginMainFrame(); - scheduler_->SetNeedsRedraw(); - EXPECT_SCOPED(AdvanceFrame()); - EXPECT_TRUE(scheduler_->CommitPending()); - EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); - task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); - EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); - scheduler_->DidSwapBuffersComplete(); - scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); - scheduler_->NotifyReadyToCommit(); - EXPECT_FALSE(scheduler_->CommitPending()); - EXPECT_ACTION("AddObserver(this)", client_, 0, 5); - EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); - EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 5); - EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); - - // Start another commit while we still have aa pending tree. - // Enter a swap throttled state. - client_->Reset(); - EXPECT_FALSE(scheduler_->CommitPending()); - scheduler_->SetNeedsBeginMainFrame(); - scheduler_->SetNeedsRedraw(); - EXPECT_SCOPED(AdvanceFrame()); - EXPECT_TRUE(scheduler_->CommitPending()); - EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); - task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); - EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); - scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); - EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); - EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); - EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); - - // Can't commit yet because there's still a pending tree. - client_->Reset(); - scheduler_->NotifyReadyToCommit(); - EXPECT_NO_ACTION(client_); - - // Activate the pending tree, which also unblocks the commit immediately. - client_->Reset(); - scheduler_->NotifyReadyToActivate(); - EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); - EXPECT_ACTION("ScheduledActionCommit", client_, 1, 2); - - // Make sure we do not send a BeginMainFrame while swap throttled and - // we have both a pending tree and an active tree that still needs - // it's first draw. - client_->Reset(); - EXPECT_FALSE(scheduler_->CommitPending()); - scheduler_->SetNeedsBeginMainFrame(); - EXPECT_SCOPED(AdvanceFrame()); - EXPECT_FALSE(scheduler_->CommitPending()); - task_runner().RunPendingTasks(); // Run posted deadline. - EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); -} - TEST_F( SchedulerTest, CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { @@ -3114,12 +2962,9 @@ TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { client_->Reset(); task_runner().RunPendingTasks(); // Run posted deadline. - EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); - client_->Reset(); - + EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); // Unthrottled frame source will immediately begin a new frame. - task_runner().RunPendingTasks(); // Run BeginFrame. - EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); + EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); scheduler_->SetNeedsRedraw(); client_->Reset(); @@ -3544,8 +3389,8 @@ TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { scheduler_settings_.using_synchronous_renderer_compositor = true; scheduler_settings_.use_external_begin_frame_source = true; - scoped_ptr<FakeSchedulerClient> client = - make_scoped_ptr(new SchedulerClientSetNeedsPrepareTilesOnDraw); + std::unique_ptr<FakeSchedulerClient> client = + base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); SetUpScheduler(std::move(client), true); scheduler_->SetNeedsRedraw(); |