| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "o3d/gpu_plugin/command_buffer.h" | 5 #include "o3d/gpu_plugin/command_buffer.h" |
| 6 | 6 |
| 7 namespace o3d { | 7 namespace o3d { |
| 8 namespace gpu_plugin { | 8 namespace gpu_plugin { |
| 9 | 9 |
| 10 CommandBuffer::CommandBuffer(NPP npp) : npp_(npp) { | 10 CommandBuffer::CommandBuffer(NPP npp) : npp_(npp) { |
| 11 } | 11 } |
| 12 | 12 |
| 13 CommandBuffer::~CommandBuffer() { | 13 CommandBuffer::~CommandBuffer() { |
| 14 if (shared_memory_) { | |
| 15 NPBrowser::get()->UnmapSharedMemory(npp_, shared_memory_); | |
| 16 } | |
| 17 } | 14 } |
| 18 | 15 |
| 19 bool CommandBuffer::Initialize(int32 size) { | 16 bool CommandBuffer::Initialize(int32 size) { |
| 20 if (buffer_object_.Get()) | 17 if (shared_memory_.Get()) |
| 21 return false; | 18 return false; |
| 22 | 19 |
| 23 NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( | 20 NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( |
| 24 NPBrowser::get()->GetWindowNPObject(npp_)); | 21 NPBrowser::get()->GetWindowNPObject(npp_)); |
| 25 if (!window.Get()) | 22 if (!window.Get()) |
| 26 return false; | 23 return false; |
| 27 | 24 |
| 28 NPObjectPointer<NPObject> chromium; | 25 NPObjectPointer<NPObject> chromium; |
| 29 if (!NPGetProperty(npp_, window, "chromium", &chromium)) { | 26 if (!NPGetProperty(npp_, window, "chromium", &chromium)) { |
| 30 return false; | 27 return false; |
| 31 } | 28 } |
| 32 | 29 |
| 33 NPObjectPointer<NPObject> system; | 30 NPObjectPointer<NPObject> system; |
| 34 if (!NPGetProperty(npp_, chromium, "system", &system)) { | 31 if (!NPGetProperty(npp_, chromium, "system", &system)) { |
| 35 return false; | 32 return false; |
| 36 } | 33 } |
| 37 | 34 |
| 35 NPObjectPointer<NPObject> result; |
| 38 if (!NPInvoke(npp_, system, "createSharedMemory", size, | 36 if (!NPInvoke(npp_, system, "createSharedMemory", size, |
| 39 &buffer_object_)) { | 37 &result)) { |
| 40 return false; | 38 return false; |
| 41 } | 39 } |
| 42 | 40 |
| 43 shared_memory_ = NPBrowser::get()->MapSharedMemory( | 41 // TODO(spatrick): validate NPClass before assuming a CHRSHaredMemory is |
| 44 npp_, buffer_object_.Get(), size, false); | 42 // returned. |
| 45 if (!shared_memory_) { | 43 shared_memory_ = NPObjectPointer<CHRSharedMemory>( |
| 46 buffer_object_ = NPObjectPointer<NPObject>(); | 44 static_cast<CHRSharedMemory*>(result.Get())); |
| 45 if (!shared_memory_.Get()) |
| 46 return false; |
| 47 |
| 48 bool mapped; |
| 49 if (!NPInvoke(npp_, shared_memory_, "map", &mapped) || !mapped) { |
| 50 shared_memory_ = NPObjectPointer<CHRSharedMemory>(); |
| 47 return false; | 51 return false; |
| 48 } | 52 } |
| 49 | 53 |
| 50 return true; | 54 return true; |
| 51 } | 55 } |
| 52 | 56 |
| 53 NPObjectPointer<NPObject> CommandBuffer::GetBuffer() { | 57 NPObjectPointer<NPObject> CommandBuffer::GetSharedMemory() { |
| 54 return buffer_object_; | 58 return shared_memory_; |
| 55 } | 59 } |
| 56 | 60 |
| 57 void CommandBuffer::SetPutOffset(int32 offset) { | 61 void CommandBuffer::SetPutOffset(int32 offset) { |
| 58 } | 62 } |
| 59 | 63 |
| 60 int32 CommandBuffer::GetGetOffset() { | 64 int32 CommandBuffer::GetGetOffset() { |
| 61 return 0; | 65 return 0; |
| 62 } | 66 } |
| 63 | 67 |
| 64 } // namespace gpu_plugin | 68 } // namespace gpu_plugin |
| 65 } // namespace o3d | 69 } // namespace o3d |
| OLD | NEW |