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

Unified Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp

Issue 2112753002: Snap paint offset paint property to pixel boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more tests, cleanup comments Created 4 years, 6 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
Index: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
diff --git a/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp b/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
index 55be3a8f0dab0ddf83531e6bd9181e902ad09dd5..c6eaf66392c474f329aa0716c4e34c0a597afc81 100644
--- a/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
@@ -918,4 +918,98 @@ TEST_F(PaintPropertyTreeBuilderTest, ColumnSpannerUnderRelativePositioned)
EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderBoxProperties()->paintOffset);
}
+TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithBasicPixelSnapping)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " * { margin: 0; }"
+ " div { position: relative; }"
+ "</style>"
+ "<div id='a' style='width: 70px; height: 70px; left: 0.3px; top: 0.3px;'>"
+ " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0);'>"
+ " <div id='c' style='width: 40px; height: 40px; left: 0.1px; top: 0.1px;'></div>"
+ " </div>"
+ "</div>"
+ );
+
+ ObjectPaintProperties* bProperties = document().getElementById("b")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transform()->matrix());
+ // The paint offset transform should be snapped from (0.3,0.3) to (0,0).
+ EXPECT_EQ(TransformationMatrix().translate(0, 0), bProperties->transform()->parent()->matrix());
+ // The residual subpixel adjustment should be (0.3,0.3) - (0,0) = (0.3,0.3).
+ LayoutPoint subpixelAccumulation = LayoutPoint(FloatPoint(0.3, 0.3));
+ EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->paintOffset);
+
+ // c should be painted starting at subpixelAccumulation + (0.1,0.1) = (0.4,0.4).
+ LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.1, 0.1));
+ ObjectPaintProperties* cProperties = document().getElementById("c")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset);
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughTransform)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " * { margin: 0; }"
+ " div { position: relative; }"
+ "</style>"
+ "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'>"
+ " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0);'>"
+ " <div id='c' style='width: 40px; height: 40px; left: 0.7px; top: 0.7px;'></div>"
+ " </div>"
+ "</div>"
+ );
+
+ ObjectPaintProperties* bProperties = document().getElementById("b")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transform()->matrix());
+ // The paint offset transform should be snapped from (0.7,0.7) to (1,1).
+ EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->parent()->matrix());
+ // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3).
+ LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0.7)) - LayoutPoint(1, 1));
+ EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->paintOffset);
+
+ // c should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0.4).
+ LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7, 0.7));
+ ObjectPaintProperties* cProperties = document().getElementById("c")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset);
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughMultipleTransforms)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " * { margin: 0; }"
+ " div { position: relative; }"
+ "</style>"
+ "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'>"
+ " <div id='b' style='width: 40px; height: 40px; transform: translate3d(5px, 7px, 0);'>"
+ " <div id='c' style='width: 40px; height: 40px; transform: translate3d(11px, 13px, 0);'>"
+ " <div id='d' style='width: 40px; height: 40px; left: 0.7px; top: 0.7px;'></div>"
+ " </div>"
+ " </div>"
+ "</div>"
+ );
+
+ ObjectPaintProperties* bProperties = document().getElementById("b")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(TransformationMatrix().translate3d(5, 7, 0), bProperties->transform()->matrix());
+ // The paint offset transform should be snapped from (0.7,0.7) to (1,1).
+ EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->parent()->matrix());
+ // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3).
+ LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0.7)) - LayoutPoint(1, 1));
+ EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->paintOffset);
+
+ ObjectPaintProperties* cProperties = document().getElementById("c")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(TransformationMatrix().translate3d(11, 13, 0), cProperties->transform()->matrix());
+ // The paint offset should be (-0.3,-0.3) but the paint offset transform should still be at
+ // (0,0) because it should be snapped.
+ EXPECT_EQ(TransformationMatrix().translate(0, 0), cProperties->transform()->parent()->matrix());
+ // The residual subpixel adjustment should still be (-0.3,-0.3).
+ EXPECT_EQ(subpixelAccumulation, cProperties->localBorderBoxProperties()->paintOffset);
+
+ // d should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0.4).
+ LayoutPoint dPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7, 0.7));
+ ObjectPaintProperties* dProperties = document().getElementById("d")->layoutObject()->objectPaintProperties();
+ EXPECT_EQ(dPaintOffset, dProperties->localBorderBoxProperties()->paintOffset);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698