| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
| 12 #include "cc/base/swap_promise.h" | 12 #include "cc/base/swap_promise.h" |
| 13 #include "cc/debug/frame_rate_counter.h" | 13 #include "cc/debug/frame_rate_counter.h" |
| 14 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
| 15 #include "cc/layers/content_layer_client.h" | 15 #include "cc/layers/content_layer_client.h" |
| 16 #include "cc/layers/io_surface_layer.h" | 16 #include "cc/layers/io_surface_layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/layers/painted_scrollbar_layer.h" | 18 #include "cc/layers/painted_scrollbar_layer.h" |
| 19 #include "cc/layers/picture_layer.h" | 19 #include "cc/layers/picture_layer.h" |
| 20 #include "cc/layers/solid_color_layer.h" | 20 #include "cc/layers/solid_color_layer.h" |
| 21 #include "cc/output/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
| 22 #include "cc/output/compositor_frame_ack.h" | 22 #include "cc/output/compositor_frame_ack.h" |
| 23 #include "cc/output/copy_output_request.h" | 23 #include "cc/output/copy_output_request.h" |
| 24 #include "cc/output/copy_output_result.h" | 24 #include "cc/output/copy_output_result.h" |
| 25 #include "cc/output/output_surface.h" | 25 #include "cc/output/output_surface.h" |
| 26 #include "cc/quads/draw_quad.h" | 26 #include "cc/quads/draw_quad.h" |
| 27 #include "cc/quads/io_surface_draw_quad.h" | 27 #include "cc/quads/io_surface_draw_quad.h" |
| 28 #include "cc/quads/tile_draw_quad.h" |
| 28 #include "cc/resources/prioritized_resource.h" | 29 #include "cc/resources/prioritized_resource.h" |
| 29 #include "cc/resources/prioritized_resource_manager.h" | 30 #include "cc/resources/prioritized_resource_manager.h" |
| 30 #include "cc/resources/resource_update_queue.h" | 31 #include "cc/resources/resource_update_queue.h" |
| 31 #include "cc/test/fake_content_layer.h" | 32 #include "cc/test/fake_content_layer.h" |
| 32 #include "cc/test/fake_content_layer_client.h" | 33 #include "cc/test/fake_content_layer_client.h" |
| 33 #include "cc/test/fake_content_layer_impl.h" | 34 #include "cc/test/fake_content_layer_impl.h" |
| 34 #include "cc/test/fake_layer_tree_host_client.h" | 35 #include "cc/test/fake_layer_tree_host_client.h" |
| 35 #include "cc/test/fake_output_surface.h" | 36 #include "cc/test/fake_output_surface.h" |
| 36 #include "cc/test/fake_painted_scrollbar_layer.h" | 37 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 37 #include "cc/test/fake_picture_layer.h" | 38 #include "cc/test/fake_picture_layer.h" |
| 38 #include "cc/test/fake_picture_layer_impl.h" | 39 #include "cc/test/fake_picture_layer_impl.h" |
| 40 #include "cc/test/fake_picture_pile.h" |
| 39 #include "cc/test/fake_proxy.h" | 41 #include "cc/test/fake_proxy.h" |
| 40 #include "cc/test/fake_scoped_ui_resource.h" | 42 #include "cc/test/fake_scoped_ui_resource.h" |
| 41 #include "cc/test/geometry_test_utils.h" | 43 #include "cc/test/geometry_test_utils.h" |
| 42 #include "cc/test/layer_tree_test.h" | 44 #include "cc/test/layer_tree_test.h" |
| 43 #include "cc/test/test_shared_bitmap_manager.h" | 45 #include "cc/test/test_shared_bitmap_manager.h" |
| 44 #include "cc/test/test_web_graphics_context_3d.h" | 46 #include "cc/test/test_web_graphics_context_3d.h" |
| 45 #include "cc/trees/layer_tree_host_impl.h" | 47 #include "cc/trees/layer_tree_host_impl.h" |
| 46 #include "cc/trees/layer_tree_impl.h" | 48 #include "cc/trees/layer_tree_impl.h" |
| 47 #include "cc/trees/single_thread_proxy.h" | 49 #include "cc/trees/single_thread_proxy.h" |
| 48 #include "cc/trees/thread_proxy.h" | 50 #include "cc/trees/thread_proxy.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 int num_draws_; | 410 int num_draws_; |
| 409 }; | 411 }; |
| 410 | 412 |
| 411 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); | 413 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); |
| 412 | 414 |
| 413 // After setNeedsRedrawRect(invalid_rect) the final damage_rect | 415 // After setNeedsRedrawRect(invalid_rect) the final damage_rect |
| 414 // must contain invalid_rect. | 416 // must contain invalid_rect. |
| 415 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { | 417 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { |
| 416 public: | 418 public: |
| 417 LayerTreeHostTestSetNeedsRedrawRect() | 419 LayerTreeHostTestSetNeedsRedrawRect() |
| 418 : num_draws_(0), | 420 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| 419 bounds_(50, 50), | |
| 420 invalid_rect_(10, 10, 20, 20), | |
| 421 root_layer_(ContentLayer::Create(&client_)) {} | |
| 422 | 421 |
| 423 void BeginTest() override { | 422 void BeginTest() override { |
| 423 if (layer_tree_host()->settings().impl_side_painting) |
| 424 root_layer_ = FakePictureLayer::Create(&client_); |
| 425 else |
| 426 root_layer_ = ContentLayer::Create(&client_); |
| 424 root_layer_->SetIsDrawable(true); | 427 root_layer_->SetIsDrawable(true); |
| 425 root_layer_->SetBounds(bounds_); | 428 root_layer_->SetBounds(bounds_); |
| 426 layer_tree_host()->SetRootLayer(root_layer_); | 429 layer_tree_host()->SetRootLayer(root_layer_); |
| 427 layer_tree_host()->SetViewportSize(bounds_); | 430 layer_tree_host()->SetViewportSize(bounds_); |
| 428 PostSetNeedsCommitToMainThread(); | 431 PostSetNeedsCommitToMainThread(); |
| 429 } | 432 } |
| 430 | 433 |
| 431 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 434 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 432 LayerTreeHostImpl::FrameData* frame_data, | 435 LayerTreeHostImpl::FrameData* frame_data, |
| 433 DrawResult draw_result) override { | 436 DrawResult draw_result) override { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 457 num_draws_++; | 460 num_draws_++; |
| 458 } | 461 } |
| 459 | 462 |
| 460 void AfterTest() override { EXPECT_EQ(2, num_draws_); } | 463 void AfterTest() override { EXPECT_EQ(2, num_draws_); } |
| 461 | 464 |
| 462 private: | 465 private: |
| 463 int num_draws_; | 466 int num_draws_; |
| 464 const gfx::Size bounds_; | 467 const gfx::Size bounds_; |
| 465 const gfx::Rect invalid_rect_; | 468 const gfx::Rect invalid_rect_; |
| 466 FakeContentLayerClient client_; | 469 FakeContentLayerClient client_; |
| 467 scoped_refptr<ContentLayer> root_layer_; | 470 scoped_refptr<Layer> root_layer_; |
| 468 }; | 471 }; |
| 469 | 472 |
| 470 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); | 473 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); |
| 471 | 474 |
| 472 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { | 475 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
| 473 public: | 476 public: |
| 474 void InitializeSettings(LayerTreeSettings* settings) override { | 477 void InitializeSettings(LayerTreeSettings* settings) override { |
| 475 settings->layer_transforms_should_scale_layer_contents = true; | 478 settings->layer_transforms_should_scale_layer_contents = true; |
| 476 } | 479 } |
| 477 | 480 |
| 478 void SetupTree() override { | 481 void SetupTree() override { |
| 479 root_layer_ = Layer::Create(); | 482 root_layer_ = Layer::Create(); |
| 480 root_layer_->SetBounds(gfx::Size(10, 20)); | 483 root_layer_->SetBounds(gfx::Size(10, 20)); |
| 481 | 484 |
| 482 scaled_layer_ = FakeContentLayer::Create(&client_); | 485 if (layer_tree_host()->settings().impl_side_painting) |
| 486 scaled_layer_ = FakePictureLayer::Create(&client_); |
| 487 else |
| 488 scaled_layer_ = FakeContentLayer::Create(&client_); |
| 483 scaled_layer_->SetBounds(gfx::Size(1, 1)); | 489 scaled_layer_->SetBounds(gfx::Size(1, 1)); |
| 484 root_layer_->AddChild(scaled_layer_); | 490 root_layer_->AddChild(scaled_layer_); |
| 485 | 491 |
| 486 layer_tree_host()->SetRootLayer(root_layer_); | 492 layer_tree_host()->SetRootLayer(root_layer_); |
| 487 LayerTreeHostTest::SetupTree(); | 493 LayerTreeHostTest::SetupTree(); |
| 488 } | 494 } |
| 489 | 495 |
| 490 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 496 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 491 | 497 |
| 492 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 498 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 493 if (host_impl->active_tree()->source_frame_number() == 1) | 499 if (host_impl->active_tree()->source_frame_number() == 1) |
| 494 EndTest(); | 500 EndTest(); |
| 495 } | 501 } |
| 496 | 502 |
| 497 void DidCommit() override { | 503 void DidCommit() override { |
| 498 switch (layer_tree_host()->source_frame_number()) { | 504 switch (layer_tree_host()->source_frame_number()) { |
| 499 case 1: | 505 case 1: |
| 500 // Changing the device scale factor causes a commit. It also changes | 506 // SetBounds grows the layer and exposes new content. |
| 501 // the content bounds of |scaled_layer_|, which should not generate | 507 if (layer_tree_host()->settings().impl_side_painting) { |
| 502 // a second commit as a result. | 508 scaled_layer_->SetBounds(gfx::Size(4, 4)); |
| 503 layer_tree_host()->SetDeviceScaleFactor(4.f); | 509 } else { |
| 510 // Changing the device scale factor causes a commit. It also changes |
| 511 // the content bounds of |scaled_layer_|, which should not generate |
| 512 // a second commit as a result. |
| 513 layer_tree_host()->SetDeviceScaleFactor(4.f); |
| 514 } |
| 504 break; | 515 break; |
| 505 default: | 516 default: |
| 506 // No extra commits. | 517 // No extra commits. |
| 507 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | 518 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| 508 } | 519 } |
| 509 } | 520 } |
| 510 | 521 |
| 511 void AfterTest() override { | 522 void AfterTest() override { |
| 512 EXPECT_EQ(gfx::Size(4, 4).ToString(), | 523 EXPECT_EQ(gfx::Size(4, 4).ToString(), |
| 513 scaled_layer_->content_bounds().ToString()); | 524 scaled_layer_->content_bounds().ToString()); |
| 514 } | 525 } |
| 515 | 526 |
| 516 private: | 527 private: |
| 517 FakeContentLayerClient client_; | 528 FakeContentLayerClient client_; |
| 518 scoped_refptr<Layer> root_layer_; | 529 scoped_refptr<Layer> root_layer_; |
| 519 scoped_refptr<FakeContentLayer> scaled_layer_; | 530 scoped_refptr<Layer> scaled_layer_; |
| 520 }; | 531 }; |
| 521 | 532 |
| 522 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); | 533 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); |
| 523 | 534 |
| 524 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate | 535 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate |
| 525 : public LayerTreeHostTest { | 536 : public LayerTreeHostTest { |
| 526 public: | 537 public: |
| 527 void InitializeSettings(LayerTreeSettings* settings) override { | 538 void InitializeSettings(LayerTreeSettings* settings) override { |
| 528 settings->layer_transforms_should_scale_layer_contents = true; | 539 settings->layer_transforms_should_scale_layer_contents = true; |
| 529 } | 540 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 scoped_refptr<Layer> root_layer_; | 587 scoped_refptr<Layer> root_layer_; |
| 577 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; | 588 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; |
| 578 }; | 589 }; |
| 579 | 590 |
| 580 SINGLE_AND_MULTI_THREAD_TEST_F( | 591 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 581 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); | 592 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); |
| 582 | 593 |
| 583 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { | 594 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { |
| 584 public: | 595 public: |
| 585 LayerTreeHostTestSetNextCommitForcesRedraw() | 596 LayerTreeHostTestSetNextCommitForcesRedraw() |
| 586 : num_draws_(0), | 597 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| 587 bounds_(50, 50), | |
| 588 invalid_rect_(10, 10, 20, 20), | |
| 589 root_layer_(ContentLayer::Create(&client_)) {} | |
| 590 | 598 |
| 591 void BeginTest() override { | 599 void BeginTest() override { |
| 600 if (layer_tree_host()->settings().impl_side_painting) |
| 601 root_layer_ = FakePictureLayer::Create(&client_); |
| 602 else |
| 603 root_layer_ = ContentLayer::Create(&client_); |
| 592 root_layer_->SetIsDrawable(true); | 604 root_layer_->SetIsDrawable(true); |
| 593 root_layer_->SetBounds(bounds_); | 605 root_layer_->SetBounds(bounds_); |
| 594 layer_tree_host()->SetRootLayer(root_layer_); | 606 layer_tree_host()->SetRootLayer(root_layer_); |
| 595 layer_tree_host()->SetViewportSize(bounds_); | 607 layer_tree_host()->SetViewportSize(bounds_); |
| 596 PostSetNeedsCommitToMainThread(); | 608 PostSetNeedsCommitToMainThread(); |
| 597 } | 609 } |
| 598 | 610 |
| 599 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 611 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 600 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) | 612 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) |
| 601 host_impl->SetNeedsRedrawRect(invalid_rect_); | 613 host_impl->SetNeedsRedrawRect(invalid_rect_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 num_draws_++; | 670 num_draws_++; |
| 659 } | 671 } |
| 660 | 672 |
| 661 void AfterTest() override { EXPECT_EQ(5, num_draws_); } | 673 void AfterTest() override { EXPECT_EQ(5, num_draws_); } |
| 662 | 674 |
| 663 private: | 675 private: |
| 664 int num_draws_; | 676 int num_draws_; |
| 665 const gfx::Size bounds_; | 677 const gfx::Size bounds_; |
| 666 const gfx::Rect invalid_rect_; | 678 const gfx::Rect invalid_rect_; |
| 667 FakeContentLayerClient client_; | 679 FakeContentLayerClient client_; |
| 668 scoped_refptr<ContentLayer> root_layer_; | 680 scoped_refptr<Layer> root_layer_; |
| 669 }; | 681 }; |
| 670 | 682 |
| 671 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( | 683 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| 672 LayerTreeHostTestSetNextCommitForcesRedraw); | 684 LayerTreeHostTestSetNextCommitForcesRedraw); |
| 673 | 685 |
| 674 // Tests that if a layer is not drawn because of some reason in the parent then | 686 // Tests that if a layer is not drawn because of some reason in the parent then |
| 675 // its damage is preserved until the next time it is drawn. | 687 // its damage is preserved until the next time it is drawn. |
| 676 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { | 688 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { |
| 677 public: | 689 public: |
| 678 LayerTreeHostTestUndrawnLayersDamageLater() | 690 LayerTreeHostTestUndrawnLayersDamageLater() {} |
| 679 : root_layer_(ContentLayer::Create(&client_)) {} | |
| 680 | 691 |
| 681 void SetupTree() override { | 692 void SetupTree() override { |
| 693 if (layer_tree_host()->settings().impl_side_painting) |
| 694 root_layer_ = FakePictureLayer::Create(&client_); |
| 695 else |
| 696 root_layer_ = ContentLayer::Create(&client_); |
| 682 root_layer_->SetIsDrawable(true); | 697 root_layer_->SetIsDrawable(true); |
| 683 root_layer_->SetBounds(gfx::Size(50, 50)); | 698 root_layer_->SetBounds(gfx::Size(50, 50)); |
| 684 layer_tree_host()->SetRootLayer(root_layer_); | 699 layer_tree_host()->SetRootLayer(root_layer_); |
| 685 | 700 |
| 686 // The initially transparent layer has a larger child layer, which is | 701 // The initially transparent layer has a larger child layer, which is |
| 687 // not initially drawn because of the this (parent) layer. | 702 // not initially drawn because of the this (parent) layer. |
| 688 parent_layer_ = FakeContentLayer::Create(&client_); | 703 if (layer_tree_host()->settings().impl_side_painting) |
| 704 parent_layer_ = FakePictureLayer::Create(&client_); |
| 705 else |
| 706 parent_layer_ = FakeContentLayer::Create(&client_); |
| 689 parent_layer_->SetBounds(gfx::Size(15, 15)); | 707 parent_layer_->SetBounds(gfx::Size(15, 15)); |
| 690 parent_layer_->SetOpacity(0.0f); | 708 parent_layer_->SetOpacity(0.0f); |
| 691 root_layer_->AddChild(parent_layer_); | 709 root_layer_->AddChild(parent_layer_); |
| 692 | 710 |
| 693 child_layer_ = FakeContentLayer::Create(&client_); | 711 if (layer_tree_host()->settings().impl_side_painting) |
| 712 child_layer_ = FakePictureLayer::Create(&client_); |
| 713 else |
| 714 child_layer_ = FakeContentLayer::Create(&client_); |
| 694 child_layer_->SetBounds(gfx::Size(25, 25)); | 715 child_layer_->SetBounds(gfx::Size(25, 25)); |
| 695 parent_layer_->AddChild(child_layer_); | 716 parent_layer_->AddChild(child_layer_); |
| 696 | 717 |
| 697 LayerTreeHostTest::SetupTree(); | 718 LayerTreeHostTest::SetupTree(); |
| 698 } | 719 } |
| 699 | 720 |
| 700 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 721 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 701 | 722 |
| 702 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 723 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 703 LayerTreeHostImpl::FrameData* frame_data, | 724 LayerTreeHostImpl::FrameData* frame_data, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 break; | 769 break; |
| 749 default: | 770 default: |
| 750 NOTREACHED(); | 771 NOTREACHED(); |
| 751 } | 772 } |
| 752 } | 773 } |
| 753 | 774 |
| 754 void AfterTest() override {} | 775 void AfterTest() override {} |
| 755 | 776 |
| 756 private: | 777 private: |
| 757 FakeContentLayerClient client_; | 778 FakeContentLayerClient client_; |
| 758 scoped_refptr<ContentLayer> root_layer_; | 779 scoped_refptr<Layer> root_layer_; |
| 759 scoped_refptr<FakeContentLayer> parent_layer_; | 780 scoped_refptr<Layer> parent_layer_; |
| 760 scoped_refptr<FakeContentLayer> child_layer_; | 781 scoped_refptr<Layer> child_layer_; |
| 761 }; | 782 }; |
| 762 | 783 |
| 763 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); | 784 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); |
| 764 | 785 |
| 765 // Tests that if a layer is not drawn because of some reason in the parent, | 786 // Tests that if a layer is not drawn because of some reason in the parent, |
| 766 // causing its content bounds to not be computed, then when it is later drawn, | 787 // causing its content bounds to not be computed, then when it is later drawn, |
| 767 // its content bounds get pushed. | 788 // its content bounds get pushed. |
| 768 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater | 789 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater |
| 769 : public LayerTreeHostTest { | 790 : public LayerTreeHostTest { |
| 770 public: | 791 public: |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 } | 1144 } |
| 1124 ~ContentLayerWithUpdateTracking() override {} | 1145 ~ContentLayerWithUpdateTracking() override {} |
| 1125 | 1146 |
| 1126 int paint_contents_count_; | 1147 int paint_contents_count_; |
| 1127 }; | 1148 }; |
| 1128 | 1149 |
| 1129 // Layer opacity change during paint should not prevent compositor resources | 1150 // Layer opacity change during paint should not prevent compositor resources |
| 1130 // from being updated during commit. | 1151 // from being updated during commit. |
| 1131 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { | 1152 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
| 1132 public: | 1153 public: |
| 1133 LayerTreeHostTestOpacityChange() | 1154 LayerTreeHostTestOpacityChange() : test_opacity_change_delegate_() {} |
| 1134 : test_opacity_change_delegate_(), | |
| 1135 update_check_layer_(ContentLayerWithUpdateTracking::Create( | |
| 1136 &test_opacity_change_delegate_)) { | |
| 1137 test_opacity_change_delegate_.SetTestLayer(update_check_layer_.get()); | |
| 1138 } | |
| 1139 | 1155 |
| 1140 void BeginTest() override { | 1156 void BeginTest() override { |
| 1157 if (layer_tree_host()->settings().impl_side_painting) { |
| 1158 update_check_picture_layer_ = |
| 1159 FakePictureLayer::Create(&test_opacity_change_delegate_); |
| 1160 test_opacity_change_delegate_.SetTestLayer( |
| 1161 update_check_picture_layer_.get()); |
| 1162 is_impl_paint_ = true; |
| 1163 } else { |
| 1164 update_check_content_layer_ = ContentLayerWithUpdateTracking::Create( |
| 1165 &test_opacity_change_delegate_); |
| 1166 test_opacity_change_delegate_.SetTestLayer( |
| 1167 update_check_content_layer_.get()); |
| 1168 is_impl_paint_ = false; |
| 1169 } |
| 1141 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | 1170 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
| 1142 layer_tree_host()->root_layer()->AddChild(update_check_layer_); | 1171 if (layer_tree_host()->settings().impl_side_painting) |
| 1172 layer_tree_host()->root_layer()->AddChild(update_check_picture_layer_); |
| 1173 else |
| 1174 layer_tree_host()->root_layer()->AddChild(update_check_content_layer_); |
| 1143 | 1175 |
| 1144 PostSetNeedsCommitToMainThread(); | 1176 PostSetNeedsCommitToMainThread(); |
| 1145 } | 1177 } |
| 1146 | 1178 |
| 1147 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { EndTest(); } | 1179 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { EndTest(); } |
| 1148 | 1180 |
| 1149 void AfterTest() override { | 1181 void AfterTest() override { |
| 1150 // Update() should have been called once. | 1182 // Update() should have been called once. |
| 1151 EXPECT_EQ(1, update_check_layer_->PaintContentsCount()); | 1183 if (is_impl_paint_) |
| 1184 EXPECT_EQ(1u, update_check_picture_layer_->update_count()); |
| 1185 else |
| 1186 EXPECT_EQ(1, update_check_content_layer_->PaintContentsCount()); |
| 1152 } | 1187 } |
| 1153 | 1188 |
| 1154 private: | 1189 private: |
| 1155 TestOpacityChangeLayerDelegate test_opacity_change_delegate_; | 1190 TestOpacityChangeLayerDelegate test_opacity_change_delegate_; |
| 1156 scoped_refptr<ContentLayerWithUpdateTracking> update_check_layer_; | 1191 scoped_refptr<ContentLayerWithUpdateTracking> update_check_content_layer_; |
| 1192 scoped_refptr<FakePictureLayer> update_check_picture_layer_; |
| 1193 bool is_impl_paint_; |
| 1157 }; | 1194 }; |
| 1158 | 1195 |
| 1159 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); | 1196 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); |
| 1160 | 1197 |
| 1161 class NoScaleContentLayer : public ContentLayer { | |
| 1162 public: | |
| 1163 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { | |
| 1164 return make_scoped_refptr(new NoScaleContentLayer(client)); | |
| 1165 } | |
| 1166 | |
| 1167 void CalculateContentsScale(float ideal_contents_scale, | |
| 1168 float* contents_scale_x, | |
| 1169 float* contents_scale_y, | |
| 1170 gfx::Size* contentBounds) override { | |
| 1171 // Skip over the ContentLayer's method to the base Layer class. | |
| 1172 Layer::CalculateContentsScale(ideal_contents_scale, | |
| 1173 contents_scale_x, | |
| 1174 contents_scale_y, | |
| 1175 contentBounds); | |
| 1176 } | |
| 1177 | |
| 1178 private: | |
| 1179 explicit NoScaleContentLayer(ContentLayerClient* client) | |
| 1180 : ContentLayer(client) {} | |
| 1181 ~NoScaleContentLayer() override {} | |
| 1182 }; | |
| 1183 | |
| 1184 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers | 1198 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| 1185 : public LayerTreeHostTest { | 1199 : public LayerTreeHostTest { |
| 1186 public: | 1200 public: |
| 1187 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() | 1201 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() {} |
| 1188 : root_layer_(NoScaleContentLayer::Create(&client_)), | 1202 |
| 1189 child_layer_(ContentLayer::Create(&client_)) {} | 1203 void InitializeSettings(LayerTreeSettings* settings) override { |
| 1204 // PictureLayer can only be used with impl side painting enabled. |
| 1205 settings->impl_side_painting = true; |
| 1206 } |
| 1190 | 1207 |
| 1191 void BeginTest() override { | 1208 void BeginTest() override { |
| 1209 client_.set_fill_with_nonsolid_color(true); |
| 1210 root_layer_ = FakePictureLayer::Create(&client_); |
| 1211 child_layer_ = FakePictureLayer::Create(&client_); |
| 1212 |
| 1192 layer_tree_host()->SetViewportSize(gfx::Size(60, 60)); | 1213 layer_tree_host()->SetViewportSize(gfx::Size(60, 60)); |
| 1193 layer_tree_host()->SetDeviceScaleFactor(1.5); | 1214 layer_tree_host()->SetDeviceScaleFactor(1.5); |
| 1194 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); | 1215 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); |
| 1195 | 1216 |
| 1196 root_layer_->AddChild(child_layer_); | 1217 root_layer_->AddChild(child_layer_); |
| 1197 | 1218 |
| 1198 root_layer_->SetIsDrawable(true); | 1219 root_layer_->SetIsDrawable(true); |
| 1199 root_layer_->SetBounds(gfx::Size(30, 30)); | 1220 root_layer_->SetBounds(gfx::Size(30, 30)); |
| 1200 | 1221 |
| 1201 child_layer_->SetIsDrawable(true); | 1222 child_layer_->SetIsDrawable(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1212 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); | 1233 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
| 1213 // Device scale factor should come over to impl. | 1234 // Device scale factor should come over to impl. |
| 1214 EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f); | 1235 EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f); |
| 1215 | 1236 |
| 1216 // Both layers are on impl. | 1237 // Both layers are on impl. |
| 1217 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); | 1238 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); |
| 1218 | 1239 |
| 1219 // Device viewport is scaled. | 1240 // Device viewport is scaled. |
| 1220 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); | 1241 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); |
| 1221 | 1242 |
| 1222 LayerImpl* root = impl->active_tree()->root_layer(); | 1243 FakePictureLayerImpl* root = |
| 1223 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; | 1244 static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer()); |
| 1245 FakePictureLayerImpl* child = static_cast<FakePictureLayerImpl*>( |
| 1246 impl->active_tree()->root_layer()->children()[0]); |
| 1224 | 1247 |
| 1225 // Positions remain in layout pixels. | 1248 // Positions remain in layout pixels. |
| 1226 EXPECT_EQ(gfx::Point(0, 0), root->position()); | 1249 EXPECT_EQ(gfx::Point(0, 0), root->position()); |
| 1227 EXPECT_EQ(gfx::Point(2, 2), child->position()); | 1250 EXPECT_EQ(gfx::Point(2, 2), child->position()); |
| 1228 | 1251 |
| 1229 // Compute all the layer transforms for the frame. | 1252 // Compute all the layer transforms for the frame. |
| 1230 LayerTreeHostImpl::FrameData frame_data; | 1253 LayerTreeHostImpl::FrameData frame_data; |
| 1231 impl->PrepareToDraw(&frame_data); | 1254 impl->PrepareToDraw(&frame_data); |
| 1232 impl->DidDrawAllLayers(frame_data); | 1255 impl->DidDrawAllLayers(frame_data); |
| 1233 | 1256 |
| 1234 const LayerImplList& render_surface_layer_list = | 1257 const LayerImplList& render_surface_layer_list = |
| 1235 *frame_data.render_surface_layer_list; | 1258 *frame_data.render_surface_layer_list; |
| 1236 | 1259 |
| 1237 // Both layers should be drawing into the root render surface. | 1260 // Both layers should be drawing into the root render surface. |
| 1238 ASSERT_EQ(1u, render_surface_layer_list.size()); | 1261 ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 1239 ASSERT_EQ(root->render_surface(), | 1262 ASSERT_EQ(root->render_surface(), |
| 1240 render_surface_layer_list[0]->render_surface()); | 1263 render_surface_layer_list[0]->render_surface()); |
| 1241 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 1264 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 1242 | 1265 |
| 1243 // The root render surface is the size of the viewport. | 1266 // The root render surface is the size of the viewport. |
| 1244 EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), | 1267 EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), |
| 1245 root->render_surface()->content_rect()); | 1268 root->render_surface()->content_rect()); |
| 1246 | 1269 |
| 1247 // The content bounds of the child should be scaled. | 1270 // The max tiling scale of the child should be scaled. |
| 1248 gfx::Size child_bounds_scaled = | 1271 EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); |
| 1249 gfx::ToCeiledSize(gfx::ScaleSize(child->bounds(), 1.5)); | |
| 1250 EXPECT_EQ(child_bounds_scaled, child->content_bounds()); | |
| 1251 | 1272 |
| 1252 gfx::Transform scale_transform; | 1273 gfx::Transform scale_transform; |
| 1253 scale_transform.Scale(impl->device_scale_factor(), | 1274 scale_transform.Scale(impl->device_scale_factor(), |
| 1254 impl->device_scale_factor()); | 1275 impl->device_scale_factor()); |
| 1255 | 1276 |
| 1256 // The root layer is scaled by 2x. | 1277 // The root layer is scaled by 2x. |
| 1257 gfx::Transform root_screen_space_transform = scale_transform; | 1278 gfx::Transform root_screen_space_transform = scale_transform; |
| 1258 gfx::Transform root_draw_transform = scale_transform; | 1279 gfx::Transform root_draw_transform = scale_transform; |
| 1259 | 1280 |
| 1260 EXPECT_EQ(root_draw_transform, root->draw_transform()); | 1281 EXPECT_EQ(root_draw_transform, root->draw_transform()); |
| 1261 EXPECT_EQ(root_screen_space_transform, root->screen_space_transform()); | 1282 EXPECT_EQ(root_screen_space_transform, root->screen_space_transform()); |
| 1262 | 1283 |
| 1263 // The child is at position 2,2, which is transformed to 3,3 after the scale | 1284 // The child is at position 2,2, which is transformed to 3,3 after the scale |
| 1264 gfx::Transform child_screen_space_transform; | 1285 gfx::Transform child_transform; |
| 1265 child_screen_space_transform.Translate(3.f, 3.f); | 1286 child_transform.Translate(3.f, 3.f); |
| 1266 gfx::Transform child_draw_transform = child_screen_space_transform; | 1287 child_transform.Scale(child->MaximumTilingContentsScale(), |
| 1288 child->MaximumTilingContentsScale()); |
| 1267 | 1289 |
| 1268 EXPECT_TRANSFORMATION_MATRIX_EQ(child_draw_transform, | 1290 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, child->draw_transform()); |
| 1269 child->draw_transform()); | 1291 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, |
| 1270 EXPECT_TRANSFORMATION_MATRIX_EQ(child_screen_space_transform, | |
| 1271 child->screen_space_transform()); | 1292 child->screen_space_transform()); |
| 1272 | 1293 |
| 1273 EndTest(); | 1294 EndTest(); |
| 1274 } | 1295 } |
| 1275 | 1296 |
| 1276 void AfterTest() override {} | 1297 void AfterTest() override {} |
| 1277 | 1298 |
| 1278 private: | 1299 private: |
| 1279 FakeContentLayerClient client_; | 1300 FakeContentLayerClient client_; |
| 1280 scoped_refptr<NoScaleContentLayer> root_layer_; | 1301 scoped_refptr<FakePictureLayer> root_layer_; |
| 1281 scoped_refptr<ContentLayer> child_layer_; | 1302 scoped_refptr<FakePictureLayer> child_layer_; |
| 1282 }; | 1303 }; |
| 1283 | 1304 |
| 1284 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); | 1305 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
| 1285 | 1306 |
| 1307 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| 1286 // Verify atomicity of commits and reuse of textures. | 1308 // Verify atomicity of commits and reuse of textures. |
| 1287 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { | 1309 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
| 1288 public: | 1310 public: |
| 1289 void InitializeSettings(LayerTreeSettings* settings) override { | 1311 void InitializeSettings(LayerTreeSettings* settings) override { |
| 1290 settings->texture_id_allocation_chunk_size = 1; | 1312 settings->texture_id_allocation_chunk_size = 1; |
| 1291 // Make sure partial texture updates are turned off. | 1313 // Make sure partial texture updates are turned off. |
| 1292 settings->max_partial_texture_updates = 0; | 1314 settings->max_partial_texture_updates = 0; |
| 1293 // Linear fade animator prevents scrollbars from drawing immediately. | 1315 // Linear fade animator prevents scrollbars from drawing immediately. |
| 1294 settings->scrollbar_animator = LayerTreeSettings::NoAnimator; | 1316 settings->scrollbar_animator = LayerTreeSettings::NoAnimator; |
| 1295 } | 1317 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 protected: | 1406 protected: |
| 1385 FakeContentLayerClient client_; | 1407 FakeContentLayerClient client_; |
| 1386 scoped_refptr<FakeContentLayer> layer_; | 1408 scoped_refptr<FakeContentLayer> layer_; |
| 1387 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; | 1409 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; |
| 1388 int drew_frame_; | 1410 int drew_frame_; |
| 1389 }; | 1411 }; |
| 1390 | 1412 |
| 1391 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 1413 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
| 1392 LayerTreeHostTestDirectRendererAtomicCommit); | 1414 LayerTreeHostTestDirectRendererAtomicCommit); |
| 1393 | 1415 |
| 1416 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| 1394 class LayerTreeHostTestDelegatingRendererAtomicCommit | 1417 class LayerTreeHostTestDelegatingRendererAtomicCommit |
| 1395 : public LayerTreeHostTestDirectRendererAtomicCommit { | 1418 : public LayerTreeHostTestDirectRendererAtomicCommit { |
| 1396 public: | 1419 public: |
| 1397 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1420 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 1398 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); | 1421 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); |
| 1399 | 1422 |
| 1400 TestWebGraphicsContext3D* context = TestContext(); | 1423 TestWebGraphicsContext3D* context = TestContext(); |
| 1401 | 1424 |
| 1402 switch (impl->active_tree()->source_frame_number()) { | 1425 switch (impl->active_tree()->source_frame_number()) { |
| 1403 case 0: | 1426 case 0: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 layer->RemoveAllChildren(); | 1474 layer->RemoveAllChildren(); |
| 1452 if (parent) | 1475 if (parent) |
| 1453 parent->AddChild(layer); | 1476 parent->AddChild(layer); |
| 1454 layer->SetTransform(transform); | 1477 layer->SetTransform(transform); |
| 1455 layer->SetTransformOrigin(transform_origin); | 1478 layer->SetTransformOrigin(transform_origin); |
| 1456 layer->SetPosition(position); | 1479 layer->SetPosition(position); |
| 1457 layer->SetBounds(bounds); | 1480 layer->SetBounds(bounds); |
| 1458 layer->SetContentsOpaque(opaque); | 1481 layer->SetContentsOpaque(opaque); |
| 1459 } | 1482 } |
| 1460 | 1483 |
| 1484 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| 1461 class LayerTreeHostTestAtomicCommitWithPartialUpdate | 1485 class LayerTreeHostTestAtomicCommitWithPartialUpdate |
| 1462 : public LayerTreeHostTest { | 1486 : public LayerTreeHostTest { |
| 1463 public: | 1487 public: |
| 1464 void InitializeSettings(LayerTreeSettings* settings) override { | 1488 void InitializeSettings(LayerTreeSettings* settings) override { |
| 1465 settings->texture_id_allocation_chunk_size = 1; | 1489 settings->texture_id_allocation_chunk_size = 1; |
| 1466 // Allow one partial texture update. | 1490 // Allow one partial texture update. |
| 1467 settings->max_partial_texture_updates = 1; | 1491 settings->max_partial_texture_updates = 1; |
| 1468 // No partial updates when impl side painting is enabled. | 1492 // No partial updates when impl side painting is enabled. |
| 1469 settings->impl_side_painting = false; | 1493 settings->impl_side_painting = false; |
| 1470 } | 1494 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 private: | 1648 private: |
| 1625 FakeContentLayerClient client_; | 1649 FakeContentLayerClient client_; |
| 1626 scoped_refptr<FakeContentLayer> parent_; | 1650 scoped_refptr<FakeContentLayer> parent_; |
| 1627 scoped_refptr<FakeContentLayer> child_; | 1651 scoped_refptr<FakeContentLayer> child_; |
| 1628 }; | 1652 }; |
| 1629 | 1653 |
| 1630 // Partial updates are not possible with a delegating renderer. | 1654 // Partial updates are not possible with a delegating renderer. |
| 1631 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1655 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1632 LayerTreeHostTestAtomicCommitWithPartialUpdate); | 1656 LayerTreeHostTestAtomicCommitWithPartialUpdate); |
| 1633 | 1657 |
| 1658 // TODO(sohanjg) : Make it work with impl-side painting. |
| 1634 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit | 1659 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit |
| 1635 : public LayerTreeHostTest { | 1660 : public LayerTreeHostTest { |
| 1636 protected: | 1661 protected: |
| 1637 void SetupTree() override { | 1662 void SetupTree() override { |
| 1638 root_layer_ = FakeContentLayer::Create(&client_); | 1663 root_layer_ = FakeContentLayer::Create(&client_); |
| 1639 root_layer_->SetBounds(gfx::Size(100, 100)); | 1664 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 1640 | 1665 |
| 1641 surface_layer1_ = FakeContentLayer::Create(&client_); | 1666 surface_layer1_ = FakeContentLayer::Create(&client_); |
| 1642 surface_layer1_->SetBounds(gfx::Size(100, 100)); | 1667 surface_layer1_->SetBounds(gfx::Size(100, 100)); |
| 1643 surface_layer1_->SetForceRenderSurface(true); | 1668 surface_layer1_->SetForceRenderSurface(true); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 | 1969 |
| 1945 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { | 1970 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| 1946 public: | 1971 public: |
| 1947 LayerTreeHostTestContinuousInvalidate() | 1972 LayerTreeHostTestContinuousInvalidate() |
| 1948 : num_commit_complete_(0), num_draw_layers_(0) {} | 1973 : num_commit_complete_(0), num_draw_layers_(0) {} |
| 1949 | 1974 |
| 1950 void BeginTest() override { | 1975 void BeginTest() override { |
| 1951 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | 1976 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
| 1952 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | 1977 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| 1953 | 1978 |
| 1954 content_layer_ = ContentLayer::Create(&client_); | 1979 if (layer_tree_host()->settings().impl_side_painting) |
| 1955 content_layer_->SetBounds(gfx::Size(10, 10)); | 1980 layer_ = FakePictureLayer::Create(&client_); |
| 1956 content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); | 1981 else |
| 1957 content_layer_->SetIsDrawable(true); | 1982 layer_ = FakeContentLayer::Create(&client_); |
| 1958 layer_tree_host()->root_layer()->AddChild(content_layer_); | 1983 |
| 1984 layer_->SetBounds(gfx::Size(10, 10)); |
| 1985 layer_->SetPosition(gfx::PointF(0.f, 0.f)); |
| 1986 layer_->SetIsDrawable(true); |
| 1987 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1959 | 1988 |
| 1960 PostSetNeedsCommitToMainThread(); | 1989 PostSetNeedsCommitToMainThread(); |
| 1961 } | 1990 } |
| 1962 | 1991 |
| 1963 void DidCommitAndDrawFrame() override { | 1992 void DidCommitAndDrawFrame() override { |
| 1964 if (num_draw_layers_ == 2) | 1993 if (num_draw_layers_ == 2) |
| 1965 return; | 1994 return; |
| 1966 content_layer_->SetNeedsDisplay(); | 1995 layer_->SetNeedsDisplay(); |
| 1967 } | 1996 } |
| 1968 | 1997 |
| 1969 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 1998 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| 1970 if (num_draw_layers_ == 1) | 1999 if (num_draw_layers_ == 1) |
| 1971 num_commit_complete_++; | 2000 num_commit_complete_++; |
| 1972 } | 2001 } |
| 1973 | 2002 |
| 1974 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 2003 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 1975 num_draw_layers_++; | 2004 num_draw_layers_++; |
| 1976 if (num_draw_layers_ == 2) | 2005 if (num_draw_layers_ == 2) |
| 1977 EndTest(); | 2006 EndTest(); |
| 1978 } | 2007 } |
| 1979 | 2008 |
| 1980 void AfterTest() override { | 2009 void AfterTest() override { |
| 1981 // Check that we didn't commit twice between first and second draw. | 2010 // Check that we didn't commit twice between first and second draw. |
| 1982 EXPECT_EQ(1, num_commit_complete_); | 2011 EXPECT_EQ(1, num_commit_complete_); |
| 1983 } | 2012 } |
| 1984 | 2013 |
| 1985 private: | 2014 private: |
| 1986 FakeContentLayerClient client_; | 2015 FakeContentLayerClient client_; |
| 1987 scoped_refptr<Layer> content_layer_; | 2016 scoped_refptr<Layer> layer_; |
| 1988 int num_commit_complete_; | 2017 int num_commit_complete_; |
| 1989 int num_draw_layers_; | 2018 int num_draw_layers_; |
| 1990 }; | 2019 }; |
| 1991 | 2020 |
| 1992 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestContinuousInvalidate); | 2021 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| 1993 | 2022 |
| 1994 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { | 2023 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { |
| 1995 public: | 2024 public: |
| 1996 LayerTreeHostTestDeferCommits() | 2025 LayerTreeHostTestDeferCommits() |
| 1997 : num_commits_deferred_(0), num_complete_commits_(0) {} | 2026 : num_commits_deferred_(0), num_complete_commits_(0) {} |
| 1998 | 2027 |
| 1999 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2028 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 2000 | 2029 |
| 2001 void DidDeferCommit() override { | 2030 void DidDeferCommit() override { |
| 2002 num_commits_deferred_++; | 2031 num_commits_deferred_++; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 NULL, | 2214 NULL, |
| 2186 settings, | 2215 settings, |
| 2187 base::MessageLoopProxy::current(), | 2216 base::MessageLoopProxy::current(), |
| 2188 nullptr); | 2217 nullptr); |
| 2189 client.SetLayerTreeHost(host.get()); | 2218 client.SetLayerTreeHost(host.get()); |
| 2190 host->Composite(base::TimeTicks::Now()); | 2219 host->Composite(base::TimeTicks::Now()); |
| 2191 | 2220 |
| 2192 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); | 2221 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); |
| 2193 } | 2222 } |
| 2194 | 2223 |
| 2224 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| 2195 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted | 2225 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted |
| 2196 : public LayerTreeHostTest { | 2226 : public LayerTreeHostTest { |
| 2197 public: | 2227 public: |
| 2198 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted() | 2228 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted() |
| 2199 : root_layer_(FakeContentLayer::Create(&client_)), | 2229 : root_layer_(FakeContentLayer::Create(&client_)), |
| 2200 child_layer1_(FakeContentLayer::Create(&client_)), | 2230 child_layer1_(FakeContentLayer::Create(&client_)), |
| 2201 child_layer2_(FakeContentLayer::Create(&client_)), | 2231 child_layer2_(FakeContentLayer::Create(&client_)), |
| 2202 num_commits_(0) {} | 2232 num_commits_(0) {} |
| 2203 | 2233 |
| 2204 void BeginTest() override { | 2234 void BeginTest() override { |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2589 SINGLE_AND_MULTI_THREAD_TEST_F( | 2619 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 2590 LayerTreeHostTestChangeLayerPropertiesInPaintContents); | 2620 LayerTreeHostTestChangeLayerPropertiesInPaintContents); |
| 2591 | 2621 |
| 2592 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { | 2622 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { |
| 2593 public: | 2623 public: |
| 2594 MockIOSurfaceWebGraphicsContext3D() { | 2624 MockIOSurfaceWebGraphicsContext3D() { |
| 2595 test_capabilities_.gpu.iosurface = true; | 2625 test_capabilities_.gpu.iosurface = true; |
| 2596 test_capabilities_.gpu.texture_rectangle = true; | 2626 test_capabilities_.gpu.texture_rectangle = true; |
| 2597 } | 2627 } |
| 2598 | 2628 |
| 2599 virtual GLuint createTexture() override { | 2629 GLuint createTexture() override { return 1; } |
| 2600 return 1; | |
| 2601 } | |
| 2602 MOCK_METHOD1(activeTexture, void(GLenum texture)); | 2630 MOCK_METHOD1(activeTexture, void(GLenum texture)); |
| 2603 MOCK_METHOD2(bindTexture, void(GLenum target, | 2631 MOCK_METHOD2(bindTexture, void(GLenum target, |
| 2604 GLuint texture_id)); | 2632 GLuint texture_id)); |
| 2605 MOCK_METHOD3(texParameteri, void(GLenum target, | 2633 MOCK_METHOD3(texParameteri, void(GLenum target, |
| 2606 GLenum pname, | 2634 GLenum pname, |
| 2607 GLint param)); | 2635 GLint param)); |
| 2608 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target, | 2636 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target, |
| 2609 GLint width, | 2637 GLint width, |
| 2610 GLint height, | 2638 GLint height, |
| 2611 GLuint ioSurfaceId, | 2639 GLuint ioSurfaceId, |
| (...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4475 output_surface->SetMemoryPolicyToSetAtBind( | 4503 output_surface->SetMemoryPolicyToSetAtBind( |
| 4476 make_scoped_ptr(new ManagedMemoryPolicy( | 4504 make_scoped_ptr(new ManagedMemoryPolicy( |
| 4477 second_context_provider_.get() ? second_output_surface_memory_limit_ | 4505 second_context_provider_.get() ? second_output_surface_memory_limit_ |
| 4478 : first_output_surface_memory_limit_, | 4506 : first_output_surface_memory_limit_, |
| 4479 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, | 4507 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, |
| 4480 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); | 4508 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); |
| 4481 return output_surface.Pass(); | 4509 return output_surface.Pass(); |
| 4482 } | 4510 } |
| 4483 | 4511 |
| 4484 void SetupTree() override { | 4512 void SetupTree() override { |
| 4485 root_ = FakeContentLayer::Create(&client_); | 4513 if (layer_tree_host()->settings().impl_side_painting) |
| 4514 root_ = FakePictureLayer::Create(&client_); |
| 4515 else |
| 4516 root_ = FakeContentLayer::Create(&client_); |
| 4486 root_->SetBounds(gfx::Size(20, 20)); | 4517 root_->SetBounds(gfx::Size(20, 20)); |
| 4487 layer_tree_host()->SetRootLayer(root_); | 4518 layer_tree_host()->SetRootLayer(root_); |
| 4488 LayerTreeHostTest::SetupTree(); | 4519 LayerTreeHostTest::SetupTree(); |
| 4489 } | 4520 } |
| 4490 | 4521 |
| 4491 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 4522 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 4492 | 4523 |
| 4493 void DidCommitAndDrawFrame() override { | 4524 void DidCommitAndDrawFrame() override { |
| 4494 // Lost context sometimes takes two frames to recreate. The third frame | 4525 // Lost context sometimes takes two frames to recreate. The third frame |
| 4495 // is sometimes aborted, so wait until the fourth frame to verify that | 4526 // is sometimes aborted, so wait until the fourth frame to verify that |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4517 } | 4548 } |
| 4518 } | 4549 } |
| 4519 | 4550 |
| 4520 void AfterTest() override {} | 4551 void AfterTest() override {} |
| 4521 | 4552 |
| 4522 scoped_refptr<TestContextProvider> first_context_provider_; | 4553 scoped_refptr<TestContextProvider> first_context_provider_; |
| 4523 scoped_refptr<TestContextProvider> second_context_provider_; | 4554 scoped_refptr<TestContextProvider> second_context_provider_; |
| 4524 size_t first_output_surface_memory_limit_; | 4555 size_t first_output_surface_memory_limit_; |
| 4525 size_t second_output_surface_memory_limit_; | 4556 size_t second_output_surface_memory_limit_; |
| 4526 FakeContentLayerClient client_; | 4557 FakeContentLayerClient client_; |
| 4527 scoped_refptr<FakeContentLayer> root_; | 4558 scoped_refptr<Layer> root_; |
| 4528 }; | 4559 }; |
| 4529 | 4560 |
| 4530 // No output to copy for delegated renderers. | |
| 4531 SINGLE_AND_MULTI_THREAD_TEST_F( | 4561 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 4532 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); | 4562 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |
| 4533 | 4563 |
| 4534 struct TestSwapPromiseResult { | 4564 struct TestSwapPromiseResult { |
| 4535 TestSwapPromiseResult() | 4565 TestSwapPromiseResult() |
| 4536 : did_swap_called(false), | 4566 : did_swap_called(false), |
| 4537 did_not_swap_called(false), | 4567 did_not_swap_called(false), |
| 4538 dtor_called(false), | 4568 dtor_called(false), |
| 4539 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) {} | 4569 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) {} |
| 4540 | 4570 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4993 void InitializeSettings(LayerTreeSettings* settings) override { | 5023 void InitializeSettings(LayerTreeSettings* settings) override { |
| 4994 settings->impl_side_painting = true; | 5024 settings->impl_side_painting = true; |
| 4995 | 5025 |
| 4996 EXPECT_FALSE(settings->gpu_rasterization_forced); | 5026 EXPECT_FALSE(settings->gpu_rasterization_forced); |
| 4997 settings->gpu_rasterization_forced = true; | 5027 settings->gpu_rasterization_forced = true; |
| 4998 } | 5028 } |
| 4999 | 5029 |
| 5000 void SetupTree() override { | 5030 void SetupTree() override { |
| 5001 LayerTreeHostTest::SetupTree(); | 5031 LayerTreeHostTest::SetupTree(); |
| 5002 | 5032 |
| 5003 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_); | 5033 scoped_refptr<FakePictureLayer> layer = |
| 5034 FakePictureLayer::Create(&layer_client_); |
| 5004 layer->SetBounds(gfx::Size(10, 10)); | 5035 layer->SetBounds(gfx::Size(10, 10)); |
| 5005 layer->SetIsDrawable(true); | 5036 layer->SetIsDrawable(true); |
| 5006 layer_tree_host()->root_layer()->AddChild(layer); | 5037 layer_tree_host()->root_layer()->AddChild(layer); |
| 5007 } | 5038 } |
| 5008 | 5039 |
| 5009 void BeginTest() override { | 5040 void BeginTest() override { |
| 5010 Layer* root = layer_tree_host()->root_layer(); | 5041 Layer* root = layer_tree_host()->root_layer(); |
| 5011 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); | 5042 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); |
| 5012 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); | 5043 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
| 5013 | 5044 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5323 | 5354 |
| 5324 void AfterTest() override { | 5355 void AfterTest() override { |
| 5325 EXPECT_TRUE(deltas_sent_to_client_); | 5356 EXPECT_TRUE(deltas_sent_to_client_); |
| 5326 } | 5357 } |
| 5327 | 5358 |
| 5328 ScrollAndScaleSet info_; | 5359 ScrollAndScaleSet info_; |
| 5329 bool deltas_sent_to_client_; | 5360 bool deltas_sent_to_client_; |
| 5330 }; | 5361 }; |
| 5331 | 5362 |
| 5332 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); | 5363 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); |
| 5364 |
| 5365 class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest { |
| 5366 protected: |
| 5367 LayerTreeHostTestCrispUpAfterPinchEnds() |
| 5368 : playback_allowed_event_(true, true) {} |
| 5369 |
| 5370 void InitializeSettings(LayerTreeSettings* settings) override { |
| 5371 settings->impl_side_painting = true; |
| 5372 } |
| 5373 |
| 5374 void SetupTree() override { |
| 5375 frame_ = 1; |
| 5376 posted_ = false; |
| 5377 client_.set_fill_with_nonsolid_color(true); |
| 5378 |
| 5379 scoped_refptr<Layer> root = Layer::Create(); |
| 5380 root->SetBounds(gfx::Size(500, 500)); |
| 5381 |
| 5382 scoped_refptr<Layer> pinch = Layer::Create(); |
| 5383 pinch->SetBounds(gfx::Size(500, 500)); |
| 5384 pinch->SetScrollClipLayerId(root->id()); |
| 5385 pinch->SetIsContainerForFixedPositionLayers(true); |
| 5386 root->AddChild(pinch); |
| 5387 |
| 5388 scoped_ptr<FakePicturePile> pile(new FakePicturePile); |
| 5389 pile->SetPlaybackAllowedEvent(&playback_allowed_event_); |
| 5390 scoped_refptr<FakePictureLayer> layer = |
| 5391 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
| 5392 layer->SetBounds(gfx::Size(500, 500)); |
| 5393 layer->SetContentsOpaque(true); |
| 5394 pinch->AddChild(layer); |
| 5395 |
| 5396 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch); |
| 5397 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); |
| 5398 layer_tree_host()->SetRootLayer(root); |
| 5399 LayerTreeHostTest::SetupTree(); |
| 5400 } |
| 5401 |
| 5402 // Returns the delta scale of all quads in the frame's root pass from their |
| 5403 // ideal, or 0 if they are not all the same. |
| 5404 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) { |
| 5405 if (frame_data->has_no_damage) |
| 5406 return 0.f; |
| 5407 float frame_scale = 0.f; |
| 5408 RenderPass* root_pass = frame_data->render_passes.back(); |
| 5409 for (const auto& draw_quad : root_pass->quad_list) { |
| 5410 // Checkerboards mean an incomplete frame. |
| 5411 if (draw_quad->material != DrawQuad::TILED_CONTENT) |
| 5412 return 0.f; |
| 5413 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad); |
| 5414 float quad_scale = |
| 5415 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width()); |
| 5416 float transform_scale = |
| 5417 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0)); |
| 5418 float scale = quad_scale / transform_scale; |
| 5419 if (frame_scale != 0.f && frame_scale != scale) |
| 5420 return 0.f; |
| 5421 frame_scale = scale; |
| 5422 } |
| 5423 return frame_scale; |
| 5424 } |
| 5425 |
| 5426 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 5427 |
| 5428 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 5429 LayerTreeHostImpl::FrameData* frame_data, |
| 5430 DrawResult draw_result) override { |
| 5431 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data); |
| 5432 switch (frame_) { |
| 5433 case 1: |
| 5434 // Drew at page scale 1 before any pinching. |
| 5435 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); |
| 5436 EXPECT_EQ(1.f, quad_scale_delta); |
| 5437 PostNextAfterDraw(host_impl); |
| 5438 break; |
| 5439 case 2: |
| 5440 if (quad_scale_delta != 1.f) |
| 5441 break; |
| 5442 // Drew at page scale 2.2 after pinching in. |
| 5443 EXPECT_EQ(2.2f, host_impl->active_tree()->total_page_scale_factor()); |
| 5444 EXPECT_EQ(1.f, quad_scale_delta); |
| 5445 PostNextAfterDraw(host_impl); |
| 5446 break; |
| 5447 case 3: |
| 5448 if (quad_scale_delta != 2.2f) |
| 5449 break; |
| 5450 // Drew at page scale 1 with the 2.2 tiling while pinching out. |
| 5451 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); |
| 5452 EXPECT_EQ(2.2f, quad_scale_delta); |
| 5453 PostNextAfterDraw(host_impl); |
| 5454 break; |
| 5455 case 4: |
| 5456 // Drew at page scale 1 with the 2.2 tiling after pinching out completed |
| 5457 // while waiting for texture uploads to complete. |
| 5458 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); |
| 5459 // This frame will not have any damage, since it's actually the same as |
| 5460 // the last frame, and should contain no incomplete tiles. We just want |
| 5461 // to make sure we drew here at least once after the pinch ended to be |
| 5462 // sure that drawing after pinch doesn't leave us at the wrong scale |
| 5463 // forever. |
| 5464 EXPECT_TRUE(frame_data->has_no_damage); |
| 5465 PostNextAfterDraw(host_impl); |
| 5466 break; |
| 5467 case 5: |
| 5468 if (quad_scale_delta != 1.f) |
| 5469 break; |
| 5470 // Drew at scale 1 after texture uploads are done. |
| 5471 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); |
| 5472 EXPECT_EQ(1.f, quad_scale_delta); |
| 5473 EndTest(); |
| 5474 break; |
| 5475 } |
| 5476 return draw_result; |
| 5477 } |
| 5478 |
| 5479 void PostNextAfterDraw(LayerTreeHostImpl* host_impl) { |
| 5480 if (posted_) |
| 5481 return; |
| 5482 posted_ = true; |
| 5483 ImplThreadTaskRunner()->PostDelayedTask( |
| 5484 FROM_HERE, base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next, |
| 5485 base::Unretained(this), host_impl), |
| 5486 // Use a delay to allow raster/upload to happen in between frames. This |
| 5487 // should cause flakiness if we fail to block raster/upload when |
| 5488 // desired. |
| 5489 base::TimeDelta::FromMilliseconds(16 * 6)); |
| 5490 } |
| 5491 |
| 5492 void Next(LayerTreeHostImpl* host_impl) { |
| 5493 ++frame_; |
| 5494 posted_ = false; |
| 5495 switch (frame_) { |
| 5496 case 2: |
| 5497 // Pinch zoom in. |
| 5498 host_impl->PinchGestureBegin(); |
| 5499 host_impl->PinchGestureUpdate(2.2f, gfx::Point(100, 100)); |
| 5500 host_impl->PinchGestureEnd(); |
| 5501 break; |
| 5502 case 3: |
| 5503 // Pinch zoom back to 1.f but don't end it. |
| 5504 host_impl->PinchGestureBegin(); |
| 5505 host_impl->PinchGestureUpdate(1.f / 2.2f, gfx::Point(100, 100)); |
| 5506 break; |
| 5507 case 4: |
| 5508 // End the pinch, but delay tile production. |
| 5509 playback_allowed_event_.Reset(); |
| 5510 host_impl->PinchGestureEnd(); |
| 5511 break; |
| 5512 case 5: |
| 5513 // Let tiles complete. |
| 5514 playback_allowed_event_.Signal(); |
| 5515 break; |
| 5516 } |
| 5517 } |
| 5518 |
| 5519 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |
| 5520 const Tile* tile) override { |
| 5521 // On frame_ == 4, we are preventing texture uploads from completing, |
| 5522 // so this verifies they are not completing before frame_ == 5. |
| 5523 // Flaky failures here indicate we're failing to prevent uploads from |
| 5524 // completing. |
| 5525 EXPECT_NE(4, frame_); |
| 5526 } |
| 5527 |
| 5528 void AfterTest() override {} |
| 5529 |
| 5530 FakeContentLayerClient client_; |
| 5531 int frame_; |
| 5532 bool posted_; |
| 5533 base::WaitableEvent playback_allowed_event_; |
| 5534 }; |
| 5535 |
| 5536 // TODO(danakj): Disabled for flake: crbug.com/433208 |
| 5537 // MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds); |
| 5538 |
| 5539 class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy |
| 5540 : public LayerTreeHostTestCrispUpAfterPinchEnds { |
| 5541 protected: |
| 5542 void InitializeSettings(LayerTreeSettings* settings) override { |
| 5543 settings->impl_side_painting = true; |
| 5544 settings->use_one_copy = true; |
| 5545 } |
| 5546 |
| 5547 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface( |
| 5548 bool fallback) override { |
| 5549 scoped_ptr<TestWebGraphicsContext3D> context3d = |
| 5550 TestWebGraphicsContext3D::Create(); |
| 5551 context3d->set_support_image(true); |
| 5552 context3d->set_support_sync_query(true); |
| 5553 |
| 5554 if (delegating_renderer()) |
| 5555 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); |
| 5556 else |
| 5557 return FakeOutputSurface::Create3d(context3d.Pass()); |
| 5558 } |
| 5559 }; |
| 5560 |
| 5561 // TODO(danakj): Disabled for flake: crbug.com/433208 |
| 5562 #if !defined(OS_LINUX) || defined(NDEBUG) |
| 5563 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy); |
| 5564 #endif |
| 5565 |
| 5566 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles |
| 5567 : public LayerTreeHostTest { |
| 5568 protected: |
| 5569 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles() |
| 5570 : playback_allowed_event_(true, true) {} |
| 5571 |
| 5572 void InitializeSettings(LayerTreeSettings* settings) override { |
| 5573 settings->impl_side_painting = true; |
| 5574 } |
| 5575 |
| 5576 void SetupTree() override { |
| 5577 step_ = 1; |
| 5578 continuous_draws_ = 0; |
| 5579 client_.set_fill_with_nonsolid_color(true); |
| 5580 |
| 5581 scoped_refptr<Layer> root = Layer::Create(); |
| 5582 root->SetBounds(gfx::Size(500, 500)); |
| 5583 |
| 5584 scoped_refptr<Layer> pinch = Layer::Create(); |
| 5585 pinch->SetBounds(gfx::Size(500, 500)); |
| 5586 pinch->SetScrollClipLayerId(root->id()); |
| 5587 pinch->SetIsContainerForFixedPositionLayers(true); |
| 5588 root->AddChild(pinch); |
| 5589 |
| 5590 scoped_ptr<FakePicturePile> pile(new FakePicturePile); |
| 5591 pile->SetPlaybackAllowedEvent(&playback_allowed_event_); |
| 5592 scoped_refptr<FakePictureLayer> layer = |
| 5593 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
| 5594 layer->SetBounds(gfx::Size(500, 500)); |
| 5595 layer->SetContentsOpaque(true); |
| 5596 pinch->AddChild(layer); |
| 5597 |
| 5598 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch); |
| 5599 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); |
| 5600 layer_tree_host()->SetRootLayer(root); |
| 5601 LayerTreeHostTest::SetupTree(); |
| 5602 } |
| 5603 |
| 5604 // Returns the delta scale of all quads in the frame's root pass from their |
| 5605 // ideal, or 0 if they are not all the same. |
| 5606 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) { |
| 5607 if (frame_data->has_no_damage) |
| 5608 return 0.f; |
| 5609 float frame_scale = 0.f; |
| 5610 RenderPass* root_pass = frame_data->render_passes.back(); |
| 5611 for (const auto& draw_quad : root_pass->quad_list) { |
| 5612 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad); |
| 5613 float quad_scale = |
| 5614 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width()); |
| 5615 float transform_scale = |
| 5616 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0)); |
| 5617 float scale = quad_scale / transform_scale; |
| 5618 if (frame_scale != 0.f && frame_scale != scale) |
| 5619 return 0.f; |
| 5620 frame_scale = scale; |
| 5621 } |
| 5622 return frame_scale; |
| 5623 } |
| 5624 |
| 5625 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 5626 |
| 5627 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 5628 LayerTreeHostImpl::FrameData* frame_data, |
| 5629 DrawResult draw_result) override { |
| 5630 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data); |
| 5631 switch (step_) { |
| 5632 case 1: |
| 5633 // Drew at scale 1 before any pinching. |
| 5634 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); |
| 5635 EXPECT_EQ(1.f, quad_scale_delta); |
| 5636 break; |
| 5637 case 2: |
| 5638 if (quad_scale_delta != 1.f / 1.5f) |
| 5639 break; |
| 5640 // Drew at scale 1 still though the ideal is 1.5. |
| 5641 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); |
| 5642 EXPECT_EQ(1.f / 1.5f, quad_scale_delta); |
| 5643 break; |
| 5644 case 3: |
| 5645 // Continuous draws are attempted. |
| 5646 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); |
| 5647 if (!frame_data->has_no_damage) |
| 5648 EXPECT_EQ(1.f / 1.5f, quad_scale_delta); |
| 5649 break; |
| 5650 case 4: |
| 5651 if (quad_scale_delta != 1.f) |
| 5652 break; |
| 5653 // Drew at scale 1.5 when all the tiles completed. |
| 5654 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); |
| 5655 EXPECT_EQ(1.f, quad_scale_delta); |
| 5656 |
| 5657 // We should not continue to draw any more. End the test after a timeout |
| 5658 // to watch for any extraneous draws. |
| 5659 // TODO(brianderson): We could remove this delay and instead wait until |
| 5660 // the BeginFrameSource decides it doesn't need to send frames anymore, |
| 5661 // or test that it already doesn't here. |
| 5662 EndTestAfterDelayMs(16 * 4); |
| 5663 ++step_; |
| 5664 break; |
| 5665 case 5: |
| 5666 ADD_FAILURE() |
| 5667 << "No draws should happen once we have a complete frame."; |
| 5668 break; |
| 5669 } |
| 5670 return draw_result; |
| 5671 } |
| 5672 |
| 5673 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 5674 switch (step_) { |
| 5675 case 1: |
| 5676 // Delay tile production. |
| 5677 playback_allowed_event_.Reset(); |
| 5678 // Pinch zoom in to cause new tiles to be required. |
| 5679 host_impl->PinchGestureBegin(); |
| 5680 host_impl->PinchGestureUpdate(1.5f, gfx::Point(100, 100)); |
| 5681 host_impl->PinchGestureEnd(); |
| 5682 ++step_; |
| 5683 break; |
| 5684 case 2: |
| 5685 ++step_; |
| 5686 break; |
| 5687 case 3: |
| 5688 // We should continue to try draw while there are incomplete visible |
| 5689 // tiles. |
| 5690 if (++continuous_draws_ > 5) { |
| 5691 // Allow the tiles to complete. |
| 5692 playback_allowed_event_.Signal(); |
| 5693 ++step_; |
| 5694 } |
| 5695 break; |
| 5696 } |
| 5697 } |
| 5698 |
| 5699 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |
| 5700 const Tile* tile) override { |
| 5701 // On step_ == 2, we are preventing texture uploads from completing, |
| 5702 // so this verifies they are not completing before step_ == 3. |
| 5703 // Flaky failures here indicate we're failing to prevent uploads from |
| 5704 // completing. |
| 5705 EXPECT_NE(2, step_); |
| 5706 } |
| 5707 |
| 5708 void AfterTest() override { EXPECT_GT(continuous_draws_, 5); } |
| 5709 |
| 5710 FakeContentLayerClient client_; |
| 5711 int step_; |
| 5712 int continuous_draws_; |
| 5713 base::WaitableEvent playback_allowed_event_; |
| 5714 }; |
| 5715 |
| 5716 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); |
| 5717 |
| 5333 } // namespace cc | 5718 } // namespace cc |
| OLD | NEW |