| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 PaintInvalidationState_h | 5 #ifndef PaintInvalidationState_h |
| 6 #define PaintInvalidationState_h | 6 #define PaintInvalidationState_h |
| 7 | 7 |
| 8 #include "platform/geometry/LayoutRect.h" | 8 #include "platform/geometry/LayoutRect.h" |
| 9 #include "platform/transforms/AffineTransform.h" | 9 #include "platform/transforms/AffineTransform.h" |
| 10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // PaintInvalidationState is an optimization used during the paint | 26 // PaintInvalidationState is an optimization used during the paint |
| 27 // invalidation phase. | 27 // invalidation phase. |
| 28 // | 28 // |
| 29 // This class is extremely close to LayoutState so see the documentation | 29 // This class is extremely close to LayoutState so see the documentation |
| 30 // of LayoutState for the class existence and performance benefits. | 30 // of LayoutState for the class existence and performance benefits. |
| 31 // | 31 // |
| 32 // The main difference with LayoutState is that it was customized for the | 32 // The main difference with LayoutState is that it was customized for the |
| 33 // needs of the paint invalidation systems (keeping visual rectangles | 33 // needs of the paint invalidation systems (keeping visual rectangles |
| 34 // instead of layout specific information). | 34 // instead of layout specific information). |
| 35 // |
| 36 // See Source/core/paint/README.md ### PaintInvalidationState for more details. |
| 37 |
| 35 class PaintInvalidationState { | 38 class PaintInvalidationState { |
| 36 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 39 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 37 WTF_MAKE_NONCOPYABLE(PaintInvalidationState); | 40 WTF_MAKE_NONCOPYABLE(PaintInvalidationState); |
| 38 public: | 41 public: |
| 39 PaintInvalidationState(const PaintInvalidationState& parentState, const Layo
utObject&); | 42 PaintInvalidationState(const PaintInvalidationState& parentState, const Layo
utObject&); |
| 40 | 43 |
| 41 // TODO(wangxianzhu): This is temporary for positioned object whose paintInv
alidationContainer is different from | |
| 42 // the one we find during tree walk. Remove this after we fix the issue with
tree walk in DOM-order. | |
| 43 PaintInvalidationState(const PaintInvalidationState& parentState, const Layo
utBoxModelObject&, const LayoutBoxModelObject& paintInvalidationContainer); | |
| 44 | |
| 45 // For root LayoutView, or when sub-frame LayoutView's invalidateTreeIfNeede
d() is called directly from | 44 // For root LayoutView, or when sub-frame LayoutView's invalidateTreeIfNeede
d() is called directly from |
| 46 // FrameView::invalidateTreeIfNeededRecursive() instead of the owner LayoutP
art. | 45 // FrameView::invalidateTreeIfNeededRecursive() instead of the owner LayoutP
art. |
| 47 // TODO(wangxianzhu): Eliminate the latter case. | 46 // TODO(wangxianzhu): Eliminate the latter case. |
| 48 PaintInvalidationState(const LayoutView&, Vector<LayoutObject*>& pendingDela
yedPaintInvalidations); | 47 PaintInvalidationState(const LayoutView&, Vector<LayoutObject*>& pendingDela
yedPaintInvalidations); |
| 49 | 48 |
| 50 // When a PaintInvalidationState is constructed, it can be used to map point
s/rects in the object's | 49 // When a PaintInvalidationState is constructed, it can be used to map point
s/rects in the object's |
| 51 // local space (border box space for LayoutBoxes). After invalidation of the
current object, | 50 // local space (border box space for LayoutBoxes). After invalidation of the
current object, |
| 52 // before invalidation of the subtrees, this method must be called to apply
clip and scroll offset | 51 // before invalidation of the subtrees, this method must be called to apply
clip and scroll offset |
| 53 // etc. for creating child PaintInvalidationStates. | 52 // etc. for creating child PaintInvalidationStates. |
| 54 void updateForChildren(); | 53 void updateForChildren(); |
| 55 | 54 |
| 56 bool forcedSubtreeInvalidationWithinContainer() const { return m_forcedSubtr
eeInvalidationWithinContainer; } | 55 bool forcedSubtreeInvalidationWithinContainer() const { return m_forcedSubtr
eeInvalidationWithinContainer; } |
| 57 void setForceSubtreeInvalidationWithinContainer() { m_forcedSubtreeInvalidat
ionWithinContainer = true; } | 56 void setForceSubtreeInvalidationWithinContainer() { m_forcedSubtreeInvalidat
ionWithinContainer = true; } |
| 58 | 57 |
| 59 bool forcedSubtreeInvalidationRectUpdateWithinContainer() const { return m_f
orcedSubtreeInvalidationRectUpdateWithinContainer; } | 58 bool forcedSubtreeInvalidationRectUpdateWithinContainer() const { return m_f
orcedSubtreeInvalidationRectUpdateWithinContainer; } |
| 60 void setForceSubtreeInvalidationRectUpdateWithinContainer() { m_forcedSubtre
eInvalidationRectUpdateWithinContainer = true; } | 59 void setForceSubtreeInvalidationRectUpdateWithinContainer() { m_forcedSubtre
eInvalidationRectUpdateWithinContainer = true; } |
| 61 | 60 |
| 62 const LayoutBoxModelObject& paintInvalidationContainer() const { return m_pa
intInvalidationContainer; } | 61 const LayoutBoxModelObject& paintInvalidationContainer() const { return *m_p
aintInvalidationContainer; } |
| 63 | 62 |
| 64 // Computes the position of the current object ((0,0) in the space of the ob
ject) | 63 // Computes the position of the current object ((0,0) in the space of the ob
ject) |
| 65 // in the space of paint invalidation backing. | 64 // in the space of paint invalidation backing. |
| 66 LayoutPoint computePositionFromPaintInvalidationBacking() const; | 65 LayoutPoint computePositionFromPaintInvalidationBacking() const; |
| 67 | 66 |
| 68 // Returns the rect bounds needed to invalidate paint of this object, | 67 // Returns the rect bounds needed to invalidate paint of this object, |
| 69 // in the space of paint invalidation backing. | 68 // in the space of paint invalidation backing. |
| 70 LayoutRect computePaintInvalidationRectInBacking() const; | 69 LayoutRect computePaintInvalidationRectInBacking() const; |
| 71 | 70 |
| 72 void mapLocalRectToPaintInvalidationBacking(LayoutRect&) const; | 71 void mapLocalRectToPaintInvalidationBacking(LayoutRect&) const; |
| 73 | 72 |
| 74 // Records |obj| as needing paint invalidation on the next frame. See the de
finition of PaintInvalidationDelayedFull for more details. | 73 // Records |obj| as needing paint invalidation on the next frame. See the de
finition of PaintInvalidationDelayedFull for more details. |
| 75 void pushDelayedPaintInvalidationTarget(LayoutObject& obj) const { m_pending
DelayedPaintInvalidations.append(&obj); } | 74 void pushDelayedPaintInvalidationTarget(LayoutObject& obj) const { m_pending
DelayedPaintInvalidations.append(&obj); } |
| 76 Vector<LayoutObject*>& pendingDelayedPaintInvalidationTargets() const { retu
rn m_pendingDelayedPaintInvalidations; } | 75 Vector<LayoutObject*>& pendingDelayedPaintInvalidationTargets() const { retu
rn m_pendingDelayedPaintInvalidations; } |
| 77 | 76 |
| 78 PaintLayer& enclosingSelfPaintingLayer(const LayoutObject&) const; | 77 PaintLayer& enclosingSelfPaintingLayer(const LayoutObject&) const; |
| 79 | 78 |
| 80 #if ENABLE(ASSERT) | 79 #if ENABLE(ASSERT) |
| 81 const LayoutObject& currentObject() const { return m_currentObject; } | 80 const LayoutObject& currentObject() const { return m_currentObject; } |
| 82 #endif | 81 #endif |
| 83 | 82 |
| 84 private: | 83 private: |
| 84 void updateForNormalChildren(); |
| 85 |
| 85 LayoutRect computePaintInvalidationRectInBackingForSVG() const; | 86 LayoutRect computePaintInvalidationRectInBackingForSVG() const; |
| 86 | 87 |
| 87 void addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect); | 88 void addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect); |
| 88 | 89 |
| 89 friend class ForceHorriblySlowRectMapping; | 90 friend class ForceHorriblySlowRectMapping; |
| 90 | 91 |
| 91 const LayoutObject& m_currentObject; | 92 const LayoutObject& m_currentObject; |
| 92 | 93 |
| 93 bool m_clipped; | |
| 94 mutable bool m_cachedOffsetsEnabled; | |
| 95 bool m_forcedSubtreeInvalidationWithinContainer; | 94 bool m_forcedSubtreeInvalidationWithinContainer; |
| 96 bool m_forcedSubtreeInvalidationRectUpdateWithinContainer; | 95 bool m_forcedSubtreeInvalidationRectUpdateWithinContainer; |
| 97 | 96 |
| 97 bool m_clipped; |
| 98 bool m_clippedForAbsolutePosition; |
| 99 |
| 100 // Clip rect from paintInvalidationContainer if m_cachedOffsetsEnabled is tr
ue. |
| 98 LayoutRect m_clipRect; | 101 LayoutRect m_clipRect; |
| 102 LayoutRect m_clipRectForAbsolutePosition; |
| 99 | 103 |
| 100 // x/y offset from paint invalidation container. Includes relative positioni
ng and scroll offsets. | 104 // x/y offset from the paintInvalidationContainer if m_cachedOffsetsEnabled
is true. |
| 105 // It includes relative positioning and scroll offsets. |
| 101 LayoutSize m_paintOffset; | 106 LayoutSize m_paintOffset; |
| 107 LayoutSize m_paintOffsetForAbsolutePosition; |
| 102 | 108 |
| 103 // The current paint invalidation container. | 109 // Whether m_paintOffset[XXX] and m_clipRect[XXX] are valid and can be used |
| 104 // | 110 // to map a rect from space of the current object to space of paintInvalidat
ionContainer. |
| 111 mutable bool m_cachedOffsetsEnabled; |
| 112 bool m_cachedOffsetsForAbsolutePositionEnabled; |
| 113 |
| 114 // The following two fields are never null. Declare them as pointers because
we need some |
| 115 // logic to initialize them in the body of the constructor. |
| 116 |
| 117 // The current paint invalidation container for normal flow objects. |
| 105 // It is the enclosing composited object. | 118 // It is the enclosing composited object. |
| 106 const LayoutBoxModelObject& m_paintInvalidationContainer; | 119 const LayoutBoxModelObject* m_paintInvalidationContainer; |
| 120 |
| 121 // The current paint invalidation container for stacked contents (stacking c
ontexts or positioned objects). |
| 122 // It is the nearest ancestor composited object which establishes a stacking
context. |
| 123 // See Source/core/paint/README.md ### PaintInvalidationState for details on
how stacked contents' |
| 124 // paint invalidation containers differ. |
| 125 const LayoutBoxModelObject* m_paintInvalidationContainerForStackedContents; |
| 126 |
| 127 const LayoutObject& m_containerForAbsolutePosition; |
| 107 | 128 |
| 108 // Transform from the initial viewport coordinate system of an outermost | 129 // Transform from the initial viewport coordinate system of an outermost |
| 109 // SVG root to the userspace _before_ the relevant element. Combining this | 130 // SVG root to the userspace _before_ the relevant element. Combining this |
| 110 // with |m_paintOffset| yields the "final" offset. | 131 // with |m_paintOffset| yields the "final" offset. |
| 111 AffineTransform m_svgTransform; | 132 AffineTransform m_svgTransform; |
| 112 | 133 |
| 113 Vector<LayoutObject*>& m_pendingDelayedPaintInvalidations; | 134 Vector<LayoutObject*>& m_pendingDelayedPaintInvalidations; |
| 114 | 135 |
| 115 PaintLayer& m_enclosingSelfPaintingLayer; | 136 PaintLayer& m_enclosingSelfPaintingLayer; |
| 116 | 137 |
| 117 #if ENABLE(ASSERT) | 138 #if ENABLE(ASSERT) |
| 118 bool m_didUpdateForChildren; | 139 bool m_didUpdateForChildren; |
| 119 #endif | 140 #endif |
| 120 }; | 141 }; |
| 121 | 142 |
| 122 // Suspends the PaintInvalidationState cached offset and clipRect optimization.
Used under transforms | |
| 123 // that cannot be represented by PaintInvalidationState (common in SVG) and when
paint invalidation | |
| 124 // containers don't follow the common tree-walk algorithm (e.g. when an absolute
positioned descendant | |
| 125 // is nested under a relatively positioned inline-block child). | |
| 126 class ForceHorriblySlowRectMapping { | |
| 127 STACK_ALLOCATED(); | |
| 128 WTF_MAKE_NONCOPYABLE(ForceHorriblySlowRectMapping); | |
| 129 public: | |
| 130 ForceHorriblySlowRectMapping(const PaintInvalidationState* paintInvalidation
State) | |
| 131 : m_paintInvalidationState(paintInvalidationState) | |
| 132 , m_didDisable(m_paintInvalidationState && m_paintInvalidationState->m_c
achedOffsetsEnabled) | |
| 133 { | |
| 134 if (m_paintInvalidationState) | |
| 135 m_paintInvalidationState->m_cachedOffsetsEnabled = false; | |
| 136 } | |
| 137 | |
| 138 ~ForceHorriblySlowRectMapping() | |
| 139 { | |
| 140 if (m_didDisable) | |
| 141 m_paintInvalidationState->m_cachedOffsetsEnabled = true; | |
| 142 } | |
| 143 private: | |
| 144 const PaintInvalidationState* m_paintInvalidationState; | |
| 145 bool m_didDisable; | |
| 146 }; | |
| 147 | |
| 148 } // namespace blink | 143 } // namespace blink |
| 149 | 144 |
| 150 #endif // PaintInvalidationState_h | 145 #endif // PaintInvalidationState_h |
| OLD | NEW |