Chromium Code Reviews| Index: cc/test/layer_tree_test.cc |
| diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc |
| index 6795f90dfb651d314b91c50d0bafebb7a1969cf9..3f6f0665cd60c0d1f6b783eccb3131ff24ab3e0d 100644 |
| --- a/cc/test/layer_tree_test.cc |
| +++ b/cc/test/layer_tree_test.cc |
| @@ -37,13 +37,113 @@ bool TestHooks::PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| return true; |
| } |
| -bool TestHooks::CanActivatePendingTree(LayerTreeHostImpl* host_impl) { |
| - return true; |
| -} |
| +class LayerTreeHostImplClientInterposer : public LayerTreeHostImplClient { |
| + public: |
| + LayerTreeHostImplClientInterposer(LayerTreeHostImplClient* client) |
| + : client_(client), |
| + block_notify_ready_to_activate_(false), |
| + notify_ready_to_activate_was_blocked_(false) { } |
| + |
| + // LayerTreeHostImplClient interface |
| + virtual void DidTryInitializeRendererOnImplThread( |
| + bool success, |
| + scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { |
| + client_->DidTryInitializeRendererOnImplThread( |
| + success, offscreen_context_provider); |
| + } |
| + |
| + virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { |
| + client_->DidLoseOutputSurfaceOnImplThread(); |
| + } |
| + |
| + virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE { |
| + client_->OnSwapBuffersCompleteOnImplThread(); |
| + } |
| + |
| + virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) OVERRIDE { |
| + client_->BeginFrameOnImplThread(args); |
| + } |
| + |
| + virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { |
| + client_->OnCanDrawStateChanged(can_draw); |
| + } |
| + |
| + virtual void NotifyReadyToActivate() OVERRIDE { |
| + if (block_notify_ready_to_activate_) |
| + notify_ready_to_activate_was_blocked_ = true; |
| + else |
| + client_->NotifyReadyToActivate(); |
| + } |
| + |
| + virtual void SetNeedsRedrawOnImplThread() OVERRIDE { |
| + client_->SetNeedsRedrawOnImplThread(); |
| + } |
| + |
| + virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) OVERRIDE { |
| + client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
| + } |
| + |
| + virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE { |
| + client_->DidInitializeVisibleTileOnImplThread(); |
| + } |
| + |
| + virtual void SetNeedsCommitOnImplThread() OVERRIDE { |
| + client_->SetNeedsCommitOnImplThread(); |
| + } |
| + |
| + virtual void PostAnimationEventsToMainThreadOnImplThread( |
| + scoped_ptr<AnimationEventsVector> events, |
| + base::Time wall_clock_time) OVERRIDE { |
| + client_->PostAnimationEventsToMainThreadOnImplThread( |
| + events.Pass(), wall_clock_time); |
| + } |
| + |
| + virtual bool ReduceContentsTextureMemoryOnImplThread( |
| + size_t limit_bytes, |
| + int priority_cutoff) OVERRIDE { |
| + return client_->ReduceContentsTextureMemoryOnImplThread( |
| + limit_bytes, priority_cutoff); |
| + } |
| + |
| + virtual void ReduceWastedContentsTextureMemoryOnImplThread() { |
| + client_->ReduceWastedContentsTextureMemoryOnImplThread(); |
| + } |
| + |
| + virtual void SendManagedMemoryStats() OVERRIDE { |
| + client_->SendManagedMemoryStats(); |
| + } |
| + |
| + virtual bool IsInsideDraw() OVERRIDE { |
| + return client_->IsInsideDraw(); |
| + } |
| + |
| + virtual void RenewTreePriority() OVERRIDE { |
| + client_->RenewTreePriority(); |
| + } |
| + |
| + virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) |
| + OVERRIDE { |
| + client_->RequestScrollbarAnimationOnImplThread(delay); |
| + } |
| + |
| + virtual void DidActivatePendingTree() OVERRIDE { |
| + client_->DidActivatePendingTree(); |
| + } |
| + |
| + // Test hooks |
| + void BlockNotifyReadyToActivate(bool block) { |
| + block_notify_ready_to_activate_ = block; |
| + if (!block && notify_ready_to_activate_was_blocked_) { |
| + NotifyReadyToActivate(); |
| + } |
| + } |
| + |
| + private: |
| + LayerTreeHostImplClient* client_; |
| + bool block_notify_ready_to_activate_; |
| + bool notify_ready_to_activate_was_blocked_; |
| +}; |
| -bool TestHooks::CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* host_impl) { |
| - return true; |
| -} |
| // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
| class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| @@ -75,6 +175,11 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| stats_instrumentation), |
| test_hooks_(test_hooks) {} |
| + virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE { |
| + test_hooks_->WillBeginFrameOnThread(this, args); |
| + LayerTreeHostImpl::BeginFrame(args); |
| + } |
| + |
| virtual void BeginCommit() OVERRIDE { |
| LayerTreeHostImpl::BeginCommit(); |
| test_hooks_->BeginCommitOnThread(this); |
| @@ -114,20 +219,7 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| test_hooks_->SwapBuffersCompleteOnThread(this); |
| } |
| - virtual void ActivatePendingTreeIfNeeded() OVERRIDE { |
| - if (!pending_tree()) |
| - return; |
| - |
| - if (!test_hooks_->CanActivatePendingTreeIfNeeded(this)) |
| - return; |
| - |
| - LayerTreeHostImpl::ActivatePendingTreeIfNeeded(); |
| - } |
| - |
| virtual void ActivatePendingTree() OVERRIDE { |
| - if (!test_hooks_->CanActivatePendingTree(this)) |
| - return; |
| - |
| test_hooks_->WillActivateTreeOnThread(this); |
| LayerTreeHostImpl::ActivatePendingTree(); |
| DCHECK(!pending_tree()); |
| @@ -181,10 +273,12 @@ class LayerTreeHostForTesting : public cc::LayerTreeHost { |
| static scoped_ptr<LayerTreeHostForTesting> Create( |
| TestHooks* test_hooks, |
| cc::LayerTreeHostClient* host_client, |
| + scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer, |
| const cc::LayerTreeSettings& settings, |
| scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
| - new LayerTreeHostForTesting(test_hooks, host_client, settings)); |
| + new LayerTreeHostForTesting( |
| + test_hooks, host_client, impl_client_interposer, settings)); |
| bool success = layer_tree_host->Initialize(impl_task_runner); |
| EXPECT_TRUE(success); |
| return layer_tree_host.Pass(); |
| @@ -192,10 +286,12 @@ class LayerTreeHostForTesting : public cc::LayerTreeHost { |
| virtual scoped_ptr<cc::LayerTreeHostImpl> CreateLayerTreeHostImpl( |
| cc::LayerTreeHostImplClient* host_impl_client) OVERRIDE { |
| + impl_client_interposer_.reset( |
| + new LayerTreeHostImplClientInterposer(host_impl_client)); |
|
brianderson
2013/08/24 02:33:29
I'm trying to think of a better way to do this...
enne (OOO)
2013/08/26 21:55:13
This seems fine to me. It's unfortunate that beca
|
| return LayerTreeHostImplForTesting::Create( |
| test_hooks_, |
| settings(), |
| - host_impl_client, |
| + impl_client_interposer_.get(), |
| proxy(), |
| rendering_stats_instrumentation()).PassAs<cc::LayerTreeHostImpl>(); |
| } |
| @@ -213,14 +309,18 @@ class LayerTreeHostForTesting : public cc::LayerTreeHost { |
| } |
| private: |
| - LayerTreeHostForTesting(TestHooks* test_hooks, |
| - cc::LayerTreeHostClient* client, |
| - const cc::LayerTreeSettings& settings) |
| - : LayerTreeHost(client, settings), |
| - test_hooks_(test_hooks), |
| - test_started_(false) {} |
| + LayerTreeHostForTesting( |
| + TestHooks* test_hooks, |
| + cc::LayerTreeHostClient* client, |
| + scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer, |
| + const cc::LayerTreeSettings& settings) |
| + : LayerTreeHost(client, settings), |
| + test_hooks_(test_hooks), |
| + impl_client_interposer_(impl_client_interposer), |
| + test_started_(false) {} |
| TestHooks* test_hooks_; |
| + scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer_; |
| bool test_started_; |
| }; |
| @@ -404,6 +504,7 @@ void LayerTreeTest::DoBeginTest() { |
| layer_tree_host_ = LayerTreeHostForTesting::Create( |
| this, |
| client_.get(), |
| + impl_client_, |
| settings_, |
| impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); |
| ASSERT_TRUE(layer_tree_host_); |
| @@ -601,6 +702,10 @@ void LayerTreeTest::RunTest(bool threaded, |
| AfterTest(); |
| } |
| +void LayerTreeTest::BlockNotifyReadyToActivate(bool block) { |
| + impl_client_->BlockNotifyReadyToActivate(block); |
| +} |
| + |
| scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
| scoped_ptr<FakeOutputSurface> output_surface; |
| if (delegating_renderer_) |