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

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

Issue 150603004: Fixed rounding issue on scrollbar rasterization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 11 matching lines...) Expand all
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
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 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
777 class MockScrollbar : public FakeScrollbar {
778 public:
779 MockScrollbar(bool paint, bool has_thumb, bool is_overlay)
780 : FakeScrollbar(paint, has_thumb, is_overlay)
781 {}
782
783 MOCK_METHOD3(PaintPart, void(SkCanvas* canvas,
784 ScrollbarPart part,
785 const gfx::Rect& content_rect));
786 };
787
788 class IsCorrectTransformMatcher : public MatcherInterface<SkCanvas*> {
789 public:
790 IsCorrectTransformMatcher(int tx, int ty, float scale)
791 : tx_(tx),
792 ty_(ty),
793 scale_(scale)
794 {}
795 virtual bool MatchAndExplain(SkCanvas* arg,
796 MatchResultListener* listener) const {
797 const SkMatrix& mat = arg->getTotalMatrix();
798 if (!(mat.getType() ==
799 (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) {
800 *listener << "Wrong matrix type - expected Translate and Scale. Got "
801 << mat.getType();
802 return false;
803 }
804
805 if (mat.getScaleX() != SkFloatToScalar(scale_) ||
806 mat.getScaleY() != SkFloatToScalar(scale_)) {
807 *listener << "Incorrect scale. Expected [" << scale_ << ", " << scale_
808 << "] Actual [" << mat.getScaleX() << ", " << mat.getScaleY()
809 << "].";
810 return false;
811 }
812
813 if (mat.getTranslateX() != SkIntToScalar(tx_) ||
814 mat.getTranslateY() != SkIntToScalar(ty_)) {
815 *listener << "Incorrect translation. Expected [" << tx_ << ", " << ty_
816 << "] Actual [" << mat.getTranslateX() << ", "
817 << mat.getTranslateY() << "].";
818 return false;
819 }
820
821 return true;
822 }
823 virtual void DescribeTo(::std::ostream* os) const {
824 *os << "SkCanvas has correct transform.";
825 }
826 virtual void DescribeNegationTo(::std::ostream* os) const {
827 *os << "SkCanvas has incorrect transform.";
828 }
829
830 private:
831 int tx_;
832 int ty_;
833 float scale_;
834 };
835
836 Matcher<SkCanvas*> IsCorrectTransform(int tx, int ty, float scale) {
837 return MakeMatcher(new IsCorrectTransformMatcher(tx, ty, scale));
838 }
839
840 public:
841 ScaledScrollbarLayerTestScaledRasterization()
842 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
843
844 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
845 layer_tree_host_.reset(
846 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
847
848 MockScrollbar* mock_scrollbar = new MockScrollbar(false, false, false);
849 scoped_refptr<Layer> layer_tree_root = Layer::Create();
850 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
851 FakePaintedScrollbarLayer::Create(false, false, layer_tree_root->id(),
852 mock_scrollbar);
853
854 layer_tree_root->AddChild(scrollbar_layer);
855
856 layer_tree_host_->SetRootLayer(layer_tree_root);
857
858 scrollbar_layer->SetBounds(scrollbar_rect.size());
859 scrollbar_layer->SetPosition(scrollbar_rect.origin());
860 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
861 gfx::SizeF scaled_size =
862 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale);
863 gfx::PointF scaled_location =
864 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale);
865 scrollbar_layer->draw_properties().content_bounds =
866 gfx::Size(scaled_size.width(), scaled_size.height());
867 scrollbar_layer->draw_properties().contents_scale_x = test_scale;
868 scrollbar_layer->draw_properties().contents_scale_y = test_scale;
869 scrollbar_layer->draw_properties().visible_content_rect =
870 gfx::Rect(scaled_location.x(),
871 scaled_location.y(),
872 scaled_size.width(),
873 scaled_size.height());
874
875 ResourceUpdateQueue queue;
876 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
877 scrollbar_layer->SavePaintProperties();
878
879 // Since Skia will round scaled coordinates, the canvas should be translated
880 // back to origin by the rounded amount.
881 int xTranslate = round(scrollbar_rect.x() * test_scale);
882 int yTranslate = round(scrollbar_rect.y() * test_scale);
883
884 EXPECT_CALL(
885 *mock_scrollbar,
886 PaintPart(IsCorrectTransform(-xTranslate, -yTranslate, test_scale),
887 TRACK,
888 scrollbar_rect));
889
890 scrollbar_layer->Update(&queue, &occlusion_tracker);
891 scrollbar_layer->ClearRenderSurface();
892 }
893
894 protected:
895 FakeLayerTreeHostClient fake_client_;
896 LayerTreeSettings layer_tree_settings_;
897 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
898 };
899
900 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
901 // Try rasterization at a scale that caused problematic floating point
902 // clamping causing a black line on scrollbar edges. Sweep across a range
903 // of coordinates to uproot numeric errors.
904 for (int i = 0; i < 10; ++i) {
905 // Vertical scrollbar.
906 TestScale(gfx::Rect(1120 - i, 0, 15, 677), 7.301320f);
907
908 // Horizontal scrollbar.
909 TestScale(gfx::Rect(0, 1120 - i, 677, 15), 7.301320f);
910 }
911 }
912
769 } // namespace 913 } // namespace
770 } // namespace cc 914 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698