summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBo Liu <boliu@chromium.org>2014-08-29 16:01:20 -0700
committerBo Liu <boliu@chromium.org>2014-08-29 23:04:11 +0000
commit95bd5aa18ad5c269e04a2ad0a757aa54e4d8456e (patch)
tree9160be379046b2ba1c0e508d6d4e2a1c4fc2959c
parent5ca4e72dec22148be0204fd749cc96bab24e1786 (diff)
downloadchromium_src-95bd5aa18ad5c269e04a2ad0a757aa54e4d8456e.zip
chromium_src-95bd5aa18ad5c269e04a2ad0a757aa54e4d8456e.tar.gz
chromium_src-95bd5aa18ad5c269e04a2ad0a757aa54e4d8456e.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 (cherry picked from commit 469239e77f20c4ab2656f0f69b8793076a867120) TBR=boliu@chromium.org Review URL: https://codereview.chromium.org/523213002 Cr-Commit-Position: refs/branch-heads/2125@{#155} Cr-Branched-From: b68026d94bda36dd106a3d91a098719f952a9477-refs/heads/master@{#290040}
-rw-r--r--android_webview/browser/hardware_renderer.cc21
-rw-r--r--cc/test/test_in_process_context_provider.cc22
-rw-r--r--content/browser/android/in_process/synchronous_compositor_factory_impl.cc61
-rw-r--r--gpu/command_buffer/client/gl_in_process_context.cc50
-rw-r--r--gpu/command_buffer/client/gl_in_process_context.h15
-rw-r--r--webkit/common/gpu/context_provider_in_process.cc7
-rw-r--r--webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc24
-rw-r--r--webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h6
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 efd03e4..e624e9b 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");
}
@@ -246,7 +255,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();