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_gpu_memory_buffer_manager.h> |
5 #include "blimp/client/feature/compositor/blimp_compositor.h" | 6 #include "blimp/client/feature/compositor/blimp_compositor.h" |
6 | 7 |
7 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
8 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | 9 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" |
9 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h" | |
10 #include "blimp/common/compositor/blimp_task_graph_runner.h" | 10 #include "blimp/common/compositor/blimp_task_graph_runner.h" |
| 11 #include "cc/layers/layer.h" |
11 #include "cc/proto/compositor_message.pb.h" | 12 #include "cc/proto/compositor_message.pb.h" |
| 13 #include "cc/surfaces/surface_manager.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 using testing::_; | 17 using testing::_; |
16 | 18 |
17 namespace blimp { | 19 namespace blimp { |
18 namespace client { | 20 namespace client { |
19 | 21 |
20 class MockBlimpCompositorClient : public BlimpCompositorClient { | 22 class MockBlimpCompositorClient : public BlimpCompositorClient { |
21 public: | 23 public: |
22 MockBlimpCompositorClient() : compositor_thread_("Compositor") { | 24 MockBlimpCompositorClient() : compositor_thread_("Compositor") { |
23 compositor_thread_.Start(); | 25 compositor_thread_.Start(); |
24 } | 26 } |
25 ~MockBlimpCompositorClient() override { compositor_thread_.Stop(); } | 27 ~MockBlimpCompositorClient() override { compositor_thread_.Stop(); } |
26 | 28 |
27 cc::LayerTreeSettings* GetLayerTreeSettings() override { return &settings_; } | 29 cc::LayerTreeSettings* GetLayerTreeSettings() override { return &settings_; } |
28 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() override | 30 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() override |
29 { return compositor_thread_.task_runner(); } | 31 { return compositor_thread_.task_runner(); } |
30 cc::TaskGraphRunner* GetTaskGraphRunner() override { | 32 cc::TaskGraphRunner* GetTaskGraphRunner() override { |
31 return &task_graph_runner_; } | 33 return &task_graph_runner_; } |
32 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { | 34 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { |
33 return &gpu_memory_buffer_manager_; | 35 return &gpu_memory_buffer_manager_; |
34 } | 36 } |
35 cc::ImageSerializationProcessor* GetImageSerializationProcessor() override { | 37 cc::ImageSerializationProcessor* GetImageSerializationProcessor() override { |
36 return BlobImageSerializationProcessor::current(); | 38 return BlobImageSerializationProcessor::current(); |
37 } | 39 } |
38 void DidCompleteSwapBuffers() override {} | |
39 void DidCommitAndDrawFrame() override {} | |
40 | 40 |
41 void SendWebGestureEvent( | 41 void SendWebGestureEvent( |
42 int render_widget_id, | 42 int render_widget_id, |
43 const blink::WebGestureEvent& gesture_event) override { | 43 const blink::WebGestureEvent& gesture_event) override { |
44 MockableSendWebGestureEvent(render_widget_id); | 44 MockableSendWebGestureEvent(render_widget_id); |
45 } | 45 } |
46 void SendCompositorMessage( | 46 void SendCompositorMessage( |
47 int render_widget_id, | 47 int render_widget_id, |
48 const cc::proto::CompositorMessage& message) override { | 48 const cc::proto::CompositorMessage& message) override { |
49 MockableSendCompositorMessage(render_widget_id); | 49 MockableSendCompositorMessage(render_widget_id); |
50 } | 50 } |
51 | 51 |
52 MOCK_METHOD1(MockableSendWebGestureEvent, void(int)); | 52 MOCK_METHOD1(MockableSendWebGestureEvent, void(int)); |
53 MOCK_METHOD1(MockableSendCompositorMessage, void(int)); | 53 MOCK_METHOD1(MockableSendCompositorMessage, void(int)); |
54 | 54 |
55 cc::LayerTreeSettings settings_; | 55 cc::LayerTreeSettings settings_; |
56 base::Thread compositor_thread_; | 56 base::Thread compositor_thread_; |
57 BlimpTaskGraphRunner task_graph_runner_; | 57 BlimpTaskGraphRunner task_graph_runner_; |
58 BlimpGpuMemoryBufferManager gpu_memory_buffer_manager_; | 58 BlimpGpuMemoryBufferManager gpu_memory_buffer_manager_; |
59 BlobImageSerializationProcessor serialization_processor_; | 59 BlobImageSerializationProcessor serialization_processor_; |
60 | 60 |
61 private: | 61 private: |
62 DISALLOW_COPY_AND_ASSIGN(MockBlimpCompositorClient); | 62 DISALLOW_COPY_AND_ASSIGN(MockBlimpCompositorClient); |
63 }; | 63 }; |
64 | 64 |
65 class BlimpCompositorForTesting : public BlimpCompositor { | 65 class BlimpCompositorForTesting : public BlimpCompositor { |
66 public: | 66 public: |
67 BlimpCompositorForTesting(int render_widget_id, | 67 BlimpCompositorForTesting(int render_widget_id, |
| 68 cc::SurfaceManager* surface_manager, |
| 69 uint32_t surface_client_id, |
68 BlimpCompositorClient* client) | 70 BlimpCompositorClient* client) |
69 : BlimpCompositor(render_widget_id, client) {} | 71 : BlimpCompositor(render_widget_id, |
| 72 surface_manager, |
| 73 surface_client_id, |
| 74 client) {} |
70 | 75 |
71 void SendProto(const cc::proto::CompositorMessage& proto) { | 76 void SendProto(const cc::proto::CompositorMessage& proto) { |
72 SendCompositorProto(proto); | 77 SendCompositorProto(proto); |
73 } | 78 } |
74 | 79 |
75 void SendGestureEvent(const blink::WebGestureEvent& gesture_event) { | 80 void SendGestureEvent(const blink::WebGestureEvent& gesture_event) { |
76 SendWebGestureEvent(gesture_event); | 81 SendWebGestureEvent(gesture_event); |
77 } | 82 } |
78 | 83 |
79 cc::LayerTreeHost* host() const { return host_.get(); } | 84 cc::LayerTreeHost* host() const { return host_.get(); } |
80 }; | 85 }; |
81 | 86 |
82 class BlimpCompositorTest : public testing::Test { | 87 class BlimpCompositorTest : public testing::Test { |
83 public: | 88 public: |
84 BlimpCompositorTest(): | 89 BlimpCompositorTest() : render_widget_id_(1), loop_(new base::MessageLoop) {} |
85 render_widget_id_(1), | |
86 loop_(new base::MessageLoop), | |
87 window_(42u) {} | |
88 | 90 |
89 void SetUp() override { | 91 void SetUp() override { |
90 compositor_.reset(new BlimpCompositorForTesting(render_widget_id_, | 92 surface_manager_ = base::MakeUnique<cc::SurfaceManager>(); |
91 &compositor_client_)); | 93 compositor_.reset(new BlimpCompositorForTesting( |
| 94 render_widget_id_, surface_manager_.get(), surface_client_id_++, |
| 95 &compositor_client_)); |
92 } | 96 } |
93 | 97 |
94 void TearDown() override { | 98 void TearDown() override { |
95 compositor_.reset(); | 99 compositor_.reset(); |
| 100 surface_manager_.reset(); |
96 } | 101 } |
97 | 102 |
98 ~BlimpCompositorTest() override {} | 103 ~BlimpCompositorTest() override {} |
99 | 104 |
100 void SendInitializeMessage() { | 105 void SendInitializeMessage() { |
101 std::unique_ptr<cc::proto::CompositorMessage> message; | 106 std::unique_ptr<cc::proto::CompositorMessage> message; |
102 message.reset(new cc::proto::CompositorMessage); | 107 message.reset(new cc::proto::CompositorMessage); |
103 cc::proto::CompositorMessageToImpl* to_impl = | 108 cc::proto::CompositorMessageToImpl* to_impl = |
104 message->mutable_to_impl(); | 109 message->mutable_to_impl(); |
105 to_impl->set_message_type( | 110 to_impl->set_message_type( |
106 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL); | 111 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL); |
107 cc::proto::InitializeImpl* initialize_message = | 112 cc::proto::InitializeImpl* initialize_message = |
108 to_impl->mutable_initialize_impl_message(); | 113 to_impl->mutable_initialize_impl_message(); |
109 cc::LayerTreeSettings settings; | 114 cc::LayerTreeSettings settings; |
110 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings()); | 115 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings()); |
111 compositor_->OnCompositorMessageReceived(std::move(message)); | 116 compositor_->OnCompositorMessageReceived(std::move(message)); |
112 } | 117 } |
113 | 118 |
114 void SendShutdownMessage() { | 119 void SendShutdownMessage() { |
115 std::unique_ptr<cc::proto::CompositorMessage> message; | 120 std::unique_ptr<cc::proto::CompositorMessage> message; |
116 message.reset(new cc::proto::CompositorMessage); | 121 message.reset(new cc::proto::CompositorMessage); |
117 cc::proto::CompositorMessageToImpl* to_impl = | 122 cc::proto::CompositorMessageToImpl* to_impl = |
118 message->mutable_to_impl(); | 123 message->mutable_to_impl(); |
119 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL); | 124 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL); |
120 compositor_->OnCompositorMessageReceived(std::move(message)); | 125 compositor_->OnCompositorMessageReceived(std::move(message)); |
121 } | 126 } |
122 | 127 |
123 int render_widget_id_; | 128 int render_widget_id_; |
| 129 std::unique_ptr<cc::SurfaceManager> surface_manager_; |
| 130 uint32_t surface_client_id_ = 1; |
124 std::unique_ptr<base::MessageLoop> loop_; | 131 std::unique_ptr<base::MessageLoop> loop_; |
125 MockBlimpCompositorClient compositor_client_; | 132 MockBlimpCompositorClient compositor_client_; |
126 std::unique_ptr<BlimpCompositorForTesting> compositor_; | 133 std::unique_ptr<BlimpCompositorForTesting> compositor_; |
127 gfx::AcceleratedWidget window_; | |
128 }; | 134 }; |
129 | 135 |
130 TEST_F(BlimpCompositorTest, ToggleVisibilityAndWidgetWithHost) { | 136 TEST_F(BlimpCompositorTest, ToggleVisibilityWithHost) { |
131 // Make the compositor visible and give it a widget when we don't have a host. | 137 // Make the compositor visible when we don't have a host. |
132 compositor_->SetVisible(true); | 138 compositor_->SetVisible(true); |
133 compositor_->SetAcceleratedWidget(window_); | |
134 SendInitializeMessage(); | 139 SendInitializeMessage(); |
135 | 140 |
136 // Check that the visibility is set correctly on the host. | 141 // Check that the visibility is set correctly on the host. |
137 EXPECT_NE(compositor_->host(), nullptr); | 142 EXPECT_NE(compositor_->host(), nullptr); |
138 EXPECT_TRUE(compositor_->host()->visible()); | 143 EXPECT_TRUE(compositor_->host()->visible()); |
139 | 144 |
140 // Make the compositor invisible. This should drop the output surface and | 145 // Make the compositor invisible. This should make the |host_| invisible. |
141 // make the |host_| invisible. | |
142 compositor_->SetVisible(false); | 146 compositor_->SetVisible(false); |
143 EXPECT_FALSE(compositor_->host()->visible()); | 147 EXPECT_FALSE(compositor_->host()->visible()); |
144 | 148 |
145 // Make the compositor visible and release the widget. This should make the | |
146 // |host_| invisible. | |
147 compositor_->SetVisible(true); | |
148 EXPECT_TRUE(compositor_->host()->visible()); | |
149 compositor_->ReleaseAcceleratedWidget(); | |
150 EXPECT_FALSE(compositor_->host()->visible()); | |
151 | |
152 SendShutdownMessage(); | 149 SendShutdownMessage(); |
153 EXPECT_EQ(compositor_->host(), nullptr); | 150 EXPECT_EQ(compositor_->host(), nullptr); |
154 } | 151 } |
155 | 152 |
156 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) { | 153 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) { |
157 // Create the host and make it visible. | 154 // Create the host and make it visible. |
158 SendInitializeMessage(); | 155 SendInitializeMessage(); |
159 compositor_->SetVisible(true); | 156 compositor_->SetVisible(true); |
160 compositor_->SetAcceleratedWidget(window_); | |
161 | 157 |
162 // Destroy this host and recreate a new one. Make sure that the visibility is | 158 // Destroy this host and recreate a new one. Make sure that the visibility is |
163 // set correctly on this host. | 159 // set correctly on this host. |
164 SendShutdownMessage(); | 160 SendShutdownMessage(); |
165 SendInitializeMessage(); | 161 SendInitializeMessage(); |
166 EXPECT_NE(compositor_->host(), nullptr); | 162 EXPECT_NE(compositor_->host(), nullptr); |
167 EXPECT_TRUE(compositor_->host()->visible()); | 163 EXPECT_TRUE(compositor_->host()->visible()); |
168 } | 164 } |
169 | 165 |
170 TEST_F(BlimpCompositorTest, MessagesHaveCorrectId) { | 166 TEST_F(BlimpCompositorTest, MessagesHaveCorrectId) { |
171 EXPECT_CALL(compositor_client_, | 167 EXPECT_CALL(compositor_client_, |
172 MockableSendCompositorMessage(render_widget_id_)).Times(1); | 168 MockableSendCompositorMessage(render_widget_id_)).Times(1); |
173 EXPECT_CALL(compositor_client_, | 169 EXPECT_CALL(compositor_client_, |
174 MockableSendWebGestureEvent(render_widget_id_)).Times(1); | 170 MockableSendWebGestureEvent(render_widget_id_)).Times(1); |
175 | 171 |
176 compositor_->SendProto(cc::proto::CompositorMessage()); | 172 compositor_->SendProto(cc::proto::CompositorMessage()); |
177 compositor_->SendGestureEvent(blink::WebGestureEvent()); | 173 compositor_->SendGestureEvent(blink::WebGestureEvent()); |
178 } | 174 } |
179 | 175 |
180 } // namespace client | 176 } // namespace client |
181 } // namespace blimp | 177 } // namespace blimp |
OLD | NEW |