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

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

Issue 2793993003: Make GeometryMapper fully static (Closed)
Patch Set: Created 3 years, 8 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/graphics/paint/FloatClipRect.h" 8 #include "platform/graphics/paint/FloatClipRect.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 10 matching lines...) Expand all
21 // corresponding to the new state. 21 // corresponding to the new state.
22 // 22 //
23 // ** WARNING** Callers to the methods below may not assume that any const 23 // ** WARNING** Callers to the methods below may not assume that any const
24 // references returned remain const across multiple calls into GeometryMapper. 24 // references returned remain const across multiple calls into GeometryMapper.
25 // If needed, callers must store local copies of the return values. 25 // If needed, callers must store local copies of the return values.
26 // 26 //
27 // Design document: http://bit.ly/28P4FDA 27 // Design document: http://bit.ly/28P4FDA
28 // 28 //
29 // TODO(chrishtr): take effect tree into account. 29 // TODO(chrishtr): take effect tree into account.
30 class PLATFORM_EXPORT GeometryMapper { 30 class PLATFORM_EXPORT GeometryMapper {
31 USING_FAST_MALLOC(GeometryMapper); 31 USING_FAST_MALLOC(GeometryMapper);
haraken 2017/04/03 23:55:27 You can remove this and instead use STATIC_ONLY :)
chrishtr 2017/04/03 23:57:17 Good catch - patch coming.
32 32
33 public: 33 public:
34 static std::unique_ptr<GeometryMapper> create() {
35 return WTF::wrapUnique(new GeometryMapper());
36 }
37
38 // The runtime of m calls among localToAncestorVisualRect, localToAncestorRect 34 // The runtime of m calls among localToAncestorVisualRect, localToAncestorRect
39 // or ancestorToLocalRect with the same |ancestorState| parameter is 35 // or ancestorToLocalRect with the same |ancestorState| parameter is
40 // guaranteed to be O(n + m), where n is the number of transform and clip 36 // guaranteed to be O(n + m), where n is the number of transform and clip
41 // nodes in their respective property trees. 37 // nodes in their respective property trees.
42 38
43 // If the clips and transforms of |sourceState| are equal to or descendants of 39 // If the clips and transforms of |sourceState| are equal to or descendants of
44 // those of |destinationState|, returns the same value as 40 // those of |destinationState|, returns the same value as
45 // localToAncestorVisualRect. Otherwise, maps the input rect to the 41 // localToAncestorVisualRect. Otherwise, maps the input rect to the
46 // transform state which is the lowest common ancestor of 42 // transform state which is the lowest common ancestor of
47 // |sourceState.transform| and |destinationState.transform|, then multiplies 43 // |sourceState.transform| and |destinationState.transform|, then multiplies
48 // it by the the inverse transform mapping from the lowest common ancestor to 44 // it by the the inverse transform mapping from the lowest common ancestor to
49 // |destinationState.transform|. 45 // |destinationState.transform|.
50 // 46 //
51 // DCHECK fails if the clip of |destinationState| is not an ancestor of the 47 // DCHECK fails if the clip of |destinationState| is not an ancestor of the
52 // clip of |sourceState|, or the inverse transform is not invertible. 48 // clip of |sourceState|, or the inverse transform is not invertible.
53 // 49 //
54 // |mappingRect| is both input and output. 50 // |mappingRect| is both input and output.
55 void sourceToDestinationVisualRect(const PropertyTreeState& sourceState, 51 static void sourceToDestinationVisualRect(
56 const PropertyTreeState& destinationState, 52 const PropertyTreeState& sourceState,
57 FloatRect& mappingRect); 53 const PropertyTreeState& destinationState,
54 FloatRect& mappingRect);
58 55
59 // Same as sourceToDestinationVisualRect() except that only transforms are 56 // Same as sourceToDestinationVisualRect() except that only transforms are
60 // applied. 57 // applied.
61 // 58 //
62 // |mappingRect| is both input and output. 59 // |mappingRect| is both input and output.
63 void sourceToDestinationRect( 60 static void sourceToDestinationRect(
64 const TransformPaintPropertyNode* sourceTransformNode, 61 const TransformPaintPropertyNode* sourceTransformNode,
65 const TransformPaintPropertyNode* destinationTransformNode, 62 const TransformPaintPropertyNode* destinationTransformNode,
66 FloatRect& mappingRect); 63 FloatRect& mappingRect);
67 64
68 // Maps from a rect in |localTransformSpace| to its visual rect in 65 // Maps from a rect in |localTransformSpace| to its visual rect in
69 // |ancestorState|. This is computed by multiplying the rect by its combined 66 // |ancestorState|. This is computed by multiplying the rect by its combined
70 // transform between |localTransformSpace| and |ancestorSpace|, then 67 // transform between |localTransformSpace| and |ancestorSpace|, then
71 // flattening into 2D space, then intersecting by the "clip visual rect" for 68 // flattening into 2D space, then intersecting by the "clip visual rect" for
72 // |localTransformState|'s clips. See above for the definition of "clip visual 69 // |localTransformState|'s clips. See above for the definition of "clip visual
73 // rect". 70 // rect".
74 // 71 //
75 // Note that the clip of |ancestorState| is *not* applied. 72 // Note that the clip of |ancestorState| is *not* applied.
76 // 73 //
77 // DCHECK fails if any of the paint property tree nodes in 74 // DCHECK fails if any of the paint property tree nodes in
78 // |localTransformState| are not equal to or a descendant of that in 75 // |localTransformState| are not equal to or a descendant of that in
79 // |ancestorState|. 76 // |ancestorState|.
80 // 77 //
81 // |mappingRect| is both input and output. 78 // |mappingRect| is both input and output.
82 void localToAncestorVisualRect(const PropertyTreeState& localTransformState, 79 static void localToAncestorVisualRect(
83 const PropertyTreeState& ancestorState, 80 const PropertyTreeState& localTransformState,
84 FloatRect& mappingRect); 81 const PropertyTreeState& ancestorState,
82 FloatRect& mappingRect);
85 83
86 // Maps from a rect in |localTransformNode| space to its transformed rect in 84 // Maps from a rect in |localTransformNode| space to its transformed rect in
87 // |ancestorTransformNode| space. This is computed by multiplying the rect by 85 // |ancestorTransformNode| space. This is computed by multiplying the rect by
88 // the combined transform between |localTransformNode| and 86 // the combined transform between |localTransformNode| and
89 // |ancestorTransformNode|, then flattening into 2D space. 87 // |ancestorTransformNode|, then flattening into 2D space.
90 // 88 //
91 // DCHECK fails if |localTransformNode| is not equal to or a descendant of 89 // DCHECK fails if |localTransformNode| is not equal to or a descendant of
92 // |ancestorTransformNode|. 90 // |ancestorTransformNode|.
93 // 91 //
94 //|mappingRect| is both input and output. 92 //|mappingRect| is both input and output.
95 void localToAncestorRect( 93 static void localToAncestorRect(
96 const TransformPaintPropertyNode* localTransformNode, 94 const TransformPaintPropertyNode* localTransformNode,
97 const TransformPaintPropertyNode* ancestorTransformNode, 95 const TransformPaintPropertyNode* ancestorTransformNode,
98 FloatRect& mappingRect); 96 FloatRect& mappingRect);
99 97
100 // Maps from a rect in |ancestorTransformNode| space to its transformed rect 98 // Maps from a rect in |ancestorTransformNode| space to its transformed rect
101 // in |localTransformNode| space. This is computed by multiplying the rect by 99 // in |localTransformNode| space. This is computed by multiplying the rect by
102 // the inverse combined transform between |localTransformNode| and 100 // the inverse combined transform between |localTransformNode| and
103 // |ancestorTransformNode|, if the transform is invertible. 101 // |ancestorTransformNode|, if the transform is invertible.
104 // 102 //
105 // DCHECK fails if the combined transform is not invertible, or 103 // DCHECK fails if the combined transform is not invertible, or
106 // |localTransformNode| is not equal to or a descendant of 104 // |localTransformNode| is not equal to or a descendant of
107 // |ancestorTransformNode|. 105 // |ancestorTransformNode|.
108 // 106 //
109 // |mappingRect| is both input and output. 107 // |mappingRect| is both input and output.
110 void ancestorToLocalRect( 108 static void ancestorToLocalRect(
111 const TransformPaintPropertyNode* ancestorTransformNode, 109 const TransformPaintPropertyNode* ancestorTransformNode,
112 const TransformPaintPropertyNode* localTransformNode, 110 const TransformPaintPropertyNode* localTransformNode,
113 FloatRect& mappingRect); 111 FloatRect& mappingRect);
114 112
115 // Returns the matrix used in |LocalToAncestorRect|. DCHECK fails iff 113 // Returns the matrix used in |LocalToAncestorRect|. DCHECK fails iff
116 // |localTransformNode| is not equal to or a descendant of 114 // |localTransformNode| is not equal to or a descendant of
117 // |ancestorTransformNode|. 115 // |ancestorTransformNode|.
118 // This matrix may not be flattened. Since GeometryMapper only supports 116 // This matrix may not be flattened. Since GeometryMapper only supports
119 // flattened ancestor spaces, the returned matrix must be flattened to have 117 // flattened ancestor spaces, the returned matrix must be flattened to have
120 // the correct semantics (calling mapRect() on it implicitly applies 118 // the correct semantics (calling mapRect() on it implicitly applies
121 // flattening to the input; flattenTo2d() does it explicitly to tme matrix). 119 // flattening to the input; flattenTo2d() does it explicitly to tme matrix).
122 const TransformationMatrix& localToAncestorMatrix( 120 static const TransformationMatrix& localToAncestorMatrix(
123 const TransformPaintPropertyNode* localTransformNode, 121 const TransformPaintPropertyNode* localTransformNode,
124 const TransformPaintPropertyNode* ancestorTransformNode); 122 const TransformPaintPropertyNode* ancestorTransformNode);
125 123
126 // Returns the "clip visual rect" between |localTransformState| and 124 // Returns the "clip visual rect" between |localTransformState| and
127 // |ancestorState|. See above for the definition of "clip visual rect". 125 // |ancestorState|. See above for the definition of "clip visual rect".
128 FloatClipRect localToAncestorClipRect( 126 static FloatClipRect localToAncestorClipRect(
129 const PropertyTreeState& localTransformState, 127 const PropertyTreeState& localTransformState,
130 const PropertyTreeState& ancestorState); 128 const PropertyTreeState& ancestorState);
131 129
132 // Like localToAncestorClipRect, except it can handle destination transform 130 // Like localToAncestorClipRect, except it can handle destination transform
133 // spaces which are not direct ancestors of the source transform space. 131 // spaces which are not direct ancestors of the source transform space.
134 const FloatClipRect& sourceToDestinationClipRect( 132 static const FloatClipRect& sourceToDestinationClipRect(
135 const PropertyTreeState& sourceState, 133 const PropertyTreeState& sourceState,
136 const PropertyTreeState& destinationState); 134 const PropertyTreeState& destinationState);
137 135
138 // Returns the lowest common ancestor in the paint property tree. 136 // Returns the lowest common ancestor in the paint property tree.
139 template <typename NodeType> 137 template <typename NodeType>
140 static PLATFORM_EXPORT const NodeType* lowestCommonAncestor(const NodeType*, 138 static PLATFORM_EXPORT const NodeType* lowestCommonAncestor(const NodeType*,
141 const NodeType*); 139 const NodeType*);
142 140
143 void clearCache(); 141 static void clearCache();
144
145 protected:
146 GeometryMapper() {}
147 142
148 private: 143 private:
149 // The internal methods do the same things as their public counterparts, but 144 // The internal methods do the same things as their public counterparts, but
150 // take an extra |success| parameter which indicates if the function is 145 // take an extra |success| parameter which indicates if the function is
151 // successful on return. See comments of the public functions for failure 146 // successful on return. See comments of the public functions for failure
152 // conditions. 147 // conditions.
153 148
154 void sourceToDestinationVisualRectInternal( 149 static void sourceToDestinationVisualRectInternal(
155 const PropertyTreeState& sourceState, 150 const PropertyTreeState& sourceState,
156 const PropertyTreeState& destinationState, 151 const PropertyTreeState& destinationState,
157 FloatRect& mappingRect, 152 FloatRect& mappingRect,
158 bool& success); 153 bool& success);
159 154
160 void localToAncestorVisualRectInternal( 155 static void localToAncestorVisualRectInternal(
161 const PropertyTreeState& localTransformState, 156 const PropertyTreeState& localTransformState,
162 const PropertyTreeState& ancestorState, 157 const PropertyTreeState& ancestorState,
163 FloatRect& mappingRect, 158 FloatRect& mappingRect,
164 bool& success); 159 bool& success);
165 160
166 void localToAncestorRectInternal( 161 static void localToAncestorRectInternal(
167 const TransformPaintPropertyNode* localTransformNode, 162 const TransformPaintPropertyNode* localTransformNode,
168 const TransformPaintPropertyNode* ancestorTransformNode, 163 const TransformPaintPropertyNode* ancestorTransformNode,
169 FloatRect&, 164 FloatRect&,
170 bool& success); 165 bool& success);
171 166
172 const TransformationMatrix& localToAncestorMatrixInternal( 167 static const TransformationMatrix& localToAncestorMatrixInternal(
173 const TransformPaintPropertyNode* localTransformNode, 168 const TransformPaintPropertyNode* localTransformNode,
174 const TransformPaintPropertyNode* ancestorTransformNode, 169 const TransformPaintPropertyNode* ancestorTransformNode,
175 bool& success); 170 bool& success);
176 171
177 const FloatClipRect& localToAncestorClipRectInternal( 172 static const FloatClipRect& localToAncestorClipRectInternal(
178 const ClipPaintPropertyNode* descendant, 173 const ClipPaintPropertyNode* descendant,
179 const ClipPaintPropertyNode* ancestorClip, 174 const ClipPaintPropertyNode* ancestorClip,
180 const TransformPaintPropertyNode* ancestorTransform, 175 const TransformPaintPropertyNode* ancestorTransform,
181 bool& success); 176 bool& success);
182 177
183 const FloatClipRect& sourceToDestinationClipRectInternal( 178 static const FloatClipRect& sourceToDestinationClipRectInternal(
184 const PropertyTreeState& sourceState, 179 const PropertyTreeState& sourceState,
185 const PropertyTreeState& destinationState, 180 const PropertyTreeState& destinationState,
186 bool& success); 181 bool& success);
187 182
188 void slowLocalToAncestorVisualRectWithEffects( 183 static void slowLocalToAncestorVisualRectWithEffects(
189 const PropertyTreeState& localState, 184 const PropertyTreeState& localState,
190 const PropertyTreeState& ancestorState, 185 const PropertyTreeState& ancestorState,
191 FloatRect& mappingRect, 186 FloatRect& mappingRect,
192 bool& success); 187 bool& success);
193 188
189 static const TransformationMatrix& identityMatrix();
190 static const FloatClipRect& infiniteClip();
191 static FloatClipRect& tempRect();
192
194 friend class GeometryMapperTest; 193 friend class GeometryMapperTest;
195 friend class PaintLayerClipperTest; 194 friend class PaintLayerClipperTest;
196 195
197 // These are used to represent various return values of the above
198 // methods.
199 const TransformationMatrix m_identity;
200 const FloatClipRect m_infiniteClip;
201 FloatClipRect m_tempRect;
202
203 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); 196 DISALLOW_COPY_AND_ASSIGN(GeometryMapper);
204 }; 197 };
205 198
206 } // namespace blink 199 } // namespace blink
207 200
208 #endif // GeometryMapper_h 201 #endif // GeometryMapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698