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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp

Issue 2793993003: Make GeometryMapper fully static (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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"
11 #include "cc/layers/layer.h" 11 #include "cc/layers/layer.h"
12 #include "cc/test/fake_compositor_frame_sink.h" 12 #include "cc/test/fake_compositor_frame_sink.h"
13 #include "cc/test/geometry_test_utils.h" 13 #include "cc/test/geometry_test_utils.h"
14 #include "cc/trees/clip_node.h" 14 #include "cc/trees/clip_node.h"
15 #include "cc/trees/effect_node.h" 15 #include "cc/trees/effect_node.h"
16 #include "cc/trees/layer_tree_host.h" 16 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/layer_tree_settings.h" 17 #include "cc/trees/layer_tree_settings.h"
18 #include "cc/trees/scroll_node.h" 18 #include "cc/trees/scroll_node.h"
19 #include "cc/trees/transform_node.h" 19 #include "cc/trees/transform_node.h"
20 #include "platform/graphics/paint/EffectPaintPropertyNode.h" 20 #include "platform/graphics/paint/EffectPaintPropertyNode.h"
21 #include "platform/graphics/paint/GeometryMapper.h"
22 #include "platform/graphics/paint/PaintArtifact.h" 21 #include "platform/graphics/paint/PaintArtifact.h"
23 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" 22 #include "platform/graphics/paint/ScrollPaintPropertyNode.h"
24 #include "platform/testing/PaintPropertyTestHelpers.h" 23 #include "platform/testing/PaintPropertyTestHelpers.h"
25 #include "platform/testing/PictureMatchers.h" 24 #include "platform/testing/PictureMatchers.h"
26 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" 25 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
27 #include "platform/testing/TestPaintArtifact.h" 26 #include "platform/testing/TestPaintArtifact.h"
28 #include "platform/testing/WebLayerTreeViewImplForTesting.h" 27 #include "platform/testing/WebLayerTreeViewImplForTesting.h"
29 #include "public/platform/WebLayerScrollClient.h" 28 #include "public/platform/WebLayerScrollClient.h"
30 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return m_webLayerTreeView->layerTreeHost() 112 return m_webLayerTreeView->layerTreeHost()
114 ->property_trees() 113 ->property_trees()
115 ->element_id_to_scroll_node_index[elementId]; 114 ->element_id_to_scroll_node_index[elementId];
116 } 115 }
117 116
118 const cc::TransformNode& transformNode(const cc::Layer* layer) { 117 const cc::TransformNode& transformNode(const cc::Layer* layer) {
119 return *propertyTrees().transform_tree.Node(layer->transform_tree_index()); 118 return *propertyTrees().transform_tree.Node(layer->transform_tree_index());
120 } 119 }
121 120
122 void update(const PaintArtifact& artifact) { 121 void update(const PaintArtifact& artifact) {
123 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); 122 m_paintArtifactCompositor->update(artifact, nullptr, false);
124 m_paintArtifactCompositor->update(artifact, nullptr, false,
125 *geometryMapper);
126 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers(); 123 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers();
127 } 124 }
128 125
129 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } 126 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); }
130 127
131 size_t contentLayerCount() { 128 size_t contentLayerCount() {
132 return m_paintArtifactCompositor->getExtraDataForTesting() 129 return m_paintArtifactCompositor->getExtraDataForTesting()
133 ->contentLayers.size(); 130 ->contentLayers.size();
134 } 131 }
135 132
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MightOverlap) { 1435 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MightOverlap) {
1439 PaintChunk paintChunk; 1436 PaintChunk paintChunk;
1440 paintChunk.properties = defaultPaintChunkProperties(); 1437 paintChunk.properties = defaultPaintChunkProperties();
1441 paintChunk.bounds = FloatRect(0, 0, 100, 100); 1438 paintChunk.bounds = FloatRect(0, 0, 100, 100);
1442 PaintArtifactCompositor::PendingLayer pendingLayer(paintChunk, false); 1439 PaintArtifactCompositor::PendingLayer pendingLayer(paintChunk, false);
1443 1440
1444 PaintChunk paintChunk2; 1441 PaintChunk paintChunk2;
1445 paintChunk2.properties = defaultPaintChunkProperties(); 1442 paintChunk2.properties = defaultPaintChunkProperties();
1446 paintChunk2.bounds = FloatRect(0, 0, 100, 100); 1443 paintChunk2.bounds = FloatRect(0, 0, 100, 100);
1447 1444
1448 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create();
1449
1450 { 1445 {
1451 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false); 1446 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false);
1452 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( 1447 EXPECT_TRUE(
1453 pendingLayer, pendingLayer2, *geometryMapper)); 1448 PaintArtifactCompositor::mightOverlap(pendingLayer, pendingLayer2));
1454 } 1449 }
1455 1450
1456 RefPtr<TransformPaintPropertyNode> transform = 1451 RefPtr<TransformPaintPropertyNode> transform =
1457 TransformPaintPropertyNode::create( 1452 TransformPaintPropertyNode::create(
1458 TransformPaintPropertyNode::root(), 1453 TransformPaintPropertyNode::root(),
1459 TransformationMatrix().translate(99, 0), FloatPoint3D(100, 100, 0), 1454 TransformationMatrix().translate(99, 0), FloatPoint3D(100, 100, 0),
1460 false); 1455 false);
1461 { 1456 {
1462 paintChunk2.properties.propertyTreeState.setTransform(transform.get()); 1457 paintChunk2.properties.propertyTreeState.setTransform(transform.get());
1463 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false); 1458 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false);
1464 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( 1459 EXPECT_TRUE(
1465 pendingLayer, pendingLayer2, *geometryMapper)); 1460 PaintArtifactCompositor::mightOverlap(pendingLayer, pendingLayer2));
1466 } 1461 }
1467 1462
1468 RefPtr<TransformPaintPropertyNode> transform2 = 1463 RefPtr<TransformPaintPropertyNode> transform2 =
1469 TransformPaintPropertyNode::create( 1464 TransformPaintPropertyNode::create(
1470 TransformPaintPropertyNode::root(), 1465 TransformPaintPropertyNode::root(),
1471 TransformationMatrix().translate(100, 0), FloatPoint3D(100, 100, 0), 1466 TransformationMatrix().translate(100, 0), FloatPoint3D(100, 100, 0),
1472 false); 1467 false);
1473 { 1468 {
1474 paintChunk2.properties.propertyTreeState.setTransform(transform2.get()); 1469 paintChunk2.properties.propertyTreeState.setTransform(transform2.get());
1475 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false); 1470 PaintArtifactCompositor::PendingLayer pendingLayer2(paintChunk2, false);
1476 EXPECT_FALSE(PaintArtifactCompositor::mightOverlap( 1471 EXPECT_FALSE(
1477 pendingLayer, pendingLayer2, *geometryMapper)); 1472 PaintArtifactCompositor::mightOverlap(pendingLayer, pendingLayer2));
1478 } 1473 }
1479 } 1474 }
1480 1475
1481 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { 1476 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) {
1482 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create();
1483
1484 PaintChunk chunk1; 1477 PaintChunk chunk1;
1485 chunk1.properties.propertyTreeState = PropertyTreeState( 1478 chunk1.properties.propertyTreeState = PropertyTreeState(
1486 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), 1479 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1487 EffectPaintPropertyNode::root()); 1480 EffectPaintPropertyNode::root());
1488 chunk1.properties.backfaceHidden = true; 1481 chunk1.properties.backfaceHidden = true;
1489 chunk1.knownToBeOpaque = true; 1482 chunk1.knownToBeOpaque = true;
1490 chunk1.bounds = FloatRect(0, 0, 30, 40); 1483 chunk1.bounds = FloatRect(0, 0, 30, 40);
1491 1484
1492 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false); 1485 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false);
1493 1486
1494 EXPECT_TRUE(pendingLayer.backfaceHidden); 1487 EXPECT_TRUE(pendingLayer.backfaceHidden);
1495 EXPECT_TRUE(pendingLayer.knownToBeOpaque); 1488 EXPECT_TRUE(pendingLayer.knownToBeOpaque);
1496 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); 1489 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds);
1497 1490
1498 PaintChunk chunk2; 1491 PaintChunk chunk2;
1499 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1492 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1500 chunk2.properties.backfaceHidden = true; 1493 chunk2.properties.backfaceHidden = true;
1501 chunk2.knownToBeOpaque = true; 1494 chunk2.knownToBeOpaque = true;
1502 chunk2.bounds = FloatRect(10, 20, 30, 40); 1495 chunk2.bounds = FloatRect(10, 20, 30, 40);
1503 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false), 1496 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false));
1504 *geometryMapper);
1505 1497
1506 EXPECT_TRUE(pendingLayer.backfaceHidden); 1498 EXPECT_TRUE(pendingLayer.backfaceHidden);
1507 // Bounds not equal to one PaintChunk. 1499 // Bounds not equal to one PaintChunk.
1508 EXPECT_FALSE(pendingLayer.knownToBeOpaque); 1500 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1509 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds); 1501 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds);
1510 1502
1511 PaintChunk chunk3; 1503 PaintChunk chunk3;
1512 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1504 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1513 chunk3.properties.backfaceHidden = true; 1505 chunk3.properties.backfaceHidden = true;
1514 chunk3.knownToBeOpaque = true; 1506 chunk3.knownToBeOpaque = true;
1515 chunk3.bounds = FloatRect(-5, -25, 20, 20); 1507 chunk3.bounds = FloatRect(-5, -25, 20, 20);
1516 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk3, false), 1508 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk3, false));
1517 *geometryMapper);
1518 1509
1519 EXPECT_TRUE(pendingLayer.backfaceHidden); 1510 EXPECT_TRUE(pendingLayer.backfaceHidden);
1520 EXPECT_FALSE(pendingLayer.knownToBeOpaque); 1511 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1521 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds); 1512 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds);
1522 } 1513 }
1523 1514
1524 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerWithGeometry) { 1515 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerWithGeometry) {
1525 RefPtr<TransformPaintPropertyNode> transform = 1516 RefPtr<TransformPaintPropertyNode> transform =
1526 TransformPaintPropertyNode::create( 1517 TransformPaintPropertyNode::create(
1527 TransformPaintPropertyNode::root(), 1518 TransformPaintPropertyNode::root(),
1528 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), 1519 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0),
1529 false, 0); 1520 false, 0);
1530 1521
1531 PaintChunk chunk1; 1522 PaintChunk chunk1;
1532 chunk1.properties.propertyTreeState = PropertyTreeState( 1523 chunk1.properties.propertyTreeState = PropertyTreeState(
1533 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), 1524 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1534 EffectPaintPropertyNode::root()); 1525 EffectPaintPropertyNode::root());
1535 chunk1.bounds = FloatRect(0, 0, 30, 40); 1526 chunk1.bounds = FloatRect(0, 0, 30, 40);
1536 1527
1537 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false); 1528 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false);
1538 1529
1539 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); 1530 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds);
1540 1531
1541 PaintChunk chunk2; 1532 PaintChunk chunk2;
1542 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1533 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1543 chunk2.properties.propertyTreeState.setTransform(transform); 1534 chunk2.properties.propertyTreeState.setTransform(transform);
1544 chunk2.bounds = FloatRect(0, 0, 50, 60); 1535 chunk2.bounds = FloatRect(0, 0, 50, 60);
1545 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); 1536 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false));
1546 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false),
1547 *geometryMapper);
1548 1537
1549 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); 1538 EXPECT_BLINK_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds);
1550 } 1539 }
1551 1540
1552 // TODO(crbug.com/701991): 1541 // TODO(crbug.com/701991):
1553 // The test is disabled because opaque rect mapping is not implemented yet. 1542 // The test is disabled because opaque rect mapping is not implemented yet.
1554 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, 1543 TEST_F(PaintArtifactCompositorTestWithPropertyTrees,
1555 PendingLayerKnownOpaque_DISABLED) { 1544 PendingLayerKnownOpaque_DISABLED) {
1556 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create();
1557
1558 PaintChunk chunk1; 1545 PaintChunk chunk1;
1559 chunk1.properties.propertyTreeState = PropertyTreeState( 1546 chunk1.properties.propertyTreeState = PropertyTreeState(
1560 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), 1547 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1561 EffectPaintPropertyNode::root()); 1548 EffectPaintPropertyNode::root());
1562 chunk1.bounds = FloatRect(0, 0, 30, 40); 1549 chunk1.bounds = FloatRect(0, 0, 30, 40);
1563 chunk1.knownToBeOpaque = false; 1550 chunk1.knownToBeOpaque = false;
1564 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false); 1551 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1, false);
1565 1552
1566 EXPECT_FALSE(pendingLayer.knownToBeOpaque); 1553 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1567 1554
1568 PaintChunk chunk2; 1555 PaintChunk chunk2;
1569 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1556 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1570 chunk2.bounds = FloatRect(0, 0, 25, 35); 1557 chunk2.bounds = FloatRect(0, 0, 25, 35);
1571 chunk2.knownToBeOpaque = true; 1558 chunk2.knownToBeOpaque = true;
1572 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false), 1559 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk2, false));
1573 *geometryMapper);
1574 1560
1575 // Chunk 2 doesn't cover the entire layer, so not opaque. 1561 // Chunk 2 doesn't cover the entire layer, so not opaque.
1576 EXPECT_FALSE(pendingLayer.knownToBeOpaque); 1562 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1577 1563
1578 PaintChunk chunk3; 1564 PaintChunk chunk3;
1579 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1565 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1580 chunk3.bounds = FloatRect(0, 0, 50, 60); 1566 chunk3.bounds = FloatRect(0, 0, 50, 60);
1581 chunk3.knownToBeOpaque = true; 1567 chunk3.knownToBeOpaque = true;
1582 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk3, false), 1568 pendingLayer.merge(PaintArtifactCompositor::PendingLayer(chunk3, false));
1583 *geometryMapper);
1584 1569
1585 // Chunk 3 covers the entire layer, so now it's opaque. 1570 // Chunk 3 covers the entire layer, so now it's opaque.
1586 EXPECT_TRUE(pendingLayer.knownToBeOpaque); 1571 EXPECT_TRUE(pendingLayer.knownToBeOpaque);
1587 } 1572 }
1588 1573
1589 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformWithElementId) { 1574 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformWithElementId) {
1590 CompositorElementId expectedCompositorElementId(2, 0); 1575 CompositorElementId expectedCompositorElementId(2, 0);
1591 RefPtr<TransformPaintPropertyNode> transform = 1576 RefPtr<TransformPaintPropertyNode> transform =
1592 TransformPaintPropertyNode::create( 1577 TransformPaintPropertyNode::create(
1593 TransformPaintPropertyNode::root(), TransformationMatrix().rotate(90), 1578 TransformPaintPropertyNode::root(), TransformationMatrix().rotate(90),
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 EXPECT_EQ(gfx::Size(50, 50), layer3->bounds()); 1957 EXPECT_EQ(gfx::Size(50, 50), layer3->bounds());
1973 EXPECT_EQ(effectNode->id, layer3->effect_tree_index()); 1958 EXPECT_EQ(effectNode->id, layer3->effect_tree_index());
1974 1959
1975 const cc::Layer* layer4 = contentLayerAt(3); 1960 const cc::Layer* layer4 = contentLayerAt(3);
1976 EXPECT_EQ(gfx::Vector2dF(100.f, 0.f), layer4->offset_to_transform_parent()); 1961 EXPECT_EQ(gfx::Vector2dF(100.f, 0.f), layer4->offset_to_transform_parent());
1977 EXPECT_EQ(gfx::Size(150, 150), layer4->bounds()); 1962 EXPECT_EQ(gfx::Size(150, 150), layer4->bounds());
1978 EXPECT_EQ(1, layer4->effect_tree_index()); 1963 EXPECT_EQ(1, layer4->effect_tree_index());
1979 } 1964 }
1980 1965
1981 } // namespace blink 1966 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698