Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1186)

Unified Diff: gpu/command_buffer/client/gl_in_process_context.cc

Issue 20017005: gpu: Refactor GpuMemoryBuffer framework for multi-process support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/gl_in_process_context.cc
diff --git a/gpu/command_buffer/client/gl_in_process_context.cc b/gpu/command_buffer/client/gl_in_process_context.cc
index 52e8d22b27bc8e261e6e17da1531858c84f19420..43cb8212404e6a632ae1ff5ae6e284697d9e749d 100644
--- a/gpu/command_buffer/client/gl_in_process_context.cc
+++ b/gpu/command_buffer/client/gl_in_process_context.cc
@@ -24,11 +24,8 @@
#include "base/message_loop/message_loop.h"
#include "base/synchronization/lock.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
-#include "gpu/command_buffer/client/gpu_memory_buffer.h"
-#include "gpu/command_buffer/client/image_factory.h"
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/common/constants.h"
-#include "gpu/command_buffer/common/id_allocator.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/gl_context_virtual.h"
@@ -43,8 +40,6 @@
namespace gpu {
-using gles2::ImageManager;
-
namespace {
const int32 kCommandBufferSize = 1024 * 1024;
@@ -70,8 +65,7 @@ static base::LazyInstance<
static bool g_use_virtualized_gl_context = false;
-static GLInProcessContext::GpuMemoryBufferCreator* g_gpu_memory_buffer_creator =
- NULL;
+static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL;
// Also calls DetachFromThreadHack on all GLES2Decoders before the lock is
// released to maintain the invariant that all decoders are unbound while the
@@ -92,7 +86,6 @@ class AutoLockAndDecoderDetachThread {
class GLInProcessContextImpl
: public GLInProcessContext,
- public gles2::ImageFactory,
public base::SupportsWeakPtr<GLInProcessContextImpl> {
public:
explicit GLInProcessContextImpl(bool share_resources);
@@ -113,12 +106,6 @@ class GLInProcessContextImpl
OVERRIDE;
virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE;
- // ImageFactory implementation:
- virtual scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBuffer(
- int width, int height, GLenum internalformat,
- unsigned* image_id) OVERRIDE;
- virtual void DeleteGpuMemoryBuffer(unsigned image_id) OVERRIDE;
-
// Other methods:
gles2::GLES2Decoder* GetDecoder();
bool GetBufferChanged(int32 transfer_buffer_id);
@@ -133,10 +120,9 @@ class GLInProcessContextImpl
void CallQueryCallback(size_t index);
bool MakeCurrent();
- gles2::ImageManager* GetImageManager();
-
base::Closure context_lost_callback_;
scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
+ scoped_refptr<gles2::ImageManager> image_manager_;
scoped_ptr<CommandBuffer> command_buffer_;
scoped_ptr<GpuScheduler> gpu_scheduler_;
scoped_ptr<gles2::GLES2Decoder> decoder_;
@@ -174,40 +160,6 @@ AutoLockAndDecoderDetachThread::~AutoLockAndDecoderDetachThread() {
&DetachThread);
}
-scoped_ptr<GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer(
- int width, int height, GLenum internalformat, unsigned int* image_id) {
- // We're taking the lock here because we're accessing the ContextGroup's
- // shared IdManager.
- AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(),
- g_all_shared_contexts.Get());
- // For Android WebView we assume the |internalformat| will always be
- // GL_RGBA8_OES.
- DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
- scoped_ptr<GpuMemoryBuffer> buffer =
- g_gpu_memory_buffer_creator(width, height);
-
- if (buffer.get() == NULL)
- return buffer.Pass();
-
- scoped_refptr<gfx::GLImage> gl_image =
- gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(),
- gfx::Size(width, height));
- *image_id = decoder_->GetContextGroup()
- ->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID();
- GetImageManager()->AddImage(gl_image.get(), *image_id);
- return buffer.Pass();
-}
-
-void GLInProcessContextImpl::DeleteGpuMemoryBuffer(unsigned int image_id) {
- // We're taking the lock here because we're accessing the ContextGroup's
- // shared ImageManager.
- AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(),
- g_all_shared_contexts.Get());
- GetImageManager()->RemoveImage(image_id);
- decoder_->GetContextGroup()->GetIdAllocator(gles2::id_namespaces::kImages)
- ->FreeID(image_id);
-}
-
GLInProcessContextImpl::GLInProcessContextImpl(bool share_resources)
: share_resources_(share_resources),
context_lost_(false) {
@@ -278,10 +230,6 @@ gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() {
return gles2_implementation_.get();
}
-gles2::ImageManager* GLInProcessContextImpl::GetImageManager() {
- return decoder_->GetContextGroup()->image_manager();
-}
-
bool GLInProcessContextImpl::Initialize(
bool is_offscreen,
gfx::AcceleratedWidget window,
@@ -329,8 +277,12 @@ bool GLInProcessContextImpl::Initialize(
manager->Initialize();
}
+ image_manager_ = new gles2::ImageManager();
+
scoped_ptr<CommandBufferService> command_buffer(
- new CommandBufferService(transfer_buffer_manager_.get()));
+ new CommandBufferService(transfer_buffer_manager_.get(),
+ image_manager_.get(),
+ g_gpu_memory_buffer_factory));
command_buffer->SetPutOffsetChangeCallback(base::Bind(
&GLInProcessContextImpl::PumpCommands, base::Unretained(this)));
command_buffer->SetGetBufferChangeCallback(base::Bind(
@@ -458,8 +410,7 @@ bool GLInProcessContextImpl::Initialize(
context_group ? context_group->GetImplementation()->share_group() : NULL,
transfer_buffer_.get(),
true,
- false,
- this));
+ false));
if (!gles2_implementation_->Initialize(
kStartTransferBufferSize,
@@ -594,9 +545,16 @@ GLInProcessContext* GLInProcessContext::CreateContext(
}
// static
-void GLInProcessContext::SetGpuMemoryBufferCreator(
- GpuMemoryBufferCreator* creator) {
- g_gpu_memory_buffer_creator = creator;
+void GLInProcessContext::SetGpuMemoryBufferFactory(
+ GpuMemoryBufferFactory* factory) {
+#if !defined(NDEBUG)
+ {
+ AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(),
+ g_all_shared_contexts.Get());
+ DCHECK(g_all_shared_contexts.Get().empty());
+ }
+#endif // !defined(NDEBUG)
+ g_gpu_memory_buffer_factory = factory;
}
// static

Powered by Google App Engine
This is Rietveld 408576698