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