Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp

Issue 2744743003: Add support for flattening in GeometryMapper. (Closed)
Patch Set: none Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
279 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { 305 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) {
280 TransformationMatrix scaleTransform; 306 TransformationMatrix scaleTransform;
281 scaleTransform.scale(2); 307 scaleTransform.scale(2);
282 RefPtr<TransformPaintPropertyNode> transform1 = 308 RefPtr<TransformPaintPropertyNode> transform1 =
283 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 309 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
284 scaleTransform, FloatPoint3D()); 310 scaleTransform, FloatPoint3D());
285 311
286 TransformationMatrix translateTransform; 312 TransformationMatrix translateTransform;
287 translateTransform.translate(100, 0); 313 translateTransform.translate(100, 0);
288 RefPtr<TransformPaintPropertyNode> transform2 = 314 RefPtr<TransformPaintPropertyNode> transform2 =
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 output = filters.mapRect(output); 838 output = filters.mapRect(output);
813 EXPECT_EQ(FloatRect(-50, -50, 210, 210), output); 839 EXPECT_EQ(FloatRect(-50, -50, 210, 210), output);
814 // 4. clipAboveEffect 840 // 4. clipAboveEffect
815 output.intersect(clipAboveEffect->clipRect().rect()); 841 output.intersect(clipAboveEffect->clipRect().rect());
816 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output); 842 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output);
817 // 5. transformAboveEffect 843 // 5. transformAboveEffect
818 output = transformAboveEffect->matrix().mapRect(output); 844 output = transformAboveEffect->matrix().mapRect(output);
819 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output); 845 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output);
820 846
821 bool hasRadius = false; 847 bool hasRadius = false;
822 CHECK_MAPPINGS( 848 TransformationMatrix combinedTransform =
823 input, output, FloatRect(0, 0, 300, 300), 849 transformAboveEffect->matrix() * transformBelowEffect->matrix();
824 transformAboveEffect->matrix() * transformBelowEffect->matrix(), 850 CHECK_MAPPINGS(input, output, FloatRect(0, 0, 300, 300), combinedTransform,
825 FloatClipRect(FloatRect(30, 30, 270, 270)), localState, 851 FloatClipRect(FloatRect(30, 30, 270, 270)), localState,
826 rootPropertyTreeState(), hasRadius); 852 rootPropertyTreeState(), hasRadius);
827 } 853 }
828 854
829 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) { 855 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) {
830 CompositorFilterOperations filters; 856 CompositorFilterOperations filters;
831 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter( 857 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter(
832 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr)); 858 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr));
833 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( 859 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create(
834 rootPropertyTreeState().effect(), rootPropertyTreeState().transform(), 860 rootPropertyTreeState().effect(), rootPropertyTreeState().transform(),
835 rootPropertyTreeState().clip(), ColorFilterNone, filters, 1.0, 861 rootPropertyTreeState().clip(), ColorFilterNone, filters, 1.0,
836 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(), 862 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(),
837 FloatPoint(100, 100)); 863 FloatPoint(100, 100));
838 864
839 PropertyTreeState localState = rootPropertyTreeState(); 865 PropertyTreeState localState = rootPropertyTreeState();
840 localState.setEffect(effect); 866 localState.setEffect(effect);
841 867
842 FloatRect input(100, 100, 50, 50); 868 FloatRect input(100, 100, 50, 50);
843 // Reflection is at (50, 100, 50, 50). 869 // Reflection is at (50, 100, 50, 50).
844 FloatRect output(50, 100, 100, 50); 870 FloatRect output(50, 100, 100, 50);
845 871
846 bool hasRadius = false; 872 bool hasRadius = false;
847 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), 873 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(),
848 localState, rootPropertyTreeState(), hasRadius); 874 localState, rootPropertyTreeState(), hasRadius);
849 } 875 }
850 876
851 } // namespace blink 877 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698