summaryrefslogtreecommitdiffstats
path: root/cc
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
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')
-rw-r--r--cc/DEPS1
-rw-r--r--cc/debug/fake_web_graphics_context_3d.h3
-rw-r--r--cc/debug/test_context_provider.cc105
-rw-r--r--cc/debug/test_context_provider.h23
-rw-r--r--cc/debug/test_web_graphics_context_3d.cc20
-rw-r--r--cc/debug/test_web_graphics_context_3d.h12
-rw-r--r--cc/layers/delegated_renderer_layer_impl_unittest.cc7
-rw-r--r--cc/layers/io_surface_layer_impl.cc16
-rw-r--r--cc/layers/nine_patch_layer_unittest.cc5
-rw-r--r--cc/layers/picture_layer_impl_unittest.cc5
-rw-r--r--cc/layers/texture_layer_unittest.cc15
-rw-r--r--cc/layers/tiled_layer_unittest.cc8
-rw-r--r--cc/layers/video_layer_impl.cc7
-rw-r--r--cc/output/context_provider.h15
-rw-r--r--cc/output/delegating_renderer.cc32
-rw-r--r--cc/output/gl_renderer.cc6
-rw-r--r--cc/output/gl_renderer_unittest.cc447
-rw-r--r--cc/output/output_surface.cc171
-rw-r--r--cc/output/output_surface.h25
-rw-r--r--cc/output/output_surface_unittest.cc159
-rw-r--r--cc/output/renderer_pixeltest.cc7
-rw-r--r--cc/output/software_renderer_unittest.cc4
-rw-r--r--cc/resources/picture_layer_tiling_set_unittest.cc4
-rw-r--r--cc/resources/prioritized_resource_unittest.cc5
-rw-r--r--cc/resources/prioritized_tile_set_unittest.cc20
-rw-r--r--cc/resources/raster_worker_pool_unittest.cc16
-rw-r--r--cc/resources/resource_provider.cc82
-rw-r--r--cc/resources/resource_provider.h8
-rw-r--r--cc/resources/resource_provider_unittest.cc248
-rw-r--r--cc/resources/resource_update_controller_unittest.cc10
-rw-r--r--cc/resources/scoped_resource_unittest.cc29
-rw-r--r--cc/resources/tile_manager_unittest.cc4
-rw-r--r--cc/resources/video_resource_updater.cc27
-rw-r--r--cc/resources/video_resource_updater.h5
-rw-r--r--cc/resources/video_resource_updater_unittest.cc13
-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
-rw-r--r--cc/trees/layer_tree_host_impl.cc8
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc156
-rw-r--r--cc/trees/layer_tree_host_unittest.cc62
-rw-r--r--cc/trees/layer_tree_host_unittest_context.cc36
-rw-r--r--cc/trees/layer_tree_host_unittest_delegated.cc10
-rw-r--r--cc/trees/layer_tree_impl.cc4
-rw-r--r--cc/trees/layer_tree_impl.h2
50 files changed, 1204 insertions, 857 deletions
diff --git a/cc/DEPS b/cc/DEPS
index ad58eba..e0482b6 100644
--- a/cc/DEPS
+++ b/cc/DEPS
@@ -12,5 +12,4 @@ include_rules = [
# DO NOT ADD ANY NEW WEBKIT HEADERS TO THIS LIST.
# TODO(danakj): Drop dependencies on WebKit Platform API from cc.
"+third_party/WebKit/public/platform/WebGraphicsContext3D.h",
- "+third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h",
]
diff --git a/cc/debug/fake_web_graphics_context_3d.h b/cc/debug/fake_web_graphics_context_3d.h
index 3c8a6f5..04c983d 100644
--- a/cc/debug/fake_web_graphics_context_3d.h
+++ b/cc/debug/fake_web_graphics_context_3d.h
@@ -67,9 +67,6 @@ class CC_EXPORT FakeWebGraphicsContext3D
WebKit::WGC3Dsizei num_attachments,
const WebKit::WGC3Denum* attachments) {}
- virtual void setMemoryAllocationChangedCallbackCHROMIUM(
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) {}
-
virtual WebKit::WebString getRequestableExtensionsCHROMIUM();
virtual void requestExtensionCHROMIUM(const char*) {}
diff --git a/cc/debug/test_context_provider.cc b/cc/debug/test_context_provider.cc
index 4a3a2fc..55fc74f 100644
--- a/cc/debug/test_context_provider.cc
+++ b/cc/debug/test_context_provider.cc
@@ -4,14 +4,57 @@
#include "cc/debug/test_context_provider.h"
+#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/logging.h"
#include "cc/debug/test_web_graphics_context_3d.h"
namespace cc {
+class TestContextProvider::LostContextCallbackProxy
+ : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
+ public:
+ explicit LostContextCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setContextLostCallback(this);
+ }
+
+ virtual ~LostContextCallbackProxy() {
+ provider_->context3d_->setContextLostCallback(NULL);
+ }
+
+ virtual void onContextLost() {
+ provider_->OnLostContext();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
+class TestContextProvider::SwapBuffersCompleteCallbackProxy
+ : public WebKit::WebGraphicsContext3D::
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
+ public:
+ explicit SwapBuffersCompleteCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this);
+ }
+
+ virtual ~SwapBuffersCompleteCallbackProxy() {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
+ }
+
+ virtual void onSwapBuffersComplete() {
+ provider_->OnSwapBuffersComplete();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
// static
scoped_refptr<TestContextProvider> TestContextProvider::Create() {
- return Create(TestWebGraphicsContext3D::CreateFactory());
+ return Create(TestWebGraphicsContext3D::Create().Pass());
}
// static
@@ -23,6 +66,17 @@ scoped_refptr<TestContextProvider> TestContextProvider::Create(
return provider;
}
+scoped_ptr<TestWebGraphicsContext3D> ReturnScopedContext(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return context.Pass();
+}
+
+// static
+scoped_refptr<TestContextProvider> TestContextProvider::Create(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return Create(base::Bind(&ReturnScopedContext, base::Passed(&context)));
+}
+
TestContextProvider::TestContextProvider()
: bound_(false),
destroyed_(false) {
@@ -60,6 +114,11 @@ bool TestContextProvider::BindToCurrentThread() {
destroyed_ = true;
return false;
}
+
+ lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
+ swap_buffers_complete_callback_proxy_.reset(
+ new SwapBuffersCompleteCallbackProxy(this));
+
return true;
}
@@ -98,10 +157,52 @@ bool TestContextProvider::DestroyedOnMainThread() {
return destroyed_;
}
+void TestContextProvider::OnLostContext() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ {
+ base::AutoLock lock(destroyed_lock_);
+ if (destroyed_)
+ return;
+ destroyed_ = true;
+ }
+ if (!lost_context_callback_.is_null())
+ base::ResetAndReturn(&lost_context_callback_).Run();
+}
+
+void TestContextProvider::OnSwapBuffersComplete() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ if (!swap_buffers_complete_callback_.is_null())
+ swap_buffers_complete_callback_.Run();
+}
+
+void TestContextProvider::SetMemoryAllocation(
+ const ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible) {
+ if (memory_policy_changed_callback_.is_null())
+ return;
+ memory_policy_changed_callback_.Run(
+ policy, discard_backbuffer_when_not_visible);
+}
+
void TestContextProvider::SetLostContextCallback(
const LostContextCallback& cb) {
DCHECK(context_thread_checker_.CalledOnValidThread());
- NOTIMPLEMENTED();
+ DCHECK(lost_context_callback_.is_null() || cb.is_null());
+ lost_context_callback_ = cb;
+}
+
+void TestContextProvider::SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(swap_buffers_complete_callback_.is_null() || cb.is_null());
+ swap_buffers_complete_callback_ = cb;
+}
+
+void TestContextProvider::SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null());
+ memory_policy_changed_callback_ = cb;
}
} // namespace cc
diff --git a/cc/debug/test_context_provider.h b/cc/debug/test_context_provider.h
index 3a95bfb..3e677049 100644
--- a/cc/debug/test_context_provider.h
+++ b/cc/debug/test_context_provider.h
@@ -26,6 +26,8 @@ class CC_EXPORT TestContextProvider
static scoped_refptr<TestContextProvider> Create();
static scoped_refptr<TestContextProvider> Create(
const CreateCallback& create_callback);
+ static scoped_refptr<TestContextProvider> Create(
+ scoped_ptr<TestWebGraphicsContext3D> context);
virtual bool BindToCurrentThread() OVERRIDE;
virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
@@ -33,15 +35,25 @@ class CC_EXPORT TestContextProvider
virtual void VerifyContexts() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE;
+ virtual void SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& cb) OVERRIDE;
+ virtual void SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& cb) OVERRIDE;
TestWebGraphicsContext3D* TestContext3d() { return context3d_.get(); }
+ void SetMemoryAllocation(const ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible);
+
protected:
TestContextProvider();
virtual ~TestContextProvider();
bool InitializeOnMainThread(const CreateCallback& create_callback);
+ void OnLostContext();
+ void OnSwapBuffersComplete();
+
scoped_ptr<TestWebGraphicsContext3D> context3d_;
bool bound_;
@@ -50,6 +62,17 @@ class CC_EXPORT TestContextProvider
base::Lock destroyed_lock_;
bool destroyed_;
+
+ LostContextCallback lost_context_callback_;
+ SwapBuffersCompleteCallback swap_buffers_complete_callback_;
+ MemoryPolicyChangedCallback memory_policy_changed_callback_;
+
+ class LostContextCallbackProxy;
+ scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
+
+ class SwapBuffersCompleteCallbackProxy;
+ scoped_ptr<SwapBuffersCompleteCallbackProxy>
+ swap_buffers_complete_callback_proxy_;
};
} // namespace cc
diff --git a/cc/debug/test_web_graphics_context_3d.cc b/cc/debug/test_web_graphics_context_3d.cc
index 62797f9..14c7ace 100644
--- a/cc/debug/test_web_graphics_context_3d.cc
+++ b/cc/debug/test_web_graphics_context_3d.cc
@@ -58,12 +58,6 @@ scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() {
return make_scoped_ptr(new TestWebGraphicsContext3D());
}
-// static
-base::Callback<scoped_ptr<TestWebGraphicsContext3D>()>
-TestWebGraphicsContext3D::CreateFactory() {
- return base::Bind(&TestWebGraphicsContext3D::Create);
-}
-
TestWebGraphicsContext3D::TestWebGraphicsContext3D()
: FakeWebGraphicsContext3D(),
context_id_(s_context_id++),
@@ -79,7 +73,6 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D()
times_map_buffer_chromium_succeeds_(-1),
context_lost_callback_(NULL),
swap_buffers_callback_(NULL),
- memory_allocation_changed_callback_(NULL),
max_texture_size_(2048),
width_(0),
height_(0),
@@ -105,7 +98,6 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D(
times_map_buffer_chromium_succeeds_(-1),
context_lost_callback_(NULL),
swap_buffers_callback_(NULL),
- memory_allocation_changed_callback_(NULL),
max_texture_size_(2048),
width_(0),
height_(0),
@@ -439,11 +431,6 @@ void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM(
swap_buffers_callback_ = callback;
}
-void TestWebGraphicsContext3D::setMemoryAllocationChangedCallbackCHROMIUM(
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) {
- memory_allocation_changed_callback_ = callback;
-}
-
void TestWebGraphicsContext3D::prepareTexture() {
if (swap_buffers_callback_) {
base::MessageLoop::current()->PostTask(
@@ -636,13 +623,6 @@ WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() {
return image_id;
}
-void TestWebGraphicsContext3D::SetMemoryAllocation(
- WebKit::WebGraphicsMemoryAllocation allocation) {
- if (!memory_allocation_changed_callback_)
- return;
- memory_allocation_changed_callback_->onMemoryAllocationChanged(allocation);
-}
-
TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {}
TestWebGraphicsContext3D::Buffer::~Buffer() {}
diff --git a/cc/debug/test_web_graphics_context_3d.h b/cc/debug/test_web_graphics_context_3d.h
index e66a165..83e48d74 100644
--- a/cc/debug/test_web_graphics_context_3d.h
+++ b/cc/debug/test_web_graphics_context_3d.h
@@ -7,7 +7,6 @@
#include <vector>
-#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
@@ -20,15 +19,11 @@
#include "cc/debug/fake_web_graphics_context_3d.h"
#include "third_party/khronos/GLES2/gl2.h"
-namespace WebKit { struct WebGraphicsMemoryAllocation; }
-
namespace cc {
class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
public:
static scoped_ptr<TestWebGraphicsContext3D> Create();
- static base::Callback<
- scoped_ptr<TestWebGraphicsContext3D>()> CreateFactory();
virtual ~TestWebGraphicsContext3D();
@@ -119,9 +114,6 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
virtual void setSwapBuffersCompleteCallbackCHROMIUM(
WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback);
- virtual void setMemoryAllocationChangedCallbackCHROMIUM(
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback);
-
virtual void prepareTexture();
virtual void finish();
virtual void flush();
@@ -207,8 +199,6 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
virtual WebKit::WebGLId NextImageId();
- void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation);
-
protected:
struct Buffer {
Buffer();
@@ -271,8 +261,6 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
int times_map_buffer_chromium_succeeds_;
WebGraphicsContextLostCallback* context_lost_callback_;
WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_;
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM*
- memory_allocation_changed_callback_;
std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_;
base::hash_set<WebKit::WebGLId> used_textures_;
std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
diff --git a/cc/layers/delegated_renderer_layer_impl_unittest.cc b/cc/layers/delegated_renderer_layer_impl_unittest.cc
index 2537c53..401ac3c 100644
--- a/cc/layers/delegated_renderer_layer_impl_unittest.cc
+++ b/cc/layers/delegated_renderer_layer_impl_unittest.cc
@@ -38,20 +38,15 @@ class DelegatedRendererLayerImplTest : public testing::Test {
LayerTreeSettings settings;
settings.minimum_occlusion_tracking_size = gfx::Size();
- host_impl_ = LayerTreeHostImpl::Create(settings,
- &client_,
- &proxy_,
- &stats_instrumentation_);
+ host_impl_.reset(new FakeLayerTreeHostImpl(settings, &proxy_));
host_impl_->InitializeRenderer(CreateFakeOutputSurface());
host_impl_->SetViewportSize(gfx::Size(10, 10));
}
protected:
FakeProxy proxy_;
- FakeLayerTreeHostImplClient client_;
DebugScopedSetImplThreadAndMainThreadBlocked
always_impl_thread_and_main_thread_blocked_;
- FakeRenderingStatsInstrumentation stats_instrumentation_;
scoped_ptr<LayerTreeHostImpl> host_impl_;
};
diff --git a/cc/layers/io_surface_layer_impl.cc b/cc/layers/io_surface_layer_impl.cc
index f8577a3..e8c627b 100644
--- a/cc/layers/io_surface_layer_impl.cc
+++ b/cc/layers/io_surface_layer_impl.cc
@@ -39,11 +39,11 @@ void IOSurfaceLayerImpl::DestroyTexture() {
}
if (io_surface_texture_id_) {
- OutputSurface* output_surface = layer_tree_impl()->output_surface();
+ ContextProvider* context_provider =
+ layer_tree_impl()->output_surface()->context_provider().get();
// TODO(skaslev): Implement this path for software compositing.
- WebKit::WebGraphicsContext3D* context3d = output_surface->context3d();
- if (context3d)
- context3d->deleteTexture(io_surface_texture_id_);
+ if (context_provider)
+ context_provider->Context3d()->deleteTexture(io_surface_texture_id_);
io_surface_texture_id_ = 0;
}
}
@@ -67,13 +67,15 @@ bool IOSurfaceLayerImpl::WillDraw(DrawMode draw_mode,
return false;
if (io_surface_changed_) {
- WebKit::WebGraphicsContext3D* context3d =
- resource_provider->GraphicsContext3D();
- if (!context3d) {
+ ContextProvider* context_provider =
+ layer_tree_impl()->output_surface()->context_provider().get();
+ if (!context_provider) {
// TODO(skaslev): Implement this path for software compositing.
return false;
}
+ WebKit::WebGraphicsContext3D* context3d = context_provider->Context3d();
+
// TODO(ernstm): Do this in a way that we can track memory usage.
if (!io_surface_texture_id_) {
io_surface_texture_id_ = context3d->createTexture();
diff --git a/cc/layers/nine_patch_layer_unittest.cc b/cc/layers/nine_patch_layer_unittest.cc
index 5268d02..f918efb 100644
--- a/cc/layers/nine_patch_layer_unittest.cc
+++ b/cc/layers/nine_patch_layer_unittest.cc
@@ -11,6 +11,7 @@
#include "cc/scheduler/texture_uploader.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"
#include "cc/test/geometry_test_utils.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/occlusion_tracker.h"
@@ -95,12 +96,14 @@ TEST_F(NinePatchLayerTest, TriggerFullUploadOnceWhenChangingBitmap) {
1024 * 1024);
layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface;
scoped_ptr<ResourceProvider> resource_provider;
{
DebugScopedSetImplThread impl_thread(Proxy());
DebugScopedSetMainThreadBlocked main_thread_blocked(Proxy());
- output_surface = CreateFakeOutputSurface();
+ output_surface = FakeOutputSurface::Create3d();
+ CHECK(output_surface->BindToClient(&output_surface_client));
resource_provider = ResourceProvider::Create(output_surface.get(), 0);
params.texture->AcquireBackingTexture(resource_provider.get());
ASSERT_TRUE(params.texture->have_backing_texture());
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc
index 047a529..b1547ae 100644
--- a/cc/layers/picture_layer_impl_unittest.cc
+++ b/cc/layers/picture_layer_impl_unittest.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/picture_layer.h"
#include "cc/test/fake_content_layer_client.h"
@@ -822,7 +823,7 @@ TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
TestWebGraphicsContext3D::Create();
context->set_max_texture_size(140);
host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>());
+ context.Pass()).PassAs<OutputSurface>());
pending_layer_->CalculateContentsScale(
1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds);
@@ -873,7 +874,7 @@ TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
TestWebGraphicsContext3D::Create();
context->set_max_texture_size(140);
host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>());
+ context.Pass()).PassAs<OutputSurface>());
pending_layer_->CalculateContentsScale(
1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds);
diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc
index 744bf00..46f9d51 100644
--- a/cc/layers/texture_layer_unittest.cc
+++ b/cc/layers/texture_layer_unittest.cc
@@ -620,8 +620,10 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
{
scoped_ptr<TextureLayerImpl> impl_layer =
TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
+ ContextProvider* context_provider =
+ host_impl_.output_surface()->context_provider();
unsigned texture =
- host_impl_.output_surface()->context3d()->createTexture();
+ context_provider->Context3d()->createTexture();
impl_layer->set_texture_id(texture);
EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
}
@@ -659,8 +661,10 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
{
scoped_ptr<TextureLayerImpl> impl_layer =
TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
+ ContextProvider* context_provider =
+ host_impl_.output_surface()->context_provider();
unsigned texture =
- host_impl_.output_surface()->context3d()->createTexture();
+ context_provider->Context3d()->createTexture();
impl_layer->set_texture_id(texture);
EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
}
@@ -683,8 +687,10 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
{
scoped_ptr<TextureLayerImpl> impl_layer =
TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
+ ContextProvider* context_provider =
+ host_impl_.output_surface()->context_provider();
unsigned texture =
- host_impl_.output_surface()->context3d()->createTexture();
+ context_provider->Context3d()->createTexture();
impl_layer->set_texture_id(texture);
EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
}
@@ -801,8 +807,7 @@ class TextureLayerClientTest
TestWebGraphicsContext3D::Create());
context_ = context.get();
texture_ = context->createTexture();
- return FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ return FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>();
}
virtual unsigned PrepareTexture() OVERRIDE {
diff --git a/cc/layers/tiled_layer_unittest.cc b/cc/layers/tiled_layer_unittest.cc
index a2f0ca7..daae39b 100644
--- a/cc/layers/tiled_layer_unittest.cc
+++ b/cc/layers/tiled_layer_unittest.cc
@@ -16,6 +16,7 @@
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "cc/test/geometry_test_utils.h"
@@ -47,7 +48,7 @@ class TiledLayerTest : public testing::Test {
public:
TiledLayerTest()
: proxy_(NULL),
- output_surface_(CreateFakeOutputSurface()),
+ output_surface_(FakeOutputSurface::Create3d()),
queue_(make_scoped_ptr(new ResourceUpdateQueue)),
fake_layer_impl_tree_host_client_(FakeLayerTreeHostClient::DIRECT_3D),
occlusion_(NULL) {
@@ -64,8 +65,10 @@ class TiledLayerTest : public testing::Test {
layer_tree_host_->InitializeOutputSurfaceIfNeeded();
layer_tree_host_->SetRootLayer(Layer::Create());
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
DebugScopedSetImplThreadAndMainThreadBlocked
- impl_thread_and_main_thread_blocked(proxy_);
+ impl_thread_and_main_thread_blocked(proxy_);
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
host_impl_ = make_scoped_ptr(new FakeLayerTreeHostImpl(proxy_));
}
@@ -183,6 +186,7 @@ class TiledLayerTest : public testing::Test {
public:
Proxy* proxy_;
LayerTreeSettings settings_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<ResourceUpdateQueue> queue_;
diff --git a/cc/layers/video_layer_impl.cc b/cc/layers/video_layer_impl.cc
index 4b5671f..4328067 100644
--- a/cc/layers/video_layer_impl.cc
+++ b/cc/layers/video_layer_impl.cc
@@ -93,8 +93,11 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
if (!LayerImpl::WillDraw(draw_mode, resource_provider))
return false;
- if (!updater_)
- updater_.reset(new VideoResourceUpdater(resource_provider));
+ if (!updater_) {
+ updater_.reset(
+ new VideoResourceUpdater(layer_tree_impl()->context_provider(),
+ layer_tree_impl()->resource_provider()));
+ }
VideoFrameExternalResources external_resources =
updater_->CreateExternalResourcesFromVideoFrame(frame_);
diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h
index 13b7df5..7d61763 100644
--- a/cc/output/context_provider.h
+++ b/cc/output/context_provider.h
@@ -12,6 +12,7 @@ class GrContext;
namespace WebKit { class WebGraphicsContext3D; }
namespace cc {
+struct ManagedMemoryPolicy;
class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
public:
@@ -41,6 +42,20 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) = 0;
+ // Sets a callback to be called when the context is lost. This should be
+ // called from the same thread that the context is bound to.
+ typedef base::Closure SwapBuffersCompleteCallback;
+ virtual void SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& swap_buffers_complete_callback) = 0;
+
+ // Sets a callback to be called when the memory policy changes. This should be
+ // called from the same thread that the context is bound to.
+ typedef base::Callback<void(
+ const cc::ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible)> MemoryPolicyChangedCallback;
+ virtual void SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
+
protected:
friend class base::RefCountedThreadSafe<ContextProvider>;
virtual ~ContextProvider() {}
diff --git a/cc/output/delegating_renderer.cc b/cc/output/delegating_renderer.cc
index bd1c5d1..be8ab03 100644
--- a/cc/output/delegating_renderer.cc
+++ b/cc/output/delegating_renderer.cc
@@ -58,13 +58,14 @@ bool DelegatingRenderer::Initialize() {
capabilities_.allow_partial_texture_updates = false;
capabilities_.using_offscreen_context3d = false;
- WebGraphicsContext3D* context3d = resource_provider_->GraphicsContext3D();
-
- if (!context3d) {
- // Software compositing.
+ if (!output_surface_->context_provider()) {
+ // TODO(danakj): Make software compositing work.
return true;
}
+ WebGraphicsContext3D* context3d =
+ output_surface_->context_provider()->Context3d();
+
if (!context3d->makeContextCurrent())
return false;
@@ -171,10 +172,11 @@ void DelegatingRenderer::ReceiveSwapBuffersAck(
}
bool DelegatingRenderer::IsContextLost() {
- WebGraphicsContext3D* context3d = resource_provider_->GraphicsContext3D();
- if (!context3d)
+ ContextProvider* context_provider = output_surface_->context_provider();
+ if (!context_provider)
return false;
- return context3d->getGraphicsResetStatusARB() != GL_NO_ERROR;
+ return context_provider->Context3d()->getGraphicsResetStatusARB() !=
+ GL_NO_ERROR;
}
void DelegatingRenderer::SetVisible(bool visible) {
@@ -182,27 +184,27 @@ void DelegatingRenderer::SetVisible(bool visible) {
return;
visible_ = visible;
- WebGraphicsContext3D* context = resource_provider_->GraphicsContext3D();
+ ContextProvider* context_provider = output_surface_->context_provider();
if (!visible_) {
TRACE_EVENT0("cc", "DelegatingRenderer::SetVisible dropping resources");
resource_provider_->ReleaseCachedData();
- if (context)
- context->flush();
+ if (context_provider)
+ context_provider->Context3d()->flush();
}
if (capabilities_.using_set_visibility) {
// We loop visibility to the GPU process, since that's what manages memory.
// That will allow it to feed us with memory allocations that we can act
// upon.
- DCHECK(context);
- context->setVisibilityCHROMIUM(visible);
+ DCHECK(context_provider);
+ context_provider->Context3d()->setVisibilityCHROMIUM(visible);
}
}
void DelegatingRenderer::SendManagedMemoryStats(size_t bytes_visible,
size_t bytes_visible_and_nearby,
size_t bytes_allocated) {
- WebGraphicsContext3D* context = resource_provider_->GraphicsContext3D();
- if (!context) {
+ ContextProvider* context_provider = output_surface_->context_provider();
+ if (!context_provider) {
// TODO(piman): software path.
NOTIMPLEMENTED();
return;
@@ -212,7 +214,7 @@ void DelegatingRenderer::SendManagedMemoryStats(size_t bytes_visible,
stats.bytesVisibleAndNearby = bytes_visible_and_nearby;
stats.bytesAllocated = bytes_allocated;
stats.backbufferRequested = false;
- context->sendManagedMemoryStatsCHROMIUM(&stats);
+ context_provider->Context3d()->sendManagedMemoryStatsCHROMIUM(&stats);
}
void DelegatingRenderer::SetDiscardBackBufferWhenNotVisible(bool discard) {
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 61d0eaa..d1cbec3 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -151,7 +151,7 @@ GLRenderer::GLRenderer(RendererClient* client,
: DirectRenderer(client, output_surface, resource_provider),
offscreen_framebuffer_id_(0),
shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
- context_(output_surface->context3d()),
+ context_(output_surface->context_provider()->Context3d()),
is_backbuffer_discarded_(false),
discard_backbuffer_when_not_visible_(false),
is_using_bind_uniform_(false),
@@ -510,7 +510,7 @@ static inline SkBitmap ApplyFilters(GLRenderer* renderer,
offscreen_contexts->Context3d()->flush();
// Use the compositor's GL context again.
- renderer->resource_provider()->GraphicsContext3D()->makeContextCurrent();
+ renderer->Context()->makeContextCurrent();
return source;
}
@@ -592,7 +592,7 @@ static SkBitmap ApplyImageFilter(GLRenderer* renderer,
offscreen_contexts->Context3d()->flush();
// Use the compositor's GL context again.
- renderer->resource_provider()->GraphicsContext3D()->makeContextCurrent();
+ renderer->Context()->makeContextCurrent();
return device.accessBitmap(false);
}
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index 9e930cc..0c90b64 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -15,6 +15,7 @@
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/mock_quad_culler.h"
#include "cc/test/pixel_test.h"
#include "cc/test/render_pass_test_common.h"
@@ -232,27 +233,32 @@ class FakeRendererGL : public GLRenderer {
class GLRendererTest : public testing::Test {
protected:
- GLRendererTest()
- : output_surface_(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- new FrameCountingContext()))),
- resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
- renderer_(&mock_client_,
- output_surface_.get(),
- resource_provider_.get()) {}
+ GLRendererTest() {
+ scoped_ptr<FrameCountingContext> context3d(new FrameCountingContext);
+ context3d_ = context3d.get();
- virtual void SetUp() { renderer_.Initialize(); }
+ output_surface_ = FakeOutputSurface::Create3d(
+ context3d.PassAs<TestWebGraphicsContext3D>()).Pass();
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
- void SwapBuffers() { renderer_.SwapBuffers(); }
-
- FrameCountingContext* Context() {
- return static_cast<FrameCountingContext*>(output_surface_->context3d());
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0).Pass();
+ renderer_ = make_scoped_ptr(new FakeRendererGL(
+ &renderer_client_,
+ output_surface_.get(),
+ resource_provider_.get()));
}
- scoped_ptr<OutputSurface> output_surface_;
- FakeRendererClient mock_client_;
+ virtual void SetUp() { renderer_->Initialize(); }
+
+ void SwapBuffers() { renderer_->SwapBuffers(); }
+
+ FrameCountingContext* context3d_;
+ FakeOutputSurfaceClient output_surface_client_;
+ scoped_ptr<FakeOutputSurface> output_surface_;
+ FakeRendererClient renderer_client_;
scoped_ptr<ResourceProvider> resource_provider_;
- FakeRendererGL renderer_;
+ scoped_ptr<FakeRendererGL> renderer_;
};
// Closing the namespace here so that GLRendererShaderTest can take advantage
@@ -320,15 +326,17 @@ class ShaderCreatorMockGraphicsContext : public TestWebGraphicsContext3D {
class GLRendererShaderTest : public testing::Test {
protected:
- GLRendererShaderTest()
- : output_surface_(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- new ShaderCreatorMockGraphicsContext()))),
- resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
- renderer_(scoped_ptr<FakeRendererGL>(
- new FakeRendererGL(&mock_client_,
- output_surface_.get(),
- resource_provider_.get()))) {
+ GLRendererShaderTest() {
+ output_surface_ = FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(
+ new ShaderCreatorMockGraphicsContext())).Pass();
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
+ resource_provider_ = ResourceProvider::Create(output_surface_.get(),
+ 0).Pass();
+ renderer_.reset(new FakeRendererGL(&renderer_client_,
+ output_surface_.get(),
+ resource_provider_.get()));
renderer_->Initialize();
}
@@ -386,8 +394,9 @@ class GLRendererShaderTest : public testing::Test {
renderer_->program_shadow_);
}
- scoped_ptr<OutputSurface> output_surface_;
- FakeRendererClient mock_client_;
+ FakeOutputSurfaceClient output_surface_client_;
+ scoped_ptr<FakeOutputSurface> output_surface_;
+ FakeRendererClient renderer_client_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<FakeRendererGL> renderer_;
};
@@ -398,12 +407,12 @@ namespace {
// Suggest recreating framebuffer when one already exists.
// Expected: it does nothing.
TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) {
- renderer_.SetDiscardBackBufferWhenNotVisible(false);
- EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count());
- EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
+ renderer_->SetDiscardBackBufferWhenNotVisible(false);
+ EXPECT_EQ(0, renderer_client_.set_full_root_layer_damage_count());
+ EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
SwapBuffers();
- EXPECT_EQ(1, Context()->frame_count());
+ EXPECT_EQ(1, context3d_->frame_count());
}
// Test GLRenderer DiscardBackbuffer functionality:
@@ -413,76 +422,76 @@ TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) {
TEST_F(
GLRendererTest,
SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayerIfNotVisible) {
- renderer_.SetVisible(false);
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
+ renderer_->SetVisible(false);
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Suggest discarding framebuffer when one exists and the renderer is visible.
// Expected: the allocation is ignored.
TEST_F(GLRendererTest, SuggestBackbufferNoDoNothingWhenVisible) {
- renderer_.SetVisible(true);
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count());
- EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
+ renderer_->SetVisible(true);
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_EQ(0, renderer_client_.set_full_root_layer_damage_count());
+ EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Suggest discarding framebuffer when one does not exist.
// Expected: it does nothing.
TEST_F(GLRendererTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) {
- renderer_.SetVisible(false);
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
-
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
+ renderer_->SetVisible(false);
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
+
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Begin drawing a frame while a framebuffer is discarded.
// Expected: will recreate framebuffer.
TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) {
- renderer_.SetVisible(false);
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
- EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
+ renderer_->SetVisible(false);
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
+ EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
- renderer_.SetVisible(true);
- renderer_.DrawFrame(mock_client_.render_passes_in_draw_order());
- EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
+ renderer_->SetVisible(true);
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
+ EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
SwapBuffers();
- EXPECT_EQ(1, Context()->frame_count());
+ EXPECT_EQ(1, context3d_->frame_count());
}
TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) {
- renderer_.SetVisible(false);
- renderer_.SetDiscardBackBufferWhenNotVisible(true);
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
- EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
+ renderer_->SetVisible(false);
+ renderer_->SetDiscardBackBufferWhenNotVisible(true);
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
+ EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
char pixels[4];
- renderer_.DrawFrame(mock_client_.render_passes_in_draw_order());
- EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
+ EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
- renderer_.GetFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1));
- EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
- EXPECT_EQ(2, mock_client_.set_full_root_layer_damage_count());
+ renderer_->GetFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1));
+ EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
+ EXPECT_EQ(2, renderer_client_.set_full_root_layer_damage_count());
}
TEST_F(GLRendererTest, ExternalStencil) {
- EXPECT_FALSE(renderer_.stencil_enabled());
+ EXPECT_FALSE(renderer_->stencil_enabled());
- mock_client_.EnableExternalStencilTest();
- mock_client_.root_render_pass()->has_transparent_background = false;
+ renderer_client_.EnableExternalStencilTest();
+ renderer_client_.root_render_pass()->has_transparent_background = false;
- renderer_.DrawFrame(mock_client_.render_passes_in_draw_order());
- EXPECT_TRUE(renderer_.stencil_enabled());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
+ EXPECT_TRUE(renderer_->stencil_enabled());
}
class ForbidSynchronousCallContext : public TestWebGraphicsContext3D {
@@ -638,14 +647,17 @@ class ForbidSynchronousCallContext : public TestWebGraphicsContext3D {
// This test isn't using the same fixture as GLRendererTest, and you can't mix
// TEST() and TEST_F() with the same name, Hence LRC2.
TEST(GLRendererTest2, InitializationDoesNotMakeSynchronousCalls) {
- FakeRendererClient mock_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new ForbidSynchronousCallContext)));
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new ForbidSynchronousCallContext)));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
}
@@ -677,14 +689,17 @@ class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D {
};
TEST(GLRendererTest2, InitializationWithQuicklyLostContextDoesNotAssert) {
- FakeRendererClient mock_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new LoseContextOnFirstGetContext)));
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new LoseContextOnFirstGetContext)));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
renderer.Initialize();
}
@@ -702,21 +717,26 @@ class ClearCountingContext : public TestWebGraphicsContext3D {
};
TEST(GLRendererTest2, OpaqueBackground) {
- FakeRendererClient mock_client;
+ scoped_ptr<ClearCountingContext> context_owned(new ClearCountingContext);
+ ClearCountingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
- ClearCountingContext* context =
- static_cast<ClearCountingContext*>(output_surface->context3d());
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
- mock_client.root_render_pass()->has_transparent_background = false;
+ renderer_client.root_render_pass()->has_transparent_background = false;
EXPECT_TRUE(renderer.Initialize());
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
// On DEBUG builds, render passes with opaque background clear to blue to
// easily see regions that were not drawn on the screen.
@@ -728,21 +748,26 @@ TEST(GLRendererTest2, OpaqueBackground) {
}
TEST(GLRendererTest2, TransparentBackground) {
- FakeRendererClient mock_client;
+ scoped_ptr<ClearCountingContext> context_owned(new ClearCountingContext);
+ ClearCountingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
- ClearCountingContext* context =
- static_cast<ClearCountingContext*>(output_surface->context3d());
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
- mock_client.root_render_pass()->has_transparent_background = true;
+ renderer_client.root_render_pass()->has_transparent_background = true;
EXPECT_TRUE(renderer.Initialize());
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
EXPECT_EQ(1, context->clear_count());
}
@@ -799,17 +824,21 @@ class VisibilityChangeIsLastCallTrackingContext
};
TEST(GLRendererTest2, VisibilityChangeIsLastCall) {
- FakeRendererClient mock_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new VisibilityChangeIsLastCallTrackingContext)));
- VisibilityChangeIsLastCallTrackingContext* context =
- static_cast<VisibilityChangeIsLastCallTrackingContext*>(
- output_surface->context3d());
+ scoped_ptr<VisibilityChangeIsLastCallTrackingContext> context_owned(
+ new VisibilityChangeIsLastCallTrackingContext);
+ VisibilityChangeIsLastCallTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
@@ -819,7 +848,7 @@ TEST(GLRendererTest2, VisibilityChangeIsLastCall) {
// RenderClient and the Context by giving them both a pointer to a variable on
// the stack.
renderer.SetVisible(true);
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
renderer.SetVisible(false);
EXPECT_TRUE(context->last_call_was_set_visibility());
}
@@ -854,16 +883,21 @@ class TextureStateTrackingContext : public TestWebGraphicsContext3D {
};
TEST(GLRendererTest2, ActiveTextureState) {
- FakeRendererClient fake_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TextureStateTrackingContext)));
- TextureStateTrackingContext* context =
- static_cast<TextureStateTrackingContext*>(output_surface->context3d());
+ scoped_ptr<TextureStateTrackingContext> context_owned(
+ new TextureStateTrackingContext);
+ TextureStateTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &fake_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
// During initialization we are allowed to set any texture parameters.
EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber());
@@ -938,22 +972,26 @@ class NoClearRootRenderPassMockContext : public TestWebGraphicsContext3D {
};
TEST(GLRendererTest2, ShouldClearRootRenderPass) {
- NoClearRootRenderPassFakeClient mock_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new NoClearRootRenderPassMockContext)));
- NoClearRootRenderPassMockContext* mock_context =
- static_cast<NoClearRootRenderPassMockContext*>(
- output_surface->context3d());
+ scoped_ptr<NoClearRootRenderPassMockContext> mock_context_owned(
+ new NoClearRootRenderPassMockContext);
+ NoClearRootRenderPassMockContext* mock_context = mock_context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ NoClearRootRenderPassFakeClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
- gfx::Rect viewport_rect(mock_client.DeviceViewport());
+ gfx::Rect viewport_rect(renderer_client.DeviceViewport());
ScopedPtrVector<RenderPass>& render_passes =
- *mock_client.render_passes_in_draw_order();
+ *renderer_client.render_passes_in_draw_order();
render_passes.clear();
RenderPass::Id root_pass_id(1, 0);
@@ -988,8 +1026,8 @@ TEST(GLRendererTest2, ShouldClearRootRenderPass) {
.After(first_render_pass);
renderer.DecideRenderPassAllocationsForFrame(
- *mock_client.render_passes_in_draw_order());
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ *renderer_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
// In multiple render passes all but the root pass should clear the
// framebuffer.
@@ -1017,20 +1055,26 @@ class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D {
};
TEST(GLRendererTest2, ScissorTestWhenClearing) {
- FakeRendererClient mock_client;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new ScissorTestOnClearCheckingContext)));
+ scoped_ptr<ScissorTestOnClearCheckingContext> context_owned(
+ new ScissorTestOnClearCheckingContext);
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ FakeRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
EXPECT_FALSE(renderer.Capabilities().using_partial_swap);
- gfx::Rect viewport_rect(mock_client.DeviceViewport());
+ gfx::Rect viewport_rect(renderer_client.DeviceViewport());
ScopedPtrVector<RenderPass>& render_passes =
- *mock_client.render_passes_in_draw_order();
+ *renderer_client.render_passes_in_draw_order();
render_passes.clear();
gfx::Rect grand_child_rect(25, 25);
@@ -1054,15 +1098,17 @@ TEST(GLRendererTest2, ScissorTestWhenClearing) {
AddRenderPassQuad(child_pass, grand_child_pass);
renderer.DecideRenderPassAllocationsForFrame(
- *mock_client.render_passes_in_draw_order());
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ *renderer_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
}
class NonReshapableOutputSurface : public FakeOutputSurface {
public:
explicit NonReshapableOutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : FakeOutputSurface(context3d.Pass(), false) {}
+ scoped_ptr<TestWebGraphicsContext3D> context3d)
+ : FakeOutputSurface(
+ TestContextProvider::Create(context3d.Pass()),
+ false) {}
virtual gfx::Size SurfaceSize() const OVERRIDE { return gfx::Size(500, 500); }
};
@@ -1108,21 +1154,27 @@ TEST(GLRendererTest2, ScissorAndViewportWithinNonreshapableSurface) {
// and maintains a fixed size. This test verifies that glViewport and
// glScissor's Y coordinate is flipped correctly in this environment, and that
// the glViewport can be at a nonzero origin within the surface.
- OffsetViewportRendererClient mock_client;
- scoped_ptr<OutputSurface> output_surface(make_scoped_ptr(
- new NonReshapableOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new FlippedScissorAndViewportContext))));
+ scoped_ptr<FlippedScissorAndViewportContext> context_owned(
+ new FlippedScissorAndViewportContext);
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(new NonReshapableOutputSurface(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
+
+ OffsetViewportRendererClient renderer_client;
FakeRendererGL renderer(
- &mock_client, output_surface.get(), resource_provider.get());
+ &renderer_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
EXPECT_FALSE(renderer.Capabilities().using_partial_swap);
- gfx::Rect viewport_rect(mock_client.DeviceViewport().size());
+ gfx::Rect viewport_rect(renderer_client.DeviceViewport().size());
gfx::Rect quad_rect = gfx::Rect(20, 20, 20, 20);
ScopedPtrVector<RenderPass>& render_passes =
- *mock_client.render_passes_in_draw_order();
+ *renderer_client.render_passes_in_draw_order();
render_passes.clear();
RenderPass::Id root_pass_id(1, 0);
@@ -1131,14 +1183,14 @@ TEST(GLRendererTest2, ScissorAndViewportWithinNonreshapableSurface) {
AddClippedQuad(root_pass, quad_rect, SK_ColorGREEN);
renderer.DecideRenderPassAllocationsForFrame(
- *mock_client.render_passes_in_draw_order());
- renderer.DrawFrame(mock_client.render_passes_in_draw_order());
+ *renderer_client.render_passes_in_draw_order());
+ renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
}
TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
- gfx::Rect viewport_rect(mock_client_.DeviceViewport());
+ gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
ScopedPtrVector<RenderPass>* render_passes =
- mock_client_.render_passes_in_draw_order();
+ renderer_client_.render_passes_in_draw_order();
gfx::Rect child_rect(50, 50);
RenderPass::Id child_pass_id(2, 0);
@@ -1193,8 +1245,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
gfx::Transform());
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassProgram();
// RenderPassColorMatrixProgram
@@ -1209,8 +1261,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
AddRenderPassQuad(root_pass, child_pass, 0, filter, gfx::Transform());
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassColorMatrixProgram();
// RenderPassMaskProgram
@@ -1229,8 +1281,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
gfx::Transform());
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassMaskProgram();
// RenderPassMaskColorMatrixProgram
@@ -1245,8 +1297,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
AddRenderPassQuad(root_pass, child_pass, mask, filter, gfx::Transform());
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassMaskColorMatrixProgram();
// RenderPassProgramAA
@@ -1265,8 +1317,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
transform_causing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassProgramAA();
// RenderPassColorMatrixProgramAA
@@ -1281,8 +1333,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
AddRenderPassQuad(root_pass, child_pass, 0, filter, transform_causing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassColorMatrixProgramAA();
// RenderPassMaskProgramAA
@@ -1298,8 +1350,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
transform_causing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassMaskProgramAA();
// RenderPassMaskColorMatrixProgramAA
@@ -1314,8 +1366,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
AddRenderPassQuad(root_pass, child_pass, mask, filter, transform_causing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestRenderPassMaskColorMatrixProgramAA();
}
@@ -1326,7 +1378,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) {
RenderPass::Id child_pass_id(2, 0);
TestRenderPass* child_pass;
- gfx::Rect viewport_rect(mock_client_.DeviceViewport());
+ gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
RenderPass::Id root_pass_id(1, 0);
TestRenderPass* root_pass;
@@ -1345,7 +1397,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) {
// Set up the render pass quad to be drawn
ScopedPtrVector<RenderPass>* render_passes =
- mock_client_.render_passes_in_draw_order();
+ renderer_client_.render_passes_in_draw_order();
render_passes->clear();
@@ -1362,8 +1414,8 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) {
transform_preventing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
// If use_aa incorrectly ignores clipping, it will use the
// RenderPassProgramAA shader instead of the RenderPassProgram.
@@ -1371,9 +1423,9 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) {
}
TEST_F(GLRendererShaderTest, DrawSolidColorShader) {
- gfx::Rect viewport_rect(mock_client_.DeviceViewport());
+ gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
ScopedPtrVector<RenderPass>* render_passes =
- mock_client_.render_passes_in_draw_order();
+ renderer_client_.render_passes_in_draw_order();
RenderPass::Id root_pass_id(1, 0);
TestRenderPass* root_pass;
@@ -1392,8 +1444,8 @@ TEST_F(GLRendererShaderTest, DrawSolidColorShader) {
pixel_aligned_transform_causing_aa);
renderer_->DecideRenderPassAllocationsForFrame(
- *mock_client_.render_passes_in_draw_order());
- renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
+ *renderer_client_.render_passes_in_draw_order());
+ renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
TestSolidColorProgramAA();
}
@@ -1427,8 +1479,9 @@ class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
class MockOutputSurface : public OutputSurface {
public:
MockOutputSurface()
- : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new StrictMock<OutputSurfaceMockContext>)) {
+ : OutputSurface(TestContextProvider::Create(
+ scoped_ptr<TestWebGraphicsContext3D>(
+ new StrictMock<OutputSurfaceMockContext>))) {
surface_size_ = gfx::Size(100, 100);
}
virtual ~MockOutputSurface() {}
@@ -1442,13 +1495,19 @@ class MockOutputSurface : public OutputSurface {
class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
protected:
- MockOutputSurfaceTest()
- : resource_provider_(ResourceProvider::Create(&output_surface_, 0)),
- renderer_(this, &output_surface_, resource_provider_.get()) {}
+ virtual void SetUp() {
+ FakeOutputSurfaceClient output_surface_client_;
+ CHECK(output_surface_.BindToClient(&output_surface_client_));
+
+ resource_provider_ = ResourceProvider::Create(&output_surface_, 0).Pass();
- virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); }
+ renderer_.reset(new FakeRendererGL(this,
+ &output_surface_,
+ resource_provider_.get()));
+ EXPECT_TRUE(renderer_->Initialize());
+ }
- void SwapBuffers() { renderer_.SwapBuffers(); }
+ void SwapBuffers() { renderer_->SwapBuffers(); }
void DrawFrame() {
gfx::Rect viewport_rect(DeviceViewport());
@@ -1469,49 +1528,51 @@ class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
EXPECT_CALL(*Context(), drawElements(_, _, _, _)).Times(1);
- renderer_.DecideRenderPassAllocationsForFrame(
+ renderer_->DecideRenderPassAllocationsForFrame(
*render_passes_in_draw_order());
- renderer_.DrawFrame(render_passes_in_draw_order());
+ renderer_->DrawFrame(render_passes_in_draw_order());
}
OutputSurfaceMockContext* Context() {
- return static_cast<OutputSurfaceMockContext*>(output_surface_.context3d());
+ return static_cast<OutputSurfaceMockContext*>(
+ output_surface_.context_provider()->Context3d());
}
+ FakeOutputSurfaceClient output_surface_client_;
StrictMock<MockOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
- FakeRendererGL renderer_;
+ scoped_ptr<FakeRendererGL> renderer_;
};
TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) {
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
- renderer_.SwapBuffers();
+ renderer_->SwapBuffers();
}
TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) {
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
- renderer_.SwapBuffers();
+ renderer_->SwapBuffers();
set_viewport_and_scale(gfx::Size(2, 2), 2.f);
- renderer_.ViewportChanged();
+ renderer_->ViewportChanged();
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
- renderer_.SwapBuffers();
+ renderer_->SwapBuffers();
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
- renderer_.SwapBuffers();
+ renderer_->SwapBuffers();
set_viewport_and_scale(gfx::Size(1, 1), 1.f);
- renderer_.ViewportChanged();
+ renderer_->ViewportChanged();
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
- renderer_.SwapBuffers();
+ renderer_->SwapBuffers();
}
class GLRendererTestSyncPoint : public GLRendererPixelTest {
@@ -1531,20 +1592,21 @@ class GLRendererTestSyncPoint : public GLRendererPixelTest {
TEST_F(GLRendererTestSyncPoint, SignalSyncPointOnLostContext) {
int sync_point_callback_count = 0;
int other_callback_count = 0;
- unsigned sync_point = output_surface_->context3d()->insertSyncPoint();
+ unsigned sync_point =
+ output_surface_->context_provider()->Context3d()->insertSyncPoint();
- output_surface_->context3d()->loseContextCHROMIUM(
+ output_surface_->context_provider()->Context3d()->loseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
SyncPointHelper::SignalSyncPoint(
- output_surface_->context3d(),
+ output_surface_->context_provider()->Context3d(),
sync_point,
base::Bind(&SyncPointCallback, &sync_point_callback_count));
EXPECT_EQ(0, sync_point_callback_count);
EXPECT_EQ(0, other_callback_count);
// Make the sync point happen.
- output_surface_->context3d()->finish();
+ output_surface_->context_provider()->Context3d()->finish();
// Post a task after the sync point.
base::MessageLoop::current()->PostTask(
FROM_HERE,
@@ -1560,17 +1622,18 @@ TEST_F(GLRendererTestSyncPoint, SignalSyncPointOnLostContext) {
TEST_F(GLRendererTestSyncPoint, SignalSyncPoint) {
int sync_point_callback_count = 0;
int other_callback_count = 0;
- unsigned sync_point = output_surface_->context3d()->insertSyncPoint();
+ unsigned sync_point =
+ output_surface_->context_provider()->Context3d()->insertSyncPoint();
SyncPointHelper::SignalSyncPoint(
- output_surface_->context3d(),
+ output_surface_->context_provider()->Context3d(),
sync_point,
base::Bind(&SyncPointCallback, &sync_point_callback_count));
EXPECT_EQ(0, sync_point_callback_count);
EXPECT_EQ(0, other_callback_count);
// Make the sync point happen.
- output_surface_->context3d()->finish();
+ output_surface_->context_provider()->Context3d()->finish();
// Post a task after the sync point.
base::MessageLoop::current()->PostTask(
FROM_HERE,
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc
index 5d2c6bb..4cd2078 100644
--- a/cc/output/output_surface.cc
+++ b/cc/output/output_surface.cc
@@ -19,7 +19,6 @@
#include "cc/output/output_surface_client.h"
#include "cc/scheduler/delay_based_time_source.h"
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
-#include "third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/rect.h"
@@ -30,67 +29,10 @@ using std::string;
using std::vector;
namespace cc {
-namespace {
-
-ManagedMemoryPolicy::PriorityCutoff ConvertPriorityCutoff(
- WebKit::WebGraphicsMemoryAllocation::PriorityCutoff priority_cutoff) {
- // This is simple a 1:1 map, the names differ only because the WebKit names
- // should be to match the cc names.
- switch (priority_cutoff) {
- case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing:
- return ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING;
- case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly:
- return ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY;
- case WebKit::WebGraphicsMemoryAllocation::
- PriorityCutoffAllowVisibleAndNearby:
- return ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE;
- case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything:
- return ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING;
- }
- NOTREACHED();
- return ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING;
-}
-
-} // anonymous namespace
-
-class OutputSurfaceCallbacks
- : public WebKit::WebGraphicsContext3D::
- WebGraphicsSwapBuffersCompleteCallbackCHROMIUM,
- public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback,
- public WebKit::WebGraphicsContext3D::
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
- public:
- explicit OutputSurfaceCallbacks(OutputSurface* client)
- : client_(client) {
- DCHECK(client_);
- }
-
- // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation.
- virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(NULL); }
-
- // WK:WGC3D::WGContextLostCallback implementation.
- virtual void onContextLost() { client_->DidLoseOutputSurface(); }
-
- // WK:WGC3D::WGMemoryAllocationChangedCallbackCHROMIUM implementation.
- virtual void onMemoryAllocationChanged(
- WebKit::WebGraphicsMemoryAllocation allocation) {
- ManagedMemoryPolicy policy(
- allocation.bytesLimitWhenVisible,
- ConvertPriorityCutoff(allocation.priorityCutoffWhenVisible),
- allocation.bytesLimitWhenNotVisible,
- ConvertPriorityCutoff(allocation.priorityCutoffWhenNotVisible),
- ManagedMemoryPolicy::kDefaultNumResourcesLimit);
- bool discard_backbuffer = !allocation.suggestHaveBackbuffer;
- client_->SetMemoryPolicy(policy, discard_backbuffer);
- }
-
- private:
- OutputSurface* client_;
-};
OutputSurface::OutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : context3d_(context3d.Pass()),
+ scoped_refptr<ContextProvider> context_provider)
+ : context_provider_(context_provider),
has_gl_discard_backbuffer_(false),
has_swap_buffers_complete_callback_(false),
device_scale_factor_(-1),
@@ -119,9 +61,9 @@ OutputSurface::OutputSurface(
}
OutputSurface::OutputSurface(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ scoped_refptr<ContextProvider> context_provider,
scoped_ptr<cc::SoftwareOutputDevice> software_device)
- : context3d_(context3d.Pass()),
+ : context_provider_(context_provider),
software_device_(software_device.Pass()),
has_gl_discard_backbuffer_(false),
has_swap_buffers_complete_callback_(false),
@@ -289,12 +231,7 @@ void OutputSurface::SetExternalDrawConstraints(const gfx::Transform& transform,
OutputSurface::~OutputSurface() {
if (frame_rate_controller_)
frame_rate_controller_->SetActive(false);
-
- if (context3d_) {
- context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
- context3d_->setContextLostCallback(NULL);
- context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
- }
+ ResetContext3d();
}
bool OutputSurface::ForcedDrawToSoftwareDevice() const {
@@ -306,10 +243,10 @@ bool OutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
client_ = client;
bool success = true;
- if (context3d_) {
- success = context3d_->makeContextCurrent();
+ if (context_provider_) {
+ success = context_provider_->BindToCurrentThread();
if (success)
- SetContext3D(context3d_.Pass());
+ SetUpContext3d();
}
if (!success)
@@ -318,40 +255,42 @@ bool OutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
return success;
}
-bool OutputSurface::InitializeAndSetContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+bool OutputSurface::InitializeAndSetContext3d(
+ scoped_refptr<ContextProvider> context_provider,
scoped_refptr<ContextProvider> offscreen_context_provider) {
- DCHECK(!context3d_);
- DCHECK(context3d);
+ DCHECK(!context_provider_);
+ DCHECK(context_provider);
DCHECK(client_);
bool success = false;
- if (context3d->makeContextCurrent()) {
- SetContext3D(context3d.Pass());
+ if (context_provider->BindToCurrentThread()) {
+ context_provider_ = context_provider;
+ SetUpContext3d();
if (client_->DeferredInitialize(offscreen_context_provider))
success = true;
}
if (!success)
- ResetContext3D();
+ ResetContext3d();
return success;
}
void OutputSurface::ReleaseGL() {
DCHECK(client_);
- DCHECK(context3d_);
+ DCHECK(context_provider_);
client_->ReleaseGL();
- ResetContext3D();
+ ResetContext3d();
}
-void OutputSurface::SetContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d) {
- DCHECK(!context3d_);
- DCHECK(context3d);
+void OutputSurface::SetUpContext3d() {
+ DCHECK(context_provider_);
DCHECK(client_);
- string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS));
+ WebKit::WebGraphicsContext3D* context3d = context_provider_->Context3d();
+
+ string extensions_string =
+ UTF16ToASCII(context3d->getString(GL_EXTENSIONS));
vector<string> extensions_list;
base::SplitString(extensions_string, ' ', &extensions_list);
set<string> extensions(extensions_list.begin(), extensions_list.end());
@@ -360,29 +299,40 @@ void OutputSurface::SetContext3D(
has_swap_buffers_complete_callback_ =
extensions.count("GL_CHROMIUM_swapbuffers_complete_callback") > 0;
-
- context3d_ = context3d.Pass();
- callbacks_.reset(new OutputSurfaceCallbacks(this));
- context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get());
- context3d_->setContextLostCallback(callbacks_.get());
- context3d_->setMemoryAllocationChangedCallbackCHROMIUM(callbacks_.get());
-}
-
-void OutputSurface::ResetContext3D() {
- context3d_.reset();
- callbacks_.reset();
+ context_provider_->SetLostContextCallback(
+ base::Bind(&OutputSurface::DidLoseOutputSurface,
+ base::Unretained(this)));
+ context_provider_->SetSwapBuffersCompleteCallback(
+ base::Bind(&OutputSurface::OnSwapBuffersComplete,
+ base::Unretained(this),
+ static_cast<CompositorFrameAck*>(NULL)));
+ context_provider_->SetMemoryPolicyChangedCallback(
+ base::Bind(&OutputSurface::SetMemoryPolicy,
+ base::Unretained(this)));
+}
+
+void OutputSurface::ResetContext3d() {
+ if (context_provider_.get()) {
+ context_provider_->SetLostContextCallback(
+ ContextProvider::LostContextCallback());
+ context_provider_->SetSwapBuffersCompleteCallback(
+ ContextProvider::SwapBuffersCompleteCallback());
+ context_provider_->SetMemoryPolicyChangedCallback(
+ ContextProvider::MemoryPolicyChangedCallback());
+ }
+ context_provider_ = NULL;
}
void OutputSurface::EnsureBackbuffer() {
- DCHECK(context3d_);
+ DCHECK(context_provider_);
if (has_gl_discard_backbuffer_)
- context3d_->ensureBackbufferCHROMIUM();
+ context_provider_->Context3d()->ensureBackbufferCHROMIUM();
}
void OutputSurface::DiscardBackbuffer() {
- DCHECK(context3d_);
+ DCHECK(context_provider_);
if (has_gl_discard_backbuffer_)
- context3d_->discardBackbufferCHROMIUM();
+ context_provider_->Context3d()->discardBackbufferCHROMIUM();
}
void OutputSurface::Reshape(gfx::Size size, float scale_factor) {
@@ -391,8 +341,8 @@ void OutputSurface::Reshape(gfx::Size size, float scale_factor) {
surface_size_ = size;
device_scale_factor_ = scale_factor;
- if (context3d_) {
- context3d_->reshapeWithScaleFactor(
+ if (context_provider_) {
+ context_provider_->Context3d()->reshapeWithScaleFactor(
size.width(), size.height(), scale_factor);
}
if (software_device_)
@@ -404,8 +354,8 @@ gfx::Size OutputSurface::SurfaceSize() const {
}
void OutputSurface::BindFramebuffer() {
- DCHECK(context3d_);
- context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0);
+ DCHECK(context_provider_);
+ context_provider_->Context3d()->bindFramebuffer(GL_FRAMEBUFFER, 0);
}
void OutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
@@ -415,20 +365,21 @@ void OutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
return;
}
- DCHECK(context3d_);
+ DCHECK(context_provider_);
DCHECK(frame->gl_frame_data);
if (frame->gl_frame_data->sub_buffer_rect ==
gfx::Rect(frame->gl_frame_data->size)) {
// Note that currently this has the same effect as SwapBuffers; we should
// consider exposing a different entry point on WebGraphicsContext3D.
- context3d()->prepareTexture();
+ context_provider_->Context3d()->prepareTexture();
} else {
gfx::Rect sub_buffer_rect = frame->gl_frame_data->sub_buffer_rect;
- context3d()->postSubBufferCHROMIUM(sub_buffer_rect.x(),
- sub_buffer_rect.y(),
- sub_buffer_rect.width(),
- sub_buffer_rect.height());
+ context_provider_->Context3d()->postSubBufferCHROMIUM(
+ sub_buffer_rect.x(),
+ sub_buffer_rect.y(),
+ sub_buffer_rect.width(),
+ sub_buffer_rect.height());
}
if (!has_swap_buffers_complete_callback_)
diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h
index 73f1c75..a94d41ef 100644
--- a/cc/output/output_surface.h
+++ b/cc/output/output_surface.h
@@ -13,7 +13,6 @@
#include "cc/output/context_provider.h"
#include "cc/output/software_output_device.h"
#include "cc/scheduler/frame_rate_controller.h"
-#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
namespace base { class SingleThreadTaskRunner; }
@@ -31,7 +30,6 @@ class CompositorFrame;
class CompositorFrameAck;
struct ManagedMemoryPolicy;
class OutputSurfaceClient;
-class OutputSurfaceCallbacks;
// Represents the output surface for a compositor. The compositor owns
// and manages its destruction. Its lifetime is:
@@ -46,11 +44,11 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient {
DEFAULT_MAX_FRAMES_PENDING = 2
};
- explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d);
+ explicit OutputSurface(scoped_refptr<ContextProvider> context_provider);
explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device);
- OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ OutputSurface(scoped_refptr<ContextProvider> context_provider,
scoped_ptr<cc::SoftwareOutputDevice> software_device);
virtual ~OutputSurface();
@@ -79,10 +77,9 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient {
// surface. Either of these may return a null pointer, but not both.
// In the event of a lost context, the entire output surface should be
// recreated.
- WebKit::WebGraphicsContext3D* context3d() const {
- return context3d_.get();
+ scoped_refptr<ContextProvider> context_provider() const {
+ return context_provider_.get();
}
-
SoftwareOutputDevice* software_device() const {
return software_device_.get();
}
@@ -127,21 +124,22 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient {
// OutputSurfaceClient::BeginFrame until the callback is disabled.
virtual void SetNeedsBeginFrame(bool enable);
+ bool HasClient() { return !!client_; }
+
protected:
// Synchronously initialize context3d and enter hardware mode.
// This can only supported in threaded compositing mode.
// |offscreen_context_provider| should match what is returned by
// LayerTreeClient::OffscreenContextProviderForCompositorThread.
- bool InitializeAndSetContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ bool InitializeAndSetContext3d(
+ scoped_refptr<ContextProvider> context_provider,
scoped_refptr<ContextProvider> offscreen_context_provider);
void ReleaseGL();
void PostSwapBuffersComplete();
struct cc::OutputSurface::Capabilities capabilities_;
- scoped_ptr<OutputSurfaceCallbacks> callbacks_;
- scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
+ scoped_refptr<ContextProvider> context_provider_;
scoped_ptr<cc::SoftwareOutputDevice> software_device_;
bool has_gl_discard_backbuffer_;
bool has_swap_buffers_complete_callback_;
@@ -163,7 +161,6 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient {
// Forwarded to OutputSurfaceClient but threaded through OutputSurface
// first so OutputSurface has a chance to update the FrameRateController
- bool HasClient() { return !!client_; }
void SetNeedsRedrawRect(gfx::Rect damage_rect);
void BeginFrame(const BeginFrameArgs& args);
void DidSwapBuffers();
@@ -182,8 +179,8 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient {
OutputSurfaceClient* client_;
friend class OutputSurfaceCallbacks;
- void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d);
- void ResetContext3D();
+ void SetUpContext3d();
+ void ResetContext3d();
void SetMemoryPolicy(const ManagedMemoryPolicy& policy,
bool discard_backbuffer_when_not_visible);
diff --git a/cc/output/output_surface_unittest.cc b/cc/output/output_surface_unittest.cc
index 4f9e370..42cbc14 100644
--- a/cc/output/output_surface_unittest.cc
+++ b/cc/output/output_surface_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/output/output_surface.h"
#include "base/test/test_simple_task_runner.h"
+#include "cc/debug/test_context_provider.h"
#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/output/managed_memory_policy.h"
#include "cc/output/output_surface_client.h"
@@ -14,38 +15,31 @@
#include "cc/test/scheduler_test_common.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h"
-
-using WebKit::WebGraphicsMemoryAllocation;
namespace cc {
namespace {
class TestOutputSurface : public OutputSurface {
public:
- explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : OutputSurface(context3d.Pass()) {}
+ explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider)
+ : OutputSurface(context_provider) {}
explicit TestOutputSurface(
scoped_ptr<cc::SoftwareOutputDevice> software_device)
: OutputSurface(software_device.Pass()) {}
- TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
+ TestOutputSurface(scoped_refptr<ContextProvider> context_provider,
scoped_ptr<cc::SoftwareOutputDevice> software_device)
- : OutputSurface(context3d.Pass(), software_device.Pass()) {}
+ : OutputSurface(context_provider, software_device.Pass()) {}
- bool InitializeNewContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) {
- return InitializeAndSetContext3D(new_context3d.Pass(),
+ bool InitializeNewContext3d(
+ scoped_refptr<ContextProvider> new_context_provider) {
+ return InitializeAndSetContext3d(new_context_provider,
scoped_refptr<ContextProvider>());
}
using OutputSurface::ReleaseGL;
- bool HasClientForTesting() {
- return HasClient();
- }
-
void OnVSyncParametersChangedForTesting(base::TimeTicks timebase,
base::TimeDelta interval) {
OnVSyncParametersChanged(timebase, interval);
@@ -85,108 +79,98 @@ class TestOutputSurface : public OutputSurface {
};
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
-
- TestOutputSurface output_surface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ TestOutputSurface output_surface(TestContextProvider::Create());
+ EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
- EXPECT_TRUE(output_surface.HasClientForTesting());
+ EXPECT_TRUE(output_surface.HasClient());
EXPECT_FALSE(client.deferred_initialize_called());
// Verify DidLoseOutputSurface callback is hooked up correctly.
EXPECT_FALSE(client.did_lose_output_surface_called());
- output_surface.context3d()->loseContextCHROMIUM(
+ output_surface.context_provider()->Context3d()->loseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
EXPECT_TRUE(client.did_lose_output_surface_called());
}
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create();
// Lose the context so BindToClient fails.
- context3d->set_times_make_current_succeeds(0);
+ context_provider->TestContext3d()->set_times_make_current_succeeds(0);
- TestOutputSurface output_surface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ TestOutputSurface output_surface(context_provider);
+ EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_FALSE(output_surface.BindToClient(&client));
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ EXPECT_FALSE(output_surface.HasClient());
}
-class InitializeNewContext3D : public ::testing::Test {
+class OutputSurfaceTestInitializeNewContext3d : public ::testing::Test {
public:
- InitializeNewContext3D()
- : context3d_(TestWebGraphicsContext3D::Create()),
+ OutputSurfaceTestInitializeNewContext3d()
+ : context_provider_(TestContextProvider::Create()),
output_surface_(
scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) {}
protected:
void BindOutputSurface() {
EXPECT_TRUE(output_surface_.BindToClient(&client_));
- EXPECT_TRUE(output_surface_.HasClientForTesting());
+ EXPECT_TRUE(output_surface_.HasClient());
}
void InitializeNewContextExpectFail() {
- EXPECT_FALSE(output_surface_.InitializeNewContext3D(
- context3d_.PassAs<WebKit::WebGraphicsContext3D>()));
- EXPECT_TRUE(output_surface_.HasClientForTesting());
+ EXPECT_FALSE(output_surface_.InitializeNewContext3d(context_provider_));
+ EXPECT_TRUE(output_surface_.HasClient());
- EXPECT_FALSE(output_surface_.context3d());
+ EXPECT_FALSE(output_surface_.context_provider());
EXPECT_TRUE(output_surface_.software_device());
}
- scoped_ptr<TestWebGraphicsContext3D> context3d_;
+ scoped_refptr<TestContextProvider> context_provider_;
TestOutputSurface output_surface_;
FakeOutputSurfaceClient client_;
};
-TEST_F(InitializeNewContext3D, Success) {
+TEST_F(OutputSurfaceTestInitializeNewContext3d, Success) {
BindOutputSurface();
EXPECT_FALSE(client_.deferred_initialize_called());
- EXPECT_TRUE(output_surface_.InitializeNewContext3D(
- context3d_.PassAs<WebKit::WebGraphicsContext3D>()));
+ EXPECT_TRUE(output_surface_.InitializeNewContext3d(context_provider_));
EXPECT_TRUE(client_.deferred_initialize_called());
+ EXPECT_EQ(context_provider_, output_surface_.context_provider());
EXPECT_FALSE(client_.did_lose_output_surface_called());
- output_surface_.context3d()->loseContextCHROMIUM(
+ context_provider_->Context3d()->loseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
EXPECT_TRUE(client_.did_lose_output_surface_called());
output_surface_.ReleaseGL();
- EXPECT_FALSE(output_surface_.context3d());
+ EXPECT_FALSE(output_surface_.context_provider());
}
-TEST_F(InitializeNewContext3D, Context3dMakeCurrentFails) {
+TEST_F(OutputSurfaceTestInitializeNewContext3d, Context3dMakeCurrentFails) {
BindOutputSurface();
- context3d_->set_times_make_current_succeeds(0);
+ context_provider_->TestContext3d()->set_times_make_current_succeeds(0);
InitializeNewContextExpectFail();
}
-TEST_F(InitializeNewContext3D, ClientDeferredInitializeFails) {
+TEST_F(OutputSurfaceTestInitializeNewContext3d, ClientDeferredInitializeFails) {
BindOutputSurface();
client_.set_deferred_initialize_result(false);
InitializeNewContextExpectFail();
}
TEST(OutputSurfaceTest, BeginFrameEmulation) {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
-
- TestOutputSurface output_surface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ TestOutputSurface output_surface(TestContextProvider::Create());
+ EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
- EXPECT_TRUE(output_surface.HasClientForTesting());
+ EXPECT_TRUE(output_surface.HasClient());
EXPECT_FALSE(client.deferred_initialize_called());
// Initialize BeginFrame emulation
@@ -264,16 +248,12 @@ TEST(OutputSurfaceTest, BeginFrameEmulation) {
}
TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
-
- TestOutputSurface output_surface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ TestOutputSurface output_surface(TestContextProvider::Create());
+ EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
- EXPECT_TRUE(output_surface.HasClientForTesting());
+ EXPECT_TRUE(output_surface.HasClient());
EXPECT_FALSE(client.deferred_initialize_called());
output_surface.SetMaxFramesPending(2);
@@ -318,16 +298,15 @@ TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) {
}
TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create();
- TestOutputSurface output_surface(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
- EXPECT_FALSE(output_surface.HasClientForTesting());
+ TestOutputSurface output_surface(context_provider);
+ EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
- EXPECT_TRUE(output_surface.HasClientForTesting());
+ EXPECT_TRUE(output_surface.HasClient());
EXPECT_FALSE(client.deferred_initialize_called());
base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000);
@@ -375,27 +354,26 @@ TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) {
}
TEST(OutputSurfaceTest, MemoryAllocation) {
- scoped_ptr<TestWebGraphicsContext3D> scoped_context =
- TestWebGraphicsContext3D::Create();
- TestWebGraphicsContext3D* context = scoped_context.get();
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create();
- TestOutputSurface output_surface(
- scoped_context.PassAs<WebKit::WebGraphicsContext3D>());
+ TestOutputSurface output_surface(context_provider);
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
- WebGraphicsMemoryAllocation allocation;
- allocation.suggestHaveBackbuffer = true;
- allocation.bytesLimitWhenVisible = 1234;
- allocation.priorityCutoffWhenVisible =
- WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly;
- allocation.bytesLimitWhenNotVisible = 4567;
- allocation.priorityCutoffWhenNotVisible =
- WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing;
+ ManagedMemoryPolicy policy(0);
+ policy.bytes_limit_when_visible = 1234;
+ policy.priority_cutoff_when_visible =
+ ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY;
+ policy.bytes_limit_when_not_visible = 4567;
+ policy.priority_cutoff_when_not_visible =
+ ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING;
- context->SetMemoryAllocation(allocation);
+ bool discard_backbuffer_when_not_visible = false;
+ context_provider->SetMemoryAllocation(policy,
+ discard_backbuffer_when_not_visible);
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY,
client.memory_policy().priority_cutoff_when_visible);
@@ -404,23 +382,26 @@ TEST(OutputSurfaceTest, MemoryAllocation) {
client.memory_policy().priority_cutoff_when_not_visible);
EXPECT_FALSE(client.discard_backbuffer_when_not_visible());
- allocation.suggestHaveBackbuffer = false;
- context->SetMemoryAllocation(allocation);
+ discard_backbuffer_when_not_visible = true;
+ context_provider->SetMemoryAllocation(policy,
+ discard_backbuffer_when_not_visible);
EXPECT_TRUE(client.discard_backbuffer_when_not_visible());
- allocation.priorityCutoffWhenVisible =
- WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything;
- allocation.priorityCutoffWhenNotVisible =
- WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby;
- context->SetMemoryAllocation(allocation);
+ policy.priority_cutoff_when_visible =
+ ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING;
+ policy.priority_cutoff_when_not_visible =
+ ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE;
+ context_provider->SetMemoryAllocation(policy,
+ discard_backbuffer_when_not_visible);
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
client.memory_policy().priority_cutoff_when_visible);
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE,
client.memory_policy().priority_cutoff_when_not_visible);
// 0 bytes limit should be ignored.
- allocation.bytesLimitWhenVisible = 0;
- context->SetMemoryAllocation(allocation);
+ policy.bytes_limit_when_visible = 0;
+ context_provider->SetMemoryAllocation(policy,
+ discard_backbuffer_when_not_visible);
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
}
diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc
index 9508aa2..ba76f16 100644
--- a/cc/output/renderer_pixeltest.cc
+++ b/cc/output/renderer_pixeltest.cc
@@ -13,6 +13,7 @@
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/pixel_test.h"
#include "gpu/GLES2/gl2extchromium.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
@@ -1003,7 +1004,8 @@ TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) {
class ExternalStencilPixelTest : public GLRendererPixelTest {
protected:
void ClearBackgroundToGreen() {
- WebKit::WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebKit::WebGraphicsContext3D* context3d =
+ output_surface_->context_provider()->Context3d();
output_surface_->EnsureBackbuffer();
output_surface_->Reshape(device_viewport_size_, 1);
context3d->clearColor(0.f, 1.f, 0.f, 1.f);
@@ -1012,7 +1014,8 @@ class ExternalStencilPixelTest : public GLRendererPixelTest {
void PopulateStencilBuffer() {
// Set two quadrants of the stencil buffer to 1.
- WebKit::WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebKit::WebGraphicsContext3D* context3d =
+ output_surface_->context_provider()->Context3d();
ASSERT_TRUE(context3d->getContextAttributes().stencil);
output_surface_->EnsureBackbuffer();
output_surface_->Reshape(device_viewport_size_, 1);
diff --git a/cc/output/software_renderer_unittest.cc b/cc/output/software_renderer_unittest.cc
index 238d654..a3361a9 100644
--- a/cc/output/software_renderer_unittest.cc
+++ b/cc/output/software_renderer_unittest.cc
@@ -13,6 +13,7 @@
#include "cc/quads/tile_draw_quad.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/render_pass_test_common.h"
#include "cc/test/render_pass_test_utils.h"
@@ -32,6 +33,8 @@ class SoftwareRendererTest : public testing::Test, public RendererClient {
scoped_ptr<SoftwareOutputDevice> software_output_device) {
output_surface_ = FakeOutputSurface::CreateSoftware(
software_output_device.Pass());
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
renderer_ = SoftwareRenderer::Create(
this, output_surface_.get(), resource_provider());
@@ -75,6 +78,7 @@ class SoftwareRendererTest : public testing::Test, public RendererClient {
virtual bool ExternalStencilTestEnabled() const OVERRIDE { return false; }
protected:
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<FakeOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<SoftwareRenderer> renderer_;
diff --git a/cc/resources/picture_layer_tiling_set_unittest.cc b/cc/resources/picture_layer_tiling_set_unittest.cc
index 134b035..db72ade 100644
--- a/cc/resources/picture_layer_tiling_set_unittest.cc
+++ b/cc/resources/picture_layer_tiling_set_unittest.cc
@@ -10,6 +10,7 @@
#include "cc/resources/resource_pool.h"
#include "cc/resources/resource_provider.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_picture_layer_tiling_client.h"
#include "cc/test/fake_tile_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -59,8 +60,11 @@ class PictureLayerTilingSetTestWithResources : public testing::Test {
float scale_increment,
float ideal_contents_scale,
float expected_scale) {
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<FakeOutputSurface> output_surface =
FakeOutputSurface::Create3d();
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider =
ResourceProvider::Create(output_surface.get(), 0);
diff --git a/cc/resources/prioritized_resource_unittest.cc b/cc/resources/prioritized_resource_unittest.cc
index 92ce9ff..91b1c2e 100644
--- a/cc/resources/prioritized_resource_unittest.cc
+++ b/cc/resources/prioritized_resource_unittest.cc
@@ -7,6 +7,7 @@
#include "cc/resources/prioritized_resource_manager.h"
#include "cc/resources/resource.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/tiled_layer_test_common.h"
#include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread
@@ -19,8 +20,9 @@ class PrioritizedResourceTest : public testing::Test {
PrioritizedResourceTest()
: texture_size_(256, 256),
texture_format_(GL_RGBA),
- output_surface_(CreateFakeOutputSurface()) {
+ output_surface_(FakeOutputSurface::Create3d()) {
DebugScopedSetImplThread impl_thread(&proxy_);
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
resource_provider_ = cc::ResourceProvider::Create(output_surface_.get(), 0);
}
@@ -92,6 +94,7 @@ class PrioritizedResourceTest : public testing::Test {
FakeProxy proxy_;
const gfx::Size texture_size_;
const GLenum texture_format_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<cc::ResourceProvider> resource_provider_;
};
diff --git a/cc/resources/prioritized_tile_set_unittest.cc b/cc/resources/prioritized_tile_set_unittest.cc
index e244aef..9325691 100644
--- a/cc/resources/prioritized_tile_set_unittest.cc
+++ b/cc/resources/prioritized_tile_set_unittest.cc
@@ -9,6 +9,7 @@
#include "cc/resources/prioritized_tile_set.h"
#include "cc/resources/tile.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/fake_tile_manager.h"
#include "cc/test/fake_tile_manager_client.h"
@@ -54,12 +55,16 @@ namespace {
class PrioritizedTileSetTest : public testing::Test {
public:
- PrioritizedTileSetTest()
- : output_surface_(FakeOutputSurface::Create3d()),
- resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
- tile_manager_(new FakeTileManager(&tile_manager_client_,
- resource_provider_.get())),
- picture_pile_(FakePicturePileImpl::CreatePile()) {}
+ PrioritizedTileSetTest() {
+ output_surface_ = FakeOutputSurface::Create3d().Pass();
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
+ resource_provider_ = ResourceProvider::Create(output_surface_.get(),
+ 0).Pass();
+ tile_manager_.reset(new FakeTileManager(&tile_manager_client_,
+ resource_provider_.get()));
+ picture_pile_ = FakePicturePileImpl::CreatePile();
+ }
scoped_refptr<Tile> CreateTile() {
return make_scoped_refptr(new Tile(tile_manager_.get(),
@@ -74,10 +79,11 @@ class PrioritizedTileSetTest : public testing::Test {
}
private:
- FakeTileManagerClient tile_manager_client_;
LayerTreeSettings settings_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<FakeOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
+ FakeTileManagerClient tile_manager_client_;
scoped_ptr<FakeTileManager> tile_manager_;
scoped_refptr<FakePicturePileImpl> picture_pile_;
};
diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc
index 3d27c41..39a8a48 100644
--- a/cc/resources/raster_worker_pool_unittest.cc
+++ b/cc/resources/raster_worker_pool_unittest.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/resources/image_raster_worker_pool.h"
#include "cc/resources/picture_pile.h"
#include "cc/resources/picture_pile_impl.h"
@@ -13,6 +14,7 @@
#include "cc/resources/resource_provider.h"
#include "cc/resources/scoped_resource.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@@ -55,12 +57,15 @@ class RasterWorkerPoolTest : public testing::Test,
public RasterWorkerPoolClient {
public:
RasterWorkerPoolTest()
- : output_surface_(FakeOutputSurface::Create3d()),
- resource_provider_(
- ResourceProvider::Create(output_surface_.get(), 0)),
+ : context_provider_(TestContextProvider::Create()),
check_interval_milliseconds_(1),
timeout_seconds_(5),
timed_out_(false) {
+ output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
+ resource_provider_ = ResourceProvider::Create(output_surface_.get(),
+ 0).Pass();
}
virtual ~RasterWorkerPoolTest() {
resource_provider_.reset();
@@ -190,6 +195,8 @@ class RasterWorkerPoolTest : public testing::Test,
}
protected:
+ scoped_refptr<TestContextProvider> context_provider_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<FakeOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<RasterWorkerPool> raster_worker_pool_;
@@ -259,8 +266,7 @@ class RasterWorkerPoolTestFailedMapResource : public RasterWorkerPoolTest {
// Overridden from RasterWorkerPoolTest:
virtual void BeginTest() OVERRIDE {
- TestWebGraphicsContext3D* context3d =
- static_cast<TestWebGraphicsContext3D*>(output_surface_->context3d());
+ TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d();
context3d->set_times_map_image_chromium_succeeds(0);
context3d->set_times_map_buffer_chromium_succeeds(0);
AppendTask(0u);
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 11eaab0..0db1b4c 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -158,7 +158,7 @@ scoped_ptr<ResourceProvider> ResourceProvider::Create(
new ResourceProvider(output_surface, highp_threshold_min));
bool success = false;
- if (output_surface->context3d()) {
+ if (resource_provider->Context3d()) {
success = resource_provider->InitializeGL();
} else {
resource_provider->InitializeSoftware();
@@ -179,11 +179,6 @@ ResourceProvider::~ResourceProvider() {
CleanUpGLIfNeeded();
}
-WebGraphicsContext3D* ResourceProvider::GraphicsContext3D() {
- DCHECK(thread_checker_.CalledOnValidThread());
- return output_surface_->context3d();
-}
-
bool ResourceProvider::InUseByConsumer(ResourceId id) {
DCHECK(thread_checker_.CalledOnValidThread());
ResourceMap::iterator it = resources_.find(id);
@@ -259,7 +254,7 @@ ResourceProvider::CreateResourceFromExternalTexture(
unsigned texture_id) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
GLC(context3d, context3d->bindTexture(texture_target, texture_id));
GLC(context3d, context3d->texParameteri(
@@ -329,30 +324,30 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
lost_resource = true;
if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id));
}
if (resource->gl_id && !resource->external) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
GLC(context3d, context3d->deleteTexture(resource->gl_id));
}
if (resource->gl_upload_query_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id));
}
if (resource->gl_pixel_buffer_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
}
if (resource->mailbox.IsValid() && resource->external) {
unsigned sync_point = resource->mailbox.sync_point();
if (resource->mailbox.IsTexture()) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
if (resource->gl_id)
GLC(context3d, context3d->deleteTexture(resource->gl_id));
@@ -402,7 +397,7 @@ void ResourceProvider::SetPixels(ResourceId id,
if (resource->gl_id) {
DCHECK(!resource->pending_set_pixels);
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
DCHECK(texture_uploader_.get());
context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
@@ -472,21 +467,21 @@ void ResourceProvider::ReleaseCachedData() {
void ResourceProvider::Flush() {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (context3d)
context3d->flush();
}
void ResourceProvider::Finish() {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (context3d)
context3d->finish();
}
bool ResourceProvider::ShallowFlushIfSupported() {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (!context3d || !use_shallow_flush_)
return false;
@@ -511,7 +506,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
if (resource->external) {
if (!resource->gl_id && resource->mailbox.IsTexture()) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
if (resource->mailbox.sync_point()) {
GLC(context3d,
@@ -685,7 +680,9 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface,
use_texture_usage_hint_(false),
use_shallow_flush_(false),
max_texture_size_(0),
- best_texture_format_(0) {}
+ best_texture_format_(0) {
+ DCHECK(output_surface_->HasClient());
+}
void ResourceProvider::InitializeSoftware() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -703,7 +700,7 @@ bool ResourceProvider::InitializeGL() {
DCHECK(!texture_uploader_);
DCHECK_NE(GLTexture, default_resource_type_);
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
if (!context3d->makeContextCurrent())
@@ -740,7 +737,7 @@ bool ResourceProvider::InitializeGL() {
}
void ResourceProvider::CleanUpGLIfNeeded() {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (default_resource_type_ != GLTexture) {
// We are not in GL mode, but double check before returning.
DCHECK(!context3d);
@@ -785,7 +782,7 @@ const ResourceProvider::ResourceIdMap& ResourceProvider::GetChildToParentMap(
void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources,
TransferableResourceArray* list) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (!context3d || !context3d->makeContextCurrent()) {
// TODO(skaslev): Implement this path for software compositing.
return;
@@ -817,7 +814,7 @@ void ResourceProvider::PrepareSendToChild(int child,
const ResourceIdArray& resources,
TransferableResourceArray* list) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (!context3d || !context3d->makeContextCurrent()) {
// TODO(skaslev): Implement this path for software compositing.
return;
@@ -854,7 +851,7 @@ void ResourceProvider::PrepareSendToChild(int child,
void ResourceProvider::ReceiveFromChild(
int child, const TransferableResourceArray& resources) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (!context3d || !context3d->makeContextCurrent()) {
// TODO(skaslev): Implement this path for software compositing.
return;
@@ -891,7 +888,7 @@ void ResourceProvider::ReceiveFromChild(
void ResourceProvider::ReceiveFromParent(
const TransferableResourceArray& resources) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
if (!context3d || !context3d->makeContextCurrent()) {
// TODO(skaslev): Implement this path for software compositing.
return;
@@ -970,7 +967,7 @@ void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
DCHECK(!resource->image_id);
if (resource->type == GLTexture) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
if (!resource->gl_pixel_buffer_id)
resource->gl_pixel_buffer_id = context3d->createBuffer();
@@ -1017,7 +1014,7 @@ void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
if (resource->type == GLTexture) {
if (!resource->gl_pixel_buffer_id)
return;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
context3d->bindBuffer(
GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
@@ -1048,7 +1045,7 @@ uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
DCHECK(!resource->image_id);
if (resource->type == GLTexture) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
context3d->bindBuffer(
@@ -1079,7 +1076,7 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
DCHECK(!resource->image_id);
if (resource->type == GLTexture) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
context3d->bindBuffer(
@@ -1095,7 +1092,7 @@ void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id,
GLenum unit,
GLenum filter) {
DCHECK(thread_checker_.CalledOnValidThread());
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
ResourceMap::iterator it = resources_.find(resource_id);
DCHECK(it != resources_.end());
Resource* resource = &it->second;
@@ -1134,7 +1131,7 @@ void ResourceProvider::UnbindForSampling(
if (!resource->image_id)
return;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d));
if (unit != GL_TEXTURE0)
GLC(context3d, context3d->activeTexture(unit));
@@ -1161,7 +1158,7 @@ void ResourceProvider::BeginSetPixels(ResourceId id) {
LockForWrite(id);
if (resource->gl_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
@@ -1222,7 +1219,7 @@ void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) {
DCHECK(!resource->set_pixels_completion_forced);
if (resource->gl_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D));
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0));
@@ -1240,7 +1237,7 @@ bool ResourceProvider::DidSetPixelsComplete(ResourceId id) {
DCHECK(resource->pending_set_pixels);
if (resource->gl_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
DCHECK(resource->gl_upload_query_id);
unsigned complete = 1;
@@ -1273,7 +1270,7 @@ void ResourceProvider::LazyCreate(Resource* resource) {
if (resource->texture_pool == 0)
return;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
// Create and set texture properties. Allocation is delayed until needed.
resource->gl_id = CreateTextureId(context3d);
@@ -1302,7 +1299,7 @@ void ResourceProvider::LazyAllocate(Resource* resource) {
if (resource->allocated || !resource->gl_id)
return;
resource->allocated = true;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
gfx::Size& size = resource->size;
GLenum format = resource->format;
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
@@ -1351,7 +1348,7 @@ void ResourceProvider::AcquireImage(ResourceId id) {
return;
resource->allocated = true;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
resource->image_id = context3d->createImageCHROMIUM(
resource->size.width(), resource->size.height(), GL_RGBA8_OES);
@@ -1370,7 +1367,7 @@ void ResourceProvider::ReleaseImage(ResourceId id) {
if (!resource->image_id)
return;
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
context3d->destroyImageCHROMIUM(resource->image_id);
resource->image_id = 0;
@@ -1388,7 +1385,7 @@ uint8_t* ResourceProvider::MapImage(ResourceId id) {
DCHECK(!resource->exported);
if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
return static_cast<uint8_t*>(
context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE));
@@ -1410,7 +1407,7 @@ void ResourceProvider::UnmapImage(ResourceId id) {
DCHECK(!resource->exported);
if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
context3d->unmapImageCHROMIUM(resource->image_id);
}
@@ -1428,7 +1425,7 @@ int ResourceProvider::GetImageStride(ResourceId id) {
int stride = 0;
if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
context3d->getImageParameterivCHROMIUM(
resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
@@ -1443,4 +1440,9 @@ GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) {
return active_unit;
}
+WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
+ ContextProvider* context_provider = output_surface_->context_provider();
+ return context_provider ? context_provider->Context3d() : NULL;
+}
+
} // namespace cc
diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h
index b5dccc8..fa37ddd 100644
--- a/cc/resources/resource_provider.h
+++ b/cc/resources/resource_provider.h
@@ -63,7 +63,6 @@ class CC_EXPORT ResourceProvider {
void DidLoseOutputSurface() { lost_output_surface_ = true; }
- WebKit::WebGraphicsContext3D* GraphicsContext3D();
int max_texture_size() const { return max_texture_size_; }
GLenum best_texture_format() const { return best_texture_format_; }
size_t num_resources() const { return resources_.size(); }
@@ -324,11 +323,11 @@ class CC_EXPORT ResourceProvider {
// Indicates if we can currently lock this resource for write.
bool CanLockForWrite(ResourceId id);
- cc::ContextProvider* offscreen_context_provider() {
+ ContextProvider* offscreen_context_provider() {
return offscreen_context_provider_.get();
}
void set_offscreen_context_provider(
- scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
+ scoped_refptr<ContextProvider> offscreen_context_provider) {
offscreen_context_provider_ = offscreen_context_provider;
}
static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context);
@@ -421,6 +420,9 @@ class CC_EXPORT ResourceProvider {
GLenum target,
GLenum unit);
+ // Returns NULL if the output_surface_ does not have a ContextProvider.
+ WebKit::WebGraphicsContext3D* Context3d() const;
+
OutputSurface* output_surface_;
bool lost_output_surface_;
int highp_threshold_min_;
diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc
index ad6b3d3..7d6a6a4 100644
--- a/cc/resources/resource_provider_unittest.cc
+++ b/cc/resources/resource_provider_unittest.cc
@@ -366,13 +366,21 @@ class ResourceProviderTest
: public testing::TestWithParam<ResourceProvider::ResourceType> {
public:
ResourceProviderTest()
- : shared_data_(ContextSharedData::Create()) {
+ : shared_data_(ContextSharedData::Create()),
+ context3d_(NULL) {
switch (GetParam()) {
- case ResourceProvider::GLTexture:
- output_surface_ =
- FakeOutputSurface::Create3d(ResourceProviderContext::Create(
- shared_data_.get()).PassAs<WebKit::WebGraphicsContext3D>());
+ case ResourceProvider::GLTexture: {
+ scoped_ptr<ResourceProviderContext> context3d(
+ ResourceProviderContext::Create(shared_data_.get()));
+ context3d_ = context3d.get();
+
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create(
+ context3d.PassAs<TestWebGraphicsContext3D>());
+
+ output_surface_ = FakeOutputSurface::Create3d(context_provider);
break;
+ }
case ResourceProvider::Bitmap:
output_surface_ = FakeOutputSurface::CreateSoftware(
make_scoped_ptr(new SoftwareOutputDevice));
@@ -381,13 +389,10 @@ class ResourceProviderTest
NOTREACHED();
break;
}
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
}
- ResourceProviderContext* context() {
- return static_cast<ResourceProviderContext*>(output_surface_->context3d());
- }
-
void SetResourceFilter(ResourceProvider* resource_provider,
ResourceProvider::ResourceId id,
WGC3Denum filter) {
@@ -396,18 +401,21 @@ class ResourceProviderTest
}
WGC3Denum GetResourceFilter(ResourceProvider* resource_provider,
+ ResourceProviderContext* context,
ResourceProvider::ResourceId id) {
DCHECK_EQ(GetParam(), ResourceProvider::GLTexture);
ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id);
EXPECT_NE(0u, lock_gl.texture_id());
- ResourceProviderContext* context = static_cast<ResourceProviderContext*>(
- resource_provider->GraphicsContext3D());
context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id());
return context->GetTextureFilter();
}
+ ResourceProviderContext* context() { return context3d_; }
+
protected:
scoped_ptr<ContextSharedData> shared_data_;
+ ResourceProviderContext* context3d_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
};
@@ -520,9 +528,16 @@ TEST_P(ResourceProviderTest, TransferResources) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d(
- ResourceProviderContext::Create(shared_data_.get())
- .PassAs<WebKit::WebGraphicsContext3D>()));
+ scoped_ptr<ResourceProviderContext> child_context_owned(
+ ResourceProviderContext::Create(shared_data_.get()));
+ ResourceProviderContext* child_context = child_context_owned.get();
+
+ FakeOutputSurfaceClient child_output_surface_client;
+ scoped_ptr<OutputSurface> child_output_surface(
+ FakeOutputSurface::Create3d(
+ child_context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(child_output_surface->BindToClient(&child_output_surface_client));
+
scoped_ptr<ResourceProvider> child_resource_provider(
ResourceProvider::Create(child_output_surface.get(), 0));
@@ -603,8 +618,6 @@ TEST_P(ResourceProviderTest, TransferResources) {
EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1));
EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2));
- ResourceProviderContext* child_context =
- static_cast<ResourceProviderContext*>(child_output_surface->context3d());
{
ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id1);
ASSERT_NE(0U, lock.texture_id());
@@ -645,9 +658,15 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d(
- ResourceProviderContext::Create(shared_data_.get())
- .PassAs<WebKit::WebGraphicsContext3D>()));
+ scoped_ptr<ResourceProviderContext> child_context_owned(
+ ResourceProviderContext::Create(shared_data_.get()));
+
+ FakeOutputSurfaceClient child_output_surface_client;
+ scoped_ptr<OutputSurface> child_output_surface(
+ FakeOutputSurface::Create3d(
+ child_context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(child_output_surface->BindToClient(&child_output_surface_client));
+
scoped_ptr<ResourceProvider> child_resource_provider(
ResourceProvider::Create(child_output_surface.get(), 0));
@@ -702,9 +721,15 @@ TEST_P(ResourceProviderTest, TextureFilters) {
if (GetParam() != ResourceProvider::GLTexture)
return;
+ scoped_ptr<ResourceProviderContext> child_context_owned(
+ ResourceProviderContext::Create(shared_data_.get()));
+ ResourceProviderContext* child_context = child_context_owned.get();
+
+ FakeOutputSurfaceClient child_output_surface_client;
scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d(
- ResourceProviderContext::Create(shared_data_.get())
- .PassAs<WebKit::WebGraphicsContext3D>()));
+ child_context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(child_output_surface->BindToClient(&child_output_surface_client));
+
scoped_ptr<ResourceProvider> child_resource_provider(
ResourceProvider::Create(child_output_surface.get(), 0));
@@ -719,10 +744,14 @@ TEST_P(ResourceProviderTest, TextureFilters) {
gfx::Rect rect(size);
child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
- GetResourceFilter(child_resource_provider.get(), id));
+ GetResourceFilter(child_resource_provider.get(),
+ child_context,
+ id));
SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
- GetResourceFilter(child_resource_provider.get(), id));
+ GetResourceFilter(child_resource_provider.get(),
+ child_context,
+ id));
int child_id = resource_provider_->CreateChild();
{
@@ -741,10 +770,10 @@ TEST_P(ResourceProviderTest, TextureFilters) {
ResourceProvider::ResourceId mapped_id = resource_map[id];
EXPECT_NE(0u, mapped_id);
EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
- GetResourceFilter(resource_provider_.get(), mapped_id));
+ GetResourceFilter(resource_provider_.get(), context(), mapped_id));
SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR);
EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
- GetResourceFilter(resource_provider_.get(), mapped_id));
+ GetResourceFilter(resource_provider_.get(), context(), mapped_id));
{
// Transfer resources back from the parent to the child.
ResourceProvider::ResourceIdArray resource_ids_to_transfer;
@@ -757,10 +786,14 @@ TEST_P(ResourceProviderTest, TextureFilters) {
child_resource_provider->ReceiveFromParent(list);
}
EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
- GetResourceFilter(child_resource_provider.get(), id));
+ GetResourceFilter(child_resource_provider.get(),
+ child_context,
+ id));
SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
- GetResourceFilter(child_resource_provider.get(), id));
+ GetResourceFilter(child_resource_provider.get(),
+ child_context,
+ id));
}
void ReleaseTextureMailbox(unsigned* release_sync_point,
@@ -1035,11 +1068,15 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TextureStateTrackingContext)));
- TextureStateTrackingContext* context =
- static_cast<TextureStateTrackingContext*>(output_surface->context3d());
+ scoped_ptr<TextureStateTrackingContext> context_owned(
+ new TextureStateTrackingContext);
+ TextureStateTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1108,11 +1145,15 @@ TEST_P(ResourceProviderTest, ManagedResource) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TextureStateTrackingContext)));
- TextureStateTrackingContext* context =
- static_cast<TextureStateTrackingContext*>(output_surface->context3d());
+ scoped_ptr<TextureStateTrackingContext> context_owned(
+ new TextureStateTrackingContext);
+ TextureStateTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1155,9 +1196,12 @@ TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
scoped_ptr<base::SharedMemory> shared_memory(
CreateAndFillSharedMemory(size, kBadBeef));
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::CreateSoftware(make_scoped_ptr(
new SoftwareOutputDevice)));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1182,11 +1226,15 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TextureStateTrackingContext)));
- TextureStateTrackingContext* context =
- static_cast<TextureStateTrackingContext*>(output_surface->context3d());
+ scoped_ptr<TextureStateTrackingContext> context_owned(
+ new TextureStateTrackingContext);
+ TextureStateTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1242,11 +1290,15 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TextureStateTrackingContext)));
- TextureStateTrackingContext* context =
- static_cast<TextureStateTrackingContext*>(output_surface->context3d());
+ scoped_ptr<TextureStateTrackingContext> context_owned(
+ new TextureStateTrackingContext);
+ TextureStateTrackingContext* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1359,11 +1411,17 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
// Only for GL textures.
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
- static_cast<WebKit::WebGraphicsContext3D*>(
- new StrictMock<AllocationTrackingContext3D>));
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(mock_context.Pass()));
+ scoped_ptr<AllocationTrackingContext3D> context_owned(
+ new StrictMock<AllocationTrackingContext3D>);
+ AllocationTrackingContext3D* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
+ scoped_ptr<ResourceProvider> resource_provider(
+ ResourceProvider::Create(output_surface.get(), 0));
gfx::Size size(2, 2);
gfx::Vector2d offset(0, 0);
@@ -1373,11 +1431,6 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
uint8_t pixels[16] = { 0 };
int texture_id = 123;
- AllocationTrackingContext3D* context =
- static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
- scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
-
// Lazy allocation. Don't allocate when creating the resource.
id = resource_provider->CreateResource(
size, format, ResourceProvider::TextureUsageAny);
@@ -1429,19 +1482,20 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
- static_cast<WebKit::WebGraphicsContext3D*>(
- new StrictMock<AllocationTrackingContext3D>));
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(mock_context.Pass()));
+ scoped_ptr<AllocationTrackingContext3D> context_owned(
+ new StrictMock<AllocationTrackingContext3D>);
+ AllocationTrackingContext3D* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
WGC3Denum format = GL_RGBA;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
- AllocationTrackingContext3D* context =
- static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1468,9 +1522,11 @@ TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) {
if (GetParam() != ResourceProvider::Bitmap)
return;
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::CreateSoftware(make_scoped_ptr(
new SoftwareOutputDevice)));
+ CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(1, 1);
WGC3Denum format = GL_RGBA;
@@ -1509,19 +1565,20 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
// Only for GL textures.
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
- static_cast<WebKit::WebGraphicsContext3D*>(
- new StrictMock<AllocationTrackingContext3D>));
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(mock_context.Pass()));
+ scoped_ptr<AllocationTrackingContext3D> context_owned(
+ new StrictMock<AllocationTrackingContext3D>);
+ AllocationTrackingContext3D* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
WGC3Denum format = GL_RGBA;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
- AllocationTrackingContext3D* context =
- static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1549,19 +1606,20 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
}
TEST_P(ResourceProviderTest, PixelBufferLostContext) {
- scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
- static_cast<WebKit::WebGraphicsContext3D*>(
- new NiceMock<AllocationTrackingContext3D>));
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(mock_context.Pass()));
+ scoped_ptr<AllocationTrackingContext3D> context_owned(
+ new NiceMock<AllocationTrackingContext3D>);
+ AllocationTrackingContext3D* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
WGC3Denum format = GL_RGBA;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
- AllocationTrackingContext3D* context =
- static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1583,11 +1641,14 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
// Only for GL textures.
if (GetParam() != ResourceProvider::GLTexture)
return;
- scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
- static_cast<WebKit::WebGraphicsContext3D*>(
- new StrictMock<AllocationTrackingContext3D>));
- scoped_ptr<OutputSurface> output_surface(
- FakeOutputSurface::Create3d(mock_context.Pass()));
+ scoped_ptr<AllocationTrackingContext3D> context_owned(
+ new StrictMock<AllocationTrackingContext3D>);
+ AllocationTrackingContext3D* context = context_owned.get();
+
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
+ CHECK(output_surface->BindToClient(&output_surface_client));
const int kWidth = 2;
const int kHeight = 2;
@@ -1597,8 +1658,6 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
const unsigned kTextureId = 123u;
const unsigned kImageId = 234u;
- AllocationTrackingContext3D* context =
- static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
@@ -1659,9 +1718,11 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
TEST_P(ResourceProviderTest, Image_Bitmap) {
if (GetParam() != ResourceProvider::Bitmap)
return;
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::CreateSoftware(make_scoped_ptr(
new SoftwareOutputDevice)));
+ CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(1, 1);
WGC3Denum format = GL_RGBA;
@@ -1699,15 +1760,17 @@ TEST_P(ResourceProviderTest, Image_Bitmap) {
void InitializeGLAndCheck(ContextSharedData* shared_data,
ResourceProvider* resource_provider,
FakeOutputSurface* output_surface) {
- scoped_ptr<ResourceProviderContext> context =
+ scoped_ptr<ResourceProviderContext> context_owned =
ResourceProviderContext::Create(shared_data);
- output_surface->SetAndInitializeContext3D(
- context.PassAs<WebKit::WebGraphicsContext3D>());
+ ResourceProviderContext* context = context_owned.get();
+
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create(
+ context_owned.PassAs<TestWebGraphicsContext3D>());
+ output_surface->InitializeAndSetContext3d(context_provider, NULL);
EXPECT_TRUE(resource_provider->InitializeGL());
- CheckCreateResource(
- ResourceProvider::GLTexture,
- resource_provider,
- static_cast<ResourceProviderContext*>(output_surface->context3d()));
+
+ CheckCreateResource(ResourceProvider::GLTexture, resource_provider, context);
}
TEST(ResourceProviderTest, BasicInitializeGLSoftware) {
@@ -1727,6 +1790,7 @@ TEST(ResourceProviderTest, BasicInitializeGLSoftware) {
output_surface.get());
resource_provider->InitializeSoftware();
+ output_surface->ReleaseGL();
CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL);
InitializeGLAndCheck(shared_data.get(),
diff --git a/cc/resources/resource_update_controller_unittest.cc b/cc/resources/resource_update_controller_unittest.cc
index 9dcb23c..e7c59bf 100644
--- a/cc/resources/resource_update_controller_unittest.cc
+++ b/cc/resources/resource_update_controller_unittest.cc
@@ -8,6 +8,7 @@
#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/resources/prioritized_resource_manager.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/scheduler_test_common.h"
#include "cc/test/tiled_layer_test_common.h"
@@ -124,9 +125,6 @@ class ResourceUpdateControllerTest : public Test {
protected:
virtual void SetUp() {
- output_surface_ =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new WebGraphicsContext3DForUploadTest(this)));
bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 300, 150);
bitmap_.allocPixels();
@@ -138,6 +136,11 @@ class ResourceUpdateControllerTest : public Test {
}
resource_manager_->PrioritizeTextures();
+ output_surface_ = FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(
+ new WebGraphicsContext3DForUploadTest(this)));
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
}
@@ -193,6 +196,7 @@ class ResourceUpdateControllerTest : public Test {
protected:
// Classes required to interact and test the ResourceUpdateController
FakeProxy proxy_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<ResourceUpdateQueue> queue_;
diff --git a/cc/resources/scoped_resource_unittest.cc b/cc/resources/scoped_resource_unittest.cc
index b08c1e2..9c66180 100644
--- a/cc/resources/scoped_resource_unittest.cc
+++ b/cc/resources/scoped_resource_unittest.cc
@@ -6,6 +6,7 @@
#include "cc/output/renderer.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/tiled_layer_test_common.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2.h"
@@ -14,9 +15,12 @@ namespace cc {
namespace {
TEST(ScopedResourceTest, NewScopedResource) {
- scoped_ptr<OutputSurface> context(CreateFakeOutputSurface());
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(context.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0));
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
@@ -29,9 +33,12 @@ TEST(ScopedResourceTest, NewScopedResource) {
}
TEST(ScopedResourceTest, CreateScopedResource) {
- scoped_ptr<OutputSurface> context(CreateFakeOutputSurface());
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(context.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0));
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
texture->Allocate(
@@ -47,9 +54,12 @@ TEST(ScopedResourceTest, CreateScopedResource) {
}
TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
- scoped_ptr<OutputSurface> context(CreateFakeOutputSurface());
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(context.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0));
{
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
@@ -76,9 +86,12 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
}
TEST(ScopedResourceTest, LeakScopedResource) {
- scoped_ptr<OutputSurface> context(CreateFakeOutputSurface());
+ FakeOutputSurfaceClient output_surface_client;
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
+ CHECK(output_surface->BindToClient(&output_surface_client));
+
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(context.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0));
{
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
diff --git a/cc/resources/tile_manager_unittest.cc b/cc/resources/tile_manager_unittest.cc
index 6fb0690..5076fb0 100644
--- a/cc/resources/tile_manager_unittest.cc
+++ b/cc/resources/tile_manager_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/resources/tile.h"
#include "cc/resources/tile_priority.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/fake_tile_manager.h"
#include "cc/test/fake_tile_manager_client.h"
@@ -22,6 +23,8 @@ class TileManagerTest : public testing::TestWithParam<bool> {
TileMemoryLimitPolicy memory_limit_policy,
TreePriority tree_priority) {
output_surface_ = FakeOutputSurface::Create3d();
+ CHECK(output_surface_->BindToClient(&output_surface_client_));
+
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
tile_manager_ = make_scoped_ptr(
new FakeTileManager(&tile_manager_client_, resource_provider_.get()));
@@ -119,6 +122,7 @@ class TileManagerTest : public testing::TestWithParam<bool> {
LayerTreeSettings settings_;
scoped_ptr<FakeTileManager> tile_manager_;
scoped_refptr<FakePicturePileImpl> picture_pile_;
+ FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<FakeOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
TileMemoryLimitPolicy memory_limit_policy_;
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index 4239e98..33682eb 100644
--- a/cc/resources/video_resource_updater.cc
+++ b/cc/resources/video_resource_updater.cc
@@ -10,6 +10,7 @@
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/video_frame.h"
#include "media/filters/skcanvas_video_renderer.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/size_conversions.h"
@@ -23,8 +24,10 @@ VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {}
VideoFrameExternalResources::~VideoFrameExternalResources() {}
-VideoResourceUpdater::VideoResourceUpdater(ResourceProvider* resource_provider)
- : resource_provider_(resource_provider) {
+VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider,
+ ResourceProvider* resource_provider)
+ : context_provider_(context_provider),
+ resource_provider_(resource_provider) {
}
VideoResourceUpdater::~VideoResourceUpdater() {
@@ -138,7 +141,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
input_frame_format != media::VideoFrame::YV16)
return VideoFrameExternalResources();
- bool software_compositor = !resource_provider_->GraphicsContext3D();
+ bool software_compositor = context_provider_ == NULL;
GLenum output_resource_format = kYUVResourceFormat;
size_t output_plane_count =
@@ -197,9 +200,10 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
DCHECK(mailbox.IsZero());
if (!software_compositor) {
+ DCHECK(context_provider_);
+
WebKit::WebGraphicsContext3D* context =
- resource_provider_->GraphicsContext3D();
- DCHECK(context);
+ context_provider_->Context3d();
GLC(context, context->genMailboxCHROMIUM(mailbox.name));
if (mailbox.IsZero()) {
@@ -330,9 +334,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
if (frame_format != media::VideoFrame::NATIVE_TEXTURE)
return VideoFrameExternalResources();
- WebKit::WebGraphicsContext3D* context =
- resource_provider_->GraphicsContext3D();
- if (!context)
+ if (!context_provider_)
return VideoFrameExternalResources();
VideoFrameExternalResources external_resources;
@@ -377,10 +379,11 @@ void VideoResourceUpdater::RecycleResource(
return;
}
- WebKit::WebGraphicsContext3D* context =
- updater->resource_provider_->GraphicsContext3D();
- if (context && sync_point)
- GLC(context, context->waitSyncPoint(sync_point));
+ ContextProvider* context_provider = updater->context_provider_;
+ if (context_provider && sync_point) {
+ GLC(context_provider->Context3d(),
+ context_provider->Context3d()->waitSyncPoint(sync_point));
+ }
if (lost_resource) {
updater->DeleteResource(data.resource_id);
diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h
index 9be79d1..cf71cfa 100644
--- a/cc/resources/video_resource_updater.h
+++ b/cc/resources/video_resource_updater.h
@@ -21,6 +21,7 @@ class VideoFrame;
}
namespace cc {
+class ContextProvider;
class ResourceProvider;
class CC_EXPORT VideoFrameExternalResources {
@@ -61,7 +62,8 @@ class CC_EXPORT VideoFrameExternalResources {
class CC_EXPORT VideoResourceUpdater
: public base::SupportsWeakPtr<VideoResourceUpdater> {
public:
- explicit VideoResourceUpdater(ResourceProvider* resource_provider);
+ explicit VideoResourceUpdater(ContextProvider* context_provider,
+ ResourceProvider* resource_provider);
~VideoResourceUpdater();
VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
@@ -102,6 +104,7 @@ class CC_EXPORT VideoResourceUpdater
unsigned sync_point,
bool lost_resource);
+ ContextProvider* context_provider_;
ResourceProvider* resource_provider_;
scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_;
diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc
index ca6ebd0..60673ed 100644
--- a/cc/resources/video_resource_updater_unittest.cc
+++ b/cc/resources/video_resource_updater_unittest.cc
@@ -8,6 +8,7 @@
#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/resources/resource_provider.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -21,8 +22,9 @@ class VideoResourceUpdaterTest : public testing::Test {
TestWebGraphicsContext3D::Create();
context3d_ = context3d.get();
- output_surface3d_ = FakeOutputSurface::Create3d(
- context3d.PassAs<WebKit::WebGraphicsContext3D>());
+ output_surface3d_ =
+ FakeOutputSurface::Create3d(context3d.Pass());
+ CHECK(output_surface3d_->BindToClient(&client_));
resource_provider3d_ =
ResourceProvider::Create(output_surface3d_.get(), 0);
}
@@ -50,12 +52,14 @@ class VideoResourceUpdaterTest : public testing::Test {
}
TestWebGraphicsContext3D* context3d_;
+ FakeOutputSurfaceClient client_;
scoped_ptr<FakeOutputSurface> output_surface3d_;
scoped_ptr<ResourceProvider> resource_provider3d_;
};
TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
- VideoResourceUpdater updater(resource_provider3d_.get());
+ VideoResourceUpdater updater(output_surface3d_->context_provider().get(),
+ resource_provider3d_.get());
scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
VideoFrameExternalResources resources =
@@ -64,7 +68,8 @@ TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
}
TEST_F(VideoResourceUpdaterTest, LostContextForSoftwareFrame) {
- VideoResourceUpdater updater(resource_provider3d_.get());
+ VideoResourceUpdater updater(output_surface3d_->context_provider().get(),
+ resource_provider3d_.get());
scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
// Fail while creating the mailbox for the second YUV plane.
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()) {}
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 5fcc2b0..936bd47 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -468,7 +468,7 @@ void LayerTreeHostImpl::FrameData::AppendRenderPass(
static DrawMode GetDrawMode(OutputSurface* output_surface) {
if (output_surface->ForcedDrawToSoftwareDevice()) {
return DRAW_MODE_RESOURCELESS_SOFTWARE;
- } else if (output_surface->context3d()) {
+ } else if (output_surface->context_provider()) {
return DRAW_MODE_HARDWARE;
} else {
DCHECK(output_surface->software_device());
@@ -1581,7 +1581,7 @@ void LayerTreeHostImpl::CreateAndSetRenderer(
if (output_surface->capabilities().delegated_rendering) {
renderer_ =
DelegatingRenderer::Create(this, output_surface, resource_provider);
- } else if (output_surface->context3d() && !skip_gl_renderer) {
+ } else if (output_surface->context_provider() && !skip_gl_renderer) {
renderer_ = GLRenderer::Create(this,
output_surface,
resource_provider,
@@ -1692,7 +1692,7 @@ bool LayerTreeHostImpl::DeferredInitialize(
DCHECK(output_surface_->capabilities().deferred_gl_initialization);
DCHECK(settings_.impl_side_painting);
DCHECK(settings_.solid_color_scrollbars);
- DCHECK(output_surface_->context3d());
+ DCHECK(output_surface_->context_provider());
ReleaseTreeResources();
renderer_.reset();
@@ -1715,7 +1715,7 @@ void LayerTreeHostImpl::ReleaseGL() {
DCHECK(output_surface_->capabilities().deferred_gl_initialization);
DCHECK(settings_.impl_side_painting);
DCHECK(settings_.solid_color_scrollbars);
- DCHECK(output_surface_->context3d());
+ DCHECK(output_surface_->context_provider());
ReleaseTreeResources();
renderer_.reset();
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 764a9cf..0c4fc35 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -34,6 +34,7 @@
#include "cc/resources/layer_tiling_data.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "cc/test/fake_video_frame_provider.h"
@@ -372,20 +373,18 @@ TEST_F(LayerTreeHostImplTest, CanDrawIncompleteFrames) {
settings.impl_side_painting = true;
host_impl_ = LayerTreeHostImpl::Create(
settings, this, &proxy_, &stats_instrumentation_);
+
+ scoped_ptr<FakeOutputSurface> output_surface(
+ FakeOutputSurface::CreateAlwaysDrawAndSwap3d());
+
host_impl_->InitializeRenderer(
- FakeOutputSurface::CreateAlwaysDrawAndSwap3d().PassAs<OutputSurface>());
+ output_surface.PassAs<OutputSurface>());
host_impl_->SetViewportSize(gfx::Size(10, 10));
bool always_draw = true;
CheckNotifyCalledIfCanDrawChanged(always_draw);
}
-class TestWebGraphicsContext3DMakeCurrentFails
- : public TestWebGraphicsContext3D {
- public:
- virtual bool makeContextCurrent() OVERRIDE { return false; }
-};
-
TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) {
ASSERT_FALSE(host_impl_->active_tree()->root_layer());
@@ -480,12 +479,15 @@ TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) {
this,
&proxy_,
&stats_instrumentation_);
+ scoped_ptr<TestWebGraphicsContext3D> context_owned =
+ TestWebGraphicsContext3D::Create();
+ context_owned->set_times_make_current_succeeds(0);
+
+ scoped_ptr<FakeOutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.Pass()));
// Initialization will fail here.
- host_impl_->InitializeRenderer(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- new TestWebGraphicsContext3DMakeCurrentFails))
- .PassAs<OutputSurface>());
+ host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>());
host_impl_->SetViewportSize(gfx::Size(10, 10));
SetupScrollAndContentsLayers(gfx::Size(100, 100));
@@ -2850,14 +2852,14 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
settings.impl_side_painting = true;
host_impl_ = LayerTreeHostImpl::Create(
settings, this, &proxy_, &stats_instrumentation_);
- scoped_ptr<OutputSurface> output_surface;
- if (always_draw) {
- output_surface = FakeOutputSurface::CreateAlwaysDrawAndSwap3d()
- .PassAs<OutputSurface>();
- } else {
- output_surface = CreateFakeOutputSurface();
- }
- host_impl_->InitializeRenderer(output_surface.Pass());
+
+ scoped_ptr<FakeOutputSurface> output_surface;
+ if (always_draw)
+ output_surface = FakeOutputSurface::CreateAlwaysDrawAndSwap3d().Pass();
+ else
+ output_surface = FakeOutputSurface::Create3d().Pass();
+
+ host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>());
viewport_size_ = gfx::Size(1000, 1000);
}
@@ -3081,11 +3083,11 @@ class FakeDrawableLayerImpl: public LayerImpl {
// can leave the window at the wrong size if we never draw and the proper
// viewport size is never set.
TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) {
- scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext))
- .PassAs<OutputSurface>();
- ReshapeTrackerContext* reshape_tracker =
- static_cast<ReshapeTrackerContext*>(output_surface->context3d());
+ scoped_ptr<ReshapeTrackerContext> owned_reshape_tracker(
+ new ReshapeTrackerContext);
+ ReshapeTrackerContext* reshape_tracker = owned_reshape_tracker.get();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ owned_reshape_tracker.PassAs<TestWebGraphicsContext3D>()));
host_impl_->InitializeRenderer(output_surface.Pass());
scoped_ptr<LayerImpl> root =
@@ -3175,11 +3177,11 @@ class SwapTrackerContext : public TestWebGraphicsContext3D {
// Make sure damage tracking propagates all the way to the graphics context,
// where it should request to swap only the sub-buffer that is damaged.
TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new SwapTrackerContext)).PassAs<OutputSurface>();
- SwapTrackerContext* swap_tracker =
- static_cast<SwapTrackerContext*>(output_surface->context3d());
+ scoped_ptr<SwapTrackerContext> context(new SwapTrackerContext);
+ SwapTrackerContext* swap_tracker = context.get();
+
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context.PassAs<TestWebGraphicsContext3D>()));
// This test creates its own LayerTreeHostImpl, so
// that we can force partial swap enabled.
@@ -3414,11 +3416,11 @@ class MockContextHarness {
};
TEST_F(LayerTreeHostImplTest, NoPartialSwap) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new MockContext)).PassAs<OutputSurface>();
- MockContext* mock_context =
- static_cast<MockContext*>(output_surface->context3d());
+ scoped_ptr<MockContext> mock_context_owned(new MockContext);
+ MockContext* mock_context = mock_context_owned.get();
+
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
MockContextHarness harness(mock_context);
// Run test case
@@ -3451,11 +3453,10 @@ TEST_F(LayerTreeHostImplTest, NoPartialSwap) {
}
TEST_F(LayerTreeHostImplTest, PartialSwap) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new MockContext)).PassAs<OutputSurface>();
- MockContext* mock_context =
- static_cast<MockContext*>(output_surface->context3d());
+ scoped_ptr<MockContext> context_owned(new MockContext);
+ MockContext* mock_context = context_owned.get();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ context_owned.PassAs<TestWebGraphicsContext3D>()));
MockContextHarness harness(mock_context);
CreateLayerTreeHost(true, output_surface.Pass());
@@ -3515,9 +3516,8 @@ static scoped_ptr<LayerTreeHostImpl> SetupLayersForOpacity(
LayerTreeHostImplClient* client,
Proxy* proxy,
RenderingStatsInstrumentation* stats_instrumentation) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
LayerTreeSettings settings;
settings.partial_swap_enabled = partial_swap;
@@ -3672,8 +3672,8 @@ TEST_F(LayerTreeHostImplTest, LayersFreeTextures) {
scoped_ptr<TestWebGraphicsContext3D> context =
TestWebGraphicsContext3D::Create();
TestWebGraphicsContext3D* context3d = context.get();
- scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(
+ FakeOutputSurface::Create3d(context.Pass()));
host_impl_->InitializeRenderer(output_surface.Pass());
scoped_ptr<LayerImpl> root_layer =
@@ -3732,12 +3732,12 @@ class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D {
};
TEST_F(LayerTreeHostImplTest, HasTransparentBackground) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new MockDrawQuadsToFillScreenContext)).PassAs<OutputSurface>();
- MockDrawQuadsToFillScreenContext* mock_context =
- static_cast<MockDrawQuadsToFillScreenContext*>(
- output_surface->context3d());
+ scoped_ptr<MockDrawQuadsToFillScreenContext> mock_context_owned(
+ new MockDrawQuadsToFillScreenContext);
+ MockDrawQuadsToFillScreenContext* mock_context = mock_context_owned.get();
+
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
// Run test case
CreateLayerTreeHost(false, output_surface.Pass());
@@ -3790,9 +3790,8 @@ static void SetupLayersForTextureCaching(
LayerImpl*& surface_layer_ptr,
LayerImpl*& child_ptr,
gfx::Size root_size) {
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
layer_tree_host_impl->InitializeRenderer(output_surface.Pass());
layer_tree_host_impl->SetViewportSize(root_size);
@@ -3869,9 +3868,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusion) {
LayerImpl* layer_s1_ptr;
LayerImpl* layer_s2_ptr;
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
gfx::Size root_size(1000, 1000);
@@ -3988,9 +3986,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionEarlyOut) {
LayerImpl* layer_s1_ptr;
LayerImpl* layer_s2_ptr;
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
gfx::Size root_size(1000, 1000);
@@ -4109,9 +4106,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionExternalOverInternal) {
LayerImpl* layer_s1_ptr;
LayerImpl* layer_s2_ptr;
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
gfx::Size root_size(1000, 1000);
@@ -4199,9 +4195,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionExternalNotAligned) {
LayerImpl* root_ptr;
LayerImpl* layer_s1_ptr;
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
gfx::Size root_size(1000, 1000);
@@ -4290,9 +4285,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionPartialSwap) {
LayerImpl* layer_s1_ptr;
LayerImpl* layer_s2_ptr;
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
gfx::Size root_size(1000, 1000);
@@ -4420,9 +4414,8 @@ TEST_F(LayerTreeHostImplTest, TextureCachingWithScissor) {
gfx::Rect child_rect(10, 10, 50, 50);
gfx::Rect grand_child_rect(5, 5, 150, 150);
- scoped_ptr<OutputSurface> output_surface =
- FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
- new PartialSwapContext)).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext)));
my_host_impl->InitializeRenderer(output_surface.Pass());
root->SetAnchorPoint(gfx::PointF());
@@ -5296,8 +5289,11 @@ static void VerifyRenderPassTestData(
}
TEST_F(LayerTreeHostImplTest, TestRemoveRenderPasses) {
+ FakeOutputSurfaceClient output_surface_client;
scoped_ptr<OutputSurface> output_surface(CreateOutputSurface());
- ASSERT_TRUE(output_surface->context3d());
+ ASSERT_TRUE(output_surface->BindToClient(&output_surface_client));
+ ASSERT_TRUE(output_surface->context_provider());
+
scoped_ptr<ResourceProvider> resource_provider =
ResourceProvider::Create(output_surface.get(), 0);
@@ -6213,9 +6209,8 @@ TEST_F(LayerTreeHostImplTest, DeferredInitializeSmoke) {
// DeferredInitialize and hardware draw.
EXPECT_FALSE(did_try_initialize_renderer_);
- EXPECT_TRUE(output_surface_ptr->SetAndInitializeContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- TestWebGraphicsContext3D::Create())));
+ EXPECT_TRUE(output_surface_ptr->InitializeAndSetContext3d(
+ TestContextProvider::Create(), NULL));
EXPECT_TRUE(did_try_initialize_renderer_);
// Defer intialized GL draw.
@@ -6246,10 +6241,10 @@ TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) {
&proxy_,
&stats_instrumentation_);
- host_impl_->InitializeRenderer(FakeOutputSurface::Create3d(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- new ContextThatDoesNotSupportMemoryManagmentExtensions))
- .PassAs<OutputSurface>());
+ scoped_ptr<OutputSurface> output_surface(
+ FakeOutputSurface::Create3d(scoped_ptr<TestWebGraphicsContext3D>(
+ new ContextThatDoesNotSupportMemoryManagmentExtensions)));
+ host_impl_->InitializeRenderer(output_surface.Pass());
EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes());
}
@@ -6280,8 +6275,7 @@ TEST_F(LayerTreeHostImplTest, UIResourceManagement) {
scoped_ptr<TestWebGraphicsContext3D> context =
TestWebGraphicsContext3D::Create();
TestWebGraphicsContext3D* context3d = context.get();
- scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ scoped_ptr<OutputSurface> output_surface = CreateFakeOutputSurface();
host_impl_->InitializeRenderer(output_surface.Pass());
EXPECT_EQ(0u, context3d->NumTextures());
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index 55841e5..570357d9 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -10,6 +10,7 @@
#include "base/synchronization/lock.h"
#include "cc/animation/timing_function.h"
#include "cc/debug/frame_rate_counter.h"
+#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/io_surface_layer.h"
@@ -1146,7 +1147,7 @@ class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest {
ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
switch (impl->active_tree()->source_frame_number()) {
case 0:
@@ -1188,7 +1189,7 @@ class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest {
virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
if (drew_frame_ == impl->active_tree()->source_frame_number()) {
EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_;
@@ -1225,7 +1226,7 @@ class LayerTreeHostTestDelegatingRendererAtomicCommit
ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
switch (impl->active_tree()->source_frame_number()) {
case 0:
@@ -1347,7 +1348,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate
ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
switch (impl->active_tree()->source_frame_number()) {
case 0:
@@ -1412,7 +1413,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate
EXPECT_LT(impl->active_tree()->source_frame_number(), 5);
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
// Number of textures used for drawing should one per layer except for
// frame 3 where the viewport only contains one layer.
@@ -2370,23 +2371,12 @@ class LayerTreeHostTestChangeLayerPropertiesInPaintContents
SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents);
-class MockIOSurfaceWebGraphicsContext3D : public FakeWebGraphicsContext3D {
+class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D {
public:
- MockIOSurfaceWebGraphicsContext3D()
- : FakeWebGraphicsContext3D() {}
-
virtual WebKit::WebGLId createTexture() OVERRIDE {
return 1;
}
- virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE {
- if (name == GL_EXTENSIONS) {
- return WebKit::WebString(
- "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle");
- }
- return WebKit::WebString();
- }
-
MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture));
MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target,
WebKit::WebGLId texture_id));
@@ -2402,6 +2392,7 @@ class MockIOSurfaceWebGraphicsContext3D : public FakeWebGraphicsContext3D {
WebKit::WGC3Dsizei count,
WebKit::WGC3Denum type,
WebKit::WGC3Dintptr offset));
+ MOCK_METHOD1(deleteTexture, void(WebKit::WGC3Denum texture));
};
@@ -2409,11 +2400,14 @@ class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
protected:
virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
OVERRIDE {
- scoped_ptr<MockIOSurfaceWebGraphicsContext3D> context(
+ scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned(
new MockIOSurfaceWebGraphicsContext3D);
- mock_context_ = context.get();
- scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(
- context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ mock_context_ = mock_context_owned.get();
+
+ mock_context_->set_have_extension_io_surface(true);
+
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
+ mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
return output_surface.Pass();
}
@@ -2492,6 +2486,8 @@ class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
Mock::VerifyAndClearExpectations(&mock_context_);
+
+ EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(1);
EndTest();
}
@@ -2595,10 +2591,14 @@ class LayerTreeHostTestAsyncReadback : public LayerTreeHostTest {
virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
OVERRIDE {
- if (use_gl_renderer_)
- return FakeOutputSurface::Create3d().PassAs<OutputSurface>();
- return FakeOutputSurface::CreateSoftware(
- make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>();
+ scoped_ptr<FakeOutputSurface> output_surface;
+ if (use_gl_renderer_) {
+ output_surface = FakeOutputSurface::Create3d().Pass();
+ } else {
+ output_surface = FakeOutputSurface::CreateSoftware(
+ make_scoped_ptr(new SoftwareOutputDevice)).Pass();
+ }
+ return output_surface.PassAs<OutputSurface>();
}
bool use_gl_renderer_;
@@ -3183,10 +3183,12 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest {
void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) {
EXPECT_FALSE(did_initialize_gl_);
// SetAndInitializeContext3D calls SetNeedsCommit.
- EXPECT_TRUE(static_cast<FakeOutputSurface*>(host_impl->output_surface())
- ->SetAndInitializeContext3D(
- scoped_ptr<WebKit::WebGraphicsContext3D>(
- TestWebGraphicsContext3D::Create())));
+ FakeOutputSurface* fake_output_surface =
+ static_cast<FakeOutputSurface*>(host_impl->output_surface());
+ scoped_refptr<TestContextProvider> context_provider =
+ TestContextProvider::Create(); // Not bound to thread.
+ EXPECT_TRUE(fake_output_surface->InitializeAndSetContext3d(
+ context_provider, NULL));
did_initialize_gl_ = true;
}
@@ -3254,7 +3256,7 @@ class LayerTreeHostTestUIResource : public LayerTreeHostTest {
void PerformTest(LayerTreeHostImpl* impl) {
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
- impl->output_surface()->context3d());
+ impl->output_surface()->context_provider()->Context3d());
int frame = num_commits_;
switch (frame) {
diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc
index 3404c1e..d6d501b 100644
--- a/cc/trees/layer_tree_host_unittest_context.cc
+++ b/cc/trees/layer_tree_host_unittest_context.cc
@@ -108,11 +108,11 @@ class LayerTreeHostContextTest : public LayerTreeTest {
}
if (delegating_renderer()) {
- return FakeOutputSurface::CreateDelegating3d(
- context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ return FakeOutputSurface::CreateDelegating3d(context3d.Pass())
+ .PassAs<OutputSurface>();
}
- return FakeOutputSurface::Create3d(
- context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
+ return FakeOutputSurface::Create3d(context3d.Pass())
+ .PassAs<OutputSurface>();
}
scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() {
@@ -141,10 +141,11 @@ class LayerTreeHostContextTest : public LayerTreeTest {
if (!offscreen_contexts_main_thread_.get() ||
offscreen_contexts_main_thread_->DestroyedOnMainThread()) {
- offscreen_contexts_main_thread_ = TestContextProvider::Create(
- base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
- base::Unretained(this)));
- if (offscreen_contexts_main_thread_.get() &&
+ offscreen_contexts_main_thread_ =
+ TestContextProvider::Create(
+ base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
+ base::Unretained(this)));
+ if (offscreen_contexts_main_thread_ &&
!offscreen_contexts_main_thread_->BindToCurrentThread())
offscreen_contexts_main_thread_ = NULL;
}
@@ -157,9 +158,10 @@ class LayerTreeHostContextTest : public LayerTreeTest {
if (!offscreen_contexts_compositor_thread_.get() ||
offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) {
- offscreen_contexts_compositor_thread_ = TestContextProvider::Create(
- base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
- base::Unretained(this)));
+ offscreen_contexts_compositor_thread_ =
+ TestContextProvider::Create(
+ base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
+ base::Unretained(this)));
}
return offscreen_contexts_compositor_thread_;
}
@@ -1219,6 +1221,10 @@ class LayerTreeHostContextTestDontUseLostResources
LayerTreeHostContextTest::CommitCompleteOnThread(host_impl);
ResourceProvider* resource_provider = host_impl->resource_provider();
+ ContextProvider* context_provider =
+ host_impl->output_surface()->context_provider();
+
+ DCHECK(context_provider);
if (host_impl->active_tree()->source_frame_number() == 0) {
// Set up impl resources on the first commit.
@@ -1255,9 +1261,8 @@ class LayerTreeHostContextTestDontUseLostResources
static_cast<TextureLayerImpl*>(
host_impl->active_tree()->root_layer()->children()[2]);
texture_impl->set_texture_id(
- resource_provider->GraphicsContext3D()->createTexture());
+ context_provider->Context3d()->createTexture());
- DCHECK(resource_provider->GraphicsContext3D());
ResourceProvider::ResourceId texture = resource_provider->CreateResource(
gfx::Size(4, 4),
resource_provider->default_resource_type(),
@@ -1265,9 +1270,8 @@ class LayerTreeHostContextTestDontUseLostResources
ResourceProvider::ScopedWriteLockGL lock(resource_provider, texture);
gpu::Mailbox mailbox;
- resource_provider->GraphicsContext3D()->genMailboxCHROMIUM(mailbox.name);
- unsigned sync_point =
- resource_provider->GraphicsContext3D()->insertSyncPoint();
+ context_provider->Context3d()->genMailboxCHROMIUM(mailbox.name);
+ unsigned sync_point = context_provider->Context3d()->insertSyncPoint();
color_video_frame_ = VideoFrame::CreateColorFrame(
gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta());
diff --git a/cc/trees/layer_tree_host_unittest_delegated.cc b/cc/trees/layer_tree_host_unittest_delegated.cc
index d489313..b76184e 100644
--- a/cc/trees/layer_tree_host_unittest_delegated.cc
+++ b/cc/trees/layer_tree_host_unittest_delegated.cc
@@ -19,6 +19,7 @@
#include "cc/test/layer_tree_test.h"
#include "cc/trees/layer_tree_impl.h"
#include "gpu/GLES2/gl2extchromium.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
namespace cc {
namespace {
@@ -246,8 +247,8 @@ class LayerTreeHostDelegatedTestCreateChildId
FakeDelegatedRendererLayerImpl* delegated_impl =
static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
- WebKit::WebGraphicsContext3D* context =
- host_impl->resource_provider()->GraphicsContext3D();
+ ContextProvider* context_provider =
+ host_impl->output_surface()->context_provider();
++num_activates_;
switch (num_activates_) {
@@ -255,8 +256,9 @@ class LayerTreeHostDelegatedTestCreateChildId
EXPECT_TRUE(delegated_impl->ChildId());
EXPECT_FALSE(did_reset_child_id_);
- context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
- GL_INNOCENT_CONTEXT_RESET_ARB);
+ context_provider->Context3d()->loseContextCHROMIUM(
+ GL_GUILTY_CONTEXT_RESET_ARB,
+ GL_INNOCENT_CONTEXT_RESET_ARB);
break;
case 3:
EXPECT_TRUE(delegated_impl->ChildId());
diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc
index 70ad6de..2850dee 100644
--- a/cc/trees/layer_tree_impl.cc
+++ b/cc/trees/layer_tree_impl.cc
@@ -408,6 +408,10 @@ const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const {
return layer_tree_host_impl_->GetRendererCapabilities();
}
+ContextProvider* LayerTreeImpl::context_provider() const {
+ return output_surface()->context_provider();
+}
+
OutputSurface* LayerTreeImpl::output_surface() const {
return layer_tree_host_impl_->output_surface();
}
diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h
index 7e66da8..fbd32db 100644
--- a/cc/trees/layer_tree_impl.h
+++ b/cc/trees/layer_tree_impl.h
@@ -28,6 +28,7 @@ struct hash<cc::LayerImpl*> {
namespace cc {
+class ContextProvider;
class DebugRectHistory;
class FrameRateCounter;
class HeadsUpDisplayLayerImpl;
@@ -58,6 +59,7 @@ class CC_EXPORT LayerTreeImpl {
// ---------------------------------------------------------------------------
const LayerTreeSettings& settings() const;
const RendererCapabilities& GetRendererCapabilities() const;
+ ContextProvider* context_provider() const;
OutputSurface* output_surface() const;
ResourceProvider* resource_provider() const;
TileManager* tile_manager() const;