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

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

Issue 2124753004: [SPv2] Build simple cc clip trees from Blink clip trees. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clip-tree-refactor
Patch Set: rebase Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_output_surface.h" 10 #include "cc/test/fake_output_surface.h"
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); 511 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black)));
512 gfx::RectF mappedRect(0, 0, 300, 200); 512 gfx::RectF mappedRect(0, 0, 300, 200);
513 layer->screen_space_transform().TransformRect(&mappedRect); 513 layer->screen_space_transform().TransformRect(&mappedRect);
514 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); 514 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect);
515 } 515 }
516 EXPECT_NE( 516 EXPECT_NE(
517 contentLayerAt(0)->transform_tree_index(), 517 contentLayerAt(0)->transform_tree_index(),
518 contentLayerAt(1)->transform_tree_index()); 518 contentLayerAt(1)->transform_tree_index());
519 } 519 }
520 520
521 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneClip)
522 {
523 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
524 nullptr, FloatRoundedRect(100, 100, 300, 200));
525
526 TestPaintArtifact artifact;
527 artifact.chunk(nullptr, clip, nullptr)
528 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black);
529 update(artifact.build());
530
531 ASSERT_EQ(1u, contentLayerCount());
532 const cc::Layer* layer = contentLayerAt(0);
533 EXPECT_THAT(layer->GetPicture(),
534 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black)));
535 EXPECT_EQ(translation(220, 80), layer->screen_space_transform());
536
537 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->data.layers_are_clipped);
540 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->data.clip);
541 }
542
543 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips)
544 {
545 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
546 nullptr, FloatRoundedRect(100, 100, 700, 700));
547 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create(
548 nullptr, FloatRoundedRect(200, 200, 700, 100), clip1);
549
550 TestPaintArtifact artifact;
551 artifact.chunk(nullptr, clip1, nullptr)
552 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white);
553 artifact.chunk(nullptr, clip2, nullptr)
554 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray);
555 artifact.chunk(nullptr, clip1, nullptr)
556 .rectDrawing(FloatRect(300, 350, 100, 100), Color::darkGray);
557 artifact.chunk(nullptr, clip2, nullptr)
558 .rectDrawing(FloatRect(300, 350, 100, 100), Color::black);
559 update(artifact.build());
560
561 ASSERT_EQ(4u, contentLayerCount());
562
563 const cc::Layer* whiteLayer = contentLayerAt(0);
564 EXPECT_THAT(whiteLayer->GetPicture(),
565 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white)));
566 EXPECT_EQ(translation(300, 350), whiteLayer->screen_space_transform());
567
568 const cc::Layer* lightGrayLayer = contentLayerAt(1);
569 EXPECT_THAT(lightGrayLayer->GetPicture(),
570 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::lightGray)));
571 EXPECT_EQ(translation(300, 350), lightGrayLayer->screen_space_transform());
572
573 const cc::Layer* darkGrayLayer = contentLayerAt(2);
574 EXPECT_THAT(darkGrayLayer->GetPicture(),
575 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::darkGray)));
576 EXPECT_EQ(translation(300, 350), darkGrayLayer->screen_space_transform());
577
578 const cc::Layer* blackLayer = contentLayerAt(3);
579 EXPECT_THAT(blackLayer->GetPicture(),
580 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black)));
581 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform());
582
583 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 EXPECT_TRUE(outerClip->data.applies_local_clip);
586 EXPECT_TRUE(outerClip->data.layers_are_clipped);
587 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->data.clip);
588
589 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 EXPECT_TRUE(innerClip->data.applies_local_clip);
592 EXPECT_TRUE(innerClip->data.layers_are_clipped);
593 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->data.clip);
594 EXPECT_EQ(outerClip->id, innerClip->parent_id);
595 }
596
597 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips)
598 {
599 Vector<RefPtr<ClipPaintPropertyNode>> clips;
600 for (unsigned i = 1; i <= 10; i++) {
601 clips.append(ClipPaintPropertyNode::create(
602 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i),
603 clips.isEmpty() ? nullptr : clips.last()));
604 }
605
606 TestPaintArtifact artifact;
607 artifact.chunk(nullptr, clips.last(), nullptr)
608 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white);
609 update(artifact.build());
610
611 // Check the drawing layer.
612 ASSERT_EQ(1u, contentLayerCount());
613 const cc::Layer* drawingLayer = contentLayerAt(0);
614 EXPECT_THAT(drawingLayer->GetPicture(),
615 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white)));
616 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform());
617
618 // Check the clip nodes.
619 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(drawingLayer-> clip_tree_index());
620 for (auto it = clips.rbegin(); it != clips.rend(); ++it) {
621 const ClipPaintPropertyNode* paintClipNode = it->get();
622 EXPECT_TRUE(clipNode->data.applies_local_clip);
623 EXPECT_TRUE(clipNode->data.layers_are_clipped);
624 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->data.clip);
625 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id);
626 }
627 }
628
629 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips)
630 {
631 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create(
632 nullptr, FloatRoundedRect(0, 0, 800, 600));
633 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
634 nullptr, FloatRoundedRect(0, 0, 400, 600), commonClip);
635 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create(
636 nullptr, FloatRoundedRect(400, 0, 400, 600), commonClip);
637
638 TestPaintArtifact artifact;
639 artifact.chunk(nullptr, clip1, nullptr)
640 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white);
641 artifact.chunk(nullptr, clip2, nullptr)
642 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black);
643 update(artifact.build());
644
645 ASSERT_EQ(2u, contentLayerCount());
646
647 const cc::Layer* whiteLayer = contentLayerAt(0);
648 EXPECT_THAT(whiteLayer->GetPicture(),
649 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white)));
650 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform());
651 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->data.layers_are_clipped);
654 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->data.clip);
655
656 const cc::Layer* blackLayer = contentLayerAt(1);
657 EXPECT_THAT(blackLayer->GetPicture(),
658 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black)));
659 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform());
660 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->data.layers_are_clipped);
663 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->data.clip);
664
665 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id);
666 const cc::ClipNode* commonClipNode = propertyTrees().clip_tree.Node(whiteCli p->parent_id);
667 EXPECT_TRUE(commonClipNode->data.applies_local_clip);
668 EXPECT_TRUE(commonClipNode->data.layers_are_clipped);
669 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->data.clip);
670 }
671
521 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ForeignLayerPassesThrough) 672 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ForeignLayerPassesThrough)
522 { 673 {
523 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); 674 scoped_refptr<cc::Layer> layer = cc::Layer::Create();
524 675
525 TestPaintArtifact artifact; 676 TestPaintArtifact artifact;
526 artifact.chunk(PaintChunkProperties()) 677 artifact.chunk(PaintChunkProperties())
527 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); 678 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer);
528 update(artifact.build()); 679 update(artifact.build());
529 680
530 ASSERT_EQ(1u, contentLayerCount()); 681 ASSERT_EQ(1u, contentLayerCount());
531 EXPECT_EQ(layer, contentLayerAt(0)); 682 EXPECT_EQ(layer, contentLayerAt(0));
532 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); 683 EXPECT_EQ(gfx::Size(400, 300), layer->bounds());
533 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); 684 EXPECT_EQ(translation(50, 100), layer->screen_space_transform());
534 } 685 }
535 686
536 } // namespace 687 } // namespace
537 } // namespace blink 688 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698