Chromium Code Reviews| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, | 559 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, |
| 560 ForeignLayerPassesThrough) { | 560 ForeignLayerPassesThrough) { |
| 561 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); | 561 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); |
| 562 | 562 |
| 563 TestPaintArtifact testArtifact; | 563 TestPaintArtifact testArtifact; |
| 564 testArtifact | 564 testArtifact |
| 565 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 565 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 566 EffectPaintPropertyNode::root()) | 566 EffectPaintPropertyNode::root()) |
| 567 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 567 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 568 testArtifact.chunk(defaultPaintChunkProperties()) | 568 testArtifact.chunk(defaultPaintChunkProperties()) |
| 569 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); | 569 .foreignLayer(FloatPoint(50, 60), IntSize(400, 300), layer); |
|
chrishtr
2016/12/29 19:35:13
Changed this to ensure overlap.
| |
| 570 testArtifact | 570 testArtifact |
| 571 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 571 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 572 EffectPaintPropertyNode::root()) | 572 EffectPaintPropertyNode::root()) |
| 573 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); | 573 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 574 | 574 |
| 575 const PaintArtifact& artifact = testArtifact.build(); | 575 const PaintArtifact& artifact = testArtifact.build(); |
| 576 | 576 |
| 577 ASSERT_EQ(3u, artifact.paintChunks().size()); | 577 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 578 PaintArtifactCompositor::PendingLayer pendingLayer1( | 578 PaintArtifactCompositor::PendingLayer pendingLayer1( |
| 579 artifact.paintChunks()[0]); | 579 artifact.paintChunks()[0]); |
| 580 // Foreign layers can't merge. | 580 // Foreign layers can't merge. |
| 581 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | 581 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 582 artifact, artifact.paintChunks()[1], pendingLayer1)); | 582 artifact, artifact.paintChunks()[1], pendingLayer1)); |
| 583 PaintArtifactCompositor::PendingLayer pendingLayer2( | 583 PaintArtifactCompositor::PendingLayer pendingLayer2( |
| 584 artifact.paintChunks()[1]); | 584 artifact.paintChunks()[1]); |
| 585 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | 585 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 586 artifact, artifact.paintChunks()[2], pendingLayer2)); | 586 artifact, artifact.paintChunks()[2], pendingLayer2)); |
| 587 | 587 |
| 588 update(artifact); | 588 update(artifact); |
| 589 | 589 |
| 590 ASSERT_EQ(3u, contentLayerCount()); | 590 ASSERT_EQ(3u, contentLayerCount()); |
| 591 EXPECT_EQ(layer, contentLayerAt(1)); | 591 EXPECT_EQ(layer, contentLayerAt(1)); |
| 592 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); | 592 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); |
| 593 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); | 593 EXPECT_EQ(translation(50, 60), layer->screen_space_transform()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { | 596 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { |
| 597 RefPtr<EffectPaintPropertyNode> effect1 = | 597 RefPtr<EffectPaintPropertyNode> effect1 = |
| 598 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); | 598 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); |
| 599 RefPtr<EffectPaintPropertyNode> effect2 = | 599 RefPtr<EffectPaintPropertyNode> effect2 = |
| 600 createOpacityOnlyEffect(effect1, 0.3); | 600 createOpacityOnlyEffect(effect1, 0.3); |
| 601 RefPtr<EffectPaintPropertyNode> effect3 = | 601 RefPtr<EffectPaintPropertyNode> effect3 = |
| 602 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.2); | 602 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.2); |
| 603 | 603 |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 rectsWithColor.push_back( | 1274 rectsWithColor.push_back( |
| 1275 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black))); | 1275 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black))); |
| 1276 rectsWithColor.push_back( | 1276 rectsWithColor.push_back( |
| 1277 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); | 1277 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1278 | 1278 |
| 1279 const cc::Layer* layer = contentLayerAt(0); | 1279 const cc::Layer* layer = contentLayerAt(0); |
| 1280 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | 1280 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1281 } | 1281 } |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OverlapTransform) { | |
| 1285 RefPtr<TransformPaintPropertyNode> transform = | |
| 1286 TransformPaintPropertyNode::create( | |
| 1287 TransformPaintPropertyNode::root(), | |
| 1288 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), | |
| 1289 false, 0, CompositingReason3DTransform); | |
| 1290 | |
| 1291 TestPaintArtifact testArtifact; | |
| 1292 testArtifact.chunk(defaultPaintChunkProperties()) | |
| 1293 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 1294 testArtifact | |
| 1295 .chunk(transform.get(), ClipPaintPropertyNode::root(), | |
| 1296 EffectPaintPropertyNode::root()) | |
| 1297 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); | |
| 1298 testArtifact.chunk(defaultPaintChunkProperties()) | |
| 1299 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); | |
| 1300 | |
| 1301 const PaintArtifact& artifact = testArtifact.build(); | |
| 1302 | |
| 1303 ASSERT_EQ(3u, artifact.paintChunks().size()); | |
| 1304 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 1305 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | |
| 1306 artifact, artifact.paintChunks()[1], pendingLayer)); | |
| 1307 | |
| 1308 PaintArtifactCompositor::PendingLayer pendingLayer2( | |
| 1309 artifact.paintChunks()[1]); | |
| 1310 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( | |
| 1311 artifact, artifact.paintChunks()[2], pendingLayer2)); | |
| 1312 | |
| 1313 GeometryMapper geometryMapper; | |
| 1314 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( | |
| 1315 artifact.paintChunks()[2], pendingLayer2, geometryMapper)); | |
| 1316 | |
| 1317 update(artifact); | |
| 1318 | |
| 1319 // The third paint chunk overlaps the second but can't merge due to | |
| 1320 // incompatible transform. The second paint chunk can't merge into the first | |
| 1321 // due to a direct compositing reason. | |
| 1322 ASSERT_EQ(3u, contentLayerCount()); | |
| 1323 } | |
| 1324 | |
| 1325 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MightOverlap) { | |
| 1326 PaintChunk paintChunk; | |
| 1327 paintChunk.properties = defaultPaintChunkProperties(); | |
| 1328 paintChunk.bounds = FloatRect(0, 0, 100, 100); | |
| 1329 | |
| 1330 PaintChunk paintChunk2; | |
| 1331 paintChunk.properties = defaultPaintChunkProperties(); | |
| 1332 paintChunk2.bounds = FloatRect(0, 0, 100, 100); | |
| 1333 | |
| 1334 GeometryMapper geometryMapper; | |
| 1335 PaintArtifactCompositor::PendingLayer pendingLayer(paintChunk); | |
| 1336 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | |
| 1337 geometryMapper)); | |
| 1338 | |
| 1339 RefPtr<TransformPaintPropertyNode> transform = | |
| 1340 TransformPaintPropertyNode::create( | |
| 1341 TransformPaintPropertyNode::root(), | |
| 1342 TransformationMatrix().translate(99, 0), FloatPoint3D(100, 100, 0), | |
| 1343 false); | |
| 1344 | |
| 1345 paintChunk2.properties.propertyTreeState.setTransform(transform.get()); | |
| 1346 | |
| 1347 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | |
| 1348 geometryMapper)); | |
| 1349 | |
| 1350 RefPtr<TransformPaintPropertyNode> transform2 = | |
| 1351 TransformPaintPropertyNode::create( | |
| 1352 TransformPaintPropertyNode::root(), | |
| 1353 TransformationMatrix().translate(100, 0), FloatPoint3D(100, 100, 0), | |
| 1354 false); | |
| 1355 paintChunk2.properties.propertyTreeState.setTransform(transform2.get()); | |
| 1356 | |
| 1357 EXPECT_FALSE(PaintArtifactCompositor::mightOverlap(paintChunk2, pendingLayer, | |
| 1358 geometryMapper)); | |
| 1359 } | |
| 1360 | |
| 1284 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { | 1361 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { |
| 1285 PaintChunk chunk1; | 1362 PaintChunk chunk1; |
| 1286 chunk1.properties.propertyTreeState = PropertyTreeState( | 1363 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1287 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 1364 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1288 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); | 1365 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 1289 chunk1.properties.backfaceHidden = true; | 1366 chunk1.properties.backfaceHidden = true; |
| 1290 chunk1.knownToBeOpaque = true; | 1367 chunk1.knownToBeOpaque = true; |
| 1291 chunk1.bounds = FloatRect(0, 0, 30, 40); | 1368 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1292 | 1369 |
| 1293 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); | 1370 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1341 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; | 1418 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1342 chunk2.properties.propertyTreeState.setTransform(transform); | 1419 chunk2.properties.propertyTreeState.setTransform(transform); |
| 1343 chunk2.bounds = FloatRect(0, 0, 50, 60); | 1420 chunk2.bounds = FloatRect(0, 0, 50, 60); |
| 1344 GeometryMapper geometryMapper; | 1421 GeometryMapper geometryMapper; |
| 1345 pendingLayer.add(chunk2, &geometryMapper); | 1422 pendingLayer.add(chunk2, &geometryMapper); |
| 1346 | 1423 |
| 1347 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); | 1424 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); |
| 1348 } | 1425 } |
| 1349 | 1426 |
| 1350 } // namespace blink | 1427 } // namespace blink |
| OLD | NEW |