Chromium Code Reviews| 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> | 5 #include <map> |
| 6 #include <queue> | 6 #include <queue> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "android_webview/browser/browser_view_renderer.h" | 9 #include "android_webview/browser/browser_view_renderer.h" |
| 10 #include "android_webview/browser/child_frame.h" | 10 #include "android_webview/browser/child_frame.h" |
| 11 #include "android_webview/browser/compositor_frame_consumer.h" | 11 #include "android_webview/browser/compositor_frame_consumer.h" |
| 12 #include "android_webview/browser/render_thread_manager.h" | 12 #include "android_webview/browser/render_thread_manager.h" |
| 13 #include "android_webview/browser/test/rendering_test.h" | 13 #include "android_webview/browser/test/rendering_test.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | |
| 16 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
| 17 #include "content/public/test/test_synchronous_compositor_android.h" | 18 #include "content/public/test/test_synchronous_compositor_android.h" |
| 18 | 19 |
| 19 namespace android_webview { | 20 namespace android_webview { |
| 20 | 21 |
| 21 class SmokeTest : public RenderingTest { | 22 class SmokeTest : public RenderingTest { |
| 22 void StartTest() override { browser_view_renderer_->PostInvalidate(); } | 23 void StartTest() override { browser_view_renderer_->PostInvalidate(); } |
| 23 | 24 |
| 24 void DidDrawOnRT() override { EndTest(); } | 25 void DidDrawOnRT() override { EndTest(); } |
| 25 }; | 26 }; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 return false; | 117 return false; |
| 117 | 118 |
| 118 return !constraints1.is_layer || | 119 return !constraints1.is_layer || |
| 119 constraints1.surface_rect_empty == constraints2.surface_rect_empty; | 120 constraints1.surface_rect_empty == constraints2.surface_rect_empty; |
| 120 } | 121 } |
| 121 | 122 |
| 122 void OnParentDrawConstraintsUpdated() override { | 123 void OnParentDrawConstraintsUpdated() override { |
| 123 ParentCompositorDrawConstraints constraints = | 124 ParentCompositorDrawConstraints constraints = |
| 124 GetCompositorFrameConsumer()->GetParentDrawConstraintsOnUI(); | 125 GetCompositorFrameConsumer()->GetParentDrawConstraintsOnUI(); |
| 125 switch (on_draw_count_) { | 126 switch (on_draw_count_) { |
| 127 case 0u: | |
| 128 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | |
| 129 break; | |
| 126 case 1u: | 130 case 1u: |
| 127 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); | 131 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); |
| 128 break; | 132 break; |
| 129 case 3u: | 133 case 3u: |
| 130 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | 134 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); |
| 131 EndTest(); | 135 EndTest(); |
| 132 break; | 136 break; |
| 133 // There will be a following 4th onDraw. But the hardware renderer won't | 137 // There will be a following 4th onDraw. But the hardware renderer won't |
| 134 // post back the draw constraints in DrawGL because the constraints | 138 // post back the draw constraints in DrawGL because the constraints |
| 135 // don't change. | 139 // don't change. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 return true; | 245 return true; |
| 242 } | 246 } |
| 243 return false; | 247 return false; |
| 244 } | 248 } |
| 245 | 249 |
| 246 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; | 250 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; |
| 247 int frame_number_; | 251 int frame_number_; |
| 248 }; | 252 }; |
| 249 | 253 |
| 250 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { | 254 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { |
| 255 public: | |
|
boliu
2016/05/10 15:18:19
are these new public calls needed? Are there subcl
Tobias Sargeant
2016/05/13 13:23:56
No they don't need to be; I was just aligning thes
| |
| 251 struct FrameInfo { | 256 struct FrameInfo { |
| 252 uint32_t output_surface_id; | 257 uint32_t output_surface_id; |
| 253 cc::ResourceId resource_id; // Each frame contains a single resource. | 258 cc::ResourceId resource_id; // Each frame contains a single resource. |
| 254 }; | 259 }; |
| 255 | 260 |
| 256 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 261 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 257 int frame_number) override { | 262 int frame_number) override { |
| 258 static const FrameInfo infos[] = { | 263 static const FrameInfo infos[] = { |
| 259 // First output surface. | 264 // First output surface. |
| 260 {0u, 1u}, | 265 {0u, 1u}, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } | 312 } |
| 308 | 313 |
| 309 private: | 314 private: |
| 310 uint32_t last_output_surface_id_; | 315 uint32_t last_output_surface_id_; |
| 311 ResourceCountMap expected_return_count_; | 316 ResourceCountMap expected_return_count_; |
| 312 }; | 317 }; |
| 313 | 318 |
| 314 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); | 319 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); |
| 315 | 320 |
| 316 class RenderThreadManagerDeletionTest : public ResourceRenderingTest { | 321 class RenderThreadManagerDeletionTest : public ResourceRenderingTest { |
| 322 public: | |
| 317 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 323 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 318 int frame_number) override { | 324 int frame_number) override { |
| 319 if (frame_number > 0) { | 325 if (frame_number > 0) { |
| 320 return nullptr; | 326 return nullptr; |
| 321 } | 327 } |
| 322 | 328 |
| 323 const uint32_t output_surface_id = 0u; | 329 const uint32_t output_surface_id = 0u; |
| 324 const cc::ResourceId resource_id = | 330 const cc::ResourceId resource_id = |
| 325 static_cast<cc::ResourceId>(frame_number); | 331 static_cast<cc::ResourceId>(frame_number); |
| 326 | 332 |
| 327 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 333 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 328 new content::SynchronousCompositor::Frame); | 334 new content::SynchronousCompositor::Frame); |
| 329 frame->output_surface_id = output_surface_id; | 335 frame->output_surface_id = output_surface_id; |
| 330 frame->frame = ConstructFrame(resource_id); | 336 frame->frame = ConstructFrame(resource_id); |
| 331 ++expected_return_count_[output_surface_id][resource_id]; | 337 ++expected_return_count_[output_surface_id][resource_id]; |
| 332 return frame; | 338 return frame; |
| 333 } | 339 } |
| 334 | 340 |
| 335 void CheckResults() override { | 341 void CheckResults() override { |
| 336 OutputSurfaceResourceCountMap resource_counts; | 342 OutputSurfaceResourceCountMap resource_counts; |
| 337 render_thread_manager_.reset(); | 343 functor_.reset(); |
| 338 // Make sure resources for the last frame are returned. | 344 // Make sure resources for the last frame are returned. |
| 339 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | 345 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); |
| 340 EndTest(); | 346 EndTest(); |
| 341 } | 347 } |
| 342 | 348 |
| 343 private: | 349 private: |
| 344 OutputSurfaceResourceCountMap expected_return_count_; | 350 OutputSurfaceResourceCountMap expected_return_count_; |
| 345 }; | 351 }; |
| 346 | 352 |
| 347 RENDERING_TEST_F(RenderThreadManagerDeletionTest); | 353 RENDERING_TEST_F(RenderThreadManagerDeletionTest); |
| 348 | 354 |
| 355 class RenderThreadManagerSwitchTest : public ResourceRenderingTest { | |
| 356 public: | |
| 357 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | |
| 358 int frame_number) override { | |
| 359 switch (frame_number) { | |
| 360 case 0: | |
| 361 // Draw a frame with initial RTM. | |
| 362 break; | |
| 363 case 1: | |
| 364 // Switch to new RTM. | |
| 365 saved_functor_ = std::move(functor_); | |
| 366 functor_.reset( | |
| 367 new Functor(base::Bind(&RenderingTest::CreateRenderThreadManager, | |
| 368 base::Unretained(this)))); | |
| 369 browser_view_renderer_->SetCurrentCompositorFrameConsumer( | |
| 370 functor_->GetCompositorFrameConsumer()); | |
| 371 window_->SetDrawFunctor(functor_.get()); | |
| 372 break; | |
| 373 case 2: | |
| 374 // Draw a frame with the new RTM, but also redraw the initial RTM. | |
| 375 window_->RequestDrawGL(saved_functor_.get()); | |
| 376 break; | |
| 377 case 3: | |
| 378 // Switch back to the initial RTM, allowing the new RTM to be destroyed. | |
| 379 functor_ = std::move(saved_functor_); | |
| 380 browser_view_renderer_->SetCurrentCompositorFrameConsumer( | |
| 381 functor_->GetCompositorFrameConsumer()); | |
| 382 window_->SetDrawFunctor(functor_.get()); | |
| 383 break; | |
| 384 default: | |
| 385 return nullptr; | |
| 386 } | |
| 387 | |
| 388 const uint32_t output_surface_id = 0u; | |
| 389 const cc::ResourceId resource_id = | |
| 390 static_cast<cc::ResourceId>(frame_number); | |
| 391 | |
| 392 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | |
| 393 new content::SynchronousCompositor::Frame); | |
| 394 frame->output_surface_id = output_surface_id; | |
| 395 frame->frame = ConstructFrame(resource_id); | |
| 396 ++expected_return_count_[output_surface_id][resource_id]; | |
| 397 return frame; | |
| 398 } | |
| 399 | |
| 400 void CheckResults() override { | |
| 401 OutputSurfaceResourceCountMap resource_counts; | |
| 402 functor_.reset(); | |
| 403 // Make sure resources for all frames are returned. | |
| 404 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | |
| 405 EndTest(); | |
| 406 } | |
| 407 | |
| 408 private: | |
| 409 std::unique_ptr<Functor> saved_functor_; | |
| 410 OutputSurfaceResourceCountMap expected_return_count_; | |
| 411 }; | |
| 412 | |
| 413 RENDERING_TEST_F(RenderThreadManagerSwitchTest); | |
| 414 | |
| 349 } // namespace android_webview | 415 } // namespace android_webview |
| OLD | NEW |