Commit a5be7190 authored by sievers's avatar sievers Committed by Commit bot

InProcessGL: Share MailboxManager per service

The current logic ends up creating a MailboxManager per ContextGroup,
so change this to share the mailbox manager across
InProcessCommandBuffer::Service instances.

This also allows for removing code in Android WebView that deals with
passing around the share group. None of these contexts (child, parent
compositor and video) need client-side share groups since mailbox names
are used.

TBR=tedchoc@chromium.org for content/public

Review URL: https://codereview.chromium.org/540143002

Cr-Commit-Position: refs/heads/master@{#293902}
parent e0dd0295
......@@ -268,9 +268,6 @@ bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) {
hardware_enabled_ = compositor_->InitializeHwDraw();
if (hardware_enabled_) {
tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this);
gpu::GLInProcessContext* share_context = compositor_->GetShareContext();
DCHECK(share_context);
shared_renderer_state_->SetSharedContext(share_context);
}
}
if (!hardware_enabled_)
......@@ -476,7 +473,6 @@ void BrowserViewRenderer::ReleaseHardware() {
DCHECK(shared_renderer_state_->ReturnedResourcesEmpty());
compositor_->ReleaseHwDraw();
shared_renderer_state_->SetSharedContext(NULL);
hardware_enabled_ = false;
SynchronousCompositorMemoryPolicy zero_policy;
......
......@@ -38,8 +38,7 @@ using webkit::gpu::WebGraphicsContext3DImpl;
scoped_refptr<cc::ContextProvider> CreateContext(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
gpu::GLInProcessContext* share_context) {
scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
blink::WebGraphicsContext3D::Attributes attributes;
......@@ -59,7 +58,7 @@ scoped_refptr<cc::ContextProvider> CreateContext(
surface->IsOffscreen(),
gfx::kNullAcceleratedWidget,
surface->GetSize(),
share_context,
NULL /* share_context */,
false /* share_resources */,
attribs_for_gles2,
gpu_preference,
......@@ -242,8 +241,7 @@ scoped_ptr<cc::OutputSurface> HardwareRenderer::CreateOutputSurface(
DCHECK(!fallback);
scoped_refptr<cc::ContextProvider> context_provider =
CreateContext(gl_surface_,
DeferredGpuCommandService::GetInstance(),
shared_renderer_state_->GetSharedContext());
DeferredGpuCommandService::GetInstance());
scoped_ptr<ParentOutputSurface> output_surface_holder(
new ParentOutputSurface(context_provider));
output_surface_ = output_surface_holder.get();
......
......@@ -80,8 +80,7 @@ SharedRendererState::SharedRendererState(
client_on_ui_(client),
weak_factory_on_ui_thread_(this),
ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
inside_hardware_release_(false),
share_context_(NULL) {
inside_hardware_release_(false) {
DCHECK(ui_loop_->BelongsToCurrentThread());
DCHECK(client_on_ui_);
ResetRequestDrawGLCallback();
......@@ -179,18 +178,6 @@ bool SharedRendererState::IsInsideHardwareRelease() const {
return inside_hardware_release_;
}
void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) {
base::AutoLock lock(lock_);
DCHECK(!share_context_ || !context);
share_context_ = context;
}
gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const {
base::AutoLock lock(lock_);
DCHECK(share_context_);
return share_context_;
}
void SharedRendererState::InsertReturnedResources(
const cc::ReturnedResourceArray& resources) {
base::AutoLock lock(lock_);
......
......@@ -64,9 +64,6 @@ class SharedRendererState {
const ParentCompositorDrawConstraints ParentDrawConstraints() const;
void SetSharedContext(gpu::GLInProcessContext* context);
gpu::GLInProcessContext* GetSharedContext() const;
void InsertReturnedResources(const cc::ReturnedResourceArray& resources);
void SwapReturnedResources(cc::ReturnedResourceArray* resources);
bool ReturnedResourcesEmpty() const;
......@@ -91,7 +88,6 @@ class SharedRendererState {
scoped_ptr<DrawGLInput> draw_gl_input_;
bool inside_hardware_release_;
ParentCompositorDrawConstraints parent_draw_constraints_;
gpu::GLInProcessContext* share_context_;
cc::ReturnedResourceArray returned_resources_;
base::Closure request_draw_gl_closure_;
......
......@@ -60,7 +60,6 @@ scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext(
scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
gpu::GLInProcessContext* share_context,
const gpu::GLInProcessContextSharedMemoryLimits& mem_limits) {
const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
gpu::gles2::ContextCreationAttribHelper in_process_attribs;
......@@ -74,7 +73,7 @@ scoped_ptr<gpu::GLInProcessContext> CreateContext(
false /* is_offscreen */,
gfx::kNullAcceleratedWidget,
gfx::Size(1, 1),
share_context,
NULL /* share_context */,
false /* share_resources */,
in_process_attribs,
gpu_preference,
......@@ -187,24 +186,15 @@ scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
CreateOnscreenContextProviderForCompositorThread() {
DCHECK(service_);
if (!share_context_.get()) {
share_context_ = CreateContext(
service_, NULL, gpu::GLInProcessContextSharedMemoryLimits());
}
gpu::GLInProcessContextSharedMemoryLimits mem_limits;
// This is half of what RenderWidget uses because synchronous compositor
// pipeline is only one frame deep.
mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024;
return webkit::gpu::ContextProviderInProcess::Create(
WrapContext(CreateContext(service_, share_context_.get(), mem_limits)),
WrapContext(CreateContext(service_, mem_limits)),
"Child-Compositor");
}
gpu::GLInProcessContext* SynchronousCompositorFactoryImpl::GetShareContext() {
DCHECK(share_context_.get());
return share_context_.get();
}
scoped_refptr<StreamTextureFactory>
SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) {
scoped_refptr<StreamTextureFactorySynchronousImpl> factory(
......@@ -252,11 +242,9 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
if (!video_context_provider_) {
DCHECK(service_);
DCHECK(share_context_.get());
video_context_provider_ = new VideoContextProvider(
CreateContext(service_,
share_context_.get(),
gpu::GLInProcessContextSharedMemoryLimits()));
}
return video_context_provider_;
......
......@@ -60,7 +60,6 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
scoped_refptr<cc::ContextProvider>
CreateOnscreenContextProviderForCompositorThread();
gpu::GLInProcessContext* GetShareContext();
private:
bool CanCreateMainThreadContext();
......@@ -70,7 +69,6 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
SynchronousInputEventFilter synchronous_input_event_filter_;
scoped_refptr<gpu::InProcessCommandBuffer::Service> service_;
scoped_ptr<gpu::GLInProcessContext> share_context_;
scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
video_context_provider_;
......
......@@ -115,11 +115,6 @@ void SynchronousCompositorImpl::ReleaseHwDraw() {
g_factory.Get().CompositorReleasedHardwareDraw();
}
gpu::GLInProcessContext* SynchronousCompositorImpl::GetShareContext() {
DCHECK(CalledOnValidThread());
return g_factory.Get().GetShareContext();
}
scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw(
gfx::Size surface_size,
const gfx::Transform& transform,
......
......@@ -53,7 +53,6 @@ class SynchronousCompositorImpl
OVERRIDE;
virtual bool InitializeHwDraw() OVERRIDE;
virtual void ReleaseHwDraw() OVERRIDE;
virtual gpu::GLInProcessContext* GetShareContext() OVERRIDE;
virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw(
gfx::Size surface_size,
const gfx::Transform& transform,
......
......@@ -80,11 +80,6 @@ class CONTENT_EXPORT SynchronousCompositor {
// releases all hardware resources.
virtual void ReleaseHwDraw() = 0;
// Get the share context of the compositor. The returned context is owned
// by the compositor and is only valid between InitializeHwDraw and
// ReleaseHwDraw.
virtual gpu::GLInProcessContext* GetShareContext() = 0;
// "On demand" hardware draw. The content is first clipped to |damage_area|,
// then transformed through |transform|, and finally clipped to |view_size|.
virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw(
......
......@@ -190,6 +190,13 @@ InProcessCommandBuffer::Service::Service() {}
InProcessCommandBuffer::Service::~Service() {}
scoped_refptr<gles2::MailboxManager>
InProcessCommandBuffer::Service::mailbox_manager() {
if (!mailbox_manager_.get())
mailbox_manager_ = new gles2::MailboxManager();
return mailbox_manager_;
}
scoped_refptr<InProcessCommandBuffer::Service>
InProcessCommandBuffer::GetDefaultService() {
base::AutoLock lock(default_thread_clients_lock_.Get());
......@@ -342,7 +349,7 @@ bool InProcessCommandBuffer::InitializeOnGpuThread(
decoder_.reset(gles2::GLES2Decoder::Create(
params.context_group
? params.context_group->decoder_->GetContextGroup()
: new gles2::ContextGroup(NULL,
: new gles2::ContextGroup(service_->mailbox_manager(),
NULL,
service_->shader_translator_cache(),
NULL,
......
......@@ -48,6 +48,7 @@ namespace gpu {
namespace gles2 {
class GLES2Decoder;
class MailboxManager;
class ShaderTranslatorCache;
}
......@@ -153,6 +154,10 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
virtual bool UseVirtualizedGLContexts() = 0;
virtual scoped_refptr<gles2::ShaderTranslatorCache>
shader_translator_cache() = 0;
scoped_refptr<gles2::MailboxManager> mailbox_manager();
private:
scoped_refptr<gles2::MailboxManager> mailbox_manager_;
};
#if defined(OS_ANDROID)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment