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

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 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 {
MuVen 2014/09/10 15:40:58 Done. Comments by dana: (probably wanna rename th
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // A non-solid-color scrollbar should have requested two textures. 743 // A non-solid-color scrollbar should have requested two textures.
745 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); 744 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
746 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 745 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
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
753 void TestResourceRelease() {
754 layer_tree_host_.reset(
755 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
756
757 gfx::Point scrollbar_location(0, 185);
758 scoped_refptr<Layer> layer_tree_root = Layer::Create();
759 scoped_refptr<Layer> content_layer = Layer::Create();
760 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
761 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
762
763 layer_tree_root->AddChild(content_layer);
764 layer_tree_root->AddChild(scrollbar_layer);
765
766 layer_tree_host_->SetRootLayer(layer_tree_root);
767
768 scrollbar_layer->SetIsDrawable(true);
769 scrollbar_layer->SetBounds(gfx::Size(100, 15));
770 scrollbar_layer->SetPosition(scrollbar_location);
771 layer_tree_root->SetBounds(gfx::Size(100, 200));
772 content_layer->SetBounds(gfx::Size(100, 200));
773
774 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
775 scrollbar_layer->draw_properties().visible_content_rect =
776 gfx::Rect(0, 0, 100, 200);
777
778 scrollbar_layer->CreateRenderSurface();
779 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
780
781 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
782 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
783
784 ResourceUpdateQueue queue;
785 gfx::Rect screen_space_clip_rect;
786 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
787 scrollbar_layer->SavePaintProperties();
788 scrollbar_layer->Update(&queue, &occlusion_tracker);
MuVen 2014/09/10 15:40:58 FakePaintedScrollbarLayer doesnt have Impl impleme
danakj 2014/09/10 16:15:03 how about verifying the Update return value?
MuVen 2014/09/11 14:07:21 Instead of verifying on Update i have verified on
789 EXPECT_NE(0, scrollbar_layer->track_resource_id());
MuVen 2014/09/10 15:40:58 Need IMPL implementation for this. comments by da
790 EXPECT_NE(0, scrollbar_layer->thumb_resource_id());
791
792 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 0, 0));
793 scrollbar_layer->Update(&queue, &occlusion_tracker);
794 EXPECT_EQ(0, scrollbar_layer->track_resource_id());
795 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id());
796
797 scrollbar_layer->fake_scrollbar()->set_track_rect(
798 gfx::Rect(30, 10, 50, 10));
799 scrollbar_layer->Update(&queue, &occlusion_tracker);
800 EXPECT_NE(0, scrollbar_layer->track_resource_id());
801 EXPECT_NE(0, scrollbar_layer->thumb_resource_id());
802
803 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
804 scrollbar_layer->Update(&queue, &occlusion_tracker);
805 EXPECT_NE(0, scrollbar_layer->track_resource_id());
MuVen 2014/09/10 15:40:58 I feel it should be present to give user an idea t
danakj 2014/09/10 16:15:03 Oh,I agree. I meant another test case that shows t
MuVen 2014/09/11 14:07:21 Done.
806 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id());
807
808 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
809
810 scrollbar_layer->ClearRenderSurface();
811 }
812
754 protected: 813 protected:
755 FakeLayerTreeHostClient fake_client_; 814 FakeLayerTreeHostClient fake_client_;
756 LayerTreeSettings layer_tree_settings_; 815 LayerTreeSettings layer_tree_settings_;
757 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 816 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
758 }; 817 };
759 818
760 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 819 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
761 bool use_solid_color_scrollbars = false; 820 bool use_solid_color_scrollbars = false;
762 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 821 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
763 int num_updates[3] = {1, 5, 10}; 822 int num_updates[3] = {1, 5, 10};
764 for (int j = 0; j < 3; j++) { 823 for (int j = 0; j < 3; j++) {
765 TestResourceUpload(num_updates[j], 824 TestResourceUpload(num_updates[j],
766 2, 825 2,
767 num_updates[j] * 2, 826 num_updates[j] * 2,
768 (num_updates[j] - 1) * 2, 827 (num_updates[j] - 1) * 2,
769 use_solid_color_scrollbars); 828 use_solid_color_scrollbars);
770 } 829 }
771 } 830 }
772 831
773 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 832 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
833 SolidColorNoResourceUpload) {
774 bool use_solid_color_scrollbars = true; 834 bool use_solid_color_scrollbars = true;
775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 835 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 836 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
777 } 837 }
778 838
839 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
840 ReleaseThumbAndTrackUIResources) {
841 TestResourceRelease();
MuVen 2014/09/10 15:40:58 I have added the test function to ScrollbarLayerTe
danakj 2014/09/10 16:15:03 The TestResourceUpdate code makes sense in the cla
MuVen 2014/09/11 14:07:21 Done.
842 }
843
779 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 844 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
780 public: 845 public:
781 ScaledScrollbarLayerTestResourceCreation() 846 ScaledScrollbarLayerTestResourceCreation()
782 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 847 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
783 848
784 void TestResourceUpload(const float test_scale) { 849 void TestResourceUpload(const float test_scale) {
785 layer_tree_host_.reset( 850 layer_tree_host_.reset(
786 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 851 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
787 852
788 gfx::Point scrollbar_location(0, 185); 853 gfx::Point scrollbar_location(0, 185);
789 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 854 scoped_refptr<Layer> layer_tree_root = Layer::Create();
790 scoped_refptr<Layer> content_layer = Layer::Create(); 855 scoped_refptr<Layer> content_layer = Layer::Create();
791 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 856 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
792 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 857 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
793 858
794 layer_tree_root->AddChild(content_layer); 859 layer_tree_root->AddChild(content_layer);
795 layer_tree_root->AddChild(scrollbar_layer); 860 layer_tree_root->AddChild(scrollbar_layer);
796 861
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height()); 905 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height());
841 906
842 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 907 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
843 908
844 scrollbar_layer->ClearRenderSurface(); 909 scrollbar_layer->ClearRenderSurface();
845 } 910 }
846 911
847 protected: 912 protected:
848 FakeLayerTreeHostClient fake_client_; 913 FakeLayerTreeHostClient fake_client_;
849 LayerTreeSettings layer_tree_settings_; 914 LayerTreeSettings layer_tree_settings_;
850 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 915 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
851 }; 916 };
852 917
853 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 918 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
854 // Pick a test scale that moves the scrollbar's (non-zero) position to 919 // Pick a test scale that moves the scrollbar's (non-zero) position to
855 // a non-pixel-aligned location. 920 // a non-pixel-aligned location.
856 TestResourceUpload(.041f); 921 TestResourceUpload(.041f);
857 TestResourceUpload(1.41f); 922 TestResourceUpload(1.41f);
858 TestResourceUpload(4.1f); 923 TestResourceUpload(4.1f);
859 } 924 }
860 925
861 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { 926 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
862 public: 927 public:
863 ScaledScrollbarLayerTestScaledRasterization() 928 ScaledScrollbarLayerTestScaledRasterization()
864 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 929 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
865 930
866 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 931 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
867 layer_tree_host_.reset( 932 layer_tree_host_.reset(
868 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 933 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
869 934
870 bool paint_during_update = true; 935 bool paint_during_update = true;
871 bool has_thumb = false; 936 bool has_thumb = false;
872 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 937 scoped_refptr<Layer> layer_tree_root = Layer::Create();
873 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 938 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
874 FakePaintedScrollbarLayer::Create(paint_during_update, 939 FakePaintedScrollbarLayer::Create(paint_during_update,
875 has_thumb, 940 has_thumb,
876 layer_tree_root->id()); 941 layer_tree_root->id());
877 942
878 layer_tree_root->AddChild(scrollbar_layer); 943 layer_tree_root->AddChild(scrollbar_layer);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 // On Android, Skia uses ABGR 1001 // On Android, Skia uses ABGR
937 static SkColor argb_to_skia(SkColor c) { 1002 static SkColor argb_to_skia(SkColor c) {
938 return (SkColorGetA(c) << SK_A32_SHIFT) | 1003 return (SkColorGetA(c) << SK_A32_SHIFT) |
939 (SkColorGetR(c) << SK_R32_SHIFT) | 1004 (SkColorGetR(c) << SK_R32_SHIFT) |
940 (SkColorGetG(c) << SK_G32_SHIFT) | 1005 (SkColorGetG(c) << SK_G32_SHIFT) |
941 (SkColorGetB(c) << SK_B32_SHIFT); 1006 (SkColorGetB(c) << SK_B32_SHIFT);
942 } 1007 }
943 1008
944 FakeLayerTreeHostClient fake_client_; 1009 FakeLayerTreeHostClient fake_client_;
945 LayerTreeSettings layer_tree_settings_; 1010 LayerTreeSettings layer_tree_settings_;
946 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 1011 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
947 }; 1012 };
948 1013
949 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { 1014 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
950 // Try rasterization at coordinates and scale that caused problematic 1015 // Try rasterization at coordinates and scale that caused problematic
951 // rounding and clipping errors. 1016 // rounding and clipping errors.
952 // Vertical Scrollbars. 1017 // Vertical Scrollbars.
953 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1018 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
954 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1019 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
955 1020
956 // Horizontal Scrollbars. 1021 // Horizontal Scrollbars.
957 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1022 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
958 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1023 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
959 } 1024 }
960 1025
961 } // namespace 1026 } // namespace
962 } // namespace cc 1027 } // 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