| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/feature/compositor/blimp_compositor_manager.h" | 5 #include "blimp/client/feature/compositor/blimp_compositor_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h" |
| 8 #include "cc/proto/compositor_message.pb.h" | 9 #include "cc/proto/compositor_message.pb.h" |
| 10 #include "cc/surfaces/surface_manager.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/events/gesture_detection/motion_event_generic.h" | 13 #include "ui/events/gesture_detection/motion_event_generic.h" |
| 12 | 14 |
| 13 using testing::_; | 15 using testing::_; |
| 14 using testing::InSequence; | 16 using testing::InSequence; |
| 15 using testing::Sequence; | 17 using testing::Sequence; |
| 16 | 18 |
| 17 namespace blimp { | 19 namespace blimp { |
| 18 namespace client { | 20 namespace client { |
| 21 namespace { |
| 19 | 22 |
| 20 class MockRenderWidgetFeature : public RenderWidgetFeature { | 23 class MockRenderWidgetFeature : public RenderWidgetFeature { |
| 21 public: | 24 public: |
| 22 MOCK_METHOD3(SendCompositorMessage, | 25 MOCK_METHOD3(SendCompositorMessage, |
| 23 void(const int, | 26 void(const int, |
| 24 const int, | 27 const int, |
| 25 const cc::proto::CompositorMessage&)); | 28 const cc::proto::CompositorMessage&)); |
| 26 MOCK_METHOD3(SendInputEvent, void(const int, | 29 MOCK_METHOD3(SendInputEvent, void(const int, |
| 27 const int, | 30 const int, |
| 28 const blink::WebInputEvent&)); | 31 const blink::WebInputEvent&)); |
| 29 MOCK_METHOD2(SetDelegate, void(int, RenderWidgetFeatureDelegate*)); | 32 MOCK_METHOD2(SetDelegate, void(int, RenderWidgetFeatureDelegate*)); |
| 30 MOCK_METHOD1(RemoveDelegate, void(const int)); | 33 MOCK_METHOD1(RemoveDelegate, void(const int)); |
| 31 }; | 34 }; |
| 32 | 35 |
| 33 class MockBlimpCompositor : public BlimpCompositor { | 36 class MockBlimpCompositor : public BlimpCompositor { |
| 34 public : | 37 public : |
| 35 explicit MockBlimpCompositor(const int render_widget_id) | 38 explicit MockBlimpCompositor(const int render_widget_id, |
| 36 : BlimpCompositor(render_widget_id, nullptr) { | 39 cc::SurfaceManager* surface_manager, |
| 37 } | 40 int surface_client_id, |
| 41 BlimpCompositorClient* client) |
| 42 : BlimpCompositor(render_widget_id, |
| 43 surface_manager, |
| 44 surface_client_id, |
| 45 client) {} |
| 38 | 46 |
| 39 MOCK_METHOD1(SetVisible, void(bool)); | 47 MOCK_METHOD1(SetVisible, void(bool)); |
| 40 MOCK_METHOD1(SetAcceleratedWidget, void(gfx::AcceleratedWidget)); | |
| 41 MOCK_METHOD0(ReleaseAcceleratedWidget, void()); | |
| 42 MOCK_METHOD1(OnTouchEvent, bool(const ui::MotionEvent& motion_event)); | 48 MOCK_METHOD1(OnTouchEvent, bool(const ui::MotionEvent& motion_event)); |
| 43 | 49 |
| 44 void OnCompositorMessageReceived( | 50 void OnCompositorMessageReceived( |
| 45 std::unique_ptr<cc::proto::CompositorMessage> message) override { | 51 std::unique_ptr<cc::proto::CompositorMessage> message) override { |
| 46 MockableOnCompositorMessageReceived(*message); | 52 MockableOnCompositorMessageReceived(*message); |
| 47 } | 53 } |
| 48 MOCK_METHOD1(MockableOnCompositorMessageReceived, | 54 MOCK_METHOD1(MockableOnCompositorMessageReceived, |
| 49 void(const cc::proto::CompositorMessage&)); | 55 void(const cc::proto::CompositorMessage&)); |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 class BlimpCompositorManagerForTesting : public BlimpCompositorManager { | 58 class BlimpCompositorManagerForTesting : public BlimpCompositorManager { |
| 53 public: | 59 public: |
| 54 explicit BlimpCompositorManagerForTesting( | 60 explicit BlimpCompositorManagerForTesting( |
| 55 RenderWidgetFeature* render_widget_feature) | 61 RenderWidgetFeature* render_widget_feature, |
| 56 : BlimpCompositorManager(render_widget_feature, nullptr) {} | 62 cc::SurfaceManager* surface_manager, |
| 63 BlimpGpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 64 SurfaceIdAllocationCallback callback) |
| 65 : BlimpCompositorManager(render_widget_feature, |
| 66 surface_manager, |
| 67 gpu_memory_buffer_manager, |
| 68 callback) {} |
| 57 | 69 |
| 58 using BlimpCompositorManager::GetCompositor; | 70 using BlimpCompositorManager::GetCompositor; |
| 59 | 71 |
| 60 std::unique_ptr<BlimpCompositor> CreateBlimpCompositor( | 72 std::unique_ptr<BlimpCompositor> CreateBlimpCompositor( |
| 61 int render_widget_id, | 73 int render_widget_id, |
| 74 cc::SurfaceManager* surface_manager, |
| 75 uint32_t surface_client_id, |
| 62 BlimpCompositorClient* client) override { | 76 BlimpCompositorClient* client) override { |
| 63 return base::WrapUnique(new MockBlimpCompositor(render_widget_id)); | 77 return base::WrapUnique(new MockBlimpCompositor( |
| 78 render_widget_id, surface_manager, surface_client_id, client)); |
| 64 } | 79 } |
| 65 }; | 80 }; |
| 66 | 81 |
| 67 class BlimpCompositorManagerTest : public testing::Test { | 82 class BlimpCompositorManagerTest : public testing::Test { |
| 68 public: | 83 public: |
| 69 void SetUp() override { | 84 void SetUp() override { |
| 70 EXPECT_CALL(render_widget_feature_, SetDelegate(_, _)).Times(1); | 85 EXPECT_CALL(render_widget_feature_, SetDelegate(_, _)).Times(1); |
| 71 EXPECT_CALL(render_widget_feature_, RemoveDelegate(_)).Times(1); | 86 EXPECT_CALL(render_widget_feature_, RemoveDelegate(_)).Times(1); |
| 72 | 87 |
| 73 compositor_manager_.reset( | 88 surface_manager_ = base::MakeUnique<cc::SurfaceManager>(); |
| 74 new BlimpCompositorManagerForTesting(&render_widget_feature_)); | 89 compositor_manager_.reset(new BlimpCompositorManagerForTesting( |
| 90 &render_widget_feature_, surface_manager_.get(), |
| 91 &gpu_memory_buffer_manager_, |
| 92 base::Bind(&BlimpCompositorManagerTest::AllocateId, |
| 93 base::Unretained(this)))); |
| 75 } | 94 } |
| 76 | 95 |
| 77 void TearDown() override { | 96 void TearDown() override { |
| 97 mock_compositor1_ = nullptr; |
| 98 mock_compositor2_ = nullptr; |
| 78 compositor_manager_.reset(); | 99 compositor_manager_.reset(); |
| 100 surface_manager_.reset(); |
| 79 } | 101 } |
| 80 | 102 |
| 103 uint32_t AllocateId() { return ++id_; } |
| 104 |
| 81 void SetUpCompositors() { | 105 void SetUpCompositors() { |
| 82 delegate()->OnRenderWidgetCreated(1); | 106 delegate()->OnRenderWidgetCreated(1); |
| 83 delegate()->OnRenderWidgetCreated(2); | 107 delegate()->OnRenderWidgetCreated(2); |
| 84 | 108 |
| 85 mock_compositor1_ = static_cast<MockBlimpCompositor*> | 109 mock_compositor1_ = static_cast<MockBlimpCompositor*> |
| 86 (compositor_manager_->GetCompositor(1)); | 110 (compositor_manager_->GetCompositor(1)); |
| 87 mock_compositor2_ = static_cast<MockBlimpCompositor*> | 111 mock_compositor2_ = static_cast<MockBlimpCompositor*> |
| 88 (compositor_manager_->GetCompositor(2)); | 112 (compositor_manager_->GetCompositor(2)); |
| 89 | 113 |
| 90 EXPECT_NE(mock_compositor1_, nullptr); | 114 EXPECT_NE(mock_compositor1_, nullptr); |
| 91 EXPECT_NE(mock_compositor2_, nullptr); | 115 EXPECT_NE(mock_compositor2_, nullptr); |
| 92 | 116 |
| 93 EXPECT_EQ(mock_compositor1_->render_widget_id(), 1); | 117 EXPECT_EQ(mock_compositor1_->render_widget_id(), 1); |
| 94 EXPECT_EQ(mock_compositor2_->render_widget_id(), 2); | 118 EXPECT_EQ(mock_compositor2_->render_widget_id(), 2); |
| 95 } | 119 } |
| 96 | 120 |
| 97 RenderWidgetFeature::RenderWidgetFeatureDelegate* delegate() const { | 121 RenderWidgetFeature::RenderWidgetFeatureDelegate* delegate() const { |
| 98 DCHECK(compositor_manager_); | 122 DCHECK(compositor_manager_); |
| 99 return static_cast<RenderWidgetFeature::RenderWidgetFeatureDelegate*> | 123 return static_cast<RenderWidgetFeature::RenderWidgetFeatureDelegate*> |
| 100 (compositor_manager_.get()); | 124 (compositor_manager_.get()); |
| 101 } | 125 } |
| 102 | 126 |
| 127 uint32_t id_ = 1; |
| 103 std::unique_ptr<BlimpCompositorManagerForTesting> compositor_manager_; | 128 std::unique_ptr<BlimpCompositorManagerForTesting> compositor_manager_; |
| 129 std::unique_ptr<cc::SurfaceManager> surface_manager_; |
| 130 BlimpGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 104 MockRenderWidgetFeature render_widget_feature_; | 131 MockRenderWidgetFeature render_widget_feature_; |
| 105 MockBlimpCompositor* mock_compositor1_; | 132 MockBlimpCompositor* mock_compositor1_; |
| 106 MockBlimpCompositor* mock_compositor2_; | 133 MockBlimpCompositor* mock_compositor2_; |
| 107 }; | 134 }; |
| 108 | 135 |
| 109 TEST_F(BlimpCompositorManagerTest, ForwardsMessagesToCorrectCompositor) { | 136 TEST_F(BlimpCompositorManagerTest, ForwardsMessagesToCorrectCompositor) { |
| 110 SetUpCompositors(); | 137 SetUpCompositors(); |
| 111 | 138 |
| 112 // Ensure that the compositor messages for a render widget are forwarded to | 139 // Ensure that the compositor messages for a render widget are forwarded to |
| 113 // the correct compositor. | 140 // the correct compositor. |
| 114 EXPECT_CALL(*mock_compositor1_, | 141 EXPECT_CALL(*mock_compositor1_, |
| 115 MockableOnCompositorMessageReceived(_)).Times(2); | 142 MockableOnCompositorMessageReceived(_)).Times(2); |
| 116 EXPECT_CALL(*mock_compositor2_, | 143 EXPECT_CALL(*mock_compositor2_, |
| 117 MockableOnCompositorMessageReceived(_)).Times(1); | 144 MockableOnCompositorMessageReceived(_)).Times(1); |
| 118 EXPECT_CALL(*mock_compositor1_, | 145 EXPECT_CALL(*mock_compositor1_, |
| 119 SetVisible(false)).Times(1); | 146 SetVisible(false)).Times(1); |
| 120 EXPECT_CALL(*mock_compositor1_, | |
| 121 SetAcceleratedWidget(gfx::kNullAcceleratedWidget)).Times(1); | |
| 122 | 147 |
| 123 delegate()->OnCompositorMessageReceived( | 148 delegate()->OnCompositorMessageReceived( |
| 124 1, base::WrapUnique(new cc::proto::CompositorMessage)); | 149 1, base::WrapUnique(new cc::proto::CompositorMessage)); |
| 125 delegate()->OnRenderWidgetInitialized(1); | 150 delegate()->OnRenderWidgetInitialized(1); |
| 126 delegate()->OnCompositorMessageReceived( | 151 delegate()->OnCompositorMessageReceived( |
| 127 2, base::WrapUnique(new cc::proto::CompositorMessage)); | 152 2, base::WrapUnique(new cc::proto::CompositorMessage)); |
| 128 delegate()->OnCompositorMessageReceived( | 153 delegate()->OnCompositorMessageReceived( |
| 129 1, base::WrapUnique(new cc::proto::CompositorMessage)); | 154 1, base::WrapUnique(new cc::proto::CompositorMessage)); |
| 130 | 155 |
| 131 delegate()->OnRenderWidgetDeleted(1); | 156 delegate()->OnRenderWidgetDeleted(1); |
| 132 EXPECT_EQ(compositor_manager_->GetCompositor(1), nullptr); | 157 EXPECT_EQ(compositor_manager_->GetCompositor(1), nullptr); |
| 133 } | 158 } |
| 134 | 159 |
| 135 TEST_F(BlimpCompositorManagerTest, ForwardsViewEventsToCorrectCompositor) { | 160 TEST_F(BlimpCompositorManagerTest, ForwardsViewEventsToCorrectCompositor) { |
| 136 InSequence sequence; | 161 InSequence sequence; |
| 137 SetUpCompositors(); | 162 SetUpCompositors(); |
| 138 | 163 |
| 139 EXPECT_CALL(*mock_compositor1_, SetVisible(true)); | 164 EXPECT_CALL(*mock_compositor1_, SetVisible(true)); |
| 140 EXPECT_CALL(*mock_compositor1_, SetAcceleratedWidget( | |
| 141 gfx::kNullAcceleratedWidget)); | |
| 142 EXPECT_CALL(*mock_compositor1_, OnTouchEvent(_)); | 165 EXPECT_CALL(*mock_compositor1_, OnTouchEvent(_)); |
| 143 EXPECT_CALL(*mock_compositor1_, SetVisible(false)); | 166 EXPECT_CALL(*mock_compositor1_, SetVisible(false)); |
| 144 EXPECT_CALL(*mock_compositor1_, ReleaseAcceleratedWidget()); | |
| 145 | 167 |
| 146 EXPECT_CALL(*mock_compositor2_, SetVisible(true)); | 168 EXPECT_CALL(*mock_compositor2_, SetVisible(true)); |
| 147 EXPECT_CALL(*mock_compositor2_, SetAcceleratedWidget( | |
| 148 gfx::kNullAcceleratedWidget)); | |
| 149 EXPECT_CALL(*mock_compositor2_, SetVisible(false)); | 169 EXPECT_CALL(*mock_compositor2_, SetVisible(false)); |
| 150 EXPECT_CALL(*mock_compositor2_, ReleaseAcceleratedWidget()); | |
| 151 | 170 |
| 152 // Make the compositor manager visible and give it the accelerated widget | 171 // Make the compositor manager visible while we don't have any render widget |
| 153 // while we don't have any render widget initialized. | 172 // initialized. |
| 154 compositor_manager_->SetVisible(true); | 173 compositor_manager_->SetVisible(true); |
| 155 compositor_manager_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | |
| 156 | 174 |
| 157 // Initialize the first render widget. This should propagate the visibility, | 175 // Initialize the first render widget. This should propagate the visibility, |
| 158 // the accelerated widget and the touch events to the corresponding | 176 // and the touch events to the corresponding compositor. |
| 159 // compositor. | |
| 160 delegate()->OnRenderWidgetInitialized(1); | 177 delegate()->OnRenderWidgetInitialized(1); |
| 161 compositor_manager_->OnTouchEvent( | 178 compositor_manager_->OnTouchEvent( |
| 162 ui::MotionEventGeneric(ui::MotionEvent::Action::ACTION_NONE, | 179 ui::MotionEventGeneric(ui::MotionEvent::Action::ACTION_NONE, |
| 163 base::TimeTicks::Now(), ui::PointerProperties())); | 180 base::TimeTicks::Now(), ui::PointerProperties())); |
| 164 | 181 |
| 165 // Now initialize the second render widget. This should swap the compositors | 182 // Now initialize the second render widget. This should swap the compositors |
| 166 // and make the first one invisible and release the accelerated widget. | 183 // and make the first one invisible. |
| 167 delegate()->OnRenderWidgetInitialized(2); | 184 delegate()->OnRenderWidgetInitialized(2); |
| 168 | 185 |
| 169 // Now make the compositor manager invisible and release the accelerated | 186 // Now make the compositor manager invisible. This should make the current |
| 170 // widget from it. This should make the current compositor invisible and | 187 // compositor invisible. |
| 171 // release the widget. | |
| 172 compositor_manager_->SetVisible(false); | 188 compositor_manager_->SetVisible(false); |
| 173 compositor_manager_->ReleaseAcceleratedWidget(); | |
| 174 | 189 |
| 175 // Destroy all the widgets. We should not be receiving any calls for the view | 190 // Destroy all the widgets. We should not be receiving any calls for the view |
| 176 // events forwarded after this. | 191 // events forwarded after this. |
| 177 delegate()->OnRenderWidgetDeleted(1); | 192 delegate()->OnRenderWidgetDeleted(1); |
| 178 delegate()->OnRenderWidgetDeleted(2); | 193 delegate()->OnRenderWidgetDeleted(2); |
| 179 | 194 |
| 180 compositor_manager_->SetVisible(true); | 195 compositor_manager_->SetVisible(true); |
| 181 } | 196 } |
| 182 | 197 |
| 198 } // namespace |
| 183 } // namespace client | 199 } // namespace client |
| 184 } // namespace blimp | 200 } // namespace blimp |
| OLD | NEW |