| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 std::unique_ptr<GeometryMapper> geometryMapper; | 25 std::unique_ptr<GeometryMapper> geometryMapper; |
| 26 | 26 |
| 27 PropertyTreeState rootPropertyTreeState() { | 27 PropertyTreeState rootPropertyTreeState() { |
| 28 PropertyTreeState state(TransformPaintPropertyNode::root(), | 28 PropertyTreeState state(TransformPaintPropertyNode::root(), |
| 29 ClipPaintPropertyNode::root(), | 29 ClipPaintPropertyNode::root(), |
| 30 EffectPaintPropertyNode::root()); | 30 EffectPaintPropertyNode::root()); |
| 31 return state; | 31 return state; |
| 32 } | 32 } |
| 33 | 33 |
| 34 const FloatClipRect* getClip( | 34 GeometryMapper::TransformCache& getTransformCache( |
| 35 const ClipPaintPropertyNode* descendantClip, | 35 const PropertyTreeState& propertyTreeState) { |
| 36 const PropertyTreeState& ancestorPropertyTreeState) { | 36 return geometryMapper->getTransformCache(propertyTreeState.transform()); |
| 37 GeometryMapperClipCache::ClipAndTransform clipAndTransform( | |
| 38 ancestorPropertyTreeState.clip(), | |
| 39 ancestorPropertyTreeState.transform()); | |
| 40 return descendantClip->getClipCache().getCachedClip(clipAndTransform); | |
| 41 } | 37 } |
| 42 | 38 |
| 43 const TransformationMatrix* getTransform( | 39 GeometryMapper::ClipCache& getClipCache( |
| 44 const TransformPaintPropertyNode* descendantTransform, | 40 const PropertyTreeState& propertyTreeState) { |
| 45 const TransformPaintPropertyNode* ancestorTransform) { | 41 return geometryMapper->getClipCache(propertyTreeState.clip(), |
| 46 return descendantTransform->getTransformCache().getCachedTransform( | 42 propertyTreeState.transform()); |
| 47 ancestorTransform); | |
| 48 } | 43 } |
| 49 | 44 |
| 50 const TransformPaintPropertyNode* lowestCommonAncestor( | 45 const TransformPaintPropertyNode* lowestCommonAncestor( |
| 51 const TransformPaintPropertyNode* a, | 46 const TransformPaintPropertyNode* a, |
| 52 const TransformPaintPropertyNode* b) { | 47 const TransformPaintPropertyNode* b) { |
| 53 return GeometryMapper::lowestCommonAncestor(a, b); | 48 return GeometryMapper::lowestCommonAncestor(a, b); |
| 54 } | 49 } |
| 55 | 50 |
| 56 FloatRect sourceToDestinationVisualRectInternal( | 51 FloatRect sourceToDestinationVisualRectInternal( |
| 57 const FloatRect& rect, | 52 const FloatRect& rect, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 EXPECT_RECT_EQ(expectedTransformedRect, \ | 133 EXPECT_RECT_EQ(expectedTransformedRect, \ |
| 139 geometryMapper->localToAncestorRect( \ | 134 geometryMapper->localToAncestorRect( \ |
| 140 inputRect, localPropertyTreeState.transform(), \ | 135 inputRect, localPropertyTreeState.transform(), \ |
| 141 ancestorPropertyTreeState.transform())); \ | 136 ancestorPropertyTreeState.transform())); \ |
| 142 EXPECT_RECT_EQ(expectedTransformedRect, \ | 137 EXPECT_RECT_EQ(expectedTransformedRect, \ |
| 143 geometryMapper->sourceToDestinationRect( \ | 138 geometryMapper->sourceToDestinationRect( \ |
| 144 inputRect, localPropertyTreeState.transform(), \ | 139 inputRect, localPropertyTreeState.transform(), \ |
| 145 ancestorPropertyTreeState.transform())); \ | 140 ancestorPropertyTreeState.transform())); \ |
| 146 if (ancestorPropertyTreeState.transform() != \ | 141 if (ancestorPropertyTreeState.transform() != \ |
| 147 localPropertyTreeState.transform()) { \ | 142 localPropertyTreeState.transform()) { \ |
| 148 const TransformationMatrix* transformForTesting = \ | 143 EXPECT_EQ(expectedTransformToAncestor, \ |
| 149 getTransform(localPropertyTreeState.transform(), \ | 144 getTransformCache(ancestorPropertyTreeState) \ |
| 150 ancestorPropertyTreeState.transform()); \ | 145 .at(localPropertyTreeState.transform())); \ |
| 151 CHECK(transformForTesting); \ | |
| 152 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \ | |
| 153 } \ | 146 } \ |
| 154 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ | 147 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ |
| 155 const FloatClipRect* outputClipForTesting = \ | 148 EXPECT_EQ(expectedClipInAncestorSpace, \ |
| 156 getClip(localPropertyTreeState.clip(), ancestorPropertyTreeState); \ | 149 getClipCache(ancestorPropertyTreeState) \ |
| 157 DCHECK(outputClipForTesting); \ | 150 .at(localPropertyTreeState.clip())) \ |
| 158 EXPECT_EQ(expectedClipInAncestorSpace, *outputClipForTesting) \ | |
| 159 << expectedClipInAncestorSpace.rect().toString() << " " \ | 151 << expectedClipInAncestorSpace.rect().toString() << " " \ |
| 160 << outputClipForTesting->rect().toString(); \ | 152 << getClipCache(ancestorPropertyTreeState) \ |
| 153 .at(localPropertyTreeState.clip()) \ |
| 154 .rect() \ |
| 155 .toString(); \ |
| 161 } \ | 156 } \ |
| 162 } while (false) | 157 } while (false) |
| 163 | 158 |
| 164 TEST_F(GeometryMapperTest, Root) { | 159 TEST_F(GeometryMapperTest, Root) { |
| 165 FloatRect input(0, 0, 100, 100); | 160 FloatRect input(0, 0, 100, 100); |
| 166 | 161 |
| 167 bool hasRadius = false; | 162 bool hasRadius = false; |
| 168 CHECK_MAPPINGS(input, input, input, | 163 CHECK_MAPPINGS(input, input, input, |
| 169 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(), | 164 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(), |
| 170 rootPropertyTreeState(), rootPropertyTreeState(), hasRadius); | 165 rootPropertyTreeState(), rootPropertyTreeState(), hasRadius); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 258 |
| 264 FloatRect input(0, 0, 100, 100); | 259 FloatRect input(0, 0, 100, 100); |
| 265 TransformationMatrix final = rotateTransform * scaleTransform; | 260 TransformationMatrix final = rotateTransform * scaleTransform; |
| 266 FloatRect output = final.mapRect(input); | 261 FloatRect output = final.mapRect(input); |
| 267 | 262 |
| 268 bool hasRadius = false; | 263 bool hasRadius = false; |
| 269 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 264 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
| 270 rootPropertyTreeState(), hasRadius); | 265 rootPropertyTreeState(), hasRadius); |
| 271 | 266 |
| 272 // Check the cached matrix for the intermediate transform. | 267 // Check the cached matrix for the intermediate transform. |
| 273 EXPECT_EQ( | 268 EXPECT_EQ(rotateTransform, |
| 274 rotateTransform, | 269 getTransformCache(rootPropertyTreeState()).at(transform1.get())); |
| 275 *getTransform(transform1.get(), rootPropertyTreeState().transform())); | |
| 276 } | 270 } |
| 277 | 271 |
| 278 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { | 272 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { |
| 279 TransformationMatrix scaleTransform; | 273 TransformationMatrix scaleTransform; |
| 280 scaleTransform.scale(2); | 274 scaleTransform.scale(2); |
| 281 RefPtr<TransformPaintPropertyNode> transform1 = | 275 RefPtr<TransformPaintPropertyNode> transform1 = |
| 282 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 276 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 283 scaleTransform, FloatPoint3D()); | 277 scaleTransform, FloatPoint3D()); |
| 284 | 278 |
| 285 TransformationMatrix translateTransform; | 279 TransformationMatrix translateTransform; |
| 286 translateTransform.translate(100, 0); | 280 translateTransform.translate(100, 0); |
| 287 RefPtr<TransformPaintPropertyNode> transform2 = | 281 RefPtr<TransformPaintPropertyNode> transform2 = |
| 288 TransformPaintPropertyNode::create(transform1, translateTransform, | 282 TransformPaintPropertyNode::create(transform1, translateTransform, |
| 289 FloatPoint3D()); | 283 FloatPoint3D()); |
| 290 | 284 |
| 291 PropertyTreeState localState = rootPropertyTreeState(); | 285 PropertyTreeState localState = rootPropertyTreeState(); |
| 292 localState.setTransform(transform2.get()); | 286 localState.setTransform(transform2.get()); |
| 293 | 287 |
| 294 FloatRect input(0, 0, 100, 100); | 288 FloatRect input(0, 0, 100, 100); |
| 295 // Note: unlike NestedTransforms, the order of these transforms matters. This | 289 // Note: unlike NestedTransforms, the order of these transforms matters. This |
| 296 // tests correct order of matrix multiplication. | 290 // tests correct order of matrix multiplication. |
| 297 TransformationMatrix final = scaleTransform * translateTransform; | 291 TransformationMatrix final = scaleTransform * translateTransform; |
| 298 FloatRect output = final.mapRect(input); | 292 FloatRect output = final.mapRect(input); |
| 299 | 293 |
| 300 bool hasRadius = false; | 294 bool hasRadius = false; |
| 301 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 295 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
| 302 rootPropertyTreeState(), hasRadius); | 296 rootPropertyTreeState(), hasRadius); |
| 303 | 297 |
| 304 // Check the cached matrix for the intermediate transform. | 298 // Check the cached matrix for the intermediate transform. |
| 305 EXPECT_EQ(scaleTransform, *getTransform(transform1.get(), | 299 EXPECT_EQ(scaleTransform, |
| 306 rootPropertyTreeState().transform())); | 300 getTransformCache(rootPropertyTreeState()) |
| 301 |
| 302 .at(transform1.get())); |
| 307 } | 303 } |
| 308 | 304 |
| 309 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { | 305 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { |
| 310 TransformationMatrix rotateTransform; | 306 TransformationMatrix rotateTransform; |
| 311 rotateTransform.rotate(45); | 307 rotateTransform.rotate(45); |
| 312 RefPtr<TransformPaintPropertyNode> transform1 = | 308 RefPtr<TransformPaintPropertyNode> transform1 = |
| 313 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 309 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 314 rotateTransform, FloatPoint3D()); | 310 rotateTransform, FloatPoint3D()); |
| 315 | 311 |
| 316 TransformationMatrix scaleTransform; | 312 TransformationMatrix scaleTransform; |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 FloatRect input(100, 100, 50, 50); | 831 FloatRect input(100, 100, 50, 50); |
| 836 // Reflection is at (50, 100, 50, 50). | 832 // Reflection is at (50, 100, 50, 50). |
| 837 FloatRect output(50, 100, 100, 50); | 833 FloatRect output(50, 100, 100, 50); |
| 838 | 834 |
| 839 bool hasRadius = false; | 835 bool hasRadius = false; |
| 840 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), | 836 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), |
| 841 localState, rootPropertyTreeState(), hasRadius); | 837 localState, rootPropertyTreeState(), hasRadius); |
| 842 } | 838 } |
| 843 | 839 |
| 844 } // namespace blink | 840 } // namespace blink |
| OLD | NEW |