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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <unordered_map> | 7 #include <unordered_map> |
8 | 8 |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
11 #include "cc/input/scrollbar_animation_controller.h" | 11 #include "cc/input/scrollbar_animation_controller.h" |
12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
13 #include "cc/layers/painted_scrollbar_layer.h" | 13 #include "cc/layers/painted_scrollbar_layer.h" |
14 #include "cc/layers/painted_scrollbar_layer_impl.h" | 14 #include "cc/layers/painted_scrollbar_layer_impl.h" |
15 #include "cc/layers/scrollbar_layer_interface.h" | 15 #include "cc/layers/scrollbar_layer_interface.h" |
16 #include "cc/layers/solid_color_scrollbar_layer.h" | 16 #include "cc/layers/solid_color_scrollbar_layer.h" |
17 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 17 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
18 #include "cc/quads/solid_color_draw_quad.h" | 18 #include "cc/quads/solid_color_draw_quad.h" |
19 #include "cc/test/fake_impl_task_runner_provider.h" | 19 #include "cc/test/fake_impl_task_runner_provider.h" |
20 #include "cc/test/fake_layer_tree_host.h" | 20 #include "cc/test/fake_layer_tree_host.h" |
21 #include "cc/test/fake_layer_tree_host_client.h" | 21 #include "cc/test/fake_layer_tree_host_client.h" |
22 #include "cc/test/fake_layer_tree_host_impl.h" | 22 #include "cc/test/fake_layer_tree_host_impl.h" |
23 #include "cc/test/fake_painted_scrollbar_layer.h" | 23 #include "cc/test/fake_painted_scrollbar_layer.h" |
24 #include "cc/test/fake_scrollbar.h" | 24 #include "cc/test/fake_scrollbar.h" |
25 #include "cc/test/geometry_test_utils.h" | 25 #include "cc/test/geometry_test_utils.h" |
26 #include "cc/test/layer_tree_test.h" | 26 #include "cc/test/layer_tree_test.h" |
27 #include "cc/test/mock_occlusion_tracker.h" | 27 #include "cc/test/mock_occlusion_tracker.h" |
28 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 28 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
29 #include "cc/test/test_context_provider.h" | |
30 #include "cc/test/test_task_graph_runner.h" | 29 #include "cc/test/test_task_graph_runner.h" |
31 #include "cc/test/test_web_graphics_context_3d.h" | 30 #include "cc/test/test_web_graphics_context_3d.h" |
32 #include "cc/trees/effect_node.h" | 31 #include "cc/trees/effect_node.h" |
33 #include "cc/trees/layer_tree_host.h" | 32 #include "cc/trees/layer_tree_host.h" |
34 #include "cc/trees/layer_tree_impl.h" | 33 #include "cc/trees/layer_tree_impl.h" |
35 #include "cc/trees/occlusion_tracker.h" | 34 #include "cc/trees/occlusion_tracker.h" |
36 #include "cc/trees/scroll_node.h" | 35 #include "cc/trees/scroll_node.h" |
37 #include "cc/trees/single_thread_proxy.h" | 36 #include "cc/trees/single_thread_proxy.h" |
38 #include "cc/trees/tree_synchronizer.h" | 37 #include "cc/trees/tree_synchronizer.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // The vertical adjustment factor has two effects: | 733 // The vertical adjustment factor has two effects: |
735 // 1.) Moves the horizontal scrollbar down | 734 // 1.) Moves the horizontal scrollbar down |
736 // 2.) Increases the vertical scrollbar's effective track length which both | 735 // 2.) Increases the vertical scrollbar's effective track length which both |
737 // increases the thumb's length and its position within the track. | 736 // increases the thumb's length and its position within the track. |
738 EXPECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), | 737 EXPECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), |
739 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 738 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
740 EXPECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), | 739 EXPECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), |
741 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 740 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
742 } | 741 } |
743 | 742 |
| 743 class ScrollbarLayerTestWithFixedScrollbarBounds : public LayerTreeTest { |
| 744 public: |
| 745 ScrollbarLayerTestWithFixedScrollbarBounds() {} |
| 746 |
| 747 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } |
| 748 |
| 749 void BeginTest() override { |
| 750 scroll_layer_ = Layer::Create(); |
| 751 layer_tree()->root_layer()->AddChild(scroll_layer_); |
| 752 |
| 753 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 754 scrollbar_layer_ = PaintedScrollbarLayer::Create(std::move(scrollbar), |
| 755 scroll_layer_->id()); |
| 756 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); |
| 757 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
| 758 scrollbar_layer_->SetBounds(bounds_); |
| 759 scrollbar_layer_->SetIsDrawable(true); |
| 760 layer_tree()->root_layer()->AddChild(scrollbar_layer_); |
| 761 |
| 762 PostSetNeedsCommitToMainThread(); |
| 763 } |
| 764 |
| 765 void DidCommitAndDrawFrame() override { |
| 766 const int kMaxTextureSize = |
| 767 layer_tree_host()->GetRendererCapabilities().max_texture_size; |
| 768 |
| 769 // Check first that we're actually testing something. |
| 770 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); |
| 771 |
| 772 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().width(), |
| 773 kMaxTextureSize - 1); |
| 774 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().height(), |
| 775 kMaxTextureSize - 1); |
| 776 |
| 777 EndTest(); |
| 778 } |
| 779 |
| 780 void AfterTest() override {} |
| 781 |
| 782 private: |
| 783 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; |
| 784 scoped_refptr<Layer> scroll_layer_; |
| 785 gfx::Size bounds_; |
| 786 }; |
| 787 |
| 788 TEST_F(ScrollbarLayerTestWithFixedScrollbarBounds, MaxTextureSize) { |
| 789 std::unique_ptr<TestWebGraphicsContext3D> context = |
| 790 TestWebGraphicsContext3D::Create(); |
| 791 int max_size = 0; |
| 792 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
| 793 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
| 794 RunTest(CompositorMode::THREADED); |
| 795 } |
| 796 |
744 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { | 797 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { |
745 public: | 798 public: |
746 void TestResourceUpload(int num_updates, | 799 void TestResourceUpload(int num_updates, |
747 size_t expected_resources, | 800 size_t expected_resources, |
748 int expected_created, | 801 int expected_created, |
749 int expected_deleted, | 802 int expected_deleted, |
750 bool use_solid_color_scrollbar) { | 803 bool use_solid_color_scrollbar) { |
751 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 804 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
752 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 805 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
753 scoped_refptr<Layer> content_layer = Layer::Create(); | 806 scoped_refptr<Layer> content_layer = Layer::Create(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 layer_tree_->SetRootLayer(layer_tree_root); | 1020 layer_tree_->SetRootLayer(layer_tree_root); |
968 | 1021 |
969 scrollbar_layer->SetIsDrawable(true); | 1022 scrollbar_layer->SetIsDrawable(true); |
970 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 1023 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
971 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); | 1024 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
972 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 1025 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
973 content_layer->SetBounds(gfx::Size(100, 200)); | 1026 content_layer->SetBounds(gfx::Size(100, 200)); |
974 scrollbar_layer->set_visible_layer_rect( | 1027 scrollbar_layer->set_visible_layer_rect( |
975 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); | 1028 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); |
976 | 1029 |
| 1030 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
977 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 1031 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
978 | 1032 |
979 layer_tree_->SetDeviceScaleFactor(test_scale); | 1033 layer_tree_->SetDeviceScaleFactor(test_scale); |
980 | 1034 |
981 scrollbar_layer->SavePaintProperties(); | 1035 scrollbar_layer->SavePaintProperties(); |
982 scrollbar_layer->Update(); | 1036 scrollbar_layer->Update(); |
983 | 1037 |
984 // Verify that we have not generated any content uploads that are larger | 1038 // Verify that we have not generated any content uploads that are larger |
985 // than their destination textures. | 1039 // than their destination textures. |
986 | 1040 |
987 gfx::Size track_size = layer_tree_host_->ui_resource_size( | 1041 gfx::Size track_size = layer_tree_host_->ui_resource_size( |
988 scrollbar_layer->track_resource_id()); | 1042 scrollbar_layer->track_resource_id()); |
989 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( | 1043 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( |
990 scrollbar_layer->thumb_resource_id()); | 1044 scrollbar_layer->thumb_resource_id()); |
991 | 1045 |
992 EXPECT_LE(track_size.width(), | 1046 EXPECT_LE(track_size.width(), |
993 scrollbar_layer->internal_content_bounds().width()); | 1047 scrollbar_layer->internal_content_bounds().width()); |
994 EXPECT_LE(track_size.height(), | 1048 EXPECT_LE(track_size.height(), |
995 scrollbar_layer->internal_content_bounds().height()); | 1049 scrollbar_layer->internal_content_bounds().height()); |
996 EXPECT_LE(thumb_size.width(), | 1050 EXPECT_LE(thumb_size.width(), |
997 scrollbar_layer->internal_content_bounds().width()); | 1051 scrollbar_layer->internal_content_bounds().width()); |
998 EXPECT_LE(thumb_size.height(), | 1052 EXPECT_LE(thumb_size.height(), |
999 scrollbar_layer->internal_content_bounds().height()); | 1053 scrollbar_layer->internal_content_bounds().height()); |
| 1054 EXPECT_LE(track_size.width(), |
| 1055 layer_tree_host_->GetRendererCapabilities().max_texture_size); |
| 1056 EXPECT_LE(track_size.height(), |
| 1057 layer_tree_host_->GetRendererCapabilities().max_texture_size); |
| 1058 EXPECT_LE(thumb_size.width(), |
| 1059 layer_tree_host_->GetRendererCapabilities().max_texture_size); |
| 1060 EXPECT_LE(thumb_size.height(), |
| 1061 layer_tree_host_->GetRendererCapabilities().max_texture_size); |
| 1062 |
| 1063 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
1000 } | 1064 } |
1001 }; | 1065 }; |
1002 | 1066 |
1003 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 1067 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
1004 // Pick a test scale that moves the scrollbar's (non-zero) position to | 1068 // Pick a test scale that moves the scrollbar's (non-zero) position to |
1005 // a non-pixel-aligned location. | 1069 // a non-pixel-aligned location. |
1006 TestResourceUpload(.041f); | 1070 TestResourceUpload(.041f); |
1007 TestResourceUpload(1.41f); | 1071 TestResourceUpload(1.41f); |
1008 TestResourceUpload(4.1f); | 1072 TestResourceUpload(4.1f); |
1009 | 1073 |
1010 // Try something extreme to be larger than max texture size, and make it a | 1074 // Try something extreme to make sure it gets clamped. |
1011 // non-integer for funsies. | 1075 TestResourceUpload(2147483647.0f); |
1012 scoped_refptr<TestContextProvider> context = TestContextProvider::Create(); | |
1013 context->BindToCurrentThread(); | |
1014 int max_texture_size = 0; | |
1015 context->ContextGL()->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | |
1016 TestResourceUpload(max_texture_size / 9.9f); | |
1017 } | 1076 } |
1018 | 1077 |
1019 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { | 1078 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { |
1020 public: | 1079 public: |
1021 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | 1080 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { |
1022 bool paint_during_update = true; | 1081 bool paint_during_update = true; |
1023 bool has_thumb = false; | 1082 bool has_thumb = false; |
1024 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 1083 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
1025 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 1084 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
1026 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, | 1085 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1147 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
1089 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1148 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
1090 | 1149 |
1091 // Horizontal Scrollbars. | 1150 // Horizontal Scrollbars. |
1092 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1151 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
1093 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1152 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
1094 } | 1153 } |
1095 | 1154 |
1096 } // namespace | 1155 } // namespace |
1097 } // namespace cc | 1156 } // namespace cc |
OLD | NEW |