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

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

Issue 2604093002: Add unittests for the bugs found in previous CL. (Closed)
Patch Set: none Created 3 years, 11 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 "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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 rectsWithColor.push_back( 867 rectsWithColor.push_back(
868 RectWithColor(FloatRect(50, 50, 100, 100), Color::black)); 868 RectWithColor(FloatRect(50, 50, 100, 100), Color::black));
869 rectsWithColor.push_back( 869 rectsWithColor.push_back(
870 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); 870 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray));
871 871
872 const cc::Layer* layer = contentLayerAt(0); 872 const cc::Layer* layer = contentLayerAt(0);
873 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); 873 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor)));
874 } 874 }
875 } 875 }
876 876
877 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeTransformOrigin) {
878 RefPtr<TransformPaintPropertyNode> transform =
879 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
880 TransformationMatrix().rotate(45),
881 FloatPoint3D(100, 100, 0), false, 0);
882
883 TestPaintArtifact testArtifact;
884 testArtifact
885 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
886 EffectPaintPropertyNode::root())
887 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white);
888 testArtifact
889 .chunk(transform.get(), ClipPaintPropertyNode::root(),
890 EffectPaintPropertyNode::root())
891 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black);
892 testArtifact
893 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
894 EffectPaintPropertyNode::root())
895 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray);
896
897 const PaintArtifact& artifact = testArtifact.build();
898
899 ASSERT_EQ(3u, artifact.paintChunks().size());
900 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]);
901 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
902 artifact, artifact.paintChunks()[1], pendingLayer));
903 pendingLayer.add(artifact.paintChunks()[1], nullptr);
904 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
905 artifact, artifact.paintChunks()[2], pendingLayer));
906 update(artifact);
907
908 ASSERT_EQ(1u, contentLayerCount());
909 {
910 Vector<RectWithColor> rectsWithColor;
911 rectsWithColor.push_back(
912 RectWithColor(FloatRect(0, 42, 100, 100), Color::white));
913 // Transform is applied to this PaintChunk.
914 rectsWithColor.push_back(RectWithColor(
915 FloatRect(29.2893, 0.578644, 141.421, 141.421), Color::black));
916 rectsWithColor.push_back(
917 RectWithColor(FloatRect(00, 42, 200, 300), Color::gray));
918
919 const cc::Layer* layer = contentLayerAt(0);
920 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor)));
921 }
922 }
923
877 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) { 924 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) {
878 float opacity = 2.0 / 255.0; 925 float opacity = 2.0 / 255.0;
879 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( 926 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create(
880 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 927 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
881 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, 928 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity,
882 SkBlendMode::kSrcOver); 929 SkBlendMode::kSrcOver);
883 930
884 TestPaintArtifact testArtifact; 931 TestPaintArtifact testArtifact;
885 testArtifact 932 testArtifact
886 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), 933 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 rectsWithColor.push_back( 1321 rectsWithColor.push_back(
1275 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black))); 1322 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black)));
1276 rectsWithColor.push_back( 1323 rectsWithColor.push_back(
1277 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); 1324 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray));
1278 1325
1279 const cc::Layer* layer = contentLayerAt(0); 1326 const cc::Layer* layer = contentLayerAt(0);
1280 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); 1327 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor)));
1281 } 1328 }
1282 } 1329 }
1283 1330
1331 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TwoTransformsClipBetween) {
1332 RefPtr<TransformPaintPropertyNode> transform =
1333 TransformPaintPropertyNode::create(
1334 TransformPaintPropertyNode::root(),
1335 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0),
1336 false, 0);
1337 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
1338 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
1339 FloatRoundedRect(0, 0, 50, 60));
1340 RefPtr<TransformPaintPropertyNode> transform2 =
1341 TransformPaintPropertyNode::create(
1342 transform.get(), TransformationMatrix().translate(20, 25),
1343 FloatPoint3D(100, 100, 0), false, 0);
1344 TestPaintArtifact testArtifact;
1345 testArtifact
1346 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1347 EffectPaintPropertyNode::root())
1348 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white);
1349 testArtifact
1350 .chunk(transform2.get(), clip.get(), EffectPaintPropertyNode::root())
1351 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black);
1352 testArtifact
1353 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1354 EffectPaintPropertyNode::root())
1355 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray);
1356 const PaintArtifact& artifact = testArtifact.build();
1357 ASSERT_EQ(3u, artifact.paintChunks().size());
1358 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]);
1359 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
1360 artifact, artifact.paintChunks()[1], pendingLayer));
1361 pendingLayer.add(artifact.paintChunks()[1], nullptr);
1362 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
1363 artifact, artifact.paintChunks()[2], pendingLayer));
1364 update(artifact);
1365 ASSERT_EQ(1u, contentLayerCount());
1366 {
1367 Vector<RectWithColor> rectsWithColor;
1368 rectsWithColor.push_back(
1369 RectWithColor(FloatRect(0, 0, 100, 100), Color::white));
1370 rectsWithColor.push_back(
1371 RectWithColor(FloatRect(40, 50, 50, 60), Color(Color::black)));
1372 rectsWithColor.push_back(
1373 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray));
1374 const cc::Layer* layer = contentLayerAt(0);
1375 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor)));
1376 }
1377 }
1378
1284 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OverlapTransform) { 1379 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OverlapTransform) {
1285 RefPtr<TransformPaintPropertyNode> transform = 1380 RefPtr<TransformPaintPropertyNode> transform =
1286 TransformPaintPropertyNode::create( 1381 TransformPaintPropertyNode::create(
1287 TransformPaintPropertyNode::root(), 1382 TransformPaintPropertyNode::root(),
1288 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), 1383 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0),
1289 false, 0, CompositingReason3DTransform); 1384 false, 0, CompositingReason3DTransform);
1290 1385
1291 TestPaintArtifact testArtifact; 1386 TestPaintArtifact testArtifact;
1292 testArtifact.chunk(defaultPaintChunkProperties()) 1387 testArtifact.chunk(defaultPaintChunkProperties())
1293 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); 1388 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white);
1294 testArtifact 1389 testArtifact
1295 .chunk(transform.get(), ClipPaintPropertyNode::root(), 1390 .chunk(transform.get(), ClipPaintPropertyNode::root(),
1296 EffectPaintPropertyNode::root()) 1391 EffectPaintPropertyNode::root())
1297 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); 1392 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black);
1298 testArtifact.chunk(defaultPaintChunkProperties()) 1393 testArtifact.chunk(defaultPaintChunkProperties())
1299 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); 1394 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray);
1300 1395
1301 const PaintArtifact& artifact = testArtifact.build(); 1396 const PaintArtifact& artifact = testArtifact.build();
1302 1397
1303 ASSERT_EQ(3u, artifact.paintChunks().size()); 1398 ASSERT_EQ(3u, artifact.paintChunks().size());
1304 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); 1399 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]);
1400
1305 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( 1401 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto(
1306 artifact, artifact.paintChunks()[1], pendingLayer)); 1402 artifact, artifact.paintChunks()[1], pendingLayer));
1307 1403
1308 PaintArtifactCompositor::PendingLayer pendingLayer2( 1404 PaintArtifactCompositor::PendingLayer pendingLayer2(
1309 artifact.paintChunks()[1]); 1405 artifact.paintChunks()[1]);
1310 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( 1406 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto(
1311 artifact, artifact.paintChunks()[2], pendingLayer2)); 1407 artifact, artifact.paintChunks()[2], pendingLayer2));
1312 1408
1313 GeometryMapper geometryMapper; 1409 GeometryMapper geometryMapper;
1314 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap( 1410 EXPECT_TRUE(PaintArtifactCompositor::mightOverlap(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 PaintChunk chunk2; 1512 PaintChunk chunk2;
1417 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1513 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1418 chunk2.properties.propertyTreeState.setTransform(transform); 1514 chunk2.properties.propertyTreeState.setTransform(transform);
1419 chunk2.bounds = FloatRect(0, 0, 50, 60); 1515 chunk2.bounds = FloatRect(0, 0, 50, 60);
1420 GeometryMapper geometryMapper; 1516 GeometryMapper geometryMapper;
1421 pendingLayer.add(chunk2, &geometryMapper); 1517 pendingLayer.add(chunk2, &geometryMapper);
1422 1518
1423 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); 1519 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds);
1424 } 1520 }
1425 1521
1522 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerKnownOpaque) {
1523 PaintChunk chunk1;
1524 chunk1.properties.propertyTreeState = PropertyTreeState(
1525 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1526 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root());
1527 chunk1.bounds = FloatRect(0, 0, 30, 40);
1528 chunk1.knownToBeOpaque = false;
1529 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1);
1530
1531 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1532
1533 PaintChunk chunk2;
1534 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1535 chunk2.bounds = FloatRect(0, 0, 25, 35);
1536 chunk2.knownToBeOpaque = true;
1537 pendingLayer.add(chunk2, nullptr);
1538
1539 // Chunk 2 doesn't cover the entire layer, so not opaque.
1540 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1541
1542 PaintChunk chunk3;
1543 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1544 chunk3.bounds = FloatRect(0, 0, 50, 60);
1545 chunk3.knownToBeOpaque = true;
1546 pendingLayer.add(chunk3, nullptr);
1547
1548 // Chunk 3 covers the entire layer, so now it's opaque.
1549 EXPECT_TRUE(pendingLayer.knownToBeOpaque);
1550 }
1551
1426 } // namespace blink 1552 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698