| 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" |
| 29 #include "cc/test/test_task_graph_runner.h" | 30 #include "cc/test/test_task_graph_runner.h" |
| 30 #include "cc/test/test_web_graphics_context_3d.h" | 31 #include "cc/test/test_web_graphics_context_3d.h" |
| 31 #include "cc/trees/effect_node.h" | 32 #include "cc/trees/effect_node.h" |
| 32 #include "cc/trees/layer_tree_host.h" | 33 #include "cc/trees/layer_tree_host.h" |
| 33 #include "cc/trees/layer_tree_impl.h" | 34 #include "cc/trees/layer_tree_impl.h" |
| 34 #include "cc/trees/occlusion_tracker.h" | 35 #include "cc/trees/occlusion_tracker.h" |
| 35 #include "cc/trees/scroll_node.h" | 36 #include "cc/trees/scroll_node.h" |
| 36 #include "cc/trees/single_thread_proxy.h" | 37 #include "cc/trees/single_thread_proxy.h" |
| 37 #include "cc/trees/tree_synchronizer.h" | 38 #include "cc/trees/tree_synchronizer.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 // The vertical adjustment factor has two effects: | 734 // The vertical adjustment factor has two effects: |
| 734 // 1.) Moves the horizontal scrollbar down | 735 // 1.) Moves the horizontal scrollbar down |
| 735 // 2.) Increases the vertical scrollbar's effective track length which both | 736 // 2.) Increases the vertical scrollbar's effective track length which both |
| 736 // increases the thumb's length and its position within the track. | 737 // increases the thumb's length and its position within the track. |
| 737 EXPECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), | 738 EXPECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), |
| 738 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 739 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 739 EXPECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), | 740 EXPECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), |
| 740 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 741 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 741 } | 742 } |
| 742 | 743 |
| 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 | |
| 797 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { | 744 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { |
| 798 public: | 745 public: |
| 799 void TestResourceUpload(int num_updates, | 746 void TestResourceUpload(int num_updates, |
| 800 size_t expected_resources, | 747 size_t expected_resources, |
| 801 int expected_created, | 748 int expected_created, |
| 802 int expected_deleted, | 749 int expected_deleted, |
| 803 bool use_solid_color_scrollbar) { | 750 bool use_solid_color_scrollbar) { |
| 804 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 751 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
| 805 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 752 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 806 scoped_refptr<Layer> content_layer = Layer::Create(); | 753 scoped_refptr<Layer> content_layer = Layer::Create(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 layer_tree_->SetRootLayer(layer_tree_root); | 967 layer_tree_->SetRootLayer(layer_tree_root); |
| 1021 | 968 |
| 1022 scrollbar_layer->SetIsDrawable(true); | 969 scrollbar_layer->SetIsDrawable(true); |
| 1023 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 970 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 1024 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); | 971 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
| 1025 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 972 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| 1026 content_layer->SetBounds(gfx::Size(100, 200)); | 973 content_layer->SetBounds(gfx::Size(100, 200)); |
| 1027 scrollbar_layer->set_visible_layer_rect( | 974 scrollbar_layer->set_visible_layer_rect( |
| 1028 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); | 975 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); |
| 1029 | 976 |
| 1030 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
| 1031 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 977 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
| 1032 | 978 |
| 1033 layer_tree_->SetDeviceScaleFactor(test_scale); | 979 layer_tree_->SetDeviceScaleFactor(test_scale); |
| 1034 | 980 |
| 1035 scrollbar_layer->SavePaintProperties(); | 981 scrollbar_layer->SavePaintProperties(); |
| 1036 scrollbar_layer->Update(); | 982 scrollbar_layer->Update(); |
| 1037 | 983 |
| 1038 // Verify that we have not generated any content uploads that are larger | 984 // Verify that we have not generated any content uploads that are larger |
| 1039 // than their destination textures. | 985 // than their destination textures. |
| 1040 | 986 |
| 1041 gfx::Size track_size = layer_tree_host_->ui_resource_size( | 987 gfx::Size track_size = layer_tree_host_->ui_resource_size( |
| 1042 scrollbar_layer->track_resource_id()); | 988 scrollbar_layer->track_resource_id()); |
| 1043 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( | 989 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( |
| 1044 scrollbar_layer->thumb_resource_id()); | 990 scrollbar_layer->thumb_resource_id()); |
| 1045 | 991 |
| 1046 EXPECT_LE(track_size.width(), | 992 EXPECT_LE(track_size.width(), |
| 1047 scrollbar_layer->internal_content_bounds().width()); | 993 scrollbar_layer->internal_content_bounds().width()); |
| 1048 EXPECT_LE(track_size.height(), | 994 EXPECT_LE(track_size.height(), |
| 1049 scrollbar_layer->internal_content_bounds().height()); | 995 scrollbar_layer->internal_content_bounds().height()); |
| 1050 EXPECT_LE(thumb_size.width(), | 996 EXPECT_LE(thumb_size.width(), |
| 1051 scrollbar_layer->internal_content_bounds().width()); | 997 scrollbar_layer->internal_content_bounds().width()); |
| 1052 EXPECT_LE(thumb_size.height(), | 998 EXPECT_LE(thumb_size.height(), |
| 1053 scrollbar_layer->internal_content_bounds().height()); | 999 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()); | |
| 1064 } | 1000 } |
| 1065 }; | 1001 }; |
| 1066 | 1002 |
| 1067 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 1003 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 1068 // Pick a test scale that moves the scrollbar's (non-zero) position to | 1004 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 1069 // a non-pixel-aligned location. | 1005 // a non-pixel-aligned location. |
| 1070 TestResourceUpload(.041f); | 1006 TestResourceUpload(.041f); |
| 1071 TestResourceUpload(1.41f); | 1007 TestResourceUpload(1.41f); |
| 1072 TestResourceUpload(4.1f); | 1008 TestResourceUpload(4.1f); |
| 1073 | 1009 |
| 1074 // Try something extreme to make sure it gets clamped. | 1010 // Try something extreme to be larger than max texture size, and make it a |
| 1075 TestResourceUpload(2147483647.0f); | 1011 // non-integer for funsies. |
| 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); |
| 1076 } | 1017 } |
| 1077 | 1018 |
| 1078 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { | 1019 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { |
| 1079 public: | 1020 public: |
| 1080 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | 1021 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { |
| 1081 bool paint_during_update = true; | 1022 bool paint_during_update = true; |
| 1082 bool has_thumb = false; | 1023 bool has_thumb = false; |
| 1083 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 1024 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 1084 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 1025 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 1085 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, | 1026 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1088 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1148 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1089 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1149 | 1090 |
| 1150 // Horizontal Scrollbars. | 1091 // Horizontal Scrollbars. |
| 1151 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1092 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1152 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1093 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1153 } | 1094 } |
| 1154 | 1095 |
| 1155 } // namespace | 1096 } // namespace |
| 1156 } // namespace cc | 1097 } // namespace cc |
| OLD | NEW |