| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/paint/DisplayItemTransformTreeBuilder.h" | 6 #include "platform/graphics/paint/DisplayItemPropertyTreeBuilder.h" |
| 7 | 7 |
| 8 #include "platform/graphics/paint/DisplayItem.h" | 8 #include "platform/graphics/paint/DisplayItem.h" |
| 9 #include "platform/graphics/paint/DisplayItemClient.h" | 9 #include "platform/graphics/paint/DisplayItemClient.h" |
| 10 #include "platform/graphics/paint/DisplayItemClipTree.h" |
| 10 #include "platform/graphics/paint/DisplayItemTransformTree.h" | 11 #include "platform/graphics/paint/DisplayItemTransformTree.h" |
| 11 #include "platform/graphics/paint/Transform3DDisplayItem.h" | 12 #include "platform/graphics/paint/Transform3DDisplayItem.h" |
| 12 #include "platform/transforms/TransformTestHelper.h" | 13 #include "platform/transforms/TransformTestHelper.h" |
| 13 #include "platform/transforms/TransformationMatrix.h" | 14 #include "platform/transforms/TransformationMatrix.h" |
| 14 #include "public/platform/WebDisplayItemTransformTree.h" | 15 #include "public/platform/WebDisplayItemTransformTree.h" |
| 16 #include "wtf/OwnPtr.h" |
| 17 #include <gmock/gmock.h> |
| 15 #include <gtest/gtest.h> | 18 #include <gtest/gtest.h> |
| 16 | 19 |
| 17 namespace blink { | 20 namespace blink { |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 using RangeRecord = WebDisplayItemTransformTree::RangeRecord; | 23 using ::testing::AllOf; |
| 24 using ::testing::ElementsAre; |
| 25 |
| 26 using RangeRecord = DisplayItemPropertyTreeBuilder::RangeRecord; |
| 27 |
| 28 MATCHER_P2(hasRange, begin, end, "") |
| 29 { |
| 30 return arg.displayListBeginIndex == static_cast<size_t>(begin) |
| 31 && arg.displayListEndIndex == static_cast<size_t>(end); |
| 32 } |
| 33 |
| 34 MATCHER_P(hasTransformNode, transformNode, "") |
| 35 { |
| 36 return arg.transformNodeIndex == static_cast<size_t>(transformNode); |
| 37 } |
| 38 |
| 39 MATCHER_P(hasOffset, offset, "") |
| 40 { |
| 41 return arg.offset == offset; |
| 42 } |
| 21 | 43 |
| 22 struct DummyClient { | 44 struct DummyClient { |
| 23 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi
s); } | 45 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi
s); } |
| 24 String debugName() const { return "DummyClient"; } | 46 String debugName() const { return "DummyClient"; } |
| 25 }; | 47 }; |
| 26 | 48 |
| 27 class DummyDisplayItem final : public DisplayItem { | 49 class DummyDisplayItem final : public DisplayItem { |
| 28 public: | 50 public: |
| 29 DummyDisplayItem(const DummyClient& client) : DisplayItem(client, DisplayIte
m::DrawingFirst, sizeof(*this)) { } | 51 DummyDisplayItem(const DummyClient& client) : DisplayItem(client, DisplayIte
m::DrawingFirst, sizeof(*this)) { } |
| 30 }; | 52 }; |
| 31 | 53 |
| 32 class DisplayItemTransformTreeBuilderTest : public ::testing::Test { | 54 class DisplayItemPropertyTreeBuilderTest : public ::testing::Test { |
| 33 protected: | 55 protected: |
| 34 DisplayItemTransformTreeBuilder& builder() { return m_builder; } | 56 DisplayItemPropertyTreeBuilder& builder() { return m_builder; } |
| 57 const DisplayItemTransformTree& transformTree() { return *m_transformTree; } |
| 58 const DisplayItemClipTree& clipTree() { return *m_clipTree; } |
| 59 const Vector<RangeRecord>& rangeRecords() { return m_rangeRecords; } |
| 60 std::vector<RangeRecord> rangeRecordsAsStdVector() { return std::vector<Rang
eRecord>(m_rangeRecords.begin(), m_rangeRecords.end()); } |
| 35 | 61 |
| 36 void processDisplayItem(const DisplayItem& displayItem) { m_builder.processD
isplayItem(displayItem); } | 62 void processDisplayItem(const DisplayItem& displayItem) { m_builder.processD
isplayItem(displayItem); } |
| 37 void processDisplayItem(PassOwnPtr<DisplayItem> displayItem) { processDispla
yItem(*displayItem); } | 63 void processDisplayItem(PassOwnPtr<DisplayItem> displayItem) { processDispla
yItem(*displayItem); } |
| 38 void processDummyDisplayItem() { processDisplayItem(DummyDisplayItem(newDumm
yClient())); } | 64 void processDummyDisplayItem() { processDisplayItem(DummyDisplayItem(newDumm
yClient())); } |
| 39 const DummyClient& processBeginTransform3D(const TransformationMatrix& trans
form) | 65 const DummyClient& processBeginTransform3D(const TransformationMatrix& trans
form) |
| 40 { | 66 { |
| 41 const DummyClient& client = newDummyClient(); | 67 const DummyClient& client = newDummyClient(); |
| 42 processDisplayItem(BeginTransform3DDisplayItem(client, DisplayItem::Tran
sform3DElementTransform, transform)); | 68 processDisplayItem(BeginTransform3DDisplayItem(client, DisplayItem::Tran
sform3DElementTransform, transform)); |
| 43 return client; | 69 return client; |
| 44 } | 70 } |
| 45 void processEndTransform3D(const DummyClient& client) | 71 void processEndTransform3D(const DummyClient& client) |
| 46 { | 72 { |
| 47 processDisplayItem(EndTransform3DDisplayItem(client, DisplayItem::transf
orm3DTypeToEndTransform3DType(DisplayItem::Transform3DElementTransform))); | 73 processDisplayItem(EndTransform3DDisplayItem(client, DisplayItem::transf
orm3DTypeToEndTransform3DType(DisplayItem::Transform3DElementTransform))); |
| 48 } | 74 } |
| 49 | 75 |
| 76 void finishPropertyTrees() |
| 77 { |
| 78 m_transformTree = m_builder.releaseTransformTree(); |
| 79 m_clipTree = m_builder.releaseClipTree(); |
| 80 m_rangeRecords = m_builder.releaseRangeRecords(); |
| 81 } |
| 82 |
| 50 private: | 83 private: |
| 51 // This makes empty objects which can be used as display item clients. | 84 // This makes empty objects which can be used as display item clients. |
| 52 const DummyClient& newDummyClient() | 85 const DummyClient& newDummyClient() |
| 53 { | 86 { |
| 54 m_dummyClients.append(adoptPtr(new DummyClient)); | 87 m_dummyClients.append(adoptPtr(new DummyClient)); |
| 55 return *m_dummyClients.last(); | 88 return *m_dummyClients.last(); |
| 56 } | 89 } |
| 57 | 90 |
| 58 DisplayItemTransformTreeBuilder m_builder; | 91 DisplayItemPropertyTreeBuilder m_builder; |
| 92 OwnPtr<DisplayItemTransformTree> m_transformTree; |
| 93 OwnPtr<DisplayItemClipTree> m_clipTree; |
| 94 Vector<RangeRecord> m_rangeRecords; |
| 59 Vector<OwnPtr<DummyClient>> m_dummyClients; | 95 Vector<OwnPtr<DummyClient>> m_dummyClients; |
| 60 }; | 96 }; |
| 61 | 97 |
| 62 TEST_F(DisplayItemTransformTreeBuilderTest, NoDisplayItems) | 98 TEST_F(DisplayItemPropertyTreeBuilderTest, NoDisplayItems) |
| 63 { | 99 { |
| 64 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 100 finishPropertyTrees(); |
| 65 | 101 |
| 66 // There should be a root transform node. | 102 // There should be a root transform node. |
| 67 ASSERT_EQ(1u, tree.nodeCount()); | 103 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 68 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 104 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 69 EXPECT_EQ(WebDisplayItemTransformTree::kInvalidIndex, tree.nodeAt(0).parentN
odeIndex); | |
| 70 | 105 |
| 71 // There should be no range records, because there are no non-empty | 106 // There should be no range records, because there are no non-empty |
| 72 // transformed ranges. | 107 // transformed ranges. |
| 73 ASSERT_EQ(0u, tree.rangeRecordCount()); | 108 ASSERT_EQ(0u, rangeRecords().size()); |
| 74 } | 109 } |
| 75 | 110 |
| 76 TEST_F(DisplayItemTransformTreeBuilderTest, NoTransforms) | 111 TEST_F(DisplayItemPropertyTreeBuilderTest, NoTransforms) |
| 77 { | 112 { |
| 78 // Three dummy display items. | 113 // Three dummy display items. |
| 79 processDummyDisplayItem(); | 114 processDummyDisplayItem(); |
| 80 processDummyDisplayItem(); | 115 processDummyDisplayItem(); |
| 81 processDummyDisplayItem(); | 116 processDummyDisplayItem(); |
| 82 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 117 finishPropertyTrees(); |
| 83 | 118 |
| 84 // There should only be a root transform node. | 119 // There should only be a root transform node. |
| 85 ASSERT_EQ(1u, tree.nodeCount()); | 120 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 86 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 121 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 87 EXPECT_EQ(WebDisplayItemTransformTree::kInvalidIndex, tree.nodeAt(0).parentN
odeIndex); | |
| 88 | 122 |
| 89 // There should be one range record, for the entire list. | 123 // There should be one range record, for the entire list. |
| 90 ASSERT_EQ(1u, tree.rangeRecordCount()); | 124 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 91 EXPECT_EQ(RangeRecord(0, 3, 0), tree.rangeRecordAt(0)); | 125 AllOf(hasRange(0, 3), hasTransformNode(0)))); |
| 92 } | 126 } |
| 93 | 127 |
| 94 TEST_F(DisplayItemTransformTreeBuilderTest, IdentityTransform) | 128 TEST_F(DisplayItemPropertyTreeBuilderTest, IdentityTransform) |
| 95 { | 129 { |
| 96 TransformationMatrix identity; | 130 TransformationMatrix identity; |
| 97 | 131 |
| 98 // There's an identity transform here, but we should not make a node for it. | 132 // There's an identity transform here, but we should not make a node for it. |
| 99 processDummyDisplayItem(); | 133 processDummyDisplayItem(); |
| 100 auto transformClient = processBeginTransform3D(identity); | 134 auto transformClient = processBeginTransform3D(identity); |
| 101 processDummyDisplayItem(); | 135 processDummyDisplayItem(); |
| 102 processEndTransform3D(transformClient); | 136 processEndTransform3D(transformClient); |
| 103 processDummyDisplayItem(); | 137 processDummyDisplayItem(); |
| 104 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 138 finishPropertyTrees(); |
| 105 | 139 |
| 106 // There should only be a root transform node. | 140 // There should only be a root transform node. |
| 107 ASSERT_EQ(1u, tree.nodeCount()); | 141 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 108 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 142 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 109 EXPECT_EQ(WebDisplayItemTransformTree::kInvalidIndex, tree.nodeAt(0).parentN
odeIndex); | |
| 110 | 143 |
| 111 // There should be three range records. | 144 // There should be three range records. |
| 112 // Since the transform is the identity, these could be combined, but there | 145 // Since the transform is the identity, these could be combined, but there |
| 113 // is not currently a special path for this case. | 146 // is not currently a special path for this case. |
| 114 ASSERT_EQ(3u, tree.rangeRecordCount()); | 147 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 115 EXPECT_EQ(RangeRecord(0, 1, 0), tree.rangeRecordAt(0)); | 148 AllOf(hasRange(0, 1), hasTransformNode(0)), |
| 116 EXPECT_EQ(RangeRecord(2, 3, 0), tree.rangeRecordAt(1)); | 149 AllOf(hasRange(2, 3), hasTransformNode(0)), |
| 117 EXPECT_EQ(RangeRecord(4, 5, 0), tree.rangeRecordAt(2)); | 150 AllOf(hasRange(4, 5), hasTransformNode(0)))); |
| 118 } | 151 } |
| 119 | 152 |
| 120 TEST_F(DisplayItemTransformTreeBuilderTest, Only2DTranslation) | 153 TEST_F(DisplayItemPropertyTreeBuilderTest, Only2DTranslation) |
| 121 { | 154 { |
| 122 FloatSize offset(200.5, -100); | 155 FloatSize offset(200.5, -100); |
| 123 TransformationMatrix translation; | 156 TransformationMatrix translation; |
| 124 translation.translate(offset.width(), offset.height()); | 157 translation.translate(offset.width(), offset.height()); |
| 125 | 158 |
| 126 // There's a translation here, but we should not make a node for it. | 159 // There's a translation here, but we should not make a node for it. |
| 127 processDummyDisplayItem(); | 160 processDummyDisplayItem(); |
| 128 auto transformClient = processBeginTransform3D(translation); | 161 auto transformClient = processBeginTransform3D(translation); |
| 129 processDummyDisplayItem(); | 162 processDummyDisplayItem(); |
| 130 processEndTransform3D(transformClient); | 163 processEndTransform3D(transformClient); |
| 131 processDummyDisplayItem(); | 164 processDummyDisplayItem(); |
| 132 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 165 finishPropertyTrees(); |
| 133 | 166 |
| 134 // There should only be a root transform node. | 167 // There should only be a root transform node. |
| 135 ASSERT_EQ(1u, tree.nodeCount()); | 168 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 136 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 169 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 137 EXPECT_EQ(WebDisplayItemTransformTree::kInvalidIndex, tree.nodeAt(0).parentN
odeIndex); | |
| 138 | 170 |
| 139 // There should be three ranges, even though there's only one node. | 171 // There should be three ranges, even though there's only one node. |
| 140 // The middle one requires an offset. | 172 // The middle one requires an offset. |
| 141 ASSERT_EQ(3u, tree.rangeRecordCount()); | 173 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 142 EXPECT_EQ(RangeRecord(0, 1, 0, FloatSize()), tree.rangeRecordAt(0)); | 174 AllOf(hasRange(0, 1), hasTransformNode(0)), |
| 143 EXPECT_EQ(RangeRecord(2, 3, 0, offset), tree.rangeRecordAt(1)); | 175 AllOf(hasRange(2, 3), hasTransformNode(0)), |
| 144 EXPECT_EQ(RangeRecord(4, 5, 0, FloatSize()), tree.rangeRecordAt(2)); | 176 AllOf(hasRange(4, 5), hasTransformNode(0)))); |
| 145 } | 177 } |
| 146 | 178 |
| 147 TEST_F(DisplayItemTransformTreeBuilderTest, Nested2DTranslation) | 179 TEST_F(DisplayItemPropertyTreeBuilderTest, Nested2DTranslation) |
| 148 { | 180 { |
| 149 FloatSize offset1(10, -40); | 181 FloatSize offset1(10, -40); |
| 150 TransformationMatrix translation1; | 182 TransformationMatrix translation1; |
| 151 translation1.translate(offset1.width(), offset1.height()); | 183 translation1.translate(offset1.width(), offset1.height()); |
| 152 FloatSize offset2(80, 80); | 184 FloatSize offset2(80, 80); |
| 153 TransformationMatrix translation2; | 185 TransformationMatrix translation2; |
| 154 translation2.translate(offset2.width(), offset2.height()); | 186 translation2.translate(offset2.width(), offset2.height()); |
| 155 | 187 |
| 156 // These drawings should share a transform node but have different range | 188 // These drawings should share a transform node but have different range |
| 157 // record offsets. | 189 // record offsets. |
| 158 processDummyDisplayItem(); | 190 processDummyDisplayItem(); |
| 159 auto transform1 = processBeginTransform3D(translation1); | 191 auto transform1 = processBeginTransform3D(translation1); |
| 160 processDummyDisplayItem(); | 192 processDummyDisplayItem(); |
| 161 auto transform2 = processBeginTransform3D(translation2); | 193 auto transform2 = processBeginTransform3D(translation2); |
| 162 processDummyDisplayItem(); | 194 processDummyDisplayItem(); |
| 163 processEndTransform3D(transform2); | 195 processEndTransform3D(transform2); |
| 164 processEndTransform3D(transform1); | 196 processEndTransform3D(transform1); |
| 165 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 197 finishPropertyTrees(); |
| 166 | 198 |
| 167 // There should only be a root transform node. | 199 // There should only be a root transform node. |
| 168 ASSERT_EQ(1u, tree.nodeCount()); | 200 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 169 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 201 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 170 EXPECT_EQ(WebDisplayItemTransformTree::kInvalidIndex, tree.nodeAt(0).parentN
odeIndex); | |
| 171 | 202 |
| 172 // Check that the range records have the right offsets. | 203 // Check that the range records have the right offsets. |
| 173 ASSERT_EQ(3u, tree.rangeRecordCount()); | 204 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 174 EXPECT_EQ(RangeRecord(0, 1, 0, FloatSize()), tree.rangeRecordAt(0)); | 205 AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize())), |
| 175 EXPECT_EQ(RangeRecord(2, 3, 0, offset1), tree.rangeRecordAt(1)); | 206 AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(offset1)), |
| 176 EXPECT_EQ(RangeRecord(4, 5, 0, offset1 + offset2), tree.rangeRecordAt(2)); | 207 AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(offset1 + offset2))
)); |
| 177 } | 208 } |
| 178 | 209 |
| 179 TEST_F(DisplayItemTransformTreeBuilderTest, ZTranslation) | 210 TEST_F(DisplayItemPropertyTreeBuilderTest, ZTranslation) |
| 180 { | 211 { |
| 181 TransformationMatrix zTranslation; | 212 TransformationMatrix zTranslation; |
| 182 zTranslation.translate3d(0, 0, 1); | 213 zTranslation.translate3d(0, 0, 1); |
| 183 | 214 |
| 184 // Z translation: we expect another node. | 215 // Z translation: we expect another node. |
| 185 processDummyDisplayItem(); | 216 processDummyDisplayItem(); |
| 186 auto transformClient = processBeginTransform3D(zTranslation); | 217 auto transformClient = processBeginTransform3D(zTranslation); |
| 187 processDummyDisplayItem(); | 218 processDummyDisplayItem(); |
| 188 processEndTransform3D(transformClient); | 219 processEndTransform3D(transformClient); |
| 189 processDummyDisplayItem(); | 220 processDummyDisplayItem(); |
| 190 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 221 finishPropertyTrees(); |
| 191 | 222 |
| 192 // There should be two nodes here. | 223 // There should be two nodes here. |
| 193 ASSERT_EQ(2u, tree.nodeCount()); | 224 ASSERT_EQ(2u, transformTree().nodeCount()); |
| 194 EXPECT_TRUE(tree.nodeAt(0).isRoot()); | 225 EXPECT_TRUE(transformTree().nodeAt(0).isRoot()); |
| 195 EXPECT_EQ(0u, tree.nodeAt(1).parentNodeIndex); | 226 EXPECT_EQ(0u, transformTree().nodeAt(1).parentNodeIndex); |
| 196 | 227 |
| 197 // There should be three range records. | 228 // There should be three range records. |
| 198 // The middle of these should be transformed, and the others should be | 229 // The middle of these should be transformed, and the others should be |
| 199 // attached to the root node. | 230 // attached to the root node. |
| 200 ASSERT_EQ(3u, tree.rangeRecordCount()); | 231 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 201 EXPECT_EQ(RangeRecord(0, 1, 0), tree.rangeRecordAt(0)); | 232 AllOf(hasRange(0, 1), hasTransformNode(0)), |
| 202 EXPECT_EQ(RangeRecord(2, 3, 1), tree.rangeRecordAt(1)); | 233 AllOf(hasRange(2, 3), hasTransformNode(1)), |
| 203 EXPECT_EQ(RangeRecord(4, 5, 0), tree.rangeRecordAt(2)); | 234 AllOf(hasRange(4, 5), hasTransformNode(0)))); |
| 204 } | 235 } |
| 205 | 236 |
| 206 size_t nodeDepth( | 237 template <typename TreeType, typename NodeType> |
| 207 const WebDisplayItemTransformTree& tree, | 238 size_t nodeDepth(const TreeType& tree, const NodeType& node) |
| 208 const WebDisplayItemTransformTree::TransformNode& node) | |
| 209 { | 239 { |
| 210 const auto* currentNode = &node; | 240 const auto* currentNode = &node; |
| 211 size_t depth = 0; | 241 size_t depth = 0; |
| 212 while (!currentNode->isRoot()) { | 242 while (!currentNode->isRoot()) { |
| 213 currentNode = &tree.parentNode(*currentNode); | 243 currentNode = &tree.nodeAt(currentNode->parentNodeIndex); |
| 214 depth++; | 244 depth++; |
| 215 } | 245 } |
| 216 return depth; | 246 return depth; |
| 217 } | 247 } |
| 218 | 248 |
| 219 TEST_F(DisplayItemTransformTreeBuilderTest, SkipUnnecessaryRangeRecords) | 249 TEST_F(DisplayItemPropertyTreeBuilderTest, SkipUnnecessaryRangeRecords) |
| 220 { | 250 { |
| 221 TransformationMatrix rotation; | 251 TransformationMatrix rotation; |
| 222 rotation.rotate(1 /* degrees */); | 252 rotation.rotate(1 /* degrees */); |
| 223 | 253 |
| 224 // The only drawing is in the second transform. | 254 // The only drawing is in the second transform. |
| 225 auto transform1 = processBeginTransform3D(rotation); | 255 auto transform1 = processBeginTransform3D(rotation); |
| 226 auto transform2 = processBeginTransform3D(rotation); | 256 auto transform2 = processBeginTransform3D(rotation); |
| 227 processDummyDisplayItem(); | 257 processDummyDisplayItem(); |
| 228 auto transform3 = processBeginTransform3D(rotation); | 258 auto transform3 = processBeginTransform3D(rotation); |
| 229 processEndTransform3D(transform3); | 259 processEndTransform3D(transform3); |
| 230 processDummyDisplayItem(); | 260 processDummyDisplayItem(); |
| 231 processEndTransform3D(transform2); | 261 processEndTransform3D(transform2); |
| 232 processEndTransform3D(transform1); | 262 processEndTransform3D(transform1); |
| 233 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 263 finishPropertyTrees(); |
| 234 | 264 |
| 235 // There should be only two ranges. | 265 // There should be only two ranges. |
| 236 // They must both belong to the same grandchild of the root node. | 266 // They must both belong to the same grandchild of the root node. |
| 237 ASSERT_EQ(2u, tree.rangeRecordCount()); | 267 ASSERT_EQ(2u, rangeRecords().size()); |
| 238 size_t transformNodeIndex = tree.rangeRecordAt(0).transformNodeIndex; | 268 size_t transformNodeIndex = rangeRecords()[0].transformNodeIndex; |
| 239 EXPECT_EQ(2u, nodeDepth(tree, tree.nodeAt(transformNodeIndex))); | 269 EXPECT_EQ(2u, nodeDepth(transformTree(), transformTree().nodeAt(transformNod
eIndex))); |
| 240 EXPECT_EQ(RangeRecord(2, 3, transformNodeIndex), tree.rangeRecordAt(0)); | 270 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre( |
| 241 EXPECT_EQ(RangeRecord(5, 6, transformNodeIndex), tree.rangeRecordAt(1)); | 271 AllOf(hasRange(2, 3), hasTransformNode(transformNodeIndex)), |
| 272 AllOf(hasRange(5, 6), hasTransformNode(transformNodeIndex)))); |
| 242 } | 273 } |
| 243 | 274 |
| 244 TEST_F(DisplayItemTransformTreeBuilderTest, RootTransformNodeHasIdentityTransfor
m) | 275 TEST_F(DisplayItemPropertyTreeBuilderTest, RootTransformNodeHasIdentityTransform
) |
| 245 { | 276 { |
| 246 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 277 finishPropertyTrees(); |
| 247 ASSERT_EQ(1u, tree.nodeCount()); | 278 ASSERT_EQ(1u, transformTree().nodeCount()); |
| 248 EXPECT_TRUE(tree.nodeAt(0).matrix.isIdentity()); | 279 EXPECT_TRUE(transformTree().nodeAt(0).matrix.isIdentity()); |
| 249 EXPECT_TRANSFORMS_ALMOST_EQ(TransformationMatrix(), tree.nodeAt(0).matrix); | 280 EXPECT_TRANSFORMS_ALMOST_EQ(TransformationMatrix(), transformTree().nodeAt(0
).matrix); |
| 250 } | 281 } |
| 251 | 282 |
| 252 TEST_F(DisplayItemTransformTreeBuilderTest, Transform3DMatrix) | 283 TEST_F(DisplayItemPropertyTreeBuilderTest, Transform3DMatrix) |
| 253 { | 284 { |
| 254 TransformationMatrix matrix; | 285 TransformationMatrix matrix; |
| 255 matrix.rotate3d(45, 45, 45); | 286 matrix.rotate3d(45, 45, 45); |
| 256 | 287 |
| 257 auto transform1 = processBeginTransform3D(matrix); | 288 auto transform1 = processBeginTransform3D(matrix); |
| 258 processDummyDisplayItem(); | 289 processDummyDisplayItem(); |
| 259 processEndTransform3D(transform1); | 290 processEndTransform3D(transform1); |
| 260 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 291 finishPropertyTrees(); |
| 261 | 292 |
| 262 const auto& rangeRecord = tree.rangeRecordAt(0); | 293 const auto& transformNode = transformTree().nodeAt(rangeRecords()[0].transfo
rmNodeIndex); |
| 263 const auto& transformNode = tree.nodeAt(rangeRecord.transformNodeIndex); | |
| 264 EXPECT_TRANSFORMS_ALMOST_EQ(matrix, transformNode.matrix); | 294 EXPECT_TRANSFORMS_ALMOST_EQ(matrix, transformNode.matrix); |
| 265 } | 295 } |
| 266 | 296 |
| 267 TEST_F(DisplayItemTransformTreeBuilderTest, NestedTransformsAreNotCombined) | 297 TEST_F(DisplayItemPropertyTreeBuilderTest, NestedTransformsAreNotCombined) |
| 268 { | 298 { |
| 269 // It's up the consumer of the tree to multiply transformation matrices. | 299 // It's up the consumer of the tree to multiply transformation matrices. |
| 270 | 300 |
| 271 TransformationMatrix matrix1; | 301 TransformationMatrix matrix1; |
| 272 matrix1.rotate3d(45, 45, 45); | 302 matrix1.rotate3d(45, 45, 45); |
| 273 TransformationMatrix matrix2; | 303 TransformationMatrix matrix2; |
| 274 matrix2.translate3d(0, 10, 20); | 304 matrix2.translate3d(0, 10, 20); |
| 275 EXPECT_NE(matrix2, matrix1 * matrix2); | 305 EXPECT_NE(matrix2, matrix1 * matrix2); |
| 276 | 306 |
| 277 auto transform1 = processBeginTransform3D(matrix1); | 307 auto transform1 = processBeginTransform3D(matrix1); |
| 278 auto transform2 = processBeginTransform3D(matrix2); | 308 auto transform2 = processBeginTransform3D(matrix2); |
| 279 processDummyDisplayItem(); | 309 processDummyDisplayItem(); |
| 280 processEndTransform3D(transform2); | 310 processEndTransform3D(transform2); |
| 281 processDummyDisplayItem(); | 311 processDummyDisplayItem(); |
| 282 processEndTransform3D(transform1); | 312 processEndTransform3D(transform1); |
| 283 WebDisplayItemTransformTree tree(builder().releaseTransformTree()); | 313 finishPropertyTrees(); |
| 284 | 314 |
| 285 const auto& transformNode = tree.nodeAt(tree.rangeRecordAt(0).transformNodeI
ndex); | 315 const auto& transformNode = transformTree().nodeAt(rangeRecords()[0].transfo
rmNodeIndex); |
| 286 ASSERT_FALSE(transformNode.isRoot()); | 316 ASSERT_FALSE(transformNode.isRoot()); |
| 287 EXPECT_TRANSFORMS_ALMOST_EQ(matrix2, transformNode.matrix); | 317 EXPECT_TRANSFORMS_ALMOST_EQ(matrix2, transformNode.matrix); |
| 288 EXPECT_TRANSFORMS_ALMOST_EQ(matrix1, tree.parentNode(transformNode).matrix); | 318 const auto& parentNode = transformTree().nodeAt(transformNode.parentNodeInde
x); |
| 319 EXPECT_TRANSFORMS_ALMOST_EQ(matrix1, parentNode.matrix); |
| 289 } | 320 } |
| 290 | 321 |
| 291 } // namespace | 322 } // namespace |
| 292 } // namespace blink | 323 } // namespace blink |
| OLD | NEW |