diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 00:41:08 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 00:41:08 +0000 |
commit | f90ef342b3dcacd675f630caa63626573cfe032a (patch) | |
tree | 724d4466908a72d5bee0abd8ec0bb437acd26810 /o3d/core | |
parent | 07f25e82ef962a56a791d115720f57957d84d782 (diff) | |
download | chromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.zip chromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.tar.gz chromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.tar.bz2 |
Switched from NPObject shared memory wrapper to Chrome shared memory in preparation for moving from NPAPI to Chrome IPC for synchronous messages.
Started work on an O3D configuration that will use Pepper 3D to connect to a remote GPU plugin. This is not building yet.
Updated to latest NPAPI from nixysa.
Review URL: http://codereview.chromium.org/371074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r-- | o3d/core/core.gyp | 17 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/display_window_cb.h | 9 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/renderer_cb.cc | 139 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/renderer_cb.h | 57 |
4 files changed, 96 insertions, 126 deletions
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 |