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

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 // Tests merging of an element which has two clips in the root
wkorman 2016/12/29 21:56:18 Is this comment accurate? The method name and code
chrishtr 2016/12/29 22:12:49 Removed.
1333 // transform space.
1334
1335 RefPtr<TransformPaintPropertyNode> transform =
1336 TransformPaintPropertyNode::create(
1337 TransformPaintPropertyNode::root(),
1338 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0),
1339 false, 0);
1340
1341 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
1342 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
1343 FloatRoundedRect(0, 0, 50, 60));
1344
1345 RefPtr<TransformPaintPropertyNode> transform2 =
1346 TransformPaintPropertyNode::create(
1347 transform.get(), TransformationMatrix().translate(20, 25),
1348 FloatPoint3D(100, 100, 0), false, 0);
1349
1350 TestPaintArtifact testArtifact;
1351 testArtifact
1352 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1353 EffectPaintPropertyNode::root())
1354 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white);
1355 testArtifact
1356 .chunk(transform2.get(), clip.get(), EffectPaintPropertyNode::root())
1357 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black);
1358 testArtifact
1359 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1360 EffectPaintPropertyNode::root())
1361 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray);
1362
1363 const PaintArtifact& artifact = testArtifact.build();
1364
1365 ASSERT_EQ(3u, artifact.paintChunks().size());
1366 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]);
1367 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
1368 artifact, artifact.paintChunks()[1], pendingLayer));
1369 pendingLayer.add(artifact.paintChunks()[1], nullptr);
1370 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(
1371 artifact, artifact.paintChunks()[2], pendingLayer));
1372 update(artifact);
1373
1374 ASSERT_EQ(1u, contentLayerCount());
1375 {
1376 Vector<RectWithColor> rectsWithColor;
1377 rectsWithColor.push_back(
1378 RectWithColor(FloatRect(0, 0, 100, 100), Color::white));
1379 rectsWithColor.push_back(
1380 RectWithColor(FloatRect(40, 50, 50, 60), Color(Color::black)));
1381 rectsWithColor.push_back(
1382 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray));
1383
1384 const cc::Layer* layer = contentLayerAt(0);
1385 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor)));
1386 }
1387 }
1388
1284 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { 1389 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) {
1285 PaintChunk chunk1; 1390 PaintChunk chunk1;
1286 chunk1.properties.propertyTreeState = PropertyTreeState( 1391 chunk1.properties.propertyTreeState = PropertyTreeState(
1287 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), 1392 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1288 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); 1393 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root());
1289 chunk1.properties.backfaceHidden = true; 1394 chunk1.properties.backfaceHidden = true;
1290 chunk1.knownToBeOpaque = true; 1395 chunk1.knownToBeOpaque = true;
1291 chunk1.bounds = FloatRect(0, 0, 30, 40); 1396 chunk1.bounds = FloatRect(0, 0, 30, 40);
1292 1397
1293 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); 1398 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 PaintChunk chunk2; 1445 PaintChunk chunk2;
1341 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; 1446 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1342 chunk2.properties.propertyTreeState.setTransform(transform); 1447 chunk2.properties.propertyTreeState.setTransform(transform);
1343 chunk2.bounds = FloatRect(0, 0, 50, 60); 1448 chunk2.bounds = FloatRect(0, 0, 50, 60);
1344 GeometryMapper geometryMapper; 1449 GeometryMapper geometryMapper;
1345 pendingLayer.add(chunk2, &geometryMapper); 1450 pendingLayer.add(chunk2, &geometryMapper);
1346 1451
1347 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); 1452 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds);
1348 } 1453 }
1349 1454
1455 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerKnownOpaque) {
1456 PaintChunk chunk1;
1457 chunk1.properties.propertyTreeState = PropertyTreeState(
1458 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
1459 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root());
1460 chunk1.bounds = FloatRect(0, 0, 30, 40);
1461 chunk1.knownToBeOpaque = false;
1462 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1);
1463
1464 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1465
1466 PaintChunk chunk2;
1467 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1468 chunk2.bounds = FloatRect(0, 0, 25, 35);
1469 chunk2.knownToBeOpaque = true;
1470 pendingLayer.add(chunk2, nullptr);
1471
1472 // Chunk 2 doesn't cover the entire layer, so not opaque.
1473 EXPECT_FALSE(pendingLayer.knownToBeOpaque);
1474
1475 PaintChunk chunk3;
1476 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState;
1477 chunk3.bounds = FloatRect(0, 0, 50, 60);
1478 chunk3.knownToBeOpaque = true;
1479 pendingLayer.add(chunk3, nullptr);
1480
1481 // Chunk 3 covers the entire layer, so now it's opaque.
1482 EXPECT_TRUE(pendingLayer.knownToBeOpaque);
1483 }
1484
1350 } // namespace blink 1485 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698