diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-22 03:22:19 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-22 03:22:19 +0000 |
commit | 41b53ac72fcfe430e816cea48a32bb00e346547f (patch) | |
tree | 0f3f1f082451247693dba41dcb919d270991c96a /cc | |
parent | 887dc5d85a487e0a071099b58f1ea2235602a0ab (diff) | |
download | chromium_src-41b53ac72fcfe430e816cea48a32bb00e346547f.zip chromium_src-41b53ac72fcfe430e816cea48a32bb00e346547f.tar.gz chromium_src-41b53ac72fcfe430e816cea48a32bb00e346547f.tar.bz2 |
cc: Allow DeferredInitialize to use DelegatingRenderer
Currently DeferredInitialize assumes OutputSurface never has
delegated_rendering capability. With this change, remove this
assumption by always first creating SoftwareRenderer for
OutputSurface with deferred_gl_initialization. Then create
either DelegatingRenderer or GLRenderer depending on
delegated_rendering capability in DeferredInitialize.
With support for DelegatingRenderer and DeferredInititalize,
have to ensure that all GL resources are returned to child
before ReleasGL is called, because ContextProvider is going
away after ReleaseGL. Add a DCHECK for this in
ResourceProvider::CleanUpGLIfNeeded.
New path covered by LayerTreeHostTestDeferredInitialize.
BUG=344087
Review URL: https://codereview.chromium.org/286953008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272070 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layers/picture_layer_impl_unittest.cc | 8 | ||||
-rw-r--r-- | cc/output/output_surface.cc | 8 | ||||
-rw-r--r-- | cc/output/output_surface.h | 5 | ||||
-rw-r--r-- | cc/output/output_surface_client.h | 1 | ||||
-rw-r--r-- | cc/output/output_surface_unittest.cc | 3 | ||||
-rw-r--r-- | cc/resources/resource_provider.cc | 9 | ||||
-rw-r--r-- | cc/resources/resource_provider_unittest.cc | 6 | ||||
-rw-r--r-- | cc/test/fake_output_surface.h | 6 | ||||
-rw-r--r-- | cc/test/fake_output_surface_client.cc | 6 | ||||
-rw-r--r-- | cc/test/fake_output_surface_client.h | 15 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 23 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.h | 6 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl_unittest.cc | 18 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 24 |
14 files changed, 102 insertions, 36 deletions
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 3fc94b1..d919298 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -1915,9 +1915,11 @@ TEST_F(PictureLayerImplTest, PinchingTooSmall) { class DeferredInitPictureLayerImplTest : public PictureLayerImplTest { public: virtual void InitializeRenderer() OVERRIDE { - host_impl_.InitializeRenderer(FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) - .PassAs<OutputSurface>()); + bool delegated_rendering = false; + host_impl_.InitializeRenderer( + FakeOutputSurface::CreateDeferredGL( + scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), + delegated_rendering).PassAs<OutputSurface>()); } virtual void SetUp() OVERRIDE { diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc index 80def54..46096d2 100644 --- a/cc/output/output_surface.cc +++ b/cc/output/output_surface.cc @@ -163,7 +163,7 @@ void OutputSurface::ReleaseGL() { DCHECK(client_); DCHECK(context_provider_); client_->ReleaseGL(); - ResetContext3d(); + DCHECK(!context_provider_); } void OutputSurface::SetUpContext3d() { @@ -181,6 +181,12 @@ void OutputSurface::SetUpContext3d() { base::Unretained(this))); } +void OutputSurface::ReleaseContextProvider() { + DCHECK(client_); + DCHECK(context_provider_); + ResetContext3d(); +} + void OutputSurface::ResetContext3d() { if (context_provider_.get()) { while (!pending_gpu_latency_query_ids_.empty()) { diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h index c82a087..f992e97 100644 --- a/cc/output/output_surface.h +++ b/cc/output/output_surface.h @@ -105,6 +105,11 @@ class CC_EXPORT OutputSurface { // thread. virtual bool BindToClient(OutputSurfaceClient* client); + // This is called by the compositor on the compositor thread inside ReleaseGL + // in order to release the ContextProvider. Only used with + // deferred_gl_initialization capability. + void ReleaseContextProvider(); + // Enable or disable vsync. void SetThrottleFrameProduction(bool enable); diff --git a/cc/output/output_surface_client.h b/cc/output/output_surface_client.h index c188fe0..9742a6f 100644 --- a/cc/output/output_surface_client.h +++ b/cc/output/output_surface_client.h @@ -28,6 +28,7 @@ class CC_EXPORT OutputSurfaceClient { // the compositor should be able to draw using GL what was previously // committed. virtual void DeferredInitialize() = 0; + // Must call OutputSurface::ReleaseContextProvider inside this call. virtual void ReleaseGL() = 0; virtual void CommitVSyncParameters(base::TimeTicks timebase, base::TimeDelta interval) = 0; diff --git a/cc/output/output_surface_unittest.cc b/cc/output/output_surface_unittest.cc index 709e03c..76a2a72 100644 --- a/cc/output/output_surface_unittest.cc +++ b/cc/output/output_surface_unittest.cc @@ -126,7 +126,8 @@ class OutputSurfaceTestInitializeNewContext3d : public ::testing::Test { OutputSurfaceTestInitializeNewContext3d() : context_provider_(TestContextProvider::Create()), output_surface_( - scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) {} + scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)), + client_(&output_surface_) {} protected: void BindOutputSurface() { diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 09b12a3..de683e7 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -1321,6 +1321,15 @@ void ResourceProvider::CleanUpGLIfNeeded() { } DCHECK(gl); +#if DCHECK_IS_ON + // Check that all GL resources has been deleted. + for (ResourceMap::const_iterator itr = resources_.begin(); + itr != resources_.end(); + ++itr) { + DCHECK_NE(GLTexture, itr->second.type); + } +#endif // DCHECK_IS_ON + texture_uploader_.reset(); texture_id_allocator_.reset(); buffer_id_allocator_.reset(); diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index 547bdbb..4bf9ec0 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -3185,10 +3185,12 @@ void InitializeGLAndCheck(ContextSharedData* shared_data, TEST(ResourceProviderTest, BasicInitializeGLSoftware) { scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); - FakeOutputSurfaceClient client; + bool delegated_rendering = false; scoped_ptr<FakeOutputSurface> output_surface( FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))); + scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), + delegated_rendering)); + FakeOutputSurfaceClient client(output_surface.get()); EXPECT_TRUE(output_surface->BindToClient(&client)); scoped_ptr<SharedBitmapManager> shared_bitmap_manager( new TestSharedBitmapManager()); diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h index e44153c..f8acc1d 100644 --- a/cc/test/fake_output_surface.h +++ b/cc/test/fake_output_surface.h @@ -66,11 +66,11 @@ class FakeOutputSurface : public OutputSurface { new FakeOutputSurface(software_device.Pass(), true)); } - // TODO(boliu): Use a general factory that takes Capabilities arg. static scoped_ptr<FakeOutputSurface> CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice> software_device) { + scoped_ptr<SoftwareOutputDevice> software_device, + bool delegated_rendering) { scoped_ptr<FakeOutputSurface> result( - new FakeOutputSurface(software_device.Pass(), false)); + new FakeOutputSurface(software_device.Pass(), delegated_rendering)); result->capabilities_.deferred_gl_initialization = true; return result.Pass(); } diff --git a/cc/test/fake_output_surface_client.cc b/cc/test/fake_output_surface_client.cc index 2033ace..6fabdf8 100644 --- a/cc/test/fake_output_surface_client.cc +++ b/cc/test/fake_output_surface_client.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "cc/output/output_surface.h" #include "cc/test/fake_output_surface_client.h" namespace cc { @@ -10,6 +11,11 @@ void FakeOutputSurfaceClient::DeferredInitialize() { deferred_initialize_called_ = true; } +void FakeOutputSurfaceClient::ReleaseGL() { + if (output_surface_) + output_surface_->ReleaseContextProvider(); +} + void FakeOutputSurfaceClient::BeginFrame(const BeginFrameArgs& args) { begin_frame_count_++; } diff --git a/cc/test/fake_output_surface_client.h b/cc/test/fake_output_surface_client.h index 0548bde..7058e52 100644 --- a/cc/test/fake_output_surface_client.h +++ b/cc/test/fake_output_surface_client.h @@ -10,16 +10,26 @@ namespace cc { +class OutputSurface; + class FakeOutputSurfaceClient : public OutputSurfaceClient { public: FakeOutputSurfaceClient() - : begin_frame_count_(0), + : output_surface_(NULL), + begin_frame_count_(0), + deferred_initialize_called_(false), + did_lose_output_surface_called_(false), + memory_policy_(0) {} + + explicit FakeOutputSurfaceClient(OutputSurface* output_surface) + : output_surface_(output_surface), + begin_frame_count_(0), deferred_initialize_called_(false), did_lose_output_surface_called_(false), memory_policy_(0) {} virtual void DeferredInitialize() OVERRIDE; - virtual void ReleaseGL() OVERRIDE {} + virtual void ReleaseGL() OVERRIDE; virtual void CommitVSyncParameters(base::TimeTicks timebase, base::TimeDelta interval) OVERRIDE {} virtual void SetNeedsRedrawRect(const gfx::Rect& damage_rect) OVERRIDE {} @@ -49,6 +59,7 @@ class FakeOutputSurfaceClient : public OutputSurfaceClient { const ManagedMemoryPolicy& memory_policy() const { return memory_policy_; } private: + OutputSurface* output_surface_; int begin_frame_count_; bool deferred_initialize_called_; bool did_lose_output_surface_called_; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 2294bb5..44da104 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -573,7 +573,10 @@ static DrawMode GetDrawMode(OutputSurface* output_surface) { return DRAW_MODE_HARDWARE; } else { DCHECK_EQ(!output_surface->software_device(), - output_surface->capabilities().delegated_rendering); + output_surface->capabilities().delegated_rendering && + !output_surface->capabilities().deferred_gl_initialization) + << output_surface->capabilities().delegated_rendering << " " + << output_surface->capabilities().deferred_gl_initialization; return DRAW_MODE_SOFTWARE; } } @@ -1823,13 +1826,12 @@ void LayerTreeHostImpl::ReleaseTreeResources() { void LayerTreeHostImpl::CreateAndSetRenderer( OutputSurface* output_surface, - ResourceProvider* resource_provider, - bool skip_gl_renderer) { + ResourceProvider* resource_provider) { DCHECK(!renderer_); if (output_surface->capabilities().delegated_rendering) { renderer_ = DelegatingRenderer::Create( this, &settings_, output_surface, resource_provider); - } else if (output_surface->context_provider() && !skip_gl_renderer) { + } else if (output_surface->context_provider()) { renderer_ = GLRenderer::Create(this, &settings_, output_surface, @@ -1956,9 +1958,7 @@ bool LayerTreeHostImpl::InitializeRenderer( if (output_surface->capabilities().deferred_gl_initialization) EnforceZeroBudget(true); - bool skip_gl_renderer = false; - CreateAndSetRenderer( - output_surface.get(), resource_provider.get(), skip_gl_renderer); + CreateAndSetRenderer(output_surface.get(), resource_provider.get()); transfer_buffer_memory_limit_ = GetMaxTransferBufferUsageBytes(output_surface->context_provider().get()); @@ -2026,9 +2026,7 @@ void LayerTreeHostImpl::DeferredInitialize() { resource_provider_->InitializeGL(); - bool skip_gl_renderer = false; - CreateAndSetRenderer( - output_surface_.get(), resource_provider_.get(), skip_gl_renderer); + CreateAndSetRenderer(output_surface_.get(), resource_provider_.get()); EnforceZeroBudget(false); client_->SetNeedsCommitOnImplThread(); @@ -2048,9 +2046,8 @@ void LayerTreeHostImpl::ReleaseGL() { staging_resource_pool_.reset(); resource_provider_->InitializeSoftware(); - bool skip_gl_renderer = true; - CreateAndSetRenderer( - output_surface_.get(), resource_provider_.get(), skip_gl_renderer); + output_surface_->ReleaseContextProvider(); + CreateAndSetRenderer(output_surface_.get(), resource_provider_.get()); EnforceZeroBudget(true); DCHECK(GetRendererCapabilities().using_map_image); diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index 3975e61..44f3985 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -483,10 +483,8 @@ class CC_EXPORT LayerTreeHostImpl Proxy* proxy_; private: - void CreateAndSetRenderer( - OutputSurface* output_surface, - ResourceProvider* resource_provider, - bool skip_gl_renderer); + void CreateAndSetRenderer(OutputSurface* output_surface, + ResourceProvider* resource_provider); void CreateAndSetTileManager(ResourceProvider* resource_provider, ContextProvider* context_provider, bool use_zero_copy, diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index 802b854..919382f 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -5542,8 +5542,11 @@ TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) { // No main thread evictions in resourceless software mode. set_reduce_memory_result(false); CountingSoftwareDevice* software_device = new CountingSoftwareDevice(); - FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(software_device)).release(); + bool delegated_rendering = false; + FakeOutputSurface* output_surface = + FakeOutputSurface::CreateDeferredGL( + scoped_ptr<SoftwareOutputDevice>(software_device), + delegated_rendering).release(); EXPECT_TRUE(CreateHostImpl(DefaultSettings(), scoped_ptr<OutputSurface>(output_surface))); host_impl_->SetViewportSize(gfx::Size(50, 50)); @@ -5569,8 +5572,11 @@ TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) { TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { set_reduce_memory_result(false); - FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release(); + bool delegated_rendering = false; + FakeOutputSurface* output_surface = + FakeOutputSurface::CreateDeferredGL( + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()), + delegated_rendering).release(); EXPECT_TRUE(CreateHostImpl(DefaultSettings(), scoped_ptr<OutputSurface>(output_surface))); @@ -5607,9 +5613,11 @@ class LayerTreeHostImplTestDeferredInitialize : public LayerTreeHostImplTest { set_reduce_memory_result(false); + bool delegated_rendering = false; scoped_ptr<FakeOutputSurface> output_surface( FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()), + delegated_rendering)); output_surface_ = output_surface.get(); EXPECT_TRUE(CreateHostImpl(DefaultSettings(), diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 8c8ac72..ce8381f 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -20,6 +20,7 @@ #include "cc/layers/solid_color_layer.h" #include "cc/layers/video_layer.h" #include "cc/output/begin_frame_args.h" +#include "cc/output/compositor_frame_ack.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" #include "cc/output/output_surface.h" @@ -2725,7 +2726,8 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { TestWebGraphicsContext3D::Create()); return FakeOutputSurface::CreateDeferredGL( - scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)); + scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), + delegating_renderer()); } virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { @@ -2784,6 +2786,24 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { did_release_gl_ = true; } + virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, + bool result) OVERRIDE { + ASSERT_TRUE(result); + DelegatedFrameData* delegated_frame_data = + output_surface()->last_sent_frame().delegated_frame_data.get(); + if (!delegated_frame_data) + return; + + // Return all resources immediately. + TransferableResourceArray resources_to_return = + output_surface()->resources_held_by_parent(); + + CompositorFrameAck ack; + for (size_t i = 0; i < resources_to_return.size(); ++i) + output_surface()->ReturnResource(resources_to_return[i].id, &ack); + host_impl->ReclaimResources(&ack); + } + virtual void AfterTest() OVERRIDE { EXPECT_TRUE(did_initialize_gl_); EXPECT_TRUE(did_release_gl_); @@ -2797,7 +2817,7 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { int last_source_frame_number_drawn_; }; -MULTI_THREAD_DIRECT_RENDERER_TEST_F(LayerTreeHostTestDeferredInitialize); +MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); // Test for UI Resource management. class LayerTreeHostTestUIResource : public LayerTreeHostTest { |