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

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

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

Powered by Google App Engine
This is Rietveld 408576698