Commit 469239e7 authored by boliu@chromium.org's avatar boliu@chromium.org

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
parent 338caf0f
...@@ -53,16 +53,17 @@ scoped_refptr<cc::ContextProvider> CreateContext( ...@@ -53,16 +53,17 @@ scoped_refptr<cc::ContextProvider> CreateContext(
attributes, &attribs_for_gles2); attributes, &attribs_for_gles2);
attribs_for_gles2.lose_context_when_out_of_memory = true; attribs_for_gles2.lose_context_when_out_of_memory = true;
scoped_ptr<gpu::GLInProcessContext> context( scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
gpu::GLInProcessContext::Create(service, service,
surface, surface,
surface->IsOffscreen(), surface->IsOffscreen(),
gfx::kNullAcceleratedWidget, gfx::kNullAcceleratedWidget,
surface->GetSize(), surface->GetSize(),
share_context, share_context,
false /* share_resources */, false /* share_resources */,
attribs_for_gles2, attribs_for_gles2,
gpu_preference)); gpu_preference,
gpu::GLInProcessContextSharedMemoryLimits()));
DCHECK(context.get()); DCHECK(context.get());
return webkit::gpu::ContextProviderInProcess::Create( return webkit::gpu::ContextProviderInProcess::Create(
......
...@@ -36,16 +36,18 @@ scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() { ...@@ -36,16 +36,18 @@ scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() {
attribs.bind_generates_resource = false; attribs.bind_generates_resource = false;
gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
scoped_ptr<gpu::GLInProcessContext> context = make_scoped_ptr( scoped_ptr<gpu::GLInProcessContext> context =
gpu::GLInProcessContext::Create(NULL, make_scoped_ptr(gpu::GLInProcessContext::Create(
NULL, NULL,
is_offscreen, NULL,
gfx::kNullAcceleratedWidget, is_offscreen,
gfx::Size(1, 1), gfx::kNullAcceleratedWidget,
NULL, gfx::Size(1, 1),
share_resources, NULL,
attribs, share_resources,
gpu_preference)); attribs,
gpu_preference,
gpu::GLInProcessContextSharedMemoryLimits()));
DCHECK(context); DCHECK(context);
return context.Pass(); return context.Pass();
......
...@@ -44,38 +44,41 @@ scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext( ...@@ -44,38 +44,41 @@ scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext(
attributes, &in_process_attribs); attributes, &in_process_attribs);
in_process_attribs.lose_context_when_out_of_memory = true; in_process_attribs.lose_context_when_out_of_memory = true;
scoped_ptr<gpu::GLInProcessContext> context( scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
gpu::GLInProcessContext::Create(NULL /* service */, NULL /* service */,
NULL /* surface */, NULL /* surface */,
true /* is_offscreen */, true /* is_offscreen */,
gfx::kNullAcceleratedWidget, gfx::kNullAcceleratedWidget,
gfx::Size(1, 1), gfx::Size(1, 1),
NULL /* share_context */, NULL /* share_context */,
false /* share_resources */, false /* share_resources */,
in_process_attribs, in_process_attribs,
gpu_preference)); gpu_preference,
gpu::GLInProcessContextSharedMemoryLimits()));
return context.Pass(); return context.Pass();
} }
scoped_ptr<gpu::GLInProcessContext> CreateContext( scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service, 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; const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
gpu::gles2::ContextCreationAttribHelper in_process_attribs; gpu::gles2::ContextCreationAttribHelper in_process_attribs;
WebGraphicsContext3DImpl::ConvertAttributes( WebGraphicsContext3DImpl::ConvertAttributes(
GetDefaultAttribs(), &in_process_attribs); GetDefaultAttribs(), &in_process_attribs);
in_process_attribs.lose_context_when_out_of_memory = true; in_process_attribs.lose_context_when_out_of_memory = true;
scoped_ptr<gpu::GLInProcessContext> context( scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
gpu::GLInProcessContext::Create(service, service,
NULL /* surface */, NULL /* surface */,
false /* is_offscreen */, false /* is_offscreen */,
gfx::kNullAcceleratedWidget, gfx::kNullAcceleratedWidget,
gfx::Size(1, 1), gfx::Size(1, 1),
share_context, share_context,
false /* share_resources */, false /* share_resources */,
in_process_attribs, in_process_attribs,
gpu_preference)); gpu_preference,
mem_limits));
return context.Pass(); return context.Pass();
} }
...@@ -184,10 +187,16 @@ scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl:: ...@@ -184,10 +187,16 @@ scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
CreateOnscreenContextProviderForCompositorThread() { CreateOnscreenContextProviderForCompositorThread() {
DCHECK(service_); DCHECK(service_);
if (!share_context_.get()) if (!share_context_.get()) {
share_context_ = CreateContext(service_, NULL); 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( return webkit::gpu::ContextProviderInProcess::Create(
WrapContext(CreateContext(service_, share_context_.get())), WrapContext(CreateContext(service_, share_context_.get(), mem_limits)),
"Child-Compositor"); "Child-Compositor");
} }
...@@ -248,7 +257,9 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { ...@@ -248,7 +257,9 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
DCHECK(share_context_.get()); DCHECK(share_context_.get());
video_context_provider_ = new VideoContextProvider( video_context_provider_ = new VideoContextProvider(
CreateContext(service_, share_context_.get())); CreateContext(service_,
share_context_.get(),
gpu::GLInProcessContextSharedMemoryLimits()));
} }
return video_context_provider_; return video_context_provider_;
} }
......
...@@ -37,18 +37,17 @@ namespace gpu { ...@@ -37,18 +37,17 @@ namespace gpu {
namespace { namespace {
const int32 kCommandBufferSize = 1024 * 1024; const int32 kDefaultCommandBufferSize = 1024 * 1024;
// TODO(kbr): make the transfer buffer size configurable via context const unsigned int kDefaultStartTransferBufferSize = 4 * 1024 * 1024;
// creation attributes. const unsigned int kDefaultMinTransferBufferSize = 1 * 256 * 1024;
const size_t kStartTransferBufferSize = 4 * 1024 * 1024; const unsigned int kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
const size_t kMinTransferBufferSize = 1 * 256 * 1024;
const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
class GLInProcessContextImpl class GLInProcessContextImpl
: public GLInProcessContext, : public GLInProcessContext,
public base::SupportsWeakPtr<GLInProcessContextImpl> { public base::SupportsWeakPtr<GLInProcessContextImpl> {
public: public:
explicit GLInProcessContextImpl(); explicit GLInProcessContextImpl(
const GLInProcessContextSharedMemoryLimits& mem_limits);
virtual ~GLInProcessContextImpl(); virtual ~GLInProcessContextImpl();
bool Initialize( bool Initialize(
...@@ -65,6 +64,7 @@ class GLInProcessContextImpl ...@@ -65,6 +64,7 @@ class GLInProcessContextImpl
// GLInProcessContext implementation: // GLInProcessContext implementation:
virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE;
virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE;
virtual size_t GetMappedMemoryLimit() OVERRIDE;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
...@@ -81,6 +81,7 @@ class GLInProcessContextImpl ...@@ -81,6 +81,7 @@ class GLInProcessContextImpl
scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
scoped_ptr<InProcessCommandBuffer> command_buffer_; scoped_ptr<InProcessCommandBuffer> command_buffer_;
const GLInProcessContextSharedMemoryLimits mem_limits_;
bool context_lost_; bool context_lost_;
base::Closure context_lost_callback_; base::Closure context_lost_callback_;
...@@ -92,8 +93,10 @@ base::LazyInstance<base::Lock> g_all_shared_contexts_lock = ...@@ -92,8 +93,10 @@ base::LazyInstance<base::Lock> g_all_shared_contexts_lock =
base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
GLInProcessContextImpl::GLInProcessContextImpl() GLInProcessContextImpl::GLInProcessContextImpl(
: context_lost_(false) {} const GLInProcessContextSharedMemoryLimits& mem_limits)
: mem_limits_(mem_limits), context_lost_(false) {
}
GLInProcessContextImpl::~GLInProcessContextImpl() { GLInProcessContextImpl::~GLInProcessContextImpl() {
{ {
...@@ -107,6 +110,10 @@ gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { ...@@ -107,6 +110,10 @@ gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() {
return gles2_implementation_.get(); return gles2_implementation_.get();
} }
size_t GLInProcessContextImpl::GetMappedMemoryLimit() {
return mem_limits_.mapped_memory_reclaim_limit;
}
void GLInProcessContextImpl::SetContextLostCallback( void GLInProcessContextImpl::SetContextLostCallback(
const base::Closure& callback) { const base::Closure& callback) {
context_lost_callback_ = callback; context_lost_callback_ = callback;
...@@ -181,7 +188,7 @@ bool GLInProcessContextImpl::Initialize( ...@@ -181,7 +188,7 @@ bool GLInProcessContextImpl::Initialize(
// Create the GLES2 helper, which writes the command buffer protocol. // Create the GLES2 helper, which writes the command buffer protocol.
gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); 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"; LOG(ERROR) << "Failed to initialize GLES2CmdHelper";
Destroy(); Destroy();
return false; return false;
...@@ -209,10 +216,10 @@ bool GLInProcessContextImpl::Initialize( ...@@ -209,10 +216,10 @@ bool GLInProcessContextImpl::Initialize(
} }
if (!gles2_implementation_->Initialize( if (!gles2_implementation_->Initialize(
kStartTransferBufferSize, mem_limits_.start_transfer_buffer_size,
kMinTransferBufferSize, mem_limits_.min_transfer_buffer_size,
kMaxTransferBufferSize, mem_limits_.max_transfer_buffer_size,
gles2::GLES2Implementation::kNoLimit)) { mem_limits_.mapped_memory_reclaim_limit)) {
return false; return false;
} }
...@@ -245,6 +252,15 @@ GLInProcessContextImpl::GetSurfaceTexture(uint32 stream_id) { ...@@ -245,6 +252,15 @@ GLInProcessContextImpl::GetSurfaceTexture(uint32 stream_id) {
} // anonymous namespace } // 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( GLInProcessContext* GLInProcessContext::Create(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service, scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
scoped_refptr<gfx::GLSurface> surface, scoped_refptr<gfx::GLSurface> surface,
...@@ -254,7 +270,8 @@ GLInProcessContext* GLInProcessContext::Create( ...@@ -254,7 +270,8 @@ GLInProcessContext* GLInProcessContext::Create(
GLInProcessContext* share_context, GLInProcessContext* share_context,
bool use_global_share_group, bool use_global_share_group,
const ::gpu::gles2::ContextCreationAttribHelper& attribs, const ::gpu::gles2::ContextCreationAttribHelper& attribs,
gfx::GpuPreference gpu_preference) { gfx::GpuPreference gpu_preference,
const GLInProcessContextSharedMemoryLimits& memory_limits) {
DCHECK(!use_global_share_group || !share_context); DCHECK(!use_global_share_group || !share_context);
if (surface.get()) { if (surface.get()) {
DCHECK_EQ(surface->IsOffscreen(), is_offscreen); DCHECK_EQ(surface->IsOffscreen(), is_offscreen);
...@@ -262,7 +279,8 @@ GLInProcessContext* GLInProcessContext::Create( ...@@ -262,7 +279,8 @@ GLInProcessContext* GLInProcessContext::Create(
DCHECK_EQ(gfx::kNullAcceleratedWidget, window); DCHECK_EQ(gfx::kNullAcceleratedWidget, window);
} }
scoped_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl()); scoped_ptr<GLInProcessContextImpl> context(
new GLInProcessContextImpl(memory_limits));
if (!context->Initialize(surface, if (!context->Initialize(surface,
is_offscreen, is_offscreen,
use_global_share_group, use_global_share_group,
......
...@@ -30,6 +30,16 @@ namespace gles2 { ...@@ -30,6 +30,16 @@ namespace gles2 {
class GLES2Implementation; 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 { class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
public: public:
virtual ~GLInProcessContext() {} virtual ~GLInProcessContext() {}
...@@ -53,7 +63,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -53,7 +63,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
GLInProcessContext* share_context, GLInProcessContext* share_context,
bool use_global_share_group, bool use_global_share_group,
const gpu::gles2::ContextCreationAttribHelper& attribs, 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; virtual void SetContextLostCallback(const base::Closure& callback) = 0;
...@@ -61,6 +72,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -61,6 +72,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
// can be used without making it current. // can be used without making it current.
virtual gles2::GLES2Implementation* GetImplementation() = 0; virtual gles2::GLES2Implementation* GetImplementation() = 0;
virtual size_t GetMappedMemoryLimit() = 0;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
uint32 stream_id) = 0; uint32 stream_id) = 0;
......
...@@ -110,6 +110,13 @@ bool ContextProviderInProcess::BindToCurrentThread() { ...@@ -110,6 +110,13 @@ bool ContextProviderInProcess::BindToCurrentThread() {
void ContextProviderInProcess::InitializeCapabilities() { void ContextProviderInProcess::InitializeCapabilities() {
capabilities_.gpu = context3d_->GetImplementation()->capabilities(); 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 cc::ContextProvider::Capabilities
......
...@@ -118,6 +118,10 @@ WebGraphicsContext3DInProcessCommandBufferImpl:: ...@@ -118,6 +118,10 @@ WebGraphicsContext3DInProcessCommandBufferImpl::
~WebGraphicsContext3DInProcessCommandBufferImpl() { ~WebGraphicsContext3DInProcessCommandBufferImpl() {
} }
size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() {
return context_->GetMappedMemoryLimit();
}
bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
if (initialized_) if (initialized_)
return true; return true;
...@@ -135,15 +139,17 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { ...@@ -135,15 +139,17 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
// will need to be lost either when the first context requesting the // will need to be lost either when the first context requesting the
// discrete GPU is created, or the last one is destroyed. // discrete GPU is created, or the last one is destroyed.
gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
context_.reset(GLInProcessContext::Create(NULL, /* service */ context_.reset(GLInProcessContext::Create(
NULL, /* surface */ NULL, /* service */
is_offscreen_, NULL, /* surface */
window_, is_offscreen_,
gfx::Size(1, 1), window_,
NULL, /* share_context */ gfx::Size(1, 1),
share_resources_, NULL, /* share_context */
attribs_, share_resources_,
gpu_preference)); attribs_,
gpu_preference,
::gpu::GLInProcessContextSharedMemoryLimits()));
} }
if (context_) { if (context_) {
......
...@@ -36,6 +36,10 @@ namespace gpu { ...@@ -36,6 +36,10 @@ namespace gpu {
class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
: public WebGraphicsContext3DImpl { : public WebGraphicsContext3DImpl {
public: public:
enum MappedMemoryReclaimLimit {
kNoLimit = 0,
};
static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
CreateViewContext( CreateViewContext(
const blink::WebGraphicsContext3D::Attributes& attributes, const blink::WebGraphicsContext3D::Attributes& attributes,
...@@ -54,6 +58,8 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl ...@@ -54,6 +58,8 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); virtual ~WebGraphicsContext3DInProcessCommandBufferImpl();
size_t GetMappedMemoryLimit();
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// WebGraphicsContext3D methods // WebGraphicsContext3D methods
virtual bool makeContextCurrent(); virtual bool makeContextCurrent();
......
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