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