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 // This OnParentDrawConstraintsUpdated is generated by | |
| 129 // connecting the compositor frame consumer to the producer. | |
| 130 break; | |
| 126 case 1u: | 131 case 1u: |
| 127 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); | 132 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); |
| 128 break; | 133 break; |
| 129 case 3u: | 134 case 3u: |
| 130 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | 135 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); |
| 131 EndTest(); | 136 EndTest(); |
| 132 break; | 137 break; |
| 133 // There will be a following 4th onDraw. But the hardware renderer won't | 138 // There will be a following 4th onDraw. But the hardware renderer won't |
| 134 // post back the draw constraints in DrawGL because the constraints | 139 // post back the draw constraints in DrawGL because the constraints |
| 135 // don't change. | 140 // don't change. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { | 255 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { |
| 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}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u}, |
| 261 {0u, 1u}, | |
| 262 {0u, 2u}, | |
| 263 {0u, 2u}, | |
| 264 {0u, 3u}, | |
| 265 {0u, 3u}, | |
| 266 {0u, 4u}, | |
| 267 // Second output surface. | 266 // Second output surface. |
| 268 {1u, 1u}, | 267 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u}, |
| 269 {1u, 1u}, | |
| 270 {1u, 2u}, | |
| 271 {1u, 2u}, | |
| 272 {1u, 3u}, | |
| 273 {1u, 3u}, | |
| 274 {1u, 4u}, | |
| 275 }; | 268 }; |
| 276 if (frame_number >= static_cast<int>(arraysize(infos))) { | 269 if (frame_number >= static_cast<int>(arraysize(infos))) { |
| 277 return nullptr; | 270 return nullptr; |
| 278 } | 271 } |
| 279 | 272 |
| 280 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 273 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 281 new content::SynchronousCompositor::Frame); | 274 new content::SynchronousCompositor::Frame); |
| 282 frame->output_surface_id = infos[frame_number].output_surface_id; | 275 frame->output_surface_id = infos[frame_number].output_surface_id; |
| 283 frame->frame = ConstructFrame(infos[frame_number].resource_id); | 276 frame->frame = ConstructFrame(infos[frame_number].resource_id); |
| 284 | 277 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 320 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 328 new content::SynchronousCompositor::Frame); | 321 new content::SynchronousCompositor::Frame); |
| 329 frame->output_surface_id = output_surface_id; | 322 frame->output_surface_id = output_surface_id; |
| 330 frame->frame = ConstructFrame(resource_id); | 323 frame->frame = ConstructFrame(resource_id); |
| 331 ++expected_return_count_[output_surface_id][resource_id]; | 324 ++expected_return_count_[output_surface_id][resource_id]; |
| 332 return frame; | 325 return frame; |
| 333 } | 326 } |
| 334 | 327 |
| 335 void CheckResults() override { | 328 void CheckResults() override { |
| 336 OutputSurfaceResourceCountMap resource_counts; | 329 OutputSurfaceResourceCountMap resource_counts; |
| 337 render_thread_manager_.reset(); | 330 functor_.reset(); |
| 338 // Make sure resources for the last frame are returned. | 331 // Make sure resources for the last frame are returned. |
| 339 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | 332 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); |
| 340 EndTest(); | 333 EndTest(); |
| 341 } | 334 } |
| 342 | 335 |
| 343 private: | 336 private: |
| 344 OutputSurfaceResourceCountMap expected_return_count_; | 337 OutputSurfaceResourceCountMap expected_return_count_; |
| 345 }; | 338 }; |
| 346 | 339 |
| 347 RENDERING_TEST_F(RenderThreadManagerDeletionTest); | 340 RENDERING_TEST_F(RenderThreadManagerDeletionTest); |
| 348 | 341 |
| 342 class RenderThreadManagerSwitchTest : public ResourceRenderingTest { | |
| 343 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | |
| 344 int frame_number) override { | |
| 345 switch (frame_number) { | |
| 346 case 0: { | |
| 347 // Draw a frame with initial RTM. | |
| 348 break; | |
| 349 } | |
| 350 case 1: { | |
| 351 // Switch to new RTM. | |
| 352 std::unique_ptr<FakeFunctor> functor(new FakeFunctor); | |
| 353 functor->Init( | |
| 354 window_.get(), | |
| 355 std::unique_ptr<RenderThreadManager>(new RenderThreadManager( | |
|
boliu
2016/05/13 16:09:01
use base::WrapUnique
Tobias Sargeant
2016/05/13 17:02:36
Done.
| |
| 356 functor.get(), base::ThreadTaskRunnerHandle::Get()))); | |
| 357 browser_view_renderer_->SetCurrentCompositorFrameConsumer( | |
| 358 functor->GetCompositorFrameConsumer()); | |
| 359 saved_functor_ = std::move(functor_); | |
| 360 functor_ = std::move(functor); | |
| 361 break; | |
| 362 } | |
| 363 case 2: { | |
| 364 // Draw a frame with the new RTM, but also redraw the initial RTM. | |
| 365 window_->RequestDrawGL(saved_functor_.get()); | |
| 366 break; | |
| 367 } | |
| 368 case 3: { | |
| 369 // Switch back to the initial RTM, allowing the new RTM to be destroyed. | |
| 370 functor_ = std::move(saved_functor_); | |
| 371 browser_view_renderer_->SetCurrentCompositorFrameConsumer( | |
| 372 functor_->GetCompositorFrameConsumer()); | |
| 373 break; | |
| 374 } | |
| 375 default: | |
| 376 return nullptr; | |
| 377 } | |
| 378 | |
| 379 const uint32_t output_surface_id = 0u; | |
| 380 const cc::ResourceId resource_id = | |
| 381 static_cast<cc::ResourceId>(frame_number); | |
| 382 | |
| 383 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | |
| 384 new content::SynchronousCompositor::Frame); | |
| 385 frame->output_surface_id = output_surface_id; | |
| 386 frame->frame = ConstructFrame(resource_id); | |
| 387 ++expected_return_count_[output_surface_id][resource_id]; | |
| 388 return frame; | |
| 389 } | |
| 390 | |
| 391 void CheckResults() override { | |
| 392 OutputSurfaceResourceCountMap resource_counts; | |
| 393 functor_.reset(); | |
| 394 // Make sure resources for all frames are returned. | |
| 395 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | |
| 396 EndTest(); | |
| 397 } | |
| 398 | |
| 399 private: | |
| 400 std::unique_ptr<FakeFunctor> saved_functor_; | |
| 401 OutputSurfaceResourceCountMap expected_return_count_; | |
| 402 }; | |
| 403 | |
| 404 RENDERING_TEST_F(RenderThreadManagerSwitchTest); | |
| 405 | |
| 349 } // namespace android_webview | 406 } // namespace android_webview |
| OLD | NEW |