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

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

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

Powered by Google App Engine
This is Rietveld 408576698