OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | |
6 #include <queue> | |
7 #include <utility> | |
8 | |
5 #include "android_webview/browser/browser_view_renderer.h" | 9 #include "android_webview/browser/browser_view_renderer.h" |
6 #include "android_webview/browser/child_frame.h" | 10 #include "android_webview/browser/child_frame.h" |
7 #include "android_webview/browser/test/rendering_test.h" | 11 #include "android_webview/browser/test/rendering_test.h" |
8 #include "base/location.h" | 12 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "cc/output/compositor_frame.h" | |
15 #include "content/public/test/test_synchronous_compositor_android.h" | |
10 | 16 |
11 namespace android_webview { | 17 namespace android_webview { |
12 | 18 |
13 class SmokeTest : public RenderingTest { | 19 class SmokeTest : public RenderingTest { |
14 void StartTest() override { browser_view_renderer_->PostInvalidate(); } | 20 void StartTest() override { browser_view_renderer_->PostInvalidate(); } |
15 | 21 |
16 void DidDrawOnRT(SharedRendererState* functor) override { | 22 void DidDrawOnRT(SharedRendererState* functor) override { |
17 EndTest(); | 23 EndTest(); |
18 } | 24 } |
19 }; | 25 }; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 CompositorNoFrameTest() : on_draw_count_(0) {} | 155 CompositorNoFrameTest() : on_draw_count_(0) {} |
150 | 156 |
151 void StartTest() override { | 157 void StartTest() override { |
152 browser_view_renderer_->PostInvalidate(); | 158 browser_view_renderer_->PostInvalidate(); |
153 } | 159 } |
154 | 160 |
155 void WillOnDraw() override { | 161 void WillOnDraw() override { |
156 if (0 == on_draw_count_) { | 162 if (0 == on_draw_count_) { |
157 // No frame from compositor. | 163 // No frame from compositor. |
158 } else if (1 == on_draw_count_) { | 164 } else if (1 == on_draw_count_) { |
159 SetCompositorFrame(); | 165 compositor_->SetHardwareFrame(0u, ConstructEmptyFrame()); |
160 } else if (2 == on_draw_count_) { | 166 } else if (2 == on_draw_count_) { |
161 // No frame from compositor. | 167 // No frame from compositor. |
162 } | 168 } |
163 // There may be trailing invalidates. | 169 // There may be trailing invalidates. |
164 } | 170 } |
165 | 171 |
166 void DidOnDraw(bool success) override { | 172 void DidOnDraw(bool success) override { |
167 if (0 == on_draw_count_) { | 173 if (0 == on_draw_count_) { |
168 // Should fail as there has been no frames from compositor. | 174 // Should fail as there has been no frames from compositor. |
169 EXPECT_FALSE(success); | 175 EXPECT_FALSE(success); |
170 browser_view_renderer_->PostInvalidate(); | 176 browser_view_renderer_->PostInvalidate(); |
171 } else if (1 == on_draw_count_) { | 177 } else if (1 == on_draw_count_) { |
172 // Should succeed with frame from compositor. | 178 // Should succeed with frame from compositor. |
173 EXPECT_TRUE(success); | 179 EXPECT_TRUE(success); |
174 browser_view_renderer_->PostInvalidate(); | 180 browser_view_renderer_->PostInvalidate(); |
175 } else if (2 == on_draw_count_) { | 181 } else if (2 == on_draw_count_) { |
176 // Should still succeed with last frame, even if no frame from compositor. | 182 // Should still succeed with last frame, even if no frame from compositor. |
177 EXPECT_TRUE(success); | 183 EXPECT_TRUE(success); |
178 EndTest(); | 184 EndTest(); |
179 } | 185 } |
180 on_draw_count_++; | 186 on_draw_count_++; |
181 } | 187 } |
182 | 188 |
183 private: | 189 private: |
184 int on_draw_count_; | 190 int on_draw_count_; |
185 }; | 191 }; |
186 | 192 |
187 RENDERING_TEST_F(CompositorNoFrameTest); | 193 RENDERING_TEST_F(CompositorNoFrameTest); |
188 | 194 |
195 class SwitchOutputSurfaceIdTest : public RenderingTest { | |
196 public: | |
197 struct FrameInfo { | |
198 uint32_t output_surface_id; | |
199 cc::ResourceId resource_id; // Each frame contains a single resource. | |
200 }; | |
201 | |
202 void StartTest() override { | |
203 last_output_surface_id_ = 0; | |
204 FrameInfo infos[] = { | |
205 // First output surface. | |
206 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u}, | |
207 // Second output surface. | |
208 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u}, | |
209 }; | |
210 for (auto& info : infos) { | |
211 content::SynchronousCompositor::Frame frame; | |
212 frame.output_surface_id = info.output_surface_id; | |
213 frame.frame = ConstructEmptyFrame(); | |
214 cc::TransferableResource resource; | |
215 resource.id = info.resource_id; | |
216 frame.frame->delegated_frame_data->resource_list.push_back(resource); | |
217 frames_.push(std::move(frame)); | |
218 | |
219 // Keep a id -> count map for the last ouptut_surface_id. | |
220 if (last_output_surface_id_ != info.output_surface_id) { | |
221 expected_return_count_.clear(); | |
222 last_output_surface_id_ = info.output_surface_id; | |
223 } | |
224 if (expected_return_count_.count(info.resource_id)) { | |
225 expected_return_count_[info.resource_id]++; | |
226 } else { | |
227 expected_return_count_[info.resource_id] = 1; | |
228 } | |
229 } | |
230 | |
231 browser_view_renderer_->PostInvalidate(); | |
232 } | |
233 | |
234 void WillOnDraw() override { | |
235 if (!frames_.empty()) { | |
236 compositor_->SetHardwareFrame(frames_.front().output_surface_id, | |
237 std::move(frames_.front().frame)); | |
238 } | |
239 } | |
240 | |
241 void DidOnDraw(bool success) override { | |
242 EXPECT_TRUE(success); | |
243 if (frames_.empty()) { | |
244 ui_task_runner_->PostTask( | |
245 FROM_HERE, base::Bind(&SwitchOutputSurfaceIdTest::CheckResults, | |
246 base::Unretained(this))); | |
247 } else { | |
248 frames_.pop(); | |
249 browser_view_renderer_->PostInvalidate(); | |
250 } | |
251 } | |
252 | |
253 void CheckResults() { | |
254 window_->Detach(); | |
255 window_.reset(); | |
256 | |
257 // Make sure resources for the last output surface are returned. | |
hush (inactive)
2016/03/10 22:34:20
why don't you also test that the resources belong
boliu
2016/03/10 22:49:30
because we intentionally drop them at places, eg:
| |
258 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; | |
259 compositor_->SwapReturnedResources(&returned_resources_array); | |
260 for (auto& resources : returned_resources_array) { | |
261 if (resources.output_surface_id != last_output_surface_id_) | |
262 continue; | |
263 for (auto& returned_resource : resources.resources) { | |
264 EXPECT_TRUE(!!expected_return_count_.count(returned_resource.id)); | |
265 EXPECT_GE(expected_return_count_[returned_resource.id], | |
266 returned_resource.count); | |
267 expected_return_count_[returned_resource.id] -= | |
268 returned_resource.count; | |
269 if (!expected_return_count_[returned_resource.id]) | |
270 expected_return_count_.erase(returned_resource.id); | |
271 } | |
272 } | |
273 EXPECT_TRUE(expected_return_count_.empty()); | |
274 | |
275 EndTest(); | |
276 } | |
277 | |
278 private: | |
279 std::queue<content::SynchronousCompositor::Frame> frames_; | |
280 uint32_t last_output_surface_id_; | |
281 std::map<cc::ResourceId, int> expected_return_count_; | |
282 }; | |
283 | |
284 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); | |
285 | |
189 } // namespace android_webview | 286 } // namespace android_webview |
OLD | NEW |