| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 ASSERT_EQ(1u, contentLayerCount()); | 412 ASSERT_EQ(1u, contentLayerCount()); |
| 413 const cc::Layer* layer = contentLayerAt(0); | 413 const cc::Layer* layer = contentLayerAt(0); |
| 414 EXPECT_THAT(layer->GetPicture(), | 414 EXPECT_THAT(layer->GetPicture(), |
| 415 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 415 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 416 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); | 416 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); |
| 417 | 417 |
| 418 const cc::ClipNode* clipNode = | 418 const cc::ClipNode* clipNode = |
| 419 propertyTrees().clip_tree.Node(layer->clip_tree_index()); | 419 propertyTrees().clip_tree.Node(layer->clip_tree_index()); |
| 420 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); | 420 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 421 EXPECT_TRUE(clipNode->layers_are_clipped); | |
| 422 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); | 421 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
| 423 } | 422 } |
| 424 | 423 |
| 425 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { | 424 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { |
| 426 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 425 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 427 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | 426 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 428 FloatRoundedRect(100, 100, 700, 700), | 427 FloatRoundedRect(100, 100, 700, 700), |
| 429 CompositingReasonOverflowScrollingTouch); | 428 CompositingReasonOverflowScrollingTouch); |
| 430 RefPtr<ClipPaintPropertyNode> clip2 = | 429 RefPtr<ClipPaintPropertyNode> clip2 = |
| 431 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), | 430 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 471 |
| 473 const cc::Layer* blackLayer = contentLayerAt(3); | 472 const cc::Layer* blackLayer = contentLayerAt(3); |
| 474 EXPECT_THAT(blackLayer->GetPicture(), | 473 EXPECT_THAT(blackLayer->GetPicture(), |
| 475 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); | 474 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); |
| 476 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); | 475 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); |
| 477 | 476 |
| 478 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); | 477 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); |
| 479 const cc::ClipNode* outerClip = | 478 const cc::ClipNode* outerClip = |
| 480 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); | 479 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); |
| 481 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, outerClip->clip_type); | 480 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, outerClip->clip_type); |
| 482 EXPECT_TRUE(outerClip->layers_are_clipped); | |
| 483 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->clip); | 481 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->clip); |
| 484 | 482 |
| 485 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); | 483 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); |
| 486 const cc::ClipNode* innerClip = | 484 const cc::ClipNode* innerClip = |
| 487 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); | 485 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); |
| 488 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, innerClip->clip_type); | 486 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, innerClip->clip_type); |
| 489 EXPECT_TRUE(innerClip->layers_are_clipped); | |
| 490 EXPECT_EQ(gfx::RectF(200, 200, 700, 700), innerClip->clip); | 487 EXPECT_EQ(gfx::RectF(200, 200, 700, 700), innerClip->clip); |
| 491 EXPECT_EQ(outerClip->id, innerClip->parent_id); | 488 EXPECT_EQ(outerClip->id, innerClip->parent_id); |
| 492 } | 489 } |
| 493 | 490 |
| 494 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) { | 491 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) { |
| 495 Vector<RefPtr<ClipPaintPropertyNode>> clips; | 492 Vector<RefPtr<ClipPaintPropertyNode>> clips; |
| 496 for (unsigned i = 1; i <= 10; i++) { | 493 for (unsigned i = 1; i <= 10; i++) { |
| 497 clips.push_back(ClipPaintPropertyNode::create( | 494 clips.push_back(ClipPaintPropertyNode::create( |
| 498 clips.isEmpty() ? ClipPaintPropertyNode::root() : clips.back(), | 495 clips.isEmpty() ? ClipPaintPropertyNode::root() : clips.back(), |
| 499 TransformPaintPropertyNode::root(), | 496 TransformPaintPropertyNode::root(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 513 EXPECT_THAT(drawingLayer->GetPicture(), | 510 EXPECT_THAT(drawingLayer->GetPicture(), |
| 514 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); | 511 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); |
| 515 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); | 512 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); |
| 516 | 513 |
| 517 // Check the clip nodes. | 514 // Check the clip nodes. |
| 518 const cc::ClipNode* clipNode = | 515 const cc::ClipNode* clipNode = |
| 519 propertyTrees().clip_tree.Node(drawingLayer->clip_tree_index()); | 516 propertyTrees().clip_tree.Node(drawingLayer->clip_tree_index()); |
| 520 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { | 517 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { |
| 521 const ClipPaintPropertyNode* paintClipNode = it->get(); | 518 const ClipPaintPropertyNode* paintClipNode = it->get(); |
| 522 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); | 519 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 523 EXPECT_TRUE(clipNode->layers_are_clipped); | |
| 524 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); | 520 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); |
| 525 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); | 521 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); |
| 526 } | 522 } |
| 527 } | 523 } |
| 528 | 524 |
| 529 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) { | 525 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) { |
| 530 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( | 526 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( |
| 531 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | 527 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 532 FloatRoundedRect(0, 0, 800, 600)); | 528 FloatRoundedRect(0, 0, 800, 600)); |
| 533 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 529 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 549 update(artifact.build()); | 545 update(artifact.build()); |
| 550 ASSERT_EQ(2u, contentLayerCount()); | 546 ASSERT_EQ(2u, contentLayerCount()); |
| 551 | 547 |
| 552 const cc::Layer* whiteLayer = contentLayerAt(0); | 548 const cc::Layer* whiteLayer = contentLayerAt(0); |
| 553 EXPECT_THAT(whiteLayer->GetPicture(), | 549 EXPECT_THAT(whiteLayer->GetPicture(), |
| 554 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); | 550 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); |
| 555 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); | 551 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); |
| 556 const cc::ClipNode* whiteClip = | 552 const cc::ClipNode* whiteClip = |
| 557 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); | 553 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); |
| 558 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, whiteClip->clip_type); | 554 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, whiteClip->clip_type); |
| 559 EXPECT_TRUE(whiteClip->layers_are_clipped); | |
| 560 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->clip); | 555 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->clip); |
| 561 | 556 |
| 562 const cc::Layer* blackLayer = contentLayerAt(1); | 557 const cc::Layer* blackLayer = contentLayerAt(1); |
| 563 EXPECT_THAT(blackLayer->GetPicture(), | 558 EXPECT_THAT(blackLayer->GetPicture(), |
| 564 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); | 559 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); |
| 565 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); | 560 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); |
| 566 const cc::ClipNode* blackClip = | 561 const cc::ClipNode* blackClip = |
| 567 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); | 562 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); |
| 568 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, blackClip->clip_type); | 563 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, blackClip->clip_type); |
| 569 EXPECT_TRUE(blackClip->layers_are_clipped); | |
| 570 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->clip); | 564 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->clip); |
| 571 | 565 |
| 572 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); | 566 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); |
| 573 const cc::ClipNode* commonClipNode = | 567 const cc::ClipNode* commonClipNode = |
| 574 propertyTrees().clip_tree.Node(whiteClip->parent_id); | 568 propertyTrees().clip_tree.Node(whiteClip->parent_id); |
| 575 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, | 569 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, |
| 576 commonClipNode->clip_type); | 570 commonClipNode->clip_type); |
| 577 EXPECT_TRUE(commonClipNode->layers_are_clipped); | |
| 578 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); | 571 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); |
| 579 } | 572 } |
| 580 | 573 |
| 581 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, | 574 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, |
| 582 ForeignLayerPassesThrough) { | 575 ForeignLayerPassesThrough) { |
| 583 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); | 576 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); |
| 584 | 577 |
| 585 TestPaintArtifact testArtifact; | 578 TestPaintArtifact testArtifact; |
| 586 testArtifact | 579 testArtifact |
| 587 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 580 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| (...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 EXPECT_EQ(gfx::Size(50, 50), layer3->bounds()); | 1972 EXPECT_EQ(gfx::Size(50, 50), layer3->bounds()); |
| 1980 EXPECT_EQ(effectNode->id, layer3->effect_tree_index()); | 1973 EXPECT_EQ(effectNode->id, layer3->effect_tree_index()); |
| 1981 | 1974 |
| 1982 const cc::Layer* layer4 = contentLayerAt(3); | 1975 const cc::Layer* layer4 = contentLayerAt(3); |
| 1983 EXPECT_EQ(gfx::Vector2dF(100.f, 0.f), layer4->offset_to_transform_parent()); | 1976 EXPECT_EQ(gfx::Vector2dF(100.f, 0.f), layer4->offset_to_transform_parent()); |
| 1984 EXPECT_EQ(gfx::Size(150, 150), layer4->bounds()); | 1977 EXPECT_EQ(gfx::Size(150, 150), layer4->bounds()); |
| 1985 EXPECT_EQ(1, layer4->effect_tree_index()); | 1978 EXPECT_EQ(1, layer4->effect_tree_index()); |
| 1986 } | 1979 } |
| 1987 | 1980 |
| 1988 } // namespace blink | 1981 } // namespace blink |
| OLD | NEW |