diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 18:40:32 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 18:40:32 +0000 |
commit | 4eaca49eab39c1f10c22a615b10dcbcc37b9e71c (patch) | |
tree | 9e4e255c327bd44e92d901043913c318c41f3535 /o3d | |
parent | fa8866b764e3eda49141b1ae18afef162c547b19 (diff) | |
download | chromium_src-4eaca49eab39c1f10c22a615b10dcbcc37b9e71c.zip chromium_src-4eaca49eab39c1f10c22a615b10dcbcc37b9e71c.tar.gz chromium_src-4eaca49eab39c1f10c22a615b10dcbcc37b9e71c.tar.bz2 |
GPUPluginObject has methods to query its current window size.
GPUPluginObject sends event to client process when its window is resized.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/344001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30223 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_object.cc | 8 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_object.h | 25 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_object_unittest.cc | 63 |
3 files changed, 96 insertions, 0 deletions
diff --git a/o3d/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu_plugin/gpu_plugin_object.cc index 5c543d8..ed4812c 100644 --- a/o3d/gpu_plugin/gpu_plugin_object.cc +++ b/o3d/gpu_plugin/gpu_plugin_object.cc @@ -44,6 +44,14 @@ NPError GPUPluginObject::SetWindow(NPWindow* new_window) { NPError error = PlatformSpecificSetWindow(new_window); if (error == NPERR_NO_ERROR) { window_ = *new_window; + + if (event_sync_.Get()) { + NPInvokeVoid(npp_, + event_sync_, + "resize", + static_cast<int32>(window_.width), + static_cast<int32>(window_.height)); + } } else { memset(&window_, 0, sizeof(window_)); } diff --git a/o3d/gpu_plugin/gpu_plugin_object.h b/o3d/gpu_plugin/gpu_plugin_object.h index 99bad08..bd55a37 100644 --- a/o3d/gpu_plugin/gpu_plugin_object.h +++ b/o3d/gpu_plugin/gpu_plugin_object.h @@ -67,6 +67,26 @@ class GPUPluginObject : public DefaultNPObject<NPObject>, return status_; } + // Get the width of the plugin window. + int32 GetWidth() { + return window_.width; + } + + // Get the height of the plugin window. + int32 GetHeight() { + return window_.height; + } + + // 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) { + event_sync_ = event_sync; + } + + 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. @@ -90,6 +110,10 @@ class GPUPluginObject : public DefaultNPObject<NPObject>, 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_END_DISPATCHER_CHAIN @@ -101,6 +125,7 @@ class GPUPluginObject : public DefaultNPObject<NPObject>, NPWindow window_; NPObjectPointer<CommandBuffer> command_buffer_; scoped_refptr<GPUProcessor> processor_; + NPObjectPointer<NPObject> event_sync_; }; } // namespace gpu_plugin diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc index 2bdf5b4..370cc33 100644 --- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc +++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc @@ -167,6 +167,29 @@ TEST_F(GPUPluginObjectTest, CanSetWindow) { EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); } +TEST_F(GPUPluginObjectTest, CanGetWindowSize) { + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", + 0, + NULL, + NULL, + NULL)); + + NPWindow window = {0}; + window.window = &window; + window.x = 10; + window.y = 10; + window.width = 100; + window.height = 200; + + EXPECT_EQ(0, plugin_object_->GetWidth()); + EXPECT_EQ(0, plugin_object_->GetHeight()); + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->SetWindow(&window)); + EXPECT_EQ(100, plugin_object_->GetWidth()); + EXPECT_EQ(200, plugin_object_->GetHeight()); + + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); +} + TEST_F(GPUPluginObjectTest, SetWindowFailsIfNotInitialized) { NPWindow window = {0}; EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->SetWindow(&window)); @@ -321,5 +344,45 @@ TEST_F(GPUPluginObjectTest, EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); } +class MockEventSync : public DefaultNPObject<NPObject> { + public: + explicit MockEventSync(NPP npp) { + } + + MOCK_METHOD2(Resize, void(int32 width, int32 height)); + + NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockEventSync, DefaultNPObject<NPObject>) + NP_UTILS_DISPATCHER(Resize, void(int32 width, int32 height)) + NP_UTILS_END_DISPATCHER_CHAIN + + private: + DISALLOW_COPY_AND_ASSIGN(MockEventSync); +}; + +TEST_F(GPUPluginObjectTest, SendsResizeEventOnSetWindow) { + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", + 0, + NULL, + NULL, + NULL)); + + NPObjectPointer<MockEventSync> event_sync = + NPCreateObject<MockEventSync>(NULL); + plugin_object_->SetEventSync(event_sync); + + EXPECT_CALL(*event_sync.Get(), Resize(100, 200)); + + NPWindow window = {0}; + window.window = &window; + window.x = 10; + window.y = 10; + window.width = 100; + window.height = 200; + + plugin_object_->SetWindow(&window); + + EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); +} + } // namespace gpu_plugin } // namespace o3d |