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

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: Fixed break on Android tests 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_scrollbar.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..794a60e3c251609a89502fb583643abefce24465 100644
--- a/cc/layers/scrollbar_layer_unittest.cc
+++ b/cc/layers/scrollbar_layer_unittest.cc
@@ -584,6 +584,13 @@ class MockLayerTreeHost : public LayerTreeHost {
return gfx::Size();
}
+ UIResourceBitmap* ui_resource_bitmap(UIResourceId id) {
+ UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
+ if (iter != ui_resource_bitmap_map_.end())
+ return &iter->second;
+ return NULL;
+ }
+
private:
typedef base::hash_map<UIResourceId, UIResourceBitmap>
UIResourceBitmapMap;
@@ -766,5 +773,104 @@ TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
TestResourceUpload(4.1f);
}
+class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
+ 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_));
+
+ bool paint_during_update = true;
+ bool has_thumb = false;
+ scoped_refptr<Layer> layer_tree_root = Layer::Create();
+ scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
+ FakePaintedScrollbarLayer::Create(paint_during_update,
+ has_thumb,
+ layer_tree_root->id());
+
+ 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());
+ scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect);
+ 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();
+
+ scrollbar_layer->Update(&queue, &occlusion_tracker);
+
+ UIResourceBitmap* bitmap = layer_tree_host_->ui_resource_bitmap(
+ scrollbar_layer->track_resource_id());
+
+ DCHECK(bitmap);
+
+ AutoLockUIResourceBitmap locked_bitmap(*bitmap);
+
+ const SkColor* pixels =
+ reinterpret_cast<const SkColor*>(locked_bitmap.GetPixels());
+ SkColor color = argb_to_skia(
+ scrollbar_layer->fake_scrollbar()->paint_fill_color());
+ int width = bitmap->GetSize().width();
+ int height = bitmap->GetSize().height();
+
+ // Make sure none of the corners of the bitmap were inadvertently clipped.
+ EXPECT_EQ(color, pixels[0])
+ << "Top left pixel doesn't match scrollbar color.";
+
+ EXPECT_EQ(color, pixels[width - 1])
+ << "Top right pixel doesn't match scrollbar color.";
+
+ EXPECT_EQ(color, pixels[width * (height - 1)])
+ << "Bottom left pixel doesn't match scrollbar color.";
+
+ EXPECT_EQ(color, pixels[width * height - 1])
+ << "Bottom right pixel doesn't match scrollbar color.";
+ }
+
+ protected:
+ // On Android, Skia uses ABGR
+ static SkColor argb_to_skia(SkColor c) {
+ return (SkColorGetA(c) << SK_A32_SHIFT) |
+ (SkColorGetR(c) << SK_R32_SHIFT) |
+ (SkColorGetG(c) << SK_G32_SHIFT) |
+ (SkColorGetB(c) << SK_B32_SHIFT);
+ }
+
+ FakeLayerTreeHostClient fake_client_;
+ LayerTreeSettings layer_tree_settings_;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host_;
+};
+
+TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
+ // Try rasterization at coordinates and scale that caused problematic
+ // rounding and clipping errors.
+ // Vertical Scrollbars.
+ TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
+ TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
+
+ // Horizontal Scrollbars.
+ TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
+ TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/layers/painted_scrollbar_layer.cc ('k') | cc/test/fake_scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698