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