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

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

Issue 537943003: Releasing Track & Thumb UIResources based on their Geometry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments and modified unittest Created 6 years, 3 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { 620 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) {
621 scoped_ptr<TestWebGraphicsContext3D> context = 621 scoped_ptr<TestWebGraphicsContext3D> context =
622 TestWebGraphicsContext3D::Create(); 622 TestWebGraphicsContext3D::Create();
623 int max_size = 0; 623 int max_size = 0;
624 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 624 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
625 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 625 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
626 RunTest(true, true, true); 626 RunTest(true, true, true);
627 } 627 }
628 628
629 class MockLayerTreeHost : public LayerTreeHost { 629 class FakeLayerTreeHost : public LayerTreeHost {
630 public: 630 public:
631 MockLayerTreeHost(FakeLayerTreeHostClient* client, 631 FakeLayerTreeHost(FakeLayerTreeHostClient* client,
632 const LayerTreeSettings& settings) 632 const LayerTreeSettings& settings)
633 : LayerTreeHost(client, NULL, settings), 633 : LayerTreeHost(client, NULL, settings),
634 next_id_(1), 634 next_id_(1),
635 total_ui_resource_created_(0), 635 total_ui_resource_created_(0),
636 total_ui_resource_deleted_(0) { 636 total_ui_resource_deleted_(0) {
637 InitializeSingleThreaded(client, base::MessageLoopProxy::current()); 637 InitializeSingleThreaded(client, base::MessageLoopProxy::current());
638 } 638 }
639 639
640 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE { 640 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE {
641 total_ui_resource_created_++; 641 total_ui_resource_created_++;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 private: 675 private:
676 typedef base::hash_map<UIResourceId, UIResourceBitmap> 676 typedef base::hash_map<UIResourceId, UIResourceBitmap>
677 UIResourceBitmapMap; 677 UIResourceBitmapMap;
678 UIResourceBitmapMap ui_resource_bitmap_map_; 678 UIResourceBitmapMap ui_resource_bitmap_map_;
679 679
680 int next_id_; 680 int next_id_;
681 int total_ui_resource_created_; 681 int total_ui_resource_created_;
682 int total_ui_resource_deleted_; 682 int total_ui_resource_deleted_;
683 }; 683 };
684 684
685 685 class ScrollbarLayerTestResourceCreationAndRelease : public testing::Test {
686 class ScrollbarLayerTestResourceCreation : public testing::Test {
687 public: 686 public:
688 ScrollbarLayerTestResourceCreation() 687 ScrollbarLayerTestResourceCreationAndRelease()
689 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 688 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
690 689
691 void TestResourceUpload(int num_updates, 690 void TestResourceUpload(int num_updates,
692 size_t expected_resources, 691 size_t expected_resources,
693 int expected_created, 692 int expected_created,
694 int expected_deleted, 693 int expected_deleted,
695 bool use_solid_color_scrollbar) { 694 bool use_solid_color_scrollbar) {
696 layer_tree_host_.reset( 695 layer_tree_host_.reset(
697 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 696 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
698 697
699 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 698 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
700 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 699 scoped_refptr<Layer> layer_tree_root = Layer::Create();
701 scoped_refptr<Layer> content_layer = Layer::Create(); 700 scoped_refptr<Layer> content_layer = Layer::Create();
702 scoped_refptr<Layer> scrollbar_layer; 701 scoped_refptr<Layer> scrollbar_layer;
703 if (use_solid_color_scrollbar) { 702 if (use_solid_color_scrollbar) {
704 const int kThumbThickness = 3; 703 const int kThumbThickness = 3;
705 const int kTrackStart = 0; 704 const int kTrackStart = 0;
706 const bool kIsLeftSideVerticalScrollbar = false; 705 const bool kIsLeftSideVerticalScrollbar = false;
707 scrollbar_layer = 706 scrollbar_layer =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 746 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
748 747
749 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 748 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
750 749
751 scrollbar_layer->ClearRenderSurface(); 750 scrollbar_layer->ClearRenderSurface();
752 } 751 }
753 752
754 protected: 753 protected:
755 FakeLayerTreeHostClient fake_client_; 754 FakeLayerTreeHostClient fake_client_;
756 LayerTreeSettings layer_tree_settings_; 755 LayerTreeSettings layer_tree_settings_;
757 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 756 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
758 }; 757 };
759 758
760 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 759 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
761 bool use_solid_color_scrollbars = false; 760 bool use_solid_color_scrollbars = false;
762 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 761 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
763 int num_updates[3] = {1, 5, 10}; 762 int num_updates[3] = {1, 5, 10};
764 for (int j = 0; j < 3; j++) { 763 for (int j = 0; j < 3; j++) {
765 TestResourceUpload(num_updates[j], 764 TestResourceUpload(num_updates[j],
766 2, 765 2,
767 num_updates[j] * 2, 766 num_updates[j] * 2,
768 (num_updates[j] - 1) * 2, 767 (num_updates[j] - 1) * 2,
769 use_solid_color_scrollbars); 768 use_solid_color_scrollbars);
770 } 769 }
771 } 770 }
772 771
773 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 772 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
773 SolidColorNoResourceUpload) {
774 bool use_solid_color_scrollbars = true; 774 bool use_solid_color_scrollbars = true;
775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
777 } 777 }
778 778
779 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);
788 scoped_refptr<Layer> layer_tree_root = Layer::Create();
789 scoped_refptr<Layer> content_layer = Layer::Create();
790 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
791 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
792
793 layer_tree_root->AddChild(content_layer);
794 layer_tree_root->AddChild(scrollbar_layer);
795
796 layer_tree_host_->SetRootLayer(layer_tree_root);
797
798 scrollbar_layer->SetIsDrawable(true);
799 scrollbar_layer->SetBounds(gfx::Size(100, 15));
800 scrollbar_layer->SetPosition(scrollbar_location);
801 layer_tree_root->SetBounds(gfx::Size(100, 200));
802 content_layer->SetBounds(gfx::Size(100, 200));
803
804 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
805 scrollbar_layer->draw_properties().visible_content_rect =
806 gfx::Rect(0, 0, 100, 200);
807
808 scrollbar_layer->CreateRenderSurface();
809 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
810
811 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
812 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
813
814 ResourceUpdateQueue queue;
815 gfx::Rect screen_space_clip_rect;
816 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
817 scrollbar_layer->SavePaintProperties();
818 EXPECT_EQ(true, scrollbar_layer->Update(&queue, &occlusion_tracker));
819
820 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 0, 0));
821 EXPECT_EQ(true, scrollbar_layer->Update(&queue, &occlusion_tracker));
822
823 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 0, 0));
824 EXPECT_EQ(false, scrollbar_layer->Update(&queue, &occlusion_tracker));
825
826 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
827 EXPECT_EQ(true, scrollbar_layer->Update(&queue, &occlusion_tracker));
828
829 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
830 EXPECT_EQ(true, scrollbar_layer->Update(&queue, &occlusion_tracker));
831
832 scrollbar_layer->ResetNeedsDisplayForTesting();
833 EXPECT_EQ(false, scrollbar_layer->Update(&queue, &occlusion_tracker));
834
835 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
836 scrollbar_layer->ClearRenderSurface();
837 }
838
779 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 839 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
780 public: 840 public:
781 ScaledScrollbarLayerTestResourceCreation() 841 ScaledScrollbarLayerTestResourceCreation()
782 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 842 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
783 843
784 void TestResourceUpload(const float test_scale) { 844 void TestResourceUpload(const float test_scale) {
785 layer_tree_host_.reset( 845 layer_tree_host_.reset(
786 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 846 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
787 847
788 gfx::Point scrollbar_location(0, 185); 848 gfx::Point scrollbar_location(0, 185);
789 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 849 scoped_refptr<Layer> layer_tree_root = Layer::Create();
790 scoped_refptr<Layer> content_layer = Layer::Create(); 850 scoped_refptr<Layer> content_layer = Layer::Create();
791 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 851 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
792 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 852 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
793 853
794 layer_tree_root->AddChild(content_layer); 854 layer_tree_root->AddChild(content_layer);
795 layer_tree_root->AddChild(scrollbar_layer); 855 layer_tree_root->AddChild(scrollbar_layer);
796 856
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height()); 900 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height());
841 901
842 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 902 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
843 903
844 scrollbar_layer->ClearRenderSurface(); 904 scrollbar_layer->ClearRenderSurface();
845 } 905 }
846 906
847 protected: 907 protected:
848 FakeLayerTreeHostClient fake_client_; 908 FakeLayerTreeHostClient fake_client_;
849 LayerTreeSettings layer_tree_settings_; 909 LayerTreeSettings layer_tree_settings_;
850 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 910 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
851 }; 911 };
852 912
853 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 913 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
854 // Pick a test scale that moves the scrollbar's (non-zero) position to 914 // Pick a test scale that moves the scrollbar's (non-zero) position to
855 // a non-pixel-aligned location. 915 // a non-pixel-aligned location.
856 TestResourceUpload(.041f); 916 TestResourceUpload(.041f);
857 TestResourceUpload(1.41f); 917 TestResourceUpload(1.41f);
858 TestResourceUpload(4.1f); 918 TestResourceUpload(4.1f);
859 } 919 }
860 920
861 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { 921 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
862 public: 922 public:
863 ScaledScrollbarLayerTestScaledRasterization() 923 ScaledScrollbarLayerTestScaledRasterization()
864 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 924 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
865 925
866 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 926 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
867 layer_tree_host_.reset( 927 layer_tree_host_.reset(
868 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 928 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
869 929
870 bool paint_during_update = true; 930 bool paint_during_update = true;
871 bool has_thumb = false; 931 bool has_thumb = false;
872 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 932 scoped_refptr<Layer> layer_tree_root = Layer::Create();
873 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 933 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
874 FakePaintedScrollbarLayer::Create(paint_during_update, 934 FakePaintedScrollbarLayer::Create(paint_during_update,
875 has_thumb, 935 has_thumb,
876 layer_tree_root->id()); 936 layer_tree_root->id());
877 937
878 layer_tree_root->AddChild(scrollbar_layer); 938 layer_tree_root->AddChild(scrollbar_layer);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 // On Android, Skia uses ABGR 996 // On Android, Skia uses ABGR
937 static SkColor argb_to_skia(SkColor c) { 997 static SkColor argb_to_skia(SkColor c) {
938 return (SkColorGetA(c) << SK_A32_SHIFT) | 998 return (SkColorGetA(c) << SK_A32_SHIFT) |
939 (SkColorGetR(c) << SK_R32_SHIFT) | 999 (SkColorGetR(c) << SK_R32_SHIFT) |
940 (SkColorGetG(c) << SK_G32_SHIFT) | 1000 (SkColorGetG(c) << SK_G32_SHIFT) |
941 (SkColorGetB(c) << SK_B32_SHIFT); 1001 (SkColorGetB(c) << SK_B32_SHIFT);
942 } 1002 }
943 1003
944 FakeLayerTreeHostClient fake_client_; 1004 FakeLayerTreeHostClient fake_client_;
945 LayerTreeSettings layer_tree_settings_; 1005 LayerTreeSettings layer_tree_settings_;
946 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 1006 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
947 }; 1007 };
948 1008
949 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { 1009 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
950 // Try rasterization at coordinates and scale that caused problematic 1010 // Try rasterization at coordinates and scale that caused problematic
951 // rounding and clipping errors. 1011 // rounding and clipping errors.
952 // Vertical Scrollbars. 1012 // Vertical Scrollbars.
953 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1013 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
954 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1014 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
955 1015
956 // Horizontal Scrollbars. 1016 // Horizontal Scrollbars.
957 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1017 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
958 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1018 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
959 } 1019 }
960 1020
961 } // namespace 1021 } // namespace
962 } // namespace cc 1022 } // namespace cc
OLDNEW
« cc/layers/painted_scrollbar_layer.cc ('K') | « cc/layers/painted_scrollbar_layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698