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

Unified Diff: o3d/gpu_plugin/command_buffer.cc

Issue 216043: Added support for registering additional shared memory objects (textures and ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | « o3d/gpu_plugin/command_buffer.h ('k') | o3d/gpu_plugin/command_buffer_mock.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: o3d/gpu_plugin/command_buffer.cc
===================================================================
--- o3d/gpu_plugin/command_buffer.cc (revision 26762)
+++ o3d/gpu_plugin/command_buffer.cc (working copy)
@@ -12,6 +12,8 @@
size_(0),
get_offset_(0),
put_offset_(0) {
+ // Element zero is always NULL.
+ registered_objects_.push_back(NPObjectPointer<NPObject>());
}
CommandBuffer::~CommandBuffer() {
@@ -97,5 +99,59 @@
put_offset_change_callback_.reset(callback);
}
+int32 CommandBuffer::RegisterObject(NPObjectPointer<NPObject> object) {
+ if (!object.Get())
+ return 0;
+
+ if (unused_registered_object_elements_.empty()) {
+ // Check we haven't exceeded the range that fits in the range of a 32-bit
+ // integer.
+ int32 handle = static_cast<int32>(registered_objects_.size());
+ if (handle != registered_objects_.size())
+ return -1;
+
+ registered_objects_.push_back(object);
+ 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;
+ return handle;
+}
+
+void CommandBuffer::UnregisterObject(NPObjectPointer<NPObject> object,
+ 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>();
+ 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()) {
+ registered_objects_.pop_back();
+ unused_registered_object_elements_.erase(
+ static_cast<int32>(registered_objects_.size()));
+ }
+}
+
+NPObjectPointer<NPObject> CommandBuffer::GetRegisteredObject(int32 handle) {
+ DCHECK_GE(handle, 0);
+ DCHECK_LT(static_cast<size_t>(handle), registered_objects_.size());
+
+ return registered_objects_[handle];
+}
+
} // namespace gpu_plugin
} // namespace o3d
« no previous file with comments | « o3d/gpu_plugin/command_buffer.h ('k') | o3d/gpu_plugin/command_buffer_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698