summaryrefslogtreecommitdiffstats
path: root/cc/test
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 00:46:09 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 00:46:09 +0000
commit0634cdd4173783be804661c755cb111e1f49034d (patch)
tree841b3e44e6c0f76a6345fa78b50cbb53c912eb65 /cc/test
parentfbe4952b1c18689bc7129267d375889cf96cd230 (diff)
downloadchromium_src-0634cdd4173783be804661c755cb111e1f49034d.zip
chromium_src-0634cdd4173783be804661c755cb111e1f49034d.tar.gz
chromium_src-0634cdd4173783be804661c755cb111e1f49034d.tar.bz2
ContextProvider in OutputSurface
Instead of putting a raw WebGraphicsContext3D in the OutputSurface given to the compositor, put a ContextProvider. This requires embedders to create ContextProviders instead of raw contexts. No change in behaviour. Covered by existing tests, including cc/ context loss tests. BUG=258625 R=aelias@chromium.org, jamesr@chromium.org, piman@chromium.org, sievers@chromium.org Review URL: https://codereview.chromium.org/20185002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r--cc/test/fake_context_provider.cc110
-rw-r--r--cc/test/fake_layer_tree_host_client.cc9
-rw-r--r--cc/test/fake_output_surface.cc17
-rw-r--r--cc/test/fake_output_surface.h61
-rw-r--r--cc/test/layer_tree_pixel_test.cc9
-rw-r--r--cc/test/layer_tree_test.cc2
-rw-r--r--cc/test/pixel_test.cc7
-rw-r--r--cc/test/pixel_test_output_surface.h4
8 files changed, 161 insertions, 58 deletions
diff --git a/cc/test/fake_context_provider.cc b/cc/test/fake_context_provider.cc
new file mode 100644
index 0000000..806eb4f
--- /dev/null
+++ b/cc/test/fake_context_provider.cc
@@ -0,0 +1,110 @@
+// 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 "base/bind.h"
+#include "cc/test/test_web_graphics_context_3d.h"
+
+namespace cc {
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::
+ CreateForOtherThread() {
+ scoped_refptr<FakeContextProvider> provider = new FakeContextProvider();
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+static scoped_ptr<TestWebGraphicsContext3D> ReturnContext(
+ scoped_ptr<TestWebGraphicsContext3D> context3d) {
+ return context3d.Pass();
+}
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::CreateForOtherThread(
+ scoped_ptr<TestWebGraphicsContext3D> context3d) {
+ CreateCallback create_callback =
+ base::Bind(&ReturnContext, base::Passed(&context3d));
+ scoped_refptr<FakeContextProvider> provider =
+ new FakeContextProvider(create_callback);
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::CreateForOtherThread(
+ const CreateCallback& create_callback) {
+ scoped_refptr<FakeContextProvider> provider =
+ new FakeContextProvider(create_callback);
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+FakeContextProvider::FakeContextProvider()
+ : destroyed_(false) {
+}
+
+FakeContextProvider::FakeContextProvider(
+ const CreateCallback& create_callback)
+ : create_callback_(create_callback),
+ bound_(false),
+ destroyed_(false) {
+}
+
+FakeContextProvider::~FakeContextProvider() {}
+
+bool FakeContextProvider::InitializeOnMainThread() {
+ DCHECK(!context3d_);
+
+ if (create_callback_.is_null())
+ context3d_ = TestWebGraphicsContext3D::Create().Pass();
+ else
+ context3d_ = create_callback_.Run();
+ return context3d_;
+}
+
+bool FakeContextProvider::BindToCurrentThread() {
+ bound_ = true;
+ if (!context3d_->makeContextCurrent()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ return false;
+ }
+ return true;
+}
+
+WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ return context3d_.get();
+}
+class GrContext* FakeContextProvider::GrContext() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ // TODO(danakj): Make a fake GrContext.
+ return NULL;
+}
+
+void FakeContextProvider::VerifyContexts() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ if (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_layer_tree_host_client.cc b/cc/test/fake_layer_tree_host_client.cc
index 71b0f4d..621fc99 100644
--- a/cc/test/fake_layer_tree_host_client.cc
+++ b/cc/test/fake_layer_tree_host_client.cc
@@ -32,22 +32,21 @@ scoped_ptr<OutputSurface> FakeLayerTreeHostClient::CreateOutputSurface(
if (use_delegating_renderer_)
return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>();
-
- return CreateFakeOutputSurface();
+ return FakeOutputSurface::Create3d().PassAs<OutputSurface>();
}
-scoped_refptr<cc::ContextProvider> FakeLayerTreeHostClient::
+scoped_refptr<ContextProvider> FakeLayerTreeHostClient::
OffscreenContextProviderForMainThread() {
if (!main_thread_contexts_.get() ||
main_thread_contexts_->DestroyedOnMainThread()) {
main_thread_contexts_ = TestContextProvider::Create();
- if (!main_thread_contexts_->BindToCurrentThread())
+ if (main_thread_contexts_ && !main_thread_contexts_->BindToCurrentThread())
main_thread_contexts_ = NULL;
}
return main_thread_contexts_;
}
-scoped_refptr<cc::ContextProvider> FakeLayerTreeHostClient::
+scoped_refptr<ContextProvider> FakeLayerTreeHostClient::
OffscreenContextProviderForCompositorThread() {
if (!compositor_thread_contexts_.get() ||
compositor_thread_contexts_->DestroyedOnMainThread())
diff --git a/cc/test/fake_output_surface.cc b/cc/test/fake_output_surface.cc
index 9ae7552..32367fd 100644
--- a/cc/test/fake_output_surface.cc
+++ b/cc/test/fake_output_surface.cc
@@ -13,9 +13,9 @@
namespace cc {
FakeOutputSurface::FakeOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ scoped_refptr<ContextProvider> context_provider,
bool delegated_rendering)
- : OutputSurface(context3d.Pass()),
+ : OutputSurface(context_provider),
client_(NULL),
num_sent_frames_(0),
needs_begin_frame_(false),
@@ -41,10 +41,10 @@ FakeOutputSurface::FakeOutputSurface(
}
FakeOutputSurface::FakeOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ scoped_refptr<ContextProvider> context_provider,
scoped_ptr<SoftwareOutputDevice> software_device,
bool delegated_rendering)
- : OutputSurface(context3d.Pass(), software_device.Pass()),
+ : OutputSurface(context_provider, software_device.Pass()),
client_(NULL),
num_sent_frames_(0),
forced_draw_to_software_device_(false),
@@ -59,7 +59,7 @@ FakeOutputSurface::~FakeOutputSurface() {}
void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
if (frame->software_frame_data || frame->delegated_frame_data ||
- !context3d()) {
+ !context_provider()) {
frame->AssignTo(&last_sent_frame_);
if (last_sent_frame_.delegated_frame_data) {
@@ -111,13 +111,6 @@ bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
}
}
-bool FakeOutputSurface::SetAndInitializeContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d) {
- context3d_.reset();
- return InitializeAndSetContext3D(context3d.Pass(),
- scoped_refptr<ContextProvider>());
-}
-
void FakeOutputSurface::SetTreeActivationCallback(
const base::Closure& callback) {
DCHECK(client_);
diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h
index 12fdcfc..3f87bd3 100644
--- a/cc/test/fake_output_surface.h
+++ b/cc/test/fake_output_surface.h
@@ -6,13 +6,14 @@
#define CC_TEST_FAKE_OUTPUT_SURFACE_H_
#include "base/callback.h"
+#include "base/logging.h"
#include "base/time/time.h"
+#include "cc/debug/test_context_provider.h"
#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/output_surface.h"
#include "cc/output/software_output_device.h"
-#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
namespace cc {
@@ -20,34 +21,42 @@ class FakeOutputSurface : public OutputSurface {
public:
virtual ~FakeOutputSurface();
+ static scoped_ptr<FakeOutputSurface> Create3d() {
+ return make_scoped_ptr(new FakeOutputSurface(
+ TestContextProvider::Create(), false));
+ }
+
static scoped_ptr<FakeOutputSurface> Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d) {
- return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), false));
+ scoped_refptr<TestContextProvider> context_provider) {
+ return make_scoped_ptr(new FakeOutputSurface(context_provider, false));
}
- static scoped_ptr<FakeOutputSurface> Create3d() {
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create()
- .PassAs<WebKit::WebGraphicsContext3D>();
- return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), false));
+ static scoped_ptr<FakeOutputSurface> Create3d(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return make_scoped_ptr(new FakeOutputSurface(
+ TestContextProvider::Create(context.Pass()), false));
}
static scoped_ptr<FakeOutputSurface> CreateSoftware(
scoped_ptr<SoftwareOutputDevice> software_device) {
- return make_scoped_ptr(
- new FakeOutputSurface(software_device.Pass(), false));
+ return make_scoped_ptr(new FakeOutputSurface(software_device.Pass(),
+ false));
+ }
+
+ static scoped_ptr<FakeOutputSurface> CreateDelegating3d() {
+ return make_scoped_ptr(new FakeOutputSurface(
+ TestContextProvider::Create(), true));
}
static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d) {
- return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), true));
+ scoped_refptr<TestContextProvider> context_provider) {
+ return make_scoped_ptr(new FakeOutputSurface(context_provider, true));
}
- static scoped_ptr<FakeOutputSurface> CreateDelegating3d() {
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create()
- .PassAs<WebKit::WebGraphicsContext3D>();
- return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), true));
+ static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return make_scoped_ptr(new FakeOutputSurface(
+ TestContextProvider::Create(context.Pass()), true));
}
static scoped_ptr<FakeOutputSurface> CreateDelegatingSoftware(
@@ -66,9 +75,9 @@ class FakeOutputSurface : public OutputSurface {
}
static scoped_ptr<FakeOutputSurface> CreateAlwaysDrawAndSwap3d() {
- scoped_ptr<FakeOutputSurface> result(Create3d());
- result->capabilities_.draw_and_swap_full_viewport_every_frame = true;
- return result.Pass();
+ scoped_ptr<FakeOutputSurface> surface(Create3d());
+ surface->capabilities_.draw_and_swap_full_viewport_every_frame = true;
+ return surface.Pass();
}
CompositorFrame& last_sent_frame() { return last_sent_frame_; }
@@ -88,10 +97,8 @@ class FakeOutputSurface : public OutputSurface {
virtual bool BindToClient(OutputSurfaceClient* client) OVERRIDE;
- bool SetAndInitializeContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d);
-
using OutputSurface::ReleaseGL;
+ using OutputSurface::InitializeAndSetContext3d;
void SetTreeActivationCallback(const base::Closure& callback);
@@ -103,7 +110,7 @@ class FakeOutputSurface : public OutputSurface {
protected:
FakeOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ scoped_refptr<ContextProvider> context_provider,
bool delegated_rendering);
FakeOutputSurface(
@@ -111,7 +118,7 @@ class FakeOutputSurface : public OutputSurface {
bool delegated_rendering);
FakeOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ scoped_refptr<ContextProvider> context_provider,
scoped_ptr<SoftwareOutputDevice> software_device,
bool delegated_rendering);
@@ -126,8 +133,8 @@ class FakeOutputSurface : public OutputSurface {
TransferableResourceArray resources_held_by_parent_;
};
-static inline scoped_ptr<cc::OutputSurface> CreateFakeOutputSurface() {
- return FakeOutputSurface::Create3d().PassAs<cc::OutputSurface>();
+static inline scoped_ptr<OutputSurface> CreateFakeOutputSurface() {
+ return FakeOutputSurface::Create3d().PassAs<OutputSurface>();
}
} // namespace cc
diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc
index a0fac61..16d7187 100644
--- a/cc/test/layer_tree_pixel_test.cc
+++ b/cc/test/layer_tree_pixel_test.cc
@@ -52,12 +52,9 @@ scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface(
case GL_WITH_BITMAP: {
CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
- using WebKit::WebGraphicsContext3D;
- using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
- scoped_ptr<WebGraphicsContext3D> context(
- WebGraphicsContext3DInProcessCommandBufferImpl::
- CreateOffscreenContext(WebGraphicsContext3D::Attributes()));
- output_surface.reset(new PixelTestOutputSurface(context.Pass()));
+ using webkit::gpu::ContextProviderInProcess;
+ output_surface = make_scoped_ptr(new PixelTestOutputSurface(
+ ContextProviderInProcess::CreateOffscreen()));
break;
}
}
diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc
index 7192f6d..6795f90 100644
--- a/cc/test/layer_tree_test.cc
+++ b/cc/test/layer_tree_test.cc
@@ -616,7 +616,7 @@ scoped_refptr<cc::ContextProvider> LayerTreeTest::
if (!main_thread_contexts_.get() ||
main_thread_contexts_->DestroyedOnMainThread()) {
main_thread_contexts_ = TestContextProvider::Create();
- if (!main_thread_contexts_->BindToCurrentThread())
+ if (main_thread_contexts_ && !main_thread_contexts_->BindToCurrentThread())
main_thread_contexts_ = NULL;
}
return main_thread_contexts_;
diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc
index c742355..dffe378 100644
--- a/cc/test/pixel_test.cc
+++ b/cc/test/pixel_test.cc
@@ -148,12 +148,9 @@ void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend) {
CHECK(fake_client_);
CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
- using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d(
- WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
- WebKit::WebGraphicsContext3D::Attributes()));
+ using webkit::gpu::ContextProviderInProcess;
output_surface_.reset(new PixelTestOutputSurface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>()));
+ ContextProviderInProcess::CreateOffscreen()));
output_surface_->BindToClient(fake_client_.get());
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
diff --git a/cc/test/pixel_test_output_surface.h b/cc/test/pixel_test_output_surface.h
index ec7a828..e9052fe 100644
--- a/cc/test/pixel_test_output_surface.h
+++ b/cc/test/pixel_test_output_surface.h
@@ -12,8 +12,8 @@ namespace cc {
class PixelTestOutputSurface : public OutputSurface {
public:
explicit PixelTestOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : OutputSurface(context3d.Pass()) {}
+ scoped_refptr<ContextProvider> context_provider)
+ : OutputSurface(context_provider) {}
explicit PixelTestOutputSurface(
scoped_ptr<cc::SoftwareOutputDevice> software_device)
: OutputSurface(software_device.Pass()) {}