| 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/paint/GeometryMapper.h" | 5 #include "platform/graphics/paint/GeometryMapper.h" |
| 6 | 6 |
| 7 #include "platform/geometry/GeometryTestHelpers.h" | 7 #include "platform/geometry/GeometryTestHelpers.h" |
| 8 #include "platform/geometry/LayoutRect.h" | 8 #include "platform/geometry/LayoutRect.h" |
| 9 #include "platform/graphics/BoxReflection.h" |
| 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 11 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 12 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 11 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 13 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 12 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 14 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 13 #include "platform/testing/PaintPropertyTestHelpers.h" | 15 #include "platform/testing/PaintPropertyTestHelpers.h" |
| 14 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 16 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 namespace blink { | 19 namespace blink { |
| 18 | 20 |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 lowestCommonAncestor(childOfChild2.get(), child1.get())); | 602 lowestCommonAncestor(childOfChild2.get(), child1.get())); |
| 601 EXPECT_EQ(rootPropertyTreeState().transform(), | 603 EXPECT_EQ(rootPropertyTreeState().transform(), |
| 602 lowestCommonAncestor(childOfChild2.get(), | 604 lowestCommonAncestor(childOfChild2.get(), |
| 603 rootPropertyTreeState().transform())); | 605 rootPropertyTreeState().transform())); |
| 604 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get())); | 606 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get())); |
| 605 | 607 |
| 606 EXPECT_EQ(rootPropertyTreeState().transform(), | 608 EXPECT_EQ(rootPropertyTreeState().transform(), |
| 607 lowestCommonAncestor(child1.get(), child2.get())); | 609 lowestCommonAncestor(child1.get(), child2.get())); |
| 608 } | 610 } |
| 609 | 611 |
| 612 TEST_F(GeometryMapperTest, FilterWithClipsAndTransforms) { |
| 613 RefPtr<TransformPaintPropertyNode> transformAboveEffect = |
| 614 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 615 TransformationMatrix().scale(3), |
| 616 FloatPoint3D()); |
| 617 RefPtr<TransformPaintPropertyNode> transformBelowEffect = |
| 618 TransformPaintPropertyNode::create(transformAboveEffect, |
| 619 TransformationMatrix().scale(2), |
| 620 FloatPoint3D()); |
| 621 |
| 622 // This clip is between transformAboveEffect and the effect. |
| 623 RefPtr<ClipPaintPropertyNode> clipAboveEffect = ClipPaintPropertyNode::create( |
| 624 rootPropertyTreeState().clip(), transformAboveEffect, |
| 625 FloatRoundedRect(-100, -100, 200, 200)); |
| 626 // This clip is between the effect and transformBelowEffect. |
| 627 RefPtr<ClipPaintPropertyNode> clipBelowEffect = |
| 628 ClipPaintPropertyNode::create(clipAboveEffect, transformAboveEffect, |
| 629 FloatRoundedRect(10, 10, 200, 200)); |
| 630 |
| 631 CompositorFilterOperations filters; |
| 632 filters.appendBlurFilter(20); |
| 633 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 634 rootPropertyTreeState().effect(), transformAboveEffect, clipAboveEffect, |
| 635 filters, 1.0, SkBlendMode::kSrcOver); |
| 636 |
| 637 PropertyTreeState localState(transformBelowEffect.get(), |
| 638 clipBelowEffect.get(), effect.get(), nullptr); |
| 639 |
| 640 FloatRect input(0, 0, 50, 50); |
| 641 // 1. transformBelowEffect |
| 642 FloatRect output = transformBelowEffect->matrix().mapRect(input); |
| 643 // 2. clipBelowEffect |
| 644 output.intersect(clipBelowEffect->clipRect().rect()); |
| 645 EXPECT_EQ(FloatRect(10, 10, 90, 90), output); |
| 646 // 3. effect (the outset is 3 times of blur amount). |
| 647 output = filters.mapRect(output); |
| 648 EXPECT_EQ(FloatRect(-50, -50, 210, 210), output); |
| 649 // 4. clipAboveEffect |
| 650 output.intersect(clipAboveEffect->clipRect().rect()); |
| 651 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output); |
| 652 // 5. transformAboveEffect |
| 653 output = transformAboveEffect->matrix().mapRect(output); |
| 654 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output); |
| 655 |
| 656 CHECK_MAPPINGS( |
| 657 input, output, FloatRect(0, 0, 300, 300), |
| 658 transformAboveEffect->matrix() * transformBelowEffect->matrix(), |
| 659 FloatRect(30, 30, 270, 270), localState, rootPropertyTreeState()); |
| 660 } |
| 661 |
| 662 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) { |
| 663 CompositorFilterOperations filters; |
| 664 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter( |
| 665 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr)); |
| 666 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 667 rootPropertyTreeState().effect(), rootPropertyTreeState().transform(), |
| 668 rootPropertyTreeState().clip(), filters, 1.0, SkBlendMode::kSrcOver, |
| 669 CompositingReasonNone, CompositorElementId(), FloatPoint(100, 100)); |
| 670 |
| 671 PropertyTreeState localState = rootPropertyTreeState(); |
| 672 localState.setEffect(effect); |
| 673 |
| 674 FloatRect input(100, 100, 50, 50); |
| 675 // Reflection is at (50, 100, 50, 50). |
| 676 FloatRect output(50, 100, 100, 50); |
| 677 |
| 678 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), |
| 679 ClipPaintPropertyNode::root()->clipRect().rect(), localState, |
| 680 rootPropertyTreeState()); |
| 681 } |
| 682 |
| 610 } // namespace blink | 683 } // namespace blink |
| OLD | NEW |