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 13 matching lines...) Expand all Loading... |
24 // This class is extremely close to LayoutState so see the documentation | 24 // This class is extremely close to LayoutState so see the documentation |
25 // of LayoutState for the class existence and performance benefits. | 25 // of LayoutState for the class existence and performance benefits. |
26 // | 26 // |
27 // The main difference with LayoutState is that it was customized for the | 27 // The main difference with LayoutState is that it was customized for the |
28 // needs of the paint invalidation systems (keeping visual rectangles | 28 // needs of the paint invalidation systems (keeping visual rectangles |
29 // instead of layout specific information). | 29 // instead of layout specific information). |
30 class PaintInvalidationState { | 30 class PaintInvalidationState { |
31 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 31 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
32 WTF_MAKE_NONCOPYABLE(PaintInvalidationState); | 32 WTF_MAKE_NONCOPYABLE(PaintInvalidationState); |
33 public: | 33 public: |
34 PaintInvalidationState(PaintInvalidationState& next, LayoutBoxModelObject& l
ayoutObject, const LayoutBoxModelObject& paintInvalidationContainer); | 34 PaintInvalidationState(const PaintInvalidationState& parentState, const Layo
utObject&); |
35 PaintInvalidationState(PaintInvalidationState& next, const LayoutSVGModelObj
ect& layoutObject); | |
36 | 35 |
| 36 // TODO(wangxianzhu): This is temporary for positioned object whose paintInv
alidationContainer is different from |
| 37 // the one we find during tree walk. Remove this after we fix the issue with
tree walk in DOM-order. |
| 38 PaintInvalidationState(const PaintInvalidationState& parentState, const Layo
utBoxModelObject&, const LayoutBoxModelObject& paintInvalidationContainer); |
| 39 |
| 40 // For root LayoutView. |
37 PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>&
pendingDelayedPaintInvalidations) | 41 PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>&
pendingDelayedPaintInvalidations) |
38 : PaintInvalidationState(layoutView, pendingDelayedPaintInvalidations, n
ullptr) { } | 42 : PaintInvalidationState(layoutView, pendingDelayedPaintInvalidations, n
ullptr) { } |
39 PaintInvalidationState(const LayoutView& layoutView, PaintInvalidationState&
ownerPaintInvalidationState) | 43 // For LayoutView in a sub-frame. |
| 44 PaintInvalidationState(const LayoutView& layoutView, const PaintInvalidation
State& ownerPaintInvalidationState) |
40 : PaintInvalidationState(layoutView, ownerPaintInvalidationState.m_pendi
ngDelayedPaintInvalidations, &ownerPaintInvalidationState) { } | 45 : PaintInvalidationState(layoutView, ownerPaintInvalidationState.m_pendi
ngDelayedPaintInvalidations, &ownerPaintInvalidationState) { } |
41 | 46 |
| 47 // When a PaintInvalidationState is constructed, it just updates paintInvali
dationContainer and |
| 48 // copy cached paintOffset and clip from the parent PaintInvalidationContain
er. |
| 49 // This PaintInvalidationContainer can be used to invalidate the current obj
ect. |
| 50 // |
| 51 // After invalidation of the current object, before invalidation of the subt
rees, |
| 52 // this method must be called to make this PaintInvalidationState suitable f
or |
| 53 // paint invalidation of children. |
| 54 void updatePaintOffsetAndClipForChildren(); |
| 55 |
42 const LayoutRect& clipRect() const { return m_clipRect; } | 56 const LayoutRect& clipRect() const { return m_clipRect; } |
43 const LayoutSize& paintOffset() const { return m_paintOffset; } | 57 const LayoutSize& paintOffset() const { return m_paintOffset; } |
44 const AffineTransform& svgTransform() const { return m_svgTransform; } | 58 const AffineTransform& svgTransform() const { return m_svgTransform; } |
45 | 59 |
46 bool cachedOffsetsEnabled() const { return m_cachedOffsetsEnabled; } | 60 bool cachedOffsetsEnabled() const { return m_cachedOffsetsEnabled; } |
47 bool isClipped() const { return m_clipped; } | 61 bool isClipped() const { return m_clipped; } |
48 | 62 |
49 bool forcedSubtreeInvalidationWithinContainer() const { return m_forcedSubtr
eeInvalidationWithinContainer; } | 63 bool forcedSubtreeInvalidationWithinContainer() const { return m_forcedSubtr
eeInvalidationWithinContainer; } |
50 void setForceSubtreeInvalidationWithinContainer() { m_forcedSubtreeInvalidat
ionWithinContainer = true; } | 64 void setForceSubtreeInvalidationWithinContainer() { m_forcedSubtreeInvalidat
ionWithinContainer = true; } |
51 | 65 |
52 bool forcedSubtreeInvalidationRectUpdateWithinContainer() const { return m_f
orcedSubtreeInvalidationRectUpdateWithinContainer; } | 66 bool forcedSubtreeInvalidationRectUpdateWithinContainer() const { return m_f
orcedSubtreeInvalidationRectUpdateWithinContainer; } |
53 void setForceSubtreeInvalidationRectUpdateWithinContainer() { m_forcedSubtre
eInvalidationRectUpdateWithinContainer = true; } | 67 void setForceSubtreeInvalidationRectUpdateWithinContainer() { m_forcedSubtre
eInvalidationRectUpdateWithinContainer = true; } |
54 | 68 |
55 const LayoutBoxModelObject& paintInvalidationContainer() const { return m_pa
intInvalidationContainer; } | 69 const LayoutBoxModelObject& paintInvalidationContainer() const { return m_pa
intInvalidationContainer; } |
56 | 70 |
57 bool canMapToAncestor(const LayoutBoxModelObject* ancestor) const | 71 bool canMapToAncestor(const LayoutBoxModelObject* ancestor) const |
58 { | 72 { |
59 return m_cachedOffsetsEnabled && ancestor == &m_paintInvalidationContain
er; | 73 return m_cachedOffsetsEnabled && ancestor == &m_paintInvalidationContain
er; |
60 } | 74 } |
61 void mapObjectRectToAncestor(const LayoutObject&, const LayoutBoxModelObject
* ancestor, LayoutRect&) const; | 75 void mapObjectRectToAncestor(const LayoutObject&, const LayoutBoxModelObject
* ancestor, LayoutRect&) const; |
62 | 76 |
63 // Records |obj| as needing paint invalidation on the next frame. See the de
finition of PaintInvalidationDelayedFull for more details. | 77 // Records |obj| as needing paint invalidation on the next frame. See the de
finition of PaintInvalidationDelayedFull for more details. |
64 void pushDelayedPaintInvalidationTarget(LayoutObject& obj) { m_pendingDelaye
dPaintInvalidations.append(&obj); } | 78 void pushDelayedPaintInvalidationTarget(LayoutObject& obj) const { m_pending
DelayedPaintInvalidations.append(&obj); } |
65 Vector<LayoutObject*>& pendingDelayedPaintInvalidationTargets() { return m_p
endingDelayedPaintInvalidations; } | 79 Vector<LayoutObject*>& pendingDelayedPaintInvalidationTargets() const { retu
rn m_pendingDelayedPaintInvalidations; } |
66 | 80 |
67 // Disable view clipping and scroll offset adjustment for paint invalidation
of FrameView scrollbars. | 81 // Disable view clipping and scroll offset adjustment for paint invalidation
of FrameView scrollbars. |
68 // TODO(wangxianzhu): Remove this when root-layer-scrolls launches. | 82 // TODO(wangxianzhu): Remove this when root-layer-scrolls launches. |
69 bool viewClippingAndScrollOffsetDisabled() const { return m_viewClippingAndS
crollOffsetDisabled; } | 83 bool viewClippingAndScrollOffsetDisabled() const { return m_viewClippingAndS
crollOffsetDisabled; } |
70 void setViewClippingAndScrollOffsetDisabled(bool b) { m_viewClippingAndScrol
lOffsetDisabled = b; } | 84 void setViewClippingAndScrollOffsetDisabled(bool b) { m_viewClippingAndScrol
lOffsetDisabled = b; } |
71 | 85 |
72 PaintLayer& enclosingSelfPaintingLayer(const LayoutObject&) const; | 86 PaintLayer& enclosingSelfPaintingLayer(const LayoutObject&) const; |
73 | 87 |
74 private: | 88 private: |
75 PaintInvalidationState(const LayoutView&, Vector<LayoutObject*>& pendingDela
yedPaintInvalidations, PaintInvalidationState* ownerPaintInvalidationState); | 89 PaintInvalidationState(const LayoutView&, Vector<LayoutObject*>& pendingDela
yedPaintInvalidations, const PaintInvalidationState* ownerPaintInvalidationState
); |
76 | 90 |
77 void applyClipIfNeeded(const LayoutObject&); | 91 void applyClipIfNeeded(); |
78 void addClipRectRelativeToPaintOffset(const LayoutSize& clipSize); | 92 void addClipRectRelativeToPaintOffset(const LayoutSize& clipSize); |
79 | 93 |
80 friend class ForceHorriblySlowRectMapping; | 94 friend class ForceHorriblySlowRectMapping; |
81 | 95 |
| 96 const LayoutObject& m_currentObject; |
| 97 |
82 bool m_clipped; | 98 bool m_clipped; |
83 mutable bool m_cachedOffsetsEnabled; | 99 mutable bool m_cachedOffsetsEnabled; |
84 bool m_forcedSubtreeInvalidationWithinContainer; | 100 bool m_forcedSubtreeInvalidationWithinContainer; |
85 bool m_forcedSubtreeInvalidationRectUpdateWithinContainer; | 101 bool m_forcedSubtreeInvalidationRectUpdateWithinContainer; |
86 bool m_viewClippingAndScrollOffsetDisabled; | 102 bool m_viewClippingAndScrollOffsetDisabled; |
87 | 103 |
88 LayoutRect m_clipRect; | 104 LayoutRect m_clipRect; |
89 | 105 |
90 // x/y offset from paint invalidation container. Includes relative positioni
ng and scroll offsets. | 106 // x/y offset from paint invalidation container. Includes relative positioni
ng and scroll offsets. |
91 LayoutSize m_paintOffset; | 107 LayoutSize m_paintOffset; |
92 | 108 |
93 // The current paint invalidation container. | 109 // The current paint invalidation container. |
94 // | 110 // |
95 // It is the enclosing composited object. | 111 // It is the enclosing composited object. |
96 const LayoutBoxModelObject& m_paintInvalidationContainer; | 112 const LayoutBoxModelObject& m_paintInvalidationContainer; |
97 | 113 |
98 // Transform from the initial viewport coordinate system of an outermost | 114 // Transform from the initial viewport coordinate system of an outermost |
99 // SVG root to the userspace _before_ the relevant element. Combining this | 115 // SVG root to the userspace _before_ the relevant element. Combining this |
100 // with |m_paintOffset| yields the "final" offset. | 116 // with |m_paintOffset| yields the "final" offset. |
101 AffineTransform m_svgTransform; | 117 AffineTransform m_svgTransform; |
102 | 118 |
103 Vector<LayoutObject*>& m_pendingDelayedPaintInvalidations; | 119 Vector<LayoutObject*>& m_pendingDelayedPaintInvalidations; |
104 | 120 |
105 PaintLayer& m_enclosingSelfPaintingLayer; | 121 PaintLayer& m_enclosingSelfPaintingLayer; |
| 122 |
| 123 #if ENABLE(ASSERT) |
| 124 bool m_didUpdatePaintOffsetAndClipForChildren; |
| 125 #endif |
| 126 }; |
| 127 |
| 128 // Suspends the PaintInvalidationState cached offset and clipRect optimization.
Used under transforms |
| 129 // that cannot be represented by PaintInvalidationState (common in SVG) and when
paint invalidation |
| 130 // containers don't follow the common tree-walk algorithm (e.g. when an absolute
positioned descendant |
| 131 // is nested under a relatively positioned inline-block child). |
| 132 class ForceHorriblySlowRectMapping { |
| 133 STACK_ALLOCATED(); |
| 134 WTF_MAKE_NONCOPYABLE(ForceHorriblySlowRectMapping); |
| 135 public: |
| 136 ForceHorriblySlowRectMapping(const PaintInvalidationState* paintInvalidation
State) |
| 137 : m_paintInvalidationState(paintInvalidationState) |
| 138 , m_didDisable(m_paintInvalidationState && m_paintInvalidationState->cac
hedOffsetsEnabled()) |
| 139 { |
| 140 if (m_paintInvalidationState) |
| 141 m_paintInvalidationState->m_cachedOffsetsEnabled = false; |
| 142 } |
| 143 |
| 144 ~ForceHorriblySlowRectMapping() |
| 145 { |
| 146 if (m_didDisable) |
| 147 m_paintInvalidationState->m_cachedOffsetsEnabled = true; |
| 148 } |
| 149 private: |
| 150 const PaintInvalidationState* m_paintInvalidationState; |
| 151 bool m_didDisable; |
106 }; | 152 }; |
107 | 153 |
108 } // namespace blink | 154 } // namespace blink |
109 | 155 |
110 #endif // PaintInvalidationState_h | 156 #endif // PaintInvalidationState_h |
OLD | NEW |