| 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" | 9 #include "platform/graphics/BoxReflection.h" |
| 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 bool hasRadius = false; | 269 bool hasRadius = false; |
| 270 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 270 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
| 271 rootPropertyTreeState(), hasRadius); | 271 rootPropertyTreeState(), hasRadius); |
| 272 | 272 |
| 273 // Check the cached matrix for the intermediate transform. | 273 // Check the cached matrix for the intermediate transform. |
| 274 EXPECT_EQ( | 274 EXPECT_EQ( |
| 275 rotateTransform, | 275 rotateTransform, |
| 276 *getTransform(transform1.get(), rootPropertyTreeState().transform())); | 276 *getTransform(transform1.get(), rootPropertyTreeState().transform())); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(GeometryMapperTest, NestedTransformsFlattening) { | |
| 280 TransformationMatrix rotateTransform; | |
| 281 rotateTransform.rotate3d(45, 0, 0); | |
| 282 RefPtr<TransformPaintPropertyNode> transform1 = | |
| 283 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | |
| 284 rotateTransform, FloatPoint3D()); | |
| 285 | |
| 286 TransformationMatrix inverseRotateTransform; | |
| 287 inverseRotateTransform.rotate3d(-45, 0, 0); | |
| 288 RefPtr<TransformPaintPropertyNode> transform2 = | |
| 289 TransformPaintPropertyNode::create(transform1, inverseRotateTransform, | |
| 290 FloatPoint3D(), | |
| 291 true); // Flattens | |
| 292 | |
| 293 PropertyTreeState localState = rootPropertyTreeState(); | |
| 294 localState.setTransform(transform2.get()); | |
| 295 | |
| 296 FloatRect input(0, 0, 100, 100); | |
| 297 rotateTransform.flattenTo2d(); | |
| 298 TransformationMatrix final = rotateTransform * inverseRotateTransform; | |
| 299 FloatRect output = final.mapRect(input); | |
| 300 bool hasRadius = false; | |
| 301 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | |
| 302 rootPropertyTreeState(), hasRadius); | |
| 303 } | |
| 304 | |
| 305 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { | 279 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { |
| 306 TransformationMatrix scaleTransform; | 280 TransformationMatrix scaleTransform; |
| 307 scaleTransform.scale(2); | 281 scaleTransform.scale(2); |
| 308 RefPtr<TransformPaintPropertyNode> transform1 = | 282 RefPtr<TransformPaintPropertyNode> transform1 = |
| 309 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 283 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 310 scaleTransform, FloatPoint3D()); | 284 scaleTransform, FloatPoint3D()); |
| 311 | 285 |
| 312 TransformationMatrix translateTransform; | 286 TransformationMatrix translateTransform; |
| 313 translateTransform.translate(100, 0); | 287 translateTransform.translate(100, 0); |
| 314 RefPtr<TransformPaintPropertyNode> transform2 = | 288 RefPtr<TransformPaintPropertyNode> transform2 = |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 output = filters.mapRect(output); | 812 output = filters.mapRect(output); |
| 839 EXPECT_EQ(FloatRect(-50, -50, 210, 210), output); | 813 EXPECT_EQ(FloatRect(-50, -50, 210, 210), output); |
| 840 // 4. clipAboveEffect | 814 // 4. clipAboveEffect |
| 841 output.intersect(clipAboveEffect->clipRect().rect()); | 815 output.intersect(clipAboveEffect->clipRect().rect()); |
| 842 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output); | 816 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output); |
| 843 // 5. transformAboveEffect | 817 // 5. transformAboveEffect |
| 844 output = transformAboveEffect->matrix().mapRect(output); | 818 output = transformAboveEffect->matrix().mapRect(output); |
| 845 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output); | 819 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output); |
| 846 | 820 |
| 847 bool hasRadius = false; | 821 bool hasRadius = false; |
| 848 TransformationMatrix combinedTransform = | 822 CHECK_MAPPINGS( |
| 849 transformAboveEffect->matrix() * transformBelowEffect->matrix(); | 823 input, output, FloatRect(0, 0, 300, 300), |
| 850 CHECK_MAPPINGS(input, output, FloatRect(0, 0, 300, 300), combinedTransform, | 824 transformAboveEffect->matrix() * transformBelowEffect->matrix(), |
| 851 FloatClipRect(FloatRect(30, 30, 270, 270)), localState, | 825 FloatClipRect(FloatRect(30, 30, 270, 270)), localState, |
| 852 rootPropertyTreeState(), hasRadius); | 826 rootPropertyTreeState(), hasRadius); |
| 853 } | 827 } |
| 854 | 828 |
| 855 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) { | 829 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) { |
| 856 CompositorFilterOperations filters; | 830 CompositorFilterOperations filters; |
| 857 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter( | 831 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter( |
| 858 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr)); | 832 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr)); |
| 859 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( | 833 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 860 rootPropertyTreeState().effect(), rootPropertyTreeState().transform(), | 834 rootPropertyTreeState().effect(), rootPropertyTreeState().transform(), |
| 861 rootPropertyTreeState().clip(), ColorFilterNone, filters, 1.0, | 835 rootPropertyTreeState().clip(), ColorFilterNone, filters, 1.0, |
| 862 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(), | 836 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(), |
| 863 FloatPoint(100, 100)); | 837 FloatPoint(100, 100)); |
| 864 | 838 |
| 865 PropertyTreeState localState = rootPropertyTreeState(); | 839 PropertyTreeState localState = rootPropertyTreeState(); |
| 866 localState.setEffect(effect); | 840 localState.setEffect(effect); |
| 867 | 841 |
| 868 FloatRect input(100, 100, 50, 50); | 842 FloatRect input(100, 100, 50, 50); |
| 869 // Reflection is at (50, 100, 50, 50). | 843 // Reflection is at (50, 100, 50, 50). |
| 870 FloatRect output(50, 100, 100, 50); | 844 FloatRect output(50, 100, 100, 50); |
| 871 | 845 |
| 872 bool hasRadius = false; | 846 bool hasRadius = false; |
| 873 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), | 847 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), |
| 874 localState, rootPropertyTreeState(), hasRadius); | 848 localState, rootPropertyTreeState(), hasRadius); |
| 875 } | 849 } |
| 876 | 850 |
| 877 } // namespace blink | 851 } // namespace blink |
| OLD | NEW |