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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/DisplayItemPropertyTreeBuilder.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/DisplayItemClipTree.h"
11 #include "platform/graphics/paint/DisplayItemTransformTree.h" 11 #include "platform/graphics/paint/DisplayItemTransformTree.h"
12 #include "platform/graphics/paint/ScrollDisplayItem.h"
12 #include "platform/graphics/paint/Transform3DDisplayItem.h" 13 #include "platform/graphics/paint/Transform3DDisplayItem.h"
14 #include "platform/graphics/paint/TransformDisplayItem.h"
13 #include "platform/transforms/TransformTestHelper.h" 15 #include "platform/transforms/TransformTestHelper.h"
14 #include "platform/transforms/TransformationMatrix.h" 16 #include "platform/transforms/TransformationMatrix.h"
15 #include "public/platform/WebDisplayItemTransformTree.h" 17 #include "public/platform/WebDisplayItemTransformTree.h"
16 #include "wtf/OwnPtr.h" 18 #include "wtf/OwnPtr.h"
17 #include <gmock/gmock.h> 19 #include <gmock/gmock.h>
18 #include <gtest/gtest.h> 20 #include <gtest/gtest.h>
19 21
20 namespace blink { 22 namespace blink {
21 namespace { 23 namespace {
22 24
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const DummyClient& processBeginTransform3D(const TransformationMatrix& trans form) 67 const DummyClient& processBeginTransform3D(const TransformationMatrix& trans form)
66 { 68 {
67 const DummyClient& client = newDummyClient(); 69 const DummyClient& client = newDummyClient();
68 processDisplayItem(BeginTransform3DDisplayItem(client, DisplayItem::Tran sform3DElementTransform, transform)); 70 processDisplayItem(BeginTransform3DDisplayItem(client, DisplayItem::Tran sform3DElementTransform, transform));
69 return client; 71 return client;
70 } 72 }
71 void processEndTransform3D(const DummyClient& client) 73 void processEndTransform3D(const DummyClient& client)
72 { 74 {
73 processDisplayItem(EndTransform3DDisplayItem(client, DisplayItem::transf orm3DTypeToEndTransform3DType(DisplayItem::Transform3DElementTransform))); 75 processDisplayItem(EndTransform3DDisplayItem(client, DisplayItem::transf orm3DTypeToEndTransform3DType(DisplayItem::Transform3DElementTransform)));
74 } 76 }
77 const DummyClient& processBeginTransform(const AffineTransform& transform)
78 {
79 const DummyClient& client = newDummyClient();
80 processDisplayItem(BeginTransformDisplayItem(client, transform));
81 return client;
82 }
83 void processEndTransform(const DummyClient& client)
84 {
85 processDisplayItem(EndTransformDisplayItem(client));
86 }
87 const DummyClient& processBeginScroll(int offsetX, int offsetY)
88 {
89 const DummyClient& client = newDummyClient();
90 processDisplayItem(BeginScrollDisplayItem(client, DisplayItem::ScrollFir st, IntSize(offsetX, offsetY)));
91 return client;
92 }
93 void processEndScroll(const DummyClient& client)
94 {
95 processDisplayItem(EndScrollDisplayItem(client, DisplayItem::EndScrollFi rst));
96 }
75 97
76 void finishPropertyTrees() 98 void finishPropertyTrees()
77 { 99 {
78 m_transformTree = m_builder.releaseTransformTree(); 100 m_transformTree = m_builder.releaseTransformTree();
79 m_clipTree = m_builder.releaseClipTree(); 101 m_clipTree = m_builder.releaseClipTree();
80 m_rangeRecords = m_builder.releaseRangeRecords(); 102 m_rangeRecords = m_builder.releaseRangeRecords();
81 } 103 }
82 104
83 private: 105 private:
84 // This makes empty objects which can be used as display item clients. 106 // This makes empty objects which can be used as display item clients.
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 processEndTransform3D(transform1); 334 processEndTransform3D(transform1);
313 finishPropertyTrees(); 335 finishPropertyTrees();
314 336
315 const auto& transformNode = transformTree().nodeAt(rangeRecords()[0].transfo rmNodeIndex); 337 const auto& transformNode = transformTree().nodeAt(rangeRecords()[0].transfo rmNodeIndex);
316 ASSERT_FALSE(transformNode.isRoot()); 338 ASSERT_FALSE(transformNode.isRoot());
317 EXPECT_TRANSFORMS_ALMOST_EQ(matrix2, transformNode.matrix); 339 EXPECT_TRANSFORMS_ALMOST_EQ(matrix2, transformNode.matrix);
318 const auto& parentNode = transformTree().nodeAt(transformNode.parentNodeInde x); 340 const auto& parentNode = transformTree().nodeAt(transformNode.parentNodeInde x);
319 EXPECT_TRANSFORMS_ALMOST_EQ(matrix1, parentNode.matrix); 341 EXPECT_TRANSFORMS_ALMOST_EQ(matrix1, parentNode.matrix);
320 } 342 }
321 343
344 TEST_F(DisplayItemPropertyTreeBuilderTest, TransformDisplayItemCreatesTransformN ode)
345 {
346 // 2D transform display items should create a transform node as well,
347 // unless the transform is a 2D translation only.
348 AffineTransform rotation;
349 rotation.rotate(45);
350
351 processDummyDisplayItem();
352 auto transformClient = processBeginTransform(rotation);
353 processDummyDisplayItem();
354 processEndTransform(transformClient);
355 processDummyDisplayItem();
356 finishPropertyTrees();
357
358 // There should be two transform nodes.
359 ASSERT_EQ(2u, transformTree().nodeCount());
360 EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
361 EXPECT_EQ(0u, transformTree().nodeAt(1).parentNodeIndex);
362 EXPECT_TRANSFORMS_ALMOST_EQ(TransformationMatrix(rotation), transformTree(). nodeAt(1).matrix);
363
364 // There should be three range records, the middle one affected by the
365 // rotation.
366 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
367 AllOf(hasRange(0, 1), hasTransformNode(0)),
368 AllOf(hasRange(2, 3), hasTransformNode(1)),
369 AllOf(hasRange(4, 5), hasTransformNode(0))));
370 }
371
372 TEST_F(DisplayItemPropertyTreeBuilderTest, TransformDisplayItemOnly2DTranslation )
373 {
374 // In this case no transform node should be created for the 2D translation.
375 AffineTransform translation = AffineTransform::translation(10, -40);
376
377 processDummyDisplayItem();
378 auto transformClient = processBeginTransform(translation);
379 processDummyDisplayItem();
380 processEndTransform(transformClient);
381 processDummyDisplayItem();
382 finishPropertyTrees();
383
384 // There should be only one transform node.
385 ASSERT_EQ(1u, transformTree().nodeCount());
386 EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
387
388 // There should be three range records, the middle one affected by the
389 // translation.
390 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
391 AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize(0, 0))),
392 AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(FloatSize(10, -40)) ),
393 AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(FloatSize(0, 0))))) ;
394 }
395
396 TEST_F(DisplayItemPropertyTreeBuilderTest, ScrollDisplayItemIs2DTranslation)
397 {
398 processDummyDisplayItem();
399 auto scrollClient = processBeginScroll(-90, 400);
400 processDummyDisplayItem();
401 processEndScroll(scrollClient);
402 processDummyDisplayItem();
403 finishPropertyTrees();
404
405 // There should be only one transform node.
406 ASSERT_EQ(1u, transformTree().nodeCount());
407 EXPECT_TRUE(transformTree().nodeAt(0).isRoot());
408
409 // There should be three range records, the middle one affected by the
410 // scroll. Note that the translation due to scroll is the negative of the
411 // scroll offset.
412 EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
413 AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize(0, 0))),
414 AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(FloatSize(90, -400) )),
415 AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(FloatSize(0, 0))))) ;
416 }
417
322 } // namespace 418 } // namespace
323 } // namespace blink 419 } // namespace blink
OLDNEW
« 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