diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-20 04:25:05 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-20 04:26:43 +0000 |
commit | 469239e77f20c4ab2656f0f69b8793076a867120 (patch) | |
tree | 4bf0424ca2eeb22861fbe3f8966235ca3468d9a6 | |
parent | 338caf0fe6dd106964a84e43f90145f658c2c490 (diff) | |
download | chromium_src-469239e77f20c4ab2656f0f69b8793076a867120.zip chromium_src-469239e77f20c4ab2656f0f69b8793076a867120.tar.gz chromium_src-469239e77f20c4ab2656f0f69b8793076a867120.tar.bz2 |
Add memory limits struct to in-process context
Add SharedMemoryLimits struct to in-process command buffer
context. Pick a reasonable value for the reclaim limit for
synchronous compositor
BUG=402086
Review URL: https://codereview.chromium.org/455083002
Cr-Commit-Position: refs/heads/master@{#290764}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290764 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 135 insertions, 71 deletions
diff --git a/android_webview/browser/hardware_renderer.cc b/android_webview/browser/hardware_renderer.cc index 6a3d54b..c2d1a6d 100644 --- a/android_webview/browser/hardware_renderer.cc +++ b/android_webview/browser/hardware_renderer.cc @@ -53,16 +53,17 @@ scoped_refptr<cc::ContextProvider> CreateContext( attributes, &attribs_for_gles2); attribs_for_gles2.lose_context_when_out_of_memory = true; - scoped_ptr<gpu::GLInProcessContext> context( - gpu::GLInProcessContext::Create(service, - surface, - surface->IsOffscreen(), - gfx::kNullAcceleratedWidget, - surface->GetSize(), - share_context, - false /* share_resources */, - attribs_for_gles2, - gpu_preference)); + scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( + service, + surface, + surface->IsOffscreen(), + gfx::kNullAcceleratedWidget, + surface->GetSize(), + share_context, + false /* share_resources */, + attribs_for_gles2, + gpu_preference, + gpu::GLInProcessContextSharedMemoryLimits())); DCHECK(context.get()); return webkit::gpu::ContextProviderInProcess::Create( diff --git a/cc/test/test_in_process_context_provider.cc b/cc/test/test_in_process_context_provider.cc index a466d87..b4d580f 100644 --- a/cc/test/test_in_process_context_provider.cc +++ b/cc/test/test_in_process_context_provider.cc @@ -36,16 +36,18 @@ scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() { attribs.bind_generates_resource = false; gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; - scoped_ptr<gpu::GLInProcessContext> context = make_scoped_ptr( - gpu::GLInProcessContext::Create(NULL, - NULL, - is_offscreen, - gfx::kNullAcceleratedWidget, - gfx::Size(1, 1), - NULL, - share_resources, - attribs, - gpu_preference)); + scoped_ptr<gpu::GLInProcessContext> context = + make_scoped_ptr(gpu::GLInProcessContext::Create( + NULL, + NULL, + is_offscreen, + gfx::kNullAcceleratedWidget, + gfx::Size(1, 1), + NULL, + share_resources, + attribs, + gpu_preference, + gpu::GLInProcessContextSharedMemoryLimits())); DCHECK(context); return context.Pass(); 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 af50011..006a3c6 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc @@ -44,38 +44,41 @@ scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext( attributes, &in_process_attribs); in_process_attribs.lose_context_when_out_of_memory = true; - scoped_ptr<gpu::GLInProcessContext> context( - gpu::GLInProcessContext::Create(NULL /* service */, - NULL /* surface */, - true /* is_offscreen */, - gfx::kNullAcceleratedWidget, - gfx::Size(1, 1), - NULL /* share_context */, - false /* share_resources */, - in_process_attribs, - gpu_preference)); + scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( + NULL /* service */, + NULL /* surface */, + true /* is_offscreen */, + gfx::kNullAcceleratedWidget, + gfx::Size(1, 1), + NULL /* share_context */, + false /* share_resources */, + in_process_attribs, + gpu_preference, + gpu::GLInProcessContextSharedMemoryLimits())); return context.Pass(); } scoped_ptr<gpu::GLInProcessContext> CreateContext( scoped_refptr<gpu::InProcessCommandBuffer::Service> service, - gpu::GLInProcessContext* share_context) { + gpu::GLInProcessContext* share_context, + const gpu::GLInProcessContextSharedMemoryLimits& mem_limits) { const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; gpu::gles2::ContextCreationAttribHelper in_process_attribs; WebGraphicsContext3DImpl::ConvertAttributes( GetDefaultAttribs(), &in_process_attribs); in_process_attribs.lose_context_when_out_of_memory = true; - scoped_ptr<gpu::GLInProcessContext> context( - gpu::GLInProcessContext::Create(service, - NULL /* surface */, - false /* is_offscreen */, - gfx::kNullAcceleratedWidget, - gfx::Size(1, 1), - share_context, - false /* share_resources */, - in_process_attribs, - gpu_preference)); + scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( + service, + NULL /* surface */, + false /* is_offscreen */, + gfx::kNullAcceleratedWidget, + gfx::Size(1, 1), + share_context, + false /* share_resources */, + in_process_attribs, + gpu_preference, + mem_limits)); return context.Pass(); } @@ -184,10 +187,16 @@ scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl:: CreateOnscreenContextProviderForCompositorThread() { DCHECK(service_); - if (!share_context_.get()) - share_context_ = CreateContext(service_, NULL); + 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())), + WrapContext(CreateContext(service_, share_context_.get(), mem_limits)), "Child-Compositor"); } @@ -248,7 +257,9 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { DCHECK(share_context_.get()); video_context_provider_ = new VideoContextProvider( - CreateContext(service_, share_context_.get())); + CreateContext(service_, + share_context_.get(), + gpu::GLInProcessContextSharedMemoryLimits())); } return video_context_provider_; } diff --git a/gpu/command_buffer/client/gl_in_process_context.cc b/gpu/command_buffer/client/gl_in_process_context.cc index 0a8294a..a5648df 100644 --- a/gpu/command_buffer/client/gl_in_process_context.cc +++ b/gpu/command_buffer/client/gl_in_process_context.cc @@ -37,18 +37,17 @@ namespace gpu { namespace { -const int32 kCommandBufferSize = 1024 * 1024; -// TODO(kbr): make the transfer buffer size configurable via context -// creation attributes. -const size_t kStartTransferBufferSize = 4 * 1024 * 1024; -const size_t kMinTransferBufferSize = 1 * 256 * 1024; -const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; +const int32 kDefaultCommandBufferSize = 1024 * 1024; +const unsigned int kDefaultStartTransferBufferSize = 4 * 1024 * 1024; +const unsigned int kDefaultMinTransferBufferSize = 1 * 256 * 1024; +const unsigned int kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; class GLInProcessContextImpl : public GLInProcessContext, public base::SupportsWeakPtr<GLInProcessContextImpl> { public: - explicit GLInProcessContextImpl(); + explicit GLInProcessContextImpl( + const GLInProcessContextSharedMemoryLimits& mem_limits); virtual ~GLInProcessContextImpl(); bool Initialize( @@ -65,6 +64,7 @@ class GLInProcessContextImpl // GLInProcessContext implementation: virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; + virtual size_t GetMappedMemoryLimit() OVERRIDE; #if defined(OS_ANDROID) virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( @@ -81,6 +81,7 @@ class GLInProcessContextImpl scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; scoped_ptr<InProcessCommandBuffer> command_buffer_; + const GLInProcessContextSharedMemoryLimits mem_limits_; bool context_lost_; base::Closure context_lost_callback_; @@ -92,8 +93,10 @@ base::LazyInstance<base::Lock> g_all_shared_contexts_lock = base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; -GLInProcessContextImpl::GLInProcessContextImpl() - : context_lost_(false) {} +GLInProcessContextImpl::GLInProcessContextImpl( + const GLInProcessContextSharedMemoryLimits& mem_limits) + : mem_limits_(mem_limits), context_lost_(false) { +} GLInProcessContextImpl::~GLInProcessContextImpl() { { @@ -107,6 +110,10 @@ gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { return gles2_implementation_.get(); } +size_t GLInProcessContextImpl::GetMappedMemoryLimit() { + return mem_limits_.mapped_memory_reclaim_limit; +} + void GLInProcessContextImpl::SetContextLostCallback( const base::Closure& callback) { context_lost_callback_ = callback; @@ -181,7 +188,7 @@ bool GLInProcessContextImpl::Initialize( // Create the GLES2 helper, which writes the command buffer protocol. gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); - if (!gles2_helper_->Initialize(kCommandBufferSize)) { + if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) { LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; Destroy(); return false; @@ -209,10 +216,10 @@ bool GLInProcessContextImpl::Initialize( } if (!gles2_implementation_->Initialize( - kStartTransferBufferSize, - kMinTransferBufferSize, - kMaxTransferBufferSize, - gles2::GLES2Implementation::kNoLimit)) { + mem_limits_.start_transfer_buffer_size, + mem_limits_.min_transfer_buffer_size, + mem_limits_.max_transfer_buffer_size, + mem_limits_.mapped_memory_reclaim_limit)) { return false; } @@ -245,6 +252,15 @@ GLInProcessContextImpl::GetSurfaceTexture(uint32 stream_id) { } // anonymous namespace +GLInProcessContextSharedMemoryLimits::GLInProcessContextSharedMemoryLimits() + : command_buffer_size(kDefaultCommandBufferSize), + start_transfer_buffer_size(kDefaultStartTransferBufferSize), + min_transfer_buffer_size(kDefaultMinTransferBufferSize), + max_transfer_buffer_size(kDefaultMaxTransferBufferSize), + mapped_memory_reclaim_limit(gles2::GLES2Implementation::kNoLimit) { +} + +// static GLInProcessContext* GLInProcessContext::Create( scoped_refptr<gpu::InProcessCommandBuffer::Service> service, scoped_refptr<gfx::GLSurface> surface, @@ -254,7 +270,8 @@ GLInProcessContext* GLInProcessContext::Create( GLInProcessContext* share_context, bool use_global_share_group, const ::gpu::gles2::ContextCreationAttribHelper& attribs, - gfx::GpuPreference gpu_preference) { + gfx::GpuPreference gpu_preference, + const GLInProcessContextSharedMemoryLimits& memory_limits) { DCHECK(!use_global_share_group || !share_context); if (surface.get()) { DCHECK_EQ(surface->IsOffscreen(), is_offscreen); @@ -262,7 +279,8 @@ GLInProcessContext* GLInProcessContext::Create( DCHECK_EQ(gfx::kNullAcceleratedWidget, window); } - scoped_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl()); + scoped_ptr<GLInProcessContextImpl> context( + new GLInProcessContextImpl(memory_limits)); if (!context->Initialize(surface, is_offscreen, use_global_share_group, diff --git a/gpu/command_buffer/client/gl_in_process_context.h b/gpu/command_buffer/client/gl_in_process_context.h index 6175cc5..33b1348 100644 --- a/gpu/command_buffer/client/gl_in_process_context.h +++ b/gpu/command_buffer/client/gl_in_process_context.h @@ -30,6 +30,16 @@ namespace gles2 { class GLES2Implementation; } +struct GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContextSharedMemoryLimits { + GLInProcessContextSharedMemoryLimits(); + + int32 command_buffer_size; + unsigned int start_transfer_buffer_size; + unsigned int min_transfer_buffer_size; + unsigned int max_transfer_buffer_size; + unsigned int mapped_memory_reclaim_limit; +}; + class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { public: virtual ~GLInProcessContext() {} @@ -53,7 +63,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { GLInProcessContext* share_context, bool use_global_share_group, const gpu::gles2::ContextCreationAttribHelper& attribs, - gfx::GpuPreference gpu_preference); + gfx::GpuPreference gpu_preference, + const GLInProcessContextSharedMemoryLimits& memory_limits); virtual void SetContextLostCallback(const base::Closure& callback) = 0; @@ -61,6 +72,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { // can be used without making it current. virtual gles2::GLES2Implementation* GetImplementation() = 0; + virtual size_t GetMappedMemoryLimit() = 0; + #if defined(OS_ANDROID) virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( uint32 stream_id) = 0; diff --git a/webkit/common/gpu/context_provider_in_process.cc b/webkit/common/gpu/context_provider_in_process.cc index 3785d38a..e4ca1d8 100644 --- a/webkit/common/gpu/context_provider_in_process.cc +++ b/webkit/common/gpu/context_provider_in_process.cc @@ -110,6 +110,13 @@ bool ContextProviderInProcess::BindToCurrentThread() { void ContextProviderInProcess::InitializeCapabilities() { capabilities_.gpu = context3d_->GetImplementation()->capabilities(); + + size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit(); + capabilities_.max_transfer_buffer_usage_bytes = + mapped_memory_limit == + WebGraphicsContext3DInProcessCommandBufferImpl::kNoLimit + ? std::numeric_limits<size_t>::max() + : mapped_memory_limit; } cc::ContextProvider::Capabilities diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index afd843a..2dc7dc8 100644 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -118,6 +118,10 @@ WebGraphicsContext3DInProcessCommandBufferImpl:: ~WebGraphicsContext3DInProcessCommandBufferImpl() { } +size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { + return context_->GetMappedMemoryLimit(); +} + bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { if (initialized_) return true; @@ -135,15 +139,17 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { // will need to be lost either when the first context requesting the // discrete GPU is created, or the last one is destroyed. gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; - context_.reset(GLInProcessContext::Create(NULL, /* service */ - NULL, /* surface */ - is_offscreen_, - window_, - gfx::Size(1, 1), - NULL, /* share_context */ - share_resources_, - attribs_, - gpu_preference)); + context_.reset(GLInProcessContext::Create( + NULL, /* service */ + NULL, /* surface */ + is_offscreen_, + window_, + gfx::Size(1, 1), + NULL, /* share_context */ + share_resources_, + attribs_, + gpu_preference, + ::gpu::GLInProcessContextSharedMemoryLimits())); } if (context_) { diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h index 54d7f17..0248dff 100644 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -36,6 +36,10 @@ namespace gpu { class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl : public WebGraphicsContext3DImpl { public: + enum MappedMemoryReclaimLimit { + kNoLimit = 0, + }; + static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> CreateViewContext( const blink::WebGraphicsContext3D::Attributes& attributes, @@ -54,6 +58,8 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); + size_t GetMappedMemoryLimit(); + //---------------------------------------------------------------------- // WebGraphicsContext3D methods virtual bool makeContextCurrent(); |