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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/painted_scrollbar_layer.cc ('k') | cc/test/fake_painted_scrollbar_layer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/scrollbar_layer_unittest.cc
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc
index 2d01af7289db11f50c91955a9dab07485f31f687..433d7e68b4ac45e9c6039ffcaa390aaa33464449 100644
--- a/cc/layers/scrollbar_layer_unittest.cc
+++ b/cc/layers/scrollbar_layer_unittest.cc
@@ -29,6 +29,13 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using ::testing::_;
+using ::testing::Invoke;
+using ::testing::MatcherInterface;
+using ::testing::Matcher;
+using ::testing::MakeMatcher;
+using ::testing::MatchResultListener;
+
namespace cc {
namespace {
@@ -766,5 +773,140 @@ TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
TestResourceUpload(4.1f);
}
+
wjmaclean 2014/02/12 18:38:53 Delete extra line space?
bokan 2014/02/13 19:04:57 Done.
+class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
+ class MockScrollbar : public FakeScrollbar {
+ public:
+ MockScrollbar(bool paint, bool has_thumb, bool is_overlay)
+ : FakeScrollbar(paint, has_thumb, is_overlay)
+ {}
+
+ MOCK_METHOD3(PaintPart, void(SkCanvas* canvas,
+ ScrollbarPart part,
+ const gfx::Rect& content_rect));
+ };
+
+ class IsCorrectTransformMatcher : public MatcherInterface<SkCanvas*> {
+ public:
+ IsCorrectTransformMatcher(int tx, int ty, float scale)
+ : tx_(tx),
+ ty_(ty),
+ scale_(scale)
+ {}
+ virtual bool MatchAndExplain(SkCanvas* arg,
+ MatchResultListener* listener) const {
+ const SkMatrix& mat = arg->getTotalMatrix();
+ if (!(mat.getType() ==
+ (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) {
+ *listener << "Wrong matrix type - expected Translate and Scale. Got "
+ << mat.getType();
+ return false;
+ }
+
+ if (mat.getScaleX() != SkFloatToScalar(scale_) ||
+ mat.getScaleY() != SkFloatToScalar(scale_)) {
+ *listener << "Incorrect scale. Expected [" << scale_ << ", " << scale_
+ << "] Actual [" << mat.getScaleX() << ", " << mat.getScaleY()
+ << "].";
+ return false;
+ }
+
+ if (mat.getTranslateX() != SkIntToScalar(tx_) ||
+ mat.getTranslateY() != SkIntToScalar(ty_)) {
+ *listener << "Incorrect translation. Expected [" << tx_ << ", " << ty_
+ << "] Actual [" << mat.getTranslateX() << ", "
+ << mat.getTranslateY() << "].";
+ return false;
+ }
+
+ return true;
+ }
+ virtual void DescribeTo(::std::ostream* os) const {
+ *os << "SkCanvas has correct transform.";
+ }
+ virtual void DescribeNegationTo(::std::ostream* os) const {
+ *os << "SkCanvas has incorrect transform.";
+ }
+
+ private:
+ int tx_;
+ int ty_;
+ float scale_;
+ };
+
+ Matcher<SkCanvas*> IsCorrectTransform(int tx, int ty, float scale) {
+ return MakeMatcher(new IsCorrectTransformMatcher(tx, ty, scale));
+ }
+
+ public:
+ ScaledScrollbarLayerTestScaledRasterization()
+ : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
+
+ void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
+ layer_tree_host_.reset(
+ new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
+
+ MockScrollbar* mock_scrollbar = new MockScrollbar(false, false, false);
+ scoped_refptr<Layer> layer_tree_root = Layer::Create();
+ scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
+ FakePaintedScrollbarLayer::Create(false, false, layer_tree_root->id(),
+ mock_scrollbar);
+
+ layer_tree_root->AddChild(scrollbar_layer);
+
+ layer_tree_host_->SetRootLayer(layer_tree_root);
+
+ scrollbar_layer->SetBounds(scrollbar_rect.size());
+ scrollbar_layer->SetPosition(scrollbar_rect.origin());
+ scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
+ gfx::SizeF scaled_size =
+ gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale);
+ gfx::PointF scaled_location =
+ gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale);
+ scrollbar_layer->draw_properties().content_bounds =
+ gfx::Size(scaled_size.width(), scaled_size.height());
+ scrollbar_layer->draw_properties().contents_scale_x = test_scale;
+ scrollbar_layer->draw_properties().contents_scale_y = test_scale;
+ scrollbar_layer->draw_properties().visible_content_rect =
+ gfx::Rect(scaled_location.x(),
+ scaled_location.y(),
+ scaled_size.width(),
+ scaled_size.height());
+
+ ResourceUpdateQueue queue;
+ OcclusionTracker occlusion_tracker(gfx::Rect(), false);
+ scrollbar_layer->SavePaintProperties();
+
+ 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.
+ int y = round(scrollbar_rect.y() * test_scale);
+
+ EXPECT_CALL(*mock_scrollbar,
+ PaintPart(IsCorrectTransform(-x, -y, test_scale),
+ TRACK,
+ scrollbar_rect));
+
+ scrollbar_layer->Update(&queue, &occlusion_tracker);
+ scrollbar_layer->ClearRenderSurface();
+ }
+
+ protected:
+ FakeLayerTreeHostClient fake_client_;
+ LayerTreeSettings layer_tree_settings_;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host_;
+};
+
+TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
+ // Try rasterization at a scale that caused problematic floating point
+ // clamping causing a black line on scrollbar edges. Sweep across a range
+ // of coordinates to uproot numeric errors.
+ for (int i = 0; i < 10; ++i) {
+ // Vertical scrollbar.
+ TestScale(gfx::Rect(1120 - i, 0, 15, 677), 7.301320f);
+
+ // Horizontal scrollbar.
+ TestScale(gfx::Rect(0, 1120 - i, 677, 15), 7.301320f);
+ }
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/layers/painted_scrollbar_layer.cc ('k') | cc/test/fake_painted_scrollbar_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698