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 "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 11 matching lines...) Expand all Loading... | |
22 #include "cc/test/layer_tree_test.h" | 22 #include "cc/test/layer_tree_test.h" |
23 #include "cc/test/mock_quad_culler.h" | 23 #include "cc/test/mock_quad_culler.h" |
24 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
25 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
26 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
27 #include "cc/trees/single_thread_proxy.h" | 27 #include "cc/trees/single_thread_proxy.h" |
28 #include "cc/trees/tree_synchronizer.h" | 28 #include "cc/trees/tree_synchronizer.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 | 31 |
32 using ::testing::_; | |
33 using ::testing::Invoke; | |
34 using ::testing::MatcherInterface; | |
35 using ::testing::Matcher; | |
36 using ::testing::MakeMatcher; | |
37 using ::testing::MatchResultListener; | |
38 | |
32 namespace cc { | 39 namespace cc { |
33 namespace { | 40 namespace { |
34 | 41 |
35 LayerImpl* LayerImplForScrollAreaAndScrollbar( | 42 LayerImpl* LayerImplForScrollAreaAndScrollbar( |
36 FakeLayerTreeHost* host, | 43 FakeLayerTreeHost* host, |
37 scoped_ptr<Scrollbar> scrollbar, | 44 scoped_ptr<Scrollbar> scrollbar, |
38 bool reverse_order, | 45 bool reverse_order, |
39 bool use_solid_color_scrollbar, | 46 bool use_solid_color_scrollbar, |
40 int thumb_thickness) { | 47 int thumb_thickness) { |
41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 48 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 }; | 766 }; |
760 | 767 |
761 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 768 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
762 // Pick a test scale that moves the scrollbar's (non-zero) position to | 769 // Pick a test scale that moves the scrollbar's (non-zero) position to |
763 // a non-pixel-aligned location. | 770 // a non-pixel-aligned location. |
764 TestResourceUpload(.041f); | 771 TestResourceUpload(.041f); |
765 TestResourceUpload(1.41f); | 772 TestResourceUpload(1.41f); |
766 TestResourceUpload(4.1f); | 773 TestResourceUpload(4.1f); |
767 } | 774 } |
768 | 775 |
776 | |
wjmaclean
2014/02/12 18:38:53
Delete extra line space?
bokan
2014/02/13 19:04:57
Done.
| |
777 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { | |
778 class MockScrollbar : public FakeScrollbar { | |
779 public: | |
780 MockScrollbar(bool paint, bool has_thumb, bool is_overlay) | |
781 : FakeScrollbar(paint, has_thumb, is_overlay) | |
782 {} | |
783 | |
784 MOCK_METHOD3(PaintPart, void(SkCanvas* canvas, | |
785 ScrollbarPart part, | |
786 const gfx::Rect& content_rect)); | |
787 }; | |
788 | |
789 class IsCorrectTransformMatcher : public MatcherInterface<SkCanvas*> { | |
790 public: | |
791 IsCorrectTransformMatcher(int tx, int ty, float scale) | |
792 : tx_(tx), | |
793 ty_(ty), | |
794 scale_(scale) | |
795 {} | |
796 virtual bool MatchAndExplain(SkCanvas* arg, | |
797 MatchResultListener* listener) const { | |
798 const SkMatrix& mat = arg->getTotalMatrix(); | |
799 if (!(mat.getType() == | |
800 (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) { | |
801 *listener << "Wrong matrix type - expected Translate and Scale. Got " | |
802 << mat.getType(); | |
803 return false; | |
804 } | |
805 | |
806 if (mat.getScaleX() != SkFloatToScalar(scale_) || | |
807 mat.getScaleY() != SkFloatToScalar(scale_)) { | |
808 *listener << "Incorrect scale. Expected [" << scale_ << ", " << scale_ | |
809 << "] Actual [" << mat.getScaleX() << ", " << mat.getScaleY() | |
810 << "]."; | |
811 return false; | |
812 } | |
813 | |
814 if (mat.getTranslateX() != SkIntToScalar(tx_) || | |
815 mat.getTranslateY() != SkIntToScalar(ty_)) { | |
816 *listener << "Incorrect translation. Expected [" << tx_ << ", " << ty_ | |
817 << "] Actual [" << mat.getTranslateX() << ", " | |
818 << mat.getTranslateY() << "]."; | |
819 return false; | |
820 } | |
821 | |
822 return true; | |
823 } | |
824 virtual void DescribeTo(::std::ostream* os) const { | |
825 *os << "SkCanvas has correct transform."; | |
826 } | |
827 virtual void DescribeNegationTo(::std::ostream* os) const { | |
828 *os << "SkCanvas has incorrect transform."; | |
829 } | |
830 | |
831 private: | |
832 int tx_; | |
833 int ty_; | |
834 float scale_; | |
835 }; | |
836 | |
837 Matcher<SkCanvas*> IsCorrectTransform(int tx, int ty, float scale) { | |
838 return MakeMatcher(new IsCorrectTransformMatcher(tx, ty, scale)); | |
839 } | |
840 | |
841 public: | |
842 ScaledScrollbarLayerTestScaledRasterization() | |
843 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | |
844 | |
845 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | |
846 layer_tree_host_.reset( | |
847 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | |
848 | |
849 MockScrollbar* mock_scrollbar = new MockScrollbar(false, false, false); | |
850 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | |
851 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | |
852 FakePaintedScrollbarLayer::Create(false, false, layer_tree_root->id(), | |
853 mock_scrollbar); | |
854 | |
855 layer_tree_root->AddChild(scrollbar_layer); | |
856 | |
857 layer_tree_host_->SetRootLayer(layer_tree_root); | |
858 | |
859 scrollbar_layer->SetBounds(scrollbar_rect.size()); | |
860 scrollbar_layer->SetPosition(scrollbar_rect.origin()); | |
861 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); | |
862 gfx::SizeF scaled_size = | |
863 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale); | |
864 gfx::PointF scaled_location = | |
865 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale); | |
866 scrollbar_layer->draw_properties().content_bounds = | |
867 gfx::Size(scaled_size.width(), scaled_size.height()); | |
868 scrollbar_layer->draw_properties().contents_scale_x = test_scale; | |
869 scrollbar_layer->draw_properties().contents_scale_y = test_scale; | |
870 scrollbar_layer->draw_properties().visible_content_rect = | |
871 gfx::Rect(scaled_location.x(), | |
872 scaled_location.y(), | |
873 scaled_size.width(), | |
874 scaled_size.height()); | |
875 | |
876 ResourceUpdateQueue queue; | |
877 OcclusionTracker occlusion_tracker(gfx::Rect(), false); | |
878 scrollbar_layer->SavePaintProperties(); | |
879 | |
880 int x = round(scrollbar_rect.x() * test_scale); | |
wjmaclean
2014/02/12 18:38:53
Is it worth adding a comment here as to why you ne
bokan
2014/02/13 19:04:57
Done.
| |
881 int y = round(scrollbar_rect.y() * test_scale); | |
882 | |
883 EXPECT_CALL(*mock_scrollbar, | |
884 PaintPart(IsCorrectTransform(-x, -y, test_scale), | |
885 TRACK, | |
886 scrollbar_rect)); | |
887 | |
888 scrollbar_layer->Update(&queue, &occlusion_tracker); | |
889 scrollbar_layer->ClearRenderSurface(); | |
890 } | |
891 | |
892 protected: | |
893 FakeLayerTreeHostClient fake_client_; | |
894 LayerTreeSettings layer_tree_settings_; | |
895 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | |
896 }; | |
897 | |
898 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { | |
899 // Try rasterization at a scale that caused problematic floating point | |
900 // clamping causing a black line on scrollbar edges. Sweep across a range | |
901 // of coordinates to uproot numeric errors. | |
902 for (int i = 0; i < 10; ++i) { | |
903 // Vertical scrollbar. | |
904 TestScale(gfx::Rect(1120 - i, 0, 15, 677), 7.301320f); | |
905 | |
906 // Horizontal scrollbar. | |
907 TestScale(gfx::Rect(0, 1120 - i, 677, 15), 7.301320f); | |
908 } | |
909 } | |
910 | |
769 } // namespace | 911 } // namespace |
770 } // namespace cc | 912 } // namespace cc |
OLD | NEW |