summaryrefslogtreecommitdiffstats
path: root/cc/test
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-22 20:32:05 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-22 20:32:05 +0000
commit0a4517266a77d10a276d6c674efafc79e4c7f7a5 (patch)
tree88b095919aa268128698e980d9b780b09f839aad /cc/test
parent3395887c69c58e75b084ef919dc88fd037bb9bc0 (diff)
downloadchromium_src-0a4517266a77d10a276d6c674efafc79e4c7f7a5.zip
chromium_src-0a4517266a77d10a276d6c674efafc79e4c7f7a5.tar.gz
chromium_src-0a4517266a77d10a276d6c674efafc79e4c7f7a5.tar.bz2
cc: Route offscreen context creation for compositor to the browser.
Currently the compositor asks WebKit for the SharedGraphicsContext. For the browser compositor, we instead route requests for an offscreen context to ui/compositor, where we are able to create the context. This patch only addresses offscreen contexts for the browser compositor. The renderer compositor still gets its contexts from WebKit, but now via the LayerTreeHostClient interface instead of directly going to the WebSharedGraphicsContext3D. Tested by the lost context unit tests. They now test that on context loss, the shared context is also recreated, and that if it fails to be recreated that we retry context creation. BUG=169373,175383 Review URL: https://chromiumcodereview.appspot.com/12212007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r--cc/test/fake_context_provider.cc61
-rw-r--r--cc/test/fake_context_provider.h45
-rw-r--r--cc/test/fake_layer_tree_host_client.cc23
-rw-r--r--cc/test/fake_layer_tree_host_client.h14
-rw-r--r--cc/test/layer_tree_test_common.cc37
-rw-r--r--cc/test/layer_tree_test_common.h15
-rw-r--r--cc/test/test_web_graphics_context_3d.cc4
-rw-r--r--cc/test/test_web_graphics_context_3d.h6
8 files changed, 198 insertions, 7 deletions
diff --git a/cc/test/fake_context_provider.cc b/cc/test/fake_context_provider.cc
new file mode 100644
index 0000000..ed777fc
--- /dev/null
+++ b/cc/test/fake_context_provider.cc
@@ -0,0 +1,61 @@
+// 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.
+
+#include "cc/test/fake_context_provider.h"
+
+#include "cc/test/test_web_graphics_context_3d.h"
+
+namespace cc {
+
+FakeContextProvider::FakeContextProvider()
+ : destroyed_(false) {
+}
+
+FakeContextProvider::FakeContextProvider(
+ const CreateCallback& create_callback)
+ : create_callback_(create_callback),
+ destroyed_(false) {
+}
+
+FakeContextProvider::~FakeContextProvider() {}
+
+bool FakeContextProvider::InitializeOnMainThread() {
+ if (destroyed_)
+ return false;
+ if (context3d_)
+ return true;
+
+ if (create_callback_.is_null())
+ context3d_ = TestWebGraphicsContext3D::Create().Pass();
+ else
+ context3d_ = create_callback_.Run();
+ destroyed_ = !context3d_;
+ return !!context3d_;
+}
+
+bool FakeContextProvider::BindToCurrentThread() {
+ return context3d_->makeContextCurrent();
+}
+
+WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
+ return context3d_.get();
+}
+class GrContext* FakeContextProvider::GrContext() {
+ // TODO(danakj): Make a fake GrContext.
+ return NULL;
+}
+
+void FakeContextProvider::VerifyContexts() {
+ if (!Context3d() || Context3d()->isContextLost()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ }
+}
+
+bool FakeContextProvider::DestroyedOnMainThread() {
+ base::AutoLock lock(destroyed_lock_);
+ return destroyed_;
+}
+
+} // namespace cc
diff --git a/cc/test/fake_context_provider.h b/cc/test/fake_context_provider.h
new file mode 100644
index 0000000..f7c1839
--- /dev/null
+++ b/cc/test/fake_context_provider.h
@@ -0,0 +1,45 @@
+// 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_TEST_FAKE_CONTEXT_PROVIDER_H_
+#define CC_TEST_FAKE_CONTEXT_PROVIDER_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
+#include "cc/context_provider.h"
+
+namespace cc {
+class TestWebGraphicsContext3D;
+
+class FakeContextProvider : public cc::ContextProvider {
+ public:
+ typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)>
+ CreateCallback;
+
+ FakeContextProvider();
+ explicit FakeContextProvider(const CreateCallback& create_callback);
+
+ virtual bool InitializeOnMainThread() OVERRIDE;
+ virtual bool BindToCurrentThread() OVERRIDE;
+ virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
+ virtual class GrContext* GrContext() OVERRIDE;
+ virtual void VerifyContexts() OVERRIDE;
+
+ bool DestroyedOnMainThread();
+
+ protected:
+ virtual ~FakeContextProvider();
+
+ CreateCallback create_callback_;
+ scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
+
+ base::Lock destroyed_lock_;
+ bool destroyed_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_FAKE_CONTEXT_PROVIDER_H_
+
diff --git a/cc/test/fake_layer_tree_host_client.cc b/cc/test/fake_layer_tree_host_client.cc
index e3e7735..253f5fd 100644
--- a/cc/test/fake_layer_tree_host_client.cc
+++ b/cc/test/fake_layer_tree_host_client.cc
@@ -4,8 +4,19 @@
#include "cc/test/fake_layer_tree_host_client.h"
+#include "cc/context_provider.h"
+#include "cc/test/test_web_graphics_context_3d.h"
+
namespace cc {
+FakeLayerImplTreeHostClient::FakeLayerImplTreeHostClient(bool useSoftwareRendering, bool useDelegatingRenderer)
+ : m_useSoftwareRendering(useSoftwareRendering)
+ , m_useDelegatingRenderer(useDelegatingRenderer)
+{
+}
+
+FakeLayerImplTreeHostClient::~FakeLayerImplTreeHostClient() { }
+
scoped_ptr<OutputSurface> FakeLayerImplTreeHostClient::createOutputSurface()
{
if (m_useSoftwareRendering) {
@@ -27,4 +38,16 @@ scoped_ptr<InputHandler> FakeLayerImplTreeHostClient::createInputHandler()
return scoped_ptr<InputHandler>();
}
+scoped_refptr<cc::ContextProvider> FakeLayerImplTreeHostClient::OffscreenContextProviderForMainThread() {
+ if (!m_mainThreadContexts || m_mainThreadContexts->DestroyedOnMainThread())
+ m_mainThreadContexts = new FakeContextProvider;
+ return m_mainThreadContexts;
+}
+
+scoped_refptr<cc::ContextProvider> FakeLayerImplTreeHostClient::OffscreenContextProviderForCompositorThread() {
+ if (!m_compositorThreadContexts || m_compositorThreadContexts->DestroyedOnMainThread())
+ m_compositorThreadContexts = new FakeContextProvider;
+ return m_compositorThreadContexts;
+}
+
} // namespace cc
diff --git a/cc/test/fake_layer_tree_host_client.h b/cc/test/fake_layer_tree_host_client.h
index f10ba59..65a40ef 100644
--- a/cc/test/fake_layer_tree_host_client.h
+++ b/cc/test/fake_layer_tree_host_client.h
@@ -8,17 +8,15 @@
#include "base/memory/scoped_ptr.h"
#include "cc/input_handler.h"
#include "cc/layer_tree_host.h"
+#include "cc/test/fake_context_provider.h"
#include "cc/test/fake_output_surface.h"
namespace cc {
class FakeLayerImplTreeHostClient : public LayerTreeHostClient {
public:
- FakeLayerImplTreeHostClient(bool useSoftwareRendering = false, bool useDelegatingRenderer = false)
- : m_useSoftwareRendering(useSoftwareRendering)
- , m_useDelegatingRenderer(useDelegatingRenderer)
- {
- }
+ FakeLayerImplTreeHostClient(bool useSoftwareRendering = false, bool useDelegatingRenderer = false);
+ virtual ~FakeLayerImplTreeHostClient();
virtual void willBeginFrame() OVERRIDE { }
virtual void didBeginFrame() OVERRIDE { }
@@ -37,9 +35,15 @@ public:
// Used only in the single-threaded path.
virtual void scheduleComposite() OVERRIDE { }
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForMainThread() OVERRIDE;
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE;
+
private:
bool m_useSoftwareRendering;
bool m_useDelegatingRenderer;
+
+ scoped_refptr<FakeContextProvider> m_mainThreadContexts;
+ scoped_refptr<FakeContextProvider> m_compositorThreadContexts;
};
} // namespace cc
diff --git a/cc/test/layer_tree_test_common.cc b/cc/test/layer_tree_test_common.cc
index 4bd689c..0100135 100644
--- a/cc/test/layer_tree_test_common.cc
+++ b/cc/test/layer_tree_test_common.cc
@@ -15,6 +15,7 @@
#include "cc/single_thread_proxy.h"
#include "cc/thread_impl.h"
#include "cc/test/animation_test_common.h"
+#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/occlusion_tracker_test_common.h"
#include "cc/test/tiled_layer_test_common.h"
@@ -28,6 +29,15 @@ using namespace WebKit;
namespace cc {
+TestHooks::TestHooks()
+{
+ bool useSoftwareRendering = false;
+ bool useDelegatingRenderer = false;
+ m_fakeClient.reset(new FakeLayerImplTreeHostClient(useSoftwareRendering, useDelegatingRenderer));
+}
+
+TestHooks::~TestHooks() { }
+
bool TestHooks::prepareToDrawOnThread(cc::LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool)
{
return true;
@@ -43,6 +53,16 @@ scoped_ptr<OutputSurface> TestHooks::createOutputSurface()
return createFakeOutputSurface();
}
+scoped_refptr<cc::ContextProvider> TestHooks::OffscreenContextProviderForMainThread()
+{
+ return m_fakeClient->OffscreenContextProviderForMainThread();
+}
+
+scoped_refptr<cc::ContextProvider> TestHooks::OffscreenContextProviderForCompositorThread()
+{
+ return m_fakeClient->OffscreenContextProviderForCompositorThread();
+}
+
scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy)
{
return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client, proxy));
@@ -198,6 +218,11 @@ public:
m_testHooks->didRecreateOutputSurface(succeeded);
}
+ virtual void willRetryRecreateOutputSurface() OVERRIDE
+ {
+ m_testHooks->willRetryRecreateOutputSurface();
+ }
+
virtual scoped_ptr<InputHandler> createInputHandler() OVERRIDE
{
return scoped_ptr<InputHandler>();
@@ -226,6 +251,16 @@ public:
m_testHooks->scheduleComposite();
}
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForMainThread() OVERRIDE
+ {
+ return m_testHooks->OffscreenContextProviderForMainThread();
+ }
+
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE
+ {
+ return m_testHooks->OffscreenContextProviderForCompositorThread();
+ }
+
private:
explicit ThreadedMockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks(testHooks) { }
@@ -312,8 +347,6 @@ void ThreadedTest::doBeginTest()
if (m_endWhenBeginReturns)
realEndTest();
- LayerTreeHost::setNeedsFilterContext(false);
-
// Allow commits to happen once beginTest() has had a chance to post tasks
// so that those tasks will happen before the first commit.
if (m_layerTreeHost)
diff --git a/cc/test/layer_tree_test_common.h b/cc/test/layer_tree_test_common.h
index 82144bd..b7352bf 100644
--- a/cc/test/layer_tree_test_common.h
+++ b/cc/test/layer_tree_test_common.h
@@ -13,7 +13,12 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegate.h"
+namespace Webkit {
+class WebGraphicsContext3D;
+}
+
namespace cc {
+class FakeLayerImplTreeHostClient;
class LayerImpl;
class LayerTreeHost;
class LayerTreeHostClient;
@@ -22,6 +27,9 @@ class LayerTreeHostImpl;
// Used by test stubs to notify the test when something interesting happens.
class TestHooks : public WebKit::WebAnimationDelegate {
public:
+ TestHooks();
+ virtual ~TestHooks();
+
virtual void beginCommitOnThread(LayerTreeHostImpl*) { }
virtual void commitCompleteOnThread(LayerTreeHostImpl*) { }
virtual bool prepareToDrawOnThread(
@@ -34,6 +42,7 @@ public:
virtual void animate(base::TimeTicks monotonicTime) { }
virtual void layout() { }
virtual void didRecreateOutputSurface(bool succeeded) { }
+ virtual void willRetryRecreateOutputSurface() { }
virtual void didAddAnimation() { }
virtual void didCommit() { }
virtual void didCommitAndDrawFrame() { }
@@ -46,6 +55,12 @@ public:
virtual void notifyAnimationFinished(double time) OVERRIDE { }
virtual scoped_ptr<OutputSurface> createOutputSurface();
+
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForMainThread();
+ virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread();
+
+private:
+ scoped_ptr<FakeLayerImplTreeHostClient> m_fakeClient;
};
class TimeoutTask;
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
index c1ac0e7..b4a2c7e 100644
--- a/cc/test/test_web_graphics_context_3d.cc
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -302,6 +302,10 @@ void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
context_lost_ = true;
if (context_lost_callback_)
context_lost_callback_->onContextLost();
+
+ for (size_t i = 0; i < shared_contexts_.size(); ++i)
+ shared_contexts_[i]->loseContextCHROMIUM(current, other);
+ shared_contexts_.clear();
}
WebKit::WebGLId TestWebGraphicsContext3D::NextTextureId() {
diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h
index abfd9c9..212da16 100644
--- a/cc/test/test_web_graphics_context_3d.h
+++ b/cc/test/test_web_graphics_context_3d.h
@@ -122,6 +122,11 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
have_extension_egl_image_ = have;
}
+ // When this context is lost, all contexts in its share group are also lost.
+ void add_share_group_context(WebKit::WebGraphicsContext3D* context3d) {
+ shared_contexts_.push_back(context3d);
+ }
+
static const WebKit::WebGLId kExternalTextureId;
virtual WebKit::WebGLId NextTextureId();
@@ -142,6 +147,7 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
WebGraphicsContextLostCallback* context_lost_callback_;
std::vector<WebKit::WebGLId> textures_;
base::hash_set<WebKit::WebGLId> used_textures_;
+ std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
int width_;
int height_;
};