diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 18:51:50 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 18:51:50 +0000 |
commit | d8cafdf39a84559f2ce223d1710bf91950415215 (patch) | |
tree | dde721bddfd4de569d06831fad16195c7ead07c5 /o3d/gpu_plugin | |
parent | b75dca87f3ff3ee3ab003960276ec7bb49d4c734 (diff) | |
download | chromium_src-d8cafdf39a84559f2ce223d1710bf91950415215.zip chromium_src-d8cafdf39a84559f2ce223d1710bf91950415215.tar.gz chromium_src-d8cafdf39a84559f2ce223d1710bf91950415215.tar.bz2 |
Moved responsibility for creating ring buffer from CommandBuffer to GPUPluginObject.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/264041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/gpu_plugin')
-rw-r--r-- | o3d/gpu_plugin/command_buffer.cc | 33 | ||||
-rw-r--r-- | o3d/gpu_plugin/command_buffer.h | 6 | ||||
-rw-r--r-- | o3d/gpu_plugin/command_buffer_mock.h | 2 | ||||
-rw-r--r-- | o3d/gpu_plugin/command_buffer_unittest.cc | 162 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_object.cc | 27 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_object_unittest.cc | 68 |
6 files changed, 164 insertions, 134 deletions
diff --git a/o3d/gpu_plugin/command_buffer.cc b/o3d/gpu_plugin/command_buffer.cc index 293235ce..3dc35b8 100644 --- a/o3d/gpu_plugin/command_buffer.cc +++ b/o3d/gpu_plugin/command_buffer.cc @@ -22,41 +22,24 @@ CommandBuffer::CommandBuffer(NPP npp) CommandBuffer::~CommandBuffer() { } -bool CommandBuffer::Initialize(int32 size) { - // Check the size will not overflow when it is converted from count of int32s - // to count of bytes. - int32 num_bytes = static_cast<int32>(size * sizeof(int32)); - if (num_bytes / sizeof(int32) != size) - return false; - +bool CommandBuffer::Initialize(NPObjectPointer<NPObject> ring_buffer) { + // Fail if already initialized. if (ring_buffer_.Get()) return false; - NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( - NPBrowser::get()->GetWindowNPObject(npp_)); - if (!window.Get()) + if (!ring_buffer.Get()) return false; - NPObjectPointer<NPObject> chromium; - if (!NPGetProperty(npp_, window, "chromium", &chromium)) { + int32 size_in_bytes; + if (!NPInvoke(npp_, ring_buffer, "getSize", &size_in_bytes)) return false; - } - NPObjectPointer<NPObject> system; - if (!NPGetProperty(npp_, chromium, "system", &system)) { + if (size_in_bytes < 0) return false; - } - if (!NPInvoke(npp_, system, "createSharedMemory", num_bytes, - &ring_buffer_)) { - return false; - } - - if (!ring_buffer_.Get()) { - return false; - } + size_ = size_in_bytes / sizeof(int32); + ring_buffer_ = ring_buffer; - size_ = size; return true; } diff --git a/o3d/gpu_plugin/command_buffer.h b/o3d/gpu_plugin/command_buffer.h index 65d5343..492bb18 100644 --- a/o3d/gpu_plugin/command_buffer.h +++ b/o3d/gpu_plugin/command_buffer.h @@ -23,8 +23,8 @@ class CommandBuffer : public DefaultNPObject<NPObject> { explicit CommandBuffer(NPP npp); virtual ~CommandBuffer(); - // Create a shared memory buffer of the given size. - virtual bool Initialize(int32 size); + // Initialize the command buffer with the given buffer. + virtual bool Initialize(NPObjectPointer<NPObject> ring_buffer); // Gets the shared memory ring buffer object for the command buffer. virtual NPObjectPointer<NPObject> GetRingBuffer(); @@ -106,7 +106,7 @@ class CommandBuffer : public DefaultNPObject<NPObject> { } NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) - NP_UTILS_DISPATCHER(Initialize, bool(int32 size)) + NP_UTILS_DISPATCHER(Initialize, bool(NPObjectPointer<NPObject> ring_buffer)) NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<NPObject>()) NP_UTILS_DISPATCHER(GetSize, int32()) NP_UTILS_DISPATCHER(SyncOffsets, int32(int32 get_offset)) diff --git a/o3d/gpu_plugin/command_buffer_mock.h b/o3d/gpu_plugin/command_buffer_mock.h index 6592546..737f8ff 100644 --- a/o3d/gpu_plugin/command_buffer_mock.h +++ b/o3d/gpu_plugin/command_buffer_mock.h @@ -22,7 +22,7 @@ class MockCommandBuffer : public CommandBuffer { .WillByDefault(testing::Return(NPObjectPointer<NPObject>())); } - MOCK_METHOD1(Initialize, bool(int32 size)); + MOCK_METHOD1(Initialize, bool(NPObjectPointer<NPObject> ring_buffer)); MOCK_METHOD0(GetRingBuffer, NPObjectPointer<NPObject>()); MOCK_METHOD0(GetSize, int32()); MOCK_METHOD1(SyncOffsets, int32(int32 put_offset)); diff --git a/o3d/gpu_plugin/command_buffer_unittest.cc b/o3d/gpu_plugin/command_buffer_unittest.cc index 8a542d3..81a7bbb 100644 --- a/o3d/gpu_plugin/command_buffer_unittest.cc +++ b/o3d/gpu_plugin/command_buffer_unittest.cc @@ -4,8 +4,8 @@ #include "base/thread.h" #include "o3d/gpu_plugin/command_buffer.h" -#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" +#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" #include "o3d/gpu_plugin/np_utils/np_object_mock.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" #include "o3d/gpu_plugin/system_services/shared_memory_mock.h" @@ -21,41 +21,19 @@ using testing::StrictMock; namespace o3d { 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 CommandBufferTest : public testing::Test { protected: virtual void SetUp() { command_buffer_ = NPCreateObject<CommandBuffer>(NULL); + ring_buffer_ = NPCreateObject<MockSharedMemory>(NULL); - window_object_ = NPCreateObject<DynamicNPObject>(NULL); - - 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_); + ON_CALL(*ring_buffer_.Get(), GetSize()) + .WillByDefault(Return(1024)); } MockNPBrowser mock_browser_; NPObjectPointer<CommandBuffer> command_buffer_; - NPObjectPointer<DynamicNPObject> window_object_; - NPObjectPointer<DynamicNPObject> chromium_object_; - NPObjectPointer<MockSystemNPObject> system_object_; + NPObjectPointer<MockSharedMemory> ring_buffer_; }; TEST_F(CommandBufferTest, NullRingBufferByDefault) { @@ -64,37 +42,30 @@ TEST_F(CommandBufferTest, NullRingBufferByDefault) { } TEST_F(CommandBufferTest, InitializesCommandBuffer) { - EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) - .WillOnce(Return(window_object_.ToReturned())); - - NPObjectPointer<MockSharedMemory> expected_shared_memory = - NPCreateObject<StrictMock<MockSharedMemory> >(NULL); + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); + EXPECT_TRUE(ring_buffer_ == command_buffer_->GetRingBuffer()); + EXPECT_EQ(256, command_buffer_->GetSize()); +} - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) - .WillOnce(Return(expected_shared_memory)); +TEST_F(CommandBufferTest, InitializeFailsSecondTime) { + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); + EXPECT_FALSE(command_buffer_->Initialize(ring_buffer_)); +} - EXPECT_TRUE(command_buffer_->Initialize(256)); - EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer()); +TEST_F(CommandBufferTest, InitializeFailsIfSizeIsNegative) { + ON_CALL(*ring_buffer_.Get(), GetSize()) + .WillByDefault(Return(-1024)); - // Cannot reinitialize. - EXPECT_FALSE(command_buffer_->Initialize(256)); - EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer()); + EXPECT_FALSE(command_buffer_->Initialize(ring_buffer_)); } -TEST_F(CommandBufferTest, InitializeFailsIfSizeIsTooBig) { - EXPECT_FALSE(command_buffer_->Initialize(0x40000000)); +TEST_F(CommandBufferTest, InitializeFailsIfRingBufferIsNull) { + EXPECT_FALSE(command_buffer_->Initialize(NPObjectPointer<NPObject>())); } -TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { - EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) - .WillOnce(Return(window_object_.ToReturned())); - - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) - .WillOnce(Return(NPObjectPointer<NPObject>())); - - EXPECT_FALSE(command_buffer_->Initialize(256)); - EXPECT_EQ(NPObjectPointer<NPObject>(), - command_buffer_->GetRingBuffer()); +TEST_F(CommandBufferTest, InitializeFailsIfRingBufferDoesNotImplementGetSize) { + EXPECT_FALSE(command_buffer_->Initialize( + NPCreateObject<DynamicNPObject>(NULL))); } TEST_F(CommandBufferTest, GetAndPutOffsetsDefaultToZero) { @@ -108,16 +79,7 @@ class MockCallback : public CallbackRunner<Tuple0> { }; TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { - EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) - .WillOnce(Return(window_object_.ToReturned())); - - NPObjectPointer<MockSharedMemory> expected_shared_memory = - NPCreateObject<StrictMock<MockSharedMemory> >(NULL); - - EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) - .WillOnce(Return(expected_shared_memory)); - - EXPECT_TRUE(command_buffer_->Initialize(256)); + EXPECT_TRUE(command_buffer_->Initialize(ring_buffer_)); StrictMock<MockCallback>* put_offset_change_callback = new StrictMock<MockCallback>; @@ -157,72 +119,72 @@ TEST_F(CommandBufferTest, RegisteringNullObjectReturnsZero) { } TEST_F(CommandBufferTest, RegistersDistinctNonZeroHandlesForObject) { - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(2)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); } TEST_F(CommandBufferTest, RegisterObjectReusesUnregisteredHandles) { - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(2)); - command_buffer_->UnregisterObject(window_object_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(3, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(3)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); + command_buffer_->UnregisterObject(ring_buffer_, 1); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(3, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(3)); } TEST_F(CommandBufferTest, CannotUnregisterHandleZero) { - command_buffer_->UnregisterObject(window_object_, 0); + command_buffer_->UnregisterObject(ring_buffer_, 0); EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(0).Get()); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); } TEST_F(CommandBufferTest, CannotUnregisterNegativeHandles) { - command_buffer_->UnregisterObject(window_object_, -1); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); + command_buffer_->UnregisterObject(ring_buffer_, -1); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); } TEST_F(CommandBufferTest, CannotUnregisterUnregisteredHandles) { - command_buffer_->UnregisterObject(window_object_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); + command_buffer_->UnregisterObject(ring_buffer_, 1); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); } TEST_F(CommandBufferTest, CannotUnregisterHandleWithoutDemonstratingAccessToObject) { - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - command_buffer_->UnregisterObject(chromium_object_, 1); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + command_buffer_->UnregisterObject(command_buffer_, 1); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); } // Testing this case specifically because there is an optimization that takes // a different code path in this case. TEST_F(CommandBufferTest, UnregistersLastRegisteredHandle) { - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - command_buffer_->UnregisterObject(window_object_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + command_buffer_->UnregisterObject(ring_buffer_, 1); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); } // Testing this case specifically because there is an optimization that takes // a different code path in this case. TEST_F(CommandBufferTest, UnregistersTwoLastRegisteredHandles) { - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); - EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(2)); - command_buffer_->UnregisterObject(window_object_, 2); - command_buffer_->UnregisterObject(window_object_, 1); - EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); - EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); + EXPECT_EQ(2, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(2)); + command_buffer_->UnregisterObject(ring_buffer_, 2); + command_buffer_->UnregisterObject(ring_buffer_, 1); + EXPECT_EQ(1, command_buffer_->RegisterObject(ring_buffer_)); + EXPECT_EQ(ring_buffer_, command_buffer_->GetRegisteredObject(1)); } TEST_F(CommandBufferTest, DefaultTokenIsZero) { diff --git a/o3d/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu_plugin/gpu_plugin_object.cc index d9a1959..8c33afa 100644 --- a/o3d/gpu_plugin/gpu_plugin_object.cc +++ b/o3d/gpu_plugin/gpu_plugin_object.cc @@ -83,8 +83,33 @@ NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() { if (command_buffer_.Get()) return command_buffer_; + NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( + NPBrowser::get()->GetWindowNPObject(npp_)); + if (!window.Get()) + return NPObjectPointer<NPObject>(); + + NPObjectPointer<NPObject> chromium; + if (!NPGetProperty(npp_, window, "chromium", &chromium)) { + return NPObjectPointer<NPObject>(); + } + + NPObjectPointer<NPObject> system; + if (!NPGetProperty(npp_, chromium, "system", &system)) { + return NPObjectPointer<NPObject>(); + } + + NPObjectPointer<NPObject> ring_buffer; + if (!NPInvoke(npp_, system, "createSharedMemory", kCommandBufferSize, + &ring_buffer)) { + return NPObjectPointer<NPObject>(); + } + + if (!ring_buffer.Get()) { + return NPObjectPointer<NPObject>(); + } + command_buffer_ = NPCreateObject<CommandBuffer>(npp_); - if (command_buffer_->Initialize(kCommandBufferSize)) { + if (command_buffer_->Initialize(ring_buffer)) { processor_ = new GPUProcessor(npp_, command_buffer_); if (processor_->Initialize(static_cast<HWND>(window_.window))) { command_buffer_->SetPutOffsetChangeCallback( diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc index efe38b2..6c32695 100644 --- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc +++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc @@ -5,8 +5,10 @@ #include "o3d/gpu_plugin/command_buffer_mock.h" #include "o3d/gpu_plugin/gpu_plugin_object.h" #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" +#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" #include "o3d/gpu_plugin/np_utils/np_object_mock.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" +#include "o3d/gpu_plugin/system_services/shared_memory_mock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" @@ -26,14 +28,43 @@ using testing::StrictMock; namespace o3d { 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); + + 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<DynamicNPObject> window_object_; + NPObjectPointer<DynamicNPObject> chromium_object_; + NPObjectPointer<MockSystemNPObject> system_object_; }; TEST_F(GPUPluginObjectTest, CanInitializeAndDestroyPluginObject) { @@ -109,6 +140,13 @@ TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) { } TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { + NPObjectPointer<NPObject> ring_buffer = + NPCreateObject<StrictMock<MockSharedMemory> >(NULL); + + EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( + GPUPluginObject::kCommandBufferSize)) + .WillOnce(Return(ring_buffer)); + // Intercept creation of command buffer object and return mock. NPObjectPointer<MockCommandBuffer> command_buffer = NPCreateObject<MockCommandBuffer>(NULL); @@ -116,8 +154,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { NPGetClass<CommandBuffer>())) .WillOnce(Return(command_buffer.ToReturned())); - EXPECT_CALL(*command_buffer.Get(), - Initialize(GPUPluginObject::kCommandBufferSize)) + EXPECT_CALL(*command_buffer.Get(), Initialize(ring_buffer)) .WillOnce(Return(true)); EXPECT_CALL(*command_buffer.Get(), SetPutOffsetChangeCallback(NotNull())); @@ -138,7 +175,31 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) { EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); } +TEST_F(GPUPluginObjectTest, + OpenCommandBufferReturnsNullIfCannotCreateRingBuffer) { + EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( + GPUPluginObject::kCommandBufferSize)) + .WillOnce(Return(NPObjectPointer<NPObject>())); + + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", + 0, + NULL, + NULL, + NULL)); + + EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); + + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); +} + TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) { + NPObjectPointer<NPObject> ring_buffer = + NPCreateObject<StrictMock<MockSharedMemory> >(NULL); + + EXPECT_CALL(*system_object_.Get(), CreateSharedMemory( + GPUPluginObject::kCommandBufferSize)) + .WillOnce(Return(ring_buffer)); + // Intercept creation of command buffer object and return mock. NPObjectPointer<MockCommandBuffer> command_buffer = NPCreateObject<StrictMock<MockCommandBuffer> >(NULL); @@ -146,8 +207,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) { NPGetClass<CommandBuffer>())) .WillOnce(Return(command_buffer.ToReturned())); - EXPECT_CALL(*command_buffer.Get(), - Initialize(GPUPluginObject::kCommandBufferSize)) + EXPECT_CALL(*command_buffer.Get(), Initialize(ring_buffer)) .WillOnce(Return(false)); EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", |