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

Unified Diff: Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp

Issue 1295403003: DisplayItemPropertyTreeBuilder: Support (2D) transform and scroll display items. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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: Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp
diff --git a/Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp b/Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp
index 469b7dd4e4b435fbe5310767cc0cfdbdf99186e8..096cf1d74ea3286506c4d65f5b53b6a3a0f30af5 100644
--- a/Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp
+++ b/Source/platform/graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp
@@ -9,7 +9,9 @@
#include "platform/graphics/paint/DisplayItemClient.h"
#include "platform/graphics/paint/DisplayItemClipTree.h"
#include "platform/graphics/paint/DisplayItemTransformTree.h"
+#include "platform/graphics/paint/ScrollDisplayItem.h"
#include "platform/graphics/paint/Transform3DDisplayItem.h"
+#include "platform/graphics/paint/TransformDisplayItem.h"
#include "platform/transforms/TransformTestHelper.h"
#include "platform/transforms/TransformationMatrix.h"
#include "public/platform/WebDisplayItemTransformTree.h"
@@ -72,6 +74,26 @@ protected:
{
processDisplayItem(EndTransform3DDisplayItem(client, DisplayItem::transform3DTypeToEndTransform3DType(DisplayItem::Transform3DElementTransform)));
}
+ const DummyClient& processBeginTransform(const AffineTransform& transform)
+ {
+ const DummyClient& client = newDummyClient();
+ processDisplayItem(BeginTransformDisplayItem(client, transform));
+ return client;
+ }
+ void processEndTransform(const DummyClient& client)
+ {
+ processDisplayItem(EndTransformDisplayItem(client));
+ }
+ const DummyClient& processBeginScroll(int offsetX, int offsetY)
+ {
+ const DummyClient& client = newDummyClient();
+ processDisplayItem(BeginScrollDisplayItem(client, DisplayItem::ScrollFirst, IntSize(offsetX, offsetY)));
+ return client;
+ }
+ void processEndScroll(const DummyClient& client)
+ {
+ processDisplayItem(EndScrollDisplayItem(client, DisplayItem::EndScrollFirst));
+ }
void finishPropertyTrees()
{
@@ -319,5 +341,79 @@ TEST_F(DisplayItemPropertyTreeBuilderTest, NestedTransformsAreNotCombined)
EXPECT_TRANSFORMS_ALMOST_EQ(matrix1, parentNode.matrix);
}
+TEST_F(DisplayItemPropertyTreeBuilderTest, TransformDisplayItemCreatesTransformNode)
+{
+ // 2D transform display items should create a transform node as well,
+ // unless the transform is a 2D translation only.
+ AffineTransform rotation;
+ rotation.rotate(45);
+
+ processDummyDisplayItem();
+ auto transformClient = processBeginTransform(rotation);
+ processDummyDisplayItem();
+ processEndTransform(transformClient);
+ processDummyDisplayItem();
+ finishPropertyTrees();
+
+ // There should be two transform nodes.
+ ASSERT_EQ(2u, transformTree().nodeCount());
+ EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
+ EXPECT_EQ(0u, transformTree().nodeAt(1).parentNodeIndex);
+ EXPECT_TRANSFORMS_ALMOST_EQ(TransformationMatrix(rotation), transformTree().nodeAt(1).matrix);
+
+ // There should be three range records, the middle one affected by the
+ // rotation.
+ EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
+ AllOf(hasRange(0, 1), hasTransformNode(0)),
+ AllOf(hasRange(2, 3), hasTransformNode(1)),
+ AllOf(hasRange(4, 5), hasTransformNode(0))));
+}
+
+TEST_F(DisplayItemPropertyTreeBuilderTest, TransformDisplayItemOnly2DTranslation)
+{
+ // In this case no transform node should be created for the 2D translation.
+ AffineTransform translation = AffineTransform::translation(10, -40);
+
+ processDummyDisplayItem();
+ auto transformClient = processBeginTransform(translation);
+ processDummyDisplayItem();
+ processEndTransform(transformClient);
+ processDummyDisplayItem();
+ finishPropertyTrees();
+
+ // There should be only one transform node.
+ ASSERT_EQ(1u, transformTree().nodeCount());
+ EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
+
+ // There should be three range records, the middle one affected by the
+ // translation.
+ EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
+ AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize(0, 0))),
+ AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(FloatSize(10, -40))),
+ AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(FloatSize(0, 0)))));
+}
+
+TEST_F(DisplayItemPropertyTreeBuilderTest, ScrollDisplayItemIs2DTranslation)
+{
+ processDummyDisplayItem();
+ auto scrollClient = processBeginScroll(-90, 400);
+ processDummyDisplayItem();
+ processEndScroll(scrollClient);
+ processDummyDisplayItem();
+ finishPropertyTrees();
+
+ // There should be only one transform node.
+ ASSERT_EQ(1u, transformTree().nodeCount());
+ EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
+
+ // There should be three range records, the middle one affected by the
+ // scroll. Note that the translation due to scroll is the negative of the
+ // scroll offset.
+ EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
+ AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize(0, 0))),
+ AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(FloatSize(90, -400))),
+ AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(FloatSize(0, 0)))));
+}
+
} // namespace
} // namespace blink
« no previous file with comments | « Source/platform/graphics/paint/DisplayItemPropertyTreeBuilder.cpp ('k') | Source/platform/graphics/paint/ScrollDisplayItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698