summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 20:39:21 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 20:39:21 +0000
commit0a10a0c4763019391f6d5e98992524f1fbd04c4c (patch)
tree453bc050d9af8a6faefeb0874a89d83b75859057 /o3d
parent0d3843bccab5e58a0f025ac8ef2e9ea23df872ad (diff)
downloadchromium_src-0a10a0c4763019391f6d5e98992524f1fbd04c4c.zip
chromium_src-0a10a0c4763019391f6d5e98992524f1fbd04c4c.tar.gz
chromium_src-0a10a0c4763019391f6d5e98992524f1fbd04c4c.tar.bz2
Added CommandBuffer::GetStatus so remote processes can query whether the plugin has a window handle.
Refactored GPUPluginObject so its CommandBuffer and GPUProcessor can be mocked. Added some new tests using these mock objects. TEST=none BUG=none Review URL: http://codereview.chromium.org/309005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/gpu_plugin/gpu_plugin.gyp1
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object.cc37
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object.h51
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object_unittest.cc143
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object_win.cc17
-rw-r--r--o3d/gpu_plugin/gpu_processor.h8
-rw-r--r--o3d/gpu_plugin/gpu_processor_mock.h43
-rw-r--r--o3d/gpu_plugin/gpu_processor_win.cc20
8 files changed, 246 insertions, 74 deletions
diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp
index 6940524..87d83f5 100644
--- a/o3d/gpu_plugin/gpu_plugin.gyp
+++ b/o3d/gpu_plugin/gpu_plugin.gyp
@@ -108,6 +108,7 @@
'command_buffer_mock.h',
'gpu_processor.h',
'gpu_processor.cc',
+ 'gpu_processor_mock.h',
'gpu_processor_win.cc',
],
},
diff --git a/o3d/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu_plugin/gpu_plugin_object.cc
index 5680ad1..5c543d8 100644
--- a/o3d/gpu_plugin/gpu_plugin_object.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object.cc
@@ -17,7 +17,9 @@ const NPUTF8 GPUPluginObject::kPluginType[] =
GPUPluginObject::GPUPluginObject(NPP npp)
: npp_(npp),
- status_(CREATED) {
+ status_(kWaitingForNew),
+ command_buffer_(NPCreateObject<CommandBuffer>(npp)),
+ processor_(new GPUProcessor(npp, command_buffer_.Get())) {
memset(&window_, 0, sizeof(window_));
}
@@ -26,18 +28,19 @@ NPError GPUPluginObject::New(NPMIMEType plugin_type,
char* argn[],
char* argv[],
NPSavedData* saved) {
- if (status_ != CREATED)
+ if (status_ != kWaitingForNew)
return NPERR_GENERIC_ERROR;
- status_ = INITIALIZED;
+ status_ = kWaitingForSetWindow;
return NPERR_NO_ERROR;
}
NPError GPUPluginObject::SetWindow(NPWindow* new_window) {
- if (status_ != INITIALIZED)
+ if (status_ == kWaitingForNew || status_ == kDestroyed)
return NPERR_GENERIC_ERROR;
+ // PlatformSpecificSetWindow advances the status depending on what happens.
NPError error = PlatformSpecificSetWindow(new_window);
if (error == NPERR_NO_ERROR) {
window_ = *new_window;
@@ -45,8 +48,6 @@ NPError GPUPluginObject::SetWindow(NPWindow* new_window) {
memset(&window_, 0, sizeof(window_));
}
- UpdateProcessorWindow();
-
return error;
}
@@ -55,22 +56,20 @@ int16 GPUPluginObject::HandleEvent(NPEvent* event) {
}
NPError GPUPluginObject::Destroy(NPSavedData** saved) {
- if (status_ != INITIALIZED)
+ if (status_ == kWaitingForNew || status_ == kDestroyed)
return NPERR_GENERIC_ERROR;
- processor_ = NULL;
if (command_buffer_.Get()) {
command_buffer_->SetPutOffsetChangeCallback(NULL);
- command_buffer_ = NPObjectPointer<CommandBuffer>();
}
- status_ = DESTROYED;
+ status_ = kDestroyed;
return NPERR_NO_ERROR;
}
void GPUPluginObject::Release() {
- DCHECK(status_ != INITIALIZED);
+ DCHECK(status_ == kWaitingForNew || status_ == kDestroyed);
NPBrowser::get()->ReleaseObject(this);
}
@@ -80,9 +79,15 @@ NPObject*GPUPluginObject::GetScriptableNPObject() {
}
NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() {
- if (command_buffer_.Get())
+ if (status_ == kInitializationSuccessful)
return command_buffer_;
+ // SetWindow must have been called before OpenCommandBuffer.
+ // PlatformSpecificSetWindow advances the status to
+ // kWaitingForOpenCommandBuffer.
+ if (status_ != kWaitingForOpenCommandBuffer)
+ return NPObjectPointer<NPObject>();
+
NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
NPBrowser::get()->GetWindowNPObject(npp_));
if (!window.Get())
@@ -108,21 +113,17 @@ NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() {
return NPObjectPointer<NPObject>();
}
- command_buffer_ = NPCreateObject<CommandBuffer>(npp_);
if (command_buffer_->Initialize(ring_buffer)) {
- processor_ = new GPUProcessor(npp_, command_buffer_.Get());
if (processor_->Initialize(static_cast<HWND>(window_.window))) {
command_buffer_->SetPutOffsetChangeCallback(
NewCallback(processor_.get(),
&GPUProcessor::ProcessCommands));
- UpdateProcessorWindow();
+ status_ = kInitializationSuccessful;
return command_buffer_;
}
}
- processor_ = NULL;
- command_buffer_ = NPObjectPointer<CommandBuffer>();
- return command_buffer_;
+ return NPObjectPointer<CommandBuffer>();
}
} // namespace gpu_plugin
diff --git a/o3d/gpu_plugin/gpu_plugin_object.h b/o3d/gpu_plugin/gpu_plugin_object.h
index 00c4b85..99bad08 100644
--- a/o3d/gpu_plugin/gpu_plugin_object.h
+++ b/o3d/gpu_plugin/gpu_plugin_object.h
@@ -10,6 +10,7 @@
#include "base/ref_counted.h"
#include "base/thread.h"
#include "o3d/gpu_plugin/command_buffer.h"
+#include "o3d/gpu_plugin/gpu_processor.h"
#include "o3d/gpu_plugin/np_utils/default_np_object.h"
#include "o3d/gpu_plugin/np_utils/np_dispatcher.h"
#include "o3d/gpu_plugin/np_utils/np_headers.h"
@@ -19,14 +20,27 @@
namespace o3d {
namespace gpu_plugin {
-class GPUProcessor;
-
// The scriptable object for the GPU plugin.
class GPUPluginObject : public DefaultNPObject<NPObject>,
public PluginObject {
public:
static const int32 kCommandBufferSize = 1024 * 1024;
+ enum Status {
+ // In the state of waiting for the named function to be called to continue
+ // the initialization sequence.
+ kWaitingForNew,
+ kWaitingForSetWindow,
+ kWaitingForOpenCommandBuffer,
+
+ // Initialization either succeeded or failed.
+ kInitializationSuccessful,
+ kInitializationFailed,
+
+ // Destroy has now been called and the plugin object cannot be used.
+ kDestroyed,
+ };
+
static const NPUTF8 kPluginType[];
explicit GPUPluginObject(NPP npp);
@@ -48,22 +62,39 @@ class GPUPluginObject : public DefaultNPObject<NPObject>,
virtual NPObject* GetScriptableNPObject();
- // Initializes and returns the command buffer object.
+ // Returns the current initialization status. See Status enum.
+ int32 GetStatus() {
+ return status_;
+ }
+
+ // 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();
+ // 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 GPU processor for testing.
+ void set_gpu_processor(const scoped_refptr<GPUProcessor>& processor) {
+ processor_ = processor;
+ }
+
NP_UTILS_BEGIN_DISPATCHER_CHAIN(GPUPluginObject, DefaultNPObject<NPObject>)
+ NP_UTILS_DISPATCHER(GetStatus, int32());
NP_UTILS_DISPATCHER(OpenCommandBuffer, NPObjectPointer<NPObject>())
NP_UTILS_END_DISPATCHER_CHAIN
private:
NPError PlatformSpecificSetWindow(NPWindow* new_window);
- void UpdateProcessorWindow();
-
- enum Status {
- CREATED,
- INITIALIZED,
- DESTROYED,
- };
NPP npp_;
Status status_;
diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
index 6c32695..2bdf5b4 100644
--- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
@@ -4,6 +4,7 @@
#include "o3d/gpu_plugin/command_buffer_mock.h"
#include "o3d/gpu_plugin/gpu_plugin_object.h"
+#include "o3d/gpu_plugin/gpu_processor_mock.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"
@@ -20,6 +21,7 @@
using testing::_;
using testing::DoAll;
+using testing::Invoke;
using testing::NotNull;
using testing::Return;
using testing::SetArgumentPointee;
@@ -49,6 +51,12 @@ class GPUPluginObjectTest : public testing::Test {
virtual void SetUp() {
plugin_object_ = NPCreateObject<GPUPluginObject>(NULL);
+ command_buffer_ = NPCreateObject<MockCommandBuffer>(NULL);
+ plugin_object_->set_command_buffer(command_buffer_);
+
+ processor_ = new MockGPUProcessor(NULL, command_buffer_.Get());
+ plugin_object_->set_gpu_processor(processor_.get());
+
window_object_ = NPCreateObject<DynamicNPObject>(NULL);
ON_CALL(mock_browser_, GetWindowNPObject(NULL))
.WillByDefault(Return(window_object_.ToReturned()));
@@ -62,18 +70,35 @@ class GPUPluginObjectTest : public testing::Test {
MockNPBrowser mock_browser_;
NPObjectPointer<GPUPluginObject> plugin_object_;
+ NPObjectPointer<MockCommandBuffer> command_buffer_;
+ scoped_refptr<MockGPUProcessor> processor_;
NPObjectPointer<DynamicNPObject> window_object_;
NPObjectPointer<DynamicNPObject> chromium_object_;
NPObjectPointer<MockSystemNPObject> system_object_;
};
-TEST_F(GPUPluginObjectTest, CanInitializeAndDestroyPluginObject) {
+namespace {
+template <typename T>
+void DeleteObject(T* object) {
+ delete object;
+}
+} // namespace anonymous
+
+
+TEST_F(GPUPluginObjectTest, CanInstantiateAndDestroyPluginObject) {
+ EXPECT_EQ(GPUPluginObject::kWaitingForNew, plugin_object_->GetStatus());
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
0,
NULL,
NULL,
NULL));
+
+ EXPECT_EQ(GPUPluginObject::kWaitingForSetWindow, plugin_object_->GetStatus());
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+
+ EXPECT_EQ(GPUPluginObject::kDestroyed, plugin_object_->GetStatus());
}
TEST_F(GPUPluginObjectTest, DestroyFailsIfNotInitialized) {
@@ -86,12 +111,18 @@ TEST_F(GPUPluginObjectTest, NewFailsIfAlreadyInitialized) {
NULL,
NULL,
NULL));
+
EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->New("application/foo",
0,
NULL,
NULL,
NULL));
+
+ EXPECT_EQ(GPUPluginObject::kWaitingForSetWindow, plugin_object_->GetStatus());
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+
+ EXPECT_EQ(GPUPluginObject::kDestroyed, plugin_object_->GetStatus());
}
TEST_F(GPUPluginObjectTest, NewFailsIfObjectHasPreviouslyBeenDestroyed) {
@@ -100,12 +131,16 @@ TEST_F(GPUPluginObjectTest, NewFailsIfObjectHasPreviouslyBeenDestroyed) {
NULL,
NULL,
NULL));
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+
EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->New("application/foo",
0,
NULL,
NULL,
NULL));
+
+ EXPECT_EQ(GPUPluginObject::kDestroyed, plugin_object_->GetStatus());
}
TEST_F(GPUPluginObjectTest, WindowIsNullBeforeSetWindowCalled) {
@@ -126,6 +161,8 @@ TEST_F(GPUPluginObjectTest, CanSetWindow) {
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->SetWindow(&window));
EXPECT_EQ(0, memcmp(&window, &plugin_object_->GetWindow(), sizeof(window)));
+ EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer,
+ plugin_object_->GetStatus());
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
@@ -133,10 +170,13 @@ TEST_F(GPUPluginObjectTest, CanSetWindow) {
TEST_F(GPUPluginObjectTest, SetWindowFailsIfNotInitialized) {
NPWindow window = {0};
EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->SetWindow(&window));
+ EXPECT_EQ(GPUPluginObject::kWaitingForNew, plugin_object_->GetStatus());
}
TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) {
- EXPECT_EQ(plugin_object_.Get(), plugin_object_->GetScriptableNPObject());
+ NPObject* scriptable_object = plugin_object_->GetScriptableNPObject();
+ EXPECT_EQ(plugin_object_.Get(), scriptable_object);
+ NPBrowser::get()->ReleaseObject(scriptable_object);
}
TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) {
@@ -147,17 +187,14 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) {
GPUPluginObject::kCommandBufferSize))
.WillOnce(Return(ring_buffer));
- // Intercept creation of command buffer object and return mock.
- NPObjectPointer<MockCommandBuffer> command_buffer =
- NPCreateObject<MockCommandBuffer>(NULL);
- EXPECT_CALL(mock_browser_, CreateObject(NULL,
- NPGetClass<CommandBuffer>()))
- .WillOnce(Return(command_buffer.ToReturned()));
+ EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer))
+ .WillOnce(Return(true));
- EXPECT_CALL(*command_buffer.Get(), Initialize(ring_buffer))
+ EXPECT_CALL(*processor_.get(), Initialize(NULL))
.WillOnce(Return(true));
- EXPECT_CALL(*command_buffer.Get(), SetPutOffsetChangeCallback(NotNull()));
+ EXPECT_CALL(*command_buffer_.Get(), SetPutOffsetChangeCallback(NotNull()))
+ .WillOnce(Invoke(DeleteObject<Callback0::Type>));
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
0,
@@ -165,16 +202,38 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) {
NULL,
NULL));
- EXPECT_EQ(command_buffer, plugin_object_->OpenCommandBuffer());
+ // Set status as though SetWindow has been called. Avoids having to create a
+ // valid window handle to pass to SetWindow in tests.
+ plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer);
+
+ EXPECT_EQ(command_buffer_, plugin_object_->OpenCommandBuffer());
// Calling OpenCommandBuffer again just returns the existing command buffer.
- EXPECT_EQ(command_buffer, plugin_object_->OpenCommandBuffer());
+ EXPECT_EQ(command_buffer_, plugin_object_->OpenCommandBuffer());
+
+ EXPECT_EQ(GPUPluginObject::kInitializationSuccessful,
+ plugin_object_->GetStatus());
- EXPECT_CALL(*command_buffer.Get(), SetPutOffsetChangeCallback(NULL));
+ EXPECT_CALL(*command_buffer_.Get(), SetPutOffsetChangeCallback(NULL));
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
+TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfWindowNotReady) {
+ EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
+ 0,
+ NULL,
+ NULL,
+ NULL));
+
+ // Set status as though SetWindow has not been called.
+ plugin_object_->set_status(GPUPluginObject::kWaitingForSetWindow);
+
+ EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer());
+
+ EXPECT_EQ(GPUPluginObject::kWaitingForSetWindow, plugin_object_->GetStatus());
+}
+
TEST_F(GPUPluginObjectTest,
OpenCommandBufferReturnsNullIfCannotCreateRingBuffer) {
EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(
@@ -187,12 +246,50 @@ TEST_F(GPUPluginObjectTest,
NULL,
NULL));
+ // Set status as though SetWindow has been called. Avoids having to create a
+ // valid window handle to pass to SetWindow in tests.
+ plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer);
+
+ EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer());
+
+ EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer,
+ plugin_object_->GetStatus());
+
+ EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+}
+
+TEST_F(GPUPluginObjectTest,
+ OpenCommandBufferReturnsNullIfCommandBufferCannotInitialize) {
+ NPObjectPointer<NPObject> ring_buffer =
+ NPCreateObject<StrictMock<MockSharedMemory> >(NULL);
+
+ EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(
+ GPUPluginObject::kCommandBufferSize))
+ .WillOnce(Return(ring_buffer));
+
+ EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer))
+ .WillOnce(Return(false));
+
+ EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
+ 0,
+ NULL,
+ NULL,
+ NULL));
+
+ // Set status as though SetWindow has been called. Avoids having to create a
+ // valid window handle to pass to SetWindow in tests.
+ plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer);
+
EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer());
+ EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer,
+ plugin_object_->GetStatus());
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
-TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) {
+TEST_F(GPUPluginObjectTest,
+ OpenCommandBufferReturnsNullIGPUProcessorCannotInitialize) {
NPObjectPointer<NPObject> ring_buffer =
NPCreateObject<StrictMock<MockSharedMemory> >(NULL);
@@ -200,14 +297,10 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) {
GPUPluginObject::kCommandBufferSize))
.WillOnce(Return(ring_buffer));
- // Intercept creation of command buffer object and return mock.
- NPObjectPointer<MockCommandBuffer> command_buffer =
- NPCreateObject<StrictMock<MockCommandBuffer> >(NULL);
- EXPECT_CALL(mock_browser_, CreateObject(NULL,
- NPGetClass<CommandBuffer>()))
- .WillOnce(Return(command_buffer.ToReturned()));
+ EXPECT_CALL(*command_buffer_.Get(), Initialize(ring_buffer))
+ .WillOnce(Return(true));
- EXPECT_CALL(*command_buffer.Get(), Initialize(ring_buffer))
+ EXPECT_CALL(*processor_.get(), Initialize(NULL))
.WillOnce(Return(false));
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
@@ -216,9 +309,17 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) {
NULL,
NULL));
+ // Set status as though SetWindow has been called. Avoids having to create a
+ // valid window handle to pass to SetWindow in tests.
+ plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer);
+
EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer());
+ EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer,
+ plugin_object_->GetStatus());
+
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
+
} // namespace gpu_plugin
} // namespace o3d
diff --git a/o3d/gpu_plugin/gpu_plugin_object_win.cc b/o3d/gpu_plugin/gpu_plugin_object_win.cc
index 9bdb331..d7579c8 100644
--- a/o3d/gpu_plugin/gpu_plugin_object_win.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object_win.cc
@@ -48,20 +48,17 @@ NPError GPUPluginObject::PlatformSpecificSetWindow(NPWindow* new_window) {
reinterpret_cast<HANDLE>(original_window_proc));
::SetWindowLong(handle, GWL_WNDPROC,
reinterpret_cast<LONG>(WindowProc));
- }
- UpdateProcessorWindow();
+ status_ = kWaitingForOpenCommandBuffer;
+ } else {
+ status_ = kWaitingForSetWindow;
+ if (processor_) {
+ processor_->Destroy();
+ }
+ }
return NPERR_NO_ERROR;
}
-void GPUPluginObject::UpdateProcessorWindow() {
- if (processor_) {
- processor_->SetWindow(reinterpret_cast<HWND>(window_.window),
- static_cast<int>(window_.width),
- static_cast<int>(window_.height));
- }
-}
-
} // namespace gpu_plugin
} // namespace o3d
diff --git a/o3d/gpu_plugin/gpu_processor.h b/o3d/gpu_plugin/gpu_processor.h
index f0b9a4b..05865ce 100644
--- a/o3d/gpu_plugin/gpu_processor.h
+++ b/o3d/gpu_plugin/gpu_processor.h
@@ -38,17 +38,17 @@ class GPUProcessor : public ::base::RefCounted<GPUProcessor>,
command_buffer::CommandParser* parser,
int commands_per_update);
- bool Initialize(HWND hwnd);
+ virtual bool Initialize(HWND hwnd);
#endif // OS_WIN
virtual ~GPUProcessor();
- void Destroy();
+ virtual void Destroy();
- void ProcessCommands();
+ virtual void ProcessCommands();
#if defined(OS_WIN)
- void SetWindow(HWND handle, int width, int height);
+ virtual bool SetWindow(HWND handle, int width, int height);
#endif
// Implementation of CommandBufferEngine.
diff --git a/o3d/gpu_plugin/gpu_processor_mock.h b/o3d/gpu_plugin/gpu_processor_mock.h
new file mode 100644
index 0000000..c3c4a52
--- /dev/null
+++ b/o3d/gpu_plugin/gpu_processor_mock.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef O3D_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_
+#define O3D_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_
+
+#include "o3d/gpu_plugin/gpu_processor.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+class MockGPUProcessor : public GPUProcessor {
+ public:
+ MockGPUProcessor(NPP npp,
+ CommandBuffer* command_buffer)
+ : GPUProcessor(npp, command_buffer) {
+ }
+
+#if defined(OS_WIN)
+ MOCK_METHOD1(Initialize, bool(HWND handle));
+#endif
+
+ MOCK_METHOD0(Destroy, void());
+ MOCK_METHOD0(ProcessCommands, void());
+
+#if defined(OS_WIN)
+ MOCK_METHOD3(SetWindow, bool(HWND handle, int width, int height));
+#endif
+
+ MOCK_METHOD1(GetSharedMemoryAddress, void*(int32 shm_id));
+ MOCK_METHOD1(GetSharedMemorySize, size_t(int32 shm_id));
+ MOCK_METHOD1(set_token, void(int32 token));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockGPUProcessor);
+};
+
+} // namespace gpu_plugin
+} // namespace o3d
+
+#endif // O3D_GPU_PLUGIN_GPU_PROCESSOR_MOCK_H_
diff --git a/o3d/gpu_plugin/gpu_processor_win.cc b/o3d/gpu_plugin/gpu_processor_win.cc
index a9fdae1..53d9afc 100644
--- a/o3d/gpu_plugin/gpu_processor_win.cc
+++ b/o3d/gpu_plugin/gpu_processor_win.cc
@@ -36,8 +36,11 @@ GPUProcessor::GPUProcessor(NPP npp,
}
bool GPUProcessor::Initialize(HWND handle) {
+ DCHECK(handle);
+
// Cannot reinitialize.
- DCHECK(gapi_->hwnd() == NULL);
+ if (gapi_->hwnd() != NULL)
+ return false;
// Map the ring buffer and create the parser.
NPObjectPointer<NPObject> ring_buffer =
@@ -60,12 +63,8 @@ bool GPUProcessor::Initialize(HWND handle) {
}
// Initialize GAPI immediately if the window handle is valid.
- if (handle) {
- gapi_->set_hwnd(handle);
- return gapi_->Initialize();
- } else {
- return true;
- }
+ gapi_->set_hwnd(handle);
+ return gapi_->Initialize();
}
void GPUProcessor::Destroy() {
@@ -76,14 +75,13 @@ void GPUProcessor::Destroy() {
}
}
-void GPUProcessor::SetWindow(HWND handle, int width, int height) {
+bool GPUProcessor::SetWindow(HWND handle, int width, int height) {
if (handle == NULL) {
// Destroy GAPI when the window handle becomes invalid.
Destroy();
+ return true;
} else {
- if (handle != gapi_->hwnd()) {
- Initialize(handle);
- }
+ return Initialize(handle);
}
}