Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GeometryMapper_h | |
| 6 #define GeometryMapper_h | |
| 7 | |
| 8 #include "platform/geometry/FloatRect.h" | |
| 9 #include "platform/graphics/paint/PropertyTreeState.h" | |
| 10 #include "platform/transforms/TransformationMatrix.h" | |
| 11 #include "wtf/HashMap.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 struct PrecomputedDataForAncestor { | |
| 16 // Maps from a transform node that is a descendant of the ancestor to the co mbined | |
| 17 // transform between the descendant's and the ancestor's coordinate space. | |
| 18 HashMap<const TransformPaintPropertyNode*, TransformationMatrix> toAncestorT ransforms; | |
| 19 | |
| 20 // Maps from a descendant clip node to its equivalent "clip visual rect" in the space of the ancestor. | |
| 21 // The clip visual rect is defined as the intersection of all clips between the descendant | |
| 22 // and the ancestor (*not* including the ancestor) in the clip tree, individ ually transformed from their | |
| 23 // localTransformSpace into the ancestor's localTransformSpace. | |
| 24 HashMap<const ClipPaintPropertyNode*, FloatRect> toAncestorClipRects; | |
| 25 | |
| 26 static std::unique_ptr<PrecomputedDataForAncestor> create() | |
| 27 { | |
| 28 return wrapUnique(new PrecomputedDataForAncestor()); | |
| 29 } | |
| 30 }; | |
| 31 | |
| 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, | |
| 34 // and running times. | |
| 35 // | |
| 36 // Design document: http://bit.ly/28P4FDA | |
| 37 // | |
| 38 // TODO(chrishtr): take effect and scroll trees into account. | |
| 39 class PLATFORM_EXPORT GeometryMapper { | |
| 40 public: | |
| 41 GeometryMapper() {} | |
| 42 | |
| 43 // The runtime of m calls among LocalToVisualeRectInAncestorSpace, LocalToAn cestorRect or AncestorToLocalRect | |
|
wkorman
2016/06/23 00:41:10
nit: typo 'e' after 'Visual'
chrishtr
2016/06/23 15:51:18
Done.
| |
| 44 // 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. | |
| 46 | |
| 47 // 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|, | |
| 49 // 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". | |
| 51 // | |
| 52 // Note that the clip of |ancestorState| is *not* applied. | |
| 53 // | |
| 54 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal | |
| 55 // to or a descendant of that in |ancestorState|. | |
| 56 FloatRect LocalToVisualRectInAncestorSpace(const FloatRect&, | |
| 57 const PropertyTreeState& localTransformState, | |
| 58 const PropertyTreeState& ancestorState); | |
| 59 | |
| 60 // 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|, | |
| 62 // then flattening into 2D space. | |
| 63 // | |
| 64 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal | |
| 65 // to or a descendant of that in |ancestorState|. | |
| 66 FloatRect LocalToAncestorRect(const FloatRect&, | |
| 67 const PropertyTreeState& localTransformState, | |
| 68 const PropertyTreeState& ancestorState); | |
| 69 | |
| 70 // 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|, | |
| 72 // if the transform is invertible. If is invertible, also sets |*success| to true. Otherwise sets |*success| to false. | |
| 73 // | |
| 74 // It is an error to call this method if any of the paint property tree node s in |localTransformState| are not equal | |
| 75 // to or a descendant of that in |ancestorState|. | |
| 76 FloatRect AncestorToLocalRect(const FloatRect&, | |
| 77 const PropertyTreeState& localTransformState, | |
| 78 const PropertyTreeState& ancestorState, bool* success); | |
| 79 | |
| 80 private: | |
| 81 // Returns the matrix used in |LocalToAncestorRect|. | |
| 82 const TransformationMatrix& LocalToAncestorMatrix( | |
| 83 const TransformPaintPropertyNode* localTransformState, | |
| 84 const PropertyTreeState& ancestorState); | |
| 85 | |
| 86 // Returns the "clip visual rect" between |localTransformState| and |ancesto rState|. See above for the definition | |
| 87 // of "clip visual rect". | |
| 88 const FloatRect& LocalToAncestorClipRect( | |
| 89 const PropertyTreeState& localTransformState, | |
| 90 const PropertyTreeState& ancestorState); | |
| 91 | |
| 92 // Returns the precomputed data if already set, or adds and memoizes a new P recomputedDataForAncestor otherwise. | |
| 93 PrecomputedDataForAncestor& GetPrecomputedDataForAncestor(const PropertyTree State&); | |
| 94 | |
| 95 friend class GeometryMapperTest; | |
| 96 | |
| 97 HashMap<const TransformPaintPropertyNode*, std::unique_ptr<PrecomputedDataFo rAncestor>> m_data; | |
| 98 }; | |
| 99 | |
| 100 } // namespace blink | |
| 101 | |
| 102 #endif // GeometryMapper_h | |
| OLD | NEW |