Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 913133004: cc: Make PaintedScrollbarLayer not use ContentsScalingLayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/containers/hash_tables.h" 5 #include "base/containers/hash_tables.h"
6 #include "cc/animation/scrollbar_animation_controller.h" 6 #include "cc/animation/scrollbar_animation_controller.h"
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/layers/painted_scrollbar_layer.h" 8 #include "cc/layers/painted_scrollbar_layer.h"
9 #include "cc/layers/painted_scrollbar_layer_impl.h" 9 #include "cc/layers/painted_scrollbar_layer_impl.h"
10 #include "cc/layers/scrollbar_layer_interface.h" 10 #include "cc/layers/scrollbar_layer_interface.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 void BeginTest() override { 571 void BeginTest() override {
572 scroll_layer_ = Layer::Create(); 572 scroll_layer_ = Layer::Create();
573 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 573 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
574 574
575 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 575 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
576 scrollbar_layer_ = 576 scrollbar_layer_ =
577 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); 577 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id());
578 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); 578 scrollbar_layer_->SetScrollLayer(scroll_layer_->id());
579 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 579 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
580 scrollbar_layer_->SetBounds(bounds_); 580 scrollbar_layer_->SetBounds(bounds_);
581 scrollbar_layer_->SetIsDrawable(true);
581 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 582 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
582 583
583 PostSetNeedsCommitToMainThread(); 584 PostSetNeedsCommitToMainThread();
584 } 585 }
585 586
586 void DidCommitAndDrawFrame() override { 587 void DidCommitAndDrawFrame() override {
587 const int kMaxTextureSize = 588 const int kMaxTextureSize =
588 layer_tree_host()->GetRendererCapabilities().max_texture_size; 589 layer_tree_host()->GetRendererCapabilities().max_texture_size;
589 590
590 // Check first that we're actually testing something. 591 // Check first that we're actually testing something.
591 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 592 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize);
592 593
593 EXPECT_EQ(scrollbar_layer_->content_bounds().width(), 594 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().width(),
594 kMaxTextureSize - 1); 595 kMaxTextureSize - 1);
595 EXPECT_EQ(scrollbar_layer_->content_bounds().height(), 596 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().height(),
596 kMaxTextureSize - 1); 597 kMaxTextureSize - 1);
597 598
598 EndTest(); 599 EndTest();
599 } 600 }
600 601
601 void AfterTest() override {} 602 void AfterTest() override {}
602 603
603 private: 604 private:
604 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; 605 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_;
605 scoped_refptr<Layer> scroll_layer_; 606 scoped_refptr<Layer> scroll_layer_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 private: 676 private:
676 typedef base::hash_map<UIResourceId, UIResourceBitmap> 677 typedef base::hash_map<UIResourceId, UIResourceBitmap>
677 UIResourceBitmapMap; 678 UIResourceBitmapMap;
678 UIResourceBitmapMap ui_resource_bitmap_map_; 679 UIResourceBitmapMap ui_resource_bitmap_map_;
679 680
680 int next_id_; 681 int next_id_;
681 int total_ui_resource_created_; 682 int total_ui_resource_created_;
682 int total_ui_resource_deleted_; 683 int total_ui_resource_deleted_;
683 }; 684 };
684 685
685 class ScrollbarLayerTestResourceCreationAndRelease : public testing::Test { 686 class ScrollbarLayerResourceTest : public testing::Test {
686 public: 687 public:
687 ScrollbarLayerTestResourceCreationAndRelease() 688 ScrollbarLayerResourceTest()
688 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 689 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {
690 layer_tree_settings_.single_thread_proxy_scheduler = false;
691 layer_tree_host_.reset(
692 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
693 fake_client_.SetLayerTreeHost(layer_tree_host_.get());
694 // Force output surface creation for renderer capabilities.
enne (OOO) 2015/02/11 21:41:59 Previously the MaxTextureSize (which reached into
695 layer_tree_host_->Composite(base::TimeTicks());
696 EXPECT_FALSE(layer_tree_host_->output_surface_lost());
697 }
689 698
699 protected:
700 FakeLayerTreeHostClient fake_client_;
701 LayerTreeSettings layer_tree_settings_;
702 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
703 };
704
705 class ScrollbarLayerTestResourceCreationAndRelease
706 : public ScrollbarLayerResourceTest {
707 public:
690 void TestResourceUpload(int num_updates, 708 void TestResourceUpload(int num_updates,
691 size_t expected_resources, 709 size_t expected_resources,
692 int expected_created, 710 int expected_created,
693 int expected_deleted, 711 int expected_deleted,
694 bool use_solid_color_scrollbar) { 712 bool use_solid_color_scrollbar) {
695 layer_tree_host_.reset(
696 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
697
698 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 713 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
699 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 714 scoped_refptr<Layer> layer_tree_root = Layer::Create();
700 scoped_refptr<Layer> content_layer = Layer::Create(); 715 scoped_refptr<Layer> content_layer = Layer::Create();
701 scoped_refptr<Layer> scrollbar_layer; 716 scoped_refptr<Layer> scrollbar_layer;
702 if (use_solid_color_scrollbar) { 717 if (use_solid_color_scrollbar) {
703 const int kThumbThickness = 3; 718 const int kThumbThickness = 3;
704 const int kTrackStart = 0; 719 const int kTrackStart = 0;
705 const bool kIsLeftSideVerticalScrollbar = false; 720 const bool kIsLeftSideVerticalScrollbar = false;
706 scrollbar_layer = 721 scrollbar_layer =
707 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 722 SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 757
743 // A non-solid-color scrollbar should have requested two textures. 758 // A non-solid-color scrollbar should have requested two textures.
744 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); 759 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
745 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 760 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
746 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 761 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
747 762
748 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 763 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
749 764
750 scrollbar_layer->ClearRenderSurface(); 765 scrollbar_layer->ClearRenderSurface();
751 } 766 }
752
753 protected:
754 FakeLayerTreeHostClient fake_client_;
755 LayerTreeSettings layer_tree_settings_;
756 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
757 }; 767 };
758 768
759 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) { 769 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
760 bool use_solid_color_scrollbars = false; 770 bool use_solid_color_scrollbars = false;
761 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 771 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
762 int num_updates[3] = {1, 5, 10}; 772 int num_updates[3] = {1, 5, 10};
773 int created = 0;
774 int deleted = 0;
763 for (int j = 0; j < 3; j++) { 775 for (int j = 0; j < 3; j++) {
764 TestResourceUpload(num_updates[j], 776 created += num_updates[j] * 2;
enne (OOO) 2015/02/11 21:41:59 This test used to recreate the LTH every time, but
765 2, 777 deleted = created - 2;
766 num_updates[j] * 2, 778 TestResourceUpload(num_updates[j], 2, created, deleted,
767 (num_updates[j] - 1) * 2,
768 use_solid_color_scrollbars); 779 use_solid_color_scrollbars);
769 } 780 }
770 } 781 }
771 782
772 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, 783 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
773 SolidColorNoResourceUpload) { 784 SolidColorNoResourceUpload) {
774 bool use_solid_color_scrollbars = true; 785 bool use_solid_color_scrollbars = true;
775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 786 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 787 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
777 } 788 }
778 789
779 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 790 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) {
780 FakeLayerTreeHostClient fake_client_(FakeLayerTreeHostClient::DIRECT_3D);
781 LayerTreeSettings layer_tree_settings_;
782 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
783
784 layer_tree_host_.reset(
785 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
786
787 gfx::Point scrollbar_location(0, 185); 791 gfx::Point scrollbar_location(0, 185);
788 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 792 scoped_refptr<Layer> layer_tree_root = Layer::Create();
789 scoped_refptr<Layer> content_layer = Layer::Create(); 793 scoped_refptr<Layer> content_layer = Layer::Create();
790 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 794 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
791 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 795 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
792 796
793 layer_tree_root->AddChild(content_layer); 797 layer_tree_root->AddChild(content_layer);
794 layer_tree_root->AddChild(scrollbar_layer); 798 layer_tree_root->AddChild(scrollbar_layer);
795 799
796 layer_tree_host_->SetRootLayer(layer_tree_root); 800 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_NE(0, scrollbar_layer->track_resource_id()); 915 EXPECT_NE(0, scrollbar_layer->track_resource_id());
912 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id()); 916 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id());
913 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount()); 917 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount());
914 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 918 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
915 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 919 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
916 920
917 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 921 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
918 scrollbar_layer->ClearRenderSurface(); 922 scrollbar_layer->ClearRenderSurface();
919 } 923 }
920 924
921 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 925 class ScaledScrollbarLayerTestResourceCreation
926 : public ScrollbarLayerResourceTest {
922 public: 927 public:
923 ScaledScrollbarLayerTestResourceCreation()
924 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
925
926 void TestResourceUpload(const float test_scale) { 928 void TestResourceUpload(const float test_scale) {
927 layer_tree_host_.reset(
928 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
929
930 gfx::Point scrollbar_location(0, 185); 929 gfx::Point scrollbar_location(0, 185);
931 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 930 scoped_refptr<Layer> layer_tree_root = Layer::Create();
932 scoped_refptr<Layer> content_layer = Layer::Create(); 931 scoped_refptr<Layer> content_layer = Layer::Create();
933 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 932 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
934 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 933 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
935 934
936 layer_tree_root->AddChild(content_layer); 935 layer_tree_root->AddChild(content_layer);
937 layer_tree_root->AddChild(scrollbar_layer); 936 layer_tree_root->AddChild(scrollbar_layer);
938 937
939 layer_tree_host_->SetRootLayer(layer_tree_root); 938 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 29 matching lines...) Expand all
969 scrollbar_layer->Update(&queue, &occlusion_tracker); 968 scrollbar_layer->Update(&queue, &occlusion_tracker);
970 969
971 // Verify that we have not generated any content uploads that are larger 970 // Verify that we have not generated any content uploads that are larger
972 // than their destination textures. 971 // than their destination textures.
973 972
974 gfx::Size track_size = layer_tree_host_->ui_resource_size( 973 gfx::Size track_size = layer_tree_host_->ui_resource_size(
975 scrollbar_layer->track_resource_id()); 974 scrollbar_layer->track_resource_id());
976 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( 975 gfx::Size thumb_size = layer_tree_host_->ui_resource_size(
977 scrollbar_layer->thumb_resource_id()); 976 scrollbar_layer->thumb_resource_id());
978 977
979 EXPECT_LE(track_size.width(), scrollbar_layer->content_bounds().width()); 978 EXPECT_LE(track_size.width(),
980 EXPECT_LE(track_size.height(), scrollbar_layer->content_bounds().height()); 979 scrollbar_layer->internal_content_bounds().width());
981 EXPECT_LE(thumb_size.width(), scrollbar_layer->content_bounds().width()); 980 EXPECT_LE(track_size.height(),
982 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height()); 981 scrollbar_layer->internal_content_bounds().height());
982 EXPECT_LE(thumb_size.width(),
983 scrollbar_layer->internal_content_bounds().width());
984 EXPECT_LE(thumb_size.height(),
985 scrollbar_layer->internal_content_bounds().height());
983 986
984 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 987 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
985 988
986 scrollbar_layer->ClearRenderSurface(); 989 scrollbar_layer->ClearRenderSurface();
987 } 990 }
988
989 protected:
990 FakeLayerTreeHostClient fake_client_;
991 LayerTreeSettings layer_tree_settings_;
992 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
993 }; 991 };
994 992
995 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 993 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
996 // Pick a test scale that moves the scrollbar's (non-zero) position to 994 // Pick a test scale that moves the scrollbar's (non-zero) position to
997 // a non-pixel-aligned location. 995 // a non-pixel-aligned location.
998 TestResourceUpload(.041f); 996 TestResourceUpload(.041f);
999 TestResourceUpload(1.41f); 997 TestResourceUpload(1.41f);
1000 TestResourceUpload(4.1f); 998 TestResourceUpload(4.1f);
1001 } 999 }
1002 1000
1003 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { 1001 class ScaledScrollbarLayerTestScaledRasterization
1002 : public ScrollbarLayerResourceTest {
1004 public: 1003 public:
1005 ScaledScrollbarLayerTestScaledRasterization()
1006 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
1007
1008 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 1004 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
1009 layer_tree_host_.reset(
1010 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
1011
1012 bool paint_during_update = true; 1005 bool paint_during_update = true;
1013 bool has_thumb = false; 1006 bool has_thumb = false;
1014 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1007 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1015 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1008 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1016 FakePaintedScrollbarLayer::Create(paint_during_update, 1009 FakePaintedScrollbarLayer::Create(paint_during_update,
1017 has_thumb, 1010 has_thumb,
1018 layer_tree_root->id()); 1011 layer_tree_root->id());
1019 1012
1020 layer_tree_root->AddChild(scrollbar_layer); 1013 layer_tree_root->AddChild(scrollbar_layer);
1021 1014
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1068 }
1076 1069
1077 protected: 1070 protected:
1078 // On Android, Skia uses ABGR 1071 // On Android, Skia uses ABGR
1079 static SkColor argb_to_skia(SkColor c) { 1072 static SkColor argb_to_skia(SkColor c) {
1080 return (SkColorGetA(c) << SK_A32_SHIFT) | 1073 return (SkColorGetA(c) << SK_A32_SHIFT) |
1081 (SkColorGetR(c) << SK_R32_SHIFT) | 1074 (SkColorGetR(c) << SK_R32_SHIFT) |
1082 (SkColorGetG(c) << SK_G32_SHIFT) | 1075 (SkColorGetG(c) << SK_G32_SHIFT) |
1083 (SkColorGetB(c) << SK_B32_SHIFT); 1076 (SkColorGetB(c) << SK_B32_SHIFT);
1084 } 1077 }
1085
1086 FakeLayerTreeHostClient fake_client_;
1087 LayerTreeSettings layer_tree_settings_;
1088 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
1089 }; 1078 };
1090 1079
1091 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { 1080 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
1092 // Try rasterization at coordinates and scale that caused problematic 1081 // Try rasterization at coordinates and scale that caused problematic
1093 // rounding and clipping errors. 1082 // rounding and clipping errors.
1094 // Vertical Scrollbars. 1083 // Vertical Scrollbars.
1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1084 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1085 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1097 1086
1098 // Horizontal Scrollbars. 1087 // Horizontal Scrollbars.
1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1088 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1089 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1101 } 1090 }
1102 1091
1103 } // namespace 1092 } // namespace
1104 } // namespace cc 1093 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698