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_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 class PaintArtifactCompositorTest : public ::testing::Test { | 35 class PaintArtifactCompositorTest : public ::testing::Test { |
36 protected: | 36 protected: |
37 void SetUp() override | 37 void SetUp() override |
38 { | 38 { |
39 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | 39 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
40 | 40 |
41 // Delay constructing the compositor until after the feature is set. | 41 // Delay constructing the compositor until after the feature is set. |
42 m_paintArtifactCompositor = wrapUnique(new PaintArtifactCompositor); | 42 m_paintArtifactCompositor = wrapUnique(new PaintArtifactCompositor); |
| 43 m_paintArtifactCompositor->enableExtraDataForTesting(); |
43 } | 44 } |
44 | 45 |
45 void TearDown() override | 46 void TearDown() override |
46 { | 47 { |
47 m_featuresBackup.restore(); | 48 m_featuresBackup.restore(); |
48 } | 49 } |
49 | 50 |
50 PaintArtifactCompositor& getPaintArtifactCompositor() { return *m_paintArtif
actCompositor; } | 51 PaintArtifactCompositor& getPaintArtifactCompositor() { return *m_paintArtif
actCompositor; } |
51 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } | 52 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } |
52 void update(const PaintArtifact& artifact) { m_paintArtifactCompositor->upda
te(artifact); } | 53 void update(const PaintArtifact& artifact) { m_paintArtifactCompositor->upda
te(artifact); } |
53 | 54 |
| 55 size_t contentLayerCount() |
| 56 { |
| 57 return m_paintArtifactCompositor->getExtraDataForTesting()->contentLayer
s.size(); |
| 58 } |
| 59 |
| 60 cc::Layer* contentLayerAt(unsigned index) |
| 61 { |
| 62 return m_paintArtifactCompositor->getExtraDataForTesting()->contentLayer
s[index].get(); |
| 63 } |
| 64 |
54 private: | 65 private: |
55 RuntimeEnabledFeatures::Backup m_featuresBackup; | 66 RuntimeEnabledFeatures::Backup m_featuresBackup; |
56 std::unique_ptr<PaintArtifactCompositor> m_paintArtifactCompositor; | 67 std::unique_ptr<PaintArtifactCompositor> m_paintArtifactCompositor; |
57 }; | 68 }; |
58 | 69 |
59 TEST_F(PaintArtifactCompositorTest, EmptyPaintArtifact) | 70 TEST_F(PaintArtifactCompositorTest, EmptyPaintArtifact) |
60 { | 71 { |
61 PaintArtifact emptyArtifact; | 72 PaintArtifact emptyArtifact; |
62 update(emptyArtifact); | 73 update(emptyArtifact); |
63 EXPECT_TRUE(rootLayer()->children().empty()); | 74 EXPECT_TRUE(rootLayer()->children().empty()); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 EXPECT_TRUE(rootLayer()->children().empty()); | 426 EXPECT_TRUE(rootLayer()->children().empty()); |
416 } | 427 } |
417 | 428 |
418 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset) | 429 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset) |
419 { | 430 { |
420 TestPaintArtifact artifact; | 431 TestPaintArtifact artifact; |
421 artifact.chunk(PaintChunkProperties()) | 432 artifact.chunk(PaintChunkProperties()) |
422 .rectDrawing(FloatRect(50, -50, 100, 100), Color::white); | 433 .rectDrawing(FloatRect(50, -50, 100, 100), Color::white); |
423 update(artifact.build()); | 434 update(artifact.build()); |
424 | 435 |
425 ASSERT_EQ(1u, rootLayer()->children().size()); | 436 ASSERT_EQ(1u, contentLayerCount()); |
426 const cc::Layer* child = rootLayer()->child_at(0); | 437 const cc::Layer* child = contentLayerAt(0); |
427 EXPECT_THAT(child->GetPicture(), | 438 EXPECT_THAT(child->GetPicture(), |
428 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 439 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
429 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); | 440 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); |
430 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 441 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
431 } | 442 } |
432 | 443 |
| 444 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) |
| 445 { |
| 446 // A 90 degree clockwise rotation about (100, 100). |
| 447 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( |
| 448 TransformationMatrix().rotate(90), FloatPoint3D(100, 100, 0)); |
| 449 |
| 450 TestPaintArtifact artifact; |
| 451 artifact.chunk(transform, nullptr, nullptr) |
| 452 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 453 artifact.chunk(nullptr, nullptr, nullptr) |
| 454 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 455 artifact.chunk(transform, nullptr, nullptr) |
| 456 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); |
| 457 update(artifact.build()); |
| 458 |
| 459 ASSERT_EQ(3u, contentLayerCount()); |
| 460 { |
| 461 const cc::Layer* layer = contentLayerAt(0); |
| 462 EXPECT_THAT(layer->GetPicture(), |
| 463 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
| 464 gfx::RectF mappedRect(0, 0, 100, 100); |
| 465 layer->screen_space_transform().TransformRect(&mappedRect); |
| 466 EXPECT_EQ(gfx::RectF(100, 0, 100, 100), mappedRect); |
| 467 } |
| 468 { |
| 469 const cc::Layer* layer = contentLayerAt(1); |
| 470 EXPECT_THAT(layer->GetPicture(), |
| 471 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::gray))); |
| 472 EXPECT_EQ(gfx::Transform(), layer->screen_space_transform()); |
| 473 } |
| 474 { |
| 475 const cc::Layer* layer = contentLayerAt(2); |
| 476 EXPECT_THAT(layer->GetPicture(), |
| 477 Pointee(drawsRectangle(FloatRect(0, 0, 200, 100), Color::black))); |
| 478 gfx::RectF mappedRect(0, 0, 200, 100); |
| 479 layer->screen_space_transform().TransformRect(&mappedRect); |
| 480 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); |
| 481 } |
| 482 } |
| 483 |
| 484 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) |
| 485 { |
| 486 // A translation by (5, 5) within a 2x scale about (10, 10). |
| 487 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create( |
| 488 TransformationMatrix().scale(2), FloatPoint3D(10, 10, 0)); |
| 489 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create( |
| 490 TransformationMatrix().translate(5, 5), FloatPoint3D(), transform1); |
| 491 |
| 492 TestPaintArtifact artifact; |
| 493 artifact.chunk(transform1, nullptr, nullptr) |
| 494 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 495 artifact.chunk(transform2, nullptr, nullptr) |
| 496 .rectDrawing(FloatRect(0, 0, 300, 200), Color::black); |
| 497 update(artifact.build()); |
| 498 |
| 499 ASSERT_EQ(2u, contentLayerCount()); |
| 500 { |
| 501 const cc::Layer* layer = contentLayerAt(0); |
| 502 EXPECT_THAT(layer->GetPicture(), |
| 503 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::white))); |
| 504 gfx::RectF mappedRect(0, 0, 300, 200); |
| 505 layer->screen_space_transform().TransformRect(&mappedRect); |
| 506 EXPECT_EQ(gfx::RectF(-10, -10, 600, 400), mappedRect); |
| 507 } |
| 508 { |
| 509 const cc::Layer* layer = contentLayerAt(1); |
| 510 EXPECT_THAT(layer->GetPicture(), |
| 511 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 512 gfx::RectF mappedRect(0, 0, 300, 200); |
| 513 layer->screen_space_transform().TransformRect(&mappedRect); |
| 514 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); |
| 515 } |
| 516 EXPECT_NE( |
| 517 contentLayerAt(0)->transform_tree_index(), |
| 518 contentLayerAt(1)->transform_tree_index()); |
| 519 } |
| 520 |
| 521 |
433 } // namespace | 522 } // namespace |
434 } // namespace blink | 523 } // namespace blink |
OLD | NEW |