Commit f3cd3806 authored by danakj's avatar danakj Committed by Commit bot

Use gpu::SharedMemoryLimits for in process GL contexts.

Replace the GLInProcessContextSharedMemoryLimits class with our new
SharedMemoryLimits class, so we can share implementations and defaults.

R=boliu@chromium.org, piman@chromium.org
BUG=584497
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

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

Cr-Commit-Position: refs/heads/master@{#388633}
parent 0ce639dc
......@@ -13,6 +13,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
......@@ -50,11 +51,20 @@ AwRenderThreadContextProvider::AwRenderThreadContextProvider(
attributes.samples = 0;
attributes.sample_buffers = 0;
attributes.bind_generates_resource = false;
gpu::SharedMemoryLimits limits;
// This context is only used for the display compositor, and there are no
// uploads done with it at all. We choose a small transfer buffer limit
// here, the minimums match the display compositor context for the android
// browser. We don't set the max since we expect the transfer buffer to be
// relatively unused.
limits.start_transfer_buffer_size = 64 * 1024;
limits.min_transfer_buffer_size = 64 * 1024;
context_.reset(gpu::GLInProcessContext::Create(
service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget,
surface->GetSize(), nullptr /* share_context */, attributes,
gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(),
nullptr, nullptr));
gfx::PreferDiscreteGpu, limits, nullptr, nullptr));
context_->GetImplementation()->SetLostContextCallback(base::Bind(
&AwRenderThreadContextProvider::OnLostContext, base::Unretained(this)));
......
......@@ -10,6 +10,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
......@@ -43,7 +44,7 @@ BlimpContextProvider::BlimpContextProvider(
context_.reset(gpu::GLInProcessContext::Create(
nullptr /* service */, nullptr /* surface */, false /* is_offscreen */,
widget, gfx::Size(1, 1), nullptr /* share_context */, attribs_for_gles2,
gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(),
gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
gpu_memory_buffer_manager, nullptr /* memory_limits */));
context_->GetImplementation()->SetLostContextCallback(
base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this)));
......
......@@ -3,6 +3,7 @@ include_rules = [
"+gpu/command_buffer/client/gles2_implementation.h",
"+gpu/command_buffer/client/gles2_interface_stub.h",
"+gpu/command_buffer/client/gles2_lib.h",
"+gpu/command_buffer/client/shared_memory_limits.h",
"+gpu/command_buffer/common/gles2_cmd_utils.h",
"+gpu/command_buffer/service/image_factory.h",
"+gpu/skia_bindings/grcontext_for_gles2_interface.h",
......
......@@ -14,6 +14,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/khronos/GLES2/gl2.h"
......@@ -47,8 +48,7 @@ std::unique_ptr<gpu::GLInProcessContext> CreateTestInProcessContext(
base::WrapUnique(gpu::GLInProcessContext::Create(
nullptr, nullptr, is_offscreen, gfx::kNullAcceleratedWidget,
gfx::Size(1, 1), shared_context, attribs, gpu_preference,
gpu::GLInProcessContextSharedMemoryLimits(),
gpu_memory_buffer_manager, image_factory));
gpu::SharedMemoryLimits(), gpu_memory_buffer_manager, image_factory));
DCHECK(context);
return context;
......
......@@ -28,6 +28,7 @@
#include "content/browser/compositor/gl_helper_scaling.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkTypes.h"
......@@ -67,8 +68,7 @@ class GLHelperTest : public testing::Test {
gfx::kNullAcceleratedWidget, /* window */
gfx::Size(1, 1), /* size */
nullptr, /* share_context */
attributes, gfx::PreferDiscreteGpu,
::gpu::GLInProcessContextSharedMemoryLimits(),
attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
nullptr, /* gpu_memory_buffer_manager */
nullptr /* image_factory */));
gl_ = context_->GetImplementation();
......
......@@ -34,6 +34,7 @@
#include "content/browser/compositor/gl_helper_scaling.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkTypes.h"
......@@ -72,8 +73,7 @@ class GLHelperTest : public testing::Test {
gfx::kNullAcceleratedWidget, /* window */
gfx::Size(1, 1), /* size */
nullptr, /* share_context */
attributes, gfx::PreferDiscreteGpu,
::gpu::GLInProcessContextSharedMemoryLimits(),
attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
nullptr, /* gpu_memory_buffer_manager */
nullptr /* image_factory */));
gl_ = context_->GetImplementation();
......
......@@ -11,6 +11,7 @@
#include "content/browser/compositor/gl_helper.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -45,8 +46,7 @@ class YUVReadbackTest : public testing::Test {
gfx::kNullAcceleratedWidget, /* window */
gfx::Size(1, 1), /* size */
nullptr, /* share_context */
attributes, gfx::PreferDiscreteGpu,
::gpu::GLInProcessContextSharedMemoryLimits(),
attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
nullptr, /* gpu_memory_buffer_manager */
nullptr /* image_factory */));
gl_ = context_->GetImplementation();
......
......@@ -11,6 +11,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_surface.h"
......@@ -37,8 +38,7 @@ class ContextTestBase : public testing::Test {
gfx::kNullAcceleratedWidget, /* window */
gfx::Size(1, 1), /* size */
nullptr, /* share_context */
attributes, gfx::PreferDiscreteGpu,
::gpu::GLInProcessContextSharedMemoryLimits(),
attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
nullptr, /* gpu_memory_buffer_manager */
nullptr /* image_factory */));
gl_ = context_->GetImplementation();
......
......@@ -43,17 +43,11 @@ namespace gpu {
namespace {
const int32_t 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(
const GLInProcessContextSharedMemoryLimits& mem_limits);
GLInProcessContextImpl();
~GLInProcessContextImpl() override;
bool Initialize(scoped_refptr<gfx::GLSurface> surface,
......@@ -64,12 +58,12 @@ class GLInProcessContextImpl
const gpu::gles2::ContextCreationAttribHelper& attribs,
gfx::GpuPreference gpu_preference,
const scoped_refptr<InProcessCommandBuffer::Service>& service,
const SharedMemoryLimits& mem_limits,
GpuMemoryBufferManager* gpu_memory_buffer_manager,
ImageFactory* image_factory);
// GLInProcessContext implementation:
gles2::GLES2Implementation* GetImplementation() override;
size_t GetMappedMemoryLimit() override;
void SetLock(base::Lock* lock) override;
private:
......@@ -81,14 +75,10 @@ class GLInProcessContextImpl
std::unique_ptr<gles2::GLES2Implementation> gles2_implementation_;
std::unique_ptr<InProcessCommandBuffer> command_buffer_;
const GLInProcessContextSharedMemoryLimits mem_limits_;
DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl);
};
GLInProcessContextImpl::GLInProcessContextImpl(
const GLInProcessContextSharedMemoryLimits& mem_limits)
: mem_limits_(mem_limits) {}
GLInProcessContextImpl::GLInProcessContextImpl() = default;
GLInProcessContextImpl::~GLInProcessContextImpl() {
Destroy();
......@@ -98,10 +88,6 @@ gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() {
return gles2_implementation_.get();
}
size_t GLInProcessContextImpl::GetMappedMemoryLimit() {
return mem_limits_.mapped_memory_reclaim_limit;
}
void GLInProcessContextImpl::SetLock(base::Lock* lock) {
NOTREACHED();
}
......@@ -115,6 +101,7 @@ bool GLInProcessContextImpl::Initialize(
const gles2::ContextCreationAttribHelper& attribs,
gfx::GpuPreference gpu_preference,
const scoped_refptr<InProcessCommandBuffer::Service>& service,
const SharedMemoryLimits& mem_limits,
GpuMemoryBufferManager* gpu_memory_buffer_manager,
ImageFactory* image_factory) {
DCHECK(size.width() >= 0 && size.height() >= 0);
......@@ -150,7 +137,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(mem_limits_.command_buffer_size)) {
if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) {
LOG(ERROR) << "Failed to initialize GLES2CmdHelper";
Destroy();
return false;
......@@ -175,10 +162,10 @@ bool GLInProcessContextImpl::Initialize(
command_buffer_.get()));
if (!gles2_implementation_->Initialize(
mem_limits_.start_transfer_buffer_size,
mem_limits_.min_transfer_buffer_size,
mem_limits_.max_transfer_buffer_size,
mem_limits_.mapped_memory_reclaim_limit)) {
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;
}
......@@ -204,13 +191,6 @@ void GLInProcessContextImpl::Destroy() {
} // 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(SharedMemoryLimits::kNoLimit) {}
// static
GLInProcessContext* GLInProcessContext::Create(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
......@@ -221,7 +201,7 @@ GLInProcessContext* GLInProcessContext::Create(
GLInProcessContext* share_context,
const ::gpu::gles2::ContextCreationAttribHelper& attribs,
gfx::GpuPreference gpu_preference,
const GLInProcessContextSharedMemoryLimits& memory_limits,
const SharedMemoryLimits& memory_limits,
GpuMemoryBufferManager* gpu_memory_buffer_manager,
ImageFactory* image_factory) {
if (surface.get()) {
......@@ -230,18 +210,10 @@ GLInProcessContext* GLInProcessContext::Create(
DCHECK_EQ(gfx::kNullAcceleratedWidget, window);
}
std::unique_ptr<GLInProcessContextImpl> context(
new GLInProcessContextImpl(memory_limits));
if (!context->Initialize(surface,
is_offscreen,
share_context,
window,
size,
attribs,
gpu_preference,
service,
gpu_memory_buffer_manager,
image_factory))
std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl);
if (!context->Initialize(surface, is_offscreen, share_context, window, size,
attribs, gpu_preference, service, memory_limits,
gpu_memory_buffer_manager, image_factory))
return NULL;
return context.release();
......
......@@ -28,21 +28,12 @@ class SurfaceTexture;
#endif
namespace gpu {
struct SharedMemoryLimits;
namespace gles2 {
class GLES2Implementation;
}
struct GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContextSharedMemoryLimits {
GLInProcessContextSharedMemoryLimits();
int32_t 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() {}
......@@ -64,7 +55,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
GLInProcessContext* share_context,
const gpu::gles2::ContextCreationAttribHelper& attribs,
gfx::GpuPreference gpu_preference,
const GLInProcessContextSharedMemoryLimits& memory_limits,
const SharedMemoryLimits& memory_limits,
GpuMemoryBufferManager* gpu_memory_buffer_manager,
ImageFactory* image_factory);
......@@ -72,8 +63,6 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
// can be used without making it current.
virtual gles2::GLES2Implementation* GetImplementation() = 0;
virtual size_t GetMappedMemoryLimit() = 0;
virtual void SetLock(base::Lock* lock) = 0;
};
......
......@@ -14,6 +14,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
......@@ -89,8 +90,8 @@ bool InProcessContextProvider::BindToCurrentThread() {
!window_, /* is_offscreen */
window_, gfx::Size(1, 1),
(shared_context_ ? shared_context_->context_.get() : nullptr), attribs_,
gpu_preference, gpu::GLInProcessContextSharedMemoryLimits(),
gpu_memory_buffer_manager_, image_factory_));
gpu_preference, gpu::SharedMemoryLimits(), gpu_memory_buffer_manager_,
image_factory_));
if (!context_)
return false;
......
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