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" |
| 11 #include "cc/trees/clip_node.h" |
11 #include "cc/trees/layer_tree_host.h" | 12 #include "cc/trees/layer_tree_host.h" |
12 #include "cc/trees/layer_tree_settings.h" | 13 #include "cc/trees/layer_tree_settings.h" |
13 #include "platform/RuntimeEnabledFeatures.h" | 14 #include "platform/RuntimeEnabledFeatures.h" |
14 #include "platform/graphics/paint/PaintArtifact.h" | 15 #include "platform/graphics/paint/PaintArtifact.h" |
15 #include "platform/testing/PictureMatchers.h" | 16 #include "platform/testing/PictureMatchers.h" |
16 #include "platform/testing/TestPaintArtifact.h" | 17 #include "platform/testing/TestPaintArtifact.h" |
17 #include "platform/testing/WebLayerTreeViewImplForTesting.h" | 18 #include "platform/testing/WebLayerTreeViewImplForTesting.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "wtf/PtrUtil.h" | 21 #include "wtf/PtrUtil.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); | 529 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); |
529 update(artifact.build()); | 530 update(artifact.build()); |
530 | 531 |
531 ASSERT_EQ(1u, contentLayerCount()); | 532 ASSERT_EQ(1u, contentLayerCount()); |
532 const cc::Layer* layer = contentLayerAt(0); | 533 const cc::Layer* layer = contentLayerAt(0); |
533 EXPECT_THAT(layer->GetPicture(), | 534 EXPECT_THAT(layer->GetPicture(), |
534 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 535 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
535 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); | 536 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); |
536 | 537 |
537 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(layer->clip_tr
ee_index()); | 538 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(layer->clip_tr
ee_index()); |
538 EXPECT_TRUE(clipNode->data.applies_local_clip); | 539 EXPECT_TRUE(clipNode->applies_local_clip); |
539 EXPECT_TRUE(clipNode->data.layers_are_clipped); | 540 EXPECT_TRUE(clipNode->layers_are_clipped); |
540 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->data.clip); | 541 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
541 } | 542 } |
542 | 543 |
543 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) | 544 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) |
544 { | 545 { |
545 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 546 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
546 nullptr, FloatRoundedRect(100, 100, 700, 700)); | 547 nullptr, FloatRoundedRect(100, 100, 700, 700)); |
547 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 548 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
548 nullptr, FloatRoundedRect(200, 200, 700, 100), clip1); | 549 nullptr, FloatRoundedRect(200, 200, 700, 100), clip1); |
549 | 550 |
550 TestPaintArtifact artifact; | 551 TestPaintArtifact artifact; |
(...skipping 24 matching lines...) Expand all Loading... |
575 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::darkGray))); | 576 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::darkGray))); |
576 EXPECT_EQ(translation(300, 350), darkGrayLayer->screen_space_transform()); | 577 EXPECT_EQ(translation(300, 350), darkGrayLayer->screen_space_transform()); |
577 | 578 |
578 const cc::Layer* blackLayer = contentLayerAt(3); | 579 const cc::Layer* blackLayer = contentLayerAt(3); |
579 EXPECT_THAT(blackLayer->GetPicture(), | 580 EXPECT_THAT(blackLayer->GetPicture(), |
580 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); | 581 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); |
581 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); | 582 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); |
582 | 583 |
583 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); | 584 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); |
584 const cc::ClipNode* outerClip = propertyTrees().clip_tree.Node(whiteLayer->c
lip_tree_index()); | 585 const cc::ClipNode* outerClip = propertyTrees().clip_tree.Node(whiteLayer->c
lip_tree_index()); |
585 EXPECT_TRUE(outerClip->data.applies_local_clip); | 586 EXPECT_TRUE(outerClip->applies_local_clip); |
586 EXPECT_TRUE(outerClip->data.layers_are_clipped); | 587 EXPECT_TRUE(outerClip->layers_are_clipped); |
587 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->data.clip); | 588 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->clip); |
588 | 589 |
589 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); | 590 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); |
590 const cc::ClipNode* innerClip = propertyTrees().clip_tree.Node(blackLayer->c
lip_tree_index()); | 591 const cc::ClipNode* innerClip = propertyTrees().clip_tree.Node(blackLayer->c
lip_tree_index()); |
591 EXPECT_TRUE(innerClip->data.applies_local_clip); | 592 EXPECT_TRUE(innerClip->applies_local_clip); |
592 EXPECT_TRUE(innerClip->data.layers_are_clipped); | 593 EXPECT_TRUE(innerClip->layers_are_clipped); |
593 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->data.clip); | 594 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->clip); |
594 EXPECT_EQ(outerClip->id, innerClip->parent_id); | 595 EXPECT_EQ(outerClip->id, innerClip->parent_id); |
595 } | 596 } |
596 | 597 |
597 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) | 598 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) |
598 { | 599 { |
599 Vector<RefPtr<ClipPaintPropertyNode>> clips; | 600 Vector<RefPtr<ClipPaintPropertyNode>> clips; |
600 for (unsigned i = 1; i <= 10; i++) { | 601 for (unsigned i = 1; i <= 10; i++) { |
601 clips.append(ClipPaintPropertyNode::create( | 602 clips.append(ClipPaintPropertyNode::create( |
602 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i), | 603 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i), |
603 clips.isEmpty() ? nullptr : clips.last())); | 604 clips.isEmpty() ? nullptr : clips.last())); |
604 } | 605 } |
605 | 606 |
606 TestPaintArtifact artifact; | 607 TestPaintArtifact artifact; |
607 artifact.chunk(nullptr, clips.last(), nullptr) | 608 artifact.chunk(nullptr, clips.last(), nullptr) |
608 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); | 609 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); |
609 update(artifact.build()); | 610 update(artifact.build()); |
610 | 611 |
611 // Check the drawing layer. | 612 // Check the drawing layer. |
612 ASSERT_EQ(1u, contentLayerCount()); | 613 ASSERT_EQ(1u, contentLayerCount()); |
613 const cc::Layer* drawingLayer = contentLayerAt(0); | 614 const cc::Layer* drawingLayer = contentLayerAt(0); |
614 EXPECT_THAT(drawingLayer->GetPicture(), | 615 EXPECT_THAT(drawingLayer->GetPicture(), |
615 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); | 616 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); |
616 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); | 617 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); |
617 | 618 |
618 // Check the clip nodes. | 619 // Check the clip nodes. |
619 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(drawingLayer->
clip_tree_index()); | 620 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(drawingLayer->
clip_tree_index()); |
620 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { | 621 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { |
621 const ClipPaintPropertyNode* paintClipNode = it->get(); | 622 const ClipPaintPropertyNode* paintClipNode = it->get(); |
622 EXPECT_TRUE(clipNode->data.applies_local_clip); | 623 EXPECT_TRUE(clipNode->applies_local_clip); |
623 EXPECT_TRUE(clipNode->data.layers_are_clipped); | 624 EXPECT_TRUE(clipNode->layers_are_clipped); |
624 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->data.clip); | 625 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); |
625 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); | 626 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); |
626 } | 627 } |
627 } | 628 } |
628 | 629 |
629 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) | 630 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) |
630 { | 631 { |
631 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( | 632 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( |
632 nullptr, FloatRoundedRect(0, 0, 800, 600)); | 633 nullptr, FloatRoundedRect(0, 0, 800, 600)); |
633 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 634 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
634 nullptr, FloatRoundedRect(0, 0, 400, 600), commonClip); | 635 nullptr, FloatRoundedRect(0, 0, 400, 600), commonClip); |
635 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 636 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
636 nullptr, FloatRoundedRect(400, 0, 400, 600), commonClip); | 637 nullptr, FloatRoundedRect(400, 0, 400, 600), commonClip); |
637 | 638 |
638 TestPaintArtifact artifact; | 639 TestPaintArtifact artifact; |
639 artifact.chunk(nullptr, clip1, nullptr) | 640 artifact.chunk(nullptr, clip1, nullptr) |
640 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); | 641 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); |
641 artifact.chunk(nullptr, clip2, nullptr) | 642 artifact.chunk(nullptr, clip2, nullptr) |
642 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); | 643 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); |
643 update(artifact.build()); | 644 update(artifact.build()); |
644 | 645 |
645 ASSERT_EQ(2u, contentLayerCount()); | 646 ASSERT_EQ(2u, contentLayerCount()); |
646 | 647 |
647 const cc::Layer* whiteLayer = contentLayerAt(0); | 648 const cc::Layer* whiteLayer = contentLayerAt(0); |
648 EXPECT_THAT(whiteLayer->GetPicture(), | 649 EXPECT_THAT(whiteLayer->GetPicture(), |
649 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); | 650 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); |
650 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); | 651 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); |
651 const cc::ClipNode* whiteClip = propertyTrees().clip_tree.Node(whiteLayer->c
lip_tree_index()); | 652 const cc::ClipNode* whiteClip = propertyTrees().clip_tree.Node(whiteLayer->c
lip_tree_index()); |
652 EXPECT_TRUE(whiteClip->data.applies_local_clip); | 653 EXPECT_TRUE(whiteClip->applies_local_clip); |
653 EXPECT_TRUE(whiteClip->data.layers_are_clipped); | 654 EXPECT_TRUE(whiteClip->layers_are_clipped); |
654 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->data.clip); | 655 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->clip); |
655 | 656 |
656 const cc::Layer* blackLayer = contentLayerAt(1); | 657 const cc::Layer* blackLayer = contentLayerAt(1); |
657 EXPECT_THAT(blackLayer->GetPicture(), | 658 EXPECT_THAT(blackLayer->GetPicture(), |
658 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); | 659 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); |
659 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); | 660 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); |
660 const cc::ClipNode* blackClip = propertyTrees().clip_tree.Node(blackLayer->c
lip_tree_index()); | 661 const cc::ClipNode* blackClip = propertyTrees().clip_tree.Node(blackLayer->c
lip_tree_index()); |
661 EXPECT_TRUE(blackClip->data.applies_local_clip); | 662 EXPECT_TRUE(blackClip->applies_local_clip); |
662 EXPECT_TRUE(blackClip->data.layers_are_clipped); | 663 EXPECT_TRUE(blackClip->layers_are_clipped); |
663 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->data.clip); | 664 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->clip); |
664 | 665 |
665 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); | 666 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); |
666 const cc::ClipNode* commonClipNode = propertyTrees().clip_tree.Node(whiteCli
p->parent_id); | 667 const cc::ClipNode* commonClipNode = propertyTrees().clip_tree.Node(whiteCli
p->parent_id); |
667 EXPECT_TRUE(commonClipNode->data.applies_local_clip); | 668 EXPECT_TRUE(commonClipNode->applies_local_clip); |
668 EXPECT_TRUE(commonClipNode->data.layers_are_clipped); | 669 EXPECT_TRUE(commonClipNode->layers_are_clipped); |
669 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->data.clip); | 670 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); |
670 } | 671 } |
671 | 672 |
672 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ForeignLayerPassesThrough) | 673 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ForeignLayerPassesThrough) |
673 { | 674 { |
674 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); | 675 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); |
675 | 676 |
676 TestPaintArtifact artifact; | 677 TestPaintArtifact artifact; |
677 artifact.chunk(PaintChunkProperties()) | 678 artifact.chunk(PaintChunkProperties()) |
678 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); | 679 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); |
679 update(artifact.build()); | 680 update(artifact.build()); |
680 | 681 |
681 ASSERT_EQ(1u, contentLayerCount()); | 682 ASSERT_EQ(1u, contentLayerCount()); |
682 EXPECT_EQ(layer, contentLayerAt(0)); | 683 EXPECT_EQ(layer, contentLayerAt(0)); |
683 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); | 684 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); |
684 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); | 685 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); |
685 } | 686 } |
686 | 687 |
687 } // namespace | 688 } // namespace |
688 } // namespace blink | 689 } // namespace blink |
OLD | NEW |