diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-28 23:36:54 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-28 23:36:54 +0000 |
commit | 36dbfe198cb0eab50ff4a7300fc86b8314d30cde (patch) | |
tree | c7b2271be2e885ca87ac58d53e338cca322276a4 /gpu/command_buffer/service/command_buffer_service.cc | |
parent | 406e6e22b82ef80e8bc44f45d85efa68799bc552 (diff) | |
download | chromium_src-36dbfe198cb0eab50ff4a7300fc86b8314d30cde.zip chromium_src-36dbfe198cb0eab50ff4a7300fc86b8314d30cde.tar.gz chromium_src-36dbfe198cb0eab50ff4a7300fc86b8314d30cde.tar.bz2 |
Moved creation of GPU command buffer shared memory into the browser process.
This is to allow the GPU process to be sandboxed on all platforms.
TEST=try, run WebGL app on win and mac.
BUG=none
Review URL: http://codereview.chromium.org/6588029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/service/command_buffer_service.cc')
-rw-r--r-- | gpu/command_buffer/service/command_buffer_service.cc | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/gpu/command_buffer/service/command_buffer_service.cc b/gpu/command_buffer/service/command_buffer_service.cc index d806de1..adc5623 100644 --- a/gpu/command_buffer/service/command_buffer_service.cc +++ b/gpu/command_buffer/service/command_buffer_service.cc @@ -25,6 +25,8 @@ CommandBufferService::CommandBufferService() } CommandBufferService::~CommandBufferService() { + delete ring_buffer_.shared_memory; + for (size_t i = 0; i < registered_objects_.size(); ++i) { if (registered_objects_[i].shared_memory) delete registered_objects_[i].shared_memory; @@ -33,42 +35,59 @@ CommandBufferService::~CommandBufferService() { bool CommandBufferService::Initialize(int32 size) { // Fail if already initialized. - if (ring_buffer_.get()) { - LOG(ERROR) << "CommandBufferService::Initialize " - << "failed because already initialized."; + if (ring_buffer_.shared_memory) { + LOG(ERROR) << "Failed because already initialized."; return false; } if (size <= 0 || size > kMaxCommandBufferSize) { - LOG(ERROR) << "CommandBufferService::Initialize " - << "because command buffer size was invalid."; + LOG(ERROR) << "Failed because command buffer size was invalid."; return false; } num_entries_ = size / sizeof(CommandBufferEntry); - ring_buffer_.reset(new SharedMemory); - if (ring_buffer_->CreateAndMapAnonymous(size)) { + SharedMemory shared_memory; + if (!shared_memory.CreateAnonymous(size)) { + LOG(ERROR) << "Failed to create shared memory for command buffer."; return true; } - num_entries_ = 0; - ring_buffer_.reset(); + return Initialize(&shared_memory, size); +} - LOG(ERROR) << "CommandBufferService::Initialize failed because ring buffer " - << "could not be created or mapped "; +bool CommandBufferService::Initialize(base::SharedMemory* buffer, int32 size) { + // Fail if already initialized. + if (ring_buffer_.shared_memory) { + LOG(ERROR) << "Failed because already initialized."; + return false; + } + + base::SharedMemoryHandle shared_memory_handle; + if (!buffer->ShareToProcess(base::GetCurrentProcessHandle(), + &shared_memory_handle)) { + LOG(ERROR) << "Failed to duplicate command buffer shared memory handle."; + return false; + } - return false; + ring_buffer_.shared_memory = new base::SharedMemory(shared_memory_handle, + false); + if (!ring_buffer_.shared_memory->Map(size)) { + LOG(ERROR) << "Failed because ring buffer could not be created or mapped "; + delete ring_buffer_.shared_memory; + ring_buffer_.shared_memory = NULL; + return false; + } + + ring_buffer_.ptr = ring_buffer_.shared_memory->memory(); + ring_buffer_.size = size; + num_entries_ = size / sizeof(CommandBufferEntry); + + return true; } Buffer CommandBufferService::GetRingBuffer() { - Buffer buffer; - if (ring_buffer_.get()) { - buffer.ptr = ring_buffer_->memory(); - buffer.size = ring_buffer_->created_size(); - buffer.shared_memory = ring_buffer_.get(); - } - return buffer; + return ring_buffer_; } CommandBufferService::State CommandBufferService::GetState() { |