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

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

Issue 2385123003: Rewrap comments to 80 columns in Source/platform/graphics/paint/. (Closed)
Patch Set: Resync Created 4 years, 2 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"
11 #include "wtf/HashMap.h" 11 #include "wtf/HashMap.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 struct PrecomputedDataForAncestor { 15 struct PrecomputedDataForAncestor {
16 // Maps from a transform node that is a descendant of the ancestor to the comb ined 16 // Maps from a transform node that is a descendant of the ancestor to the
17 // transform between the descendant's and the ancestor's coordinate space. 17 // combined transform between the descendant's and the ancestor's coordinate
18 // space.
18 HashMap<const TransformPaintPropertyNode*, TransformationMatrix> 19 HashMap<const TransformPaintPropertyNode*, TransformationMatrix>
19 toAncestorTransforms; 20 toAncestorTransforms;
20 21
21 // Maps from a descendant clip node to its equivalent "clip visual rect" in th e space of the ancestor. 22 // Maps from a descendant clip node to its equivalent "clip visual rect" in
22 // The clip visual rect is defined as the intersection of all clips between th e descendant 23 // the space of the ancestor. The clip visual rect is defined as the
23 // and the ancestor (*not* including the ancestor) in the clip tree, individua lly transformed from their 24 // intersection of all clips between the descendant and the ancestor (*not*
24 // localTransformSpace into the ancestor's localTransformSpace. 25 // including the ancestor) in the clip tree, individually transformed from
26 // their localTransformSpace into the ancestor's localTransformSpace.
25 HashMap<const ClipPaintPropertyNode*, FloatRect> toAncestorClipRects; 27 HashMap<const ClipPaintPropertyNode*, FloatRect> toAncestorClipRects;
26 28
27 static std::unique_ptr<PrecomputedDataForAncestor> create() { 29 static std::unique_ptr<PrecomputedDataForAncestor> create() {
28 return wrapUnique(new PrecomputedDataForAncestor()); 30 return wrapUnique(new PrecomputedDataForAncestor());
29 } 31 }
30 }; 32 };
31 33
32 // GeometryMapper is a helper class for fast computations of transformed and vis ual rects in 34 // GeometryMapper is a helper class for fast computations of transformed and
33 // different PropertyTreeStates. The design document has a number of details on use cases, 35 // visual rects in different PropertyTreeStates. The design document has a
34 // algorithmic definitions, and running times. 36 // number of details on use cases, algorithmic definitions, and running times.
35 // 37 //
36 // NOTE: A GeometryMapper object is only valid for property trees that do not ch ange. If any 38 // NOTE: A GeometryMapper object is only valid for property trees that do not
37 // mutation occurs, a new GeometryMapper object must be allocated corresponding to the new state. 39 // change. If any mutation occurs, a new GeometryMapper object must be allocated
40 // corresponding to the new state.
38 // 41 //
39 // Design document: http://bit.ly/28P4FDA 42 // Design document: http://bit.ly/28P4FDA
40 // 43 //
41 // TODO(chrishtr): take effect tree into account. 44 // TODO(chrishtr): take effect tree into account.
42 class PLATFORM_EXPORT GeometryMapper { 45 class PLATFORM_EXPORT GeometryMapper {
43 public: 46 public:
44 GeometryMapper() {} 47 GeometryMapper() {}
45 // The runtime of m calls among localToVisualRectInAncestorSpace, localToAnces torRect or ancestorToLocalRect 48 // The runtime of m calls among localToVisualRectInAncestorSpace,
46 // with the same |ancestorState| parameter is guaranteed to be O(n + m), wher e n is the number of transform and clip 49 // localToAncestorRect or ancestorToLocalRect with the same |ancestorState|
47 // nodes in their respective property trees. 50 // parameter is guaranteed to be O(n + m), where n is the number of transform
51 // and clip nodes in their respective property trees.
48 52
49 // If the clips and transforms of |sourceState| are equal to or descendants of those of |destinationState|, returns 53 // If the clips and transforms of |sourceState| are equal to or descendants of
50 // the same value as localToVisualRectInAncestorSpace. Otherwise, maps the inp ut rect to the transform state which is 54 // those of |destinationState|, returns the same value as
51 // the least common ancestor of |sourceState.transform| and |destinationState. transform|, then multiplies it by 55 // localToVisualRectInAncestorSpace. Otherwise, maps the input rect to the
52 // the the inverse transform mapping from the least common ancestor to |destin ationState.transform|. 56 // transform state which is the least common ancestor of
57 // |sourceState.transform| and |destinationState.transform|, then multiplies
58 // it by the the inverse transform mapping from the least common ancestor to
59 // |destinationState.transform|.
53 // 60 //
54 // If that inverse transform is not invertible, sets |success| to false and re turns the input rect. Otherwise, sets 61 // Sets |success| to whether that inverse transform is invertible. If it is
55 // |success| to true. 62 // not, returns the input rect.
56 FloatRect mapToVisualRectInDestinationSpace( 63 FloatRect mapToVisualRectInDestinationSpace(
57 const FloatRect&, 64 const FloatRect&,
58 const PropertyTreeState& sourceState, 65 const PropertyTreeState& sourceState,
59 const PropertyTreeState& destinationState, 66 const PropertyTreeState& destinationState,
60 bool& success); 67 bool& success);
61 68
62 // Same as mapToVisualRectInDestinationSpace() except that *no* clip is applie d. 69 // Same as mapToVisualRectInDestinationSpace() except that *no* clip is
70 // applied.
63 FloatRect mapRectToDestinationSpace(const FloatRect&, 71 FloatRect mapRectToDestinationSpace(const FloatRect&,
64 const PropertyTreeState& sourceState, 72 const PropertyTreeState& sourceState,
65 const PropertyTreeState& destinationState, 73 const PropertyTreeState& destinationState,
66 bool& success); 74 bool& success);
67 75
68 // Maps from a rect in |localTransformSpace| to its visual rect in |ancestorSt ate|. This is computed 76 // Maps from a rect in |localTransformSpace| to its visual rect in
69 // by multiplying the rect by its combined transform between |localTransformSp ace| and |ancestorSpace|, 77 // |ancestorState|. This is computed by multiplying the rect by its combined
70 // then flattening into 2D space, then intersecting by the "clip visual rect" for |localTransformState|'s clips. 78 // transform between |localTransformSpace| and |ancestorSpace|, then
71 // See above for the definition of "clip visual rect". 79 // flattening into 2D space, then intersecting by the "clip visual rect" for
80 // |localTransformState|'s clips. See above for the definition of "clip visual
81 // rect".
72 // 82 //
73 // Note that the clip of |ancestorState| is *not* applied. 83 // Note that the clip of |ancestorState| is *not* applied.
74 // 84 //
75 // If any of the paint property tree nodes in |localTransformState| are not eq ual 85 // If any of the paint property tree nodes in |localTransformState| are not
76 // to or a descendant of that in |ancestorState|, returns the passed-in rect a nd sets |success| to false. Otherwise, 86 // equal to or a descendant of that in |ancestorState|, returns the passed-in
77 // sets |success| to true. 87 // rect and sets |success| to false. Otherwise, sets |success| to true.
78 FloatRect localToVisualRectInAncestorSpace( 88 FloatRect localToVisualRectInAncestorSpace(
79 const FloatRect&, 89 const FloatRect&,
80 const PropertyTreeState& localTransformState, 90 const PropertyTreeState& localTransformState,
81 const PropertyTreeState& ancestorState, 91 const PropertyTreeState& ancestorState,
82 bool& success); 92 bool& success);
83 93
84 // Maps from a rect in |localTransformSpace| to its transformed rect in |ances torSpace|. This is computed 94 // Maps from a rect in |localTransformSpace| to its transformed rect in
85 // by multiplying the rect by the combined transform between |localTransformSt ate| and |ancestorState|, 95 // |ancestorSpace|. This is computed by multiplying the rect by the combined
86 // then flattening into 2D space. 96 // transform between |localTransformState| and |ancestorState|, then
97 // flattening into 2D space.
87 // 98 //
88 // If any of the paint property tree nodes in |localTransformState| are not eq ual 99 // If any of the paint property tree nodes in |localTransformState| are not
89 // to or a descendant of that in |ancestorState|, returns the passed-in rec an d sets |success| to false. Otherwise, 100 // equal to or a descendant of that in |ancestorState|, returns the passed-in
90 // sets |success| to true. 101 // rec and sets |success| to false. Otherwise, sets |success| to true.
91 //
92 // If any of the paint property tree nodes in |localTransformState| are not eq ual
93 // to or a descendant of that in |ancestorState|, returns the passed-in rect a nd sets |success| to false. Otherwise,
94 // sets |success| to true.
95 FloatRect localToAncestorRect(const FloatRect&, 102 FloatRect localToAncestorRect(const FloatRect&,
96 const PropertyTreeState& localTransformState, 103 const PropertyTreeState& localTransformState,
97 const PropertyTreeState& ancestorState, 104 const PropertyTreeState& ancestorState,
98 bool& success); 105 bool& success);
99 106
100 // Maps from a rect in |ancestorSpace| to its transformed rect in |localTransf ormSpace|. This is computed 107 // Maps from a rect in |ancestorSpace| to its transformed rect in
101 // by multiplying the rect by the inverse combined transform between |localTra nsformState| and |ancestorState|, 108 // |localTransformSpace|. This is computed by multiplying the rect by the
102 // if the transform is invertible. 109 // inverse combined transform between |localTransformState| and
110 // |ancestorState|, if the transform is invertible.
103 // 111 //
104 // If any of the paint property tree nodes in |localTransformState| are not eq ual 112 // If any of the paint property tree nodes in |localTransformState| are not
105 // to or a descendant of that in |ancestorState|, returns the passed-in rect a nd sets |success| to false. Otherwise, 113 // equal to or a descendant of that in |ancestorState|, returns the passed-in
106 // sets |success| to true. 114 // rect and sets |success| to false. Otherwise, sets |success| to true.
107 FloatRect ancestorToLocalRect(const FloatRect&, 115 FloatRect ancestorToLocalRect(const FloatRect&,
108 const PropertyTreeState& localTransformState, 116 const PropertyTreeState& localTransformState,
109 const PropertyTreeState& ancestorState, 117 const PropertyTreeState& ancestorState,
110 bool& success); 118 bool& success);
111 119
112 private: 120 private:
113 // Used by mapToVisualRectInDestinationSpace() after fast mapping (assuming de stination is an ancestor of source) failed. 121 // Used by mapToVisualRectInDestinationSpace() after fast mapping (assuming
122 // destination is an ancestor of source) failed.
114 FloatRect slowMapToVisualRectInDestinationSpace( 123 FloatRect slowMapToVisualRectInDestinationSpace(
115 const FloatRect&, 124 const FloatRect&,
116 const PropertyTreeState& sourceState, 125 const PropertyTreeState& sourceState,
117 const PropertyTreeState& destinationState, 126 const PropertyTreeState& destinationState,
118 bool& success); 127 bool& success);
119 128
120 // Used by mapRectToDestinationSpace() after fast mapping (assuming destinatio n is an ancestor of source) failed. 129 // Used by mapRectToDestinationSpace() after fast mapping (assuming
130 // destination is an ancestor of source) failed.
121 FloatRect slowMapRectToDestinationSpace( 131 FloatRect slowMapRectToDestinationSpace(
122 const FloatRect&, 132 const FloatRect&,
123 const PropertyTreeState& sourceState, 133 const PropertyTreeState& sourceState,
124 const PropertyTreeState& destinationState, 134 const PropertyTreeState& destinationState,
125 bool& success); 135 bool& success);
126 136
127 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to failse iff |localTransformNode| is not 137 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to false
128 // equal to or a descendant of |ancestorState.transform|. 138 // iff |localTransformNode| is not equal to or a descendant of
139 // |ancestorState.transform|.
129 const TransformationMatrix& localToAncestorMatrix( 140 const TransformationMatrix& localToAncestorMatrix(
130 const TransformPaintPropertyNode* localTransformNode, 141 const TransformPaintPropertyNode* localTransformNode,
131 const PropertyTreeState& ancestorState, 142 const PropertyTreeState& ancestorState,
132 bool& success); 143 bool& success);
133 144
134 // Returns the "clip visual rect" between |localTransformState| and |ancestorS tate|. See above for the definition 145 // Returns the "clip visual rect" between |localTransformState| and
135 // of "clip visual rect". 146 // |ancestorState|. See above for the definition of "clip visual rect".
136 FloatRect localToAncestorClipRect( 147 FloatRect localToAncestorClipRect(
137 const PropertyTreeState& localTransformState, 148 const PropertyTreeState& localTransformState,
138 const PropertyTreeState& ancestorState, 149 const PropertyTreeState& ancestorState,
139 bool& success); 150 bool& success);
140 151
141 // Returns the precomputed data if already set, or adds and memoizes a new Pre computedDataForAncestor otherwise. 152 // Returns the precomputed data if already set, or adds and memoizes a new
153 // PrecomputedDataForAncestor otherwise.
142 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( 154 PrecomputedDataForAncestor& getPrecomputedDataForAncestor(
143 const PropertyTreeState&); 155 const PropertyTreeState&);
144 156
145 // Returns the least common ancestor in the transform tree. 157 // Returns the least common ancestor in the transform tree.
146 static const TransformPaintPropertyNode* leastCommonAncestor( 158 static const TransformPaintPropertyNode* leastCommonAncestor(
147 const TransformPaintPropertyNode*, 159 const TransformPaintPropertyNode*,
148 const TransformPaintPropertyNode*); 160 const TransformPaintPropertyNode*);
149 161
150 friend class GeometryMapperTest; 162 friend class GeometryMapperTest;
151 163
152 HashMap<const TransformPaintPropertyNode*, 164 HashMap<const TransformPaintPropertyNode*,
153 std::unique_ptr<PrecomputedDataForAncestor>> 165 std::unique_ptr<PrecomputedDataForAncestor>>
154 m_data; 166 m_data;
155 167
156 const TransformationMatrix m_identity; 168 const TransformationMatrix m_identity;
157 169
158 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); 170 DISALLOW_COPY_AND_ASSIGN(GeometryMapper);
159 }; 171 };
160 172
161 } // namespace blink 173 } // namespace blink
162 174
163 #endif // GeometryMapper_h 175 #endif // GeometryMapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698