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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.h

Issue 2105273004: GeometryMapper: Support computing visual rects in spaces that are not direct ancestors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: none Created 4 years, 5 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 #ifndef GeometryMapper_h 5 #ifndef GeometryMapper_h
6 #define GeometryMapper_h 6 #define GeometryMapper_h
7 7
8 #include "platform/geometry/FloatRect.h" 8 #include "platform/geometry/FloatRect.h"
9 #include "platform/graphics/paint/PropertyTreeState.h" 9 #include "platform/graphics/paint/PropertyTreeState.h"
10 #include "platform/transforms/TransformationMatrix.h" 10 #include "platform/transforms/TransformationMatrix.h"
(...skipping 15 matching lines...) Expand all
26 static std::unique_ptr<PrecomputedDataForAncestor> create() 26 static std::unique_ptr<PrecomputedDataForAncestor> create()
27 { 27 {
28 return wrapUnique(new PrecomputedDataForAncestor()); 28 return wrapUnique(new PrecomputedDataForAncestor());
29 } 29 }
30 }; 30 };
31 31
32 // GeometryMapper is a helper class for fast computations of transformed and vis ual rects in different 32 // GeometryMapper is a helper class for fast computations of transformed and vis ual rects in different
33 // PropertyTreeStates. The design document has a number of details on use cases, algorithmic definitions, 33 // PropertyTreeStates. The design document has a number of details on use cases, algorithmic definitions,
34 // and running times. 34 // and running times.
35 // 35 //
36 // NOTE: a GeometryMapper object is only valid for property trees that do not ch ange. If any mutation occurs,
37 // a new GeometryMapper object must be allocated corresponding to the new state.
38 //
36 // Design document: http://bit.ly/28P4FDA 39 // Design document: http://bit.ly/28P4FDA
37 // 40 //
38 // TODO(chrishtr): take effect and scroll trees into account. 41 // TODO(chrishtr): take effect and scroll trees into account.
39 class PLATFORM_EXPORT GeometryMapper { 42 class PLATFORM_EXPORT GeometryMapper {
40 public: 43 public:
41 GeometryMapper() {} 44 GeometryMapper() {}
42
43 // The runtime of m calls among LocalToVisualRectInAncestorSpace, LocalToAnc estorRect or AncestorToLocalRect 45 // The runtime of m calls among LocalToVisualRectInAncestorSpace, LocalToAnc estorRect or AncestorToLocalRect
44 // with the same |ancestorState| parameter is guaranteed to be O(n + m), wh ere n is the number of transform and clip 46 // with the same |ancestorState| parameter is guaranteed to be O(n + m), wh ere n is the number of transform and clip
45 // nodes in their respective property trees. 47 // nodes in their respective property trees.
46 48
49 // If the clips and transforms of |sourceState| are equal to or descendants of those of |destinationState|, returns
50 // the same value as localToVisualRectInAncestorSpace. Otherwise, maps the i nput rect to the transform state which is
51 // the least common ancestor of |sourceState.transform| and |destinationStat e.transform|, then multiplies it by
52 // the the inverse transform mapping from the least common ancestor to |dest inationState.transform|.
53 //
54 // If that inverse transform is not invertible, sets |success| to false and returns the input rect. Otherwise, sets
55 // |success| to true.
56 FloatRect mapToVisualRectInDestinationSpace(const FloatRect&,
57 const PropertyTreeState& sourceState,
58 const PropertyTreeState& destinationState,
59 bool& success);
60
47 // Maps from a rect in |localTransformSpace| to its visual rect in |ancestor State|. This is computed 61 // Maps from a rect in |localTransformSpace| to its visual rect in |ancestor State|. This is computed
48 // by multiplying the rect by its combined transform between |localTransform Space| and |ancestorSpace|, 62 // by multiplying the rect by its combined transform between |localTransform Space| and |ancestorSpace|,
49 // then flattening into 2D space, then intersecting by the "clip visual rect " for |localTransformState|'s clips. 63 // then flattening into 2D space, then intersecting by the "clip visual rect " for |localTransformState|'s clips.
50 // See above for the definition of "clip visual rect". 64 // See above for the definition of "clip visual rect".
51 // 65 //
52 // Note that the clip of |ancestorState| is *not* applied. 66 // Note that the clip of |ancestorState| is *not* applied.
53 // 67 //
54 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal 68 // If any of the paint property tree nodes in |localTransformState| are not equal
55 // to or a descendant of that in |ancestorState|. 69 // to or a descendant of that in |ancestorState|, returns the passed-in rect and sets |success| to false. Otherwise,
56 FloatRect LocalToVisualRectInAncestorSpace(const FloatRect&, 70 // sets |success| to true.
71 FloatRect localToVisualRectInAncestorSpace(const FloatRect&,
57 const PropertyTreeState& localTransformState, 72 const PropertyTreeState& localTransformState,
58 const PropertyTreeState& ancestorState); 73 const PropertyTreeState& ancestorState, bool& success);
59 74
60 // Maps from a rect in |localTransformSpace| to its transformed rect in |anc estorSpace|. This is computed 75 // Maps from a rect in |localTransformSpace| to its transformed rect in |anc estorSpace|. This is computed
61 // by multiplying the rect by the combined transform between |localTransform State| and |ancestorState|, 76 // by multiplying the rect by the combined transform between |localTransform State| and |ancestorState|,
62 // then flattening into 2D space. 77 // then flattening into 2D space.
63 // 78 //
64 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal 79 // If any of the paint property tree nodes in |localTransformState| are not equal
65 // to or a descendant of that in |ancestorState|. 80 // to or a descendant of that in |ancestorState|, returns the passed-in rec and sets |success| to false. Otherwise,
66 FloatRect LocalToAncestorRect(const FloatRect&, 81 // sets |success| to true.
82 //
83 // If any of the paint property tree nodes in |localTransformState| are not equal
84 // to or a descendant of that in |ancestorState|, returns the passed-in rect and sets |success| to false. Otherwise,
85 // sets |success| to true.
86 FloatRect localToAncestorRect(const FloatRect&,
67 const PropertyTreeState& localTransformState, 87 const PropertyTreeState& localTransformState,
68 const PropertyTreeState& ancestorState); 88 const PropertyTreeState& ancestorState, bool& success);
69 89
70 // Maps from a rect in |ancestorSpace| to its transformed rect in |localTran sformSpace|. This is computed 90 // Maps from a rect in |ancestorSpace| to its transformed rect in |localTran sformSpace|. This is computed
71 // by multiplying the rect by the inverse combined transform between |localT ransformState| and |ancestorState|, 91 // by multiplying the rect by the inverse combined transform between |localT ransformState| and |ancestorState|,
72 // if the transform is invertible. If is invertible, also sets |*success| to true. Otherwise sets |*success| to false. 92 // if the transform is invertible.
73 // 93 //
74 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal 94 // If any of the paint property tree nodes in |localTransformState| are not equal
75 // to or a descendant of that in |ancestorState|. 95 // to or a descendant of that in |ancestorState|, returns the passed-in rect and sets |success| to false. Otherwise,
76 FloatRect AncestorToLocalRect(const FloatRect&, 96 // sets |success| to true.
97 FloatRect ancestorToLocalRect(const FloatRect&,
77 const PropertyTreeState& localTransformState, 98 const PropertyTreeState& localTransformState,
78 const PropertyTreeState& ancestorState, bool* success); 99 const PropertyTreeState& ancestorState, bool& success);
79 100
80 private: 101 private:
81 // Returns the matrix used in |LocalToAncestorRect|. 102 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to fails e iff |localTransformNode| is not
82 const TransformationMatrix& LocalToAncestorMatrix( 103 // equal to or a descendant of |ancestorState.transform|.
83 const TransformPaintPropertyNode* localTransformState, 104 const TransformationMatrix& localToAncestorMatrix(
84 const PropertyTreeState& ancestorState); 105 const TransformPaintPropertyNode* localTransformNode,
106 const PropertyTreeState& ancestorState, bool& success);
85 107
86 // Returns the "clip visual rect" between |localTransformState| and |ancesto rState|. See above for the definition 108 // Returns the "clip visual rect" between |localTransformState| and |ancesto rState|. See above for the definition
87 // of "clip visual rect". 109 // of "clip visual rect".
88 const FloatRect& LocalToAncestorClipRect( 110 const FloatRect& localToAncestorClipRect(
89 const PropertyTreeState& localTransformState, 111 const PropertyTreeState& localTransformState,
90 const PropertyTreeState& ancestorState); 112 const PropertyTreeState& ancestorState);
91 113
92 // Returns the precomputed data if already set, or adds and memoizes a new P recomputedDataForAncestor otherwise. 114 // Returns the precomputed data if already set, or adds and memoizes a new P recomputedDataForAncestor otherwise.
93 PrecomputedDataForAncestor& GetPrecomputedDataForAncestor(const PropertyTree State&); 115 PrecomputedDataForAncestor& getPrecomputedDataForAncestor(const PropertyTree State&);
116
117 // Returns the least common ancestor in the transform tree.
118 PassRefPtr<TransformPaintPropertyNode> leastCommonAncestor(PassRefPtr<Transf ormPaintPropertyNode>, PassRefPtr<TransformPaintPropertyNode>);
94 119
95 friend class GeometryMapperTest; 120 friend class GeometryMapperTest;
96 121
97 HashMap<const TransformPaintPropertyNode*, std::unique_ptr<PrecomputedDataFo rAncestor>> m_data; 122 HashMap<const TransformPaintPropertyNode*, std::unique_ptr<PrecomputedDataFo rAncestor>> m_data;
98 123
124 const TransformationMatrix m_identity;
125
99 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); 126 DISALLOW_COPY_AND_ASSIGN(GeometryMapper);
100 }; 127 };
101 128
102 } // namespace blink 129 } // namespace blink
103 130
104 #endif // GeometryMapper_h 131 #endif // GeometryMapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698