diff options
Diffstat (limited to 'o3d')
50 files changed, 695 insertions, 781 deletions
@@ -1,6 +1,6 @@ vars = { "chromium_trunk": "http://src.chromium.org/svn/trunk", - "nixysa_rev": "56", + "nixysa_rev": "61", "chromium_rev": "28829", "o3d_code_rev": "161", "skia_rev": "376", diff --git a/o3d/build/common.gypi b/o3d/build/common.gypi index 383240e..ea2c179 100644 --- a/o3d/build/common.gypi +++ b/o3d/build/common.gypi @@ -245,5 +245,14 @@ }, }, ], + ['cb_service == "remote"', + { + 'target_defaults': { + 'defines': [ + 'CB_SERVICE_REMOTE', + ], + }, + }, + ], ], } diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper.cc b/o3d/command_buffer/client/cross/cmd_buffer_helper.cc index 47aa871..39f06ba 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper.cc +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper.cc @@ -37,13 +37,14 @@ namespace command_buffer { +using gpu_plugin::CommandBuffer; using gpu_plugin::NPBrowser; using gpu_plugin::NPInvoke; using gpu_plugin::NPObjectPointer; CommandBufferHelper::CommandBufferHelper( NPP npp, - const NPObjectPointer<NPObject>& command_buffer) + const NPObjectPointer<CommandBuffer>& command_buffer) : npp_(npp), command_buffer_(command_buffer), entries_(NULL), @@ -55,36 +56,19 @@ CommandBufferHelper::CommandBufferHelper( } bool CommandBufferHelper::Initialize() { - // Get the ring buffer from the GPU process. - if (!NPInvoke(npp_, command_buffer_, "getRingBuffer", &ring_buffer_) || - !ring_buffer_.Get()) { + ring_buffer_ = command_buffer_->GetRingBuffer(); + if (!ring_buffer_) return false; - } // Map the ring buffer into this process. - size_t size_bytes; - entries_ = static_cast<CommandBufferEntry*>( - NPBrowser::get()->MapMemory(npp_, ring_buffer_.Get(), &size_bytes)); - - // Get the command buffer size. - if (!NPInvoke(npp_, command_buffer_, "getSize", &entry_count_)) { + if (!ring_buffer_->Map(ring_buffer_->max_size())) return false; - } - // Get the initial get offset. - if (!NPInvoke(npp_, command_buffer_, "getGetOffset", &get_)) { - return false; - } - - // Get the initial put offset. - if (!NPInvoke(npp_, command_buffer_, "getPutOffset", &put_)) { - return false; - } - - // Get the last token. - if (!NPInvoke(npp_, command_buffer_, "getToken", &last_token_read_)) { - return false; - } + entries_ = static_cast<CommandBufferEntry*>(ring_buffer_->memory()); + entry_count_ = command_buffer_->GetSize(); + get_ = command_buffer_->GetGetOffset(); + put_ = command_buffer_->GetPutOffset(); + last_token_read_ = command_buffer_->GetToken(); return true; } @@ -93,8 +77,8 @@ CommandBufferHelper::~CommandBufferHelper() { } bool CommandBufferHelper::Flush() { - // If this fails it means the command buffer reader has been shutdown. - return NPInvoke(npp_, command_buffer_, "syncOffsets", put_, &get_); + get_ = command_buffer_->SyncOffsets(put_); + return !command_buffer_->GetErrorStatus(); } // Calls Flush() and then waits until the buffer is empty. Break early if the @@ -125,8 +109,7 @@ int32 CommandBufferHelper::InsertToken() { if (token_ == 0) { // we wrapped Finish(); - if (!NPInvoke(npp_, command_buffer_, "getToken", &last_token_read_)) - return -1; + last_token_read_ = command_buffer_->GetToken(); DCHECK_EQ(token_, last_token_read_); } return token_; @@ -141,8 +124,7 @@ void CommandBufferHelper::WaitForToken(int32 token) { if (last_token_read_ >= token) return; // fast path. if (token > token_) return; // we wrapped Flush(); - if (!NPInvoke(npp_, command_buffer_, "getToken", &last_token_read_)) - return; + last_token_read_ = command_buffer_->GetToken(); while (last_token_read_ < token) { if (get_ == put_) { LOG(FATAL) << "Empty command buffer while waiting on a token."; @@ -152,8 +134,7 @@ void CommandBufferHelper::WaitForToken(int32 token) { // has shutdown. if (!Flush()) return; - if (!NPInvoke(npp_, command_buffer_, "getToken", &last_token_read_)) - return; + last_token_read_ = command_buffer_->GetToken(); } } @@ -209,8 +190,7 @@ CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) { } parse_error::ParseError CommandBufferHelper::GetParseError() { - int32 parse_error; - DCHECK(NPInvoke(npp_, command_buffer_, "resetParseError", &parse_error)); + int32 parse_error = command_buffer_->ResetParseError(); return static_cast<parse_error::ParseError>(parse_error); } diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper.h b/o3d/command_buffer/client/cross/cmd_buffer_helper.h index 171b31f..8ee23d5 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper.h +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper.h @@ -38,6 +38,7 @@ #include "command_buffer/common/cross/logging.h" #include "command_buffer/common/cross/constants.h" #include "command_buffer/common/cross/cmd_buffer_common.h" +#include "o3d/gpu_plugin/command_buffer.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" namespace command_buffer { @@ -61,7 +62,8 @@ class CommandBufferHelper { public: CommandBufferHelper( NPP npp, - const gpu_plugin::NPObjectPointer<NPObject>& command_buffer); + const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>& + command_buffer); virtual ~CommandBufferHelper(); bool Initialize(); @@ -192,8 +194,8 @@ class CommandBufferHelper { } NPP npp_; - gpu_plugin::NPObjectPointer<NPObject> command_buffer_; - gpu_plugin::NPObjectPointer<NPObject> ring_buffer_; + gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; + ::base::SharedMemory* ring_buffer_; CommandBufferEntry *entries_; int32 entry_count_; int32 token_; diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc b/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc index 9001935..cb41668 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc @@ -39,7 +39,6 @@ #include "gpu_plugin/command_buffer.h" #include "gpu_plugin/gpu_processor.h" #include "gpu_plugin/np_utils/np_object_pointer.h" -#include "gpu_plugin/system_services/shared_memory.h" namespace command_buffer { @@ -70,17 +69,14 @@ class CommandBufferHelperTest : public testing::Test { EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) .WillRepeatedly(Return(parse_error::kParseNoError)); - NPObjectPointer<gpu_plugin::SharedMemory> ring_buffer = - NPCreateObject<gpu_plugin::SharedMemory>(NULL); - ring_buffer->Initialize(kCommandBufferSizeBytes); - - size_t size_bytes; - void* buffer = NPN_MapMemory(NULL, ring_buffer.Get(), &size_bytes); + ::base::SharedMemory* ring_buffer = new ::base::SharedMemory; + ring_buffer->Create(std::wstring(), false, false, kCommandBufferSizeBytes); + ring_buffer->Map(1024); command_buffer_ = NPCreateObject<CommandBuffer>(NULL); command_buffer_->Initialize(ring_buffer); - parser_ = new command_buffer::CommandParser(buffer, + parser_ = new command_buffer::CommandParser(ring_buffer->memory(), kCommandBufferSizeBytes, 0, kCommandBufferSizeBytes, diff --git a/o3d/command_buffer/client/cross/fenced_allocator_test.cc b/o3d/command_buffer/client/cross/fenced_allocator_test.cc index b74bb6e..5d629da 100644 --- a/o3d/command_buffer/client/cross/fenced_allocator_test.cc +++ b/o3d/command_buffer/client/cross/fenced_allocator_test.cc @@ -41,7 +41,6 @@ #include "gpu_plugin/command_buffer.h" #include "gpu_plugin/gpu_processor.h" #include "gpu_plugin/np_utils/np_object_pointer.h" -#include "gpu_plugin/system_services/shared_memory.h" namespace command_buffer { @@ -72,17 +71,14 @@ class BaseFencedAllocatorTest : public testing::Test { .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), Return(parse_error::kParseNoError))); - NPObjectPointer<gpu_plugin::SharedMemory> ring_buffer = - NPCreateObject<gpu_plugin::SharedMemory>(NULL); - ring_buffer->Initialize(1024); - - size_t size_bytes; - void* buffer = NPN_MapMemory(NULL, ring_buffer.Get(), &size_bytes); + ::base::SharedMemory* ring_buffer = new ::base::SharedMemory; + ring_buffer->Create(std::wstring(), false, false, 1024); + ring_buffer->Map(1024); command_buffer_ = NPCreateObject<CommandBuffer>(NULL); command_buffer_->Initialize(ring_buffer); - parser_ = new command_buffer::CommandParser(buffer, + parser_ = new command_buffer::CommandParser(ring_buffer->memory(), kBufferSize, 0, kBufferSize, diff --git a/o3d/command_buffer/client/cross/o3d_cmd_helper.h b/o3d/command_buffer/client/cross/o3d_cmd_helper.h index 8e960ef..a42d89b 100644 --- a/o3d/command_buffer/client/cross/o3d_cmd_helper.h +++ b/o3d/command_buffer/client/cross/o3d_cmd_helper.h @@ -48,7 +48,8 @@ class O3DCmdHelper : public CommandBufferHelper { public: O3DCmdHelper( NPP npp, - const gpu_plugin::NPObjectPointer<NPObject>& command_buffer) + const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>& + command_buffer) : CommandBufferHelper(npp, command_buffer) { } virtual ~O3DCmdHelper() { diff --git a/o3d/core/core.gyp b/o3d/core/core.gyp index fe72c17..cd2a8d9 100644 --- a/o3d/core/core.gyp +++ b/o3d/core/core.gyp @@ -399,12 +399,6 @@ { 'dependencies': [ '../command_buffer/command_buffer.gyp:command_buffer_client', - '../command_buffer/command_buffer.gyp:command_buffer_service', - '../gpu_plugin/gpu_plugin.gyp:np_utils', - - # These dependencies is only needed for RendererCBLocal. They can - # be removed when RendererCBLocal is not needed. - '../gpu_plugin/gpu_plugin.gyp:command_buffer', '../gpu_plugin/gpu_plugin.gyp:np_utils', ], 'sources': [ @@ -433,6 +427,17 @@ ], }, ], + ['renderer == "cb" and cb_service != "remote"', + { + 'dependencies': [ + '../command_buffer/command_buffer.gyp:command_buffer_service', + + # These dependencies are only needed for RendererCBLocal. They can + # be removed when RendererCBLocal is not needed. + '../gpu_plugin/gpu_plugin.gyp:command_buffer', + ], + }, + ], ], }, { diff --git a/o3d/core/cross/command_buffer/display_window_cb.h b/o3d/core/cross/command_buffer/display_window_cb.h index 52cd08a..06b494e 100644 --- a/o3d/core/cross/command_buffer/display_window_cb.h +++ b/o3d/core/cross/command_buffer/display_window_cb.h @@ -34,6 +34,7 @@ #define O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_ #include "core/cross/display_window.h" +#include "gpu_plugin/command_buffer.h" #include "gpu_plugin/np_utils/np_object_pointer.h" namespace o3d { @@ -53,12 +54,14 @@ class DisplayWindowCB : public DisplayWindow { npp_ = npp; } - gpu_plugin::NPObjectPointer<NPObject> command_buffer() const { + gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> + command_buffer() const { return command_buffer_; } void set_command_buffer( - const gpu_plugin::NPObjectPointer<NPObject> command_buffer) { + const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> + command_buffer) { command_buffer_ = command_buffer; } @@ -80,7 +83,7 @@ class DisplayWindowCB : public DisplayWindow { private: NPP npp_; - gpu_plugin::NPObjectPointer<NPObject> command_buffer_; + gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; int width_; int height_; DISALLOW_COPY_AND_ASSIGN(DisplayWindowCB); diff --git a/o3d/core/cross/command_buffer/renderer_cb.cc b/o3d/core/cross/command_buffer/renderer_cb.cc index 5d0dcd58..e964672 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.cc +++ b/o3d/core/cross/command_buffer/renderer_cb.cc @@ -53,20 +53,26 @@ #include "gpu_plugin/gpu_processor.h" #include "gpu_plugin/np_utils/np_browser.h" #include "gpu_plugin/np_utils/np_utils.h" -#include "gpu_plugin/system_services/shared_memory.h" + +#if !defined(CB_SERVICE_REMOTE) +#include "gpu_plugin/gpu_processor.h" +#endif namespace o3d { +using ::base::SharedMemory; using command_buffer::o3d::GAPIInterface; using command_buffer::O3DCmdHelper; -using gpu_plugin::CommandBuffer; -using gpu_plugin::GPUProcessor; using gpu_plugin::NPBrowser; using gpu_plugin::NPCreateObject; using gpu_plugin::NPGetProperty; using gpu_plugin::NPInvoke; using gpu_plugin::NPInvokeVoid; using gpu_plugin::NPObjectPointer; -using gpu_plugin::SharedMemory; + +#if !defined(CB_SERVICE_REMOTE) +using gpu_plugin::CommandBuffer; +using gpu_plugin::GPUProcessor; +#endif RendererCB::RendererCB(ServiceLocator* service_locator, int32 transfer_memory_size) @@ -88,12 +94,13 @@ RendererCB::~RendererCB() { } void RendererCB::Destroy() { - if (transfer_shm_id_ >= 0) { - NPInvokeVoid(npp_, command_buffer_, "unregisterObject", transfer_shm_id_); - transfer_shm_id_ = command_buffer::kInvalidSharedMemoryId; + if (command_buffer_.Get()) { + command_buffer_->DestroyTransferBuffer(transfer_shm_id_); } - transfer_shm_ = NPObjectPointer<NPObject>(); + transfer_shm_id_ = command_buffer::kInvalidSharedMemoryId; + transfer_shm_ = NULL; + transfer_shm_address_ = NULL; if (allocator_) { delete allocator_; @@ -298,30 +305,25 @@ Renderer::InitStatus RendererCB::InitPlatformSpecific( return INITIALIZATION_ERROR; } - // Create and map a block of memory for the transfer buffer. - transfer_shm_ = CreateSharedMemory(transfer_memory_size_, npp_); - if (!transfer_shm_.Get()) { + transfer_shm_id_ = command_buffer_->CreateTransferBuffer( + transfer_memory_size_); + if (transfer_shm_id_ < 0) { Destroy(); return INITIALIZATION_ERROR; } - size_t size_bytes; - transfer_shm_address_ = NPBrowser::get()->MapMemory(npp_, - transfer_shm_.Get(), - &size_bytes); - if (!transfer_shm_address_) { + + transfer_shm_ = command_buffer_->GetTransferBuffer(transfer_shm_id_); + if (!transfer_shm_) { Destroy(); return INITIALIZATION_ERROR; } - DCHECK(size_bytes == transfer_memory_size_); - // Register the transfer buffer so it can be identified with an integer - // in future commands. - if (!NPInvoke(npp_, command_buffer_, "registerObject", transfer_shm_, - &transfer_shm_id_)) { + if (!transfer_shm_->Map(transfer_memory_size_)) { Destroy(); return INITIALIZATION_ERROR; } - DCHECK_GE(transfer_shm_id_, 0); + + transfer_shm_address_ = transfer_shm_->memory(); // Insert a token. frame_token_ = helper_->InsertToken(); @@ -340,12 +342,34 @@ Renderer::InitStatus RendererCB::InitPlatformSpecific( return SUCCESS; } -static const unsigned int kDefaultCommandBufferSize = 256 << 10; - // This should be enough to hold the biggest possible buffer // (2048x2048xABGR16F texture = 32MB) static const int32 kDefaultTransferMemorySize = 32 << 20; +#if defined(CB_SERVICE_REMOTE) + +RendererCBRemote *RendererCBRemote::CreateDefault( + ServiceLocator* service_locator) { + return new RendererCBRemote(service_locator, + kDefaultTransferMemorySize); +} + +RendererCBRemote::RendererCBRemote(ServiceLocator* service_locator, + int32 transfer_memory_size) + : RendererCB(service_locator, transfer_memory_size) { +} + +RendererCBRemote::~RendererCBRemote() { +} + +Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { + return RendererCBRemote::CreateDefault(service_locator); +} + +#else // CB_SERVICE_REMOTE + +static const unsigned int kDefaultCommandBufferSize = 256 << 10; + RendererCBLocal *RendererCBLocal::CreateDefault( ServiceLocator* service_locator) { return new RendererCBLocal(service_locator, @@ -363,23 +387,16 @@ RendererCBLocal::~RendererCBLocal() { NPObjectPointer<CommandBuffer> RendererCBLocal::CreateCommandBuffer( NPP npp, void* hwnd, int32 size) { #if defined(OS_WIN) - NPObjectPointer<SharedMemory> ring_buffer = - NPCreateObject<SharedMemory>(npp); - if (!ring_buffer->Initialize(size)) + scoped_ptr<SharedMemory> ring_buffer(new SharedMemory); + if (!ring_buffer->Create(std::wstring(), false, false, size)) return NPObjectPointer<CommandBuffer>(); - size_t mapped_size; - if (!NPBrowser::get()->MapMemory(npp, - ring_buffer.Get(), - &mapped_size)) { + if (!ring_buffer->Map(size)) return NPObjectPointer<CommandBuffer>(); - } - - DCHECK(mapped_size == size); NPObjectPointer<CommandBuffer> command_buffer = NPCreateObject<CommandBuffer>(npp); - if (!command_buffer->Initialize(ring_buffer)) + if (!command_buffer->Initialize(ring_buffer.release())) return NPObjectPointer<CommandBuffer>(); scoped_refptr<GPUProcessor> gpu_processor( @@ -397,58 +414,10 @@ NPObjectPointer<CommandBuffer> RendererCBLocal::CreateCommandBuffer( #endif } -NPObjectPointer<NPObject> RendererCBLocal::CreateSharedMemory(int32 size, - NPP npp) { - NPObjectPointer<SharedMemory> shared_memory = - NPCreateObject<SharedMemory>(npp); - - if (!shared_memory->Initialize(size)) - return NPObjectPointer<NPObject>(); - - return shared_memory; -} - -RendererCBRemote *RendererCBRemote::CreateDefault( - ServiceLocator* service_locator) { - return new RendererCBRemote(service_locator, - kDefaultTransferMemorySize); -} - -RendererCBRemote::RendererCBRemote(ServiceLocator* service_locator, - int32 transfer_memory_size) - : RendererCB(service_locator, transfer_memory_size) { -} - -RendererCBRemote::~RendererCBRemote() { -} - -NPObjectPointer<NPObject> RendererCBRemote::CreateSharedMemory(int32 size, - NPP npp) { - NPObjectPointer<NPObject> shared_memory; - - NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( - NPBrowser::get()->GetWindowNPObject(npp)); - if (!window.Get()) - return shared_memory; - - NPObjectPointer<NPObject> chromium; - if (!NPGetProperty(npp, window, "chromium", &chromium) || !chromium.Get()) - return shared_memory; - - NPObjectPointer<NPObject> system; - if (!NPGetProperty(npp, chromium, "system", &system) || !system.Get()) - return shared_memory; - - if (!NPInvoke(npp, system, "createSharedMemory", size, - &shared_memory)) { - return shared_memory; - } - - return shared_memory; -} - Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { return RendererCBLocal::CreateDefault(service_locator); } +#endif // CB_SERVICE_REMOTE + } // namespace o3d diff --git a/o3d/core/cross/command_buffer/renderer_cb.h b/o3d/core/cross/command_buffer/renderer_cb.h index 59aca05..e58a2bc 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.h +++ b/o3d/core/cross/command_buffer/renderer_cb.h @@ -35,6 +35,7 @@ #ifndef O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_ #define O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_ +#include "base/shared_memory.h" #include "core/cross/precompile.h" #include <vector> #include "core/cross/renderer.h" @@ -251,17 +252,13 @@ class RendererCB : public Renderer { virtual InitStatus InitPlatformSpecific(const DisplayWindow& display_window, bool off_screen); - // Create a shared memory object of the given size. - virtual gpu_plugin::NPObjectPointer<NPObject> - CreateSharedMemory(int32 size, NPP npp) = 0; - private: int32 transfer_memory_size_; - gpu_plugin::NPObjectPointer<NPObject> transfer_shm_; + ::base::SharedMemory* transfer_shm_; int32 transfer_shm_id_; void *transfer_shm_address_; NPP npp_; - gpu_plugin::NPObjectPointer<NPObject> command_buffer_; + gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; ::command_buffer::O3DCmdHelper *helper_; ::command_buffer::FencedAllocatorWrapper *allocator_; @@ -282,6 +279,27 @@ class RendererCB : public Renderer { DISALLOW_COPY_AND_ASSIGN(RendererCB); }; +#if defined(CB_SERVICE_REMOTE) + +// This subclass initializes itself with a remotely created, potentially out- +// of-process CommandBuffer. It requires that the browser supports the "system +// service" to create shared memory, which is not available in the mange branch +// of Chrome. Use RendererCBLocal for now. +class RendererCBRemote : public RendererCB { + public: + // Creates a default RendererCBRemote. + static RendererCBRemote *CreateDefault(ServiceLocator* service_locator); + + protected: + RendererCBRemote(ServiceLocator* service_locator, int32 transfer_memory_size); + virtual ~RendererCBRemote(); + + private: + DISALLOW_COPY_AND_ASSIGN(RendererCBRemote); +}; + +#else // CB_SERVICE_REMOTE + // This subclass initializes itself with a locally created in-process // CommandBuffer and GPUProcessor. This class will eventually go away and the // code in RendererCBRemote will be merged into RendererCB. @@ -298,36 +316,11 @@ class RendererCBLocal : public RendererCB { int32 transfer_memory_size); virtual ~RendererCBLocal(); - // Create a shared memory object of the given size using the system services - // library directly. - virtual gpu_plugin::NPObjectPointer<NPObject> - CreateSharedMemory(int32 size, NPP npp); - private: DISALLOW_COPY_AND_ASSIGN(RendererCBLocal); }; -// This subclass initializes itself with a remotely created, potentially out- -// of-process CommandBuffer. It requires that the browser supports the "system -// service" to create shared memory, which is not available in the mange branch -// of Chrome. Use RendererCBLocal for now. -class RendererCBRemote : public RendererCB { - public: - // Creates a default RendererCBRemote. - static RendererCBRemote *CreateDefault(ServiceLocator* service_locator); - - protected: - RendererCBRemote(ServiceLocator* service_locator, int32 transfer_memory_size); - virtual ~RendererCBRemote(); - - // Create a shared memory object using the browser's - // chromium.system.createSharedMemory method. - virtual gpu_plugin::NPObjectPointer<NPObject> - CreateSharedMemory(int32 size, NPP npp); - - private: - DISALLOW_COPY_AND_ASSIGN(RendererCBRemote); -}; +#endif // CB_SERVICE_REMOTE } // namespace o3d 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() { diff --git a/o3d/gpu_plugin/command_buffer.h b/o3d/gpu_plugin/command_buffer.h index 0b2d507..84457c0 100644 --- a/o3d/gpu_plugin/command_buffer.h +++ b/o3d/gpu_plugin/command_buffer.h @@ -8,7 +8,9 @@ #include <set> #include <vector> +#include "base/linked_ptr.h" #include "base/scoped_ptr.h" +#include "base/shared_memory.h" #include "base/task.h" #include "o3d/gpu_plugin/np_utils/default_np_object.h" #include "o3d/gpu_plugin/np_utils/np_dispatcher.h" @@ -22,11 +24,12 @@ class CommandBuffer : public DefaultNPObject<NPObject> { explicit CommandBuffer(NPP npp); virtual ~CommandBuffer(); - // Initialize the command buffer with the given buffer. - virtual bool Initialize(NPObjectPointer<NPObject> ring_buffer); + // Initialize the command buffer with the given ring buffer. Takes ownership + // of ring buffer. + virtual bool Initialize(::base::SharedMemory* ring_buffer); // Gets the shared memory ring buffer object for the command buffer. - virtual NPObjectPointer<NPObject> GetRingBuffer(); + virtual ::base::SharedMemory* GetRingBuffer(); virtual int32 GetSize(); @@ -56,19 +59,15 @@ class CommandBuffer : public DefaultNPObject<NPObject> { // Takes ownership of callback. The callback is invoked on the plugin thread. virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); - // Get an opaque integer handle for an NPObject. This can be used - // to identify the shared memory object from the ring buffer. Note that the - // object will be retained. Consider reference cycle issues. Returns zero for - // NULL, positive for non-NULL and -1 on error. Objects may be registered - // multiple times and have multiple associated handles. Each handle for a - // distinct object must be separately unregistered. - virtual int32 RegisterObject(NPObjectPointer<NPObject> object); + // Create a shared memory transfer buffer and return a handle that uniquely + // identifies it or -1 on error. + virtual int32 CreateTransferBuffer(size_t size); - // Unregister a previously registered NPObject. It is safe to unregister the - // zero handle. - virtual void UnregisterObject(NPObjectPointer<NPObject> object, int32 handle); + // Destroy a shared memory transfer buffer and recycle the handle. + virtual void DestroyTransferBuffer(int32 id); - virtual NPObjectPointer<NPObject> GetRegisteredObject(int32 handle); + // Get the shared memory associated with a handle. + virtual ::base::SharedMemory* GetTransferBuffer(int32 handle); // Get the current token value. This is used for by the writer to defer // changes to shared memory objects until the reader has reached a certain @@ -103,16 +102,10 @@ class CommandBuffer : public DefaultNPObject<NPObject> { } NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) - NP_UTILS_DISPATCHER(Initialize, bool(NPObjectPointer<NPObject> ring_buffer)) - NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<NPObject>()) NP_UTILS_DISPATCHER(GetSize, int32()) NP_UTILS_DISPATCHER(SyncOffsets, int32(int32 get_offset)) NP_UTILS_DISPATCHER(GetGetOffset, int32()); NP_UTILS_DISPATCHER(GetPutOffset, int32()); - NP_UTILS_DISPATCHER(RegisterObject, - int32(NPObjectPointer<NPObject> object)); - NP_UTILS_DISPATCHER(UnregisterObject, - void(NPObjectPointer<NPObject> object, int32 handle)); NP_UTILS_DISPATCHER(GetToken, int32()); NP_UTILS_DISPATCHER(ResetParseError, int32()); NP_UTILS_DISPATCHER(GetErrorStatus, bool()); @@ -120,12 +113,12 @@ class CommandBuffer : public DefaultNPObject<NPObject> { private: NPP npp_; - NPObjectPointer<NPObject> ring_buffer_; + scoped_ptr< ::base::SharedMemory> ring_buffer_; int32 size_; int32 get_offset_; int32 put_offset_; scoped_ptr<Callback0::Type> put_offset_change_callback_; - std::vector<NPObjectPointer<NPObject> > registered_objects_; + std::vector<linked_ptr< ::base::SharedMemory> > registered_objects_; std::set<int32> unused_registered_object_elements_; int32 token_; int32 parse_error_; diff --git a/o3d/gpu_plugin/command_buffer_mock.h b/o3d/gpu_plugin/command_buffer_mock.h index a10e56d..ab82bdb 100644 --- a/o3d/gpu_plugin/command_buffer_mock.h +++ b/o3d/gpu_plugin/command_buffer_mock.h @@ -16,23 +16,22 @@ class MockCommandBuffer : public CommandBuffer { public: explicit MockCommandBuffer(NPP npp) : CommandBuffer(npp) { ON_CALL(*this, GetRingBuffer()) - .WillByDefault(testing::Return(NPObjectPointer<NPObject>())); - ON_CALL(*this, GetRegisteredObject(testing::_)) - .WillByDefault(testing::Return(NPObjectPointer<NPObject>())); + .WillByDefault(testing::Return(static_cast<::base::SharedMemory*>(NULL))); + ON_CALL(*this, GetTransferBuffer(testing::_)) + .WillByDefault(testing::Return(static_cast<::base::SharedMemory*>(NULL))); } - MOCK_METHOD1(Initialize, bool(NPObjectPointer<NPObject> ring_buffer)); - MOCK_METHOD0(GetRingBuffer, NPObjectPointer<NPObject>()); + MOCK_METHOD1(Initialize, bool(::base::SharedMemory* ring_buffer)); + MOCK_METHOD0(GetRingBuffer, ::base::SharedMemory*()); MOCK_METHOD0(GetSize, int32()); MOCK_METHOD1(SyncOffsets, int32(int32 put_offset)); MOCK_METHOD0(GetGetOffset, int32()); MOCK_METHOD1(SetGetOffset, void(int32 get_offset)); MOCK_METHOD0(GetPutOffset, int32()); MOCK_METHOD1(SetPutOffsetChangeCallback, void(Callback0::Type* callback)); - MOCK_METHOD1(RegisterObject, int32(NPObjectPointer<NPObject> object)); - MOCK_METHOD2(UnregisterObject, void(NPObjectPointer<NPObject> object, - int32 handle)); - MOCK_METHOD1(GetRegisteredObject, NPObjectPointer<NPObject>(int32 handle)); + MOCK_METHOD1(CreateTransferBuffer, int32(size_t size)); + MOCK_METHOD1(DestroyTransferBuffer, void(int32 handle)); + MOCK_METHOD1(GetTransferBuffer, ::base::SharedMemory*(int32 handle)); private: DISALLOW_COPY_AND_ASSIGN(MockCommandBuffer); diff --git a/o3d/gpu_plugin/command_buffer_unittest.cc b/o3d/gpu_plugin/command_buffer_unittest.cc index d09c5c7..5041d48 100644 --- a/o3d/gpu_plugin/command_buffer_unittest.cc +++ b/o3d/gpu_plugin/command_buffer_unittest.cc @@ -8,10 +8,10 @@ #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" #include "o3d/gpu_plugin/np_utils/np_object_mock.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" -#include "o3d/gpu_plugin/system_services/shared_memory_mock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +using base::SharedMemory; using testing::_; using testing::DoAll; using testing::Return; @@ -24,47 +24,28 @@ class CommandBufferTest : public testing::Test { protected: virtual void SetUp() { command_buffer_ = NPCreateObject<CommandBuffer>(NULL); - ring_buffer_ = NPCreateObject<MockSharedMemory>(NULL); - - ON_CALL(*ring_buffer_.Get(), GetSize()) - .WillByDefault(Return(1024)); } MockNPBrowser mock_browser_; NPObjectPointer<CommandBuffer> command_buffer_; - NPObjectPointer<MockSharedMemory> ring_buffer_; }; TEST_F(CommandBufferTest, NullRingBufferByDefault) { - EXPECT_EQ(NPObjectPointer<NPObject>(), - command_buffer_->GetRingBuffer()); + EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer()); } TEST_F(CommandBufferTest, InitializesCommandBuffer) { - EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); - EXPECT_TRUE(ring_buffer_ == command_buffer_->GetRingBuffer()); + SharedMemory* ring_buffer = new SharedMemory; + EXPECT_TRUE(ring_buffer->Create(std::wstring(), false, false, 1024)); + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer)); + EXPECT_TRUE(ring_buffer == command_buffer_->GetRingBuffer()); EXPECT_EQ(256, command_buffer_->GetSize()); } TEST_F(CommandBufferTest, InitializeFailsSecondTime) { - EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); - EXPECT_FALSE(command_buffer_->Initialize(ring_buffer_)); -} - -TEST_F(CommandBufferTest, InitializeFailsIfSizeIsNegative) { - ON_CALL(*ring_buffer_.Get(), GetSize()) - .WillByDefault(Return(-1024)); - - EXPECT_FALSE(command_buffer_->Initialize(ring_buffer_)); -} - -TEST_F(CommandBufferTest, InitializeFailsIfRingBufferIsNull) { - EXPECT_FALSE(command_buffer_->Initialize(NPObjectPointer<NPObject>())); -} - -TEST_F(CommandBufferTest, InitializeFailsIfRingBufferDoesNotImplementGetSize) { - EXPECT_FALSE(command_buffer_->Initialize( - NPCreateObject<DynamicNPObject>(NULL))); + SharedMemory* ring_buffer = new SharedMemory; + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer)); + EXPECT_FALSE(command_buffer_->Initialize(ring_buffer)); } TEST_F(CommandBufferTest, GetAndPutOffsetsDefaultToZero) { @@ -78,7 +59,10 @@ class MockCallback : public CallbackRunner<Tuple0> { }; TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { - EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); + SharedMemory* ring_buffer = new SharedMemory; + ring_buffer->Create(std::wstring(), false, false, 1024); + + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer)); StrictMock<MockCallback>* put_offset_change_callback = new StrictMock<MockCallback>; @@ -102,88 +86,69 @@ TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { } TEST_F(CommandBufferTest, ZeroHandleMapsToNull) { - EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(0).Get()); + EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); } TEST_F(CommandBufferTest, NegativeHandleMapsToNull) { - EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(-1).Get()); + EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1)); } TEST_F(CommandBufferTest, OutOfRangeHandleMapsToNull) { - EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(1).Get()); + EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1)); } -TEST_F(CommandBufferTest, RegisteringNullObjectReturnsZero) { - EXPECT_EQ(0, command_buffer_->RegisterObject(NPObjectPointer<NPObject>())); +TEST_F(CommandBufferTest, CanCreateTransferBuffers) { + int32 handle = command_buffer_->CreateTransferBuffer(1024); + EXPECT_EQ(1, handle); + SharedMemory* buffer = command_buffer_->GetTransferBuffer(handle); + ASSERT_TRUE(NULL != buffer); + EXPECT_EQ(1024, buffer->max_size()); } -TEST_F(CommandBufferTest, RegistersDistinctNonZeroHandlesForObject) { - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); +TEST_F(CommandBufferTest, CreateTransferBufferReturnsDistinctHandles) { + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, RegisterObjectReusesUnregisteredHandles) { - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); - command_buffer_->UnregisterObject(ring_buffer_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(3, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(3)); +TEST_F(CommandBufferTest, CreateTransferBufferReusesUnregisteredHandles) { + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); + EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); + command_buffer_->DestroyTransferBuffer(1); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); + EXPECT_EQ(3, command_buffer_->CreateTransferBuffer(1024)); } TEST_F(CommandBufferTest, CannotUnregisterHandleZero) { - command_buffer_->UnregisterObject(ring_buffer_, 0); - EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(0).Get()); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + command_buffer_->DestroyTransferBuffer(0); + EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } TEST_F(CommandBufferTest, CannotUnregisterNegativeHandles) { - command_buffer_->UnregisterObject(ring_buffer_, -1); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + command_buffer_->DestroyTransferBuffer(-1); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } TEST_F(CommandBufferTest, CannotUnregisterUnregisteredHandles) { - command_buffer_->UnregisterObject(ring_buffer_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); -} - -TEST_F(CommandBufferTest, - CannotUnregisterHandleWithoutDemonstratingAccessToObject) { - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - command_buffer_->UnregisterObject(command_buffer_, 1); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); + command_buffer_->DestroyTransferBuffer(1); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } // Testing this case specifically because there is an optimization that takes // a different code path in this case. TEST_F(CommandBufferTest, UnregistersLastRegisteredHandle) { - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - command_buffer_->UnregisterObject(ring_buffer_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); + command_buffer_->DestroyTransferBuffer(1); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } // Testing this case specifically because there is an optimization that takes // a different code path in this case. TEST_F(CommandBufferTest, UnregistersTwoLastRegisteredHandles) { - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); - command_buffer_->UnregisterObject(ring_buffer_, 2); - command_buffer_->UnregisterObject(ring_buffer_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); - EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); + EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); + command_buffer_->DestroyTransferBuffer(2); + command_buffer_->DestroyTransferBuffer(1); + EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } TEST_F(CommandBufferTest, DefaultTokenIsZero) { diff --git a/o3d/gpu_plugin/gpu_plugin.cc b/o3d/gpu_plugin/gpu_plugin.cc index 086500c..fa270f7 100644 --- a/o3d/gpu_plugin/gpu_plugin.cc +++ b/o3d/gpu_plugin/gpu_plugin.cc @@ -11,7 +11,7 @@ #if defined(O3D_IN_CHROME) #include "webkit/glue/plugins/nphostapi.h" #else -#include "o3d/third_party/npapi/include/npupp.h" +#include "o3d/third_party/npapi/include/npfunctions.h" #endif namespace gpu_plugin { diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp index 7f22619..c604a30 100644 --- a/o3d/gpu_plugin/gpu_plugin.gyp +++ b/o3d/gpu_plugin/gpu_plugin.gyp @@ -48,9 +48,6 @@ 'np_utils/np_utils.cc', 'np_utils/np_utils.h', 'np_utils/webkit_browser.h', - 'system_services/shared_memory.cc', - 'system_services/shared_memory.h', - 'system_services/shared_memory_mock.h', ], }, @@ -79,7 +76,6 @@ 'np_utils/np_class_unittest.cc', 'np_utils/np_object_pointer_unittest.cc', 'np_utils/np_utils_unittest.cc', - 'system_services/shared_memory_unittest.cc', ], }, diff --git a/o3d/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu_plugin/gpu_plugin_object.cc index 165addc..801cbca 100644 --- a/o3d/gpu_plugin/gpu_plugin_object.cc +++ b/o3d/gpu_plugin/gpu_plugin_object.cc @@ -9,6 +9,8 @@ #include "o3d/gpu_plugin/gpu_plugin_object.h" #include "o3d/gpu_plugin/gpu_processor.h" +using ::base::SharedMemory; + namespace gpu_plugin { const NPUTF8 GPUPluginObject::kPluginType[] = @@ -95,32 +97,11 @@ NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() { if (status_ != kWaitingForOpenCommandBuffer) return NPObjectPointer<NPObject>(); - NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( - NPBrowser::get()->GetWindowNPObject(npp_)); - if (!window.Get()) - return NPObjectPointer<NPObject>(); - - NPObjectPointer<NPObject> chromium; - if (!NPGetProperty(npp_, window, "chromium", &chromium)) { + scoped_ptr<SharedMemory> ring_buffer(new SharedMemory); + if (!ring_buffer->Create(std::wstring(), false, false, kCommandBufferSize)) return NPObjectPointer<NPObject>(); - } - - NPObjectPointer<NPObject> system; - if (!NPGetProperty(npp_, chromium, "system", &system)) { - return NPObjectPointer<NPObject>(); - } - - NPObjectPointer<NPObject> ring_buffer; - if (!NPInvoke(npp_, system, "createSharedMemory", kCommandBufferSize, - &ring_buffer)) { - return NPObjectPointer<NPObject>(); - } - - if (!ring_buffer.Get()) { - return NPObjectPointer<NPObject>(); - } - if (command_buffer_->Initialize(ring_buffer)) { + if (command_buffer_->Initialize(ring_buffer.release())) { if (processor_->Initialize(static_cast<HWND>(window_.window))) { command_buffer_->SetPutOffsetChangeCallback( NewCallback(processor_.get(), diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc index 04f312e..8bc7bfb 100644 --- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc +++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc @@ -9,16 +9,17 @@ #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" #include "o3d/gpu_plugin/np_utils/np_object_mock.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" -#include "o3d/gpu_plugin/system_services/shared_memory_mock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" #if defined(O3D_IN_CHROME) #include "webkit/glue/plugins/nphostapi.h" #else -#include "o3d/third_party/npapi/include/npupp.h" +#include "o3d/third_party/npapi/include/npfunctions.h" #endif +using ::base::SharedMemory; + using testing::_; using testing::DoAll; using testing::Invoke; @@ -202,15 +203,9 @@ TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) { } TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { - NPObjectPointer<NPObject> ring_buffer = - NPCreateObject<StrictMock<MockSharedMemory> >(NULL); - - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( - GPUPluginObject::kCommandBufferSize)) - .WillOnce(Return(ring_buffer)); - - EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer)) - .WillOnce(Return(true)); + EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), + Return(true))); EXPECT_CALL(*processor_.get(), Initialize(NULL)) .WillOnce(Return(true)); @@ -256,41 +251,12 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfWindowNotReady) { EXPECT_EQ(GPUPluginObject::kWaitingForSetWindow, plugin_object_->GetStatus()); } -TEST_F(GPUPluginObjectTest, - OpenCommandBufferReturnsNullIfCannotCreateRingBuffer) { - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( - GPUPluginObject::kCommandBufferSize)) - .WillOnce(Return(NPObjectPointer<NPObject>())); - - EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", - 0, - NULL, - NULL, - NULL)); - - // Set status as though SetWindow has been called. Avoids having to create a - // valid window handle to pass to SetWindow in tests. - plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer); - - EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); - - EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, - plugin_object_->GetStatus()); - - EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); -} TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCommandBufferCannotInitialize) { - NPObjectPointer<NPObject> ring_buffer = - NPCreateObject<StrictMock<MockSharedMemory> >(NULL); - - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( - GPUPluginObject::kCommandBufferSize)) - .WillOnce(Return(ring_buffer)); - - EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer)) - .WillOnce(Return(false)); + EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), + Return(false))); EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", 0, @@ -312,15 +278,9 @@ TEST_F(GPUPluginObjectTest, TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIGPUProcessorCannotInitialize) { - NPObjectPointer<NPObject> ring_buffer = - NPCreateObject<StrictMock<MockSharedMemory> >(NULL); - - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( - GPUPluginObject::kCommandBufferSize)) - .WillOnce(Return(ring_buffer)); - - EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer)) - .WillOnce(Return(true)); + EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), + Return(true))); EXPECT_CALL(*processor_.get(), Initialize(NULL)) .WillOnce(Return(false)); diff --git a/o3d/gpu_plugin/gpu_plugin_unittest.cc b/o3d/gpu_plugin/gpu_plugin_unittest.cc index 51e47a3..0bc53fd 100644 --- a/o3d/gpu_plugin/gpu_plugin_unittest.cc +++ b/o3d/gpu_plugin/gpu_plugin_unittest.cc @@ -12,7 +12,7 @@ #if defined(O3D_IN_CHROME) #include "webkit/glue/plugins/nphostapi.h" #else -#include "o3d/third_party/npapi/include/npupp.h" +#include "o3d/third_party/npapi/include/npfunctions.h" #endif #if defined(OS_LINUX) diff --git a/o3d/gpu_plugin/gpu_processor.cc b/o3d/gpu_plugin/gpu_processor.cc index 2bc2ccd..f554fb5 100644 --- a/o3d/gpu_plugin/gpu_processor.cc +++ b/o3d/gpu_plugin/gpu_processor.cc @@ -4,6 +4,8 @@ #include "o3d/gpu_plugin/gpu_processor.h" +using ::base::SharedMemory; + namespace gpu_plugin { GPUProcessor::~GPUProcessor() { @@ -49,23 +51,26 @@ void GPUProcessor::ProcessCommands() { } void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) { - NPObjectPointer<NPObject> shared_memory = - command_buffer_->GetRegisteredObject(shm_id); + SharedMemory* shared_memory = command_buffer_->GetTransferBuffer(shm_id); + if (!shared_memory) + return NULL; + + if (!shared_memory->memory()) { + if (!shared_memory->Map(shared_memory->max_size())) + return NULL; + } - size_t size; - return NPBrowser::get()->MapMemory(npp_, shared_memory.Get(), &size); + return shared_memory->memory(); } // TODO(apatrick): Consolidate this with the above and return both the address // and size. size_t GPUProcessor::GetSharedMemorySize(int32 shm_id) { - NPObjectPointer<NPObject> shared_memory = - command_buffer_->GetRegisteredObject(shm_id); - - size_t size; - NPBrowser::get()->MapMemory(npp_, shared_memory.Get(), &size); + SharedMemory* shared_memory = command_buffer_->GetTransferBuffer(shm_id); + if (!shared_memory) + return 0; - return size; + return shared_memory->max_size(); } void GPUProcessor::set_token(int32 token) { diff --git a/o3d/gpu_plugin/gpu_processor_unittest.cc b/o3d/gpu_plugin/gpu_processor_unittest.cc index 236f418..2a518c2 100644 --- a/o3d/gpu_plugin/gpu_processor_unittest.cc +++ b/o3d/gpu_plugin/gpu_processor_unittest.cc @@ -9,10 +9,11 @@ #include "o3d/gpu_plugin/gpu_processor.h" #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" -#include "o3d/gpu_plugin/system_services/shared_memory_mock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +using ::base::SharedMemory; + using testing::_; using testing::DoAll; using testing::Invoke; @@ -23,15 +24,18 @@ using testing::StrictMock; namespace gpu_plugin { +const size_t kRingBufferSize = 1024; +const size_t kRingBufferEntries = kRingBufferSize / sizeof(int32); + class GPUProcessorTest : public testing::Test { protected: virtual void SetUp() { - shared_memory_ = NPCreateObject<NiceMock<MockSharedMemory> >(NULL); - memset(buffer_, 0, sizeof(buffer_)); + shared_memory_.reset(new SharedMemory); + shared_memory_->Create(std::wstring(), false, false, kRingBufferSize); + shared_memory_->Map(kRingBufferSize); + buffer_ = static_cast<int32*>(shared_memory_->memory()); - ON_CALL(mock_browser_, MapMemory(NULL, shared_memory_.Get(), _)) - .WillByDefault(DoAll(SetArgumentPointee<2>(sizeof(buffer_)), - Return(buffer_))); + memset(buffer_, 0, kRingBufferSize); // Don't mock PluginThreadAsyncCall. Have it schedule the task. ON_CALL(mock_browser_, PluginThreadAsyncCall(_, _, _)) @@ -40,9 +44,9 @@ class GPUProcessorTest : public testing::Test { command_buffer_ = NPCreateObject<MockCommandBuffer>(NULL); ON_CALL(*command_buffer_.Get(), GetRingBuffer()) - .WillByDefault(Return(shared_memory_)); + .WillByDefault(Return(shared_memory_.get())); ON_CALL(*command_buffer_.Get(), GetSize()) - .WillByDefault(Return(sizeof(buffer_))); + .WillByDefault(Return(kRingBufferEntries)); #if defined(OS_WIN) gapi_ = new GPUProcessor::GPUGAPIInterface; @@ -53,9 +57,9 @@ class GPUProcessorTest : public testing::Test { decoder_ = new command_buffer::o3d::GAPIDecoder(gapi_); parser_ = new command_buffer::CommandParser(buffer_, - sizeof(buffer_), + kRingBufferEntries, 0, - sizeof(buffer_), + kRingBufferEntries, 0, async_api_.get()); @@ -77,8 +81,8 @@ class GPUProcessorTest : public testing::Test { MessageLoop message_loop; MockNPBrowser mock_browser_; NPObjectPointer<MockCommandBuffer> command_buffer_; - NPObjectPointer<NiceMock<MockSharedMemory> > shared_memory_; - int32 buffer_[1024 / sizeof(int32)]; + scoped_ptr<SharedMemory> shared_memory_; + int32* buffer_; command_buffer::o3d::GAPIDecoder* decoder_; command_buffer::CommandParser* parser_; scoped_ptr<command_buffer::AsyncAPIMock> async_api_; @@ -273,8 +277,8 @@ TEST_F(GPUProcessorTest, ProcessCommandsDoesNothingAfterUnrecoverableError) { } TEST_F(GPUProcessorTest, CanGetAddressOfSharedMemory) { - EXPECT_CALL(*command_buffer_.Get(), GetRegisteredObject(7)) - .WillOnce(Return(shared_memory_)); + EXPECT_CALL(*command_buffer_.Get(), GetTransferBuffer(7)) + .WillOnce(Return(shared_memory_.get())); EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryAddress(7)); } @@ -284,21 +288,17 @@ ACTION_P2(SetPointee, address, value) { } TEST_F(GPUProcessorTest, GetAddressOfSharedMemoryMapsMemoryIfUnmapped) { - EXPECT_CALL(*command_buffer_.Get(), GetRegisteredObject(7)) - .WillOnce(Return(shared_memory_)); - - EXPECT_CALL(mock_browser_, MapMemory(NULL, shared_memory_.Get(), _)) - .WillOnce(DoAll(SetArgumentPointee<2>(sizeof(buffer_)), - Return(buffer_))); + EXPECT_CALL(*command_buffer_.Get(), GetTransferBuffer(7)) + .WillOnce(Return(shared_memory_.get())); EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryAddress(7)); } TEST_F(GPUProcessorTest, CanGetSizeOfSharedMemory) { - EXPECT_CALL(*command_buffer_.Get(), GetRegisteredObject(7)) - .WillOnce(Return(shared_memory_)); + EXPECT_CALL(*command_buffer_.Get(), GetTransferBuffer(7)) + .WillOnce(Return(shared_memory_.get())); - EXPECT_EQ(sizeof(buffer_), processor_->GetSharedMemorySize(7)); + EXPECT_EQ(kRingBufferSize, processor_->GetSharedMemorySize(7)); } TEST_F(GPUProcessorTest, SetTokenForwardsToCommandBuffer) { @@ -306,4 +306,4 @@ TEST_F(GPUProcessorTest, SetTokenForwardsToCommandBuffer) { EXPECT_EQ(7, command_buffer_->GetToken()); } -} // namespace gpu_plugin +} // namespace gpu_plugin
\ No newline at end of file diff --git a/o3d/gpu_plugin/gpu_processor_win.cc b/o3d/gpu_plugin/gpu_processor_win.cc index bb7915e..21a1c4a 100644 --- a/o3d/gpu_plugin/gpu_processor_win.cc +++ b/o3d/gpu_plugin/gpu_processor_win.cc @@ -6,6 +6,8 @@ #include "o3d/gpu_plugin/gpu_processor.h" +using ::base::SharedMemory; + namespace gpu_plugin { GPUProcessor::GPUProcessor(NPP npp, @@ -42,18 +44,14 @@ bool GPUProcessor::Initialize(HWND handle) { return false; // Map the ring buffer and create the parser. - NPObjectPointer<NPObject> ring_buffer = - command_buffer_->GetRingBuffer(); - - if (ring_buffer.Get()) { - size_t size; - void* ptr = NPBrowser::get()->MapMemory(npp_, - ring_buffer.Get(), - &size); - if (ptr == NULL) { + SharedMemory* ring_buffer = command_buffer_->GetRingBuffer(); + if (ring_buffer) { + size_t size = ring_buffer->max_size(); + if (!ring_buffer->Map(size)) { return false; } + void* ptr = ring_buffer->memory(); parser_.reset(new command_buffer::CommandParser(ptr, size, 0, size, 0, decoder_.get())); } else { diff --git a/o3d/gpu_plugin/np_utils/np_browser.cc b/o3d/gpu_plugin/np_utils/np_browser.cc index 31600b5..3fc9185 100644 --- a/o3d/gpu_plugin/np_utils/np_browser.cc +++ b/o3d/gpu_plugin/np_utils/np_browser.cc @@ -8,10 +8,7 @@ #if defined(O3D_IN_CHROME) #include "webkit/glue/plugins/nphostapi.h" #else -#include "o3d/third_party/npapi/include/npupp.h" - -// TODO: Remove this when we figure out what to do about NPN_MapMemory. -#include "o3d/gpu_plugin/system_services/shared_memory.h" +#include "o3d/third_party/npapi/include/npfunctions.h" #endif namespace gpu_plugin { @@ -117,16 +114,15 @@ void NPBrowser::PluginThreadAsyncCall(NPP npp, netscape_funcs_->pluginthreadasynccall(npp, callback, data); } -void* NPBrowser::MapMemory(NPP npp, - NPObject* object, - size_t* size) { - // NPN_MapMemory is an experiment. It only exists in NPNetscapeFuncs in - // a hacked version of Chromium. -#if defined(O3D_IN_CHROME) - return NULL; -#else - return NPN_MapMemory(npp, object, size); -#endif +uint32 NPBrowser::ScheduleTimer(NPP npp, + uint32 interval, + bool repeat, + TimerProc callback) { + return netscape_funcs_->scheduletimer(npp, interval, repeat, callback); +} + +void NPBrowser::UnscheduleTimer(NPP npp, uint32 timer_id) { + netscape_funcs_->unscheduletimer(npp, timer_id); } } // namespace gpu_plugin diff --git a/o3d/gpu_plugin/np_utils/np_browser.h b/o3d/gpu_plugin/np_utils/np_browser.h index b2b129a..5e71aac 100644 --- a/o3d/gpu_plugin/np_utils/np_browser.h +++ b/o3d/gpu_plugin/np_utils/np_browser.h @@ -75,9 +75,13 @@ class NPBrowser { PluginThreadAsyncCallProc callback, void* data); - virtual void* MapMemory(NPP npp, - NPObject* object, - size_t* size); + typedef void (*TimerProc)(NPP npp, uint32 timer_id); + virtual uint32 ScheduleTimer(NPP npp, + uint32 interval, + bool repeat, + TimerProc callback); + + virtual void UnscheduleTimer(NPP npp, uint32 timer_id); private: static NPBrowser* browser_; diff --git a/o3d/gpu_plugin/np_utils/np_browser_mock.h b/o3d/gpu_plugin/np_utils/np_browser_mock.h index fd98e52..9175e42 100644 --- a/o3d/gpu_plugin/np_utils/np_browser_mock.h +++ b/o3d/gpu_plugin/np_utils/np_browser_mock.h @@ -38,7 +38,11 @@ class MockNPBrowser : public StubNPBrowser { MOCK_METHOD1(GetWindowNPObject, NPObject*(NPP cpp)); MOCK_METHOD3(PluginThreadAsyncCall, void(NPP npp, PluginThreadAsyncCallProc callback, void* data)); - MOCK_METHOD3(MapMemory, void*(NPP npp, NPObject* object, size_t* size)); + MOCK_METHOD4(ScheduleTimer, uint32(NPP npp, + uint32 interval, + bool repeat, + TimerProc callback)); + MOCK_METHOD2(UnscheduleTimer, void(NPP npp, uint32 timer_id)); }; } // namespace gpu_plugin diff --git a/o3d/gpu_plugin/np_utils/np_browser_stub.cc b/o3d/gpu_plugin/np_utils/np_browser_stub.cc index 9f56b4c..f20bbda 100644 --- a/o3d/gpu_plugin/np_utils/np_browser_stub.cc +++ b/o3d/gpu_plugin/np_utils/np_browser_stub.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "o3d/gpu_plugin/np_utils/np_browser_stub.h" -#include "o3d/gpu_plugin/system_services/shared_memory.h" #include "base/logging.h" #include "base/message_loop.h" @@ -113,10 +112,14 @@ void StubNPBrowser::PluginThreadAsyncCall( NewRunnableFunction(callback, data)); } -void* StubNPBrowser::MapMemory(NPP npp, - NPObject* object, - size_t* size) { - return NPN_MapMemory(npp, object, size); +uint32 StubNPBrowser::ScheduleTimer(NPP npp, + uint32 interval, + bool repeat, + TimerProc callback) { + return 0; +} + +void StubNPBrowser::UnscheduleTimer(NPP npp, uint32 timer_id) { } } // namespace gpu_plugin diff --git a/o3d/gpu_plugin/np_utils/np_browser_stub.h b/o3d/gpu_plugin/np_utils/np_browser_stub.h index ed5e208..0740244 100644 --- a/o3d/gpu_plugin/np_utils/np_browser_stub.h +++ b/o3d/gpu_plugin/np_utils/np_browser_stub.h @@ -67,9 +67,13 @@ class StubNPBrowser : public NPBrowser { virtual void PluginThreadAsyncCall(NPP npp, PluginThreadAsyncCallProc callback, void* data); - virtual void* MapMemory(NPP npp, - NPObject* object, - size_t* size); + + virtual uint32 ScheduleTimer(NPP npp, + uint32 interval, + bool repeat, + TimerProc callback); + + virtual void UnscheduleTimer(NPP npp, uint32 timer_id); private: DISALLOW_COPY_AND_ASSIGN(StubNPBrowser); diff --git a/o3d/gpu_plugin/np_utils/np_headers.h b/o3d/gpu_plugin/np_utils/np_headers.h index 3ba3c30..89e666a 100644 --- a/o3d/gpu_plugin/np_utils/np_headers.h +++ b/o3d/gpu_plugin/np_utils/np_headers.h @@ -5,11 +5,6 @@ #ifndef O3D_GPU_PLUGIN_NP_UTILS_NP_HEADERS_H_ #define O3D_GPU_PLUGIN_NP_UTILS_NP_HEADERS_H_ -// This is a hack to work around the differing definitions of NPString in the -// Chrome and O3D NPAPI headers. -#define utf8characters UTF8Characters -#define utf8length UTF8Length - #if defined(O3D_IN_CHROME) #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npruntime.h" @@ -18,9 +13,4 @@ #include "o3d/third_party/npapi/include/npruntime.h" #endif -// Deliberately not including a directory name because Chromium and O3D put -// these headers in different directories. -#undef utf8characters -#undef utf8length - #endif // O3D_GPU_PLUGIN_NP_UTILS_NP_HEADERS_H_ diff --git a/o3d/gpu_plugin/system_services/shared_memory.cc b/o3d/gpu_plugin/system_services/shared_memory.cc deleted file mode 100644 index 10f5719..0000000 --- a/o3d/gpu_plugin/system_services/shared_memory.cc +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "o3d/gpu_plugin/np_utils/np_class.h" -#include "o3d/gpu_plugin/system_services/shared_memory.h" - -namespace gpu_plugin { - -SharedMemory::SharedMemory(NPP npp) - : npp_(npp), - shared_memory_(NULL) { -} - -SharedMemory::~SharedMemory() { -} - -bool SharedMemory::Initialize(int32 size) { - if (size < 0) - return false; - - if (shared_memory_.get()) - return false; - - shared_memory_.reset(new base::SharedMemory()); - if (!shared_memory_->Create(std::wstring(), false, false, size)) { - shared_memory_.reset(); - return false; - } - - return true; -} - -int32 SharedMemory::GetSize() { - return shared_memory_.get() ? shared_memory_->max_size() : 0; -} - -} // namespace gpu_plugin - -void* NPN_MapMemory(NPP npp, NPObject* object, size_t* size) { - *size = 0; - - // Check that the object really is shared memory. - if (object->_class != - gpu_plugin::NPGetClass<gpu_plugin::SharedMemory>()) { - return NULL; - } - - gpu_plugin::SharedMemory* shared_memory_object = - static_cast<gpu_plugin::SharedMemory*>(object); - base::SharedMemory* shared_memory = - shared_memory_object->shared_memory(); - if (!shared_memory) { - return NULL; - } - - if (!shared_memory->memory()) { - shared_memory->Map(shared_memory->max_size()); - } - - *size = shared_memory->max_size(); - return shared_memory->memory(); -} diff --git a/o3d/gpu_plugin/system_services/shared_memory.h b/o3d/gpu_plugin/system_services/shared_memory.h deleted file mode 100644 index b01b6a7..0000000 --- a/o3d/gpu_plugin/system_services/shared_memory.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_H_ -#define O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_H_ - -#include "base/scoped_ptr.h" -#include "base/shared_memory.h" -#include "o3d/gpu_plugin/np_utils/default_np_object.h" -#include "o3d/gpu_plugin/np_utils/np_dispatcher.h" -#include "o3d/gpu_plugin/np_utils/np_object_pointer.h" -#include "o3d/gpu_plugin/np_utils/np_headers.h" - -namespace gpu_plugin { - -// An NPObject holding a shared memory handle. -class SharedMemory : public DefaultNPObject<NPObject> { - public: - explicit SharedMemory(NPP npp); - ~SharedMemory(); - - virtual bool Initialize(int32 size); - - virtual int32 GetSize(); - - ::base::SharedMemory* shared_memory() const { - return shared_memory_.get(); - } - - NP_UTILS_BEGIN_DISPATCHER_CHAIN(SharedMemory, DefaultNPObject<NPObject>) - NP_UTILS_DISPATCHER(Initialize, bool(int32 size)); - NP_UTILS_DISPATCHER(GetSize, int32()) - NP_UTILS_END_DISPATCHER_CHAIN - - private: - NPP npp_; - scoped_ptr< ::base::SharedMemory> shared_memory_; - DISALLOW_COPY_AND_ASSIGN(SharedMemory); -}; - -} // namespace gpu_plugin - -void* NPN_MapMemory(NPP npp, NPObject* object, size_t* size); - -#endif // O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_H_ diff --git a/o3d/gpu_plugin/system_services/shared_memory_mock.h b/o3d/gpu_plugin/system_services/shared_memory_mock.h deleted file mode 100644 index 4ca0d16..0000000 --- a/o3d/gpu_plugin/system_services/shared_memory_mock.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_MOCK_H_ -#define O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_MOCK_H_ - -#include "o3d/gpu_plugin/system_services/shared_memory.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace gpu_plugin { - -class MockSharedMemory : public SharedMemory { - public: - explicit MockSharedMemory(NPP npp) : SharedMemory(npp) { - } - - MOCK_METHOD1(Initialize, bool(int32 size)); - MOCK_METHOD0(GetSize, int32()); - - private: - DISALLOW_COPY_AND_ASSIGN(MockSharedMemory); -}; - -} // namespace gpu_plugin - -#endif // O3D_GPU_PLUGIN_SYSTEM_SERVICES_SHARED_MEMORY_MOCK_H_ diff --git a/o3d/gpu_plugin/system_services/shared_memory_unittest.cc b/o3d/gpu_plugin/system_services/shared_memory_unittest.cc deleted file mode 100644 index 17687ae..0000000 --- a/o3d/gpu_plugin/system_services/shared_memory_unittest.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/process_util.h" -#include "o3d/gpu_plugin/np_utils/np_browser_stub.h" -#include "o3d/gpu_plugin/system_services/shared_memory.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/gmock/include/gmock/gmock.h" - -using testing::_; -using testing::DoAll; -using testing::Return; -using testing::SetArgumentPointee; -using testing::StrictMock; - -namespace gpu_plugin { - -class SharedMemoryTest : public testing::Test { - protected: - virtual void SetUp() { - shared_memory_ = NPCreateObject<SharedMemory>(NULL); - } - - StubNPBrowser stub_browser_; - NPObjectPointer<SharedMemory> shared_memory_; -}; - -TEST_F(SharedMemoryTest, SizeIsaZeroBeforeInitialization) { - EXPECT_EQ(0, shared_memory_->GetSize()); -} - -TEST_F(SharedMemoryTest, InitializesAndReturnsMappedMemory) { - EXPECT_TRUE(shared_memory_->Initialize(65536)); - EXPECT_EQ(65536, shared_memory_->GetSize()); - - size_t size; - int8* ptr = static_cast<int8*>(NPN_MapMemory(NULL, - shared_memory_.Get(), - &size)); - ASSERT_TRUE(NULL != ptr); - EXPECT_EQ(65536, size); - - // Test that memory can be written to. - for (int i = 0; i < 65536; ++i) { - ptr[i] = 7; - } -} - -TEST_F(SharedMemoryTest, MapFailsBeforeInitialization) { - size_t size = 7; - int8* ptr = static_cast<int8*>(NPN_MapMemory(NULL, - shared_memory_.Get(), - &size)); - EXPECT_TRUE(NULL == ptr); - EXPECT_EQ(0, size); -} - -TEST_F(SharedMemoryTest, InitializeFailsForNegativeSize) { - EXPECT_FALSE(shared_memory_->Initialize(-1)); -} - -TEST_F(SharedMemoryTest, SecondCallToInitializeFails) { - EXPECT_TRUE(shared_memory_->Initialize(65536)); - EXPECT_FALSE(shared_memory_->Initialize(65536)); -} - -TEST_F(SharedMemoryTest, InitializeRoundsUpToPageSize) { - EXPECT_TRUE(shared_memory_->Initialize(7)); - EXPECT_EQ(7, shared_memory_->GetSize()); - - size_t size; - int8* ptr = static_cast<int8*>(NPN_MapMemory(NULL, - shared_memory_.Get(), - &size)); - ASSERT_TRUE(NULL != ptr); - EXPECT_EQ(7, size); - - // Test that memory can be written to. - for (int i = 0; i < 7; ++i) { - ptr[i] = 7; - } -} - -TEST_F(SharedMemoryTest, SecondMapDoesNothing) { - EXPECT_TRUE(shared_memory_->Initialize(65536)); - - size_t size1; - int8* ptr1 = static_cast<int8*>(NPN_MapMemory(NULL, - shared_memory_.Get(), - &size1)); - - size_t size2; - int8* ptr2 = static_cast<int8*>(NPN_MapMemory(NULL, - shared_memory_.Get(), - &size2)); - - EXPECT_EQ(ptr1, ptr2); - EXPECT_EQ(65536, size1); - EXPECT_EQ(65536, size2); -} - -} // namespace gpu_plugin diff --git a/o3d/plugin/cross/main.h b/o3d/plugin/cross/main.h index d4e1d24..f8c8512 100644 --- a/o3d/plugin/cross/main.h +++ b/o3d/plugin/cross/main.h @@ -39,7 +39,7 @@ #include "core/cross/renderer_platform.h" -#include <npupp.h> +#include <npfunctions.h> #include <stdio.h> #include <fstream> diff --git a/o3d/plugin/cross/main_remote_cb.cc b/o3d/plugin/cross/main_remote_cb.cc new file mode 100644 index 0000000..e2346ed --- /dev/null +++ b/o3d/plugin/cross/main_remote_cb.cc @@ -0,0 +1,210 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file implements the entry points for the windowless O3D plugin that +// relies on a GPU plugin for output. + +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/logging.h" +#include "base/scoped_ptr.h" +#include "core/cross/command_buffer/renderer_cb.h" +#include "core/cross/command_buffer/display_window_cb.h" +#include "gpu_plugin/command_buffer.h" +#include "gpu_plugin/np_utils/np_browser_stub.h" +#include "gpu_plugin/np_utils/np_object_pointer.h" +#include "gpu_plugin/np_utils/np_utils.h" +#include "plugin/cross/main.h" + +using glue::_o3d::PluginObject; +using glue::StreamManager; +using o3d::Event; +using gpu_plugin::NPObjectPointer; +using gpu_plugin::NPInvoke; + +namespace { +const uint32 kTimerInterval = 16; + +gpu_plugin::NPBrowser* g_browser; + +#if defined(OS_WIN) +const wchar_t* const kLogFile = L"debug.log"; +#else +const char* const kLogFile = "debug.log"; +#endif +} // end anonymous namespace + +#if defined(O3D_INTERNAL_PLUGIN) +namespace o3d { +#else +extern "C" { +#endif + +NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) { + CommandLine::Init(0, NULL); + InitLogging(kLogFile, + logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, + logging::DONT_LOCK_LOG_FILE, + logging::APPEND_TO_OLD_LOG_FILE); + + NPError retval = InitializeNPNApi(browserFuncs); + if (retval != NPERR_NO_ERROR) return retval; + + g_browser = new gpu_plugin::NPBrowser(browserFuncs); + + return NPERR_NO_ERROR; +} + +NPError EXPORT_SYMBOL OSCALL NP_Shutdown(void) { + DLOG(INFO) << "NP_Shutdown"; + + CommandLine::Reset(); + + return NPERR_NO_ERROR; +} + +} // namespace o3d / extern "C" + +namespace o3d { + +NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) { + return NPERR_NO_ERROR; +} + +void OnTimer(NPP instance, uint32 timer_id) { + PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); + if (plugin_object) { + // If the GPU plugin object has been set and the renderer is not initialized + // then attempt to initialize it. + NPObjectPointer<NPObject> gpu_plugin_object( + plugin_object->GetGPUPluginObject()); + if (gpu_plugin_object.Get() && !plugin_object->renderer()) { + NPObjectPointer<NPObject> command_buffer; + if (NPInvoke(plugin_object->npp(), + gpu_plugin_object, + "openCommandBuffer", + &command_buffer)) { + DisplayWindowCB default_display; + default_display.set_npp(plugin_object->npp()); + default_display.set_command_buffer(command_buffer); + plugin_object->CreateRenderer(default_display); + + // Get the GPU plugins size and resize the renderer. + int32 width; + int32 height; + if (NPInvoke(plugin_object->npp(), + gpu_plugin_object, + "getWidth", + &width) && + NPInvoke(plugin_object->npp(), + gpu_plugin_object, + "getHeight", + &height)) { + plugin_object->renderer()->Resize(width, height); + plugin_object->client()->Init(); + } + } + } + + plugin_object->client()->Tick(); + if (plugin_object->client()->render_mode() == + o3d::Client::RENDERMODE_CONTINUOUS) { + plugin_object->client()->RenderClient(true); + } + } +} + +NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, + char *argn[], char *argv[], NPSavedData *saved) { + NPError error = NPN_SetValue( + instance, NPPVpluginWindowBool, reinterpret_cast<void*>(false)); + if (error != NPERR_NO_ERROR) + return error; + + PluginObject* plugin_object = glue::_o3d::PluginObject::Create( + instance); + instance->pdata = plugin_object; + glue::_o3d::InitializeGlue(instance); + plugin_object->Init(argc, argn, argv); + + gpu_plugin::NPBrowser::get()->ScheduleTimer(instance, + kTimerInterval, + true, + OnTimer); + + return NPERR_NO_ERROR; +} + +NPError NPP_Destroy(NPP instance, NPSavedData **save) { + PluginObject *plugin_object = static_cast<PluginObject*>(instance->pdata); + if (plugin_object) { + plugin_object->TearDown(); + NPN_ReleaseObject(plugin_object); + instance->pdata = NULL; + } + + return NPERR_NO_ERROR; +} + +NPError NPP_SetWindow(NPP instance, NPWindow *window) { + return NPERR_NO_ERROR; +} + +// Called when the browser has finished attempting to stream data to +// a file as requested. If fname == NULL the attempt was not successful. +void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) { + PluginObject *plugin_object = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = plugin_object->stream_manager(); + stream_manager->SetStreamFile(stream, fname); +} + +int16 NPP_HandleEvent(NPP instance, void *event) { + return 0; +} +} // namespace o3d + +namespace glue { +namespace _o3d { +bool PluginObject::GetDisplayMode(int mode_id, o3d::DisplayMode *mode) { + return renderer()->GetDisplayMode(mode_id, mode); +} + +// TODO: Where should this really live? It's platform-specific, but in +// PluginObject, which mainly lives in cross/o3d_glue.h+cc. +bool PluginObject::RequestFullscreenDisplay() { + return false; +} + +void PluginObject::CancelFullscreenDisplay() { +} +} // namespace _o3d +} // namespace glue diff --git a/o3d/plugin/cross/np_v8_bridge.cc b/o3d/plugin/cross/np_v8_bridge.cc index 2acdfd8..f898b6b 100644 --- a/o3d/plugin/cross/np_v8_bridge.cc +++ b/o3d/plugin/cross/np_v8_bridge.cc @@ -786,7 +786,7 @@ Local<Value> NPV8Bridge::NPToV8Variant(const NPVariant& np_variant) { { NPString np_string = NPVARIANT_TO_STRING(np_variant); v8_result = Local<Value>::New( - v8::String::New(np_string.utf8characters, np_string.utf8length)); + v8::String::New(np_string.UTF8Characters, np_string.UTF8Length)); break; } case NPVariantType_Object: diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index c52e242..f2cfb4f 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -39,7 +39,10 @@ #include <algorithm> #include "core/cross/renderer.h" #include "core/cross/client_info.h" +#include "core/cross/command_buffer/display_window_cb.h" #include "gpu_plugin/np_utils/np_headers.h" +#include "gpu_plugin/np_utils/np_object_pointer.h" +#include "gpu_plugin/np_utils/np_utils.h" #include "plugin/cross/o3d_glue.h" #include "plugin/cross/config.h" #include "plugin/cross/stream_manager.h" @@ -50,6 +53,11 @@ #include "plugin_mac.h" #endif +using o3d::DisplayWindowCB; +using gpu_plugin::NPObjectPointer; +using gpu_plugin::NPVariantToValue; +using gpu_plugin::ValueToNPVariant; + namespace glue { namespace _o3d { @@ -149,6 +157,9 @@ PluginObject::PluginObject(NPP npp) draw_(true), in_plugin_(false), #endif +#if defined(CB_SERVICE_REMOTE) + gpu_plugin_object_(NULL), +#endif np_v8_bridge_(&service_locator_, npp), stream_manager_(new StreamManager(npp)), cursor_type_(o3d::Cursor::DEFAULT), @@ -400,7 +411,6 @@ bool PluginObject::SetRendererIsSoftware(bool state) { #endif // OS_MACOSX - void PluginObject::RegisterType(const ObjectBase::Class *clientclass, NPClass *npclass) { client_to_np_class_map_[clientclass] = npclass; @@ -472,26 +482,51 @@ void PluginObject::LogAssertHandlerFunction(const std::string& str) { DLOG(ERROR) << "FATAL LOG ERROR: " << str; } +#if defined(CB_SERVICE_REMOTE) +void PluginObject::SetGPUPluginObject(NPObject* gpu_plugin_object) {
+ if (gpu_plugin_object) {
+ NPN_RetainObject(gpu_plugin_object);
+ }
+
+ if (gpu_plugin_object_) {
+ NPN_ReleaseObject(gpu_plugin_object_);
+ }
+
+ gpu_plugin_object_ = gpu_plugin_object;
+}
+#endif + enum { - PROP_CLIENT, - PROP_GPU_CONFIG, - NUM_PROPERTY_IDS + kPropClient, + kPropGpuConfig, + kNumPropertyIds }; -static NPIdentifier property_ids[NUM_PROPERTY_IDS]; -static const NPUTF8 *property_names[NUM_PROPERTY_IDS] = { +static NPIdentifier property_ids[kNumPropertyIds]; +static const NPUTF8 *property_names[kNumPropertyIds] = { "client", "gpuConfig", }; enum { - METHOD_EVAL, - NUM_METHOD_IDS, + kMethodEval, + +#if defined(CB_SERVICE_REMOTE) + kMethodSetGPUPluginObject, + kMethodGetGPUPluginObject, +#endif + + kNumMethodIds, }; -static NPIdentifier method_ids[NUM_METHOD_IDS]; -static const NPUTF8 *method_names[NUM_METHOD_IDS] = { +static NPIdentifier method_ids[kNumMethodIds]; +static const NPUTF8 *method_names[kNumMethodIds] = { "eval", + +#if defined(CB_SERVICE_REMOTE) + "setGPUPluginObject", + "getGPUPluginObject", +#endif }; static NPObject *PluginAllocate(NPP npp, NPClass *npclass) { @@ -505,7 +540,7 @@ static void PluginDeallocate(NPObject *object) { static bool PluginHasMethod(NPObject *header, NPIdentifier name) { DebugScopedId id(name); PluginObject *plugin_object = static_cast<PluginObject *>(header); - for (int i = 0; i < NUM_METHOD_IDS; ++i) { + for (int i = 0; i < kNumMethodIds; ++i) { if (name == method_ids[i]) { return true; } @@ -516,31 +551,51 @@ static bool PluginHasMethod(NPObject *header, NPIdentifier name) { } static bool PluginInvoke(NPObject *header, NPIdentifier name, - const NPVariant *args, uint32_t argCount, + const NPVariant *args, uint32_t arg_count, NPVariant *np_result) { DebugScopedId id(name); PluginObject *plugin_object = static_cast<PluginObject *>(header); - if (name == method_ids[METHOD_EVAL]) { - return plugin_object->np_v8_bridge()->Evaluate(args, argCount, np_result); - } else { + if (name == method_ids[kMethodEval]) { + return plugin_object->np_v8_bridge()->Evaluate(args, arg_count, np_result); + } +#if defined(CB_SERVICE_REMOTE) + else if (name == method_ids[kMethodGetGPUPluginObject]) { + if (arg_count != 0) + return false; + ValueToNPVariant(plugin_object->GetGPUPluginObject(), np_result); + return true; + } else if (name == method_ids[kMethodSetGPUPluginObject]) { + if (arg_count != 1) + return false; + VOID_TO_NPVARIANT(*np_result); + NPObjectPointer<NPObject> gpu_plugin_object; + if (NPVariantToValue(&gpu_plugin_object, args[0])) { + plugin_object->SetGPUPluginObject(gpu_plugin_object.Get()); + return true; + } else { + return false; + } + } // NOLINT +#endif // CB_SERVICE_REMOTE + else { // NOLINT NPObject *globals = plugin_object->globals_npobject(); - return globals->_class->invoke(globals, name, args, argCount, np_result); + return globals->_class->invoke(globals, name, args, arg_count, np_result); } } static bool PluginInvokeDefault(NPObject *header, const NPVariant *args, - uint32_t argCount, NPVariant *result) { + uint32_t arg_count, NPVariant *result) { PluginObject *plugin_object = static_cast<PluginObject *>(header); NPP npp = plugin_object->npp(); NPObject *globals = plugin_object->globals_npobject(); - return globals->_class->invokeDefault(globals, args, argCount, result); + return globals->_class->invokeDefault(globals, args, arg_count, result); } static bool PluginHasProperty(NPObject *header, NPIdentifier name) { DebugScopedId id(name); PluginObject *plugin_object = static_cast<PluginObject *>(header); NPP npp = plugin_object->npp(); - for (unsigned int i = 0; i < NUM_PROPERTY_IDS; ++i) { + for (unsigned int i = 0; i < kNumPropertyIds; ++i) { if (name == property_ids[i]) return true; } NPObject *globals = plugin_object->globals_npobject(); @@ -552,7 +607,7 @@ static bool PluginGetProperty(NPObject *header, NPIdentifier name, DebugScopedId id(name); PluginObject *plugin_object = static_cast<PluginObject *>(header); NPP npp = plugin_object->npp(); - if (name == property_ids[PROP_GPU_CONFIG]) { + if (name == property_ids[kPropGpuConfig]) { // Gets the GPU config (VendorID, DeviceID, name) as a string. // NOTE: this should probably be removed before we ship. o3d::GPUDevice device; @@ -580,7 +635,7 @@ static bool PluginGetProperty(NPObject *header, NPIdentifier name, return temp; } - if (name == property_ids[PROP_CLIENT]) { + if (name == property_ids[kPropClient]) { NPObject *npobject = plugin_object->client_npobject(); GLUE_PROFILE_START(npp, "retainobject"); NPN_RetainObject(npobject); @@ -597,7 +652,7 @@ static bool PluginSetProperty(NPObject *header, NPIdentifier name, DebugScopedId id(name); PluginObject *plugin_object = static_cast<PluginObject *>(header); NPP npp = plugin_object->npp(); - if (name == property_ids[PROP_CLIENT]) { + if (name == property_ids[kPropClient]) { return false; } NPObject *globals = plugin_object->globals_npobject(); @@ -606,18 +661,18 @@ static bool PluginSetProperty(NPObject *header, NPIdentifier name, static bool PluginEnumerate(NPObject *header, NPIdentifier **value, uint32_t *count) { - *count = NUM_PROPERTY_IDS + NUM_METHOD_IDS + glue::GetStaticPropertyCount(); + *count = kNumPropertyIds + kNumMethodIds + glue::GetStaticPropertyCount(); PluginObject *plugin_object = static_cast<PluginObject *>(header); NPP npp = plugin_object->npp(); GLUE_PROFILE_START(npp, "memalloc"); *value = static_cast<NPIdentifier *>( NPN_MemAlloc(*count * sizeof(NPIdentifier))); GLUE_PROFILE_STOP(npp, "memalloc"); - memcpy(*value, property_ids, NUM_PROPERTY_IDS * sizeof(NPIdentifier)); - memcpy(*value + NUM_PROPERTY_IDS, method_ids, - NUM_METHOD_IDS * sizeof(NPIdentifier)); + memcpy(*value, property_ids, kNumPropertyIds * sizeof(NPIdentifier)); + memcpy(*value + kNumPropertyIds, method_ids, + kNumMethodIds * sizeof(NPIdentifier)); glue::StaticEnumeratePropertyHelper( - *value + NUM_PROPERTY_IDS + NUM_METHOD_IDS); + *value + kNumPropertyIds + kNumMethodIds); return true; } @@ -646,8 +701,8 @@ PluginObject *PluginObject::Create(NPP npp) { void InitializeGlue(NPP npp) { GLUE_PROFILE_START(npp, "getstringidentifiers"); - NPN_GetStringIdentifiers(property_names, NUM_PROPERTY_IDS, property_ids); - NPN_GetStringIdentifiers(method_names, NUM_METHOD_IDS, method_ids); + NPN_GetStringIdentifiers(property_names, kNumPropertyIds, property_ids); + NPN_GetStringIdentifiers(method_names, kNumMethodIds, method_ids); GLUE_PROFILE_STOP(npp, "getstringidentifiers"); glue::InitializeGlue(npp); } @@ -896,7 +951,7 @@ void PluginObject::AsyncTick() { } void PluginObject::Tick() { - DCHECK(pending_ticks_ > 0); + DCHECK_GT(pending_ticks_, 0); --pending_ticks_; client_->Tick(); diff --git a/o3d/plugin/cross/o3d_glue.h b/o3d/plugin/cross/o3d_glue.h index 4d2a90c..fb8c5b7 100644 --- a/o3d/plugin/cross/o3d_glue.h +++ b/o3d/plugin/cross/o3d_glue.h @@ -456,6 +456,13 @@ class PluginObject: public NPObject { void set_last_click_time(Time value) { last_click_time_ = value; } #endif +#if defined(CB_SERVICE_REMOTE) + void SetGPUPluginObject(NPObject* gpu_plugin_object); + NPObject* GetGPUPluginObject() { + return gpu_plugin_object_; + } +#endif + private: bool fullscreen_region_valid_; int fullscreen_region_x_; @@ -471,6 +478,10 @@ class PluginObject: public NPObject { HCURSOR hCursor_; bool painted_once_; #endif // OS_WIN + +#if defined(CB_SERVICE_REMOTE) + NPObject* gpu_plugin_object_; +#endif }; } // namespace o3d diff --git a/o3d/plugin/mac/main_mac.mm b/o3d/plugin/mac/main_mac.mm index 3f09e698..e34e6c8 100644 --- a/o3d/plugin/mac/main_mac.mm +++ b/o3d/plugin/mac/main_mac.mm @@ -155,7 +155,7 @@ void DispatchKeyboardEvent(PluginObject* obj, break; case keyUp: type = Event::TYPE_KEYUP; - break; + break; default: return; break; @@ -477,6 +477,8 @@ bool HandleCocoaEvent(NPP instance, NPCocoaEvent* the_event) { } break; + case NPCocoaEventTextInput: + break; } return handled; @@ -651,7 +653,7 @@ NPError OSCALL NP_Initialize(NPNetscapeFuncs* browserFuncs) { #if !defined(O3D_INTERNAL_PLUGIN) // Wrapper that discards the return value to match the expected type of -// NPP_ShutdownUPP. +// NPP_ShutdownProcPtr. void NPP_ShutdownWrapper() { NP_Shutdown(); } @@ -661,7 +663,7 @@ void NPP_ShutdownWrapper() { // to be a main() to call to do basic setup. int main(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, - NPP_ShutdownUPP* shutdownProc) { + NPP_ShutdownProcPtr* shutdownProc) { HANDLE_CRASHES; NPError error = NP_Initialize(browserFuncs); if (error == NPERR_NO_ERROR) @@ -881,7 +883,7 @@ NPError NPP_SetWindow(NPP instance, NPWindow* window) { NSWindow * ns_window = reinterpret_cast<NSWindow*>(np_cg->window); new_window = reinterpret_cast<WindowRef>([ns_window windowRef]); } else { - new_window = np_cg->window; + new_window = static_cast<OpaqueWindowPtr*>(np_cg->window); } obj->mac_2d_context_ = np_cg->context; } diff --git a/o3d/plugin/mac/plugin_mac.h b/o3d/plugin/mac/plugin_mac.h index 85d7c85..2d9d07a 100644 --- a/o3d/plugin/mac/plugin_mac.h +++ b/o3d/plugin/mac/plugin_mac.h @@ -34,7 +34,7 @@ #define O3D_PLUGIN_MAC_PLUGIN_MAC_H_ #include <CoreFoundation/CoreFoundation.h> -#include <npupp.h> +#include <npfunctions.h> #include <AGL/agl.h> #include <vector> diff --git a/o3d/plugin/npapi_host_control/win/dispatch_proxy.h b/o3d/plugin/npapi_host_control/win/dispatch_proxy.h index 64209ec..ceb651f 100644 --- a/o3d/plugin/npapi_host_control/win/dispatch_proxy.h +++ b/o3d/plugin/npapi_host_control/win/dispatch_proxy.h @@ -39,7 +39,7 @@ #include <atlctl.h> #include <dispex.h> -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" #include "plugin/npapi_host_control/win/np_browser_proxy.h" class NPBrowserProxy; diff --git a/o3d/plugin/npapi_host_control/win/np_browser_proxy.cc b/o3d/plugin/npapi_host_control/win/np_browser_proxy.cc index bba80d1..5dad231 100644 --- a/o3d/plugin/npapi_host_control/win/np_browser_proxy.cc +++ b/o3d/plugin/npapi_host_control/win/np_browser_proxy.cc @@ -589,7 +589,7 @@ void NPBrowserProxy::NPN_ReleaseVariantValue(NPVariant *variant) { break; case NPVariantType_String: NPN_MemFree( - const_cast<NPUTF8*>(variant->value.stringValue.utf8characters)); + const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters)); break; case NPVariantType_Object: NPN_ReleaseObject(variant->value.objectValue); @@ -765,7 +765,7 @@ bool NPBrowserProxy::NPN_Evaluate(NPP npp, if (ConstructObject(npp, window_object, "Object", NULL, 0, &result_object)) { CStringA function_code; function_code.Format("result_object.result = (%s);", - script->utf8characters); + script->UTF8Characters); NPVariant args[2]; STRINGZ_TO_NPVARIANT("result_object", args[0]); diff --git a/o3d/plugin/npapi_host_control/win/np_browser_proxy.h b/o3d/plugin/npapi_host_control/win/np_browser_proxy.h index 4c28cea..2bcd63d 100644 --- a/o3d/plugin/npapi_host_control/win/np_browser_proxy.h +++ b/o3d/plugin/npapi_host_control/win/np_browser_proxy.h @@ -47,7 +47,7 @@ #include <dispex.h> #include <map> -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" #include "plugin/npapi_host_control/win/dispatch_proxy.h" #include "plugin/npapi_host_control/win/np_object_proxy.h" diff --git a/o3d/plugin/npapi_host_control/win/np_object_proxy.cc b/o3d/plugin/npapi_host_control/win/np_object_proxy.cc index 4c6ee3b..b70b02b 100644 --- a/o3d/plugin/npapi_host_control/win/np_object_proxy.cc +++ b/o3d/plugin/npapi_host_control/win/np_object_proxy.cc @@ -38,7 +38,7 @@ #include "plugin/npapi_host_control/win/np_object_proxy.h" #include "plugin/npapi_host_control/win/np_browser_proxy.h" #include "plugin/npapi_host_control/win/variant_utils.h" -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" namespace { diff --git a/o3d/plugin/npapi_host_control/win/np_object_proxy.h b/o3d/plugin/npapi_host_control/win/np_object_proxy.h index 4cf20c8..3a290a6 100644 --- a/o3d/plugin/npapi_host_control/win/np_object_proxy.h +++ b/o3d/plugin/npapi_host_control/win/np_object_proxy.h @@ -44,7 +44,7 @@ // type-lib. #include "npapi_host_control.h" -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" struct NPObject; class NPBrowserProxy; diff --git a/o3d/plugin/npapi_host_control/win/np_plugin_proxy.h b/o3d/plugin/npapi_host_control/win/np_plugin_proxy.h index e3f1c9e..f693bf2 100644 --- a/o3d/plugin/npapi_host_control/win/np_plugin_proxy.h +++ b/o3d/plugin/npapi_host_control/win/np_plugin_proxy.h @@ -37,7 +37,7 @@ #define O3D_PLUGIN_NPAPI_HOST_CONTROL_WIN_NP_PLUGIN_PROXY_H_ #include <vector> -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" class NPBrowserProxy; struct INPObjectProxy; diff --git a/o3d/plugin/npapi_host_control/win/stream_operation.h b/o3d/plugin/npapi_host_control/win/stream_operation.h index 25f35cb..6f1ae97 100644 --- a/o3d/plugin/npapi_host_control/win/stream_operation.h +++ b/o3d/plugin/npapi_host_control/win/stream_operation.h @@ -49,7 +49,7 @@ #include <atlstr.h> #include <urlmon.h> -#include "third_party/npapi/include/npupp.h" +#include "third_party/npapi/include/npfunctions.h" class NPPluginProxy; diff --git a/o3d/plugin/npapi_host_control/win/variant_utils.cc b/o3d/plugin/npapi_host_control/win/variant_utils.cc index fd0e441..cdd9499 100644 --- a/o3d/plugin/npapi_host_control/win/variant_utils.cc +++ b/o3d/plugin/npapi_host_control/win/variant_utils.cc @@ -183,14 +183,14 @@ void NPVariantToVariant(NPBrowserProxy* browser_proxy, int required_size = 0; required_size = MultiByteToWideChar( CP_UTF8, 0, - source->value.stringValue.utf8characters, - source->value.stringValue.utf8length, NULL, 0); + source->value.stringValue.UTF8Characters, + source->value.stringValue.UTF8Length, NULL, 0); scoped_array<wchar_t> wide_value(new wchar_t[required_size + 1]); MultiByteToWideChar( CP_UTF8, 0, - source->value.stringValue.utf8characters, - source->value.stringValue.utf8length, wide_value.get(), + source->value.stringValue.UTF8Characters, + source->value.stringValue.UTF8Length, wide_value.get(), required_size + 1); wide_value[required_size] = 0; diff --git a/o3d/plugin/plugin.gyp b/o3d/plugin/plugin.gyp index 15ebabd..10cb1c4 100644 --- a/o3d/plugin/plugin.gyp +++ b/o3d/plugin/plugin.gyp @@ -119,7 +119,6 @@ ], 'sources': [ 'mac/config_mac.mm', - 'mac/main_mac.mm', 'mac/o3d_plugin.r', 'mac/plugin_logging-mac.mm', 'mac/plugin_mac.h', @@ -189,10 +188,16 @@ ], }, ], + ['OS == "mac" and cb_service != "remote"', + { + 'sources': [ + 'mac/main_mac.mm', + ], + }, + ], ['OS == "linux"', { 'sources': [ - 'linux/main_linux.cc', 'linux/config.cc', 'linux/envvars.cc', ], @@ -206,6 +211,13 @@ ], }, ], + ['OS == "linux" and cb_service != "remote"', + { + 'sources': [ + 'linux/main_linux.cc', + ], + }, + ], ['OS == "win"', { 'dependencies': [ @@ -214,7 +226,6 @@ 'sources': [ 'win/config.cc', 'win/logger_main.cc', - 'win/main_win.cc', 'win/o3dPlugin.def', 'win/o3dPlugin.rc', 'win/plugin_logging-win32.cc', @@ -229,6 +240,13 @@ }, }, ], + ['OS == "win" and cb_service != "remote"', + { + 'sources': [ + 'win/main_win.cc', + ], + }, + ], ['OS == "win" and renderer == "d3d9"', { 'link_settings': { @@ -239,7 +257,7 @@ }, }, ], - ['OS == "win" and (renderer == "d3d9" or cb_service == "d3d9")', + ['OS == "win" and (renderer == "d3d9" or cb_service == "d3d9" or cb_service == "remote")', { 'link_settings': { 'libraries': [ @@ -248,6 +266,13 @@ }, }, ], + ['cb_service == "remote"', + { + 'sources': [ + 'cross/main_remote_cb.cc', + ], + }, + ], ], }, ], diff --git a/o3d/tests/tests.gyp b/o3d/tests/tests.gyp index 8942228..27e48a6 100644 --- a/o3d/tests/tests.gyp +++ b/o3d/tests/tests.gyp @@ -105,10 +105,16 @@ ['renderer == "cb"', { 'dependencies': [ + '../gpu_plugin/gpu_plugin.gyp:np_utils', + ] + }, + ], + ['renderer == "cb" and cb_service != "remote"', + { + 'dependencies': [ '../command_buffer/command_buffer.gyp:command_buffer_client_test', '../command_buffer/command_buffer.gyp:command_buffer_common_test', '../command_buffer/command_buffer.gyp:command_buffer_service_test', - '../gpu_plugin/gpu_plugin.gyp:np_utils', ] }, ], |