From 2331a49ecb27f38888bf4f60f24e054cbb8a8890 Mon Sep 17 00:00:00 2001 From: "apatrick@google.com" Date: Thu, 24 Sep 2009 19:19:25 +0000 Subject: GPUProcessor uses O3D command buffer service to render to a window. Added libraries that contain a subset of the O3D command buffer code independent on NaCl. Extracted Upcall interface from CommandBufferEngine. Now this works in JavaScript to clear the GPU plugin element to a random color: // BEGIN_FRAME sharedMemory.setInt32(putOffset++, 0x00000201); // CLEAR sharedMemory.setInt32(putOffset++, 0x00000408); sharedMemory.setInt32(putOffset++, 7); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, Math.random()); sharedMemory.setFloat(putOffset++, 1); sharedMemory.setFloat(putOffset++, 0.5); sharedMemory.setInt32(putOffset++, 0); // END_FRAME sharedMemory.setInt32(putOffset++, 0x00000301); TEST=none BUG=none Review URL: http://codereview.chromium.org/234001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27098 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/gpu_plugin/command_buffer.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'o3d/gpu_plugin/command_buffer.cc') diff --git a/o3d/gpu_plugin/command_buffer.cc b/o3d/gpu_plugin/command_buffer.cc index 04b1f41..c499866 100644 --- a/o3d/gpu_plugin/command_buffer.cc +++ b/o3d/gpu_plugin/command_buffer.cc @@ -13,7 +13,8 @@ CommandBuffer::CommandBuffer(NPP npp) get_offset_(0), put_offset_(0), token_(0), - error_(ERROR_NO_ERROR) { + parse_error_(0), + error_status_(false) { // Element zero is always NULL. registered_objects_.push_back(NPObjectPointer()); } @@ -22,6 +23,12 @@ CommandBuffer::~CommandBuffer() { } bool CommandBuffer::Initialize(int32 size) { + // Check the size will not overflow when it is converted from count of int32s + // to count of bytes. + int32 num_bytes = static_cast(size * sizeof(int32)); + if (num_bytes / sizeof(int32) != size) + return false; + if (shared_memory_.Get()) return false; @@ -41,7 +48,7 @@ bool CommandBuffer::Initialize(int32 size) { } NPObjectPointer result; - if (!NPInvoke(npp_, system, "createSharedMemory", size, + if (!NPInvoke(npp_, system, "createSharedMemory", num_bytes, &result)) { return false; } @@ -148,15 +155,18 @@ void CommandBuffer::UnregisterObject(NPObjectPointer object, } NPObjectPointer CommandBuffer::GetRegisteredObject(int32 handle) { - DCHECK_GE(handle, 0); - DCHECK_LT(static_cast(handle), registered_objects_.size()); + if (handle < 0) + return NPObjectPointer(); + + if (static_cast(handle) >= registered_objects_.size()) + return NPObjectPointer(); return registered_objects_[handle]; } -int32 CommandBuffer::ResetError() { - int32 last_error = error_; - error_ = ERROR_NO_ERROR; +int32 CommandBuffer::ResetParseError() { + int32 last_error = parse_error_; + parse_error_ = 0; return last_error; } -- cgit v1.1