diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 17:12:38 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 17:12:38 +0000 |
commit | e06e11233aadfb6dc6b7683ea17849fc956bef57 (patch) | |
tree | eb5bace81c67a0eebf9dd85fb6000127e69a3b51 /content | |
parent | 90c7150220dbed1bd721a048cab81cf9f17f0db3 (diff) | |
download | chromium_src-e06e11233aadfb6dc6b7683ea17849fc956bef57.zip chromium_src-e06e11233aadfb6dc6b7683ea17849fc956bef57.tar.gz chromium_src-e06e11233aadfb6dc6b7683ea17849fc956bef57.tar.bz2 |
Make ContextProvider::InitializeOnMainThread implicit.
The creator of a ContextProvider is now responsible for
calling InitializeOnMainThread() and should return NULL if
it fails. Now all places that request a ContextProvider
should check if the provider is NULL instead of initializing
it, and if its not NULL, can assume that it was initialized.
Added some DCHECKs to the context provider implementations
while I'm here.
No change in behaviour, this is covered by existing tests.
TBR=piman,jamesr
BUG=181228
Review URL: https://codereview.chromium.org/12872003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
9 files changed, 86 insertions, 92 deletions
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index f2aa4c4..239aa94 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -385,27 +385,13 @@ void CompositorImpl::scheduleComposite() { client_->ScheduleComposite(); } -class NullContextProvider : public cc::ContextProvider { - virtual bool InitializeOnMainThread() OVERRIDE { return false; } - virtual bool BindToCurrentThread() OVERRIDE { return false; } - virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { return NULL; } - virtual class GrContext* GrContext() OVERRIDE { return NULL; } - virtual void VerifyContexts() OVERRIDE {} - virtual bool DestroyedOnMainThread() OVERRIDE { return false; } - - protected: - virtual ~NullContextProvider() {} -}; - scoped_refptr<cc::ContextProvider> CompositorImpl::OffscreenContextProviderForMainThread() { // There is no support for offscreen contexts, or compositor filters that // would require them in this compositor instance. If they are needed, // then implement a context provider that provides contexts from // ImageTransportSurfaceAndroid. - if (!null_offscreen_context_provider_) - null_offscreen_context_provider_ = new NullContextProvider(); - return null_offscreen_context_provider_; + return NULL; } scoped_refptr<cc::ContextProvider> @@ -414,9 +400,7 @@ CompositorImpl::OffscreenContextProviderForCompositorThread() { // would require them in this compositor instance. If they are needed, // then implement a context provider that provides contexts from // ImageTransportSurfaceAndroid. - if (!null_offscreen_context_provider_) - null_offscreen_context_provider_ = new NullContextProvider(); - return null_offscreen_context_provider_; + return NULL; } void CompositorImpl::OnViewContextSwapBuffersPosted() { diff --git a/content/browser/renderer_host/image_transport_factory.cc b/content/browser/renderer_host/image_transport_factory.cc index 01fe4ab..83fde5a 100644 --- a/content/browser/renderer_host/image_transport_factory.cc +++ b/content/browser/renderer_host/image_transport_factory.cc @@ -581,10 +581,18 @@ class GpuProcessTransportFactory class MainThreadContextProvider : public ContextProviderCommandBuffer { public: - explicit MainThreadContextProvider(GpuProcessTransportFactory* factory) - : factory_(factory) {} + static scoped_refptr<MainThreadContextProvider> Create( + GpuProcessTransportFactory* factory) { + scoped_refptr<MainThreadContextProvider> provider = + new MainThreadContextProvider(factory); + if (!provider->InitializeOnMainThread()) + return NULL; + return provider; + } protected: + explicit MainThreadContextProvider(GpuProcessTransportFactory* factory) + : factory_(factory) {} virtual ~MainThreadContextProvider() {} virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> @@ -593,8 +601,6 @@ class GpuProcessTransportFactory } virtual void OnLostContext() OVERRIDE { - ContextProviderCommandBuffer::OnLostContext(); - MessageLoop::current()->PostTask( FROM_HERE, base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, @@ -609,17 +615,28 @@ class GpuProcessTransportFactory OffscreenContextProviderForMainThread() OVERRIDE { if (!shared_contexts_main_thread_ || shared_contexts_main_thread_->DestroyedOnMainThread()) { - shared_contexts_main_thread_ = new MainThreadContextProvider(this); + shared_contexts_main_thread_ = MainThreadContextProvider::Create(this); + if (shared_contexts_main_thread_ && + !shared_contexts_main_thread_->BindToCurrentThread()) + shared_contexts_main_thread_ = NULL; } return shared_contexts_main_thread_; } class CompositorThreadContextProvider : public ContextProviderCommandBuffer { public: - explicit CompositorThreadContextProvider( - GpuProcessTransportFactory* factory) : factory_(factory) {} + static scoped_refptr<CompositorThreadContextProvider> Create( + GpuProcessTransportFactory* factory) { + scoped_refptr<CompositorThreadContextProvider> provider = + new CompositorThreadContextProvider(factory); + if (!provider->InitializeOnMainThread()) + return NULL; + return provider; + } protected: + explicit CompositorThreadContextProvider( + GpuProcessTransportFactory* factory) : factory_(factory) {} virtual ~CompositorThreadContextProvider() {} virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> @@ -636,7 +653,7 @@ class GpuProcessTransportFactory if (!shared_contexts_compositor_thread_ || shared_contexts_compositor_thread_->DestroyedOnMainThread()) { shared_contexts_compositor_thread_ = - new CompositorThreadContextProvider(this); + CompositorThreadContextProvider::Create(this); } return shared_contexts_compositor_thread_; } @@ -644,16 +661,11 @@ class GpuProcessTransportFactory void CreateSharedContextLazy() { scoped_refptr<cc::ContextProvider> provider = OffscreenContextProviderForMainThread(); - if (!provider->InitializeOnMainThread()) { + if (!provider) { // If we can't recreate contexts, we won't be able to show the UI. // Better crash at this point. FatalGPUError("Failed to initialize UI shared context."); } - if (!provider->BindToCurrentThread()) { - // If we can't recreate contexts, we won't be able to show the UI. - // Better crash at this point. - FatalGPUError("Failed to make UI shared context current."); - } } void OnLostMainThreadSharedContext() { @@ -689,27 +701,6 @@ void CompositorSwapClient::OnLostContext() { // Note: previous line destroyed this. Don't access members from now on. } -class FailingContextProvider : public cc::ContextProvider { - public: - FailingContextProvider() {} - - virtual bool InitializeOnMainThread() OVERRIDE { return false; } - - virtual bool BindToCurrentThread() OVERRIDE { - NOTREACHED(); - return false; - } - - virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { return NULL; } - virtual class GrContext* GrContext() OVERRIDE { return NULL; } - virtual void VerifyContexts() OVERRIDE {} - virtual bool DestroyedOnMainThread() OVERRIDE { return false; } - - protected: - virtual ~FailingContextProvider() {} - DISALLOW_COPY_AND_ASSIGN(FailingContextProvider); -}; - class SoftwareContextFactory : public ui::ContextFactory { public: SoftwareContextFactory() {} @@ -738,20 +729,15 @@ class SoftwareContextFactory : public ui::ContextFactory { virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForMainThread() OVERRIDE { - if (!context_provider_) - context_provider_ = new FailingContextProvider(); - return context_provider_; + return NULL; } virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE { - if (!context_provider_) - context_provider_ = new FailingContextProvider(); - return context_provider_; + return NULL; } private: - scoped_refptr<FailingContextProvider> context_provider_; DISALLOW_COPY_AND_ASSIGN(SoftwareContextFactory); }; diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc index a291c31..84d6a50 100644 --- a/content/common/gpu/client/context_provider_command_buffer.cc +++ b/content/common/gpu/client/context_provider_command_buffer.cc @@ -17,7 +17,7 @@ class ContextProviderCommandBuffer::LostContextCallbackProxy } virtual void onContextLost() { - provider_->OnLostContext(); + provider_->OnLostContextInternal(); } private: @@ -58,17 +58,14 @@ ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { } bool ContextProviderCommandBuffer::InitializeOnMainThread() { - if (destroyed_) - return false; - if (context3d_) - return true; - + DCHECK(!context3d_); context3d_ = CreateOffscreenContext3d().Pass(); - destroyed_ = !context3d_; return !!context3d_; } bool ContextProviderCommandBuffer::BindToCurrentThread() { + DCHECK(context3d_); + if (lost_context_callback_proxy_) return true; @@ -81,10 +78,16 @@ bool ContextProviderCommandBuffer::BindToCurrentThread() { WebGraphicsContext3DCommandBufferImpl* ContextProviderCommandBuffer::Context3d() { + DCHECK(context3d_); + DCHECK(lost_context_callback_proxy_); // Is bound to thread. + return context3d_.get(); } class GrContext* ContextProviderCommandBuffer::GrContext() { + DCHECK(context3d_); + DCHECK(lost_context_callback_proxy_); // Is bound to thread. + if (gr_context_) return gr_context_->get(); @@ -96,13 +99,21 @@ class GrContext* ContextProviderCommandBuffer::GrContext() { } void ContextProviderCommandBuffer::VerifyContexts() { - if (!destroyed_ && context3d_->isContextLost()) - OnLostContext(); + DCHECK(context3d_); + DCHECK(lost_context_callback_proxy_); // Is bound to thread. + + if (context3d_->isContextLost()) + OnLostContextInternal(); } -void ContextProviderCommandBuffer::OnLostContext() { - base::AutoLock lock(main_thread_lock_); - destroyed_ = true; +void ContextProviderCommandBuffer::OnLostContextInternal() { + { + base::AutoLock lock(main_thread_lock_); + if (destroyed_) + return; + destroyed_ = true; + } + OnLostContext(); } bool ContextProviderCommandBuffer::DestroyedOnMainThread() { diff --git a/content/common/gpu/client/context_provider_command_buffer.h b/content/common/gpu/client/context_provider_command_buffer.h index 6264c48..8134ac9 100644 --- a/content/common/gpu/client/context_provider_command_buffer.h +++ b/content/common/gpu/client/context_provider_command_buffer.h @@ -22,9 +22,6 @@ namespace content { // WebGraphicsContext3DCommandBufferImpl context and a GrContext. class ContextProviderCommandBuffer : public cc::ContextProvider { public: - ContextProviderCommandBuffer(); - - virtual bool InitializeOnMainThread() OVERRIDE; virtual bool BindToCurrentThread() OVERRIDE; virtual WebGraphicsContext3DCommandBufferImpl* Context3d() OVERRIDE; virtual class GrContext* GrContext() OVERRIDE; @@ -37,13 +34,19 @@ class ContextProviderCommandBuffer : public cc::ContextProvider { } protected: + ContextProviderCommandBuffer(); virtual ~ContextProviderCommandBuffer(); + // This must be called immedately after creating this object, and it should + // be thrown away if this returns false. + bool InitializeOnMainThread(); + // Subclass must provide an implementation to create an offscreen context. virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateOffscreenContext3d() = 0; - virtual void OnLostContext(); + void OnLostContextInternal(); + virtual void OnLostContext() {} virtual void OnMemoryAllocationChanged(bool nonzero_allocation); private: diff --git a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc index 5d903d6..06302af 100644 --- a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc +++ b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc @@ -70,9 +70,7 @@ void BrowserPluginCompositingHelper::FreeMailboxMemory( scoped_refptr<cc::ContextProvider> context_provider = RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); - if (!context_provider->InitializeOnMainThread()) - return; - if (!context_provider->BindToCurrentThread()) + if (!context_provider) return; WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); diff --git a/content/renderer/pepper/pepper_platform_context_3d_impl.cc b/content/renderer/pepper/pepper_platform_context_3d_impl.cc index 64c1625..2a839ae 100644 --- a/content/renderer/pepper/pepper_platform_context_3d_impl.cc +++ b/content/renderer/pepper/pepper_platform_context_3d_impl.cc @@ -125,11 +125,9 @@ bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() { parent_context_provider_ = RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); - if (!parent_context_provider_->InitializeOnMainThread() || - !parent_context_provider_->BindToCurrentThread()) { - DestroyParentContextProviderAndBackingTexture(); + parent_texture_id_ = 0; + if (!parent_context_provider_) return false; - } // Flush any remaining commands in the parent context to make sure the // texture id accounting stays consistent. diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 4f88790..a3fc63d 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -242,6 +242,15 @@ class RenderThreadImpl::GpuVDAContextLostCallback class RenderThreadImpl::RendererContextProviderCommandBuffer : public ContextProviderCommandBuffer { + public: + static scoped_refptr<RendererContextProviderCommandBuffer> Create() { + scoped_refptr<RendererContextProviderCommandBuffer> provider = + new RendererContextProviderCommandBuffer(); + if (!provider->InitializeOnMainThread()) + return NULL; + return provider; + } + protected: virtual ~RendererContextProviderCommandBuffer() {} @@ -953,18 +962,27 @@ RenderThreadImpl::CreateOffscreenContext3d() { scoped_refptr<ContextProviderCommandBuffer> RenderThreadImpl::OffscreenContextProviderForMainThread() { + DCHECK(IsMainThread()); + if (!shared_contexts_main_thread_ || - shared_contexts_main_thread_->DestroyedOnMainThread()) - shared_contexts_main_thread_ = new RendererContextProviderCommandBuffer; + shared_contexts_main_thread_->DestroyedOnMainThread()) { + shared_contexts_main_thread_ = + RendererContextProviderCommandBuffer::Create(); + if (shared_contexts_main_thread_ && + !shared_contexts_main_thread_->BindToCurrentThread()) + shared_contexts_main_thread_ = NULL; + } return shared_contexts_main_thread_; } scoped_refptr<ContextProviderCommandBuffer> RenderThreadImpl::OffscreenContextProviderForCompositorThread() { + DCHECK(IsMainThread()); + if (!shared_contexts_compositor_thread_ || shared_contexts_compositor_thread_->DestroyedOnMainThread()) { shared_contexts_compositor_thread_ = - new RendererContextProviderCommandBuffer; + RendererContextProviderCommandBuffer::Create(); } return shared_contexts_compositor_thread_; } diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index c7a0da0..6578cd8 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2682,8 +2682,7 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer( scoped_refptr<cc::ContextProvider> context_provider = RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); - if (!context_provider->InitializeOnMainThread() || - !context_provider->BindToCurrentThread()) { + if (!context_provider) { LOG(ERROR) << "Failed to get context3d for media player"; return NULL; } diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index addb397..d8392f4 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -883,11 +883,8 @@ WebKit::WebGraphicsContext3D* RendererWebKitPlatformSupportImpl:: shared_offscreen_context_ = RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); } - if (!shared_offscreen_context_->InitializeOnMainThread() || - !shared_offscreen_context_->BindToCurrentThread()) { - shared_offscreen_context_ = NULL; + if (!shared_offscreen_context_) return NULL; - } return shared_offscreen_context_->Context3d(); } |