diff options
-rw-r--r-- | cc/BUILD.gn | 1 | ||||
-rw-r--r-- | cc/cc.gyp | 1 | ||||
-rw-r--r-- | cc/layers/layer_unittest.cc | 2 | ||||
-rw-r--r-- | cc/layers/texture_layer_unittest.cc | 2 | ||||
-rw-r--r-- | cc/test/fake_layer_tree_host.cc | 2 | ||||
-rw-r--r-- | cc/test/layer_tree_test.cc | 17 | ||||
-rw-r--r-- | cc/trees/compositor_mode.h | 23 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.cc | 32 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.h | 8 | ||||
-rw-r--r-- | ui/android/resources/resource_manager_impl_unittest.cc | 8 |
10 files changed, 75 insertions, 21 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 88e3524..df0083a 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -471,6 +471,7 @@ component("cc") { "trees/blocking_task_runner.h", "trees/channel_impl.h", "trees/channel_main.h", + "trees/compositor_mode.h", "trees/damage_tracker.cc", "trees/damage_tracker.h", "trees/draw_property_utils.cc", @@ -533,6 +533,7 @@ 'trees/blocking_task_runner.h', 'trees/channel_impl.h', 'trees/channel_main.h', + 'trees/compositor_mode.h', 'trees/damage_tracker.cc', 'trees/damage_tracker.h', 'trees/draw_property_utils.cc', diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc index 212dff1..4ac0309 100644 --- a/cc/layers/layer_unittest.cc +++ b/cc/layers/layer_unittest.cc @@ -47,7 +47,7 @@ class MockLayerTreeHost : public LayerTreeHost { public: MockLayerTreeHost(LayerTreeHostSingleThreadClient* single_thread_client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params) { + : LayerTreeHost(params, CompositorMode::SingleThreaded) { InitializeSingleThreaded(single_thread_client, base::ThreadTaskRunnerHandle::Get(), nullptr); } diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc index 7c982c8..c7c64b6 100644 --- a/cc/layers/texture_layer_unittest.cc +++ b/cc/layers/texture_layer_unittest.cc @@ -74,7 +74,7 @@ class MockLayerTreeHost : public LayerTreeHost { private: MockLayerTreeHost(FakeLayerTreeHostClient* client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params) { + : LayerTreeHost(params, CompositorMode::SingleThreaded) { InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), nullptr); } diff --git a/cc/test/fake_layer_tree_host.cc b/cc/test/fake_layer_tree_host.cc index 741a1b4..b2b6a3f 100644 --- a/cc/test/fake_layer_tree_host.cc +++ b/cc/test/fake_layer_tree_host.cc @@ -10,7 +10,7 @@ namespace cc { FakeLayerTreeHost::FakeLayerTreeHost(FakeLayerTreeHostClient* client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params), + : LayerTreeHost(params, CompositorMode::SingleThreaded), client_(client), host_impl_(*params->settings, &task_runner_provider_, diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc index a8241ae..d7f7024 100644 --- a/cc/test/layer_tree_test.cc +++ b/cc/test/layer_tree_test.cc @@ -678,6 +678,7 @@ class LayerTreeHostForTesting : public LayerTreeHost { public: static scoped_ptr<LayerTreeHostForTesting> Create( TestHooks* test_hooks, + CompositorMode mode, LayerTreeHostClientForTesting* client, SharedBitmapManager* shared_bitmap_manager, gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, @@ -693,11 +694,12 @@ class LayerTreeHostForTesting : public LayerTreeHost { params.task_graph_runner = task_graph_runner; params.settings = &settings; scoped_ptr<LayerTreeHostForTesting> layer_tree_host( - new LayerTreeHostForTesting(test_hooks, ¶ms)); + new LayerTreeHostForTesting(test_hooks, ¶ms, mode)); scoped_ptr<TaskRunnerProvider> task_runner_provider = TaskRunnerProvider::Create(main_task_runner, impl_task_runner); scoped_ptr<Proxy> proxy; - if (impl_task_runner.get()) { + if (mode == CompositorMode::Threaded) { + DCHECK(impl_task_runner.get()); proxy = ThreadProxyForTest::Create( test_hooks, layer_tree_host.get(), task_runner_provider.get(), std::move(external_begin_frame_source)); @@ -735,8 +737,11 @@ class LayerTreeHostForTesting : public LayerTreeHost { private: LayerTreeHostForTesting(TestHooks* test_hooks, - LayerTreeHost::InitParams* params) - : LayerTreeHost(params), test_hooks_(test_hooks), test_started_(false) {} + LayerTreeHost::InitParams* params, + CompositorMode mode) + : LayerTreeHost(params, mode), + test_hooks_(test_hooks), + test_started_(false) {} TestHooks* test_hooks_; bool test_started_; @@ -915,8 +920,10 @@ void LayerTreeTest::DoBeginTest() { } DCHECK(!impl_thread_ || impl_thread_->task_runner().get()); + CompositorMode mode = + impl_thread_ ? CompositorMode::Threaded : CompositorMode::SingleThreaded; layer_tree_host_ = LayerTreeHostForTesting::Create( - this, client_.get(), shared_bitmap_manager_.get(), + this, mode, client_.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_, base::ThreadTaskRunnerHandle::Get(), impl_thread_ ? impl_thread_->task_runner() : NULL, diff --git a/cc/trees/compositor_mode.h b/cc/trees/compositor_mode.h new file mode 100644 index 0000000..6494419 --- /dev/null +++ b/cc/trees/compositor_mode.h @@ -0,0 +1,23 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_TREES_COMPOSITOR_MODE_H_ +#define CC_TREES_COMPOSITOR_MODE_H_ + +namespace cc { + +// The LayerTreeHost uses the CompositorMode to determine the current mode of +// operation, which is needed to: +// 1) Safely cast Proxy to SingleThreadProxy to allow operations only supported +// in SingleThreaded mode. +// 2) Make decisions restricted to either browser(SingleThreaded) or renderer +// compositors(Threaded). +enum CompositorMode { + SingleThreaded, + Threaded, +}; + +} // namespace cc + +#endif // CC_TREES_COMPOSITOR_MODE_H_ diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index a62b978..b5f0231 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -66,7 +66,8 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( DCHECK(params->main_task_runner.get()); DCHECK(impl_task_runner.get()); DCHECK(params->settings); - scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(params)); + scoped_ptr<LayerTreeHost> layer_tree_host( + new LayerTreeHost(params, CompositorMode::Threaded)); layer_tree_host->InitializeThreaded( params->main_task_runner, impl_task_runner, std::move(params->external_begin_frame_source)); @@ -77,16 +78,18 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( LayerTreeHostSingleThreadClient* single_thread_client, InitParams* params) { DCHECK(params->settings); - scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(params)); + scoped_ptr<LayerTreeHost> layer_tree_host( + new LayerTreeHost(params, CompositorMode::SingleThreaded)); layer_tree_host->InitializeSingleThreaded( single_thread_client, params->main_task_runner, std::move(params->external_begin_frame_source)); return layer_tree_host; } -LayerTreeHost::LayerTreeHost(InitParams* params) +LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) : micro_benchmark_controller_(this), next_ui_resource_id_(1), + compositor_mode_(mode), needs_full_tree_sync_(true), needs_meta_info_recomputation_(true), client_(params->client), @@ -674,7 +677,7 @@ void LayerTreeHost::NotifyInputThrottledUntilCommit() { } void LayerTreeHost::LayoutAndUpdateLayers() { - DCHECK(!task_runner_provider_->HasImplThread()); + DCHECK(IsSingleThreaded()); // This function is only valid when not using the scheduler. DCHECK(!settings_.single_thread_proxy_scheduler); SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); @@ -692,7 +695,7 @@ void LayerTreeHost::LayoutAndUpdateLayers() { } void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) { - DCHECK(!task_runner_provider_->HasImplThread()); + DCHECK(IsSingleThreaded()); // This function is only valid when not using the scheduler. DCHECK(!settings_.single_thread_proxy_scheduler); SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); @@ -732,9 +735,8 @@ static Layer* FindFirstScrollableLayer(Layer* layer) { void LayerTreeHost::RecordGpuRasterizationHistogram() { // Gpu rasterization is only supported for Renderer compositors. - // Checking for proxy_->HasImplThread() to exclude Browser compositors. - if (gpu_rasterization_histogram_recorded_ || - !task_runner_provider_->HasImplThread()) + // Checking for IsThreaded() to exclude Browser compositors. + if (gpu_rasterization_histogram_recorded_ || IsThreaded()) return; // Record how widely gpu rasterization is enabled. @@ -896,7 +898,7 @@ void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, TopControlsState current, bool animate) { // Top controls are only used in threaded mode. - DCHECK(task_runner_provider_->HasImplThread()); + DCHECK(IsThreaded()); proxy_->UpdateTopControlsState(constraints, current, animate); } @@ -1247,4 +1249,16 @@ bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const { : false; } +bool LayerTreeHost::IsSingleThreaded() const { + DCHECK(compositor_mode_ != CompositorMode::SingleThreaded || + !task_runner_provider_->HasImplThread()); + return compositor_mode_ == CompositorMode::SingleThreaded; +} + +bool LayerTreeHost::IsThreaded() const { + DCHECK(compositor_mode_ != CompositorMode::Threaded || + task_runner_provider_->HasImplThread()); + return compositor_mode_ == CompositorMode::Threaded; +} + } // namespace cc diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index 9c8e1ec..3bfd73c 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -33,6 +33,7 @@ #include "cc/resources/resource_format.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/surfaces/surface_sequence.h" +#include "cc/trees/compositor_mode.h" #include "cc/trees/layer_tree_host_client.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_settings.h" @@ -359,7 +360,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { bool HasActiveAnimation(const Layer* layer) const; protected: - explicit LayerTreeHost(InitParams* params); + LayerTreeHost(InitParams* params, CompositorMode mode); void InitializeThreaded( scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, @@ -397,6 +398,9 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { bool AnimateLayersRecursive(Layer* current, base::TimeTicks time); + bool IsSingleThreaded() const; + bool IsThreaded() const; + struct UIResourceClientData { UIResourceClient* client; gfx::Size size; @@ -417,6 +421,8 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { void SetPropertyTreesNeedRebuild(); + const CompositorMode compositor_mode_; + bool needs_full_tree_sync_; bool needs_meta_info_recomputation_; diff --git a/ui/android/resources/resource_manager_impl_unittest.cc b/ui/android/resources/resource_manager_impl_unittest.cc index 1c6db18..82ed7b1 100644 --- a/ui/android/resources/resource_manager_impl_unittest.cc +++ b/ui/android/resources/resource_manager_impl_unittest.cc @@ -69,8 +69,9 @@ const ui::SystemUIResourceType kTestResourceType = ui::OVERSCROLL_GLOW; class MockLayerTreeHost : public cc::LayerTreeHost { public: - MockLayerTreeHost(cc::LayerTreeHost::InitParams* params) - : cc::LayerTreeHost(params) {} + MockLayerTreeHost(cc::LayerTreeHost::InitParams* params, + cc::CompositorMode mode) + : cc::LayerTreeHost(params, mode) {} MOCK_METHOD1(CreateUIResource, cc::UIResourceId(cc::UIResourceClient*)); MOCK_METHOD1(DeleteUIResource, void(cc::UIResourceId)); @@ -92,7 +93,8 @@ class ResourceManagerTest : public testing::Test { params.client = &fake_client_; params.settings = &settings; params.task_graph_runner = &task_graph_runner_; - host_.reset(new MockLayerTreeHost(¶ms)); + host_.reset(new MockLayerTreeHost(¶ms, + cc::CompositorMode::SingleThreaded)); resource_manager_.Init(host_.get()); } |