| 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" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 private: | 287 private: |
| 288 int on_draw_count_; | 288 int on_draw_count_; |
| 289 }; | 289 }; |
| 290 | 290 |
| 291 RENDERING_TEST_F(CompositorNoFrameTest); | 291 RENDERING_TEST_F(CompositorNoFrameTest); |
| 292 | 292 |
| 293 class ResourceRenderingTest : public RenderingTest { | 293 class ResourceRenderingTest : public RenderingTest { |
| 294 public: | 294 public: |
| 295 using ResourceCountMap = std::map<cc::ResourceId, int>; | 295 using ResourceCountMap = std::map<cc::ResourceId, int>; |
| 296 using OutputSurfaceResourceCountMap = std::map<uint32_t, ResourceCountMap>; | 296 using CompositorFrameSinkResourceCountMap = |
| 297 std::map<uint32_t, ResourceCountMap>; |
| 297 | 298 |
| 298 virtual std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 299 virtual std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 299 int frame_number) = 0; | 300 int frame_number) = 0; |
| 300 | 301 |
| 301 void StartTest() override { | 302 void StartTest() override { |
| 302 frame_number_ = 0; | 303 frame_number_ = 0; |
| 303 AdvanceFrame(); | 304 AdvanceFrame(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void WillOnDraw() override { | 307 void WillOnDraw() override { |
| 307 if (next_frame_) { | 308 if (next_frame_) { |
| 308 compositor_->SetHardwareFrame(next_frame_->output_surface_id, | 309 compositor_->SetHardwareFrame(next_frame_->compositor_frame_sink_id, |
| 309 std::move(next_frame_->frame)); | 310 std::move(next_frame_->frame)); |
| 310 } | 311 } |
| 311 } | 312 } |
| 312 | 313 |
| 313 void DidOnDraw(bool success) override { | 314 void DidOnDraw(bool success) override { |
| 314 EXPECT_EQ(next_frame_ != nullptr, success); | 315 EXPECT_EQ(next_frame_ != nullptr, success); |
| 315 if (!AdvanceFrame()) { | 316 if (!AdvanceFrame()) { |
| 316 ui_task_runner_->PostTask(FROM_HERE, | 317 ui_task_runner_->PostTask(FROM_HERE, |
| 317 base::Bind(&ResourceRenderingTest::CheckResults, | 318 base::Bind(&ResourceRenderingTest::CheckResults, |
| 318 base::Unretained(this))); | 319 base::Unretained(this))); |
| 319 } | 320 } |
| 320 } | 321 } |
| 321 | 322 |
| 322 OutputSurfaceResourceCountMap GetReturnedResourceCounts() { | 323 CompositorFrameSinkResourceCountMap GetReturnedResourceCounts() { |
| 323 OutputSurfaceResourceCountMap counts; | 324 CompositorFrameSinkResourceCountMap counts; |
| 324 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; | 325 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; |
| 325 compositor_->SwapReturnedResources(&returned_resources_array); | 326 compositor_->SwapReturnedResources(&returned_resources_array); |
| 326 for (const auto& resources : returned_resources_array) { | 327 for (const auto& resources : returned_resources_array) { |
| 327 for (const auto& returned_resource : resources.resources) { | 328 for (const auto& returned_resource : resources.resources) { |
| 328 counts[resources.output_surface_id][returned_resource.id] += | 329 counts[resources.compositor_frame_sink_id][returned_resource.id] += |
| 329 returned_resource.count; | 330 returned_resource.count; |
| 330 } | 331 } |
| 331 } | 332 } |
| 332 return counts; | 333 return counts; |
| 333 } | 334 } |
| 334 | 335 |
| 335 virtual void CheckResults() = 0; | 336 virtual void CheckResults() = 0; |
| 336 | 337 |
| 337 private: | 338 private: |
| 338 bool AdvanceFrame() { | 339 bool AdvanceFrame() { |
| 339 next_frame_ = GetFrame(frame_number_++); | 340 next_frame_ = GetFrame(frame_number_++); |
| 340 if (next_frame_) { | 341 if (next_frame_) { |
| 341 browser_view_renderer_->PostInvalidate(ActiveCompositor()); | 342 browser_view_renderer_->PostInvalidate(ActiveCompositor()); |
| 342 return true; | 343 return true; |
| 343 } | 344 } |
| 344 return false; | 345 return false; |
| 345 } | 346 } |
| 346 | 347 |
| 347 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; | 348 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; |
| 348 int frame_number_; | 349 int frame_number_; |
| 349 }; | 350 }; |
| 350 | 351 |
| 351 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { | 352 class SwitchCompositorFrameSinkIdTest : public ResourceRenderingTest { |
| 352 struct FrameInfo { | 353 struct FrameInfo { |
| 353 uint32_t output_surface_id; | 354 uint32_t compositor_frame_sink_id; |
| 354 cc::ResourceId resource_id; // Each frame contains a single resource. | 355 cc::ResourceId resource_id; // Each frame contains a single resource. |
| 355 }; | 356 }; |
| 356 | 357 |
| 357 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 358 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 358 int frame_number) override { | 359 int frame_number) override { |
| 359 static const FrameInfo infos[] = { | 360 static const FrameInfo infos[] = { |
| 360 // First output surface. | 361 // First output surface. |
| 361 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u}, | 362 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u}, |
| 362 // Second output surface. | 363 // Second output surface. |
| 363 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u}, | 364 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u}, |
| 364 }; | 365 }; |
| 365 if (frame_number >= static_cast<int>(arraysize(infos))) { | 366 if (frame_number >= static_cast<int>(arraysize(infos))) { |
| 366 return nullptr; | 367 return nullptr; |
| 367 } | 368 } |
| 368 | 369 |
| 369 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 370 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 370 new content::SynchronousCompositor::Frame); | 371 new content::SynchronousCompositor::Frame); |
| 371 frame->output_surface_id = infos[frame_number].output_surface_id; | 372 frame->compositor_frame_sink_id = |
| 373 infos[frame_number].compositor_frame_sink_id; |
| 372 frame->frame = ConstructFrame(infos[frame_number].resource_id); | 374 frame->frame = ConstructFrame(infos[frame_number].resource_id); |
| 373 | 375 |
| 374 if (last_output_surface_id_ != infos[frame_number].output_surface_id) { | 376 if (last_compositor_frame_sink_id_ != |
| 377 infos[frame_number].compositor_frame_sink_id) { |
| 375 expected_return_count_.clear(); | 378 expected_return_count_.clear(); |
| 376 last_output_surface_id_ = infos[frame_number].output_surface_id; | 379 last_compositor_frame_sink_id_ = |
| 380 infos[frame_number].compositor_frame_sink_id; |
| 377 } | 381 } |
| 378 ++expected_return_count_[infos[frame_number].resource_id]; | 382 ++expected_return_count_[infos[frame_number].resource_id]; |
| 379 return frame; | 383 return frame; |
| 380 } | 384 } |
| 381 | 385 |
| 382 void StartTest() override { | 386 void StartTest() override { |
| 383 last_output_surface_id_ = -1U; | 387 last_compositor_frame_sink_id_ = -1U; |
| 384 ResourceRenderingTest::StartTest(); | 388 ResourceRenderingTest::StartTest(); |
| 385 } | 389 } |
| 386 | 390 |
| 387 void CheckResults() override { | 391 void CheckResults() override { |
| 388 GetCompositorFrameConsumer()->DeleteHardwareRendererOnUI(); | 392 GetCompositorFrameConsumer()->DeleteHardwareRendererOnUI(); |
| 389 window_->Detach(); | 393 window_->Detach(); |
| 390 window_.reset(); | 394 window_.reset(); |
| 391 | 395 |
| 392 // Make sure resources for the last output surface are returned. | 396 // Make sure resources for the last output surface are returned. |
| 393 EXPECT_EQ(expected_return_count_, | 397 EXPECT_EQ(expected_return_count_, |
| 394 GetReturnedResourceCounts()[last_output_surface_id_]); | 398 GetReturnedResourceCounts()[last_compositor_frame_sink_id_]); |
| 395 EndTest(); | 399 EndTest(); |
| 396 } | 400 } |
| 397 | 401 |
| 398 private: | 402 private: |
| 399 uint32_t last_output_surface_id_; | 403 uint32_t last_compositor_frame_sink_id_; |
| 400 ResourceCountMap expected_return_count_; | 404 ResourceCountMap expected_return_count_; |
| 401 }; | 405 }; |
| 402 | 406 |
| 403 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); | 407 RENDERING_TEST_F(SwitchCompositorFrameSinkIdTest); |
| 404 | 408 |
| 405 class RenderThreadManagerDeletionTest : public ResourceRenderingTest { | 409 class RenderThreadManagerDeletionTest : public ResourceRenderingTest { |
| 406 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 410 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 407 int frame_number) override { | 411 int frame_number) override { |
| 408 if (frame_number > 0) { | 412 if (frame_number > 0) { |
| 409 return nullptr; | 413 return nullptr; |
| 410 } | 414 } |
| 411 | 415 |
| 412 const uint32_t output_surface_id = 0u; | 416 const uint32_t compositor_frame_sink_id = 0u; |
| 413 const cc::ResourceId resource_id = | 417 const cc::ResourceId resource_id = |
| 414 static_cast<cc::ResourceId>(frame_number); | 418 static_cast<cc::ResourceId>(frame_number); |
| 415 | 419 |
| 416 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 420 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 417 new content::SynchronousCompositor::Frame); | 421 new content::SynchronousCompositor::Frame); |
| 418 frame->output_surface_id = output_surface_id; | 422 frame->compositor_frame_sink_id = compositor_frame_sink_id; |
| 419 frame->frame = ConstructFrame(resource_id); | 423 frame->frame = ConstructFrame(resource_id); |
| 420 ++expected_return_count_[output_surface_id][resource_id]; | 424 ++expected_return_count_[compositor_frame_sink_id][resource_id]; |
| 421 return frame; | 425 return frame; |
| 422 } | 426 } |
| 423 | 427 |
| 424 void CheckResults() override { | 428 void CheckResults() override { |
| 425 OutputSurfaceResourceCountMap resource_counts; | 429 CompositorFrameSinkResourceCountMap resource_counts; |
| 426 functor_.reset(); | 430 functor_.reset(); |
| 427 // Make sure resources for the last frame are returned. | 431 // Make sure resources for the last frame are returned. |
| 428 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | 432 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); |
| 429 EndTest(); | 433 EndTest(); |
| 430 } | 434 } |
| 431 | 435 |
| 432 private: | 436 private: |
| 433 OutputSurfaceResourceCountMap expected_return_count_; | 437 CompositorFrameSinkResourceCountMap expected_return_count_; |
| 434 }; | 438 }; |
| 435 | 439 |
| 436 RENDERING_TEST_F(RenderThreadManagerDeletionTest); | 440 RENDERING_TEST_F(RenderThreadManagerDeletionTest); |
| 437 | 441 |
| 438 class RenderThreadManagerSwitchTest : public ResourceRenderingTest { | 442 class RenderThreadManagerSwitchTest : public ResourceRenderingTest { |
| 439 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( | 443 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( |
| 440 int frame_number) override { | 444 int frame_number) override { |
| 441 switch (frame_number) { | 445 switch (frame_number) { |
| 442 case 0: { | 446 case 0: { |
| 443 // Draw a frame with initial RTM. | 447 // Draw a frame with initial RTM. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 464 // Switch back to the initial RTM, allowing the new RTM to be destroyed. | 468 // Switch back to the initial RTM, allowing the new RTM to be destroyed. |
| 465 functor_ = std::move(saved_functor_); | 469 functor_ = std::move(saved_functor_); |
| 466 browser_view_renderer_->SetCurrentCompositorFrameConsumer( | 470 browser_view_renderer_->SetCurrentCompositorFrameConsumer( |
| 467 functor_->GetCompositorFrameConsumer()); | 471 functor_->GetCompositorFrameConsumer()); |
| 468 break; | 472 break; |
| 469 } | 473 } |
| 470 default: | 474 default: |
| 471 return nullptr; | 475 return nullptr; |
| 472 } | 476 } |
| 473 | 477 |
| 474 const uint32_t output_surface_id = 0u; | 478 const uint32_t compositor_frame_sink_id = 0u; |
| 475 const cc::ResourceId resource_id = | 479 const cc::ResourceId resource_id = |
| 476 static_cast<cc::ResourceId>(frame_number); | 480 static_cast<cc::ResourceId>(frame_number); |
| 477 | 481 |
| 478 std::unique_ptr<content::SynchronousCompositor::Frame> frame( | 482 std::unique_ptr<content::SynchronousCompositor::Frame> frame( |
| 479 new content::SynchronousCompositor::Frame); | 483 new content::SynchronousCompositor::Frame); |
| 480 frame->output_surface_id = output_surface_id; | 484 frame->compositor_frame_sink_id = compositor_frame_sink_id; |
| 481 frame->frame = ConstructFrame(resource_id); | 485 frame->frame = ConstructFrame(resource_id); |
| 482 ++expected_return_count_[output_surface_id][resource_id]; | 486 ++expected_return_count_[compositor_frame_sink_id][resource_id]; |
| 483 return frame; | 487 return frame; |
| 484 } | 488 } |
| 485 | 489 |
| 486 void CheckResults() override { | 490 void CheckResults() override { |
| 487 OutputSurfaceResourceCountMap resource_counts; | 491 CompositorFrameSinkResourceCountMap resource_counts; |
| 488 functor_.reset(); | 492 functor_.reset(); |
| 489 // Make sure resources for all frames are returned. | 493 // Make sure resources for all frames are returned. |
| 490 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); | 494 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); |
| 491 EndTest(); | 495 EndTest(); |
| 492 } | 496 } |
| 493 | 497 |
| 494 private: | 498 private: |
| 495 std::unique_ptr<FakeFunctor> saved_functor_; | 499 std::unique_ptr<FakeFunctor> saved_functor_; |
| 496 OutputSurfaceResourceCountMap expected_return_count_; | 500 CompositorFrameSinkResourceCountMap expected_return_count_; |
| 497 }; | 501 }; |
| 498 | 502 |
| 499 RENDERING_TEST_F(RenderThreadManagerSwitchTest); | 503 RENDERING_TEST_F(RenderThreadManagerSwitchTest); |
| 500 | 504 |
| 501 } // namespace android_webview | 505 } // namespace android_webview |
| OLD | NEW |