summaryrefslogtreecommitdiffstats
path: root/o3d/gpu_plugin/command_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'o3d/gpu_plugin/command_buffer.cc')
-rw-r--r--o3d/gpu_plugin/command_buffer.cc58
1 files changed, 25 insertions, 33 deletions
diff --git a/o3d/gpu_plugin/command_buffer.cc b/o3d/gpu_plugin/command_buffer.cc
index c24e655..15f52da 100644
--- a/o3d/gpu_plugin/command_buffer.cc
+++ b/o3d/gpu_plugin/command_buffer.cc
@@ -4,6 +4,8 @@
#include "o3d/gpu_plugin/command_buffer.h"
+using ::base::SharedMemory;
+
namespace gpu_plugin {
CommandBuffer::CommandBuffer(NPP npp)
@@ -15,35 +17,28 @@ CommandBuffer::CommandBuffer(NPP npp)
parse_error_(0),
error_status_(false) {
// Element zero is always NULL.
- registered_objects_.push_back(NPObjectPointer<NPObject>());
+ registered_objects_.push_back(linked_ptr<SharedMemory>());
}
CommandBuffer::~CommandBuffer() {
}
-bool CommandBuffer::Initialize(NPObjectPointer<NPObject> ring_buffer) {
- // Fail if already initialized.
- if (ring_buffer_.Get())
- return false;
-
- if (!ring_buffer.Get())
- return false;
+bool CommandBuffer::Initialize(::base::SharedMemory* ring_buffer) {
+ DCHECK(ring_buffer);
- int32 size_in_bytes;
- if (!NPInvoke(npp_, ring_buffer, "getSize", &size_in_bytes))
- return false;
-
- if (size_in_bytes < 0)
+ // Fail if already initialized.
+ if (ring_buffer_.get())
return false;
+ size_t size_in_bytes = ring_buffer->max_size();
size_ = size_in_bytes / sizeof(int32);
- ring_buffer_ = ring_buffer;
+ ring_buffer_.reset(ring_buffer);
return true;
}
-NPObjectPointer<NPObject> CommandBuffer::GetRingBuffer() {
- return ring_buffer_;
+SharedMemory* CommandBuffer::GetRingBuffer() {
+ return ring_buffer_.get();
}
int32 CommandBuffer::GetSize() {
@@ -80,9 +75,10 @@ void CommandBuffer::SetPutOffsetChangeCallback(Callback0::Type* callback) {
put_offset_change_callback_.reset(callback);
}
-int32 CommandBuffer::RegisterObject(NPObjectPointer<NPObject> object) {
- if (!object.Get())
- return 0;
+int32 CommandBuffer::CreateTransferBuffer(size_t size) {
+ linked_ptr<SharedMemory> buffer(new SharedMemory);
+ if (!buffer->Create(std::wstring(), false, false, size))
+ return -1;
if (unused_registered_object_elements_.empty()) {
// Check we haven't exceeded the range that fits in a 32-bit integer.
@@ -90,50 +86,46 @@ int32 CommandBuffer::RegisterObject(NPObjectPointer<NPObject> object) {
if (handle != registered_objects_.size())
return -1;
- registered_objects_.push_back(object);
+ registered_objects_.push_back(buffer);
return handle;
}
int32 handle = *unused_registered_object_elements_.begin();
unused_registered_object_elements_.erase(
unused_registered_object_elements_.begin());
- DCHECK(!registered_objects_[handle].Get());
- registered_objects_[handle] = object;
+ DCHECK(!registered_objects_[handle].get());
+ registered_objects_[handle] = buffer;
return handle;
}
-void CommandBuffer::UnregisterObject(NPObjectPointer<NPObject> object,
- int32 handle) {
+void CommandBuffer::DestroyTransferBuffer(int32 handle) {
if (handle <= 0)
return;
if (static_cast<size_t>(handle) >= registered_objects_.size())
return;
- if (registered_objects_[handle] != object)
- return;
-
- registered_objects_[handle] = NPObjectPointer<NPObject>();
+ registered_objects_[handle].reset();
unused_registered_object_elements_.insert(handle);
// Remove all null objects from the end of the vector. This allows the vector
// to shrink when, for example, all objects are unregistered. Note that this
// loop never removes element zero, which is always NULL.
- while (registered_objects_.size() > 1 && !registered_objects_.back().Get()) {
+ while (registered_objects_.size() > 1 && !registered_objects_.back().get()) {
registered_objects_.pop_back();
unused_registered_object_elements_.erase(
static_cast<int32>(registered_objects_.size()));
}
}
-NPObjectPointer<NPObject> CommandBuffer::GetRegisteredObject(int32 handle) {
+::base::SharedMemory* CommandBuffer::GetTransferBuffer(int32 handle) {
if (handle < 0)
- return NPObjectPointer<NPObject>();
+ return NULL;
if (static_cast<size_t>(handle) >= registered_objects_.size())
- return NPObjectPointer<NPObject>();
+ return NULL;
- return registered_objects_[handle];
+ return registered_objects_[handle].get();
}
int32 CommandBuffer::ResetParseError() {