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

Unified Diff: mojo/gles2/command_buffer_client_impl.cc

Issue 221453007: mojo/gpu: use SharedBuffer instead of base::SharedMemory with hacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix missing include Created 6 years, 9 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
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.h ('k') | mojo/mojo_services.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/gles2/command_buffer_client_impl.cc
diff --git a/mojo/gles2/command_buffer_client_impl.cc b/mojo/gles2/command_buffer_client_impl.cc
index 3ffecf3d02ff959ad860c1c9dd171b0fde540035..a08f1b9cc29ffb3052ac540240bc09e0411ea444 100644
--- a/mojo/gles2/command_buffer_client_impl.cc
+++ b/mojo/gles2/command_buffer_client_impl.cc
@@ -11,10 +11,37 @@
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/bindings/sync_dispatcher.h"
#include "mojo/services/gles2/command_buffer_type_conversions.h"
+#include "mojo/services/gles2/mojo_buffer_backing.h"
namespace mojo {
namespace gles2 {
+namespace {
+
+bool CreateMapAndDupSharedBuffer(size_t size,
+ void** memory,
+ mojo::ScopedSharedBufferHandle* handle,
+ mojo::ScopedSharedBufferHandle* duped) {
+ MojoResult result = mojo::CreateSharedBuffer(NULL, size, handle);
+ if (result != MOJO_RESULT_OK)
+ return false;
+ DCHECK(handle->is_valid());
+
+ result = mojo::DuplicateBuffer(handle->get(), NULL, duped);
+ if (result != MOJO_RESULT_OK)
+ return false;
+ DCHECK(duped->is_valid());
+
+ result = mojo::MapBuffer(
+ handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE);
+ if (result != MOJO_RESULT_OK)
+ return false;
+ DCHECK(*memory);
+
+ return true;
+}
+}
+
CommandBufferDelegate::~CommandBufferDelegate() {}
void CommandBufferDelegate::ContextLost() {}
@@ -26,6 +53,7 @@ CommandBufferClientImpl::CommandBufferClientImpl(
ScopedCommandBufferHandle command_buffer_handle)
: delegate_(delegate),
command_buffer_(command_buffer_handle.Pass(), this, this, async_waiter),
+ shared_state_(NULL),
last_put_offset_(-1),
next_transfer_buffer_id_(0),
initialize_result_(false) {}
@@ -33,15 +61,15 @@ CommandBufferClientImpl::CommandBufferClientImpl(
CommandBufferClientImpl::~CommandBufferClientImpl() {}
bool CommandBufferClientImpl::Initialize() {
- shared_state_shm_.reset(new base::SharedMemory);
- if (!shared_state_shm_->CreateAndMapAnonymous(
- sizeof(gpu::CommandBufferSharedState)))
+ const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState);
+ void* memory = NULL;
+ mojo::ScopedSharedBufferHandle duped;
+ bool result = CreateMapAndDupSharedBuffer(
+ kSharedStateSize, &memory, &shared_state_handle_, &duped);
+ if (!result)
return false;
- base::SharedMemoryHandle handle;
- shared_state_shm_->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
- if (!base::SharedMemory::IsHandleValid(handle))
- return false;
+ shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory);
shared_state()->Initialize();
@@ -49,7 +77,7 @@ bool CommandBufferClientImpl::Initialize() {
sync_dispatcher_.reset(new SyncDispatcher<CommandBufferSyncClient>(
sync_pipe.handle_to_peer.Pass(), this));
AllocationScope scope;
- command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), handle);
+ command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), duped.Pass());
// Wait for DidInitialize to come on the sync client pipe.
if (!sync_dispatcher_->WaitAndDispatchOneMessage()) {
VLOG(1) << "Channel encountered error while creating command buffer";
@@ -109,23 +137,21 @@ scoped_refptr<gpu::Buffer> CommandBufferClientImpl::CreateTransferBuffer(
if (size >= std::numeric_limits<uint32_t>::max())
return NULL;
- scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
- if (!shared_memory->CreateAndMapAnonymous(size))
- return NULL;
-
- base::SharedMemoryHandle handle;
- shared_memory->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
- if (!base::SharedMemory::IsHandleValid(handle))
+ void* memory = NULL;
+ mojo::ScopedSharedBufferHandle handle;
+ mojo::ScopedSharedBufferHandle duped;
+ if (!CreateMapAndDupSharedBuffer(size, &memory, &handle, &duped))
return NULL;
*id = ++next_transfer_buffer_id_;
AllocationScope scope;
command_buffer_->RegisterTransferBuffer(
- *id, handle, static_cast<uint32_t>(size));
+ *id, duped.Pass(), static_cast<uint32_t>(size));
- scoped_refptr<gpu::Buffer> buffer =
- gpu::MakeBufferFromSharedMemory(shared_memory.Pass(), size);
+ scoped_ptr<gpu::BufferBacking> backing(
+ new MojoBufferBacking(handle.Pass(), memory, size));
+ scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(backing.Pass()));
return buffer;
}
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.h ('k') | mojo/mojo_services.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698