| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return m_webLayerTreeView->layerTreeHost() | 112 return m_webLayerTreeView->layerTreeHost() |
| 113 ->property_trees() | 113 ->property_trees() |
| 114 ->element_id_to_scroll_node_index[elementId]; | 114 ->element_id_to_scroll_node_index[elementId]; |
| 115 } | 115 } |
| 116 | 116 |
| 117 const cc::TransformNode& transformNode(const cc::Layer* layer) { | 117 const cc::TransformNode& transformNode(const cc::Layer* layer) { |
| 118 return *propertyTrees().transform_tree.Node(layer->transform_tree_index()); | 118 return *propertyTrees().transform_tree.Node(layer->transform_tree_index()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void update(const PaintArtifact& artifact) { | 121 void update(const PaintArtifact& artifact) { |
| 122 GeometryMapper geometryMapper; | 122 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); |
| 123 m_paintArtifactCompositor->update(artifact, nullptr, false, geometryMapper); | 123 m_paintArtifactCompositor->update(artifact, nullptr, false, |
| 124 *geometryMapper); |
| 124 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers(); | 125 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } | 128 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } |
| 128 | 129 |
| 129 size_t contentLayerCount() { | 130 size_t contentLayerCount() { |
| 130 return m_paintArtifactCompositor->getExtraDataForTesting() | 131 return m_paintArtifactCompositor->getExtraDataForTesting() |
| 131 ->contentLayers.size(); | 132 ->contentLayers.size(); |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | 1503 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1503 | 1504 |
| 1504 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | 1505 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 1505 artifact, artifact.paintChunks()[1], pendingLayer)); | 1506 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1506 | 1507 |
| 1507 PaintArtifactCompositor::PendingLayer pendingLayer2( | 1508 PaintArtifactCompositor::PendingLayer pendingLayer2( |
| 1508 artifact.paintChunks()[1]); | 1509 artifact.paintChunks()[1]); |
| 1509 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | 1510 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 1510 artifact, artifact.paintChunks()[2], pendingLayer2)); | 1511 artifact, artifact.paintChunks()[2], pendingLayer2)); |
| 1511 | 1512 |
| 1512 GeometryMapper geometryMapper; | 1513 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); |
| 1513 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( | 1514 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( |
| 1514 artifact.paintChunks()[2], pendingLayer2, geometryMapper)); | 1515 artifact.paintChunks()[2], pendingLayer2, *geometryMapper)); |
| 1515 | 1516 |
| 1516 update(artifact); | 1517 update(artifact); |
| 1517 | 1518 |
| 1518 // The third paint chunk overlaps the second but can't merge due to | 1519 // The third paint chunk overlaps the second but can't merge due to |
| 1519 // incompatible transform. The second paint chunk can't merge into the first | 1520 // incompatible transform. The second paint chunk can't merge into the first |
| 1520 // due to a direct compositing reason. | 1521 // due to a direct compositing reason. |
| 1521 ASSERT_EQ(3u, contentLayerCount()); | 1522 ASSERT_EQ(3u, contentLayerCount()); |
| 1522 } | 1523 } |
| 1523 | 1524 |
| 1524 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MightOverlap) { | 1525 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MightOverlap) { |
| 1525 PaintChunk paintChunk; | 1526 PaintChunk paintChunk; |
| 1526 paintChunk.properties = defaultPaintChunkProperties(); | 1527 paintChunk.properties = defaultPaintChunkProperties(); |
| 1527 paintChunk.bounds = FloatRect(0, 0, 100, 100); | 1528 paintChunk.bounds = FloatRect(0, 0, 100, 100); |
| 1528 | 1529 |
| 1529 PaintChunk paintChunk2; | 1530 PaintChunk paintChunk2; |
| 1530 paintChunk2.properties = defaultPaintChunkProperties(); | 1531 paintChunk2.properties = defaultPaintChunkProperties(); |
| 1531 paintChunk2.bounds = FloatRect(0, 0, 100, 100); | 1532 paintChunk2.bounds = FloatRect(0, 0, 100, 100); |
| 1532 | 1533 |
| 1533 GeometryMapper geometryMapper; | 1534 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); |
| 1534 PaintArtifactCompositor::PendingLayer pendingLayer(paintChunk); | 1535 PaintArtifactCompositor::PendingLayer pendingLayer(paintChunk); |
| 1535 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | 1536 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, |
| 1536 geometryMapper)); | 1537 *geometryMapper)); |
| 1537 | 1538 |
| 1538 RefPtr<TransformPaintPropertyNode> transform = | 1539 RefPtr<TransformPaintPropertyNode> transform = |
| 1539 TransformPaintPropertyNode::create( | 1540 TransformPaintPropertyNode::create( |
| 1540 TransformPaintPropertyNode::root(), | 1541 TransformPaintPropertyNode::root(), |
| 1541 TransformationMatrix().translate(99, 0), FloatPoint3D(100, 100, 0), | 1542 TransformationMatrix().translate(99, 0), FloatPoint3D(100, 100, 0), |
| 1542 false); | 1543 false); |
| 1543 | 1544 |
| 1544 paintChunk2.properties.propertyTreeState.setTransform(transform.get()); | 1545 paintChunk2.properties.propertyTreeState.setTransform(transform.get()); |
| 1545 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | 1546 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, |
| 1546 geometryMapper)); | 1547 *geometryMapper)); |
| 1547 | 1548 |
| 1548 RefPtr<TransformPaintPropertyNode> transform2 = | 1549 RefPtr<TransformPaintPropertyNode> transform2 = |
| 1549 TransformPaintPropertyNode::create( | 1550 TransformPaintPropertyNode::create( |
| 1550 TransformPaintPropertyNode::root(), | 1551 TransformPaintPropertyNode::root(), |
| 1551 TransformationMatrix().translate(100, 0), FloatPoint3D(100, 100, 0), | 1552 TransformationMatrix().translate(100, 0), FloatPoint3D(100, 100, 0), |
| 1552 false); | 1553 false); |
| 1553 paintChunk2.properties.propertyTreeState.setTransform(transform2.get()); | 1554 paintChunk2.properties.propertyTreeState.setTransform(transform2.get()); |
| 1554 | 1555 |
| 1555 EXPECT_FALSE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | 1556 EXPECT_FALSE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, |
| 1556 geometryMapper)); | 1557 *geometryMapper)); |
| 1557 } | 1558 } |
| 1558 | 1559 |
| 1559 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { | 1560 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { |
| 1560 PaintChunk chunk1; | 1561 PaintChunk chunk1; |
| 1561 chunk1.properties.propertyTreeState = PropertyTreeState( | 1562 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1562 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 1563 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1563 EffectPaintPropertyNode::root()); | 1564 EffectPaintPropertyNode::root()); |
| 1564 chunk1.properties.backfaceHidden = true; | 1565 chunk1.properties.backfaceHidden = true; |
| 1565 chunk1.knownToBeOpaque = true; | 1566 chunk1.knownToBeOpaque = true; |
| 1566 chunk1.bounds = FloatRect(0, 0, 30, 40); | 1567 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 chunk1.bounds = FloatRect(0, 0, 30, 40); | 1610 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1610 | 1611 |
| 1611 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); | 1612 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| 1612 | 1613 |
| 1613 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); | 1614 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| 1614 | 1615 |
| 1615 PaintChunk chunk2; | 1616 PaintChunk chunk2; |
| 1616 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; | 1617 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1617 chunk2.properties.propertyTreeState.setTransform(transform); | 1618 chunk2.properties.propertyTreeState.setTransform(transform); |
| 1618 chunk2.bounds = FloatRect(0, 0, 50, 60); | 1619 chunk2.bounds = FloatRect(0, 0, 50, 60); |
| 1619 GeometryMapper geometryMapper; | 1620 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); |
| 1620 pendingLayer.add(chunk2, &geometryMapper); | 1621 pendingLayer.add(chunk2, geometryMapper.get()); |
| 1621 | 1622 |
| 1622 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); | 1623 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); |
| 1623 } | 1624 } |
| 1624 | 1625 |
| 1625 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerKnownOpaque) { | 1626 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerKnownOpaque) { |
| 1626 PaintChunk chunk1; | 1627 PaintChunk chunk1; |
| 1627 chunk1.properties.propertyTreeState = PropertyTreeState( | 1628 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1628 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 1629 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1629 EffectPaintPropertyNode::root()); | 1630 EffectPaintPropertyNode::root()); |
| 1630 chunk1.bounds = FloatRect(0, 0, 30, 40); | 1631 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 artifact | 1684 artifact |
| 1684 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 1685 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1685 effect.get()) | 1686 effect.get()) |
| 1686 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); | 1687 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); |
| 1687 update(artifact.build()); | 1688 update(artifact.build()); |
| 1688 | 1689 |
| 1689 EXPECT_EQ(2, elementIdToEffectNodeIndex(expectedCompositorElementId)); | 1690 EXPECT_EQ(2, elementIdToEffectNodeIndex(expectedCompositorElementId)); |
| 1690 } | 1691 } |
| 1691 | 1692 |
| 1692 } // namespace blink | 1693 } // namespace blink |
| OLD | NEW |