From d29c2783db449ea8c802423887fa4669abb453d5 Mon Sep 17 00:00:00 2001 From: kbr Date: Wed, 16 Sep 2015 18:43:02 -0700 Subject: [PATCH] Revert of cc: Implement shared worker contexts. (patchset #9 id:160001 of https://codereview.chromium.org/1336733002/ ) Reason for revert: Broke GPU rasterization on Mac OS; please see https://code.google.com/p/chromium/issues/detail?id=523411#c26 . I'm really sorry -- I don't know how this got past the CQ. Original issue's description: > cc: Implement shared worker contexts. > > This moves the responsibility to call BindToCurrentThread/SetupLock out > of cc::OutputSurface and to the maintainer of the (possibly) shared > context. > > OutputSurface now needs to be destroyed on the same thread they > were created. OutputSurface::DetachFromClient() can be used to > destroy any resources that need to be destroyed on the thread > that the OutputSurface has been bound to. > > BUG=523411 > CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel > > Committed: https://crrev.com/a47ef41ea03d3a5b8965eb700b682ddf8a1f055a > Cr-Commit-Position: refs/heads/master@{#349274} TBR=danakj@chromium.org,piman@chromium.org,sievers@chromium.org,reveman@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=523411 Review URL: https://codereview.chromium.org/1356463002 Cr-Commit-Position: refs/heads/master@{#349313} --- .../delegated_renderer_layer_impl_unittest.cc | 6 +-- cc/layers/heads_up_display_layer_impl_unittest.cc | 3 +- cc/layers/layer_impl_unittest.cc | 9 ++-- cc/layers/nine_patch_layer_impl_unittest.cc | 3 +- cc/layers/picture_image_layer_impl_unittest.cc | 4 +- cc/layers/picture_layer_impl_perftest.cc | 4 +- cc/layers/picture_layer_impl_unittest.cc | 23 +++------ cc/layers/texture_layer_unittest.cc | 4 +- cc/layers/ui_resource_layer_impl_unittest.cc | 9 ++-- cc/output/context_provider.h | 14 ++---- cc/output/output_surface.cc | 31 +++++-------- cc/output/output_surface.h | 10 +--- cc/raster/tile_task_worker_pool_unittest.cc | 5 +- cc/test/fake_output_surface.h | 18 ++++---- cc/test/fake_proxy.h | 2 +- cc/test/layer_test_common.cc | 4 +- cc/test/layer_test_common.h | 1 - cc/test/layer_tree_test.cc | 4 +- cc/test/test_context_provider.cc | 15 +----- cc/test/test_context_provider.h | 3 -- cc/tiles/tile_manager_perftest.cc | 4 +- cc/tiles/tile_manager_unittest.cc | 16 +++---- cc/trees/layer_tree_host.cc | 12 +---- cc/trees/layer_tree_host.h | 7 --- cc/trees/layer_tree_host_common_unittest.cc | 3 +- cc/trees/layer_tree_host_impl.cc | 42 ++++++----------- cc/trees/layer_tree_host_impl.h | 6 +-- cc/trees/layer_tree_host_impl_unittest.cc | 54 +++++++++------------- cc/trees/layer_tree_host_unittest.cc | 18 +------- cc/trees/layer_tree_impl_unittest.cc | 8 ++-- cc/trees/occlusion_tracker_perftest.cc | 6 +-- cc/trees/proxy.h | 2 +- cc/trees/single_thread_proxy.cc | 5 +- cc/trees/single_thread_proxy.h | 2 +- cc/trees/thread_proxy.cc | 11 +++-- cc/trees/thread_proxy.h | 5 +- .../synchronous_compositor_factory_impl.cc | 39 ++-------------- .../synchronous_compositor_factory_impl.h | 3 -- .../synchronous_compositor_output_surface.cc | 14 ++---- .../synchronous_compositor_output_surface.h | 1 - .../compositor/gpu_process_transport_factory.cc | 12 ++--- content/child/child_thread_impl.cc | 9 ++-- content/renderer/gpu/compositor_output_surface.cc | 30 ++++++------ content/renderer/gpu/compositor_output_surface.h | 1 - content/renderer/gpu/mailbox_output_surface.cc | 4 -- content/renderer/gpu/mailbox_output_surface.h | 1 - content/renderer/render_thread_impl.cc | 26 ----------- content/renderer/render_thread_impl.h | 4 -- content/renderer/render_widget.cc | 7 +-- ui/compositor/test/in_process_context_factory.cc | 32 +++---------- ui/compositor/test/in_process_context_factory.h | 4 +- ui/compositor/test/in_process_context_provider.h | 18 ++++---- 52 files changed, 174 insertions(+), 404 deletions(-) diff --git a/cc/layers/delegated_renderer_layer_impl_unittest.cc b/cc/layers/delegated_renderer_layer_impl_unittest.cc index 8410221e487c..69857dc345bc 100644 --- a/cc/layers/delegated_renderer_layer_impl_unittest.cc +++ b/cc/layers/delegated_renderer_layer_impl_unittest.cc @@ -32,14 +32,13 @@ class DelegatedRendererLayerImplTest : public testing::Test { public: DelegatedRendererLayerImplTest() : proxy_(), - always_impl_thread_and_main_thread_blocked_(&proxy_), - output_surface_(FakeOutputSurface::Create3d()) { + always_impl_thread_and_main_thread_blocked_(&proxy_) { LayerTreeSettings settings; settings.minimum_occlusion_tracking_size = gfx::Size(); host_impl_.reset(new FakeLayerTreeHostImpl( settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_)); - host_impl_->InitializeRenderer(output_surface_.get()); + host_impl_->InitializeRenderer(FakeOutputSurface::Create3d()); host_impl_->SetViewportSize(gfx::Size(10, 10)); } @@ -49,7 +48,6 @@ class DelegatedRendererLayerImplTest : public testing::Test { always_impl_thread_and_main_thread_blocked_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; scoped_ptr host_impl_; }; diff --git a/cc/layers/heads_up_display_layer_impl_unittest.cc b/cc/layers/heads_up_display_layer_impl_unittest.cc index ef377838571d..ad2215595aa6 100644 --- a/cc/layers/heads_up_display_layer_impl_unittest.cc +++ b/cc/layers/heads_up_display_layer_impl_unittest.cc @@ -34,11 +34,10 @@ TEST(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); host_impl.CreatePendingTree(); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); scoped_ptr layer = HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1); layer->SetBounds(gfx::Size(100, 100)); diff --git a/cc/layers/layer_impl_unittest.cc b/cc/layers/layer_impl_unittest.cc index 7404e4e26632..0676597eb760 100644 --- a/cc/layers/layer_impl_unittest.cc +++ b/cc/layers/layer_impl_unittest.cc @@ -89,10 +89,9 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); + EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); scoped_ptr root_clip = LayerImpl::Create(host_impl.active_tree(), 1); scoped_ptr root_ptr = @@ -248,10 +247,9 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); + EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); host_impl.active_tree()->SetRootLayer( LayerImpl::Create(host_impl.active_tree(), 1)); LayerImpl* root = host_impl.active_tree()->root_layer(); @@ -363,10 +361,9 @@ TEST(LayerImplTest, SafeOpaqueBackgroundColor) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); + EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); scoped_ptr layer = LayerImpl::Create(host_impl.active_tree(), 1); for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { diff --git a/cc/layers/nine_patch_layer_impl_unittest.cc b/cc/layers/nine_patch_layer_impl_unittest.cc index 3405bc545cfb..ac77d123d010 100644 --- a/cc/layers/nine_patch_layer_impl_unittest.cc +++ b/cc/layers/nine_patch_layer_impl_unittest.cc @@ -46,10 +46,9 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); scoped_ptr layer = NinePatchLayerImpl::Create(host_impl.active_tree(), 1); diff --git a/cc/layers/picture_image_layer_impl_unittest.cc b/cc/layers/picture_image_layer_impl_unittest.cc index 01ad1f308443..2a9dda710db5 100644 --- a/cc/layers/picture_image_layer_impl_unittest.cc +++ b/cc/layers/picture_image_layer_impl_unittest.cc @@ -43,13 +43,12 @@ class PictureImageLayerImplTest : public testing::Test { public: PictureImageLayerImplTest() : proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(PictureLayerImplImageTestSettings(), &proxy_, &shared_bitmap_manager_, &task_graph_runner_) { host_impl_.CreatePendingTree(); - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); } scoped_ptr CreateLayer(int id, @@ -94,7 +93,6 @@ class PictureImageLayerImplTest : public testing::Test { FakeImplProxy proxy_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; }; diff --git a/cc/layers/picture_layer_impl_perftest.cc b/cc/layers/picture_layer_impl_perftest.cc index 85d8c26cc8d2..9e7d82bf6fc3 100644 --- a/cc/layers/picture_layer_impl_perftest.cc +++ b/cc/layers/picture_layer_impl_perftest.cc @@ -41,7 +41,6 @@ class PictureLayerImplPerfTest : public testing::Test { public: PictureLayerImplPerfTest() : proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(LayerTreeSettings(), &proxy_, &shared_bitmap_manager_, @@ -51,7 +50,7 @@ class PictureLayerImplPerfTest : public testing::Test { kTimeCheckInterval) {} void SetUp() override { - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); } void SetupActiveTree(const gfx::Size& layer_bounds, @@ -165,7 +164,6 @@ class PictureLayerImplPerfTest : public testing::Test { TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeImplProxy proxy_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerImpl* active_layer_; LapTimer timer_; diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 970742b329dc..1628c0c5c76f 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -93,7 +93,6 @@ class PictureLayerImplTest : public testing::Test { public: PictureLayerImplTest() : proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_, @@ -108,7 +107,6 @@ class PictureLayerImplTest : public testing::Test { explicit PictureLayerImplTest(const LayerTreeSettings& settings) : proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(settings, &proxy_, &shared_bitmap_manager_, @@ -123,7 +121,7 @@ class PictureLayerImplTest : public testing::Test { void SetUp() override { InitializeRenderer(); } virtual void InitializeRenderer() { - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); } void SetupDefaultTrees(const gfx::Size& layer_bounds) { @@ -361,7 +359,6 @@ class PictureLayerImplTest : public testing::Test { FakeImplProxy proxy_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; int root_id_; int id_; @@ -1630,10 +1627,8 @@ TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) { TestWebGraphicsContext3D::Create(); context->set_max_texture_size(140); host_impl_.DidLoseOutputSurface(); - scoped_ptr new_output_surface = - FakeOutputSurface::Create3d(context.Pass()); - host_impl_.InitializeRenderer(new_output_surface.get()); - output_surface_ = new_output_surface.Pass(); + host_impl_.InitializeRenderer( + FakeOutputSurface::Create3d(context.Pass()).Pass()); SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, false); @@ -1677,10 +1672,8 @@ TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { TestWebGraphicsContext3D::Create(); context->set_max_texture_size(140); host_impl_.DidLoseOutputSurface(); - scoped_ptr new_output_surface = - FakeOutputSurface::Create3d(context.Pass()); - host_impl_.InitializeRenderer(new_output_surface.get()); - output_surface_ = new_output_surface.Pass(); + host_impl_.InitializeRenderer( + FakeOutputSurface::Create3d(context.Pass()).Pass()); SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, false); @@ -3932,12 +3925,10 @@ TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) { class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { public: - PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() { - output_surface_ = FakeOutputSurface::CreateDelegating3d(); - } + PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {} void InitializeRenderer() override { - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d()); } }; diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc index ef631d856912..82894299f7ae 100644 --- a/cc/layers/texture_layer_unittest.cc +++ b/cc/layers/texture_layer_unittest.cc @@ -189,7 +189,6 @@ class TextureLayerTest : public testing::Test { TextureLayerTest() : fake_client_( FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), test_data_(&shared_bitmap_manager_) {} @@ -215,7 +214,6 @@ class TextureLayerTest : public testing::Test { FakeLayerTreeHostClient fake_client_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; CommonMailboxObjects test_data_; LayerSettings layer_settings_; @@ -884,7 +882,7 @@ class TextureLayerImplWithMailboxTest : public TextureLayerTest { TextureLayerTest::SetUp(); layer_tree_host_ = MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); - EXPECT_TRUE(host_impl_.InitializeRenderer(output_surface_.get())); + EXPECT_TRUE(host_impl_.InitializeRenderer(FakeOutputSurface::Create3d())); } bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { diff --git a/cc/layers/ui_resource_layer_impl_unittest.cc b/cc/layers/ui_resource_layer_impl_unittest.cc index 826c53f8181a..e31d68ae6e59 100644 --- a/cc/layers/ui_resource_layer_impl_unittest.cc +++ b/cc/layers/ui_resource_layer_impl_unittest.cc @@ -60,10 +60,9 @@ TEST(UIResourceLayerImplTest, VerifyDrawQuads) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); // Make sure we're appending quads when there are valid values. gfx::Size bitmap_size(100, 100); @@ -107,10 +106,9 @@ TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); gfx::Size bitmap_size(100, 100); gfx::Size layer_size(100, 100);; @@ -138,10 +136,9 @@ TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) { FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); gfx::Size bitmap_size(100, 100); gfx::Size layer_size(100, 100); diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h index 47eff203548f..c024e02328e9 100644 --- a/cc/output/context_provider.h +++ b/cc/output/context_provider.h @@ -32,11 +32,11 @@ class ContextProvider : public base::RefCountedThreadSafe { explicit ScopedContextLock(ContextProvider* context_provider) : context_provider_(context_provider), context_lock_(*context_provider_->GetLock()) { - // Allow current thread to use |context_provider_|. + // Allow current thread to bind to |context_provider|. context_provider_->DetachFromThread(); } ~ScopedContextLock() { - // Allow usage by thread for which |context_provider_| is bound to. + // Allow a different thread to bind to |context_provider|. context_provider_->DetachFromThread(); } @@ -51,9 +51,7 @@ class ContextProvider : public base::RefCountedThreadSafe { // Bind the 3d context to the current thread. This should be called before // accessing the contexts. Calling it more than once should have no effect. // Once this function has been called, the class should only be accessed - // from the same thread unless the function has some explicitly specified - // rules for access on a different thread. See SetupLockOnMainThread(), which - // can be used to provide access from multiple threads. + // from the same thread. virtual bool BindToCurrentThread() = 0; virtual void DetachFromThread() {} @@ -72,13 +70,11 @@ class ContextProvider : public base::RefCountedThreadSafe { // See skia GrContext::resetContext for details. virtual void InvalidateGrContext(uint32_t state) = 0; - // Sets up a lock so this context can be used from multiple threads. After - // calling this, all functions without explicit thread usage constraints can - // be used on any thread while the lock returned by GetLock() is acquired. + // Sets up a lock so this context can be used from multiple threads. virtual void SetupLock() = 0; // Returns the lock that should be held if using this context from multiple - // threads. This can be called on any thread. + // threads. virtual base::Lock* GetLock() = 0; // Returns the capabilities of the currently bound 3d context. diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc index dd6e54fb955d..056879f49d84 100644 --- a/cc/output/output_surface.cc +++ b/cc/output/output_surface.cc @@ -32,7 +32,6 @@ OutputSurface::OutputSurface( device_scale_factor_(-1), external_stencil_test_enabled_(false), weak_ptr_factory_(this) { - client_thread_checker_.DetachFromThread(); } OutputSurface::OutputSurface( @@ -102,8 +101,12 @@ void OutputSurface::SetExternalDrawConstraints( } OutputSurface::~OutputSurface() { - if (client_) - DetachFromClient(); + if (context_provider_.get()) { + context_provider_->SetLostContextCallback( + ContextProvider::LostContextCallback()); + context_provider_->SetMemoryPolicyChangedCallback( + ContextProvider::MemoryPolicyChangedCallback()); + } } bool OutputSurface::HasExternalStencilTest() const { @@ -111,9 +114,7 @@ bool OutputSurface::HasExternalStencilTest() const { } bool OutputSurface::BindToClient(OutputSurfaceClient* client) { - DCHECK(client_thread_checker_.CalledOnValidThread()); DCHECK(client); - DCHECK(!client_); client_ = client; bool success = true; @@ -127,26 +128,18 @@ bool OutputSurface::BindToClient(OutputSurfaceClient* client) { } } + if (success && worker_context_provider_.get()) { + success = worker_context_provider_->BindToCurrentThread(); + if (success) + worker_context_provider_->SetupLock(); + } + if (!success) client_ = NULL; return success; } -void OutputSurface::DetachFromClient() { - DCHECK(client_thread_checker_.CalledOnValidThread()); - DCHECK(client_); - if (context_provider_.get()) { - context_provider_->SetLostContextCallback( - ContextProvider::LostContextCallback()); - context_provider_->SetMemoryPolicyChangedCallback( - ContextProvider::MemoryPolicyChangedCallback()); - } - context_provider_ = nullptr; - client_ = nullptr; - weak_ptr_factory_.InvalidateWeakPtrs(); -} - void OutputSurface::EnsureBackbuffer() { if (software_device_) software_device_->EnsureBackbuffer(); diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h index 863db2dcf22b..9611ef4406e0 100644 --- a/cc/output/output_surface.h +++ b/cc/output/output_surface.h @@ -11,7 +11,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/threading/thread_checker.h" #include "cc/base/cc_export.h" #include "cc/output/context_provider.h" #include "cc/output/overlay_candidate_validator.h" @@ -113,14 +112,10 @@ class CC_EXPORT OutputSurface { // Called by the compositor on the compositor thread. This is a place where // thread-specific data for the output surface can be initialized, since from - // this point to when DetachFromClient() is called the output surface will - // only be used on the compositor thread. + // this point on the output surface will only be used on the compositor + // thread. virtual bool BindToClient(OutputSurfaceClient* client); - // Called by the compositor on the compositor thread. This is a place where - // thread-specific data for the output surface can be uninitialized. - virtual void DetachFromClient(); - virtual void EnsureBackbuffer(); virtual void DiscardBackbuffer(); @@ -181,7 +176,6 @@ class CC_EXPORT OutputSurface { scoped_ptr software_device_; gfx::Size surface_size_; float device_scale_factor_; - base::ThreadChecker client_thread_checker_; void CommitVSyncParameters(base::TimeTicks timebase, base::TimeDelta interval); diff --git a/cc/raster/tile_task_worker_pool_unittest.cc b/cc/raster/tile_task_worker_pool_unittest.cc index 8ecdb6c6c403..d8e0d19090b5 100644 --- a/cc/raster/tile_task_worker_pool_unittest.cc +++ b/cc/raster/tile_task_worker_pool_unittest.cc @@ -130,10 +130,9 @@ class TileTaskWorkerPoolTest TileTaskWorkerPoolTest() : context_provider_(TestContextProvider::Create()), - worker_context_provider_(TestContextProvider::CreateWorker()), + worker_context_provider_(TestContextProvider::Create()), all_tile_tasks_finished_( - base::ThreadTaskRunnerHandle::Get() - .get(), + base::ThreadTaskRunnerHandle::Get().get(), base::Bind(&TileTaskWorkerPoolTest::AllTileTasksFinished, base::Unretained(this))), timeout_seconds_(5), diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h index d2af2e3d44c7..066f0272cf41 100644 --- a/cc/test/fake_output_surface.h +++ b/cc/test/fake_output_surface.h @@ -23,15 +23,14 @@ class FakeOutputSurface : public OutputSurface { ~FakeOutputSurface() override; static scoped_ptr Create3d() { - return make_scoped_ptr( - new FakeOutputSurface(TestContextProvider::Create(), - TestContextProvider::CreateWorker(), false)); + return make_scoped_ptr(new FakeOutputSurface( + TestContextProvider::Create(), TestContextProvider::Create(), false)); } static scoped_ptr Create3d( scoped_refptr context_provider) { return make_scoped_ptr(new FakeOutputSurface( - context_provider, TestContextProvider::CreateWorker(), false)); + context_provider, TestContextProvider::Create(), false)); } static scoped_ptr Create3d( @@ -45,7 +44,7 @@ class FakeOutputSurface : public OutputSurface { scoped_ptr context) { return make_scoped_ptr( new FakeOutputSurface(TestContextProvider::Create(context.Pass()), - TestContextProvider::CreateWorker(), false)); + TestContextProvider::Create(), false)); } static scoped_ptr CreateSoftware( @@ -55,22 +54,21 @@ class FakeOutputSurface : public OutputSurface { } static scoped_ptr CreateDelegating3d() { - return make_scoped_ptr( - new FakeOutputSurface(TestContextProvider::Create(), - TestContextProvider::CreateWorker(), true)); + return make_scoped_ptr(new FakeOutputSurface( + TestContextProvider::Create(), TestContextProvider::Create(), true)); } static scoped_ptr CreateDelegating3d( scoped_refptr context_provider) { return make_scoped_ptr(new FakeOutputSurface( - context_provider, TestContextProvider::CreateWorker(), true)); + context_provider, TestContextProvider::Create(), true)); } static scoped_ptr CreateDelegating3d( scoped_ptr context) { return make_scoped_ptr( new FakeOutputSurface(TestContextProvider::Create(context.Pass()), - TestContextProvider::CreateWorker(), true)); + TestContextProvider::Create(), true)); } static scoped_ptr CreateDelegatingSoftware( diff --git a/cc/test/fake_proxy.h b/cc/test/fake_proxy.h index 2b3ec4751d20..c809d09036c3 100644 --- a/cc/test/fake_proxy.h +++ b/cc/test/fake_proxy.h @@ -24,7 +24,7 @@ class FakeProxy : public Proxy { void FinishAllRendering() override {} bool IsStarted() const override; bool CommitToActiveTree() const override; - void SetOutputSurface(OutputSurface* output_surface) override {} + void SetOutputSurface(scoped_ptr) override {} void SetLayerTreeHostClientReady() override {} void SetVisible(bool visible) override {} void SetThrottleFrameProduction(bool throttle) override {} diff --git a/cc/test/layer_test_common.cc b/cc/test/layer_test_common.cc index 8ed49a2920cc..7cb97cd51bc4 100644 --- a/cc/test/layer_test_common.cc +++ b/cc/test/layer_test_common.cc @@ -116,13 +116,13 @@ LayerTestCommon::LayerImplTest::LayerImplTest() LayerTestCommon::LayerImplTest::LayerImplTest(const LayerTreeSettings& settings) : client_(FakeLayerTreeHostClient::DIRECT_3D), - output_surface_(FakeOutputSurface::Create3d()), host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_, settings)), root_layer_impl_(LayerImpl::Create(host_->host_impl()->active_tree(), 1)), render_pass_(RenderPass::Create()), layer_impl_id_(2) { root_layer_impl_->SetHasRenderSurface(true); - host_->host_impl()->InitializeRenderer(output_surface_.get()); + scoped_ptr output_surface = FakeOutputSurface::Create3d(); + host_->host_impl()->InitializeRenderer(FakeOutputSurface::Create3d()); } LayerTestCommon::LayerImplTest::~LayerImplTest() {} diff --git a/cc/test/layer_test_common.h b/cc/test/layer_test_common.h index f801461297c1..a915b597d0c3 100644 --- a/cc/test/layer_test_common.h +++ b/cc/test/layer_test_common.h @@ -139,7 +139,6 @@ class LayerTestCommon { private: FakeLayerTreeHostClient client_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; scoped_ptr host_; scoped_ptr root_layer_impl_; scoped_ptr render_pass_; diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc index e2d19b0f43e0..c87c36b780ba 100644 --- a/cc/test/layer_tree_test.cc +++ b/cc/test/layer_tree_test.cc @@ -404,8 +404,8 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl { test_hooks_->DidActivateTreeOnThread(this); } - bool InitializeRenderer(OutputSurface* output_surface) override { - bool success = LayerTreeHostImpl::InitializeRenderer(output_surface); + bool InitializeRenderer(scoped_ptr output_surface) override { + bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass()); test_hooks_->InitializedRendererOnThread(this, success); return success; } diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc index 5e43ee3fcc58..ca7714d30cf9 100644 --- a/cc/test/test_context_provider.cc +++ b/cc/test/test_context_provider.cc @@ -19,20 +19,7 @@ namespace cc { // static scoped_refptr TestContextProvider::Create() { - return Create(TestWebGraphicsContext3D::Create()); -} - -// static -scoped_refptr TestContextProvider::CreateWorker() { - scoped_refptr worker_context_provider = - Create(TestWebGraphicsContext3D::Create()); - if (!worker_context_provider) - return nullptr; - // Worker contexts are bound to the thread they are created on. - if (!worker_context_provider->BindToCurrentThread()) - return nullptr; - worker_context_provider->SetupLock(); - return worker_context_provider; + return Create(TestWebGraphicsContext3D::Create().Pass()); } // static diff --git a/cc/test/test_context_provider.h b/cc/test/test_context_provider.h index 3ff9092faece..82b3e612d681 100644 --- a/cc/test/test_context_provider.h +++ b/cc/test/test_context_provider.h @@ -25,9 +25,6 @@ class TestContextProvider : public ContextProvider { CreateCallback; static scoped_refptr Create(); - // Creates a worker context provider that can be used on any thread. This is - // equivalent to: Create(); BindToCurrentThread(); SetupLock(). - static scoped_refptr CreateWorker(); static scoped_refptr Create( scoped_ptr context); diff --git a/cc/tiles/tile_manager_perftest.cc b/cc/tiles/tile_manager_perftest.cc index 0ba9c8ee6341..1542233bc1c8 100644 --- a/cc/tiles/tile_manager_perftest.cc +++ b/cc/tiles/tile_manager_perftest.cc @@ -89,7 +89,6 @@ class TileManagerPerfTest : public testing::Test { max_tiles_(10000), id_(7), proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(LayerTreeSettings(), &proxy_, &shared_bitmap_manager_, @@ -120,7 +119,7 @@ class TileManagerPerfTest : public testing::Test { } virtual void InitializeRenderer() { - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::Create3d().Pass()); tile_manager()->SetTileTaskRunnerForTesting( g_fake_tile_task_runner.Pointer()); } @@ -413,7 +412,6 @@ class TileManagerPerfTest : public testing::Test { int max_tiles_; int id_; FakeImplProxy proxy_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerImpl* pending_root_layer_; FakePictureLayerImpl* active_root_layer_; diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc index 44bc75637aee..e1fd51e9fc5d 100644 --- a/cc/tiles/tile_manager_unittest.cc +++ b/cc/tiles/tile_manager_unittest.cc @@ -46,7 +46,6 @@ class TileManagerTilePriorityQueueTest : public testing::Test { ready_to_activate_(false), id_(7), proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_, @@ -75,7 +74,7 @@ class TileManagerTilePriorityQueueTest : public testing::Test { } virtual void InitializeRenderer() { - host_impl_.InitializeRenderer(output_surface_.get()); + host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); } void SetupDefaultTrees(const gfx::Size& layer_bounds) { @@ -157,7 +156,6 @@ class TileManagerTilePriorityQueueTest : public testing::Test { bool ready_to_activate_; int id_; FakeImplProxy proxy_; - scoped_ptr output_surface_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerImpl* pending_layer_; FakePictureLayerImpl* active_layer_; @@ -1425,11 +1423,7 @@ TEST_F(TileManagerTilePriorityQueueTest, RasterQueueAllUsesCorrectTileBounds) { class TileManagerTest : public testing::Test { public: TileManagerTest() - : output_surface_(FakeOutputSurface::CreateSoftware( - make_scoped_ptr(new SoftwareOutputDevice))), - host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_) { - host_impl_.InitializeRenderer(output_surface_.get()); - } + : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_) {} protected: // MockLayerTreeHostImpl allows us to intercept tile manager callbacks. @@ -1438,7 +1432,10 @@ class TileManagerTest : public testing::Test { MockLayerTreeHostImpl(Proxy* proxy, SharedBitmapManager* manager, TaskGraphRunner* task_graph_runner) - : FakeLayerTreeHostImpl(proxy, manager, task_graph_runner) {} + : FakeLayerTreeHostImpl(proxy, manager, task_graph_runner) { + InitializeRenderer(FakeOutputSurface::CreateSoftware( + make_scoped_ptr(new SoftwareOutputDevice))); + } MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); }; @@ -1446,7 +1443,6 @@ class TileManagerTest : public testing::Test { TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeImplProxy proxy_; - scoped_ptr output_surface_; MockLayerTreeHostImpl host_impl_; }; diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index 860c2159d098..2572cd6df23f 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -388,9 +388,7 @@ void LayerTreeHost::SetOutputSurface(scoped_ptr surface) { DCHECK(output_surface_lost_); DCHECK(surface); - DCHECK(!new_output_surface_); - new_output_surface_ = surface.Pass(); - proxy_->SetOutputSurface(new_output_surface_.get()); + proxy_->SetOutputSurface(surface.Pass()); } void LayerTreeHost::RequestNewOutputSurface() { @@ -398,20 +396,12 @@ void LayerTreeHost::RequestNewOutputSurface() { } void LayerTreeHost::DidInitializeOutputSurface() { - DCHECK(new_output_surface_); output_surface_lost_ = false; - current_output_surface_ = new_output_surface_.Pass(); client_->DidInitializeOutputSurface(); } void LayerTreeHost::DidFailToInitializeOutputSurface() { DCHECK(output_surface_lost_); - DCHECK(new_output_surface_); - // Note: It is safe to drop all output surface references here as - // LayerTreeHostImpl will not keep a pointer to either the old or - // new output surface after failing to initialize the new one. - current_output_surface_ = nullptr; - new_output_surface_ = nullptr; client_->DidFailToInitializeOutputSurface(); } diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index 29990f930c37..e17431d89c00 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -434,13 +434,6 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { int meta_information_sequence_number_; scoped_ptr rendering_stats_instrumentation_; - // |current_output_surface_| can't be updated until we've successfully - // initialized a new output surface. |new_output_surface_| contains the - // new output surface that is currently being initialized. If initialization - // is successful then |new_output_surface_| replaces - // |current_output_surface_|. - scoped_ptr new_output_surface_; - scoped_ptr current_output_surface_; bool output_surface_lost_; scoped_refptr root_layer_; diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc index d8beb5f663e4..bc6bae0190a0 100644 --- a/cc/trees/layer_tree_host_common_unittest.cc +++ b/cc/trees/layer_tree_host_common_unittest.cc @@ -2670,7 +2670,6 @@ TEST_F(LayerTreeHostCommonTest, FakeImplProxy proxy; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, &task_graph_runner); scoped_ptr root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -2710,7 +2709,7 @@ TEST_F(LayerTreeHostCommonTest, root->AddChild(child.Pass()); root->AddChild(occluding_child.Pass()); host_impl.active_tree()->SetRootLayer(root.Pass()); - host_impl.InitializeRenderer(output_surface.get()); + host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); bool update_lcd_text = false; host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 1212691b3d3b..c69d8ea02e26 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -172,7 +172,6 @@ LayerTreeHostImpl::LayerTreeHostImpl( : client_(client), proxy_(proxy), current_begin_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), - output_surface_(nullptr), content_is_suitable_for_gpu_rasterization_(true), has_gpu_rasterization_trigger_(false), use_gpu_rasterization_(false), @@ -286,13 +285,6 @@ LayerTreeHostImpl::~LayerTreeHostImpl() { } CleanUpTileManager(); - renderer_ = nullptr; - resource_provider_ = nullptr; - - if (output_surface_) { - output_surface_->DetachFromClient(); - output_surface_ = nullptr; - } } void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { @@ -1570,7 +1562,7 @@ void LayerTreeHostImpl::DrawLayers(FrameData* frame) { scoped_ptr temp_software_renderer = SoftwareRenderer::Create(this, &settings_.renderer_settings, - output_surface_, NULL); + output_surface_.get(), NULL); temp_software_renderer->DrawFrame(&frame->render_passes, device_scale_factor_, DeviceViewport(), @@ -1632,7 +1624,7 @@ bool LayerTreeHostImpl::CanUseGpuRasterization() { ContextProvider* context_provider = output_surface_->worker_context_provider(); - ContextProvider::ScopedContextLock scoped_context(context_provider); + base::AutoLock context_lock(*context_provider->GetLock()); if (!context_provider->GrContext()) return false; @@ -2016,18 +2008,18 @@ void LayerTreeHostImpl::CreateAndSetRenderer() { DCHECK(resource_provider_); if (output_surface_->capabilities().delegated_rendering) { - renderer_ = - DelegatingRenderer::Create(this, &settings_.renderer_settings, - output_surface_, resource_provider_.get()); + renderer_ = DelegatingRenderer::Create(this, &settings_.renderer_settings, + output_surface_.get(), + resource_provider_.get()); } else if (output_surface_->context_provider()) { renderer_ = GLRenderer::Create( - this, &settings_.renderer_settings, output_surface_, + this, &settings_.renderer_settings, output_surface_.get(), resource_provider_.get(), texture_mailbox_deleter_.get(), settings_.renderer_settings.highp_threshold_min); } else if (output_surface_->software_device()) { - renderer_ = - SoftwareRenderer::Create(this, &settings_.renderer_settings, - output_surface_, resource_provider_.get()); + renderer_ = SoftwareRenderer::Create(this, &settings_.renderer_settings, + output_surface_.get(), + resource_provider_.get()); } DCHECK(renderer_); @@ -2156,7 +2148,8 @@ void LayerTreeHostImpl::CleanUpTileManager() { single_thread_synchronous_task_graph_runner_ = nullptr; } -bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { +bool LayerTreeHostImpl::InitializeRenderer( + scoped_ptr output_surface) { TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); // Since we will create a new resource provider, we cannot continue to use @@ -2168,14 +2161,7 @@ bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { renderer_ = nullptr; CleanUpTileManager(); resource_provider_ = nullptr; - - // Detach from the old output surface and reset |output_surface_| pointer - // as this surface is going to be destroyed independent of if binding the - // new output surface succeeds or not. - if (output_surface_) { - output_surface_->DetachFromClient(); - output_surface_ = nullptr; - } + output_surface_ = nullptr; if (!output_surface->BindToClient(this)) { // Avoid recreating tree resources because we might not have enough @@ -2184,9 +2170,9 @@ bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { return false; } - output_surface_ = output_surface; + output_surface_ = output_surface.Pass(); resource_provider_ = ResourceProvider::Create( - output_surface_, shared_bitmap_manager_, gpu_memory_buffer_manager_, + output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, proxy_->blocking_main_thread_task_runner(), settings_.renderer_settings.highp_threshold_min, settings_.renderer_settings.use_rgba_4444_textures, diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index f7fad1517c51..1fbd92d9123a 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -362,14 +362,14 @@ class CC_EXPORT LayerTreeHostImpl // Implementation. int id() const { return id_; } bool CanDraw() const; - OutputSurface* output_surface() const { return output_surface_; } + OutputSurface* output_surface() const { return output_surface_.get(); } std::string LayerTreeAsJson() const; void FinishAllRendering(); int RequestedMSAASampleCount() const; - virtual bool InitializeRenderer(OutputSurface* output_surface); + virtual bool InitializeRenderer(scoped_ptr output_surface); TileManager* tile_manager() { return tile_manager_.get(); } void SetHasGpuRasterizationTrigger(bool flag) { @@ -696,7 +696,7 @@ class CC_EXPORT LayerTreeHostImpl // request queue. std::set evicted_ui_resources_; - OutputSurface* output_surface_; + scoped_ptr output_surface_; scoped_ptr resource_provider_; bool content_is_suitable_for_gpu_rasterization_; diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index a963c2f56553..458af3480e32 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -168,8 +168,7 @@ class LayerTreeHostImplTest : public testing::Test, settings, this, &proxy_, &stats_instrumentation_, &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, 0); - output_surface_ = output_surface.Pass(); - bool init = host_impl_->InitializeRenderer(output_surface_.get()); + bool init = host_impl_->InitializeRenderer(output_surface.Pass()); host_impl_->SetViewportSize(gfx::Size(10, 10)); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); // Set the BeginFrameArgs so that methods which use it are able to. @@ -421,7 +420,6 @@ class LayerTreeHostImplTest : public testing::Test, TestSharedBitmapManager shared_bitmap_manager_; TestGpuMemoryBufferManager gpu_memory_buffer_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; scoped_ptr host_impl_; FakeRenderingStatsInstrumentation stats_instrumentation_; bool on_can_draw_state_changed_called_; @@ -2119,8 +2117,7 @@ class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { settings, this, &proxy_, &shared_bitmap_manager_, &task_graph_runner_, &stats_instrumentation_); host_impl_ = make_scoped_ptr(host_impl_override_time); - output_surface_ = CreateOutputSurface(); - host_impl_->InitializeRenderer(output_surface_.get()); + host_impl_->InitializeRenderer(CreateOutputSurface()); SetupScrollAndContentsLayers(content_size); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); @@ -5605,7 +5602,7 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { LayerTreeHostImpl::Create( settings, this, &proxy_, &stats_instrumentation_, &shared_bitmap_manager_, NULL, &task_graph_runner_, 0); - layer_tree_host_impl->InitializeRenderer(output_surface.get()); + layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); layer_tree_host_impl->WillBeginImplFrame( CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); @@ -5882,14 +5879,19 @@ static scoped_ptr SetupLayersForOpacity( Proxy* proxy, SharedBitmapManager* manager, TaskGraphRunner* task_graph_runner, - RenderingStatsInstrumentation* stats_instrumentation, - OutputSurface* output_surface) { + RenderingStatsInstrumentation* stats_instrumentation) { + scoped_refptr provider(TestContextProvider::Create()); + scoped_ptr output_surface( + FakeOutputSurface::Create3d(provider)); + provider->BindToCurrentThread(); + provider->TestContext3d()->set_have_post_sub_buffer(true); + LayerTreeSettings settings; settings.renderer_settings.partial_swap_enabled = partial_swap; scoped_ptr my_host_impl = LayerTreeHostImpl::Create(settings, client, proxy, stats_instrumentation, manager, nullptr, task_graph_runner, 0); - my_host_impl->InitializeRenderer(output_surface); + my_host_impl->InitializeRenderer(output_surface.Pass()); my_host_impl->WillBeginImplFrame( CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); my_host_impl->SetViewportSize(gfx::Size(100, 100)); @@ -5952,14 +5954,9 @@ static scoped_ptr SetupLayersForOpacity( TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_refptr provider(TestContextProvider::Create()); - provider->BindToCurrentThread(); - provider->TestContext3d()->set_have_post_sub_buffer(true); - scoped_ptr output_surface( - FakeOutputSurface::Create3d(provider)); - scoped_ptr my_host_impl = SetupLayersForOpacity( - true, this, &proxy_, &shared_bitmap_manager, &task_graph_runner, - &stats_instrumentation_, output_surface.get()); + scoped_ptr my_host_impl = + SetupLayersForOpacity(true, this, &proxy_, &shared_bitmap_manager, + &task_graph_runner, &stats_instrumentation_); { LayerTreeHostImpl::FrameData frame; EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); @@ -5981,14 +5978,9 @@ TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - scoped_refptr provider(TestContextProvider::Create()); - provider->BindToCurrentThread(); - provider->TestContext3d()->set_have_post_sub_buffer(true); - scoped_ptr output_surface( - FakeOutputSurface::Create3d(provider)); - scoped_ptr my_host_impl = SetupLayersForOpacity( - false, this, &proxy_, &shared_bitmap_manager, &task_graph_runner, - &stats_instrumentation_, output_surface.get()); + scoped_ptr my_host_impl = + SetupLayersForOpacity(false, this, &proxy_, &shared_bitmap_manager, + &task_graph_runner, &stats_instrumentation_); { LayerTreeHostImpl::FrameData frame; EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); @@ -6407,9 +6399,9 @@ TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { settings, this, &proxy_, &stats_instrumentation_, &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, 0); - output_surface_ = - FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create()); - host_impl_->InitializeRenderer(output_surface_.get()); + scoped_ptr output_surface( + FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); + host_impl_->InitializeRenderer(output_surface.Pass()); EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); } @@ -6470,8 +6462,7 @@ class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { new FakeLayerTreeHostImpl(LayerTreeSettings(), &proxy_, &shared_bitmap_manager_, &task_graph_runner_); host_impl_.reset(fake_host_impl_); - output_surface_ = CreateOutputSurface(); - host_impl_->InitializeRenderer(output_surface_.get()); + host_impl_->InitializeRenderer(CreateOutputSurface()); host_impl_->SetViewportSize(gfx::Size(10, 10)); } @@ -8467,8 +8458,7 @@ class MockReclaimResourcesOutputSurface : public FakeOutputSurface { public: static scoped_ptr Create3d() { return make_scoped_ptr(new MockReclaimResourcesOutputSurface( - TestContextProvider::Create(), TestContextProvider::CreateWorker(), - false)); + TestContextProvider::Create(), TestContextProvider::Create(), false)); } MOCK_METHOD0(ForceReclaimResources, void()); diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 7acc6ffea7d3..d084c43abfc9 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -465,7 +465,7 @@ class LayerTreeHostFreeWorkerContextResourcesTest : public LayerTreeHostTest { explicit MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface( bool delegated_rendering) : FakeOutputSurface(TestContextProvider::Create(), - TestContextProvider::CreateWorker(), + TestContextProvider::Create(), delegated_rendering) {} MOCK_METHOD1(SetWorkerContextShouldAggressivelyFreeResources, void(bool is_visible)); @@ -6190,21 +6190,5 @@ class LayerTreeHostScrollingAndScalingUpdatesLayers : public LayerTreeHostTest { MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers); -class LayerTreeHostTestDestroyWhileInitializingOutputSurface - : public LayerTreeHostTest { - protected: - void BeginTest() override { - // By ending the test immediately we start initialization of an output - // surface but destroy the LTH before it completes. This test verifies - // that this works correctly and the output surface is destroyed on - // the correct thread. - EndTest(); - } - - void AfterTest() override {} -}; - -MULTI_THREAD_TEST_F(LayerTreeHostTestDestroyWhileInitializingOutputSurface); - } // namespace } // namespace cc diff --git a/cc/trees/layer_tree_impl_unittest.cc b/cc/trees/layer_tree_impl_unittest.cc index 05f873a45694..ce05e1beb559 100644 --- a/cc/trees/layer_tree_impl_unittest.cc +++ b/cc/trees/layer_tree_impl_unittest.cc @@ -22,12 +22,12 @@ namespace { class LayerTreeImplTest : public LayerTreeHostCommonTest { public: - LayerTreeImplTest() : output_surface_(FakeOutputSurface::Create3d()) { + LayerTreeImplTest() { LayerTreeSettings settings; settings.layer_transforms_should_scale_layer_contents = true; host_impl_.reset(new FakeLayerTreeHostImpl( settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_)); - EXPECT_TRUE(host_impl_->InitializeRenderer(output_surface_.get())); + EXPECT_TRUE(host_impl_->InitializeRenderer(FakeOutputSurface::Create3d())); } FakeLayerTreeHostImpl& host_impl() { return *host_impl_; } @@ -42,7 +42,6 @@ class LayerTreeImplTest : public LayerTreeHostCommonTest { TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeImplProxy proxy_; - scoped_ptr output_surface_; scoped_ptr host_impl_; }; @@ -98,11 +97,10 @@ TEST_F(LayerTreeImplTest, UpdateViewportAndHitTest) { FakeImplProxy proxy; LayerTreeSettings settings; settings.verify_property_trees = true; - scoped_ptr output_surface = FakeOutputSurface::Create3d(); scoped_ptr host_impl; host_impl.reset(new FakeLayerTreeHostImpl( settings, &proxy, &shared_bitmap_manager, &task_graph_runner)); - EXPECT_TRUE(host_impl->InitializeRenderer(output_surface.get())); + EXPECT_TRUE(host_impl->InitializeRenderer(FakeOutputSurface::Create3d())); scoped_ptr root = LayerImpl::Create(host_impl->active_tree(), 12345); diff --git a/cc/trees/occlusion_tracker_perftest.cc b/cc/trees/occlusion_tracker_perftest.cc index 01b63de6279a..209399dce111 100644 --- a/cc/trees/occlusion_tracker_perftest.cc +++ b/cc/trees/occlusion_tracker_perftest.cc @@ -35,14 +35,13 @@ class OcclusionTrackerPerfTest : public testing::Test { base::TimeDelta::FromMilliseconds(kTimeLimitMillis), kTimeCheckInterval), proxy_(base::ThreadTaskRunnerHandle::Get(), nullptr), - impl_(&proxy_), - output_surface_(FakeOutputSurface::Create3d()) {} + impl_(&proxy_) {} void CreateHost() { LayerTreeSettings settings; host_impl_ = LayerTreeHostImpl::Create(settings, &client_, &proxy_, &stats_, &shared_bitmap_manager_, nullptr, &task_graph_runner_, 1); - host_impl_->InitializeRenderer(output_surface_.get()); + host_impl_->InitializeRenderer(FakeOutputSurface::Create3d()); scoped_ptr root_layer = LayerImpl::Create(active_tree(), 1); root_layer->SetHasRenderSurface(true); @@ -72,7 +71,6 @@ class OcclusionTrackerPerfTest : public testing::Test { FakeRenderingStatsInstrumentation stats_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - scoped_ptr output_surface_; scoped_ptr host_impl_; }; diff --git a/cc/trees/proxy.h b/cc/trees/proxy.h index 013d70928ff4..57efe3f4c1c6 100644 --- a/cc/trees/proxy.h +++ b/cc/trees/proxy.h @@ -60,7 +60,7 @@ class CC_EXPORT Proxy { // Will call LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted // with the result of this function. - virtual void SetOutputSurface(OutputSurface* output_surface) = 0; + virtual void SetOutputSurface(scoped_ptr output_surface) = 0; // Indicates that the compositing surface associated with our context is // ready to use. diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc index 11012151f1ca..72a718c2958a 100644 --- a/cc/trees/single_thread_proxy.cc +++ b/cc/trees/single_thread_proxy.cc @@ -149,7 +149,8 @@ void SingleThreadProxy::RequestNewOutputSurface() { layer_tree_host_->RequestNewOutputSurface(); } -void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) { +void SingleThreadProxy::SetOutputSurface( + scoped_ptr output_surface) { DCHECK(Proxy::IsMainThread()); DCHECK(layer_tree_host_->output_surface_lost()); DCHECK(output_surface_creation_requested_); @@ -159,7 +160,7 @@ void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) { { DebugScopedSetMainThreadBlocked main_thread_blocked(this); DebugScopedSetImplThread impl(this); - success = layer_tree_host_impl_->InitializeRenderer(output_surface); + success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); } if (success) { diff --git a/cc/trees/single_thread_proxy.h b/cc/trees/single_thread_proxy.h index 95d9d6fbdae3..913d1ce64565 100644 --- a/cc/trees/single_thread_proxy.h +++ b/cc/trees/single_thread_proxy.h @@ -38,7 +38,7 @@ class CC_EXPORT SingleThreadProxy : public Proxy, void FinishAllRendering() override; bool IsStarted() const override; bool CommitToActiveTree() const override; - void SetOutputSurface(OutputSurface* output_surface) override; + void SetOutputSurface(scoped_ptr) override; void SetLayerTreeHostClientReady() override; void SetVisible(bool visible) override; void SetThrottleFrameProduction(bool throttle) override; diff --git a/cc/trees/thread_proxy.cc b/cc/trees/thread_proxy.cc index 77aea560fa2a..ef49ff85d4d4 100644 --- a/cc/trees/thread_proxy.cc +++ b/cc/trees/thread_proxy.cc @@ -210,10 +210,11 @@ void ThreadProxy::RequestNewOutputSurface() { layer_tree_host()->RequestNewOutputSurface(); } -void ThreadProxy::SetOutputSurface(OutputSurface* output_surface) { +void ThreadProxy::SetOutputSurface(scoped_ptr output_surface) { Proxy::ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, - impl_thread_weak_ptr_, output_surface)); + FROM_HERE, + base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, + impl_thread_weak_ptr_, base::Passed(&output_surface))); } void ThreadProxy::DidInitializeOutputSurface( @@ -1043,12 +1044,12 @@ void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { } void ThreadProxy::InitializeOutputSurfaceOnImplThread( - OutputSurface* output_surface) { + scoped_ptr output_surface) { TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); DCHECK(IsImplThread()); LayerTreeHostImpl* host_impl = impl().layer_tree_host_impl.get(); - bool success = host_impl->InitializeRenderer(output_surface); + bool success = host_impl->InitializeRenderer(output_surface.Pass()); RendererCapabilities capabilities; if (success) { capabilities = diff --git a/cc/trees/thread_proxy.h b/cc/trees/thread_proxy.h index 6fff58230004..35db6fc3a7a6 100644 --- a/cc/trees/thread_proxy.h +++ b/cc/trees/thread_proxy.h @@ -155,7 +155,7 @@ class CC_EXPORT ThreadProxy : public Proxy, void FinishAllRendering() override; bool IsStarted() const override; bool CommitToActiveTree() const override; - void SetOutputSurface(OutputSurface* output_surface) override; + void SetOutputSurface(scoped_ptr) override; void SetLayerTreeHostClientReady() override; void SetVisible(bool visible) override; void SetThrottleFrameProduction(bool throttle) override; @@ -272,7 +272,8 @@ class CC_EXPORT ThreadProxy : public Proxy, CompletionEvent* completion, bool* has_initialized_output_surface); void DeleteContentsTexturesOnImplThread(CompletionEvent* completion); - void InitializeOutputSurfaceOnImplThread(OutputSurface* output_surface); + void InitializeOutputSurfaceOnImplThread( + scoped_ptr output_surface); void FinishGLOnImplThread(CompletionEvent* completion); void LayerTreeHostClosedOnImplThread(CompletionEvent* completion); DrawResult DrawSwapInternal(bool forced_draw); diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc index 9888c2d0a38f..b90edd69a2f2 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc @@ -24,7 +24,6 @@ #include "content/renderer/render_thread_impl.h" #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "gpu/command_buffer/client/gl_in_process_context.h" -#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "ui/gl/android/surface_texture.h" #include "ui/gl/gl_surface.h" @@ -170,40 +169,11 @@ SynchronousCompositorFactoryImpl::CreateOutputSurface( scoped_refptr frame_swap_message_queue) { scoped_refptr onscreen_context = CreateContextProviderForCompositor(surface_id, RENDER_COMPOSITOR_CONTEXT); - - bool shared_worker_context_lost = false; - if (shared_worker_context_) { - // Note: If context is lost, we delete reference after releasing the lock. - base::AutoLock lock(*shared_worker_context_->GetLock()); - if (shared_worker_context_->ContextGL()->GetGraphicsResetStatusKHR() != - GL_NO_ERROR) { - shared_worker_context_lost = true; - } - } - // Note: shared worker context support requires |use_ipc_command_buffer_|. - if (use_ipc_command_buffer_ && - (!shared_worker_context_ || shared_worker_context_lost)) { - // TODO(reveman): This limit is based on the usage required by async - // uploads. Determine what a good limit is now that async uploads are - // no longer used. - unsigned int mapped_memory_reclaim_limit = - (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; - WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; - mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; - scoped_ptr context = - CreateContext3D(0, GetDefaultAttribs(), mem_limits); - shared_worker_context_ = - make_scoped_refptr(new SynchronousCompositorContextProvider( - context.Pass(), RENDER_WORKER_CONTEXT)); - if (!shared_worker_context_->BindToCurrentThread()) - shared_worker_context_ = nullptr; - if (shared_worker_context_) - shared_worker_context_->SetupLock(); - } + scoped_refptr worker_context = + CreateContextProviderForCompositor(0, RENDER_WORKER_CONTEXT); return make_scoped_ptr(new SynchronousCompositorOutputSurface( - onscreen_context, shared_worker_context_, routing_id, - frame_swap_message_queue)); + onscreen_context, worker_context, routing_id, frame_swap_message_queue)); } InputHandlerManagerClient* @@ -241,9 +211,6 @@ SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor( // This is half of what RenderWidget uses because synchronous compositor // pipeline is only one frame deep. But twice of half for low end here // because 16bit texture is not supported. - // TODO(reveman): This limit is based on the usage required by async - // uploads. Determine what a good limit is now that async uploads are - // no longer used. unsigned int mapped_memory_reclaim_limit = (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.h b/content/browser/android/in_process/synchronous_compositor_factory_impl.h index 342b2a9441f4..84ceb030b327 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.h @@ -28,7 +28,6 @@ class WebGraphicsContext3DInProcessCommandBufferImpl; namespace content { class InProcessChildThreadParams; -class SynchronousCompositorContextProvider; class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { public: @@ -89,8 +88,6 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { class VideoContextProvider; scoped_refptr video_context_provider_; - scoped_refptr shared_worker_context_; - bool use_ipc_command_buffer_; // |num_hardware_compositor_lock_| is updated on UI thread only but can be diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.cc b/content/browser/android/in_process/synchronous_compositor_output_surface.cc index f03f992d83d4..85c7bcb3c398 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.cc +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.cc @@ -83,6 +83,11 @@ SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( } SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { + DCHECK(CalledOnValidThread()); + if (registered_) { + SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( + routing_id_, this); + } } bool SynchronousCompositorOutputSurface::BindToClient( @@ -100,15 +105,6 @@ bool SynchronousCompositorOutputSurface::BindToClient( return true; } -void SynchronousCompositorOutputSurface::DetachFromClient() { - DCHECK(CalledOnValidThread()); - if (registered_) { - SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( - routing_id_, this); - } - cc::OutputSurface::DetachFromClient(); -} - void SynchronousCompositorOutputSurface::SetCompositor( SynchronousCompositorImpl* compositor) { DCHECK(CalledOnValidThread()); diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.h b/content/browser/android/in_process/synchronous_compositor_output_surface.h index b1baa643d987..414695230c10 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.h +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.h @@ -58,7 +58,6 @@ class SynchronousCompositorOutputSurface // OutputSurface. bool BindToClient(cc::OutputSurfaceClient* surface_client) override; - void DetachFromClient() override; void Reshape(const gfx::Size& size, float scale_factor) override; void SwapBuffers(cc::CompositorFrame* frame) override; void Invalidate() override; diff --git a/content/browser/compositor/gpu_process_transport_factory.cc b/content/browser/compositor/gpu_process_transport_factory.cc index 1af8acddf2f5..a5b14336ab76 100644 --- a/content/browser/compositor/gpu_process_transport_factory.cc +++ b/content/browser/compositor/gpu_process_transport_factory.cc @@ -244,14 +244,11 @@ void GpuProcessTransportFactory::EstablishedGpuChannel( scoped_refptr context_provider; if (create_gpu_output_surface) { // Try to reuse existing worker context provider. - bool shared_worker_context_provider_lost = false; if (shared_worker_context_provider_) { - // Note: If context is lost, we delete reference after releasing the lock. base::AutoLock lock(*shared_worker_context_provider_->GetLock()); if (shared_worker_context_provider_->ContextGL() - ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { - shared_worker_context_provider_lost = true; - } + ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) + shared_worker_context_provider_ = nullptr; } scoped_refptr gpu_channel_host = BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); @@ -262,8 +259,7 @@ void GpuProcessTransportFactory::EstablishedGpuChannel( BROWSER_COMPOSITOR_ONSCREEN_CONTEXT); if (context_provider && !context_provider->BindToCurrentThread()) context_provider = nullptr; - if (!shared_worker_context_provider_ || - shared_worker_context_provider_lost) { + if (!shared_worker_context_provider_) { shared_worker_context_provider_ = ContextProviderCommandBuffer::Create( GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host, 0), @@ -271,8 +267,6 @@ void GpuProcessTransportFactory::EstablishedGpuChannel( if (shared_worker_context_provider_ && !shared_worker_context_provider_->BindToCurrentThread()) shared_worker_context_provider_ = nullptr; - if (shared_worker_context_provider_) - shared_worker_context_provider_->SetupLock(); } } diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc index 8c5291d880bc..bfb1f3a21bf3 100644 --- a/content/child/child_thread_impl.cc +++ b/content/child/child_thread_impl.cc @@ -590,7 +590,7 @@ scoped_ptr ChildThreadImpl::AllocateSharedMemory( shared_buf.reset(new base::SharedMemory); if (!shared_buf->CreateAnonymous(buf_size)) { NOTREACHED(); - return nullptr; + return NULL; } #else // On POSIX, we need to ask the browser to create the shared memory for us, @@ -602,14 +602,11 @@ scoped_ptr ChildThreadImpl::AllocateSharedMemory( shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); } else { NOTREACHED() << "Browser failed to allocate shared memory"; - return nullptr; + return NULL; } - } else if (ChildProcess::current()->GetShutDownEvent()->IsSignaled()) { - // Send is allowed to fail during shutdown. Return null in this case. - return nullptr; } else { NOTREACHED() << "Browser allocation request message failed"; - return nullptr; + return NULL; } #endif return shared_buf; diff --git a/content/renderer/gpu/compositor_output_surface.cc b/content/renderer/gpu/compositor_output_surface.cc index 3f96ef3745a0..c3298d03d5fa 100644 --- a/content/renderer/gpu/compositor_output_surface.cc +++ b/content/renderer/gpu/compositor_output_surface.cc @@ -50,15 +50,28 @@ CompositorOutputSurface::CompositorOutputSurface( weak_ptrs_(this) { DCHECK(output_surface_filter_.get()); DCHECK(frame_swap_message_queue_.get()); + DetachFromThread(); capabilities_.max_frames_pending = 1; message_sender_ = RenderThreadImpl::current()->sync_message_filter(); DCHECK(message_sender_.get()); } -CompositorOutputSurface::~CompositorOutputSurface() {} +CompositorOutputSurface::~CompositorOutputSurface() { + DCHECK(CalledOnValidThread()); + if (!HasClient()) + return; + UpdateSmoothnessTakesPriority(false); + if (output_surface_proxy_.get()) + output_surface_proxy_->ClearOutputSurface(); + output_surface_filter_->RemoveHandlerOnCompositorThread( + routing_id_, + output_surface_filter_handler_); +} bool CompositorOutputSurface::BindToClient( cc::OutputSurfaceClient* client) { + DCHECK(CalledOnValidThread()); + if (!cc::OutputSurface::BindToClient(client)) return false; @@ -81,17 +94,6 @@ bool CompositorOutputSurface::BindToClient( return true; } -void CompositorOutputSurface::DetachFromClient() { - if (!HasClient()) - return; - UpdateSmoothnessTakesPriority(false); - if (output_surface_proxy_.get()) - output_surface_proxy_->ClearOutputSurface(); - output_surface_filter_->RemoveHandlerOnCompositorThread( - routing_id_, output_surface_filter_handler_); - cc::OutputSurface::DetachFromClient(); -} - void CompositorOutputSurface::ShortcutSwapAck( uint32 output_surface_id, scoped_ptr gl_frame_data) { @@ -154,7 +156,7 @@ void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { } void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { - DCHECK(client_thread_checker_.CalledOnValidThread()); + DCHECK(CalledOnValidThread()); if (!HasClient()) return; IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) @@ -168,7 +170,7 @@ void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( base::TimeTicks timebase, base::TimeDelta interval) { - DCHECK(client_thread_checker_.CalledOnValidThread()); + DCHECK(CalledOnValidThread()); CommitVSyncParameters(timebase, interval); } diff --git a/content/renderer/gpu/compositor_output_surface.h b/content/renderer/gpu/compositor_output_surface.h index 909bf5fb48d8..fa91b7550de8 100644 --- a/content/renderer/gpu/compositor_output_surface.h +++ b/content/renderer/gpu/compositor_output_surface.h @@ -51,7 +51,6 @@ class CompositorOutputSurface // cc::OutputSurface implementation. bool BindToClient(cc::OutputSurfaceClient* client) override; - void DetachFromClient() override; void SwapBuffers(cc::CompositorFrame* frame) override; // TODO(epenner): This seems out of place here and would be a better fit diff --git a/content/renderer/gpu/mailbox_output_surface.cc b/content/renderer/gpu/mailbox_output_surface.cc index 5747a6861f9a..4a598d4c6064 100644 --- a/content/renderer/gpu/mailbox_output_surface.cc +++ b/content/renderer/gpu/mailbox_output_surface.cc @@ -45,9 +45,6 @@ MailboxOutputSurface::MailboxOutputSurface( } MailboxOutputSurface::~MailboxOutputSurface() { -} - -void MailboxOutputSurface::DetachFromClient() { DiscardBackbuffer(); while (!pending_textures_.empty()) { if (pending_textures_.front().texture_id) { @@ -56,7 +53,6 @@ void MailboxOutputSurface::DetachFromClient() { } pending_textures_.pop_front(); } - cc::OutputSurface::DetachFromClient(); } void MailboxOutputSurface::EnsureBackbuffer() { diff --git a/content/renderer/gpu/mailbox_output_surface.h b/content/renderer/gpu/mailbox_output_surface.h index 6b408f85fd4d..098b9a9873f9 100644 --- a/content/renderer/gpu/mailbox_output_surface.h +++ b/content/renderer/gpu/mailbox_output_surface.h @@ -38,7 +38,6 @@ class MailboxOutputSurface : public CompositorOutputSurface { ~MailboxOutputSurface() override; // cc::OutputSurface implementation. - void DetachFromClient() override; void EnsureBackbuffer() override; void DiscardBackbuffer() override; void Reshape(const gfx::Size& size, float scale_factor) override; diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index b42936fec15c..0a4021edc280 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -846,7 +846,6 @@ void RenderThreadImpl::Shutdown() { main_thread_compositor_task_runner_ = NULL; // Context providers must be released prior to destroying the GPU channel. - shared_worker_context_provider_ = nullptr; gpu_va_context_provider_ = nullptr; shared_main_thread_contexts_ = nullptr; @@ -1892,31 +1891,6 @@ base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() { return raster_worker_pool_.get(); } -scoped_refptr -RenderThreadImpl::SharedWorkerContextProvider() { - DCHECK(IsMainThread()); - // Try to reuse existing shared worker context provider. - bool shared_worker_context_provider_lost = false; - if (shared_worker_context_provider_) { - // Note: If context is lost, delete reference after releasing the lock. - base::AutoLock lock(*shared_worker_context_provider_->GetLock()); - if (shared_worker_context_provider_->ContextGL() - ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { - shared_worker_context_provider_lost = true; - } - } - if (!shared_worker_context_provider_ || shared_worker_context_provider_lost) { - shared_worker_context_provider_ = ContextProviderCommandBuffer::Create( - CreateOffscreenContext3d(), RENDER_WORKER_CONTEXT); - if (shared_worker_context_provider_ && - !shared_worker_context_provider_->BindToCurrentThread()) - shared_worker_context_provider_ = nullptr; - if (shared_worker_context_provider_) - shared_worker_context_provider_->SetupLock(); - } - return shared_worker_context_provider_; -} - void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { blink_platform_impl_->sampleGamepads(*data); } diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 4ac40da39788..b09df57f5992 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -325,9 +325,6 @@ class CONTENT_EXPORT RenderThreadImpl // A TaskRunner instance that runs tasks on the raster worker pool. base::TaskRunner* GetWorkerTaskRunner(); - // Returns a shared worker context provider that can be used on any thread. - scoped_refptr SharedWorkerContextProvider(); - // Causes the idle handler to skip sending idle notifications // on the two next scheduled calls, so idle notifications are // not sent for at least one notification delay. @@ -592,7 +589,6 @@ class CONTENT_EXPORT RenderThreadImpl base::ObserverList observers_; - scoped_refptr shared_worker_context_provider_; scoped_refptr gpu_va_context_provider_; scoped_ptr audio_renderer_mixer_manager_; diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index 7cff9fe11725..8997a58307d4 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -1018,9 +1018,10 @@ scoped_ptr RenderWidget::CreateOutputSurface(bool fallback) { // Cause the compositor to wait and try again. return scoped_ptr(); } - worker_context_provider = - RenderThreadImpl::current()->SharedWorkerContextProvider(); - if (!worker_context_provider) { + + worker_context_provider = ContextProviderCommandBuffer::Create( + CreateGraphicsContext3D(false), RENDER_WORKER_CONTEXT); + if (!worker_context_provider.get()) { // Cause the compositor to wait and try again. return scoped_ptr(); } diff --git a/ui/compositor/test/in_process_context_factory.cc b/ui/compositor/test/in_process_context_factory.cc index 1d96e0188b16..942947d5b1b0 100644 --- a/ui/compositor/test/in_process_context_factory.cc +++ b/ui/compositor/test/in_process_context_factory.cc @@ -112,37 +112,19 @@ void InProcessContextFactory::CreateOutputSurface( InProcessContextProvider::Create(attribs, &gpu_memory_buffer_manager_, &image_factory_, compositor->widget(), "UICompositor"); - - // Try to reuse existing shared worker context provider. - bool shared_worker_context_provider_lost = false; - if (shared_worker_context_provider_) { - // Note: If context is lost, delete reference after releasing the lock. - base::AutoLock lock(*shared_worker_context_provider_->GetLock()); - if (shared_worker_context_provider_->ContextGL() - ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { - shared_worker_context_provider_lost = true; - } - } - if (!shared_worker_context_provider_ || shared_worker_context_provider_lost) { - shared_worker_context_provider_ = InProcessContextProvider::CreateOffscreen( - &gpu_memory_buffer_manager_, &image_factory_); - if (shared_worker_context_provider_ && - !shared_worker_context_provider_->BindToCurrentThread()) - shared_worker_context_provider_ = nullptr; - if (shared_worker_context_provider_) - shared_worker_context_provider_->SetupLock(); - } + scoped_refptr worker_context_provider = + InProcessContextProvider::CreateOffscreen(&gpu_memory_buffer_manager_, + &image_factory_); scoped_ptr real_output_surface; if (use_test_surface_) { bool flipped_output_surface = false; real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( - context_provider, shared_worker_context_provider_, - flipped_output_surface)); + context_provider, worker_context_provider, flipped_output_surface)); } else { - real_output_surface = make_scoped_ptr(new DirectOutputSurface( - context_provider, shared_worker_context_provider_)); + real_output_surface = make_scoped_ptr( + new DirectOutputSurface(context_provider, worker_context_provider)); } if (surface_manager_) { @@ -154,7 +136,7 @@ void InProcessContextFactory::CreateOutputSurface( scoped_ptr surface_output_surface( new cc::SurfaceDisplayOutputSurface( surface_manager_, compositor->surface_id_allocator(), - context_provider, shared_worker_context_provider_)); + context_provider, worker_context_provider)); display_client->set_surface_output_surface(surface_output_surface.get()); surface_output_surface->set_display_client(display_client.get()); diff --git a/ui/compositor/test/in_process_context_factory.h b/ui/compositor/test/in_process_context_factory.h index 3c4e176d1f6e..4387adca5d5c 100644 --- a/ui/compositor/test/in_process_context_factory.h +++ b/ui/compositor/test/in_process_context_factory.h @@ -21,7 +21,6 @@ class SurfaceManager; } namespace ui { -class InProcessContextProvider; class InProcessContextFactory : public ContextFactory { public: @@ -57,8 +56,7 @@ class InProcessContextFactory : public ContextFactory { const gfx::Size& size) override; private: - scoped_refptr shared_main_thread_contexts_; - scoped_refptr shared_worker_context_provider_; + scoped_refptr shared_main_thread_contexts_; cc::TestSharedBitmapManager shared_bitmap_manager_; cc::TestGpuMemoryBufferManager gpu_memory_buffer_manager_; cc::TestImageFactory image_factory_; diff --git a/ui/compositor/test/in_process_context_provider.h b/ui/compositor/test/in_process_context_provider.h index 628eaecf497c..0f5f35f14123 100644 --- a/ui/compositor/test/in_process_context_provider.h +++ b/ui/compositor/test/in_process_context_provider.h @@ -38,6 +38,15 @@ class InProcessContextProvider : public cc::ContextProvider { gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, gpu::ImageFactory* image_factory); + private: + InProcessContextProvider( + const gpu::gles2::ContextCreationAttribHelper& attribs, + gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, + gpu::ImageFactory* image_factory, + gfx::AcceleratedWidget window, + const std::string& debug_name); + ~InProcessContextProvider() override; + // cc::ContextProvider: bool BindToCurrentThread() override; void DetachFromThread() override; @@ -57,15 +66,6 @@ class InProcessContextProvider : public cc::ContextProvider { const MemoryPolicyChangedCallback& memory_policy_changed_callback) override; - private: - InProcessContextProvider( - const gpu::gles2::ContextCreationAttribHelper& attribs, - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, - gpu::ImageFactory* image_factory, - gfx::AcceleratedWidget window, - const std::string& debug_name); - ~InProcessContextProvider() override; - void OnLostContext(); base::ThreadChecker main_thread_checker_; -- 2.11.4.GIT