Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 EXPECT_LT(low_res_factor, 1.f); | 696 EXPECT_LT(low_res_factor, 1.f); |
| 697 | 697 |
| 698 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | 698 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
| 699 1.7f, // device scale | 699 1.7f, // device scale |
| 700 3.2f, // page scale | 700 3.2f, // page scale |
| 701 1.f, // maximum animation scale | 701 1.f, // maximum animation scale |
| 702 false, | 702 false, |
| 703 &result_scale_x, | 703 &result_scale_x, |
| 704 &result_scale_y, | 704 &result_scale_y, |
| 705 &result_bounds); | 705 &result_bounds); |
| 706 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 706 ASSERT_EQ( |
| 707 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
|
enne (OOO)
2014/05/02 17:03:16
Just make the test set the settings appropriately
Sergey
2014/05/07 02:34:25
Done.
| |
| 708 pending_layer_->tilings()->num_tilings()); | |
| 707 EXPECT_FLOAT_EQ( | 709 EXPECT_FLOAT_EQ( |
| 708 1.3f, | 710 1.3f, |
| 709 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 711 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 710 EXPECT_FLOAT_EQ( | 712 if (host_impl_.settings().create_low_res_tiling) |
| 711 1.3f * low_res_factor, | 713 EXPECT_FLOAT_EQ( |
| 712 pending_layer_->tilings()->tiling_at(1)->contents_scale()); | 714 1.3f * low_res_factor, |
| 715 pending_layer_->tilings()->tiling_at(1)->contents_scale()); | |
| 713 | 716 |
| 714 // If we change the layer's CSS scale factor, then we should not get new | 717 // If we change the layer's CSS scale factor, then we should not get new |
| 715 // tilings. | 718 // tilings. |
| 716 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale | 719 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale |
| 717 1.7f, // device scale | 720 1.7f, // device scale |
| 718 3.2f, // page scale | 721 3.2f, // page scale |
| 719 1.f, // maximum animation scale | 722 1.f, // maximum animation scale |
| 720 false, | 723 false, |
| 721 &result_scale_x, | 724 &result_scale_x, |
| 722 &result_scale_y, | 725 &result_scale_y, |
| 723 &result_bounds); | 726 &result_bounds); |
| 724 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 727 ASSERT_EQ( |
| 728 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 729 pending_layer_->tilings()->num_tilings()); | |
| 725 EXPECT_FLOAT_EQ( | 730 EXPECT_FLOAT_EQ( |
| 726 1.3f, | 731 1.3f, |
| 727 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 732 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 728 EXPECT_FLOAT_EQ( | 733 if (host_impl_.settings().create_low_res_tiling) |
| 729 1.3f * low_res_factor, | 734 EXPECT_FLOAT_EQ( |
| 730 pending_layer_->tilings()->tiling_at(1)->contents_scale()); | 735 1.3f * low_res_factor, |
| 736 pending_layer_->tilings()->tiling_at(1)->contents_scale()); | |
| 731 | 737 |
| 732 // If we change the page scale factor, then we should get new tilings. | 738 // If we change the page scale factor, then we should get new tilings. |
| 733 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale | 739 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale |
| 734 1.7f, // device scale | 740 1.7f, // device scale |
| 735 2.2f, // page scale | 741 2.2f, // page scale |
| 736 1.f, // maximum animation scale | 742 1.f, // maximum animation scale |
| 737 false, | 743 false, |
| 738 &result_scale_x, | 744 &result_scale_x, |
| 739 &result_scale_y, | 745 &result_scale_y, |
| 740 &result_bounds); | 746 &result_bounds); |
| 741 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); | 747 ASSERT_EQ( |
| 748 host_impl_.settings().create_low_res_tiling ? 4u : 2u, | |
| 749 pending_layer_->tilings()->num_tilings()); | |
| 742 EXPECT_FLOAT_EQ( | 750 EXPECT_FLOAT_EQ( |
| 743 1.8f, | 751 1.8f, |
| 744 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 752 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 745 EXPECT_FLOAT_EQ( | 753 if (host_impl_.settings().create_low_res_tiling) |
| 746 1.8f * low_res_factor, | 754 EXPECT_FLOAT_EQ( |
| 747 pending_layer_->tilings()->tiling_at(2)->contents_scale()); | 755 1.8f * low_res_factor, |
| 756 pending_layer_->tilings()->tiling_at(2)->contents_scale()); | |
| 748 | 757 |
| 749 // If we change the device scale factor, then we should get new tilings. | 758 // If we change the device scale factor, then we should get new tilings. |
| 750 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale | 759 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale |
| 751 1.4f, // device scale | 760 1.4f, // device scale |
| 752 2.2f, // page scale | 761 2.2f, // page scale |
| 753 1.f, // maximum animation scale | 762 1.f, // maximum animation scale |
| 754 false, | 763 false, |
| 755 &result_scale_x, | 764 &result_scale_x, |
| 756 &result_scale_y, | 765 &result_scale_y, |
| 757 &result_bounds); | 766 &result_bounds); |
| 758 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); | 767 ASSERT_EQ( |
| 768 host_impl_.settings().create_low_res_tiling ? 6u : 3u, | |
| 769 pending_layer_->tilings()->num_tilings()); | |
| 759 EXPECT_FLOAT_EQ( | 770 EXPECT_FLOAT_EQ( |
| 760 1.9f, | 771 1.9f, |
| 761 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 772 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 762 EXPECT_FLOAT_EQ( | 773 if (host_impl_.settings().create_low_res_tiling) |
| 763 1.9f * low_res_factor, | 774 EXPECT_FLOAT_EQ( |
| 764 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | 775 1.9f * low_res_factor, |
| 776 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | |
| 765 | 777 |
| 766 // If we change the device scale factor, but end up at the same total scale | 778 // If we change the device scale factor, but end up at the same total scale |
| 767 // factor somehow, then we don't get new tilings. | 779 // factor somehow, then we don't get new tilings. |
| 768 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale | 780 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale |
| 769 2.2f, // device scale | 781 2.2f, // device scale |
| 770 1.4f, // page scale | 782 1.4f, // page scale |
| 771 1.f, // maximum animation scale | 783 1.f, // maximum animation scale |
| 772 false, | 784 false, |
| 773 &result_scale_x, | 785 &result_scale_x, |
| 774 &result_scale_y, | 786 &result_scale_y, |
| 775 &result_bounds); | 787 &result_bounds); |
| 776 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); | 788 ASSERT_EQ( |
| 789 host_impl_.settings().create_low_res_tiling ? 6u : 3u, | |
| 790 pending_layer_->tilings()->num_tilings()); | |
| 777 EXPECT_FLOAT_EQ( | 791 EXPECT_FLOAT_EQ( |
| 778 1.9f, | 792 1.9f, |
| 779 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 793 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 780 EXPECT_FLOAT_EQ( | 794 if (host_impl_.settings().create_low_res_tiling) |
| 781 1.9f * low_res_factor, | 795 EXPECT_FLOAT_EQ( |
| 782 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | 796 1.9f * low_res_factor, |
| 797 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | |
| 783 } | 798 } |
| 784 | 799 |
| 785 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { | 800 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { |
| 786 // This test makes sure that if a layer can have tilings, then a commit makes | 801 // This test makes sure that if a layer can have tilings, then a commit makes |
| 787 // it not able to have tilings (empty size), and then a future commit that | 802 // it not able to have tilings (empty size), and then a future commit that |
| 788 // makes it valid again should be able to create tilings. | 803 // makes it valid again should be able to create tilings. |
| 789 gfx::Size tile_size(400, 400); | 804 gfx::Size tile_size(400, 400); |
| 790 gfx::Size layer_bounds(1300, 1900); | 805 gfx::Size layer_bounds(1300, 1900); |
| 791 | 806 |
| 792 scoped_refptr<FakePicturePileImpl> empty_pile = | 807 scoped_refptr<FakePicturePileImpl> empty_pile = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 807 | 822 |
| 808 SetupPendingTree(valid_pile); | 823 SetupPendingTree(valid_pile); |
| 809 pending_layer_->CalculateContentsScale(high_res_scale, | 824 pending_layer_->CalculateContentsScale(high_res_scale, |
| 810 device_scale, | 825 device_scale, |
| 811 page_scale, | 826 page_scale, |
| 812 maximum_animation_scale, | 827 maximum_animation_scale, |
| 813 false, | 828 false, |
| 814 &result_scale_x, | 829 &result_scale_x, |
| 815 &result_scale_y, | 830 &result_scale_y, |
| 816 &result_bounds); | 831 &result_bounds); |
| 817 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 832 ASSERT_EQ( |
| 833 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 834 pending_layer_->tilings()->num_tilings()); | |
| 818 EXPECT_FLOAT_EQ(high_res_scale, | 835 EXPECT_FLOAT_EQ(high_res_scale, |
| 819 pending_layer_->HighResTiling()->contents_scale()); | 836 pending_layer_->HighResTiling()->contents_scale()); |
| 820 EXPECT_FLOAT_EQ(low_res_scale, | 837 if (host_impl_.settings().create_low_res_tiling) |
| 821 pending_layer_->LowResTiling()->contents_scale()); | 838 EXPECT_FLOAT_EQ(low_res_scale, |
| 839 pending_layer_->LowResTiling()->contents_scale()); | |
| 822 | 840 |
| 823 ActivateTree(); | 841 ActivateTree(); |
| 824 SetupPendingTree(empty_pile); | 842 SetupPendingTree(empty_pile); |
| 825 pending_layer_->CalculateContentsScale(high_res_scale, | 843 pending_layer_->CalculateContentsScale(high_res_scale, |
| 826 device_scale, | 844 device_scale, |
| 827 page_scale, | 845 page_scale, |
| 828 maximum_animation_scale, | 846 maximum_animation_scale, |
| 829 false, | 847 false, |
| 830 &result_scale_x, | 848 &result_scale_x, |
| 831 &result_scale_y, | 849 &result_scale_y, |
| 832 &result_bounds); | 850 &result_bounds); |
| 833 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 851 ASSERT_EQ( |
| 852 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 853 active_layer_->tilings()->num_tilings()); | |
| 834 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 854 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 835 | 855 |
| 836 ActivateTree(); | 856 ActivateTree(); |
| 837 active_layer_->CalculateContentsScale(high_res_scale, | 857 active_layer_->CalculateContentsScale(high_res_scale, |
| 838 device_scale, | 858 device_scale, |
| 839 page_scale, | 859 page_scale, |
| 840 maximum_animation_scale, | 860 maximum_animation_scale, |
| 841 false, | 861 false, |
| 842 &result_scale_x, | 862 &result_scale_x, |
| 843 &result_scale_y, | 863 &result_scale_y, |
| 844 &result_bounds); | 864 &result_bounds); |
| 845 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); | 865 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 846 | 866 |
| 847 SetupPendingTree(valid_pile); | 867 SetupPendingTree(valid_pile); |
| 848 pending_layer_->CalculateContentsScale(high_res_scale, | 868 pending_layer_->CalculateContentsScale(high_res_scale, |
| 849 device_scale, | 869 device_scale, |
| 850 page_scale, | 870 page_scale, |
| 851 maximum_animation_scale, | 871 maximum_animation_scale, |
| 852 false, | 872 false, |
| 853 &result_scale_x, | 873 &result_scale_x, |
| 854 &result_scale_y, | 874 &result_scale_y, |
| 855 &result_bounds); | 875 &result_bounds); |
| 856 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 876 ASSERT_EQ( |
| 877 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 878 pending_layer_->tilings()->num_tilings()); | |
| 857 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); | 879 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 858 EXPECT_FLOAT_EQ(high_res_scale, | 880 EXPECT_FLOAT_EQ(high_res_scale, |
| 859 pending_layer_->HighResTiling()->contents_scale()); | 881 pending_layer_->HighResTiling()->contents_scale()); |
| 860 EXPECT_FLOAT_EQ(low_res_scale, | 882 if (host_impl_.settings().create_low_res_tiling) |
| 861 pending_layer_->LowResTiling()->contents_scale()); | 883 EXPECT_FLOAT_EQ(low_res_scale, |
| 884 pending_layer_->LowResTiling()->contents_scale()); | |
| 862 } | 885 } |
| 863 | 886 |
| 864 TEST_F(PictureLayerImplTest, ZoomOutCrash) { | 887 TEST_F(PictureLayerImplTest, ZoomOutCrash) { |
| 865 gfx::Size tile_size(400, 400); | 888 gfx::Size tile_size(400, 400); |
| 866 gfx::Size layer_bounds(1300, 1900); | 889 gfx::Size layer_bounds(1300, 1900); |
| 867 | 890 |
| 868 // Set up the high and low res tilings before pinch zoom. | 891 // Set up the high and low res tilings before pinch zoom. |
| 869 scoped_refptr<FakePicturePileImpl> pending_pile = | 892 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 870 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 893 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 871 scoped_refptr<FakePicturePileImpl> active_pile = | 894 scoped_refptr<FakePicturePileImpl> active_pile = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 887 scoped_refptr<FakePicturePileImpl> pending_pile = | 910 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 888 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 911 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 889 scoped_refptr<FakePicturePileImpl> active_pile = | 912 scoped_refptr<FakePicturePileImpl> active_pile = |
| 890 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 913 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 891 | 914 |
| 892 // Set up the high and low res tilings before pinch zoom. | 915 // Set up the high and low res tilings before pinch zoom. |
| 893 SetupTrees(pending_pile, active_pile); | 916 SetupTrees(pending_pile, active_pile); |
| 894 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 917 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 895 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false); | 918 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false); |
| 896 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 919 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 897 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings()); | 920 EXPECT_EQ( |
| 921 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 922 active_layer_->tilings()->num_tilings()); | |
| 898 EXPECT_FLOAT_EQ( | 923 EXPECT_FLOAT_EQ( |
| 899 1.0f, | 924 1.0f, |
| 900 active_layer_->tilings()->tiling_at(0)->contents_scale()); | 925 active_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 901 EXPECT_FLOAT_EQ( | 926 if (host_impl_.settings().create_low_res_tiling) |
| 902 1.0f * low_res_factor, | 927 EXPECT_FLOAT_EQ( |
| 903 active_layer_->tilings()->tiling_at(1)->contents_scale()); | 928 1.0f * low_res_factor, |
| 929 active_layer_->tilings()->tiling_at(1)->contents_scale()); | |
| 904 | 930 |
| 905 // Start a pinch gesture. | 931 // Start a pinch gesture. |
| 906 host_impl_.PinchGestureBegin(); | 932 host_impl_.PinchGestureBegin(); |
| 907 | 933 |
| 908 // Zoom out by a small amount. We should create a tiling at half | 934 // Zoom out by a small amount. We should create a tiling at half |
| 909 // the scale (1/kMaxScaleRatioDuringPinch). | 935 // the scale (1/kMaxScaleRatioDuringPinch). |
| 910 SetContentsScaleOnBothLayers(0.90f, 1.0f, 0.9f, 1.0f, false); | 936 SetContentsScaleOnBothLayers(0.90f, 1.0f, 0.9f, 1.0f, false); |
| 911 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); | 937 EXPECT_EQ( |
| 938 host_impl_.settings().create_low_res_tiling ? 3u : 2u, | |
| 939 active_layer_->tilings()->num_tilings()); | |
| 912 EXPECT_FLOAT_EQ( | 940 EXPECT_FLOAT_EQ( |
| 913 1.0f, | 941 1.0f, |
| 914 active_layer_->tilings()->tiling_at(0)->contents_scale()); | 942 active_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 915 EXPECT_FLOAT_EQ( | 943 EXPECT_FLOAT_EQ( |
| 916 0.5f, | 944 0.5f, |
| 917 active_layer_->tilings()->tiling_at(1)->contents_scale()); | 945 active_layer_->tilings()->tiling_at(1)->contents_scale()); |
| 918 EXPECT_FLOAT_EQ( | 946 if (host_impl_.settings().create_low_res_tiling) |
| 919 1.0f * low_res_factor, | 947 EXPECT_FLOAT_EQ( |
| 920 active_layer_->tilings()->tiling_at(2)->contents_scale()); | 948 1.0f * low_res_factor, |
| 949 active_layer_->tilings()->tiling_at(2)->contents_scale()); | |
| 921 | 950 |
| 922 // Zoom out further, close to our low-res scale factor. We should | 951 // Zoom out further, close to our low-res scale factor. We should |
| 923 // use that tiling as high-res, and not create a new tiling. | 952 // use that tiling as high-res, and not create a new tiling. |
| 924 SetContentsScaleOnBothLayers( | 953 SetContentsScaleOnBothLayers( |
| 925 low_res_factor, 1.0f, low_res_factor, 1.0f, false); | 954 low_res_factor, 1.0f, low_res_factor, 1.0f, false); |
| 926 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); | 955 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); |
| 927 | 956 |
| 928 // Zoom in a lot now. Since we increase by increments of | 957 // Zoom in a lot now. Since we increase by increments of |
| 929 // kMaxScaleRatioDuringPinch, this will first use 0.5, then 1.0 | 958 // kMaxScaleRatioDuringPinch, this will first use 0.5, then 1.0 |
| 930 // and then finally create a new tiling at 2.0. | 959 // and then finally create a new tiling at 2.0. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 955 SetupTrees(pending_pile, active_pile); | 984 SetupTrees(pending_pile, active_pile); |
| 956 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 985 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 957 | 986 |
| 958 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 987 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 959 EXPECT_LT(low_res_factor, 1.f); | 988 EXPECT_LT(low_res_factor, 1.f); |
| 960 | 989 |
| 961 float device_scale = 1.7f; | 990 float device_scale = 1.7f; |
| 962 float page_scale = 3.2f; | 991 float page_scale = 3.2f; |
| 963 | 992 |
| 964 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); | 993 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
| 965 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 994 ASSERT_EQ( |
| 995 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 996 active_layer_->tilings()->num_tilings()); | |
| 966 | 997 |
| 967 // We only have ideal tilings, so they aren't removed. | 998 // We only have ideal tilings, so they aren't removed. |
| 968 used_tilings.clear(); | 999 used_tilings.clear(); |
| 969 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1000 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 970 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 1001 ASSERT_EQ( |
| 1002 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1003 active_layer_->tilings()->num_tilings()); | |
| 971 | 1004 |
| 972 // Changing the ideal but not creating new tilings. | 1005 // Changing the ideal but not creating new tilings. |
| 973 SetContentsScaleOnBothLayers(1.5f, device_scale, page_scale, 1.f, false); | 1006 SetContentsScaleOnBothLayers(1.5f, device_scale, page_scale, 1.f, false); |
| 974 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 1007 ASSERT_EQ( |
| 1008 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1009 active_layer_->tilings()->num_tilings()); | |
| 975 | 1010 |
| 976 // The tilings are still our target scale, so they aren't removed. | 1011 // The tilings are still our target scale, so they aren't removed. |
| 977 used_tilings.clear(); | 1012 used_tilings.clear(); |
| 978 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1013 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 979 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 1014 ASSERT_EQ( |
| 1015 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1016 active_layer_->tilings()->num_tilings()); | |
| 980 | 1017 |
| 981 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. | 1018 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. |
| 982 page_scale = 1.2f; | 1019 page_scale = 1.2f; |
| 983 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); | 1020 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); |
| 984 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); | 1021 ASSERT_EQ( |
| 1022 host_impl_.settings().create_low_res_tiling ? 4u : 2u, | |
| 1023 active_layer_->tilings()->num_tilings()); | |
| 985 EXPECT_FLOAT_EQ( | 1024 EXPECT_FLOAT_EQ( |
| 986 1.f, | 1025 1.f, |
| 987 active_layer_->tilings()->tiling_at(1)->contents_scale()); | 1026 active_layer_->tilings()->tiling_at(1)->contents_scale()); |
| 988 EXPECT_FLOAT_EQ( | 1027 if (host_impl_.settings().create_low_res_tiling) |
| 989 1.f * low_res_factor, | 1028 EXPECT_FLOAT_EQ( |
| 990 active_layer_->tilings()->tiling_at(3)->contents_scale()); | 1029 1.f * low_res_factor, |
| 1030 active_layer_->tilings()->tiling_at(3)->contents_scale()); | |
| 991 | 1031 |
| 992 // Mark the non-ideal tilings as used. They won't be removed. | 1032 // Mark the non-ideal tilings as used. They won't be removed. |
| 993 used_tilings.clear(); | 1033 used_tilings.clear(); |
| 994 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); | 1034 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
| 995 used_tilings.push_back(active_layer_->tilings()->tiling_at(3)); | 1035 used_tilings.push_back(active_layer_->tilings()->tiling_at(3)); |
| 996 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1036 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 997 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); | 1037 ASSERT_EQ( |
| 1038 host_impl_.settings().create_low_res_tiling ? 4u : 2u, | |
| 1039 active_layer_->tilings()->num_tilings()); | |
| 998 | 1040 |
| 999 // Now move the ideal scale to 0.5. Our target stays 1.2. | 1041 // Now move the ideal scale to 0.5. Our target stays 1.2. |
| 1000 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); | 1042 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); |
| 1001 | 1043 |
| 1002 // The high resolution tiling is between target and ideal, so is not | 1044 // The high resolution tiling is between target and ideal, so is not |
| 1003 // removed. The low res tiling for the old ideal=1.0 scale is removed. | 1045 // removed. The low res tiling for the old ideal=1.0 scale is removed. |
| 1004 used_tilings.clear(); | 1046 used_tilings.clear(); |
| 1005 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1047 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 1006 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 1048 ASSERT_EQ( |
| 1049 host_impl_.settings().create_low_res_tiling ? 3u : 2u, | |
| 1050 active_layer_->tilings()->num_tilings()); | |
| 1007 | 1051 |
| 1008 // Now move the ideal scale to 1.0. Our target stays 1.2. | 1052 // Now move the ideal scale to 1.0. Our target stays 1.2. |
| 1009 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); | 1053 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
| 1010 | 1054 |
| 1011 // All the tilings are between are target and the ideal, so they are not | 1055 // All the tilings are between are target and the ideal, so they are not |
| 1012 // removed. | 1056 // removed. |
| 1013 used_tilings.clear(); | 1057 used_tilings.clear(); |
| 1014 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1058 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 1015 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 1059 ASSERT_EQ( |
| 1060 host_impl_.settings().create_low_res_tiling ? 3u : 2u, | |
| 1061 active_layer_->tilings()->num_tilings()); | |
| 1016 | 1062 |
| 1017 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. | 1063 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. |
| 1018 active_layer_->CalculateContentsScale(1.1f, | 1064 active_layer_->CalculateContentsScale(1.1f, |
| 1019 device_scale, | 1065 device_scale, |
| 1020 page_scale, | 1066 page_scale, |
| 1021 1.f, | 1067 1.f, |
| 1022 false, | 1068 false, |
| 1023 &result_scale_x, | 1069 &result_scale_x, |
| 1024 &result_scale_y, | 1070 &result_scale_y, |
| 1025 &result_bounds); | 1071 &result_bounds); |
| 1026 | 1072 |
| 1027 // Because the pending layer's ideal scale is still 1.0, our tilings fall | 1073 // Because the pending layer's ideal scale is still 1.0, our tilings fall |
| 1028 // in the range [1.0,1.2] and are kept. | 1074 // in the range [1.0,1.2] and are kept. |
| 1029 used_tilings.clear(); | 1075 used_tilings.clear(); |
| 1030 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1076 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 1031 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 1077 ASSERT_EQ( |
| 1078 host_impl_.settings().create_low_res_tiling ? 3u : 2u, | |
| 1079 active_layer_->tilings()->num_tilings()); | |
| 1032 | 1080 |
| 1033 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays | 1081 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays |
| 1034 // 1.2 still. | 1082 // 1.2 still. |
| 1035 pending_layer_->CalculateContentsScale(1.1f, | 1083 pending_layer_->CalculateContentsScale(1.1f, |
| 1036 device_scale, | 1084 device_scale, |
| 1037 page_scale, | 1085 page_scale, |
| 1038 1.f, | 1086 1.f, |
| 1039 false, | 1087 false, |
| 1040 &result_scale_x, | 1088 &result_scale_x, |
| 1041 &result_scale_y, | 1089 &result_scale_y, |
| 1042 &result_bounds); | 1090 &result_bounds); |
| 1043 | 1091 |
| 1044 // Our 1.0 tiling now falls outside the range between our ideal scale and our | 1092 // Our 1.0 tiling now falls outside the range between our ideal scale and our |
| 1045 // target raster scale. But it is in our used tilings set, so nothing is | 1093 // target raster scale. But it is in our used tilings set, so nothing is |
| 1046 // deleted. | 1094 // deleted. |
| 1047 used_tilings.clear(); | 1095 used_tilings.clear(); |
| 1048 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); | 1096 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
| 1049 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1097 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 1050 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 1098 ASSERT_EQ( |
| 1099 host_impl_.settings().create_low_res_tiling ? 3u : 2u, | |
| 1100 active_layer_->tilings()->num_tilings()); | |
| 1051 | 1101 |
| 1052 // If we remove it from our used tilings set, it is outside the range to keep | 1102 // If we remove it from our used tilings set, it is outside the range to keep |
| 1053 // so it is deleted. | 1103 // so it is deleted. |
| 1054 used_tilings.clear(); | 1104 used_tilings.clear(); |
| 1055 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 1105 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 1056 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 1106 ASSERT_EQ( |
| 1107 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1108 active_layer_->tilings()->num_tilings()); | |
| 1057 } | 1109 } |
| 1058 | 1110 |
| 1059 #define EXPECT_BOTH_EQ(expression, x) \ | 1111 #define EXPECT_BOTH_EQ(expression, x) \ |
| 1060 do { \ | 1112 do { \ |
| 1061 EXPECT_EQ(pending_layer_->expression, x); \ | 1113 EXPECT_EQ(pending_layer_->expression, x); \ |
| 1062 EXPECT_EQ(active_layer_->expression, x); \ | 1114 EXPECT_EQ(active_layer_->expression, x); \ |
| 1063 } while (false) | 1115 } while (false) |
| 1064 | 1116 |
| 1065 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { | 1117 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { |
| 1066 // Make sure this layer covers multiple tiles, since otherwise low | 1118 // Make sure this layer covers multiple tiles, since otherwise low |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1088 EXPECT_BOTH_EQ(num_tilings(), 1u); | 1140 EXPECT_BOTH_EQ(num_tilings(), 1u); |
| 1089 | 1141 |
| 1090 // Stop animating, low res gets created. | 1142 // Stop animating, low res gets created. |
| 1091 animating_transform = false; | 1143 animating_transform = false; |
| 1092 SetContentsScaleOnBothLayers(contents_scale, | 1144 SetContentsScaleOnBothLayers(contents_scale, |
| 1093 device_scale, | 1145 device_scale, |
| 1094 page_scale, | 1146 page_scale, |
| 1095 maximum_animation_scale, | 1147 maximum_animation_scale, |
| 1096 animating_transform); | 1148 animating_transform); |
| 1097 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); | 1149 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); |
| 1098 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor); | 1150 if (host_impl_.settings().create_low_res_tiling) |
| 1099 EXPECT_BOTH_EQ(num_tilings(), 2u); | 1151 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor); |
| 1152 EXPECT_BOTH_EQ( | |
| 1153 num_tilings(), | |
| 1154 host_impl_.settings().create_low_res_tiling ? 2u : 1u); | |
| 1100 | 1155 |
| 1101 // Page scale animation, new high res, but not new low res because animating. | 1156 // Page scale animation, new high res, but not new low res because animating. |
| 1102 contents_scale = 2.f; | 1157 contents_scale = 2.f; |
| 1103 page_scale = 2.f; | 1158 page_scale = 2.f; |
| 1104 animating_transform = true; | 1159 animating_transform = true; |
| 1105 SetContentsScaleOnBothLayers(contents_scale, | 1160 SetContentsScaleOnBothLayers(contents_scale, |
| 1106 device_scale, | 1161 device_scale, |
| 1107 page_scale, | 1162 page_scale, |
| 1108 maximum_animation_scale, | 1163 maximum_animation_scale, |
| 1109 animating_transform); | 1164 animating_transform); |
| 1110 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); | 1165 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); |
| 1111 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor); | 1166 if (host_impl_.settings().create_low_res_tiling) |
| 1112 EXPECT_BOTH_EQ(num_tilings(), 3u); | 1167 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor); |
| 1168 EXPECT_BOTH_EQ( | |
| 1169 num_tilings(), | |
| 1170 host_impl_.settings().create_low_res_tiling ? 3u : 2u); | |
| 1113 | 1171 |
| 1114 // Stop animating, new low res gets created for final page scale. | 1172 // Stop animating, new low res gets created for final page scale. |
| 1115 animating_transform = false; | 1173 animating_transform = false; |
| 1116 SetContentsScaleOnBothLayers(contents_scale, | 1174 SetContentsScaleOnBothLayers(contents_scale, |
| 1117 device_scale, | 1175 device_scale, |
| 1118 page_scale, | 1176 page_scale, |
| 1119 maximum_animation_scale, | 1177 maximum_animation_scale, |
| 1120 animating_transform); | 1178 animating_transform); |
| 1121 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); | 1179 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); |
| 1122 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor); | 1180 if (host_impl_.settings().create_low_res_tiling) |
| 1123 EXPECT_BOTH_EQ(num_tilings(), 4u); | 1181 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor); |
| 1182 EXPECT_BOTH_EQ( | |
| 1183 num_tilings(), | |
| 1184 host_impl_.settings().create_low_res_tiling ? 4u : 2u); | |
| 1124 } | 1185 } |
| 1125 | 1186 |
| 1126 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { | 1187 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { |
| 1127 gfx::Size tile_size(host_impl_.settings().default_tile_size); | 1188 gfx::Size tile_size(host_impl_.settings().default_tile_size); |
| 1128 SetupDefaultTrees(tile_size); | 1189 SetupDefaultTrees(tile_size); |
| 1129 | 1190 |
| 1130 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 1191 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 1131 float device_scale = 1.f; | 1192 float device_scale = 1.f; |
| 1132 float page_scale = 1.f; | 1193 float page_scale = 1.f; |
| 1133 float maximum_animation_scale = 1.f; | 1194 float maximum_animation_scale = 1.f; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1159 | 1220 |
| 1160 // Any content bounds that would create more than one tile will | 1221 // Any content bounds that would create more than one tile will |
| 1161 // generate a low res tiling. | 1222 // generate a low res tiling. |
| 1162 contents_scale = 2.5f; | 1223 contents_scale = 2.5f; |
| 1163 SetContentsScaleOnBothLayers(contents_scale, | 1224 SetContentsScaleOnBothLayers(contents_scale, |
| 1164 device_scale, | 1225 device_scale, |
| 1165 page_scale, | 1226 page_scale, |
| 1166 maximum_animation_scale, | 1227 maximum_animation_scale, |
| 1167 animating_transform); | 1228 animating_transform); |
| 1168 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); | 1229 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); |
| 1169 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), | 1230 if (host_impl_.settings().create_low_res_tiling) |
| 1170 contents_scale * low_res_factor); | 1231 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), |
| 1171 EXPECT_BOTH_EQ(num_tilings(), 2u); | 1232 contents_scale * low_res_factor); |
| 1233 EXPECT_BOTH_EQ( | |
| 1234 num_tilings(), | |
| 1235 host_impl_.settings().create_low_res_tiling ? 2u : 1u); | |
| 1172 | 1236 |
| 1173 ResetTilingsAndRasterScales(); | 1237 ResetTilingsAndRasterScales(); |
| 1174 | 1238 |
| 1175 // Mask layers dont create low res since they always fit on one tile. | 1239 // Mask layers dont create low res since they always fit on one tile. |
| 1176 pending_layer_->SetIsMask(true); | 1240 pending_layer_->SetIsMask(true); |
| 1177 active_layer_->SetIsMask(true); | 1241 active_layer_->SetIsMask(true); |
| 1178 SetContentsScaleOnBothLayers(contents_scale, | 1242 SetContentsScaleOnBothLayers(contents_scale, |
| 1179 device_scale, | 1243 device_scale, |
| 1180 page_scale, | 1244 page_scale, |
| 1181 maximum_animation_scale, | 1245 maximum_animation_scale, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1200 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1264 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1201 | 1265 |
| 1202 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | 1266 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
| 1203 2.7f, // device scale | 1267 2.7f, // device scale |
| 1204 3.2f, // page scale | 1268 3.2f, // page scale |
| 1205 1.f, // maximum animation scale | 1269 1.f, // maximum animation scale |
| 1206 false, | 1270 false, |
| 1207 &result_scale_x, | 1271 &result_scale_x, |
| 1208 &result_scale_y, | 1272 &result_scale_y, |
| 1209 &result_bounds); | 1273 &result_bounds); |
| 1210 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1274 EXPECT_EQ( |
| 1275 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1276 pending_layer_->tilings()->num_tilings()); | |
| 1211 | 1277 |
| 1212 // All tilings should be removed when losing output surface. | 1278 // All tilings should be removed when losing output surface. |
| 1213 active_layer_->ReleaseResources(); | 1279 active_layer_->ReleaseResources(); |
| 1214 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 1280 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 1215 pending_layer_->ReleaseResources(); | 1281 pending_layer_->ReleaseResources(); |
| 1216 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1282 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1217 | 1283 |
| 1218 // This should create new tilings. | 1284 // This should create new tilings. |
| 1219 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | 1285 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
| 1220 2.7f, // device scale | 1286 2.7f, // device scale |
| 1221 3.2f, // page scale | 1287 3.2f, // page scale |
| 1222 1.f, // maximum animation scale | 1288 1.f, // maximum animation scale |
| 1223 false, | 1289 false, |
| 1224 &result_scale_x, | 1290 &result_scale_x, |
| 1225 &result_scale_y, | 1291 &result_scale_y, |
| 1226 &result_bounds); | 1292 &result_bounds); |
| 1227 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1293 EXPECT_EQ( |
| 1294 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1295 pending_layer_->tilings()->num_tilings()); | |
| 1228 } | 1296 } |
| 1229 | 1297 |
| 1230 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { | 1298 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { |
| 1231 // The default max tile size is larger than 400x400. | 1299 // The default max tile size is larger than 400x400. |
| 1232 gfx::Size tile_size(400, 400); | 1300 gfx::Size tile_size(400, 400); |
| 1233 gfx::Size layer_bounds(5000, 5000); | 1301 gfx::Size layer_bounds(5000, 5000); |
| 1234 | 1302 |
| 1235 scoped_refptr<FakePicturePileImpl> pending_pile = | 1303 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1236 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1304 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1237 scoped_refptr<FakePicturePileImpl> active_pile = | 1305 scoped_refptr<FakePicturePileImpl> active_pile = |
| 1238 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1306 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1239 | 1307 |
| 1240 float result_scale_x, result_scale_y; | 1308 float result_scale_x, result_scale_y; |
| 1241 gfx::Size result_bounds; | 1309 gfx::Size result_bounds; |
| 1242 | 1310 |
| 1243 SetupTrees(pending_pile, active_pile); | 1311 SetupTrees(pending_pile, active_pile); |
| 1244 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1312 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1245 | 1313 |
| 1246 pending_layer_->CalculateContentsScale(1.f, | 1314 pending_layer_->CalculateContentsScale(1.f, |
| 1247 1.f, | 1315 1.f, |
| 1248 1.f, | 1316 1.f, |
| 1249 1.f, | 1317 1.f, |
| 1250 false, | 1318 false, |
| 1251 &result_scale_x, | 1319 &result_scale_x, |
| 1252 &result_scale_y, | 1320 &result_scale_y, |
| 1253 &result_bounds); | 1321 &result_bounds); |
| 1254 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1322 ASSERT_EQ( |
| 1323 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1324 pending_layer_->tilings()->num_tilings()); | |
| 1255 | 1325 |
| 1256 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1326 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
| 1257 | 1327 |
| 1258 // The default value. | 1328 // The default value. |
| 1259 EXPECT_EQ(gfx::Size(256, 256).ToString(), | 1329 EXPECT_EQ(gfx::Size(256, 256).ToString(), |
| 1260 host_impl_.settings().default_tile_size.ToString()); | 1330 host_impl_.settings().default_tile_size.ToString()); |
| 1261 | 1331 |
| 1262 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1332 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
| 1263 EXPECT_EQ(gfx::Size(256, 256).ToString(), | 1333 EXPECT_EQ(gfx::Size(256, 256).ToString(), |
| 1264 tile->content_rect().size().ToString()); | 1334 tile->content_rect().size().ToString()); |
| 1265 | 1335 |
| 1266 pending_layer_->ReleaseResources(); | 1336 pending_layer_->ReleaseResources(); |
| 1267 | 1337 |
| 1268 // Change the max texture size on the output surface context. | 1338 // Change the max texture size on the output surface context. |
| 1269 scoped_ptr<TestWebGraphicsContext3D> context = | 1339 scoped_ptr<TestWebGraphicsContext3D> context = |
| 1270 TestWebGraphicsContext3D::Create(); | 1340 TestWebGraphicsContext3D::Create(); |
| 1271 context->set_max_texture_size(140); | 1341 context->set_max_texture_size(140); |
| 1272 host_impl_.DidLoseOutputSurface(); | 1342 host_impl_.DidLoseOutputSurface(); |
| 1273 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( | 1343 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( |
| 1274 context.Pass()).PassAs<OutputSurface>()); | 1344 context.Pass()).PassAs<OutputSurface>()); |
| 1275 | 1345 |
| 1276 pending_layer_->CalculateContentsScale(1.f, | 1346 pending_layer_->CalculateContentsScale(1.f, |
| 1277 1.f, | 1347 1.f, |
| 1278 1.f, | 1348 1.f, |
| 1279 1.f, | 1349 1.f, |
| 1280 false, | 1350 false, |
| 1281 &result_scale_x, | 1351 &result_scale_x, |
| 1282 &result_scale_y, | 1352 &result_scale_y, |
| 1283 &result_bounds); | 1353 &result_bounds); |
| 1284 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1354 ASSERT_EQ( |
| 1355 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1356 pending_layer_->tilings()->num_tilings()); | |
| 1285 | 1357 |
| 1286 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1358 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
| 1287 | 1359 |
| 1288 // Verify the tiles are not larger than the context's max texture size. | 1360 // Verify the tiles are not larger than the context's max texture size. |
| 1289 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1361 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
| 1290 EXPECT_GE(140, tile->content_rect().width()); | 1362 EXPECT_GE(140, tile->content_rect().width()); |
| 1291 EXPECT_GE(140, tile->content_rect().height()); | 1363 EXPECT_GE(140, tile->content_rect().height()); |
| 1292 } | 1364 } |
| 1293 | 1365 |
| 1294 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { | 1366 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 } | 1542 } |
| 1471 } | 1543 } |
| 1472 | 1544 |
| 1473 EXPECT_GT(num_visible, 0); | 1545 EXPECT_GT(num_visible, 0); |
| 1474 EXPECT_GT(num_offscreen, 0); | 1546 EXPECT_GT(num_offscreen, 0); |
| 1475 } | 1547 } |
| 1476 | 1548 |
| 1477 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { | 1549 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { |
| 1478 gfx::Size layer_bounds(400, 400); | 1550 gfx::Size layer_bounds(400, 400); |
| 1479 gfx::Size tile_size(100, 100); | 1551 gfx::Size tile_size(100, 100); |
| 1552 | |
| 1480 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1553 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
| 1481 | 1554 |
| 1482 // No tiles shared. | 1555 // No tiles shared. |
| 1483 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); | 1556 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); |
| 1484 | 1557 |
| 1485 CreateHighLowResAndSetAllTilesVisible(); | 1558 CreateHighLowResAndSetAllTilesVisible(); |
| 1486 | 1559 |
| 1487 active_layer_->SetAllTilesReady(); | 1560 active_layer_->SetAllTilesReady(); |
| 1488 | 1561 |
| 1489 // No shared tiles and all active tiles ready, so pending can only | 1562 // No shared tiles and all active tiles ready, so pending can only |
| 1490 // activate with all high res tiles. | 1563 // activate with all high res tiles. |
| 1491 pending_layer_->MarkVisibleResourcesAsRequired(); | 1564 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1492 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1565 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
| 1493 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1566 if (host_impl_.settings().create_low_res_tiling) |
| 1567 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
| 1494 } | 1568 } |
| 1495 | 1569 |
| 1496 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { | 1570 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { |
| 1497 gfx::Size layer_bounds(400, 400); | 1571 gfx::Size layer_bounds(400, 400); |
| 1498 gfx::Size tile_size(100, 100); | 1572 gfx::Size tile_size(100, 100); |
| 1499 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1573 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
| 1500 | 1574 |
| 1501 // All tiles shared (no invalidation). | 1575 // All tiles shared (no invalidation). |
| 1502 CreateHighLowResAndSetAllTilesVisible(); | 1576 CreateHighLowResAndSetAllTilesVisible(); |
| 1503 | 1577 |
| 1504 // Verify active tree not ready. | 1578 // Verify active tree not ready. |
| 1505 Tile* some_active_tile = | 1579 Tile* some_active_tile = |
| 1506 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | 1580 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
| 1507 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | 1581 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
| 1508 | 1582 |
| 1509 // When high res are required, even if the active tree is not ready, | 1583 // When high res are required, even if the active tree is not ready, |
| 1510 // the high res tiles must be ready. | 1584 // the high res tiles must be ready. |
| 1511 host_impl_.active_tree()->SetRequiresHighResToDraw(); | 1585 host_impl_.active_tree()->SetRequiresHighResToDraw(); |
| 1512 pending_layer_->MarkVisibleResourcesAsRequired(); | 1586 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1513 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1587 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
| 1514 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1588 if (host_impl_.settings().create_low_res_tiling) |
| 1589 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
| 1515 } | 1590 } |
| 1516 | 1591 |
| 1517 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { | 1592 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { |
| 1518 gfx::Size layer_bounds(400, 400); | 1593 gfx::Size layer_bounds(400, 400); |
| 1519 gfx::Size tile_size(100, 100); | 1594 gfx::Size tile_size(100, 100); |
| 1520 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1595 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
| 1521 | 1596 |
| 1522 CreateHighLowResAndSetAllTilesVisible(); | 1597 CreateHighLowResAndSetAllTilesVisible(); |
| 1523 | 1598 |
| 1524 Tile* some_active_tile = | 1599 Tile* some_active_tile = |
| 1525 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | 1600 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
| 1526 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | 1601 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
| 1527 | 1602 |
| 1528 // All tiles shared (no invalidation), so even though the active tree's | 1603 // All tiles shared (no invalidation), so even though the active tree's |
| 1529 // tiles aren't ready, there is nothing required. | 1604 // tiles aren't ready, there is nothing required. |
| 1530 pending_layer_->MarkVisibleResourcesAsRequired(); | 1605 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1606 VLOG(0) << "NothingRequiredIfAllHighResTilesShared::AssertNoTilesRequired"; | |
| 1531 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 1607 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 1532 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1608 if (host_impl_.settings().create_low_res_tiling) { |
| 1609 VLOG(0) << "NothingRequiredIfAllHighResTilesShared::AssertNoTilesRequired -> low-res"; | |
| 1610 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
| 1611 } | |
| 1533 } | 1612 } |
| 1534 | 1613 |
| 1535 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { | 1614 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { |
| 1536 gfx::Size layer_bounds(400, 400); | 1615 gfx::Size layer_bounds(400, 400); |
| 1537 gfx::Size tile_size(100, 100); | 1616 gfx::Size tile_size(100, 100); |
| 1538 scoped_refptr<FakePicturePileImpl> pending_pile = | 1617 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1539 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1618 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1540 // This pile will create tilings, but has no recordings so will not create any | 1619 // This pile will create tilings, but has no recordings so will not create any |
| 1541 // tiles. This is attempting to simulate scrolling past the end of recorded | 1620 // tiles. This is attempting to simulate scrolling past the end of recorded |
| 1542 // content on the active layer, where the recordings are so far away that | 1621 // content on the active layer, where the recordings are so far away that |
| 1543 // no tiles are created. | 1622 // no tiles are created. |
| 1544 scoped_refptr<FakePicturePileImpl> active_pile = | 1623 scoped_refptr<FakePicturePileImpl> active_pile = |
| 1545 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | 1624 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
| 1546 tile_size, layer_bounds); | 1625 tile_size, layer_bounds); |
| 1547 SetupTrees(pending_pile, active_pile); | 1626 SetupTrees(pending_pile, active_pile); |
| 1548 pending_layer_->set_fixed_tile_size(tile_size); | 1627 pending_layer_->set_fixed_tile_size(tile_size); |
| 1549 active_layer_->set_fixed_tile_size(tile_size); | 1628 active_layer_->set_fixed_tile_size(tile_size); |
| 1550 | 1629 |
| 1551 CreateHighLowResAndSetAllTilesVisible(); | 1630 CreateHighLowResAndSetAllTilesVisible(); |
| 1552 | 1631 |
| 1553 // Active layer has tilings, but no tiles due to missing recordings. | 1632 // Active layer has tilings, but no tiles due to missing recordings. |
| 1554 EXPECT_TRUE(active_layer_->CanHaveTilings()); | 1633 EXPECT_TRUE(active_layer_->CanHaveTilings()); |
| 1555 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); | 1634 EXPECT_EQ( |
| 1635 active_layer_->tilings()->num_tilings(), | |
| 1636 host_impl_.settings().create_low_res_tiling ? 2u : 1u); | |
| 1556 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 1637 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); |
| 1557 | 1638 |
| 1558 // Since the active layer has no tiles at all, the pending layer doesn't | 1639 // Since the active layer has no tiles at all, the pending layer doesn't |
| 1559 // need content in order to activate. | 1640 // need content in order to activate. |
| 1560 pending_layer_->MarkVisibleResourcesAsRequired(); | 1641 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1561 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 1642 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 1562 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1643 if (host_impl_.settings().create_low_res_tiling) |
| 1644 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
| 1563 } | 1645 } |
| 1564 | 1646 |
| 1565 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { | 1647 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { |
| 1566 gfx::Size layer_bounds(400, 400); | 1648 gfx::Size layer_bounds(400, 400); |
| 1567 gfx::Size tile_size(100, 100); | 1649 gfx::Size tile_size(100, 100); |
| 1568 scoped_refptr<FakePicturePileImpl> pending_pile = | 1650 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1569 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1651 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1570 scoped_refptr<FakePicturePileImpl> active_pile = | 1652 scoped_refptr<FakePicturePileImpl> active_pile = |
| 1571 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 1653 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 1572 SetupTrees(pending_pile, active_pile); | 1654 SetupTrees(pending_pile, active_pile); |
| 1573 pending_layer_->set_fixed_tile_size(tile_size); | 1655 pending_layer_->set_fixed_tile_size(tile_size); |
| 1574 active_layer_->set_fixed_tile_size(tile_size); | 1656 active_layer_->set_fixed_tile_size(tile_size); |
| 1575 | 1657 |
| 1576 CreateHighLowResAndSetAllTilesVisible(); | 1658 CreateHighLowResAndSetAllTilesVisible(); |
| 1577 | 1659 |
| 1578 // Active layer can't have tiles. | 1660 // Active layer can't have tiles. |
| 1579 EXPECT_FALSE(active_layer_->CanHaveTilings()); | 1661 EXPECT_FALSE(active_layer_->CanHaveTilings()); |
| 1580 | 1662 |
| 1581 // All high res tiles required. This should be considered identical | 1663 // All high res tiles required. This should be considered identical |
| 1582 // to the case where there is no active layer, to avoid flashing content. | 1664 // to the case where there is no active layer, to avoid flashing content. |
| 1583 // This can happen if a layer exists for a while and switches from | 1665 // This can happen if a layer exists for a while and switches from |
| 1584 // not being able to have content to having content. | 1666 // not being able to have content to having content. |
| 1585 pending_layer_->MarkVisibleResourcesAsRequired(); | 1667 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1586 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1668 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
| 1587 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1669 if (host_impl_.settings().create_low_res_tiling) |
| 1670 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
| 1588 } | 1671 } |
| 1589 | 1672 |
| 1590 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { | 1673 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { |
| 1591 gfx::Size tile_size(100, 100); | 1674 gfx::Size tile_size(100, 100); |
| 1592 gfx::Size layer_bounds(400, 400); | 1675 gfx::Size layer_bounds(400, 400); |
| 1593 scoped_refptr<FakePicturePileImpl> pending_pile = | 1676 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1594 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1677 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1595 | 1678 |
| 1596 host_impl_.CreatePendingTree(); | 1679 host_impl_.CreatePendingTree(); |
| 1597 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 1680 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1698 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1781 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1699 pending_layer_->CalculateContentsScale(1.f, | 1782 pending_layer_->CalculateContentsScale(1.f, |
| 1700 1.f, | 1783 1.f, |
| 1701 1.f, | 1784 1.f, |
| 1702 1.f, | 1785 1.f, |
| 1703 false, | 1786 false, |
| 1704 &result_scale_x, | 1787 &result_scale_x, |
| 1705 &result_scale_y, | 1788 &result_scale_y, |
| 1706 &result_bounds); | 1789 &result_bounds); |
| 1707 // Should have a low-res and a high-res tiling. | 1790 // Should have a low-res and a high-res tiling. |
| 1708 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1791 ASSERT_EQ( |
| 1792 host_impl_.settings().create_low_res_tiling ? 2u : 1u, | |
| 1793 pending_layer_->tilings()->num_tilings()); | |
| 1709 | 1794 |
| 1710 pending_layer_->SetUseGpuRasterization(true); | 1795 pending_layer_->SetUseGpuRasterization(true); |
| 1711 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | 1796 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1712 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1797 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1713 pending_layer_->CalculateContentsScale(1.f, | 1798 pending_layer_->CalculateContentsScale(1.f, |
| 1714 1.f, | 1799 1.f, |
| 1715 1.f, | 1800 1.f, |
| 1716 1.f, | 1801 1.f, |
| 1717 false, | 1802 false, |
| 1718 &result_scale_x, | 1803 &result_scale_x, |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2274 occluded, | 2359 occluded, |
| 2275 &partially_occluded_count); | 2360 &partially_occluded_count); |
| 2276 // The layer outputs one quad, which is partially occluded. | 2361 // The layer outputs one quad, which is partially occluded. |
| 2277 EXPECT_EQ(100u - 10u, impl.quad_list().size()); | 2362 EXPECT_EQ(100u - 10u, impl.quad_list().size()); |
| 2278 EXPECT_EQ(10u + 10u, partially_occluded_count); | 2363 EXPECT_EQ(10u + 10u, partially_occluded_count); |
| 2279 } | 2364 } |
| 2280 } | 2365 } |
| 2281 | 2366 |
| 2282 } // namespace | 2367 } // namespace |
| 2283 } // namespace cc | 2368 } // namespace cc |
| OLD | NEW |