OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "cc/test/fake_content_layer.h" | 12 #include "cc/test/fake_content_layer.h" |
13 #include "cc/test/fake_content_layer_client.h" | 13 #include "cc/test/fake_content_layer_client.h" |
14 #include "cc/test/fake_painted_scrollbar_layer.h" | 14 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 15 #include "cc/test/fake_picture_layer.h" |
15 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
16 #include "cc/trees/damage_tracker.h" | 17 #include "cc/trees/damage_tracker.h" |
17 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 namespace { | 21 namespace { |
21 | 22 |
22 // These tests deal with damage tracking. | 23 // These tests deal with damage tracking. |
23 class LayerTreeHostDamageTest : public LayerTreeTest {}; | 24 class LayerTreeHostDamageTest : public LayerTreeTest {}; |
24 | 25 |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 682 |
682 virtual void AfterTest() OVERRIDE { | 683 virtual void AfterTest() OVERRIDE { |
683 EXPECT_EQ(3, did_swaps_); | 684 EXPECT_EQ(3, did_swaps_); |
684 } | 685 } |
685 | 686 |
686 int did_swaps_; | 687 int did_swaps_; |
687 }; | 688 }; |
688 | 689 |
689 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 690 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
690 | 691 |
| 692 class LayerTreeHostDamageTestVisibleTilesStillTriggerDraws |
| 693 : public LayerTreeHostDamageTest { |
| 694 |
| 695 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 696 settings->impl_side_painting = true; |
| 697 } |
| 698 |
| 699 virtual void BeginTest() OVERRIDE { |
| 700 PostSetNeedsCommitToMainThread(); |
| 701 } |
| 702 |
| 703 virtual void SetupTree() OVERRIDE { |
| 704 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); |
| 705 root->SetBounds(gfx::Size(500, 500)); |
| 706 layer_tree_host()->SetRootLayer(root); |
| 707 LayerTreeHostDamageTest::SetupTree(); |
| 708 |
| 709 swap_count_ = 0; |
| 710 prepare_to_draw_count_ = 0; |
| 711 update_visible_tile_count_ = 0; |
| 712 } |
| 713 |
| 714 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 715 LayerTreeHostImpl::FrameData* frame_data, |
| 716 bool result) OVERRIDE { |
| 717 EXPECT_TRUE(result); |
| 718 prepare_to_draw_count_++; |
| 719 switch (prepare_to_draw_count_) { |
| 720 case 1: |
| 721 // Detect that we have an incomplete tile, during the first frame. |
| 722 // The first frame should have damage. |
| 723 frame_data->contains_incomplete_tile = true; |
| 724 DCHECK(!frame_data->has_no_damage); |
| 725 break; |
| 726 case 2: |
| 727 // Make a no-damage frame. We early out and can't detect |
| 728 // incomplete tiles, even if they still exist. |
| 729 frame_data->contains_incomplete_tile = false; |
| 730 frame_data->has_no_damage = true; |
| 731 break; |
| 732 case 3: |
| 733 // Trigger the last swap for the completed tile. |
| 734 frame_data->contains_incomplete_tile = false; |
| 735 frame_data->has_no_damage = false; |
| 736 EndTest(); |
| 737 break; |
| 738 default: |
| 739 NOTREACHED(); |
| 740 break; |
| 741 } |
| 742 |
| 743 return result; |
| 744 } |
| 745 |
| 746 virtual void UpdateVisibleTilesOnThread( |
| 747 LayerTreeHostImpl* host_impl) OVERRIDE { |
| 748 // Simulate creating some visible tiles (that trigger prepare-to-draws). |
| 749 // The first we make into a no-damage-frame during prepare-to-draw (see |
| 750 // above). This is to ensure we still get UpdateVisibleTiles calls after |
| 751 // a no-damage or aborted frame. |
| 752 update_visible_tile_count_++; |
| 753 switch (update_visible_tile_count_) { |
| 754 case 3: |
| 755 case 6: |
| 756 host_impl->DidInitializeVisibleTileForTesting(); |
| 757 break; |
| 758 case 7: |
| 759 NOTREACHED(); |
| 760 break; |
| 761 } |
| 762 } |
| 763 |
| 764 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 765 bool didSwap) OVERRIDE { |
| 766 if (!didSwap) |
| 767 return; |
| 768 ++swap_count_; |
| 769 } |
| 770 |
| 771 virtual void AfterTest() OVERRIDE { |
| 772 // We should keep getting update-visible-tiles calls |
| 773 // until we report there are no more incomplete-tiles. |
| 774 EXPECT_EQ(update_visible_tile_count_, 6); |
| 775 // First frame, plus two triggered by DidInitializeVisibleTile() |
| 776 EXPECT_EQ(prepare_to_draw_count_, 3); |
| 777 // First swap, plus final swap (contained damage). |
| 778 EXPECT_EQ(swap_count_, 2); |
| 779 } |
| 780 |
| 781 FakeContentLayerClient client_; |
| 782 int swap_count_; |
| 783 int prepare_to_draw_count_; |
| 784 int update_visible_tile_count_; |
| 785 }; |
| 786 |
| 787 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestVisibleTilesStillTriggerDraws); |
| 788 |
691 } // namespace | 789 } // namespace |
692 } // namespace cc | 790 } // namespace cc |
OLD | NEW |