diff options
27 files changed, 262 insertions, 193 deletions
diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc index c66eb85..0414acb 100644 --- a/cc/layers/layer_unittest.cc +++ b/cc/layers/layer_unittest.cc @@ -38,9 +38,9 @@ namespace { class MockLayerTreeHost : public LayerTreeHost { public: - explicit MockLayerTreeHost(LayerTreeHostClient* client) + explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) : LayerTreeHost(client, NULL, LayerTreeSettings()) { - Initialize(NULL); + InitializeSingleThreaded(client); } MOCK_METHOD0(SetNeedsCommit, void()); @@ -803,12 +803,17 @@ class LayerTreeHostFactory { : client_(FakeLayerTreeHostClient::DIRECT_3D) {} scoped_ptr<LayerTreeHost> Create() { - return LayerTreeHost::Create(&client_, NULL, LayerTreeSettings(), NULL) - .Pass(); + return LayerTreeHost::CreateSingleThreaded(&client_, + &client_, + NULL, + LayerTreeSettings()).Pass(); } scoped_ptr<LayerTreeHost> Create(LayerTreeSettings settings) { - return LayerTreeHost::Create(&client_, NULL, settings, NULL).Pass(); + return LayerTreeHost::CreateSingleThreaded(&client_, + &client_, + NULL, + settings).Pass(); } private: diff --git a/cc/layers/nine_patch_layer_unittest.cc b/cc/layers/nine_patch_layer_unittest.cc index 7213a51..41da351 100644 --- a/cc/layers/nine_patch_layer_unittest.cc +++ b/cc/layers/nine_patch_layer_unittest.cc @@ -10,6 +10,7 @@ #include "cc/resources/resource_update_queue.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/scheduler/texture_uploader.h" +#include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_output_surface_client.h" @@ -29,30 +30,20 @@ using ::testing::AnyNumber; namespace cc { namespace { -class MockLayerTreeHost : public LayerTreeHost { - public: - explicit MockLayerTreeHost(LayerTreeHostClient* client) - : LayerTreeHost(client, NULL, LayerTreeSettings()) { - Initialize(NULL); - } -}; - class NinePatchLayerTest : public testing::Test { public: NinePatchLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} - cc::Proxy* Proxy() const { return layer_tree_host_->proxy(); } - protected: virtual void SetUp() { - layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); + layer_tree_host_ = FakeLayerTreeHost::Create(); } virtual void TearDown() { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); } - scoped_ptr<MockLayerTreeHost> layer_tree_host_; + scoped_ptr<FakeLayerTreeHost> layer_tree_host_; FakeLayerTreeHostClient fake_client_; }; @@ -66,8 +57,6 @@ TEST_F(NinePatchLayerTest, SetLayerProperties) { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); - layer_tree_host_->InitializeOutputSurfaceIfNeeded(); - ResourceUpdateQueue queue; OcclusionTracker occlusion_tracker(gfx::Rect(), false); test_layer->SavePaintProperties(); diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc index df12b73..53a9fa8 100644 --- a/cc/layers/scrollbar_layer_unittest.cc +++ b/cc/layers/scrollbar_layer_unittest.cc @@ -512,13 +512,13 @@ TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { class MockLayerTreeHost : public LayerTreeHost { public: - MockLayerTreeHost(LayerTreeHostClient* client, + MockLayerTreeHost(FakeLayerTreeHostClient* client, const LayerTreeSettings& settings) : LayerTreeHost(client, NULL, settings), next_id_(1), total_ui_resource_created_(0), total_ui_resource_deleted_(0) { - Initialize(NULL); + InitializeSingleThreaded(client); } virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE { diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc index d793473..5acc9c5 100644 --- a/cc/layers/texture_layer_unittest.cc +++ b/cc/layers/texture_layer_unittest.cc @@ -43,9 +43,9 @@ namespace { class MockLayerTreeHost : public LayerTreeHost { public: - explicit MockLayerTreeHost(LayerTreeHostClient* client) + explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) : LayerTreeHost(client, NULL, LayerTreeSettings()) { - Initialize(NULL); + InitializeSingleThreaded(client); } MOCK_METHOD0(AcquireLayerTextures, void()); diff --git a/cc/layers/tiled_layer_unittest.cc b/cc/layers/tiled_layer_unittest.cc index 6f5d485..42ef29c 100644 --- a/cc/layers/tiled_layer_unittest.cc +++ b/cc/layers/tiled_layer_unittest.cc @@ -59,10 +59,11 @@ class TiledLayerTest : public testing::Test { virtual void SetUp() { impl_thread_.Start(); - layer_tree_host_ = LayerTreeHost::Create(&fake_layer_tree_host_client_, - NULL, - settings_, - impl_thread_.message_loop_proxy()); + layer_tree_host_ = LayerTreeHost::CreateThreaded( + &fake_layer_tree_host_client_, + NULL, + settings_, + impl_thread_.message_loop_proxy()); proxy_ = layer_tree_host_->proxy(); resource_manager_ = PrioritizedResourceManager::Create(proxy_); layer_tree_host_->SetLayerTreeHostClientReady(); diff --git a/cc/layers/ui_resource_layer_unittest.cc b/cc/layers/ui_resource_layer_unittest.cc index a2c75c1..48dbdf5 100644 --- a/cc/layers/ui_resource_layer_unittest.cc +++ b/cc/layers/ui_resource_layer_unittest.cc @@ -10,6 +10,7 @@ #include "cc/resources/resource_update_queue.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/scheduler/texture_uploader.h" +#include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_output_surface_client.h" @@ -29,30 +30,21 @@ using ::testing::AnyNumber; namespace cc { namespace { -class MockLayerTreeHost : public LayerTreeHost { - public: - explicit MockLayerTreeHost(LayerTreeHostClient* client) - : LayerTreeHost(client, NULL, LayerTreeSettings()) { - Initialize(NULL); - } -}; - class UIResourceLayerTest : public testing::Test { public: UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} - cc::Proxy* Proxy() const { return layer_tree_host_->proxy(); } - protected: virtual void SetUp() { - layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); + layer_tree_host_ = FakeLayerTreeHost::Create(); + layer_tree_host_->InitializeSingleThreaded(&fake_client_); } virtual void TearDown() { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); } - scoped_ptr<MockLayerTreeHost> layer_tree_host_; + scoped_ptr<FakeLayerTreeHost> layer_tree_host_; FakeLayerTreeHostClient fake_client_; }; diff --git a/cc/test/fake_layer_tree_host.h b/cc/test/fake_layer_tree_host.h index 3acfdd2..09657ef 100644 --- a/cc/test/fake_layer_tree_host.h +++ b/cc/test/fake_layer_tree_host.h @@ -14,7 +14,7 @@ namespace cc { -class FakeLayerTreeHost : protected LayerTreeHost { +class FakeLayerTreeHost : public LayerTreeHost { public: static scoped_ptr<FakeLayerTreeHost> Create(); @@ -36,6 +36,7 @@ class FakeLayerTreeHost : protected LayerTreeHost { using LayerTreeHost::ScheduleMicroBenchmark; using LayerTreeHost::SetOutputSurfaceLostForTesting; + using LayerTreeHost::InitializeSingleThreaded; using LayerTreeHost::InitializeForTesting; void UpdateLayers(ResourceUpdateQueue* queue) { LayerTreeHost::UpdateLayers(queue); diff --git a/cc/test/fake_layer_tree_host_client.h b/cc/test/fake_layer_tree_host_client.h index 0bad7ad..8b60f50 100644 --- a/cc/test/fake_layer_tree_host_client.h +++ b/cc/test/fake_layer_tree_host_client.h @@ -8,12 +8,14 @@ #include "base/memory/scoped_ptr.h" #include "cc/input/input_handler.h" #include "cc/test/test_context_provider.h" -#include "cc/trees/layer_tree_host.h" +#include "cc/trees/layer_tree_host_client.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" namespace cc { class OutputSurface; -class FakeLayerTreeHostClient : public LayerTreeHostClient { +class FakeLayerTreeHostClient : public LayerTreeHostClient, + public LayerTreeHostSingleThreadClient { public: enum RendererOptions { DIRECT_3D, @@ -24,6 +26,7 @@ class FakeLayerTreeHostClient : public LayerTreeHostClient { explicit FakeLayerTreeHostClient(RendererOptions options); virtual ~FakeLayerTreeHostClient(); + // LayerTreeHostClient implementation. virtual void WillBeginMainFrame() OVERRIDE {} virtual void DidBeginMainFrame() OVERRIDE {} virtual void Animate(double frame_begin_time) OVERRIDE {} @@ -37,11 +40,12 @@ class FakeLayerTreeHostClient : public LayerTreeHostClient { virtual void DidCommit() OVERRIDE {} virtual void DidCommitAndDrawFrame() OVERRIDE {} virtual void DidCompleteSwapBuffers() OVERRIDE {} + virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE; - // Used only in the single-threaded path. + // LayerTreeHostSingleThreadClient implementation. virtual void ScheduleComposite() OVERRIDE {} - - virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE; + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} private: bool use_software_rendering_; diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc index 79b3445..292f7bb 100644 --- a/cc/test/layer_tree_test.cc +++ b/cc/test/layer_tree_test.cc @@ -20,7 +20,9 @@ #include "cc/test/occlusion_tracker_test_common.h" #include "cc/test/test_context_provider.h" #include "cc/test/tiled_layer_test_common.h" +#include "cc/trees/layer_tree_host_client.h" #include "cc/trees/layer_tree_host_impl.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "cc/trees/single_thread_proxy.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/frame_time.h" @@ -194,57 +196,9 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl { bool notify_ready_to_activate_was_blocked_; }; -// Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. -class LayerTreeHostForTesting : public LayerTreeHost { - public: - static scoped_ptr<LayerTreeHostForTesting> Create( - TestHooks* test_hooks, - LayerTreeHostClient* host_client, - const LayerTreeSettings& settings, - scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { - scoped_ptr<LayerTreeHostForTesting> layer_tree_host( - new LayerTreeHostForTesting(test_hooks, host_client, settings)); - bool success = layer_tree_host->Initialize(impl_task_runner); - EXPECT_TRUE(success); - return layer_tree_host.Pass(); - } - - virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( - LayerTreeHostImplClient* host_impl_client) OVERRIDE { - return LayerTreeHostImplForTesting::Create( - test_hooks_, - settings(), - host_impl_client, - proxy(), - rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>(); - } - - virtual void SetNeedsCommit() OVERRIDE { - if (!test_started_) - return; - LayerTreeHost::SetNeedsCommit(); - } - - void set_test_started(bool started) { test_started_ = started; } - - virtual void DidDeferCommit() OVERRIDE { - test_hooks_->DidDeferCommit(); - } - - private: - LayerTreeHostForTesting(TestHooks* test_hooks, - LayerTreeHostClient* client, - const LayerTreeSettings& settings) - : LayerTreeHost(client, NULL, settings), - test_hooks_(test_hooks), - test_started_(false) {} - - TestHooks* test_hooks_; - bool test_started_; -}; - // Implementation of LayerTreeHost callback interface. -class LayerTreeHostClientForTesting : public LayerTreeHostClient { +class LayerTreeHostClientForTesting : public LayerTreeHostClient, + public LayerTreeHostSingleThreadClient { public: static scoped_ptr<LayerTreeHostClientForTesting> Create( TestHooks* test_hooks) { @@ -305,6 +259,9 @@ class LayerTreeHostClientForTesting : public LayerTreeHostClient { test_hooks_->ScheduleComposite(); } + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} + virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE { return test_hooks_->OffscreenContextProvider(); } @@ -316,6 +273,59 @@ class LayerTreeHostClientForTesting : public LayerTreeHostClient { TestHooks* test_hooks_; }; +// Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. +class LayerTreeHostForTesting : public LayerTreeHost { + public: + static scoped_ptr<LayerTreeHostForTesting> Create( + TestHooks* test_hooks, + LayerTreeHostClientForTesting* client, + const LayerTreeSettings& settings, + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { + scoped_ptr<LayerTreeHostForTesting> layer_tree_host( + new LayerTreeHostForTesting(test_hooks, client, settings)); + bool success; + if (impl_task_runner.get()) + success = layer_tree_host->InitializeThreaded(impl_task_runner); + else + success = layer_tree_host->InitializeSingleThreaded(client); + EXPECT_TRUE(success); + return layer_tree_host.Pass(); + } + + virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( + LayerTreeHostImplClient* host_impl_client) OVERRIDE { + return LayerTreeHostImplForTesting::Create( + test_hooks_, + settings(), + host_impl_client, + proxy(), + rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>(); + } + + virtual void SetNeedsCommit() OVERRIDE { + if (!test_started_) + return; + LayerTreeHost::SetNeedsCommit(); + } + + void set_test_started(bool started) { test_started_ = started; } + + virtual void DidDeferCommit() OVERRIDE { + test_hooks_->DidDeferCommit(); + } + + private: + LayerTreeHostForTesting(TestHooks* test_hooks, + LayerTreeHostClient* client, + const LayerTreeSettings& settings) + : LayerTreeHost(client, NULL, settings), + test_hooks_(test_hooks), + test_started_(false) {} + + TestHooks* test_hooks_; + bool test_started_; +}; + LayerTreeTest::LayerTreeTest() : beginning_(false), end_when_begin_returns_(false), diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index c14736a..e919805 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -98,21 +98,36 @@ UIResourceRequest& UIResourceRequest::operator=( UIResourceRequest::~UIResourceRequest() {} -scoped_ptr<LayerTreeHost> LayerTreeHost::Create( +scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( LayerTreeHostClient* client, SharedBitmapManager* manager, const LayerTreeSettings& settings, scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { + DCHECK(impl_task_runner); scoped_ptr<LayerTreeHost> layer_tree_host( new LayerTreeHost(client, manager, settings)); - if (!layer_tree_host->Initialize(impl_task_runner)) + if (!layer_tree_host->InitializeThreaded(impl_task_runner)) return scoped_ptr<LayerTreeHost>(); return layer_tree_host.Pass(); } -LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, - SharedBitmapManager* manager, - const LayerTreeSettings& settings) +scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( + LayerTreeHostClient* client, + LayerTreeHostSingleThreadClient* single_thread_client, + SharedBitmapManager* manager, + const LayerTreeSettings& settings) { + scoped_ptr<LayerTreeHost> layer_tree_host( + new LayerTreeHost(client, manager, settings)); + if (!layer_tree_host->InitializeSingleThreaded(single_thread_client)) + return scoped_ptr<LayerTreeHost>(); + return layer_tree_host.Pass(); +} + + +LayerTreeHost::LayerTreeHost( + LayerTreeHostClient* client, + SharedBitmapManager* manager, + const LayerTreeSettings& settings) : next_ui_resource_id_(1), animating_(false), needs_full_tree_sync_(true), @@ -147,12 +162,15 @@ LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, debug_state_.RecordRenderingStats()); } -bool LayerTreeHost::Initialize( +bool LayerTreeHost::InitializeThreaded( scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { - if (impl_task_runner.get()) - return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); - else - return InitializeProxy(SingleThreadProxy::Create(this)); + return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); +} + +bool LayerTreeHost::InitializeSingleThreaded( + LayerTreeHostSingleThreadClient* single_thread_client) { + return InitializeProxy( + SingleThreadProxy::Create(this, single_thread_client)); } bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { @@ -562,8 +580,6 @@ void LayerTreeHost::SetNeedsRedraw() { void LayerTreeHost::SetNeedsRedrawRect(gfx::Rect damage_rect) { proxy_->SetNeedsRedraw(damage_rect); - if (!proxy_->HasImplThread()) - client_->ScheduleComposite(); } bool LayerTreeHost::CommitRequested() const { @@ -739,10 +755,6 @@ void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) { SetNeedsCommit(); } -void LayerTreeHost::ScheduleComposite() { - client_->ScheduleComposite(); -} - bool LayerTreeHost::InitializeOutputSurfaceIfNeeded() { if (!output_surface_can_be_initialized_) return false; diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index aa057e0..dba4aa6 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -48,8 +48,9 @@ class HeadsUpDisplayLayer; class Layer; class LayerTreeHostImpl; class LayerTreeHostImplClient; -class PrioritizedResourceManager; +class LayerTreeHostSingleThreadClient; class PrioritizedResource; +class PrioritizedResourceManager; class Region; class RenderingStatsInstrumentation; class ResourceProvider; @@ -112,11 +113,17 @@ class CC_EXPORT UIResourceRequest { class CC_EXPORT LayerTreeHost { public: // The SharedBitmapManager will be used on the compositor thread. - static scoped_ptr<LayerTreeHost> Create( + static scoped_ptr<LayerTreeHost> CreateThreaded( LayerTreeHostClient* client, SharedBitmapManager* manager, const LayerTreeSettings& settings, scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); + + static scoped_ptr<LayerTreeHost> CreateSingleThreaded( + LayerTreeHostClient* client, + LayerTreeHostSingleThreadClient* single_thread_client, + SharedBitmapManager* manager, + const LayerTreeSettings& settings); virtual ~LayerTreeHost(); void SetLayerTreeHostClientReady(); @@ -165,9 +172,6 @@ class CC_EXPORT LayerTreeHost { void Composite(base::TimeTicks frame_begin_time); - // Only used when compositing on the main thread. - void ScheduleComposite(); - // Composites and attempts to read back the result into the provided // buffer. If it wasn't possible, e.g. due to context lost, will return // false. @@ -316,7 +320,10 @@ class CC_EXPORT LayerTreeHost { LayerTreeHost(LayerTreeHostClient* client, SharedBitmapManager* manager, const LayerTreeSettings& settings); - bool Initialize(scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); + bool InitializeThreaded( + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); + bool InitializeSingleThreaded( + LayerTreeHostSingleThreadClient* single_thread_client); bool InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing); void SetOutputSurfaceLostForTesting(bool is_lost) { output_surface_lost_ = is_lost; diff --git a/cc/trees/layer_tree_host_client.h b/cc/trees/layer_tree_host_client.h index 5c1cc1d..9d1fa77 100644 --- a/cc/trees/layer_tree_host_client.h +++ b/cc/trees/layer_tree_host_client.h @@ -36,9 +36,6 @@ class LayerTreeHostClient { virtual void DidCommitAndDrawFrame() = 0; virtual void DidCompleteSwapBuffers() = 0; - // Used only in the single-threaded path. - virtual void ScheduleComposite() = 0; - // If the client provides an OutputSurface bound to a 3d context for direct // rendering, this must return a provider that provides contexts usable from // the same thread as the OutputSurface's context. diff --git a/cc/trees/layer_tree_host_single_thread_client.h b/cc/trees/layer_tree_host_single_thread_client.h new file mode 100644 index 0000000..5d4be95 --- /dev/null +++ b/cc/trees/layer_tree_host_single_thread_client.h @@ -0,0 +1,29 @@ +// Copyright 2013 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_LAYER_TREE_HOST_SINGLE_THREAD_CLIENT_H_ +#define CC_TREES_LAYER_TREE_HOST_SINGLE_THREAD_CLIENT_H_ + +namespace cc { + +class LayerTreeHostSingleThreadClient { + public: + // Request that the client schedule a composite. + virtual void ScheduleComposite() = 0; + + // Called whenever the compositor posts a SwapBuffers (either full or + // partial). After DidPostSwapBuffers(), exactly one of + // LayerTreeHostClient::DidCompleteSwapBuffers() or DidAbortSwapBuffers() will + // be called, thus these functions can be used to keep track of pending swap + // buffers calls for rate limiting. + virtual void DidPostSwapBuffers() = 0; + virtual void DidAbortSwapBuffers() = 0; + + protected: + virtual ~LayerTreeHostSingleThreadClient() {} +}; + +} // namespace cc + +#endif // CC_TREES_LAYER_TREE_HOST_SINGLE_THREAD_CLIENT_H_ diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 59bad2e..99c2482 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -2373,7 +2373,7 @@ TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { settings.max_partial_texture_updates = 4; scoped_ptr<LayerTreeHost> host = - LayerTreeHost::Create(&client, NULL, settings, NULL); + LayerTreeHost::CreateSingleThreaded(&client, &client, NULL, settings); EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); EXPECT_EQ(4u, host->settings().max_partial_texture_updates); } @@ -2385,7 +2385,7 @@ TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { settings.max_partial_texture_updates = 4; scoped_ptr<LayerTreeHost> host = - LayerTreeHost::Create(&client, NULL, settings, NULL); + LayerTreeHost::CreateSingleThreaded(&client, &client, NULL, settings); EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); EXPECT_EQ(4u, host->settings().max_partial_texture_updates); } @@ -2397,7 +2397,7 @@ TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { settings.max_partial_texture_updates = 4; scoped_ptr<LayerTreeHost> host = - LayerTreeHost::Create(&client, NULL, settings, NULL); + LayerTreeHost::CreateSingleThreaded(&client, &client, NULL, settings); EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); } @@ -2410,7 +2410,7 @@ TEST(LayerTreeHostTest, settings.max_partial_texture_updates = 4; scoped_ptr<LayerTreeHost> host = - LayerTreeHost::Create(&client, NULL, settings, NULL); + LayerTreeHost::CreateSingleThreaded(&client, &client, NULL, settings); EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); } diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc index ce5dfe1..d0874c4 100644 --- a/cc/trees/layer_tree_host_unittest_context.cc +++ b/cc/trees/layer_tree_host_unittest_context.cc @@ -1779,21 +1779,20 @@ class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface void RunTest(bool threaded, bool delegating_renderer, bool impl_side_painting) { - scoped_ptr<base::Thread> impl_thread; + LayerTreeSettings settings; + settings.impl_side_painting = impl_side_painting; if (threaded) { - impl_thread.reset(new base::Thread("LayerTreeTest")); + scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest")); ASSERT_TRUE(impl_thread->Start()); ASSERT_TRUE(impl_thread->message_loop_proxy().get()); + scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded( + this, NULL, settings, impl_thread->message_loop_proxy()); + EXPECT_FALSE(layer_tree_host); + } else { + scoped_ptr<LayerTreeHost> layer_tree_host = + LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); + EXPECT_FALSE(layer_tree_host); } - - LayerTreeSettings settings; - settings.impl_side_painting = impl_side_painting; - scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::Create( - this, - NULL, - settings, - impl_thread ? impl_thread->message_loop_proxy() : NULL); - EXPECT_FALSE(layer_tree_host); } }; diff --git a/cc/trees/layer_tree_host_unittest_scroll.cc b/cc/trees/layer_tree_host_unittest_scroll.cc index 1142622..3871154 100644 --- a/cc/trees/layer_tree_host_unittest_scroll.cc +++ b/cc/trees/layer_tree_host_unittest_scroll.cc @@ -1012,7 +1012,7 @@ TEST(LayerTreeHostFlingTest, DidStopFlingingThread) { FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); ASSERT_TRUE(impl_thread.message_loop_proxy().get()); - scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::Create( + scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded( &client, NULL, settings, impl_thread.message_loop_proxy()); impl_thread.message_loop_proxy() diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc index 9de0fdd..13d8111 100644 --- a/cc/trees/single_thread_proxy.cc +++ b/cc/trees/single_thread_proxy.cc @@ -14,19 +14,24 @@ #include "cc/resources/resource_update_controller.h" #include "cc/trees/blocking_task_runner.h" #include "cc/trees/layer_tree_host.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "cc/trees/layer_tree_impl.h" #include "ui/gfx/frame_time.h" namespace cc { -scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) { +scoped_ptr<Proxy> SingleThreadProxy::Create( + LayerTreeHost* layer_tree_host, + LayerTreeHostSingleThreadClient* client) { return make_scoped_ptr( - new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>(); + new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); } -SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host) +SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, + LayerTreeHostSingleThreadClient* client) : Proxy(NULL), layer_tree_host_(layer_tree_host), + client_(client), created_offscreen_context_provider_(false), next_frame_is_newly_committed_frame_(false), inside_draw_(false) { @@ -178,7 +183,7 @@ void SingleThreadProxy::SetNeedsAnimate() { void SingleThreadProxy::SetNeedsUpdateLayers() { DCHECK(Proxy::IsMainThread()); - layer_tree_host_->ScheduleComposite(); + client_->ScheduleComposite(); } void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { @@ -237,11 +242,12 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { void SingleThreadProxy::SetNeedsCommit() { DCHECK(Proxy::IsMainThread()); - layer_tree_host_->ScheduleComposite(); + client_->ScheduleComposite(); } void SingleThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { SetNeedsRedrawRectOnImplThread(damage_rect); + client_->ScheduleComposite(); } void SingleThreadProxy::SetNextCommitWaitsForActivation() { @@ -286,7 +292,7 @@ void SingleThreadProxy::NotifyReadyToActivate() { } void SingleThreadProxy::SetNeedsRedrawOnImplThread() { - layer_tree_host_->ScheduleComposite(); + client_->ScheduleComposite(); } void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { @@ -308,7 +314,7 @@ void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { } void SingleThreadProxy::SetNeedsCommitOnImplThread() { - layer_tree_host_->ScheduleComposite(); + client_->ScheduleComposite(); } void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( diff --git a/cc/trees/single_thread_proxy.h b/cc/trees/single_thread_proxy.h index e5b706f..7fd822e 100644 --- a/cc/trees/single_thread_proxy.h +++ b/cc/trees/single_thread_proxy.h @@ -17,10 +17,13 @@ namespace cc { class ContextProvider; class LayerTreeHost; +class LayerTreeHostSingleThreadClient; class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { public: - static scoped_ptr<Proxy> Create(LayerTreeHost* layer_tree_host); + static scoped_ptr<Proxy> Create( + LayerTreeHost* layer_tree_host, + LayerTreeHostSingleThreadClient* client); virtual ~SingleThreadProxy(); // Proxy implementation @@ -79,7 +82,8 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { void CompositeImmediately(base::TimeTicks frame_begin_time); private: - explicit SingleThreadProxy(LayerTreeHost* layer_tree_host); + SingleThreadProxy(LayerTreeHost* layer_tree_host, + LayerTreeHostSingleThreadClient* client); void OnOutputSurfaceInitializeAttempted(bool success); bool CommitAndComposite(base::TimeTicks frame_begin_time, @@ -100,6 +104,7 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { // Accessed on main thread only. LayerTreeHost* layer_tree_host_; + LayerTreeHostSingleThreadClient* client_; bool created_offscreen_context_provider_; // Holds the first output surface passed from Start. Should not be used for diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index 7bb93a7..3687a41 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -91,7 +91,6 @@ class OutputSurfaceWithoutParent : public cc::OutputSurface { }; static bool g_initialized = false; -static base::Thread* g_impl_thread = NULL; } // anonymous namespace @@ -120,11 +119,6 @@ bool CompositorImpl::IsInitialized() { } // static -bool CompositorImpl::IsThreadingEnabled() { - return g_impl_thread; -} - -// static jobject CompositorImpl::GetSurface(int surface_id) { base::AutoLock lock(g_surface_map_lock.Get()); SurfaceMap* surfaces = g_surface_map.Pointer(); @@ -226,12 +220,7 @@ void CompositorImpl::SetVisible(bool visible) { settings.use_memory_management = false; settings.highp_threshold_min = 2048; - scoped_refptr<base::SingleThreadTaskRunner> impl_thread_task_runner = - g_impl_thread ? g_impl_thread->message_loop()->message_loop_proxy() - : NULL; - - host_ = cc::LayerTreeHost::Create( - this, NULL, settings, impl_thread_task_runner); + host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); host_->SetRootLayer(root_layer_); host_->SetVisible(true); diff --git a/content/browser/renderer_host/compositor_impl_android.h b/content/browser/renderer_host/compositor_impl_android.h index 7ef04f7..ece532d 100644 --- a/content/browser/renderer_host/compositor_impl_android.h +++ b/content/browser/renderer_host/compositor_impl_android.h @@ -12,6 +12,7 @@ #include "base/memory/weak_ptr.h" #include "cc/resources/ui_resource_client.h" #include "cc/trees/layer_tree_host_client.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "content/browser/renderer_host/image_transport_factory_android.h" #include "content/common/content_export.h" #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" @@ -36,6 +37,7 @@ class GraphicsContext; class CONTENT_EXPORT CompositorImpl : public Compositor, public cc::LayerTreeHostClient, + public cc::LayerTreeHostSingleThreadClient, public WebGraphicsContext3DSwapBuffersClient, public ImageTransportFactoryAndroidObserver { public: @@ -43,7 +45,6 @@ class CONTENT_EXPORT CompositorImpl virtual ~CompositorImpl(); static bool IsInitialized(); - static bool IsThreadingEnabled(); // Returns the Java Surface object for a given view surface id. static jobject GetSurface(int surface_id); @@ -85,10 +86,14 @@ class CONTENT_EXPORT CompositorImpl virtual void DidCommit() OVERRIDE {} virtual void DidCommitAndDrawFrame() OVERRIDE {} virtual void DidCompleteSwapBuffers() OVERRIDE; - virtual void ScheduleComposite() OVERRIDE; virtual scoped_refptr<cc::ContextProvider> OffscreenContextProvider() OVERRIDE; + // LayerTreeHostSingleThreadClient implementation. + virtual void ScheduleComposite() OVERRIDE; + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} + // WebGraphicsContext3DSwapBuffersClient implementation. virtual void OnViewContextSwapBuffersPosted() OVERRIDE; virtual void OnViewContextSwapBuffersComplete() OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 8441767..2b7b6f0 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -827,11 +827,6 @@ void RenderWidgetHostViewAndroid::BuffersSwapped( ImageTransportFactoryAndroid* factory = ImageTransportFactoryAndroid::GetInstance(); - // TODO(sievers): When running the impl thread in the browser we - // need to delay the ACK until after commit and use more than a single - // texture. - DCHECK(!CompositorImpl::IsThreadingEnabled()); - if (!texture_id_in_layer_) { texture_id_in_layer_ = factory->CreateTexture(); texture_layer_->SetIsDrawable(true); diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index bea8b07..9d728cc 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -307,7 +307,7 @@ scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( } #endif - if (!compositor->initialize(settings)) + if (!compositor->Initialize(settings)) return scoped_ptr<RenderWidgetCompositor>(); return compositor.Pass(); @@ -413,11 +413,16 @@ bool RenderWidgetCompositor::ScheduleMicroBenchmark( return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); } -bool RenderWidgetCompositor::initialize(cc::LayerTreeSettings settings) { +bool RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) { scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy = RenderThreadImpl::current()->compositor_message_loop_proxy(); - layer_tree_host_ = cc::LayerTreeHost::Create( - this, NULL, settings, compositor_message_loop_proxy); + if (compositor_message_loop_proxy.get()) { + layer_tree_host_ = cc::LayerTreeHost::CreateThreaded( + this, NULL, settings, compositor_message_loop_proxy); + } else { + layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded( + this, this, NULL, settings); + } return layer_tree_host_; } @@ -638,16 +643,16 @@ void RenderWidgetCompositor::DidCompleteSwapBuffers() { widget_->didCompleteSwapBuffers(); } -void RenderWidgetCompositor::ScheduleComposite() { - if (!suppress_schedule_composite_) - widget_->scheduleComposite(); -} - scoped_refptr<cc::ContextProvider> RenderWidgetCompositor::OffscreenContextProvider() { return RenderThreadImpl::current()->OffscreenCompositorContextProvider(); } +void RenderWidgetCompositor::ScheduleComposite() { + if (!suppress_schedule_composite_) + widget_->scheduleComposite(); +} + void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { cc::ContextProvider* provider = RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); diff --git a/content/renderer/gpu/render_widget_compositor.h b/content/renderer/gpu/render_widget_compositor.h index d3019ce..44a3e8a 100644 --- a/content/renderer/gpu/render_widget_compositor.h +++ b/content/renderer/gpu/render_widget_compositor.h @@ -12,6 +12,7 @@ #include "cc/debug/rendering_stats.h" #include "cc/input/top_controls_state.h" #include "cc/trees/layer_tree_host_client.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "cc/trees/layer_tree_settings.h" #include "third_party/WebKit/public/platform/WebLayerTreeView.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -31,7 +32,8 @@ namespace content { class RenderWidget; class RenderWidgetCompositor : public WebKit::WebLayerTreeView, - public cc::LayerTreeHostClient { + public cc::LayerTreeHostClient, + public cc::LayerTreeHostSingleThreadClient { public: // Attempt to construct and initialize a compositor instance for the widget // with the given settings. Returns NULL if initialization fails. @@ -123,15 +125,19 @@ class RenderWidgetCompositor : public WebKit::WebLayerTreeView, virtual void DidCommit() OVERRIDE; virtual void DidCommitAndDrawFrame() OVERRIDE; virtual void DidCompleteSwapBuffers() OVERRIDE; - virtual void ScheduleComposite() OVERRIDE; virtual scoped_refptr<cc::ContextProvider> OffscreenContextProvider() OVERRIDE; virtual void RateLimitSharedMainThreadContext() OVERRIDE; + // cc::LayerTreeHostSingleThreadClient implementation. + virtual void ScheduleComposite() OVERRIDE; + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} + private: RenderWidgetCompositor(RenderWidget* widget, bool threaded); - bool initialize(cc::LayerTreeSettings settings); + bool Initialize(cc::LayerTreeSettings settings); bool threaded_; bool suppress_schedule_composite_; diff --git a/content/test/web_layer_tree_view_impl_for_testing.cc b/content/test/web_layer_tree_view_impl_for_testing.cc index 64be748..7858fd8 100644 --- a/content/test/web_layer_tree_view_impl_for_testing.cc +++ b/content/test/web_layer_tree_view_impl_for_testing.cc @@ -45,7 +45,8 @@ bool WebLayerTreeViewImplForTesting::Initialize() { // Accelerated animations are enabled for unit tests. settings.accelerated_animation_enabled = true; - layer_tree_host_ = cc::LayerTreeHost::Create(this, NULL, settings, NULL); + layer_tree_host_ = + cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); if (!layer_tree_host_) return false; return true; @@ -162,9 +163,6 @@ WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback) { new cc::OutputSurface(cc::TestContextProvider::Create())); } -void WebLayerTreeViewImplForTesting::ScheduleComposite() { -} - scoped_refptr<cc::ContextProvider> WebLayerTreeViewImplForTesting::OffscreenContextProvider() { // Unit tests only run in single threaded mode. diff --git a/content/test/web_layer_tree_view_impl_for_testing.h b/content/test/web_layer_tree_view_impl_for_testing.h index 8811ac0..6f0d4aa 100644 --- a/content/test/web_layer_tree_view_impl_for_testing.h +++ b/content/test/web_layer_tree_view_impl_for_testing.h @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "cc/trees/layer_tree_host_client.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "third_party/WebKit/public/platform/WebLayerTreeView.h" namespace cc { @@ -17,8 +18,10 @@ namespace WebKit { class WebLayer; } namespace webkit { -class WebLayerTreeViewImplForTesting : public WebKit::WebLayerTreeView, - public cc::LayerTreeHostClient { +class WebLayerTreeViewImplForTesting + : public WebKit::WebLayerTreeView, + public cc::LayerTreeHostClient, + public cc::LayerTreeHostSingleThreadClient { public: WebLayerTreeViewImplForTesting(); virtual ~WebLayerTreeViewImplForTesting(); @@ -70,10 +73,14 @@ class WebLayerTreeViewImplForTesting : public WebKit::WebLayerTreeView, virtual void DidCommit() OVERRIDE {} virtual void DidCommitAndDrawFrame() OVERRIDE {} virtual void DidCompleteSwapBuffers() OVERRIDE {} - virtual void ScheduleComposite() OVERRIDE; virtual scoped_refptr<cc::ContextProvider> OffscreenContextProvider() OVERRIDE; + // cc::LayerTreeHostSingleThreadClient implementation. + virtual void ScheduleComposite() OVERRIDE {} + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} + private: scoped_ptr<cc::LayerTreeHost> layer_tree_host_; diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index 1061424..41581f9 100644 --- a/ui/compositor/compositor.cc +++ b/ui/compositor/compositor.cc @@ -285,11 +285,12 @@ Compositor::Compositor(gfx::AcceleratedWidget widget) settings.initial_debug_state.show_non_occluding_rects = command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); - scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = - g_compositor_thread ? g_compositor_thread->message_loop_proxy() : NULL; - - host_ = - cc::LayerTreeHost::Create(this, NULL, settings, compositor_task_runner); + if (!!g_compositor_thread) { + host_ = cc::LayerTreeHost::CreateThreaded( + this, NULL, settings, g_compositor_thread->message_loop_proxy()); + } else { + host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); + } host_->SetRootLayer(root_web_layer_); host_->SetLayerTreeHostClientReady(); } @@ -557,15 +558,15 @@ void Compositor::DidCompleteSwapBuffers() { NotifyEnd(); } +scoped_refptr<cc::ContextProvider> Compositor::OffscreenContextProvider() { + return ContextFactory::GetInstance()->OffscreenCompositorContextProvider(); +} + void Compositor::ScheduleComposite() { if (!disable_schedule_composite_) ScheduleDraw(); } -scoped_refptr<cc::ContextProvider> Compositor::OffscreenContextProvider() { - return ContextFactory::GetInstance()->OffscreenCompositorContextProvider(); -} - const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { return host_->debug_state(); } diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h index 8b0aba6..348c022 100644 --- a/ui/compositor/compositor.h +++ b/ui/compositor/compositor.h @@ -13,6 +13,7 @@ #include "base/observer_list.h" #include "base/time/time.h" #include "cc/trees/layer_tree_host_client.h" +#include "cc/trees/layer_tree_host_single_thread_client.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/compositor/compositor_export.h" #include "ui/compositor/compositor_observer.h" @@ -219,6 +220,7 @@ class COMPOSITOR_EXPORT DrawWaiterForTest : public ui::CompositorObserver { // view hierarchy. class COMPOSITOR_EXPORT Compositor : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), + NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), public base::SupportsWeakPtr<Compositor> { public: explicit Compositor(gfx::AcceleratedWidget widget); @@ -321,10 +323,14 @@ class COMPOSITOR_EXPORT Compositor virtual void DidCommit() OVERRIDE; virtual void DidCommitAndDrawFrame() OVERRIDE; virtual void DidCompleteSwapBuffers() OVERRIDE; - virtual void ScheduleComposite() OVERRIDE; virtual scoped_refptr<cc::ContextProvider> OffscreenContextProvider() OVERRIDE; + // cc::LayerTreeHostSingleThreadClient implementation. + virtual void ScheduleComposite() OVERRIDE; + virtual void DidPostSwapBuffers() OVERRIDE {} + virtual void DidAbortSwapBuffers() OVERRIDE {} + int last_started_frame() { return last_started_frame_; } int last_ended_frame() { return last_ended_frame_; } |