diff options
author | reveman <reveman@chromium.org> | 2015-09-23 17:19:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-24 00:34:48 +0000 |
commit | d180dfc3198c1e58a8c10f7349f3d949e22c5f3d (patch) | |
tree | 3f1b2d58647d991dd3ab1d3ba13da4f7d8205979 /content/browser/android/in_process | |
parent | f86718093f9c88d956207b527cf5bed4a872a24f (diff) | |
download | chromium_src-d180dfc3198c1e58a8c10f7349f3d949e22c5f3d.zip chromium_src-d180dfc3198c1e58a8c10f7349f3d949e22c5f3d.tar.gz chromium_src-d180dfc3198c1e58a8c10f7349f3d949e22c5f3d.tar.bz2 |
Re-land: 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,525811
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1336733002
Cr-Commit-Position: refs/heads/master@{#350409}
Diffstat (limited to 'content/browser/android/in_process')
4 files changed, 82 insertions, 7 deletions
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 b90edd6..5d62030 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc @@ -24,6 +24,7 @@ #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,8 +171,7 @@ SynchronousCompositorFactoryImpl::CreateOutputSurface( scoped_refptr<cc::ContextProvider> onscreen_context = CreateContextProviderForCompositor(surface_id, RENDER_COMPOSITOR_CONTEXT); scoped_refptr<cc::ContextProvider> worker_context = - CreateContextProviderForCompositor(0, RENDER_WORKER_CONTEXT); - + GetSharedWorkerContextProvider(); return make_scoped_ptr(new SynchronousCompositorOutputSurface( onscreen_context, worker_context, routing_id, frame_swap_message_queue)); } @@ -211,6 +211,9 @@ 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(); @@ -232,6 +235,67 @@ SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor( "Child-Compositor"); } +scoped_refptr<cc::ContextProvider> +SynchronousCompositorFactoryImpl::GetSharedWorkerContextProvider() { + // 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; + + if (use_ipc_command_buffer_) { + 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; + } + } + if (!shared_worker_context_ || shared_worker_context_lost) { + WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; + mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; + scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 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(); + } + + return shared_worker_context_; + } + + bool in_process_shared_worker_context_lost = false; + if (in_process_shared_worker_context_) { + // Note: If context is lost, we delete reference after releasing the lock. + base::AutoLock lock(*in_process_shared_worker_context_->GetLock()); + if (in_process_shared_worker_context_->ContextGL() + ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { + in_process_shared_worker_context_lost = true; + } + } + if (!in_process_shared_worker_context_ || + in_process_shared_worker_context_lost) { + gpu::GLInProcessContextSharedMemoryLimits mem_limits; + mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; + ContextHolder holder = CreateContextHolder( + GetDefaultAttribs(), GpuThreadService(), mem_limits, true); + in_process_shared_worker_context_ = ContextProviderInProcess::Create( + holder.command_buffer.Pass(), "Child-Worker"); + if (!in_process_shared_worker_context_->BindToCurrentThread()) + in_process_shared_worker_context_ = nullptr; + if (in_process_shared_worker_context_) + in_process_shared_worker_context_->SetupLock(); + } + + return in_process_shared_worker_context_; +} + scoped_refptr<StreamTextureFactory> SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { scoped_refptr<StreamTextureFactorySynchronousImpl> factory( 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 84ceb03..90d6105 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.h @@ -28,6 +28,7 @@ class WebGraphicsContext3DInProcessCommandBufferImpl; namespace content { class InProcessChildThreadParams; +class SynchronousCompositorContextProvider; class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { public: @@ -74,6 +75,7 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { scoped_refptr<cc::ContextProvider> CreateContextProviderForCompositor( int surface_id, CommandBufferContextType type); + scoped_refptr<cc::ContextProvider> GetSharedWorkerContextProvider(); bool CanCreateMainThreadContext(); scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> TryCreateStreamTextureFactory(); @@ -88,6 +90,10 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { class VideoContextProvider; scoped_refptr<VideoContextProvider> video_context_provider_; + scoped_refptr<SynchronousCompositorContextProvider> shared_worker_context_; + scoped_refptr<cc_blink::ContextProviderWebContext> + in_process_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 85c7bcb..f03f992 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.cc +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.cc @@ -83,11 +83,6 @@ SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( } SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { - DCHECK(CalledOnValidThread()); - if (registered_) { - SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( - routing_id_, this); - } } bool SynchronousCompositorOutputSurface::BindToClient( @@ -105,6 +100,15 @@ 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 4146952..b1baa64 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.h +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.h @@ -58,6 +58,7 @@ 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; |