summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-07 05:01:32 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-07 05:01:32 +0000
commit943528e092b0a1c242c75af60c7b08385908e954 (patch)
tree02904b3b722389bbe339cfd4a892c57a65016fbd /cc
parent341acce17f767566e8602902055a29996e85ff64 (diff)
downloadchromium_src-943528e092b0a1c242c75af60c7b08385908e954.zip
chromium_src-943528e092b0a1c242c75af60c7b08385908e954.tar.gz
chromium_src-943528e092b0a1c242c75af60c7b08385908e954.tar.bz2
Introduce separate client and init path for single-threaded cc
The chromium compositor can be used in either a single-threaded fashion or multi-threaded. The requirements, APIs and responsibilities of the embedder are different for these two modes. Some users of cc only use one path or the other. This adds a separate client interface and initialization path for code that only uses the single threaded path. Having a dedicated client for the single threaded path will make it possible to get rid of the WebGraphicsContext3DSwapBuffersClient which will then make it easier to break cc's dependency on WGC3D. R=piman BUG=181120 Review URL: https://codereview.chromium.org/61823008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/layers/layer_unittest.cc15
-rw-r--r--cc/layers/nine_patch_layer_unittest.cc17
-rw-r--r--cc/layers/scrollbar_layer_unittest.cc4
-rw-r--r--cc/layers/texture_layer_unittest.cc4
-rw-r--r--cc/layers/tiled_layer_unittest.cc9
-rw-r--r--cc/layers/ui_resource_layer_unittest.cc16
-rw-r--r--cc/test/fake_layer_tree_host.h3
-rw-r--r--cc/test/fake_layer_tree_host_client.h14
-rw-r--r--cc/test/layer_tree_test.cc110
-rw-r--r--cc/trees/layer_tree_host.cc44
-rw-r--r--cc/trees/layer_tree_host.h19
-rw-r--r--cc/trees/layer_tree_host_client.h3
-rw-r--r--cc/trees/layer_tree_host_single_thread_client.h29
-rw-r--r--cc/trees/layer_tree_host_unittest.cc8
-rw-r--r--cc/trees/layer_tree_host_unittest_context.cc21
-rw-r--r--cc/trees/layer_tree_host_unittest_scroll.cc2
-rw-r--r--cc/trees/single_thread_proxy.cc20
-rw-r--r--cc/trees/single_thread_proxy.h9
18 files changed, 202 insertions, 145 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