diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-16 23:24:41 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-16 23:24:41 +0000 |
commit | ba1d6b0893d6d07cf1fb924f4212446d4e6136d4 (patch) | |
tree | 1a614a02f797a7e172a72c99857debbd9706d28f | |
parent | 8ca3290c9c7bc8dfff4520562290363c71cf0235 (diff) | |
download | chromium_src-ba1d6b0893d6d07cf1fb924f4212446d4e6136d4.zip chromium_src-ba1d6b0893d6d07cf1fb924f4212446d4e6136d4.tar.gz chromium_src-ba1d6b0893d6d07cf1fb924f4212446d4e6136d4.tar.bz2 |
Renamed CommandBuffer to CommandBufferServer and extracted CommandBuffer interface.
Moved np_utils classes into new np_utils namespace.
Removed some of the command_buffer dependencies on NPAPI.
CommandBuffer(Server) is no longer an NPObject.
Review URL: http://codereview.chromium.org/387063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32119 0039d316-1c4b-4281-b951-d872f2087c98
59 files changed, 529 insertions, 515 deletions
diff --git a/o3d/core/core.gyp b/o3d/core/core.gyp index 1f3afa8..11b4d33 100644 --- a/o3d/core/core.gyp +++ b/o3d/core/core.gyp @@ -431,10 +431,6 @@ { 'dependencies': [ '../gpu/gpu.gyp:command_buffer_service', - - # These dependencies are only needed for RendererCBLocal. They can - # be removed when RendererCBLocal is not needed. - '../gpu/gpu.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 74486bf..a855457 100644 --- a/o3d/core/cross/command_buffer/display_window_cb.h +++ b/o3d/core/cross/command_buffer/display_window_cb.h @@ -34,8 +34,7 @@ #define O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_ #include "core/cross/display_window.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/np_utils/np_object_pointer.h" +#include "gpu/command_buffer/common/command_buffer.h" namespace o3d { @@ -43,25 +42,14 @@ namespace o3d { // an out-of-process command buffer renderer. class DisplayWindowCB : public DisplayWindow { public: - DisplayWindowCB() : npp_(NULL), width_(0), height_(0) {} + DisplayWindowCB() : width_(0), height_(0) {} virtual ~DisplayWindowCB() {} - NPP npp() const { - return npp_; - } - - void set_npp(NPP npp) { - npp_ = npp; - } - - gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> - command_buffer() const { + command_buffer::CommandBuffer* command_buffer() const { return command_buffer_; } - void set_command_buffer( - const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> - command_buffer) { + void set_command_buffer(command_buffer::CommandBuffer* command_buffer) { command_buffer_ = command_buffer; } @@ -82,8 +70,7 @@ class DisplayWindowCB : public DisplayWindow { } private: - NPP npp_; - gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; + command_buffer::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 a6a07d8..3ea8db5 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.cc +++ b/o3d/core/cross/command_buffer/renderer_cb.cc @@ -49,29 +49,26 @@ #include "core/cross/command_buffer/texture_cb.h" #include "core/cross/command_buffer/display_window_cb.h" #include "core/cross/renderer_platform.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/np_browser.h" #include "gpu/np_utils/np_utils.h" -#if !defined(CB_SERVICE_REMOTE) -#include "gpu/gpu_plugin/gpu_processor.h" -#endif - namespace o3d { using ::base::SharedMemory; +using ::command_buffer::CommandBufferService; using command_buffer::o3d::GAPIInterface; using command_buffer::O3DCmdHelper; -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 np_utils::NPBrowser; +using np_utils::NPCreateObject; +using np_utils::NPGetProperty; +using np_utils::NPInvoke; +using np_utils::NPInvokeVoid; +using np_utils::NPObjectPointer; #if !defined(CB_SERVICE_REMOTE) -using gpu_plugin::CommandBuffer; -using gpu_plugin::GPUProcessor; +using command_buffer::CommandBuffer; +using command_buffer::GPUProcessor; #endif RendererCB::RendererCB(ServiceLocator* service_locator, @@ -94,7 +91,7 @@ RendererCB::~RendererCB() { } void RendererCB::Destroy() { - if (command_buffer_.Get()) { + if (command_buffer_.get()) { command_buffer_->DestroyTransferBuffer(transfer_shm_id_); } @@ -294,12 +291,11 @@ Renderer::InitStatus RendererCB::InitPlatformSpecific( const DisplayWindowCB& display_platform = static_cast<const DisplayWindowCB&>(display_window); - npp_ = display_platform.npp(); - command_buffer_ = display_platform.command_buffer(); - DCHECK(command_buffer_.Get()); + command_buffer_.reset(display_platform.command_buffer()); + DCHECK(command_buffer_.get()); // Create and initialize a O3DCmdHelper. - helper_ = new O3DCmdHelper(npp_, command_buffer_); + helper_ = new O3DCmdHelper(command_buffer_.get()); if (!helper_->Initialize()) { Destroy(); return INITIALIZATION_ERROR; @@ -384,33 +380,33 @@ RendererCBLocal::RendererCBLocal(ServiceLocator* service_locator, RendererCBLocal::~RendererCBLocal() { } -NPObjectPointer<CommandBuffer> RendererCBLocal::CreateCommandBuffer( - NPP npp, void* hwnd, int32 size) { +CommandBuffer* RendererCBLocal::CreateCommandBuffer(NPP npp, + void* hwnd, + int32 size) { #if defined(OS_WIN) scoped_ptr<SharedMemory> ring_buffer(new SharedMemory); if (!ring_buffer->Create(std::wstring(), false, false, size)) - return NPObjectPointer<CommandBuffer>(); + return NULL; if (!ring_buffer->Map(size)) - return NPObjectPointer<CommandBuffer>(); + return NULL; - NPObjectPointer<CommandBuffer> command_buffer = - NPCreateObject<CommandBuffer>(npp); + scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService); if (!command_buffer->Initialize(ring_buffer.release())) - return NPObjectPointer<CommandBuffer>(); + return NULL; scoped_refptr<GPUProcessor> gpu_processor( - new GPUProcessor(npp, command_buffer.Get())); + new GPUProcessor(npp, command_buffer.get())); if (!gpu_processor->Initialize(reinterpret_cast<HWND>(hwnd))) - return NPObjectPointer<CommandBuffer>(); + return NULL; command_buffer->SetPutOffsetChangeCallback( NewCallback(gpu_processor.get(), &GPUProcessor::ProcessCommands)); - return command_buffer; + return command_buffer.release(); #else - return NPObjectPointer<CommandBuffer>(); + return NULL; #endif } diff --git a/o3d/core/cross/command_buffer/renderer_cb.h b/o3d/core/cross/command_buffer/renderer_cb.h index 9168bb5..56b1d17 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.h +++ b/o3d/core/cross/command_buffer/renderer_cb.h @@ -39,11 +39,11 @@ #include "core/cross/precompile.h" #include <vector> #include "core/cross/renderer.h" +#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/constants.h" #include "gpu/command_buffer/common/resource.h" #include "gpu/command_buffer/client/fenced_allocator.h" #include "gpu/command_buffer/client/id_allocator.h" -#include "gpu/gpu_plugin/command_buffer.h" #include "gpu/np_utils/np_object_pointer.h" namespace command_buffer { @@ -249,6 +249,7 @@ class RendererCB : public Renderer { protected: // Initializes the renderer for use, claiming hardware resources. + // Takes ownership of CommandBuffer. virtual InitStatus InitPlatformSpecific(const DisplayWindow& display_window, bool off_screen); @@ -258,7 +259,7 @@ class RendererCB : public Renderer { int32 transfer_shm_id_; void *transfer_shm_address_; NPP npp_; - gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; + scoped_ptr<::command_buffer::CommandBuffer> command_buffer_; ::command_buffer::O3DCmdHelper *helper_; ::command_buffer::FencedAllocatorWrapper *allocator_; @@ -305,8 +306,8 @@ class RendererCBRemote : public RendererCB { // code in RendererCBRemote will be merged into RendererCB. class RendererCBLocal : public RendererCB { public: - static gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> - CreateCommandBuffer(NPP npp, void* hwnd, int32 size); + static ::command_buffer::CommandBuffer* CreateCommandBuffer( + NPP npp, void* hwnd, int32 size); // Creates a default RendererCBLocal. static RendererCBLocal *CreateDefault(ServiceLocator* service_locator); diff --git a/o3d/gpu/command_buffer/client/cmd_buffer_helper.cc b/o3d/gpu/command_buffer/client/cmd_buffer_helper.cc index e6a49d1..e8f6fef 100644 --- a/o3d/gpu/command_buffer/client/cmd_buffer_helper.cc +++ b/o3d/gpu/command_buffer/client/cmd_buffer_helper.cc @@ -33,20 +33,18 @@ // This file contains the implementation of the command buffer helper class. #include "gpu/command_buffer/client/cmd_buffer_helper.h" +#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/np_utils/np_utils.h" namespace command_buffer { -using gpu_plugin::CommandBuffer; -using gpu_plugin::NPBrowser; -using gpu_plugin::NPInvoke; -using gpu_plugin::NPObjectPointer; +using command_buffer::CommandBuffer; +using np_utils::NPBrowser; +using np_utils::NPInvoke; +using np_utils::NPObjectPointer; -CommandBufferHelper::CommandBufferHelper( - NPP npp, - const NPObjectPointer<CommandBuffer>& command_buffer) - : npp_(npp), - command_buffer_(command_buffer), +CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) + : command_buffer_(command_buffer), entries_(NULL), entry_count_(0), token_(0), diff --git a/o3d/gpu/command_buffer/client/cmd_buffer_helper.h b/o3d/gpu/command_buffer/client/cmd_buffer_helper.h index f416baa..7cac568 100644 --- a/o3d/gpu/command_buffer/client/cmd_buffer_helper.h +++ b/o3d/gpu/command_buffer/client/cmd_buffer_helper.h @@ -38,8 +38,7 @@ #include "gpu/command_buffer/common/logging.h" #include "gpu/command_buffer/common/constants.h" #include "gpu/command_buffer/common/cmd_buffer_common.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/np_utils/np_object_pointer.h" +#include "gpu/command_buffer/common/command_buffer.h" namespace command_buffer { @@ -60,10 +59,7 @@ namespace command_buffer { // // commands have been executed. class CommandBufferHelper { public: - CommandBufferHelper( - NPP npp, - const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>& - command_buffer); + explicit CommandBufferHelper(command_buffer::CommandBuffer* command_buffer); virtual ~CommandBufferHelper(); bool Initialize(); @@ -202,8 +198,7 @@ class CommandBufferHelper { return (get_ - put_ - 1 + entry_count_) % entry_count_; } - NPP npp_; - gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer> command_buffer_; + command_buffer::CommandBuffer* command_buffer_; ::base::SharedMemory* ring_buffer_; CommandBufferEntry *entries_; int32 entry_count_; diff --git a/o3d/gpu/command_buffer/client/cmd_buffer_helper_test.cc b/o3d/gpu/command_buffer/client/cmd_buffer_helper_test.cc index 6f7dcfb..413b561 100644 --- a/o3d/gpu/command_buffer/client/cmd_buffer_helper_test.cc +++ b/o3d/gpu/command_buffer/client/cmd_buffer_helper_test.cc @@ -36,18 +36,18 @@ #include "base/message_loop.h" #include "gpu/command_buffer/client/cmd_buffer_helper.h" #include "gpu/command_buffer/service/mocks.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/np_object_pointer.h" #include "gpu/np_utils/np_browser_stub.h" #include "testing/gtest/include/gtest/gtest.h" namespace command_buffer { -using gpu_plugin::CommandBuffer; -using gpu_plugin::GPUProcessor; -using gpu_plugin::NPCreateObject; -using gpu_plugin::NPObjectPointer; +using command_buffer::CommandBufferService; +using command_buffer::GPUProcessor; +using np_utils::NPCreateObject; +using np_utils::NPObjectPointer; using testing::Return; using testing::Mock; using testing::Truly; @@ -75,7 +75,7 @@ class CommandBufferHelperTest : public testing::Test { ring_buffer->Create(std::wstring(), false, false, kCommandBufferSizeBytes); ring_buffer->Map(1024); - command_buffer_ = NPCreateObject<CommandBuffer>(NULL); + command_buffer_.reset(new CommandBufferService); command_buffer_->Initialize(ring_buffer); parser_ = new command_buffer::CommandParser(ring_buffer->memory(), @@ -86,13 +86,13 @@ class CommandBufferHelperTest : public testing::Test { api_mock_.get()); scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( - NULL, command_buffer_.Get(), NULL, NULL, parser_, 1)); + command_buffer_.get(), NULL, NULL, parser_, 1)); command_buffer_->SetPutOffsetChangeCallback(NewCallback( gpu_processor.get(), &GPUProcessor::ProcessCommands)); api_mock_->set_engine(gpu_processor.get()); - helper_.reset(new CommandBufferHelper(NULL, command_buffer_)); + helper_.reset(new CommandBufferHelper(command_buffer_.get())); helper_->Initialize(); } @@ -142,9 +142,9 @@ class CommandBufferHelperTest : public testing::Test { base::AtExitManager at_exit_manager_; MessageLoop message_loop_; - gpu_plugin::StubNPBrowser browser_; + np_utils::StubNPBrowser browser_; scoped_ptr<AsyncAPIMock> api_mock_; - NPObjectPointer<CommandBuffer> command_buffer_; + scoped_ptr<CommandBufferService> command_buffer_; command_buffer::CommandParser* parser_; scoped_ptr<CommandBufferHelper> helper_; Sequence sequence_; diff --git a/o3d/gpu/command_buffer/client/fenced_allocator_test.cc b/o3d/gpu/command_buffer/client/fenced_allocator_test.cc index 992acde..2a1c81d 100644 --- a/o3d/gpu/command_buffer/client/fenced_allocator_test.cc +++ b/o3d/gpu/command_buffer/client/fenced_allocator_test.cc @@ -37,18 +37,18 @@ #include "gpu/command_buffer/client/fenced_allocator.h" #include "gpu/command_buffer/service/cmd_buffer_engine.h" #include "gpu/command_buffer/service/mocks.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/np_browser_stub.h" #include "gpu/np_utils/np_object_pointer.h" #include "testing/gtest/include/gtest/gtest.h" namespace command_buffer { -using gpu_plugin::CommandBuffer; -using gpu_plugin::GPUProcessor; -using gpu_plugin::NPCreateObject; -using gpu_plugin::NPObjectPointer; +using command_buffer::CommandBufferService; +using command_buffer::GPUProcessor; +using np_utils::NPCreateObject; +using np_utils::NPObjectPointer; using testing::Return; using testing::Mock; using testing::Truly; @@ -76,7 +76,7 @@ class BaseFencedAllocatorTest : public testing::Test { ring_buffer->Create(std::wstring(), false, false, 1024); ring_buffer->Map(1024); - command_buffer_ = NPCreateObject<CommandBuffer>(NULL); + command_buffer_.reset(new CommandBufferService); command_buffer_->Initialize(ring_buffer); parser_ = new command_buffer::CommandParser(ring_buffer->memory(), @@ -87,13 +87,13 @@ class BaseFencedAllocatorTest : public testing::Test { api_mock_.get()); scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( - NULL, command_buffer_.Get(), NULL, NULL, parser_, INT_MAX)); + command_buffer_.get(), NULL, NULL, parser_, INT_MAX)); command_buffer_->SetPutOffsetChangeCallback(NewCallback( gpu_processor.get(), &GPUProcessor::ProcessCommands)); api_mock_->set_engine(gpu_processor.get()); - helper_.reset(new CommandBufferHelper(NULL, command_buffer_)); + helper_.reset(new CommandBufferHelper(command_buffer_.get())); helper_->Initialize(); } @@ -102,9 +102,9 @@ class BaseFencedAllocatorTest : public testing::Test { } MessageLoop message_loop_; - gpu_plugin::StubNPBrowser browser_; + np_utils::StubNPBrowser browser_; scoped_ptr<AsyncAPIMock> api_mock_; - NPObjectPointer<CommandBuffer> command_buffer_; + scoped_ptr<CommandBufferService> command_buffer_; command_buffer::CommandParser* parser_; scoped_ptr<CommandBufferHelper> helper_; }; diff --git a/o3d/gpu/command_buffer/client/gles2_cmd_helper.h b/o3d/gpu/command_buffer/client/gles2_cmd_helper.h index 87f3054..578e4c8 100644 --- a/o3d/gpu/command_buffer/client/gles2_cmd_helper.h +++ b/o3d/gpu/command_buffer/client/gles2_cmd_helper.h @@ -15,11 +15,8 @@ namespace gles2 { // A class that helps write GL command buffers. class GLES2CmdHelper : public CommandBufferHelper { public: - GLES2CmdHelper( - NPP npp, - const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>& - command_buffer) - : CommandBufferHelper(npp, command_buffer) { + explicit GLES2CmdHelper(command_buffer::CommandBuffer* command_buffer) + : CommandBufferHelper(command_buffer) { } virtual ~GLES2CmdHelper() { } @@ -29,6 +26,7 @@ class GLES2CmdHelper : public CommandBufferHelper { // file instead of having to edit some template or the code generator. #include "gpu/command_buffer/client/gles2_cmd_helper_autogen.h" + private: DISALLOW_COPY_AND_ASSIGN(GLES2CmdHelper); }; diff --git a/o3d/gpu/command_buffer/client/o3d_cmd_helper.h b/o3d/gpu/command_buffer/client/o3d_cmd_helper.h index 0dbbff4..535da21 100644 --- a/o3d/gpu/command_buffer/client/o3d_cmd_helper.h +++ b/o3d/gpu/command_buffer/client/o3d_cmd_helper.h @@ -35,22 +35,18 @@ #ifndef GPU_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ #define GPU_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ +#include "gpu/command_buffer/client/cmd_buffer_helper.h" #include "gpu/command_buffer/common/logging.h" #include "gpu/command_buffer/common/constants.h" -#include "gpu/command_buffer/client/cmd_buffer_helper.h" #include "gpu/command_buffer/common/o3d_cmd_format.h" -#include "gpu/np_utils/np_object_pointer.h" namespace command_buffer { // A helper for O3D command buffers. class O3DCmdHelper : public CommandBufferHelper { public: - O3DCmdHelper( - NPP npp, - const gpu_plugin::NPObjectPointer<gpu_plugin::CommandBuffer>& - command_buffer) - : CommandBufferHelper(npp, command_buffer) { + explicit O3DCmdHelper(command_buffer::CommandBuffer* command_buffer) + : CommandBufferHelper(command_buffer) { } virtual ~O3DCmdHelper() { } diff --git a/o3d/gpu/gpu_plugin/command_buffer.h b/o3d/gpu/command_buffer/common/command_buffer.h index c92e0f3..3ce841a 100644 --- a/o3d/gpu/gpu_plugin/command_buffer.h +++ b/o3d/gpu/command_buffer/common/command_buffer.h @@ -2,50 +2,45 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GPU_GPU_PLUGIN_COMMAND_BUFFER_H_ -#define GPU_GPU_PLUGIN_COMMAND_BUFFER_H_ +#ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ +#define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ -#include <set> -#include <vector> - -#include "base/linked_ptr.h" -#include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/task.h" -#include "gpu/np_utils/default_np_object.h" -#include "gpu/np_utils/np_dispatcher.h" -namespace gpu_plugin { +namespace command_buffer { -// An NPObject that implements a shared memory command buffer and a synchronous -// API to manage the put and get pointers. -class CommandBuffer : public DefaultNPObject<NPObject> { +// Common interface for CommandBuffer implementations. +class CommandBuffer { public: - explicit CommandBuffer(NPP npp); - virtual ~CommandBuffer(); + CommandBuffer() { + } + + virtual ~CommandBuffer() { + } // Initialize the command buffer with the given ring buffer. Takes ownership // of ring buffer. - virtual bool Initialize(::base::SharedMemory* ring_buffer); + virtual bool Initialize(::base::SharedMemory* ring_buffer) = 0; // Gets the shared memory ring buffer object for the command buffer. - virtual ::base::SharedMemory* GetRingBuffer(); + virtual ::base::SharedMemory* GetRingBuffer() = 0; - virtual int32 GetSize(); + virtual int32 GetSize() = 0; // The writer calls this to update its put offset. This function returns the // reader's most recent get offset. Does not return until after the put offset // change callback has been invoked. Returns -1 if the put offset is invalid. - virtual int32 SyncOffsets(int32 put_offset); + virtual int32 SyncOffsets(int32 put_offset) = 0; // Returns the current get offset. This can be called from any thread. - virtual int32 GetGetOffset(); + virtual int32 GetGetOffset() = 0; // Sets the current get offset. This can be called from any thread. - virtual void SetGetOffset(int32 get_offset); + virtual void SetGetOffset(int32 get_offset) = 0; // Returns the current put offset. This can be called from any thread. - virtual int32 GetPutOffset(); + virtual int32 GetPutOffset() = 0; // Sets a callback that should be posted on another thread whenever the put // offset is changed. The callback must not return until some progress has @@ -57,74 +52,46 @@ class CommandBuffer : public DefaultNPObject<NPObject> { // the use of a synchronization primitive like a condition variable to // synchronize reader and writer reduces the risk of deadlock. // Takes ownership of callback. The callback is invoked on the plugin thread. - virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); + virtual void SetPutOffsetChangeCallback(Callback0::Type* callback) = 0; // Create a shared memory transfer buffer and return a handle that uniquely // identifies it or -1 on error. - virtual int32 CreateTransferBuffer(size_t size); + virtual int32 CreateTransferBuffer(size_t size) = 0; // Destroy a shared memory transfer buffer and recycle the handle. - virtual void DestroyTransferBuffer(int32 id); + virtual void DestroyTransferBuffer(int32 id) = 0; // Get the shared memory associated with a handle. - virtual ::base::SharedMemory* GetTransferBuffer(int32 handle); + virtual ::base::SharedMemory* GetTransferBuffer(int32 handle) = 0; // 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 // point in the command buffer. The reader is responsible for updating the // token value, for example in response to an asynchronous set token command // embedded in the command buffer. The default token value is zero. - int32 GetToken() { - return token_; - } + virtual int32 GetToken() = 0; // Allows the reader to update the current token value. - void SetToken(int32 token) { - token_ = token; - } + virtual void SetToken(int32 token) = 0; // Get the current parse error and reset it to zero. Zero means no error. Non- // zero means error. The default error status is zero. - int32 ResetParseError(); + virtual int32 ResetParseError() = 0; // Allows the reader to set the current parse error. - void SetParseError(int32 parse_error); + virtual void SetParseError(int32 parse_error) = 0; // Returns whether the command buffer is in the error state. - bool GetErrorStatus() { - return error_status_; - } + virtual bool GetErrorStatus() = 0; // Allows the reader to set the error status. Once in an error state, the // command buffer cannot recover and ceases to process commands. - void RaiseErrorStatus() { - error_status_ = true; - } - - NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<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(GetToken, int32()); - NP_UTILS_DISPATCHER(ResetParseError, int32()); - NP_UTILS_DISPATCHER(GetErrorStatus, bool()); - NP_UTILS_END_DISPATCHER_CHAIN + virtual void RaiseErrorStatus() = 0; private: - NPP npp_; - scoped_ptr< ::base::SharedMemory> ring_buffer_; - int32 size_; - int32 get_offset_; - int32 put_offset_; - scoped_ptr<Callback0::Type> put_offset_change_callback_; - std::vector<linked_ptr< ::base::SharedMemory> > registered_objects_; - std::set<int32> unused_registered_object_elements_; - int32 token_; - int32 parse_error_; - bool error_status_; + DISALLOW_COPY_AND_ASSIGN(CommandBuffer); }; -} // namespace gpu_plugin +} // namespace command_buffer -#endif // GPU_GPU_PLUGIN_COMMAND_BUFFER_H_ +#endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ diff --git a/o3d/gpu/gpu_plugin/command_buffer_mock.h b/o3d/gpu/command_buffer/common/command_buffer_mock.h index bb55f52..faa5536 100644 --- a/o3d/gpu/gpu_plugin/command_buffer_mock.h +++ b/o3d/gpu/command_buffer/common/command_buffer_mock.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GPU_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_ -#define GPU_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_ +#ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_MOCK_H_ +#define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_MOCK_H_ -#include "gpu/gpu_plugin/command_buffer.h" +#include "gpu/command_buffer/common/command_buffer.h" #include "testing/gmock/include/gmock/gmock.h" -namespace gpu_plugin { +namespace command_buffer { // An NPObject that implements a shared memory command buffer and a synchronous // API to manage the put and get pointers. class MockCommandBuffer : public CommandBuffer { public: - explicit MockCommandBuffer(NPP npp) : CommandBuffer(npp) { + MockCommandBuffer() { ON_CALL(*this, GetRingBuffer()) .WillByDefault(testing::Return(static_cast<::base::SharedMemory*>(NULL))); ON_CALL(*this, GetTransferBuffer(testing::_)) @@ -32,11 +32,17 @@ class MockCommandBuffer : public CommandBuffer { MOCK_METHOD1(CreateTransferBuffer, int32(size_t size)); MOCK_METHOD1(DestroyTransferBuffer, void(int32 handle)); MOCK_METHOD1(GetTransferBuffer, ::base::SharedMemory*(int32 handle)); + MOCK_METHOD0(GetToken, int32()); + MOCK_METHOD1(SetToken, void(int32 token)); + MOCK_METHOD0(ResetParseError, int32()); + MOCK_METHOD1(SetParseError, void(int32 parse_erro)); + MOCK_METHOD0(GetErrorStatus, bool()); + MOCK_METHOD0(RaiseErrorStatus, void()); private: DISALLOW_COPY_AND_ASSIGN(MockCommandBuffer); }; -} // namespace gpu_plugin +} // namespace command_buffer -#endif // GPU_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_ +#endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_MOCK_H_ diff --git a/o3d/gpu/gpu_plugin/command_buffer.cc b/o3d/gpu/command_buffer/service/command_buffer_service.cc index b293693..1ab2a9b 100644 --- a/o3d/gpu/gpu_plugin/command_buffer.cc +++ b/o3d/gpu/command_buffer/service/command_buffer_service.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/gpu_plugin/command_buffer.h" +#include "gpu/command_buffer/service/command_buffer_service.h" using ::base::SharedMemory; -namespace gpu_plugin { +namespace command_buffer { -CommandBuffer::CommandBuffer(NPP npp) - : npp_(npp), - size_(0), +CommandBufferService::CommandBufferService() + : size_(0), get_offset_(0), put_offset_(0), token_(0), @@ -20,10 +19,10 @@ CommandBuffer::CommandBuffer(NPP npp) registered_objects_.push_back(linked_ptr<SharedMemory>()); } -CommandBuffer::~CommandBuffer() { +CommandBufferService::~CommandBufferService() { } -bool CommandBuffer::Initialize(::base::SharedMemory* ring_buffer) { +bool CommandBufferService::Initialize(::base::SharedMemory* ring_buffer) { DCHECK(ring_buffer); // Fail if already initialized. @@ -37,15 +36,15 @@ bool CommandBuffer::Initialize(::base::SharedMemory* ring_buffer) { return true; } -SharedMemory* CommandBuffer::GetRingBuffer() { +SharedMemory* CommandBufferService::GetRingBuffer() { return ring_buffer_.get(); } -int32 CommandBuffer::GetSize() { +int32 CommandBufferService::GetSize() { return size_; } -int32 CommandBuffer::SyncOffsets(int32 put_offset) { +int32 CommandBufferService::SyncOffsets(int32 put_offset) { if (put_offset < 0 || put_offset >= size_) return -1; @@ -58,24 +57,25 @@ int32 CommandBuffer::SyncOffsets(int32 put_offset) { return get_offset_; } -int32 CommandBuffer::GetGetOffset() { +int32 CommandBufferService::GetGetOffset() { return get_offset_; } -void CommandBuffer::SetGetOffset(int32 get_offset) { +void CommandBufferService::SetGetOffset(int32 get_offset) { DCHECK(get_offset >= 0 && get_offset < size_); get_offset_ = get_offset; } -int32 CommandBuffer::GetPutOffset() { +int32 CommandBufferService::GetPutOffset() { return put_offset_; } -void CommandBuffer::SetPutOffsetChangeCallback(Callback0::Type* callback) { +void CommandBufferService::SetPutOffsetChangeCallback( + Callback0::Type* callback) { put_offset_change_callback_.reset(callback); } -int32 CommandBuffer::CreateTransferBuffer(size_t size) { +int32 CommandBufferService::CreateTransferBuffer(size_t size) { linked_ptr<SharedMemory> buffer(new SharedMemory); if (!buffer->Create(std::wstring(), false, false, size)) return -1; @@ -98,7 +98,7 @@ int32 CommandBuffer::CreateTransferBuffer(size_t size) { return handle; } -void CommandBuffer::DestroyTransferBuffer(int32 handle) { +void CommandBufferService::DestroyTransferBuffer(int32 handle) { if (handle <= 0) return; @@ -118,7 +118,7 @@ void CommandBuffer::DestroyTransferBuffer(int32 handle) { } } -::base::SharedMemory* CommandBuffer::GetTransferBuffer(int32 handle) { +::base::SharedMemory* CommandBufferService::GetTransferBuffer(int32 handle) { if (handle < 0) return NULL; @@ -128,16 +128,32 @@ void CommandBuffer::DestroyTransferBuffer(int32 handle) { return registered_objects_[handle].get(); } -int32 CommandBuffer::ResetParseError() { +int32 CommandBufferService::GetToken() { + return token_; +} + +void CommandBufferService::SetToken(int32 token) { + token_ = token; +} + +int32 CommandBufferService::ResetParseError() { int32 last_error = parse_error_; parse_error_ = 0; return last_error; } -void CommandBuffer::SetParseError(int32 parse_error) { +void CommandBufferService::SetParseError(int32 parse_error) { if (parse_error_ == 0) { parse_error_ = parse_error; } } -} // namespace gpu_plugin +bool CommandBufferService::GetErrorStatus() { + return error_status_; +} + +void CommandBufferService::RaiseErrorStatus() { + error_status_ = true; +} + +} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/command_buffer_service.h b/o3d/gpu/command_buffer/service/command_buffer_service.h new file mode 100644 index 0000000..d6da953 --- /dev/null +++ b/o3d/gpu/command_buffer/service/command_buffer_service.h @@ -0,0 +1,93 @@ +// 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 GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_H_ +#define GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_H_ + +#include <set> +#include <vector> + +#include "base/linked_ptr.h" +#include "base/scoped_ptr.h" +#include "base/shared_memory.h" +#include "base/task.h" +#include "gpu/command_buffer/common/command_buffer.h" +#include "gpu/np_utils/default_np_object.h" +#include "gpu/np_utils/np_dispatcher.h" + +namespace command_buffer { + +// An NPObject that implements a shared memory command buffer and a synchronous +// API to manage the put and get pointers. +class CommandBufferService : public CommandBuffer { + public: + CommandBufferService(); + virtual ~CommandBufferService(); + + // Overrides CommandBuffer. + virtual bool Initialize(::base::SharedMemory* ring_buffer); + + // Overrides CommandBuffer. + virtual ::base::SharedMemory* GetRingBuffer(); + + virtual int32 GetSize(); + + // Overrides CommandBuffer. + virtual int32 SyncOffsets(int32 put_offset); + + // Overrides CommandBuffer. + virtual int32 GetGetOffset(); + + // Overrides CommandBuffer. + virtual void SetGetOffset(int32 get_offset); + + // Overrides CommandBuffer. + virtual int32 GetPutOffset(); + + // Overrides CommandBuffer. + virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); + + // Overrides CommandBuffer. + virtual int32 CreateTransferBuffer(size_t size); + + // Overrides CommandBuffer. + virtual void DestroyTransferBuffer(int32 id); + + // Overrides CommandBuffer. + virtual ::base::SharedMemory* GetTransferBuffer(int32 handle); + + // Overrides CommandBuffer. + virtual int32 GetToken(); + + // Overrides CommandBuffer. + virtual void SetToken(int32 token); + + // Overrides CommandBuffer. + virtual int32 ResetParseError(); + + // Overrides CommandBuffer. + virtual void SetParseError(int32 parse_error); + + // Overrides CommandBuffer. + virtual bool GetErrorStatus(); + + // Overrides CommandBuffer. + virtual void RaiseErrorStatus(); + + private: + scoped_ptr< ::base::SharedMemory> ring_buffer_; + int32 size_; + int32 get_offset_; + int32 put_offset_; + scoped_ptr<Callback0::Type> put_offset_change_callback_; + std::vector<linked_ptr< ::base::SharedMemory> > registered_objects_; + std::set<int32> unused_registered_object_elements_; + int32 token_; + int32 parse_error_; + bool error_status_; +}; + +} // namespace command_buffer + +#endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_H_ diff --git a/o3d/gpu/gpu_plugin/command_buffer_unittest.cc b/o3d/gpu/command_buffer/service/command_buffer_service_unittest.cc index 00e5640..2f9c1fb 100644 --- a/o3d/gpu/gpu_plugin/command_buffer_unittest.cc +++ b/o3d/gpu/command_buffer/service/command_buffer_service_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/thread.h" -#include "gpu/gpu_plugin/command_buffer.h" +#include "gpu/command_buffer/service/command_buffer_service.h" #include "gpu/np_utils/np_browser_mock.h" #include "gpu/np_utils/dynamic_np_object.h" #include "gpu/np_utils/np_object_mock.h" @@ -12,29 +12,31 @@ #include "testing/gmock/include/gmock/gmock.h" using base::SharedMemory; +using np_utils::NPCreateObject; +using np_utils::NPObjectPointer; using testing::_; using testing::DoAll; using testing::Return; using testing::SetArgumentPointee; using testing::StrictMock; -namespace gpu_plugin { +namespace command_buffer { -class CommandBufferTest : public testing::Test { +class CommandBufferServiceTest : public testing::Test { protected: virtual void SetUp() { - command_buffer_ = NPCreateObject<CommandBuffer>(NULL); + command_buffer_.reset(new CommandBufferService); } - MockNPBrowser mock_browser_; - NPObjectPointer<CommandBuffer> command_buffer_; + np_utils::MockNPBrowser mock_browser_; + scoped_ptr<CommandBufferService> command_buffer_; }; -TEST_F(CommandBufferTest, NullRingBufferByDefault) { +TEST_F(CommandBufferServiceTest, NullRingBufferByDefault) { EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer()); } -TEST_F(CommandBufferTest, InitializesCommandBuffer) { +TEST_F(CommandBufferServiceTest, InitializesCommandBuffer) { SharedMemory* ring_buffer = new SharedMemory; EXPECT_TRUE(ring_buffer->Create(std::wstring(), false, false, 1024)); EXPECT_TRUE(command_buffer_->Initialize(ring_buffer)); @@ -42,13 +44,13 @@ TEST_F(CommandBufferTest, InitializesCommandBuffer) { EXPECT_EQ(256, command_buffer_->GetSize()); } -TEST_F(CommandBufferTest, InitializeFailsSecondTime) { +TEST_F(CommandBufferServiceTest, InitializeFailsSecondTime) { SharedMemory* ring_buffer = new SharedMemory; EXPECT_TRUE(command_buffer_->Initialize(ring_buffer)); EXPECT_FALSE(command_buffer_->Initialize(ring_buffer)); } -TEST_F(CommandBufferTest, GetAndPutOffsetsDefaultToZero) { +TEST_F(CommandBufferServiceTest, GetAndPutOffsetsDefaultToZero) { EXPECT_EQ(0, command_buffer_->GetGetOffset()); EXPECT_EQ(0, command_buffer_->GetPutOffset()); } @@ -58,7 +60,7 @@ class MockCallback : public CallbackRunner<Tuple0> { MOCK_METHOD1(RunWithParams, void(const Tuple0&)); }; -TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { +TEST_F(CommandBufferServiceTest, CanSyncGetAndPutOffset) { SharedMemory* ring_buffer = new SharedMemory; ring_buffer->Create(std::wstring(), false, false, 1024); @@ -85,19 +87,19 @@ TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { EXPECT_EQ(-1, command_buffer_->SyncOffsets(1024)); } -TEST_F(CommandBufferTest, ZeroHandleMapsToNull) { +TEST_F(CommandBufferServiceTest, ZeroHandleMapsToNull) { EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); } -TEST_F(CommandBufferTest, NegativeHandleMapsToNull) { +TEST_F(CommandBufferServiceTest, NegativeHandleMapsToNull) { EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1)); } -TEST_F(CommandBufferTest, OutOfRangeHandleMapsToNull) { +TEST_F(CommandBufferServiceTest, OutOfRangeHandleMapsToNull) { EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1)); } -TEST_F(CommandBufferTest, CanCreateTransferBuffers) { +TEST_F(CommandBufferServiceTest, CanCreateTransferBuffers) { int32 handle = command_buffer_->CreateTransferBuffer(1024); EXPECT_EQ(1, handle); SharedMemory* buffer = command_buffer_->GetTransferBuffer(handle); @@ -105,11 +107,12 @@ TEST_F(CommandBufferTest, CanCreateTransferBuffers) { EXPECT_EQ(1024, buffer->max_size()); } -TEST_F(CommandBufferTest, CreateTransferBufferReturnsDistinctHandles) { +TEST_F(CommandBufferServiceTest, CreateTransferBufferReturnsDistinctHandles) { EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, CreateTransferBufferReusesUnregisteredHandles) { +TEST_F(CommandBufferServiceTest, + CreateTransferBufferReusesUnregisteredHandles) { EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); command_buffer_->DestroyTransferBuffer(1); @@ -117,25 +120,25 @@ TEST_F(CommandBufferTest, CreateTransferBufferReusesUnregisteredHandles) { EXPECT_EQ(3, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, CannotUnregisterHandleZero) { +TEST_F(CommandBufferServiceTest, CannotUnregisterHandleZero) { command_buffer_->DestroyTransferBuffer(0); EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, CannotUnregisterNegativeHandles) { +TEST_F(CommandBufferServiceTest, CannotUnregisterNegativeHandles) { command_buffer_->DestroyTransferBuffer(-1); EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, CannotUnregisterUnregisteredHandles) { +TEST_F(CommandBufferServiceTest, CannotUnregisterUnregisteredHandles) { 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) { +TEST_F(CommandBufferServiceTest, UnregistersLastRegisteredHandle) { EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); command_buffer_->DestroyTransferBuffer(1); EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); @@ -143,7 +146,7 @@ TEST_F(CommandBufferTest, UnregistersLastRegisteredHandle) { // Testing this case specifically because there is an optimization that takes // a different code path in this case. -TEST_F(CommandBufferTest, UnregistersTwoLastRegisteredHandles) { +TEST_F(CommandBufferServiceTest, UnregistersTwoLastRegisteredHandles) { EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); command_buffer_->DestroyTransferBuffer(2); @@ -151,32 +154,32 @@ TEST_F(CommandBufferTest, UnregistersTwoLastRegisteredHandles) { EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); } -TEST_F(CommandBufferTest, DefaultTokenIsZero) { +TEST_F(CommandBufferServiceTest, DefaultTokenIsZero) { EXPECT_EQ(0, command_buffer_->GetToken()); } -TEST_F(CommandBufferTest, CanSetToken) { +TEST_F(CommandBufferServiceTest, CanSetToken) { command_buffer_->SetToken(7); EXPECT_EQ(7, command_buffer_->GetToken()); } -TEST_F(CommandBufferTest, DefaultParseErrorIsNoError) { +TEST_F(CommandBufferServiceTest, DefaultParseErrorIsNoError) { EXPECT_EQ(0, command_buffer_->ResetParseError()); } -TEST_F(CommandBufferTest, CanSetAndResetParseError) { +TEST_F(CommandBufferServiceTest, CanSetAndResetParseError) { command_buffer_->SetParseError(1); EXPECT_EQ(1, command_buffer_->ResetParseError()); EXPECT_EQ(0, command_buffer_->ResetParseError()); } -TEST_F(CommandBufferTest, DefaultErrorStatusIsFalse) { +TEST_F(CommandBufferServiceTest, DefaultErrorStatusIsFalse) { EXPECT_FALSE(command_buffer_->GetErrorStatus()); } -TEST_F(CommandBufferTest, CanRaiseErrorStatus) { +TEST_F(CommandBufferServiceTest, CanRaiseErrorStatus) { command_buffer_->RaiseErrorStatus(); EXPECT_TRUE(command_buffer_->GetErrorStatus()); } -} // namespace gpu_plugin +} // namespace command_buffer diff --git a/o3d/gpu/gpu_plugin/gpu_processor.cc b/o3d/gpu/command_buffer/service/gpu_processor.cc index 7b97917..845d5b6 100644 --- a/o3d/gpu/gpu_plugin/gpu_processor.cc +++ b/o3d/gpu/command_buffer/service/gpu_processor.cc @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/gpu_processor.h" +#include "gpu/np_utils/np_browser.h" using ::base::SharedMemory; +using np_utils::NPBrowser; -namespace gpu_plugin { +namespace command_buffer { GPUProcessor::~GPUProcessor() { } @@ -51,7 +53,8 @@ void GPUProcessor::ProcessCommands() { } void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) { - SharedMemory* shared_memory = command_buffer_->GetTransferBuffer(shm_id); + ::base::SharedMemory* shared_memory = + command_buffer_->GetTransferBuffer(shm_id); if (!shared_memory) return NULL; @@ -66,7 +69,8 @@ void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) { // TODO(apatrick): Consolidate this with the above and return both the address // and size. size_t GPUProcessor::GetSharedMemorySize(int32 shm_id) { - SharedMemory* shared_memory = command_buffer_->GetTransferBuffer(shm_id); + ::base::SharedMemory* shared_memory = + command_buffer_->GetTransferBuffer(shm_id); if (!shared_memory) return 0; @@ -77,4 +81,4 @@ void GPUProcessor::set_token(int32 token) { command_buffer_->SetToken(token); } -} // namespace gpu_plugin +} // namespace command_buffer diff --git a/o3d/gpu/gpu_plugin/gpu_processor.h b/o3d/gpu/command_buffer/service/gpu_processor.h index 31617b0..d61f3d2 100644 --- a/o3d/gpu/gpu_plugin/gpu_processor.h +++ b/o3d/gpu/command_buffer/service/gpu_processor.h @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GPU_GPU_PLUGIN_GPU_PROCESSOR_H_ -#define GPU_GPU_PLUGIN_GPU_PROCESSOR_H_ +#ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ +#define GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/shared_memory.h" +#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/service/cmd_buffer_engine.h" #include "gpu/command_buffer/service/cmd_parser.h" #include "gpu/command_buffer/service/gapi_decoder.h" -#include "gpu/gpu_plugin/command_buffer.h" #include "gpu/np_utils/np_object_pointer.h" #if defined(CB_SERVICE_D3D9) @@ -22,7 +22,7 @@ #error command buffer service not defined #endif -namespace gpu_plugin { +namespace command_buffer { // This class processes commands in a command buffer. It is event driven and // posts tasks to the current message loop to do additional work. @@ -37,12 +37,10 @@ class GPUProcessor : public ::base::RefCounted<GPUProcessor>, #error command buffer service not defined #endif - GPUProcessor(NPP npp, - CommandBuffer* command_buffer); + GPUProcessor(NPP npp, CommandBuffer* command_buffer); // This constructor is for unit tests. - GPUProcessor(NPP npp, - CommandBuffer* command_buffer, + GPUProcessor(CommandBuffer* command_buffer, GPUGAPIInterface* gapi, command_buffer::o3d::GAPIDecoder* decoder, command_buffer::CommandParser* parser, @@ -91,13 +89,13 @@ class GPUProcessor : public ::base::RefCounted<GPUProcessor>, scoped_ptr<command_buffer::CommandParser> parser_; }; -} // namespace gpu_plugin +} // namespace command_buffer // Callbacks to the GPUProcessor hold a reference count. template <typename Method> -class CallbackStorage<gpu_plugin::GPUProcessor, Method> { +class CallbackStorage<command_buffer::GPUProcessor, Method> { public: - CallbackStorage(gpu_plugin::GPUProcessor* obj, Method method) + CallbackStorage(command_buffer::GPUProcessor* obj, Method method) : obj_(obj), meth_(method) { DCHECK(obj_); @@ -109,11 +107,11 @@ class CallbackStorage<gpu_plugin::GPUProcessor, Method> { } protected: - gpu_plugin::GPUProcessor* obj_; + command_buffer::GPUProcessor* obj_; Method meth_; private: DISALLOW_COPY_AND_ASSIGN(CallbackStorage); }; -#endif // GPU_GPU_PLUGIN_GPU_PROCESSOR_H_ +#endif // GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ diff --git a/o3d/gpu/gpu_plugin/gpu_processor_mock.h b/o3d/gpu/command_buffer/service/gpu_processor_mock.h index e93c155..d65965f 100644 --- a/o3d/gpu/gpu_plugin/gpu_processor_mock.h +++ b/o3d/gpu/command_buffer/service/gpu_processor_mock.h @@ -2,19 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GPU_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_ -#define GPU_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_ +#ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_MOCK_H_ +#define GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_MOCK_H_ -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "testing/gmock/include/gmock/gmock.h" -namespace gpu_plugin { +namespace command_buffer { class MockGPUProcessor : public GPUProcessor { public: - MockGPUProcessor(NPP npp, - CommandBuffer* command_buffer) - : GPUProcessor(npp, command_buffer) { + explicit MockGPUProcessor(CommandBuffer* command_buffer) + : GPUProcessor(NULL, command_buffer) { } #if defined(OS_WIN) @@ -36,6 +35,6 @@ class MockGPUProcessor : public GPUProcessor { DISALLOW_COPY_AND_ASSIGN(MockGPUProcessor); }; -} // namespace gpu_plugin +} // namespace command_buffer -#endif // GPU_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_ +#endif // GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_MOCK_H_ diff --git a/o3d/gpu/gpu_plugin/gpu_processor_unittest.cc b/o3d/gpu/command_buffer/service/gpu_processor_unittest.cc index 97c44b9..faefcd2 100644 --- a/o3d/gpu/gpu_plugin/gpu_processor_unittest.cc +++ b/o3d/gpu/command_buffer/service/gpu_processor_unittest.cc @@ -4,16 +4,13 @@ #include "base/at_exit.h" #include "base/message_loop.h" +#include "gpu/command_buffer/common/command_buffer_mock.h" #include "gpu/command_buffer/service/mocks.h" -#include "gpu/gpu_plugin/command_buffer_mock.h" -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/np_browser_mock.h" -#include "gpu/np_utils/np_object_pointer.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; @@ -22,7 +19,7 @@ using testing::Return; using testing::SetArgumentPointee; using testing::StrictMock; -namespace gpu_plugin { +namespace command_buffer { const size_t kRingBufferSize = 1024; const size_t kRingBufferEntries = kRingBufferSize / sizeof(int32); @@ -30,7 +27,7 @@ const size_t kRingBufferEntries = kRingBufferSize / sizeof(int32); class GPUProcessorTest : public testing::Test { protected: virtual void SetUp() { - shared_memory_.reset(new SharedMemory); + shared_memory_.reset(new ::base::SharedMemory); shared_memory_->Create(std::wstring(), false, false, kRingBufferSize); shared_memory_->Map(kRingBufferSize); buffer_ = static_cast<int32*>(shared_memory_->memory()); @@ -39,13 +36,14 @@ class GPUProcessorTest : public testing::Test { // Don't mock PluginThreadAsyncCall. Have it schedule the task. ON_CALL(mock_browser_, PluginThreadAsyncCall(_, _, _)) - .WillByDefault(Invoke(&mock_browser_, - &MockNPBrowser::ConcretePluginThreadAsyncCall)); + .WillByDefault( + Invoke(&mock_browser_, + &np_utils::MockNPBrowser::ConcretePluginThreadAsyncCall)); - command_buffer_ = NPCreateObject<MockCommandBuffer>(NULL); - ON_CALL(*command_buffer_.Get(), GetRingBuffer()) + command_buffer_.reset(new MockCommandBuffer); + ON_CALL(*command_buffer_.get(), GetRingBuffer()) .WillByDefault(Return(shared_memory_.get())); - ON_CALL(*command_buffer_.Get(), GetSize()) + ON_CALL(*command_buffer_.get(), GetSize()) .WillByDefault(Return(kRingBufferEntries)); #if defined(OS_WIN) @@ -63,8 +61,7 @@ class GPUProcessorTest : public testing::Test { 0, async_api_.get()); - processor_ = new GPUProcessor(NULL, - command_buffer_.Get(), + processor_ = new GPUProcessor(command_buffer_.get(), gapi_, decoder_, parser_, @@ -79,9 +76,9 @@ class GPUProcessorTest : public testing::Test { base::AtExitManager at_exit_manager; MessageLoop message_loop; - MockNPBrowser mock_browser_; - NPObjectPointer<MockCommandBuffer> command_buffer_; - scoped_ptr<SharedMemory> shared_memory_; + np_utils::MockNPBrowser mock_browser_; + scoped_ptr<MockCommandBuffer> command_buffer_; + scoped_ptr<::base::SharedMemory> shared_memory_; int32* buffer_; command_buffer::o3d::GAPIDecoder* decoder_; command_buffer::CommandParser* parser_; @@ -199,11 +196,10 @@ TEST_F(GPUProcessorTest, SetsErrorCodeOnCommandBuffer) { .WillOnce(Return( command_buffer::parse_error::kParseUnknownCommand)); - processor_->ProcessCommands(); + EXPECT_CALL(*command_buffer_, + SetParseError(command_buffer::parse_error::kParseUnknownCommand)); - EXPECT_EQ(command_buffer::parse_error::kParseUnknownCommand, - command_buffer_->ResetParseError()); - EXPECT_FALSE(command_buffer_->GetErrorStatus()); + processor_->ProcessCommands(); } TEST_F(GPUProcessorTest, @@ -226,11 +222,10 @@ TEST_F(GPUProcessorTest, EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[1])) .WillOnce(Return(command_buffer::parse_error::kParseNoError)); - processor_->ProcessCommands(); + EXPECT_CALL(*command_buffer_, + SetParseError(command_buffer::parse_error::kParseUnknownCommand)); - EXPECT_EQ(command_buffer::parse_error::kParseUnknownCommand, - command_buffer_->ResetParseError()); - EXPECT_FALSE(command_buffer_->GetErrorStatus()); + processor_->ProcessCommands(); } TEST_F(GPUProcessorTest, UnrecoverableParseErrorsRaiseTheErrorStatus) { @@ -247,37 +242,26 @@ TEST_F(GPUProcessorTest, UnrecoverableParseErrorsRaiseTheErrorStatus) { EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0])) .WillOnce(Return(command_buffer::parse_error::kParseInvalidSize)); - processor_->ProcessCommands(); + EXPECT_CALL(*command_buffer_, + SetParseError(command_buffer::parse_error::kParseInvalidSize)); - EXPECT_EQ(command_buffer::parse_error::kParseInvalidSize, - command_buffer_->ResetParseError()); - EXPECT_TRUE(command_buffer_->GetErrorStatus()); + EXPECT_CALL(*command_buffer_, RaiseErrorStatus()); + + processor_->ProcessCommands(); } TEST_F(GPUProcessorTest, ProcessCommandsDoesNothingAfterUnrecoverableError) { - command_buffer::CommandHeader* header = - reinterpret_cast<command_buffer::CommandHeader*>(&buffer_[0]); - header[0].command = 7; - header[0].size = 1; - header[1].command = 8; - header[1].size = 1; + EXPECT_CALL(*command_buffer_, GetErrorStatus()) + .WillOnce(Return(true)); EXPECT_CALL(*command_buffer_, GetPutOffset()) - .WillOnce(Return(2)); - - EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0])) - .WillOnce(Return(command_buffer::parse_error::kParseInvalidSize)); + .Times(0); processor_->ProcessCommands(); - processor_->ProcessCommands(); - - EXPECT_EQ(command_buffer::parse_error::kParseInvalidSize, - command_buffer_->ResetParseError()); - EXPECT_TRUE(command_buffer_->GetErrorStatus()); } TEST_F(GPUProcessorTest, CanGetAddressOfSharedMemory) { - EXPECT_CALL(*command_buffer_.Get(), GetTransferBuffer(7)) + EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) .WillOnce(Return(shared_memory_.get())); EXPECT_EQ(&buffer_[0], processor_->GetSharedMemoryAddress(7)); @@ -288,22 +272,22 @@ ACTION_P2(SetPointee, address, value) { } TEST_F(GPUProcessorTest, GetAddressOfSharedMemoryMapsMemoryIfUnmapped) { - EXPECT_CALL(*command_buffer_.Get(), GetTransferBuffer(7)) + 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(), GetTransferBuffer(7)) + EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) .WillOnce(Return(shared_memory_.get())); EXPECT_EQ(kRingBufferSize, processor_->GetSharedMemorySize(7)); } TEST_F(GPUProcessorTest, SetTokenForwardsToCommandBuffer) { + EXPECT_CALL(*command_buffer_, SetToken(7)); processor_->set_token(7); - EXPECT_EQ(7, command_buffer_->GetToken()); } -} // namespace gpu_plugin
\ No newline at end of file +} // namespace command_buffer diff --git a/o3d/gpu/gpu_plugin/gpu_processor_win.cc b/o3d/gpu/command_buffer/service/gpu_processor_win.cc index 4c62098..9d7d4de 100644 --- a/o3d/gpu/gpu_plugin/gpu_processor_win.cc +++ b/o3d/gpu/command_buffer/service/gpu_processor_win.cc @@ -4,14 +4,13 @@ #include <windows.h> -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/service/gpu_processor.h" using ::base::SharedMemory; -namespace gpu_plugin { +namespace command_buffer { -GPUProcessor::GPUProcessor(NPP npp, - CommandBuffer* command_buffer) +GPUProcessor::GPUProcessor(NPP npp, CommandBuffer* command_buffer) : npp_(npp), command_buffer_(command_buffer), commands_per_update_(100) { @@ -21,13 +20,12 @@ GPUProcessor::GPUProcessor(NPP npp, decoder_->set_engine(this); } -GPUProcessor::GPUProcessor(NPP npp, - CommandBuffer* command_buffer, +GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, GPUGAPIInterface* gapi, command_buffer::o3d::GAPIDecoder* decoder, command_buffer::CommandParser* parser, int commands_per_update) - : npp_(npp), + : npp_(NULL), command_buffer_(command_buffer), commands_per_update_(commands_per_update) { DCHECK(command_buffer); @@ -44,7 +42,7 @@ bool GPUProcessor::Initialize(HWND handle) { return false; // Map the ring buffer and create the parser. - SharedMemory* ring_buffer = command_buffer_->GetRingBuffer(); + ::base::SharedMemory* ring_buffer = command_buffer_->GetRingBuffer(); if (ring_buffer) { size_t size = ring_buffer->max_size(); if (!ring_buffer->Map(size)) { @@ -82,4 +80,4 @@ bool GPUProcessor::SetWindow(HWND handle, int width, int height) { } } -} // namespace gpu_plugin +} // namespace command_buffer diff --git a/o3d/gpu/gpu.gyp b/o3d/gpu/gpu.gyp index 7e348da..e9e9881 100644 --- a/o3d/gpu/gpu.gyp +++ b/o3d/gpu/gpu.gyp @@ -29,6 +29,8 @@ 'command_buffer/common/bitfield_helpers.h', 'command_buffer/common/cmd_buffer_common.h', 'command_buffer/common/cmd_buffer_common.cc', + 'command_buffer/common/command_buffer.h', + 'command_buffer/common/command_buffer_mock.h', 'command_buffer/common/gles2_cmd_format.cc', 'command_buffer/common/gles2_cmd_format.h', 'command_buffer/common/gles2_cmd_utils.cc', @@ -164,17 +166,26 @@ }, # 'all_dependent_settings' 'dependencies': [ 'command_buffer_common', + + # TODO(apatrick): Remove this dependency when the synchronous messages + # are via IPC. + 'np_utils', ], 'sources': [ 'command_buffer/service/common_decoder.cc', 'command_buffer/service/common_decoder.h', 'command_buffer/service/cmd_buffer_engine.h', + 'command_buffer/service/command_buffer_service.cc', + 'command_buffer/service/command_buffer_service.h', 'command_buffer/service/cmd_parser.cc', 'command_buffer/service/cmd_parser.h', 'command_buffer/service/effect_utils.cc', 'command_buffer/service/effect_utils.h', 'command_buffer/service/gapi_decoder.cc', 'command_buffer/service/gapi_decoder.h', + 'command_buffer/service/gpu_processor.h', + 'command_buffer/service/gpu_processor.cc', + 'command_buffer/service/gpu_processor_mock.h', 'command_buffer/service/mocks.h', 'command_buffer/service/precompile.cc', 'command_buffer/service/precompile.h', @@ -253,6 +264,13 @@ ], }, ], + ['OS == "win"', + { + 'sources': [ + 'command_buffer/service/gpu_processor_win.cc', + ], + }, + ], ], # 'conditions' }, { @@ -261,6 +279,8 @@ 'direct_dependent_settings': { 'sources': [ 'command_buffer/service/cmd_parser_test.cc', + 'command_buffer/service/command_buffer_service_unittest.cc', + 'command_buffer/service/gpu_processor_unittest.cc', 'command_buffer/service/resource_test.cc', ], }, @@ -330,45 +350,12 @@ ], }, }, - - # These can eventually be merged back into the gpu_plugin target. There - # separated for now so O3D can statically link against them and use command - # buffers in-process without the GPU plugin. - { - 'target_name': 'command_buffer', - 'type': '<(library)', - 'dependencies': [ - '../../base/base.gyp:base', - 'command_buffer_service', - 'np_utils', - ], - 'include_dirs': [ - '..', - '../..', - ], - 'all_dependent_settings': { - 'include_dirs': [ - '..', - '../..', - ], - }, # 'all_dependent_settings' - 'sources': [ - 'gpu_plugin/command_buffer.cc', - 'gpu_plugin/command_buffer.h', - 'gpu_plugin/command_buffer_mock.h', - 'gpu_plugin/gpu_processor.h', - 'gpu_plugin/gpu_processor.cc', - 'gpu_plugin/gpu_processor_mock.h', - 'gpu_plugin/gpu_processor_win.cc', - ], - }, - { 'target_name': 'gpu_plugin', 'type': '<(library)', 'dependencies': [ '../../base/base.gyp:base', - 'command_buffer', + 'command_buffer_service', 'np_utils', ], 'include_dirs': [ @@ -400,11 +387,9 @@ '../..', ], 'sources': [ - 'gpu_plugin/command_buffer_unittest.cc', 'gpu_plugin/gpu_plugin_unittest.cc', 'gpu_plugin/gpu_plugin_object_unittest.cc', 'gpu_plugin/gpu_plugin_object_factory_unittest.cc', - 'gpu_plugin/gpu_processor_unittest.cc', ], }, }, diff --git a/o3d/gpu/gpu_plugin/gpu_plugin.cc b/o3d/gpu/gpu_plugin/gpu_plugin.cc index d8cfb58..5a10a25 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin.cc @@ -14,6 +14,10 @@ #include "o3d/third_party/npapi/include/npfunctions.h" #endif +using np_utils::NPBrowser; +using np_utils::NPPluginObjectFactory; +using np_utils::PluginObject; + namespace gpu_plugin { // Definitions of NPAPI plugin entry points. diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu/gpu_plugin/gpu_plugin_object.cc index 6a2bd6c..d4ea9150 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object.cc @@ -5,11 +5,17 @@ #include <stdlib.h> #include "base/logging.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/np_utils.h" #include "gpu/gpu_plugin/gpu_plugin_object.h" -#include "gpu/gpu_plugin/gpu_processor.h" using ::base::SharedMemory; +using command_buffer::CommandBuffer; +using command_buffer::CommandBufferService; +using command_buffer::GPUProcessor; +using np_utils::NPBrowser; +using np_utils::NPObjectPointer; namespace gpu_plugin { @@ -19,8 +25,8 @@ const NPUTF8 GPUPluginObject::kPluginType[] = GPUPluginObject::GPUPluginObject(NPP npp) : npp_(npp), status_(kWaitingForNew), - command_buffer_(NPCreateObject<CommandBuffer>(npp)), - processor_(new GPUProcessor(npp, command_buffer_.Get())) { + command_buffer_(new CommandBufferService), + processor_(new GPUProcessor(npp, command_buffer_.get())) { memset(&window_, 0, sizeof(window_)); } @@ -68,7 +74,7 @@ NPError GPUPluginObject::Destroy(NPSavedData** saved) { if (status_ == kWaitingForNew || status_ == kDestroyed) return NPERR_GENERIC_ERROR; - if (command_buffer_.Get()) { + if (command_buffer_.get()) { command_buffer_->SetPutOffsetChangeCallback(NULL); } @@ -87,19 +93,19 @@ NPObject*GPUPluginObject::GetScriptableNPObject() { return this; } -NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() { +CommandBuffer* GPUPluginObject::OpenCommandBuffer() { if (status_ == kInitializationSuccessful) - return command_buffer_; + return command_buffer_.get(); // SetWindow must have been called before OpenCommandBuffer. // PlatformSpecificSetWindow advances the status to // kWaitingForOpenCommandBuffer. if (status_ != kWaitingForOpenCommandBuffer) - return NPObjectPointer<NPObject>(); + return NULL; scoped_ptr<SharedMemory> ring_buffer(new SharedMemory); if (!ring_buffer->Create(std::wstring(), false, false, kCommandBufferSize)) - return NPObjectPointer<NPObject>(); + return NULL; if (command_buffer_->Initialize(ring_buffer.release())) { if (processor_->Initialize(static_cast<HWND>(window_.window))) { @@ -107,11 +113,11 @@ NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() { NewCallback(processor_.get(), &GPUProcessor::ProcessCommands)); status_ = kInitializationSuccessful; - return command_buffer_; + return command_buffer_.get(); } } - return NPObjectPointer<CommandBuffer>(); + return NULL; } } // namespace gpu_plugin diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object.h b/o3d/gpu/gpu_plugin/gpu_plugin_object.h index 09f612d..0602aa9 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object.h +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object.h @@ -9,8 +9,8 @@ #include "base/ref_counted.h" #include "base/thread.h" -#include "gpu/gpu_plugin/command_buffer.h" -#include "gpu/gpu_plugin/gpu_processor.h" +#include "gpu/command_buffer/common/command_buffer.h" +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/np_utils/default_np_object.h" #include "gpu/np_utils/np_dispatcher.h" #include "gpu/np_utils/np_headers.h" @@ -20,8 +20,8 @@ namespace gpu_plugin { // The scriptable object for the GPU plugin. -class GPUPluginObject : public DefaultNPObject<NPObject>, - public PluginObject { +class GPUPluginObject : public np_utils::DefaultNPObject<NPObject>, + public np_utils::PluginObject { public: static const int32 kCommandBufferSize = 1024 * 1024; @@ -78,42 +78,43 @@ class GPUPluginObject : public DefaultNPObject<NPObject>, // Set the object that receives notifications of GPU plugin object events // such as resize and keyboard and mouse input. - void SetEventSync(NPObjectPointer<NPObject> event_sync) { + void SetEventSync(np_utils::NPObjectPointer<NPObject> event_sync) { event_sync_ = event_sync; } - NPObjectPointer<NPObject> GetEventSync() { + np_utils::NPObjectPointer<NPObject> GetEventSync() { return event_sync_; } // Initializes and returns the command buffer object. Returns NULL if the // command buffer cannot be initialized, for example if the plugin does not // yet have a window handle. - NPObjectPointer<NPObject> OpenCommandBuffer(); + command_buffer::CommandBuffer* OpenCommandBuffer(); // Set the status for testing. void set_status(Status status) { status_ = status; } - // Replace the default command buffer for testing. - void set_command_buffer( - const NPObjectPointer<CommandBuffer>& command_buffer) { - command_buffer_ = command_buffer; + // Replace the default command buffer for testing. Takes ownership. + void set_command_buffer(command_buffer::CommandBuffer* + command_buffer) { + command_buffer_.reset(command_buffer); } // Replace the default GPU processor for testing. - void set_gpu_processor(const scoped_refptr<GPUProcessor>& processor) { + void set_gpu_processor( + const scoped_refptr<command_buffer::GPUProcessor>& processor) { processor_ = processor; } NP_UTILS_BEGIN_DISPATCHER_CHAIN(GPUPluginObject, DefaultNPObject<NPObject>) - NP_UTILS_DISPATCHER(GetStatus, int32()); - NP_UTILS_DISPATCHER(GetWidth, int32()); - NP_UTILS_DISPATCHER(GetHeight, int32()); - NP_UTILS_DISPATCHER(SetEventSync, void(NPObjectPointer<NPObject> sync)); - NP_UTILS_DISPATCHER(GetEventSync, NPObjectPointer<NPObject>()); - NP_UTILS_DISPATCHER(OpenCommandBuffer, NPObjectPointer<NPObject>()) + NP_UTILS_DISPATCHER(GetStatus, int32()) + NP_UTILS_DISPATCHER(GetWidth, int32()) + NP_UTILS_DISPATCHER(GetHeight, int32()) + NP_UTILS_DISPATCHER(SetEventSync, + void(np_utils::NPObjectPointer<NPObject> sync)) + NP_UTILS_DISPATCHER(GetEventSync, np_utils::NPObjectPointer<NPObject>()) NP_UTILS_END_DISPATCHER_CHAIN private: @@ -122,9 +123,9 @@ class GPUPluginObject : public DefaultNPObject<NPObject>, NPP npp_; Status status_; NPWindow window_; - NPObjectPointer<CommandBuffer> command_buffer_; - scoped_refptr<GPUProcessor> processor_; - NPObjectPointer<NPObject> event_sync_; + scoped_ptr<command_buffer::CommandBuffer> command_buffer_; + scoped_refptr<command_buffer::GPUProcessor> processor_; + np_utils::NPObjectPointer<NPObject> event_sync_; }; } // namespace gpu_plugin diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.cc b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.cc index cfdced8..da9e17a 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.cc @@ -14,11 +14,11 @@ GPUPluginObjectFactory::GPUPluginObjectFactory() { GPUPluginObjectFactory::~GPUPluginObjectFactory() { } -PluginObject* GPUPluginObjectFactory::CreatePluginObject( +np_utils::PluginObject* GPUPluginObjectFactory::CreatePluginObject( NPP npp, NPMIMEType plugin_type) { if (strcmp(plugin_type, GPUPluginObject::kPluginType) == 0) { - return NPCreateObject<GPUPluginObject>(npp).ToReturned(); + return np_utils::NPCreateObject<GPUPluginObject>(npp).ToReturned(); } return NULL; diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.h b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.h index 1a73baf..0d1d80e 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.h +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory.h @@ -10,12 +10,13 @@ namespace gpu_plugin { // Plugin object factory for creating the GPUPluginObject. -class GPUPluginObjectFactory : public NPPluginObjectFactory { +class GPUPluginObjectFactory : public np_utils::NPPluginObjectFactory { public: GPUPluginObjectFactory(); virtual ~GPUPluginObjectFactory(); - virtual PluginObject* CreatePluginObject(NPP npp, NPMIMEType plugin_type); + virtual np_utils::PluginObject* CreatePluginObject(NPP npp, + NPMIMEType plugin_type); private: DISALLOW_COPY_AND_ASSIGN(GPUPluginObjectFactory); diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory_unittest.cc b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory_unittest.cc index 7b006c2..298a8c5 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object_factory_unittest.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object_factory_unittest.cc @@ -8,6 +8,8 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using np_utils::PluginObject; + namespace gpu_plugin { class PluginObjectFactoryTest : public testing::Test { @@ -20,7 +22,7 @@ class PluginObjectFactoryTest : public testing::Test { delete factory_; } - StubNPBrowser stub_browser_; + np_utils::StubNPBrowser stub_browser_; GPUPluginObjectFactory* factory_; }; diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu/gpu_plugin/gpu_plugin_object_unittest.cc index 2f91225..6ca3770 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object_unittest.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/gpu_plugin/command_buffer_mock.h" +#include "gpu/command_buffer/common/command_buffer_mock.h" #include "gpu/gpu_plugin/gpu_plugin_object.h" -#include "gpu/gpu_plugin/gpu_processor_mock.h" +#include "gpu/command_buffer/service/gpu_processor_mock.h" #include "gpu/np_utils/np_browser_mock.h" #include "gpu/np_utils/dynamic_np_object.h" #include "gpu/np_utils/np_object_mock.h" @@ -19,7 +19,12 @@ #endif using ::base::SharedMemory; - +using command_buffer::GPUProcessor; +using command_buffer::MockCommandBuffer; +using command_buffer::MockGPUProcessor; +using np_utils::MockNPBrowser; +using np_utils::NPBrowser; +using np_utils::NPObjectPointer; using testing::_; using testing::DoAll; using testing::Invoke; @@ -30,51 +35,24 @@ using testing::StrictMock; namespace gpu_plugin { -class MockSystemNPObject : public DefaultNPObject<NPObject> { - public: - explicit MockSystemNPObject(NPP npp) { - } - - MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32 size)); - - NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DefaultNPObject<NPObject>) - NP_UTILS_DISPATCHER(CreateSharedMemory, - NPObjectPointer<NPObject>(int32 size)) - NP_UTILS_END_DISPATCHER_CHAIN - - private: - DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject); -}; - class GPUPluginObjectTest : public testing::Test { protected: virtual void SetUp() { - plugin_object_ = NPCreateObject<GPUPluginObject>(NULL); + plugin_object_ = np_utils::NPCreateObject<GPUPluginObject>(NULL); + + command_buffer_ = new MockCommandBuffer; - command_buffer_ = NPCreateObject<MockCommandBuffer>(NULL); + // Takes ownership. plugin_object_->set_command_buffer(command_buffer_); - processor_ = new MockGPUProcessor(NULL, command_buffer_.Get()); + processor_ = new MockGPUProcessor(command_buffer_); plugin_object_->set_gpu_processor(processor_.get()); - - window_object_ = NPCreateObject<DynamicNPObject>(NULL); - ON_CALL(mock_browser_, GetWindowNPObject(NULL)) - .WillByDefault(Return(window_object_.ToReturned())); - - chromium_object_ = NPCreateObject<DynamicNPObject>(NULL); - NPSetProperty(NULL, window_object_, "chromium", chromium_object_); - - system_object_ = NPCreateObject<StrictMock<MockSystemNPObject> >(NULL); - NPSetProperty(NULL, chromium_object_, "system", system_object_); } MockNPBrowser mock_browser_; NPObjectPointer<GPUPluginObject> plugin_object_; - NPObjectPointer<MockCommandBuffer> command_buffer_; + MockCommandBuffer* command_buffer_; scoped_refptr<MockGPUProcessor> processor_; - NPObjectPointer<DynamicNPObject> window_object_; - NPObjectPointer<DynamicNPObject> chromium_object_; - NPObjectPointer<MockSystemNPObject> system_object_; }; namespace { @@ -203,14 +181,14 @@ TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) { } TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { - EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + EXPECT_CALL(*command_buffer_, Initialize(NotNull())) .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), Return(true))); EXPECT_CALL(*processor_.get(), Initialize(NULL)) .WillOnce(Return(true)); - EXPECT_CALL(*command_buffer_.Get(), SetPutOffsetChangeCallback(NotNull())) + EXPECT_CALL(*command_buffer_, SetPutOffsetChangeCallback(NotNull())) .WillOnce(Invoke(DeleteObject<Callback0::Type>)); EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", @@ -231,7 +209,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { EXPECT_EQ(GPUPluginObject::kInitializationSuccessful, plugin_object_->GetStatus()); - EXPECT_CALL(*command_buffer_.Get(), SetPutOffsetChangeCallback(NULL)); + EXPECT_CALL(*command_buffer_, SetPutOffsetChangeCallback(NULL)); EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); } @@ -246,7 +224,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfWindowNotReady) { // Set status as though SetWindow has not been called. plugin_object_->set_status(GPUPluginObject::kWaitingForSetWindow); - EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); + EXPECT_TRUE(NULL == plugin_object_->OpenCommandBuffer()); EXPECT_EQ(GPUPluginObject::kWaitingForSetWindow, plugin_object_->GetStatus()); } @@ -254,7 +232,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfWindowNotReady) { TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCommandBufferCannotInitialize) { - EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + EXPECT_CALL(*command_buffer_, Initialize(NotNull())) .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), Return(false))); @@ -268,7 +246,7 @@ TEST_F(GPUPluginObjectTest, // valid window handle to pass to SetWindow in tests. plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer); - EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); + EXPECT_TRUE(NULL == plugin_object_->OpenCommandBuffer()); EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, plugin_object_->GetStatus()); @@ -278,7 +256,7 @@ TEST_F(GPUPluginObjectTest, TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIGPUProcessorCannotInitialize) { - EXPECT_CALL(*command_buffer_.Get(), Initialize(NotNull())) + EXPECT_CALL(*command_buffer_, Initialize(NotNull())) .WillOnce(DoAll(Invoke(DeleteObject<SharedMemory>), Return(true))); @@ -295,7 +273,7 @@ TEST_F(GPUPluginObjectTest, // valid window handle to pass to SetWindow in tests. plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer); - EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); + EXPECT_TRUE(NULL == plugin_object_->OpenCommandBuffer()); EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, plugin_object_->GetStatus()); @@ -303,7 +281,7 @@ TEST_F(GPUPluginObjectTest, EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); } -class MockEventSync : public DefaultNPObject<NPObject> { +class MockEventSync : public np_utils::DefaultNPObject<NPObject> { public: explicit MockEventSync(NPP npp) { } @@ -326,7 +304,7 @@ TEST_F(GPUPluginObjectTest, SendsResizeEventOnSetWindow) { NULL)); NPObjectPointer<MockEventSync> event_sync = - NPCreateObject<MockEventSync>(NULL); + np_utils::NPCreateObject<MockEventSync>(NULL); plugin_object_->SetEventSync(event_sync); EXPECT_CALL(*event_sync.Get(), Resize(100, 200)); diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_object_win.cc b/o3d/gpu/gpu_plugin/gpu_plugin_object_win.cc index 7108a09..31c6393 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_object_win.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_object_win.cc @@ -4,8 +4,8 @@ #include <windows.h> +#include "gpu/command_buffer/service/gpu_processor.h" #include "gpu/gpu_plugin/gpu_plugin_object.h" -#include "gpu/gpu_plugin/gpu_processor.h" namespace gpu_plugin { diff --git a/o3d/gpu/gpu_plugin/gpu_plugin_unittest.cc b/o3d/gpu/gpu_plugin/gpu_plugin_unittest.cc index 7d9ae86..8e10ba8 100644 --- a/o3d/gpu/gpu_plugin/gpu_plugin_unittest.cc +++ b/o3d/gpu/gpu_plugin/gpu_plugin_unittest.cc @@ -21,6 +21,8 @@ #define INITIALIZE_PLUGIN_FUNCS #endif +using np_utils::MockPluginObject; +using np_utils::PluginObject; using testing::_; using testing::DoAll; using testing::NiceMock; @@ -37,9 +39,9 @@ class GPUPluginTest : public testing::Test { memset(&browser_funcs_, 0, sizeof(browser_funcs_)); memset(&plugin_funcs_, 0, sizeof(plugin_funcs_)); - plugin_object_factory_ = new StrictMock<MockPluginObjectFactory>; + plugin_object_factory_ = new StrictMock<np_utils::MockPluginObjectFactory>; - np_class_ = NPGetClass<StrictMock<MockNPObject> >(); + np_class_ = np_utils::NPGetClass<StrictMock<np_utils::MockNPObject> >(); } virtual void TearDown() { @@ -49,7 +51,7 @@ class GPUPluginTest : public testing::Test { NPP_t npp_; NPNetscapeFuncs browser_funcs_; NPPluginFuncs plugin_funcs_; - MockPluginObjectFactory* plugin_object_factory_; + np_utils::MockPluginObjectFactory* plugin_object_factory_; const NPClass* np_class_; }; @@ -144,7 +146,7 @@ TEST_F(GPUPluginTest, HandleEventReturnsFalseForInvalidInstance) { } TEST_F(GPUPluginTest, NewCreatesAPluginObjectAndInitializesIt) { - StrictMock<MockPluginObject> plugin_object; + StrictMock<np_utils::MockPluginObject> plugin_object; EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) diff --git a/o3d/gpu/np_utils/default_np_object.h b/o3d/gpu/np_utils/default_np_object.h index 575dabc..b3b5fc0 100644 --- a/o3d/gpu/np_utils/default_np_object.h +++ b/o3d/gpu/np_utils/default_np_object.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "gpu/np_utils/np_headers.h" -namespace gpu_plugin { +namespace np_utils { class BaseNPDispatcher; @@ -79,6 +79,6 @@ class DefaultNPObject : public RootClass { private: DISALLOW_COPY_AND_ASSIGN(DefaultNPObject); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_DEFAULT_NP_OBJECT_H_ diff --git a/o3d/gpu/np_utils/dispatched_np_object_unittest.cc b/o3d/gpu/np_utils/dispatched_np_object_unittest.cc index d4b2f96..19d5a2b 100644 --- a/o3d/gpu/np_utils/dispatched_np_object_unittest.cc +++ b/o3d/gpu/np_utils/dispatched_np_object_unittest.cc @@ -14,7 +14,7 @@ using testing::Return; using testing::StrictMock; -namespace gpu_plugin { +namespace np_utils { // This mock class has a dispatcher chain with an entry for each mocked // function. The tests that follow that invoking an NPAPI method calls the @@ -400,4 +400,4 @@ TEST_F(DispatchedNPObjectTest, EnumeratesAllAvailableMethods) { NPBrowser::get()->MemFree(names); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/dynamic_np_object.cc b/o3d/gpu/np_utils/dynamic_np_object.cc index 153c189..e037fdc 100644 --- a/o3d/gpu/np_utils/dynamic_np_object.cc +++ b/o3d/gpu/np_utils/dynamic_np_object.cc @@ -4,7 +4,7 @@ #include "gpu/np_utils/dynamic_np_object.h" -namespace gpu_plugin { +namespace np_utils { DynamicNPObject::DynamicNPObject(NPP npp) { } @@ -56,4 +56,4 @@ bool DynamicNPObject::Enumerate(NPIdentifier** names, uint32_t* count) { return true; } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/dynamic_np_object.h b/o3d/gpu/np_utils/dynamic_np_object.h index 8dd4892..2b63e78 100644 --- a/o3d/gpu/np_utils/dynamic_np_object.h +++ b/o3d/gpu/np_utils/dynamic_np_object.h @@ -10,7 +10,7 @@ #include "gpu/np_utils/default_np_object.h" #include "gpu/np_utils/np_utils.h" -namespace gpu_plugin { +namespace np_utils { // NPObjects of this type have a dictionary of property name / variant pairs // that can be changed at runtime through NPAPI. @@ -30,6 +30,6 @@ class DynamicNPObject : public DefaultNPObject<NPObject> { PropertyMap properties_; DISALLOW_COPY_AND_ASSIGN(DynamicNPObject); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_DYNAMIC_NP_OBJECT_H_ diff --git a/o3d/gpu/np_utils/dynamic_np_object_unittest.cc b/o3d/gpu/np_utils/dynamic_np_object_unittest.cc index 56fcff7..d58e963 100644 --- a/o3d/gpu/np_utils/dynamic_np_object_unittest.cc +++ b/o3d/gpu/np_utils/dynamic_np_object_unittest.cc @@ -13,7 +13,7 @@ using testing::Return; using testing::StrictMock; -namespace gpu_plugin { +namespace np_utils { class NPDynamicNPObjectTest : public testing::Test { protected: @@ -80,4 +80,4 @@ TEST_F(NPDynamicNPObjectTest, InvalidateNullsObjectProperties) { EXPECT_EQ(2, object_->referenceCount); NPBrowser::get()->ReleaseObject(object_.Get()); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_browser.cc b/o3d/gpu/np_utils/np_browser.cc index 3754d3b..5eb93a3 100644 --- a/o3d/gpu/np_utils/np_browser.cc +++ b/o3d/gpu/np_utils/np_browser.cc @@ -11,7 +11,7 @@ #include "o3d/third_party/npapi/include/npfunctions.h" #endif -namespace gpu_plugin { +namespace np_utils { NPBrowser* NPBrowser::browser_; @@ -125,4 +125,4 @@ void NPBrowser::UnscheduleTimer(NPP npp, uint32 timer_id) { netscape_funcs_->unscheduletimer(npp, timer_id); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_browser.h b/o3d/gpu/np_utils/np_browser.h index d792316..e46bf38 100644 --- a/o3d/gpu/np_utils/np_browser.h +++ b/o3d/gpu/np_utils/np_browser.h @@ -10,7 +10,7 @@ typedef struct _NPNetscapeFuncs NPNetscapeFuncs; -namespace gpu_plugin { +namespace np_utils { // This class exposes the functions provided by the browser to a plugin (the // ones prefixed NPN_). @@ -90,6 +90,6 @@ class NPBrowser { DISALLOW_COPY_AND_ASSIGN(NPBrowser); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_BROWSER_H_ diff --git a/o3d/gpu/np_utils/np_browser_mock.h b/o3d/gpu/np_utils/np_browser_mock.h index 1ef574e..c5361c7 100644 --- a/o3d/gpu/np_utils/np_browser_mock.h +++ b/o3d/gpu/np_utils/np_browser_mock.h @@ -8,7 +8,7 @@ #include "gpu/np_utils/np_browser_stub.h" #include "testing/gmock/include/gmock/gmock.h" -namespace gpu_plugin { +namespace np_utils { // This mocks certain member functions of the stub browser. Those relating // to identifiers, memory management, reference counting and forwarding to @@ -45,6 +45,6 @@ class MockNPBrowser : public StubNPBrowser { MOCK_METHOD2(UnscheduleTimer, void(NPP npp, uint32 timer_id)); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_BROWSER_MOCK_H_ diff --git a/o3d/gpu/np_utils/np_browser_stub.cc b/o3d/gpu/np_utils/np_browser_stub.cc index 2bc1c6a..2e1c757 100644 --- a/o3d/gpu/np_utils/np_browser_stub.cc +++ b/o3d/gpu/np_utils/np_browser_stub.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "base/message_loop.h" -namespace gpu_plugin { +namespace np_utils { StubNPBrowser::StubNPBrowser() : NPBrowser(NULL) { } @@ -122,4 +122,4 @@ uint32 StubNPBrowser::ScheduleTimer(NPP npp, void StubNPBrowser::UnscheduleTimer(NPP npp, uint32 timer_id) { } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_browser_stub.h b/o3d/gpu/np_utils/np_browser_stub.h index b18d52d..f208b7b 100644 --- a/o3d/gpu/np_utils/np_browser_stub.h +++ b/o3d/gpu/np_utils/np_browser_stub.h @@ -10,7 +10,7 @@ #include "gpu/np_utils/np_browser.h" -namespace gpu_plugin { +namespace np_utils { // Simple implementation of subset of the NPN functions for testing. class StubNPBrowser : public NPBrowser { @@ -79,6 +79,6 @@ class StubNPBrowser : public NPBrowser { DISALLOW_COPY_AND_ASSIGN(StubNPBrowser); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_BROWSER_STUB_H_ diff --git a/o3d/gpu/np_utils/np_class.h b/o3d/gpu/np_utils/np_class.h index 113f493..21d1d4b 100644 --- a/o3d/gpu/np_utils/np_class.h +++ b/o3d/gpu/np_utils/np_class.h @@ -13,7 +13,7 @@ // function pointers will invoke the most derived corresponding member // functions in T. -namespace gpu_plugin { +namespace np_utils { namespace np_class_impl { // This template version of the NPClass allocate function creates a subclass @@ -120,6 +120,6 @@ const NPClass* NPGetClass() { return &np_class; }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_CLASS_H_ diff --git a/o3d/gpu/np_utils/np_class_unittest.cc b/o3d/gpu/np_utils/np_class_unittest.cc index 0db632b..0e7807f 100644 --- a/o3d/gpu/np_utils/np_class_unittest.cc +++ b/o3d/gpu/np_utils/np_class_unittest.cc @@ -9,7 +9,7 @@ using testing::StrictMock; -namespace gpu_plugin { +namespace np_utils { class NPClassTest : public testing::Test { protected: @@ -140,4 +140,4 @@ TEST_F(NPClassTest, ConstructForwards) { np_class->deallocate(object); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_dispatcher.cc b/o3d/gpu/np_utils/np_dispatcher.cc index 7859f8b..63293c0 100644 --- a/o3d/gpu/np_utils/np_dispatcher.cc +++ b/o3d/gpu/np_utils/np_dispatcher.cc @@ -4,7 +4,7 @@ #include "gpu/np_utils/np_dispatcher.h" -namespace gpu_plugin { +namespace np_utils { bool DispatcherHasMethodHelper(BaseNPDispatcher* chain, NPObject* object, @@ -83,4 +83,4 @@ BaseNPDispatcher::BaseNPDispatcher(BaseNPDispatcher* next, const NPUTF8* name) BaseNPDispatcher::~BaseNPDispatcher() { } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_dispatcher.h b/o3d/gpu/np_utils/np_dispatcher.h index 5b84f86..ff6bed5 100644 --- a/o3d/gpu/np_utils/np_dispatcher.h +++ b/o3d/gpu/np_utils/np_dispatcher.h @@ -39,12 +39,13 @@ NP_UTILS_DISPATCHER_JOIN(dispatcher, __LINE__) #define NP_UTILS_BEGIN_DISPATCHER_CHAIN(Class, BaseClass) \ - static BaseNPDispatcher* GetDispatcherChain() { \ + static ::np_utils::BaseNPDispatcher* GetDispatcherChain() { \ typedef Class ThisClass; \ - BaseNPDispatcher* top_dispatcher = BaseClass::GetDispatcherChain(); \ + ::np_utils::BaseNPDispatcher* top_dispatcher = \ + BaseClass::GetDispatcherChain(); \ #define NP_UTILS_DISPATCHER(name, Signature) \ - static NPDispatcher<ThisClass, Signature> \ + static ::np_utils::NPDispatcher<ThisClass, Signature> \ NP_UTILS_DISPATCHER_UNIQUE( \ top_dispatcher, \ #name, \ @@ -55,27 +56,28 @@ return top_dispatcher; \ } \ bool HasMethod(NPIdentifier name) { \ - return DispatcherHasMethodHelper(GetDispatcherChain(), this, name); \ + return ::np_utils::DispatcherHasMethodHelper( \ + GetDispatcherChain(), this, name); \ } \ bool Invoke(NPIdentifier name, \ const NPVariant* args, \ uint32_t num_args, \ NPVariant* result) { \ - return DispatcherInvokeHelper(GetDispatcherChain(), \ - this, \ - name, \ - args, \ - num_args, \ - result); \ + return ::np_utils::DispatcherInvokeHelper(GetDispatcherChain(), \ + this, \ + name, \ + args, \ + num_args, \ + result); \ } \ bool Enumerate(NPIdentifier** names, uint32_t* num_names) { \ - return DispatcherEnumerateHelper(GetDispatcherChain(), \ - this, \ - names, \ - num_names); \ + return ::np_utils::DispatcherEnumerateHelper(GetDispatcherChain(), \ + this, \ + names, \ + num_names); \ } \ -namespace gpu_plugin { +namespace np_utils { class BaseNPDispatcher { public: @@ -217,6 +219,6 @@ struct NPDispatcher { #undef TO_NPVARIANT -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_DISPATCHER_H_ diff --git a/o3d/gpu/np_utils/np_object_mock.h b/o3d/gpu/np_utils/np_object_mock.h index 8c3d0e7..99d1ff6 100644 --- a/o3d/gpu/np_utils/np_object_mock.h +++ b/o3d/gpu/np_utils/np_object_mock.h @@ -8,7 +8,7 @@ #include "gpu/np_utils/np_browser.h" #include "testing/gmock/include/gmock/gmock.h" -namespace gpu_plugin { +namespace np_utils { class MockNPObject : public NPObject { public: @@ -31,6 +31,6 @@ class MockNPObject : public NPObject { DISALLOW_COPY_AND_ASSIGN(MockNPObject); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_OBJECT_MOCK_H_ diff --git a/o3d/gpu/np_utils/np_object_pointer.h b/o3d/gpu/np_utils/np_object_pointer.h index a8987be..44286a7 100644 --- a/o3d/gpu/np_utils/np_object_pointer.h +++ b/o3d/gpu/np_utils/np_object_pointer.h @@ -9,7 +9,7 @@ #include "gpu/np_utils/np_browser.h" #include "gpu/np_utils/np_headers.h" -namespace gpu_plugin { +namespace np_utils { // Smart pointer for NPObjects that automatically handles reference counting. template <typename NPObjectType> @@ -114,6 +114,6 @@ std::ostream& operator<<(std::ostream& stream, const NPObjectPointer<NPObjectType>& pointer) { return stream << pointer.Get(); } -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_OBJECT_POINTER_H_ diff --git a/o3d/gpu/np_utils/np_object_pointer_unittest.cc b/o3d/gpu/np_utils/np_object_pointer_unittest.cc index c14f6ed..1e48453 100644 --- a/o3d/gpu/np_utils/np_object_pointer_unittest.cc +++ b/o3d/gpu/np_utils/np_object_pointer_unittest.cc @@ -12,7 +12,7 @@ using testing::Return; using testing::StrictMock; -namespace gpu_plugin { +namespace np_utils { class DerivedNPObject : public MockNPObject { public: @@ -217,4 +217,4 @@ TEST_F(NPObjectPointerTest, NULLPointerCanBeReturnedAsARawNPObject) { EXPECT_TRUE(NULL == p.ToReturned()); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_plugin_object.h b/o3d/gpu/np_utils/np_plugin_object.h index 063079f..ad578e4 100644 --- a/o3d/gpu/np_utils/np_plugin_object.h +++ b/o3d/gpu/np_utils/np_plugin_object.h @@ -8,7 +8,7 @@ #include "gpu/np_utils/np_object_pointer.h" #include "gpu/np_utils/np_headers.h" -namespace gpu_plugin { +namespace np_utils { // Interface for a plugin instance. The NPP plugin calls forwards to an instance // of this interface. @@ -45,6 +45,6 @@ class PluginObject { DISALLOW_COPY_AND_ASSIGN(PluginObject); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_PLUGIN_OBJECT_H_ diff --git a/o3d/gpu/np_utils/np_plugin_object_factory.cc b/o3d/gpu/np_utils/np_plugin_object_factory.cc index 831a4bd..7eedcc8 100644 --- a/o3d/gpu/np_utils/np_plugin_object_factory.cc +++ b/o3d/gpu/np_utils/np_plugin_object_factory.cc @@ -5,7 +5,7 @@ #include "gpu/gpu_plugin/gpu_plugin_object_factory.h" #include "base/logging.h" -namespace gpu_plugin { +namespace np_utils { NPPluginObjectFactory* NPPluginObjectFactory::factory_; @@ -27,4 +27,4 @@ NPPluginObjectFactory::~NPPluginObjectFactory() { factory_ = previous_factory_; } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_plugin_object_factory.h b/o3d/gpu/np_utils/np_plugin_object_factory.h index 403d8d5..969f5a3 100644 --- a/o3d/gpu/np_utils/np_plugin_object_factory.h +++ b/o3d/gpu/np_utils/np_plugin_object_factory.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "gpu/np_utils/np_headers.h" -namespace gpu_plugin { +namespace np_utils { class PluginObject; @@ -32,6 +32,6 @@ class NPPluginObjectFactory { DISALLOW_COPY_AND_ASSIGN(NPPluginObjectFactory); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_PLUGIN_OBJECT_FACTORY_H_ diff --git a/o3d/gpu/np_utils/np_plugin_object_factory_mock.h b/o3d/gpu/np_utils/np_plugin_object_factory_mock.h index e15447a..a09205c 100644 --- a/o3d/gpu/np_utils/np_plugin_object_factory_mock.h +++ b/o3d/gpu/np_utils/np_plugin_object_factory_mock.h @@ -9,7 +9,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -namespace gpu_plugin { +namespace np_utils { // Mockable factory used to create instances of PluginObject based on plugin // mime type. @@ -18,6 +18,6 @@ class MockPluginObjectFactory : public NPPluginObjectFactory { MOCK_METHOD2(CreatePluginObject, PluginObject*(NPP, NPMIMEType)); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_PLUGIN_OBJECT_FACTORY_MOCK_H_ diff --git a/o3d/gpu/np_utils/np_plugin_object_mock.h b/o3d/gpu/np_utils/np_plugin_object_mock.h index e67861b..342b22c 100644 --- a/o3d/gpu/np_utils/np_plugin_object_mock.h +++ b/o3d/gpu/np_utils/np_plugin_object_mock.h @@ -9,7 +9,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -namespace gpu_plugin { +namespace np_utils { class MockPluginObject : public PluginObject { public: @@ -21,6 +21,6 @@ class MockPluginObject : public PluginObject { MOCK_METHOD0(GetScriptableNPObject, NPObject*()); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_PLUGIN_OBJECT_MOCK_H_ diff --git a/o3d/gpu/np_utils/np_utils.cc b/o3d/gpu/np_utils/np_utils.cc index 03c4a20..d6a15a4 100644 --- a/o3d/gpu/np_utils/np_utils.cc +++ b/o3d/gpu/np_utils/np_utils.cc @@ -4,7 +4,7 @@ #include "gpu/np_utils/np_utils.h" -namespace gpu_plugin { +namespace np_utils { bool NPVariantToValue(bool* value, const NPVariant& variant) { if (NPVARIANT_IS_BOOLEAN(variant)) { @@ -167,4 +167,4 @@ bool NPRemoveProperty(NPP npp, NPBrowser::get()->GetStringIdentifier(name)); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/np_utils.h b/o3d/gpu/np_utils/np_utils.h index 2ab9384..5c7e3b7 100644 --- a/o3d/gpu/np_utils/np_utils.h +++ b/o3d/gpu/np_utils/np_utils.h @@ -12,7 +12,7 @@ #include "gpu/np_utils/np_object_pointer.h" #include "gpu/np_utils/np_headers.h" -namespace gpu_plugin { +namespace np_utils { // Convert NPVariant to C++ type. Returns whether the conversion was successful. bool NPVariantToValue(bool* value, const NPVariant& variant); @@ -266,6 +266,6 @@ NPObjectPointer<NPObjectType> NPCreateObject(NPP npp) { return NPObjectPointer<NPObjectType>::FromReturned(object); } -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_NP_UTILS_H_ diff --git a/o3d/gpu/np_utils/np_utils_unittest.cc b/o3d/gpu/np_utils/np_utils_unittest.cc index e481187..ceb87ad 100644 --- a/o3d/gpu/np_utils/np_utils_unittest.cc +++ b/o3d/gpu/np_utils/np_utils_unittest.cc @@ -17,7 +17,7 @@ using testing::Return; using testing::SetArgumentPointee; using testing::StrictMock; -namespace gpu_plugin { +namespace np_utils { class NPUtilsTest : public testing::Test { protected: @@ -421,4 +421,4 @@ TEST_F(NPUtilsTest, CanRemovePropertyValue) { EXPECT_TRUE(NPRemoveProperty(NULL, object, "foo")); } -} // namespace gpu_plugin +} // namespace np_utils diff --git a/o3d/gpu/np_utils/webkit_browser.h b/o3d/gpu/np_utils/webkit_browser.h index 8afc167..6b57d05 100644 --- a/o3d/gpu/np_utils/webkit_browser.h +++ b/o3d/gpu/np_utils/webkit_browser.h @@ -17,7 +17,7 @@ typedef struct _NPNetscapeFuncs NPNetscapeFuncs; typedef struct _NPChromiumFuncs NPChromiumFuncs; -namespace gpu_plugin { +namespace np_utils { // This class implements NPBrowser for the WebKit WebBindings. class WebKitBrowser : public NPBrowser { @@ -112,6 +112,6 @@ class WebKitBrowser : public NPBrowser { DISALLOW_COPY_AND_ASSIGN(WebKitBrowser); }; -} // namespace gpu_plugin +} // namespace np_utils #endif // GPU_NP_UTILS_WEBKIT_BROWSER_H_ diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index 0dfa4b5..aa59a5d 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -54,9 +54,9 @@ #endif using o3d::DisplayWindowCB; -using gpu_plugin::NPObjectPointer; -using gpu_plugin::NPVariantToValue; -using gpu_plugin::ValueToNPVariant; +using np_utils::NPObjectPointer; +using np_utils::NPVariantToValue; +using np_utils::ValueToNPVariant; namespace glue { namespace _o3d { diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc index 13cfc12..da4a1c2 100644 --- a/o3d/plugin/win/main_win.cc +++ b/o3d/plugin/win/main_win.cc @@ -54,7 +54,7 @@ #if defined(RENDERER_CB) #include "core/cross/command_buffer/renderer_cb.h" #include "core/cross/command_buffer/display_window_cb.h" -#include "gpu/gpu_plugin/command_buffer.h" +#include "gpu/command_buffer/common/command_buffer.h" #endif using glue::_o3d::PluginObject; @@ -63,8 +63,7 @@ using o3d::DisplayWindowWindows; using o3d::Event; #if defined(RENDERER_CB) -using gpu_plugin::CommandBuffer; -using gpu_plugin::NPObjectPointer; +using command_buffer::CommandBuffer; #endif namespace { @@ -75,7 +74,7 @@ HINSTANCE g_module_instance; // move over to gyp. This is just to avoid having to write scons files for // np_utils. #if defined(RENDERER_CB) -gpu_plugin::NPBrowser* g_browser; +np_utils::NPBrowser* g_browser; #endif } // namespace anonymous @@ -738,7 +737,7 @@ NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) { HANDLE_CRASHES; #if defined(RENDERER_CB) - g_browser = new gpu_plugin::NPBrowser(browserFuncs); + g_browser = new np_utils::NPBrowser(browserFuncs); #endif NPError retval = InitializeNPNApi(browserFuncs); @@ -918,13 +917,14 @@ NPError NPP_SetWindow(NPP instance, NPWindow *window) { // create and assign the graphics context #if defined(RENDERER_CB) const unsigned int kDefaultCommandBufferSize = 256 << 10; - NPObjectPointer<CommandBuffer> command_buffer = + + // RendererCB takes ownership of CommandBuffer. + CommandBuffer* command_buffer = RendererCBLocal::CreateCommandBuffer(instance, obj->GetHWnd(), kDefaultCommandBufferSize); DisplayWindowCB default_display; - default_display.set_npp(instance); default_display.set_command_buffer(command_buffer); obj->CreateRenderer(default_display); diff --git a/o3d/tests/common/win/testing_common.cc b/o3d/tests/common/win/testing_common.cc index ba7c402..7e8937d 100644 --- a/o3d/tests/common/win/testing_common.cc +++ b/o3d/tests/common/win/testing_common.cc @@ -53,7 +53,6 @@ #if defined(RENDERER_CB) #include "core/cross/command_buffer/renderer_cb.h" #include "core/cross/command_buffer/display_window_cb.h" -#include "gpu/gpu_plugin/command_buffer.h" #include "gpu/np_utils/np_browser_stub.h" #endif @@ -61,9 +60,8 @@ using o3d::DisplayWindowWindows; #if defined(RENDERER_CB) using o3d::DisplayWindowCB; -using gpu_plugin::CommandBuffer; -using gpu_plugin::NPObjectPointer; -using gpu_plugin::StubNPBrowser; +using np_utils::NPObjectPointer; +using np_utils::StubNPBrowser; using o3d::RendererCBLocal; #endif @@ -190,8 +188,8 @@ int WINAPI WinMain(HINSTANCE instance, #if defined(RENDERER_CB) const unsigned int kDefaultCommandBufferSize = 256 << 10; + // RendererCB takes ownership of CommandBuffer. DisplayWindowCB* display_window = new o3d::DisplayWindowCB; - display_window->set_npp(NULL); display_window->set_command_buffer(RendererCBLocal::CreateCommandBuffer( NULL, g_window_handle, |