| 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_compositor_frame_sink.h" | 10 #include "cc/test/fake_compositor_frame_sink.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 update(artifact.build()); | 357 update(artifact.build()); |
| 358 | 358 |
| 359 ASSERT_EQ(1u, contentLayerCount()); | 359 ASSERT_EQ(1u, contentLayerCount()); |
| 360 const cc::Layer* layer = contentLayerAt(0); | 360 const cc::Layer* layer = contentLayerAt(0); |
| 361 EXPECT_THAT(layer->GetPicture(), | 361 EXPECT_THAT(layer->GetPicture(), |
| 362 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 362 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 363 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); | 363 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); |
| 364 | 364 |
| 365 const cc::ClipNode* clipNode = | 365 const cc::ClipNode* clipNode = |
| 366 propertyTrees().clip_tree.Node(layer->clip_tree_index()); | 366 propertyTrees().clip_tree.Node(layer->clip_tree_index()); |
| 367 EXPECT_TRUE(clipNode->applies_local_clip); | 367 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 368 EXPECT_TRUE(clipNode->layers_are_clipped); | 368 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 369 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); | 369 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
| 370 } | 370 } |
| 371 | 371 |
| 372 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { | 372 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { |
| 373 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 373 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 374 nullptr, nullptr, FloatRoundedRect(100, 100, 700, 700)); | 374 nullptr, nullptr, FloatRoundedRect(100, 100, 700, 700)); |
| 375 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 375 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 376 clip1, nullptr, FloatRoundedRect(200, 200, 700, 100)); | 376 clip1, nullptr, FloatRoundedRect(200, 200, 700, 100)); |
| 377 | 377 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 406 EXPECT_EQ(translation(300, 350), darkGrayLayer->screen_space_transform()); | 406 EXPECT_EQ(translation(300, 350), darkGrayLayer->screen_space_transform()); |
| 407 | 407 |
| 408 const cc::Layer* blackLayer = contentLayerAt(3); | 408 const cc::Layer* blackLayer = contentLayerAt(3); |
| 409 EXPECT_THAT(blackLayer->GetPicture(), | 409 EXPECT_THAT(blackLayer->GetPicture(), |
| 410 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); | 410 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); |
| 411 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); | 411 EXPECT_EQ(translation(300, 350), blackLayer->screen_space_transform()); |
| 412 | 412 |
| 413 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); | 413 EXPECT_EQ(whiteLayer->clip_tree_index(), darkGrayLayer->clip_tree_index()); |
| 414 const cc::ClipNode* outerClip = | 414 const cc::ClipNode* outerClip = |
| 415 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); | 415 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); |
| 416 EXPECT_TRUE(outerClip->applies_local_clip); | 416 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, outerClip->clip_type); |
| 417 EXPECT_TRUE(outerClip->layers_are_clipped); | 417 EXPECT_TRUE(outerClip->layers_are_clipped); |
| 418 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->clip); | 418 EXPECT_EQ(gfx::RectF(100, 100, 700, 700), outerClip->clip); |
| 419 | 419 |
| 420 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); | 420 EXPECT_EQ(lightGrayLayer->clip_tree_index(), blackLayer->clip_tree_index()); |
| 421 const cc::ClipNode* innerClip = | 421 const cc::ClipNode* innerClip = |
| 422 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); | 422 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); |
| 423 EXPECT_TRUE(innerClip->applies_local_clip); | 423 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, innerClip->clip_type); |
| 424 EXPECT_TRUE(innerClip->layers_are_clipped); | 424 EXPECT_TRUE(innerClip->layers_are_clipped); |
| 425 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->clip); | 425 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->clip); |
| 426 EXPECT_EQ(outerClip->id, innerClip->parent_id); | 426 EXPECT_EQ(outerClip->id, innerClip->parent_id); |
| 427 } | 427 } |
| 428 | 428 |
| 429 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) { | 429 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) { |
| 430 Vector<RefPtr<ClipPaintPropertyNode>> clips; | 430 Vector<RefPtr<ClipPaintPropertyNode>> clips; |
| 431 for (unsigned i = 1; i <= 10; i++) { | 431 for (unsigned i = 1; i <= 10; i++) { |
| 432 clips.append(ClipPaintPropertyNode::create( | 432 clips.append(ClipPaintPropertyNode::create( |
| 433 clips.isEmpty() ? nullptr : clips.last(), nullptr, | 433 clips.isEmpty() ? nullptr : clips.last(), nullptr, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 444 const cc::Layer* drawingLayer = contentLayerAt(0); | 444 const cc::Layer* drawingLayer = contentLayerAt(0); |
| 445 EXPECT_THAT(drawingLayer->GetPicture(), | 445 EXPECT_THAT(drawingLayer->GetPicture(), |
| 446 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); | 446 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); |
| 447 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); | 447 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); |
| 448 | 448 |
| 449 // Check the clip nodes. | 449 // Check the clip nodes. |
| 450 const cc::ClipNode* clipNode = | 450 const cc::ClipNode* clipNode = |
| 451 propertyTrees().clip_tree.Node(drawingLayer->clip_tree_index()); | 451 propertyTrees().clip_tree.Node(drawingLayer->clip_tree_index()); |
| 452 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { | 452 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { |
| 453 const ClipPaintPropertyNode* paintClipNode = it->get(); | 453 const ClipPaintPropertyNode* paintClipNode = it->get(); |
| 454 EXPECT_TRUE(clipNode->applies_local_clip); | 454 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 455 EXPECT_TRUE(clipNode->layers_are_clipped); | 455 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 456 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); | 456 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); |
| 457 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); | 457 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) { | 461 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) { |
| 462 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( | 462 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( |
| 463 nullptr, nullptr, FloatRoundedRect(0, 0, 800, 600)); | 463 nullptr, nullptr, FloatRoundedRect(0, 0, 800, 600)); |
| 464 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 464 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 465 commonClip, nullptr, FloatRoundedRect(0, 0, 400, 600)); | 465 commonClip, nullptr, FloatRoundedRect(0, 0, 400, 600)); |
| 466 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 466 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 467 commonClip, nullptr, FloatRoundedRect(400, 0, 400, 600)); | 467 commonClip, nullptr, FloatRoundedRect(400, 0, 400, 600)); |
| 468 | 468 |
| 469 TestPaintArtifact artifact; | 469 TestPaintArtifact artifact; |
| 470 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 470 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 471 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); | 471 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); |
| 472 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 472 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 473 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); | 473 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); |
| 474 update(artifact.build()); | 474 update(artifact.build()); |
| 475 | 475 |
| 476 ASSERT_EQ(2u, contentLayerCount()); | 476 ASSERT_EQ(2u, contentLayerCount()); |
| 477 | 477 |
| 478 const cc::Layer* whiteLayer = contentLayerAt(0); | 478 const cc::Layer* whiteLayer = contentLayerAt(0); |
| 479 EXPECT_THAT(whiteLayer->GetPicture(), | 479 EXPECT_THAT(whiteLayer->GetPicture(), |
| 480 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); | 480 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::white))); |
| 481 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); | 481 EXPECT_EQ(gfx::Transform(), whiteLayer->screen_space_transform()); |
| 482 const cc::ClipNode* whiteClip = | 482 const cc::ClipNode* whiteClip = |
| 483 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); | 483 propertyTrees().clip_tree.Node(whiteLayer->clip_tree_index()); |
| 484 EXPECT_TRUE(whiteClip->applies_local_clip); | 484 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, whiteClip->clip_type); |
| 485 EXPECT_TRUE(whiteClip->layers_are_clipped); | 485 EXPECT_TRUE(whiteClip->layers_are_clipped); |
| 486 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->clip); | 486 ASSERT_EQ(gfx::RectF(0, 0, 400, 600), whiteClip->clip); |
| 487 | 487 |
| 488 const cc::Layer* blackLayer = contentLayerAt(1); | 488 const cc::Layer* blackLayer = contentLayerAt(1); |
| 489 EXPECT_THAT(blackLayer->GetPicture(), | 489 EXPECT_THAT(blackLayer->GetPicture(), |
| 490 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); | 490 Pointee(drawsRectangle(FloatRect(0, 0, 640, 480), Color::black))); |
| 491 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); | 491 EXPECT_EQ(gfx::Transform(), blackLayer->screen_space_transform()); |
| 492 const cc::ClipNode* blackClip = | 492 const cc::ClipNode* blackClip = |
| 493 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); | 493 propertyTrees().clip_tree.Node(blackLayer->clip_tree_index()); |
| 494 EXPECT_TRUE(blackClip->applies_local_clip); | 494 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, blackClip->clip_type); |
| 495 EXPECT_TRUE(blackClip->layers_are_clipped); | 495 EXPECT_TRUE(blackClip->layers_are_clipped); |
| 496 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->clip); | 496 ASSERT_EQ(gfx::RectF(400, 0, 400, 600), blackClip->clip); |
| 497 | 497 |
| 498 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); | 498 EXPECT_EQ(whiteClip->parent_id, blackClip->parent_id); |
| 499 const cc::ClipNode* commonClipNode = | 499 const cc::ClipNode* commonClipNode = |
| 500 propertyTrees().clip_tree.Node(whiteClip->parent_id); | 500 propertyTrees().clip_tree.Node(whiteClip->parent_id); |
| 501 EXPECT_TRUE(commonClipNode->applies_local_clip); | 501 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, |
| 502 commonClipNode->clip_type); |
| 502 EXPECT_TRUE(commonClipNode->layers_are_clipped); | 503 EXPECT_TRUE(commonClipNode->layers_are_clipped); |
| 503 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); | 504 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, | 507 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, |
| 507 ForeignLayerPassesThrough) { | 508 ForeignLayerPassesThrough) { |
| 508 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); | 509 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); |
| 509 | 510 |
| 510 TestPaintArtifact artifact; | 511 TestPaintArtifact artifact; |
| 511 artifact.chunk(PaintChunkProperties()) | 512 artifact.chunk(PaintChunkProperties()) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); | 653 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); |
| 653 | 654 |
| 654 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & | 655 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & |
| 655 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 656 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 656 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & | 657 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & |
| 657 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 658 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 658 } | 659 } |
| 659 | 660 |
| 660 } // namespace | 661 } // namespace |
| 661 } // namespace blink | 662 } // namespace blink |
| OLD | NEW |