OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 PaintPropertyTreeBuilder_h | 5 #ifndef PaintPropertyTreeBuilder_h |
6 #define PaintPropertyTreeBuilder_h | 6 #define PaintPropertyTreeBuilder_h |
7 | 7 |
8 #include "platform/geometry/LayoutPoint.h" | 8 #include "platform/geometry/LayoutPoint.h" |
9 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
11 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 11 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
12 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 12 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
13 #include "platform/wtf/RefPtr.h" | 13 #include "platform/wtf/RefPtr.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class FrameView; | 17 class FrameView; |
18 class LayoutBoxModelObject; | 18 class LayoutBoxModelObject; |
19 class LayoutObject; | 19 class LayoutObject; |
20 | 20 |
21 // The context for PaintPropertyTreeBuilder. | 21 // The context for PaintPropertyTreeBuilder. |
22 // It's responsible for bookkeeping tree state in other order, for example, the | 22 // It's responsible for bookkeeping tree state in other order, for example, the |
23 // most recent position container seen. | 23 // most recent position container seen. |
24 struct PaintPropertyTreeBuilderContext { | 24 struct PaintPropertyTreeBuilderFragmentContext { |
25 USING_FAST_MALLOC(PaintPropertyTreeBuilderContext); | 25 USING_FAST_MALLOC(PaintPropertyTreeBuilderFragmentContext); |
26 | 26 |
27 public: | 27 public: |
28 // Initializes all property tree nodes to the roots. | 28 // Initializes all property tree nodes to the roots. |
29 PaintPropertyTreeBuilderContext(); | 29 PaintPropertyTreeBuilderFragmentContext(); |
30 | 30 |
31 // State that propagates on the containing block chain (and so is adjusted | 31 // State that propagates on the containing block chain (and so is adjusted |
32 // when an absolute or fixed position object is encountered). | 32 // when an absolute or fixed position object is encountered). |
33 struct ContainingBlockContext { | 33 struct ContainingBlockContext { |
34 // The combination of a transform and paint offset describes a linear space. | 34 // The combination of a transform and paint offset describes a linear space. |
35 // When a layout object recur to its children, the main context is expected | 35 // When a layout object recur to its children, the main context is expected |
36 // to refer the object's border box, then the callee will derive its own | 36 // to refer the object's border box, then the callee will derive its own |
37 // border box by translating the space with its own layout location. | 37 // border box by translating the space with its own layout location. |
38 const TransformPaintPropertyNode* transform = nullptr; | 38 const TransformPaintPropertyNode* transform = nullptr; |
39 LayoutPoint paint_offset; | 39 LayoutPoint paint_offset; |
(...skipping 21 matching lines...) Expand all Loading... |
61 ContainingBlockContext current; | 61 ContainingBlockContext current; |
62 | 62 |
63 // Separate context for out-of-flow positioned and fixed positioned elements | 63 // Separate context for out-of-flow positioned and fixed positioned elements |
64 // are needed because they don't use DOM parent as their containing block. | 64 // are needed because they don't use DOM parent as their containing block. |
65 // These additional contexts normally pass through untouched, and are only | 65 // These additional contexts normally pass through untouched, and are only |
66 // copied from the main context when the current element serves as the | 66 // copied from the main context when the current element serves as the |
67 // containing block of corresponding positioned descendants. Overflow clips | 67 // containing block of corresponding positioned descendants. Overflow clips |
68 // are also inherited by containing block tree instead of DOM tree, thus they | 68 // are also inherited by containing block tree instead of DOM tree, thus they |
69 // are included in the additional context too. | 69 // are included in the additional context too. |
70 ContainingBlockContext absolute_position; | 70 ContainingBlockContext absolute_position; |
71 const LayoutObject* container_for_absolute_position; | |
72 | 71 |
73 ContainingBlockContext fixed_position; | 72 ContainingBlockContext fixed_position; |
74 | 73 |
75 // This is the same as current.paintOffset except when a floating object has | 74 // This is the same as current.paintOffset except when a floating object has |
76 // non-block ancestors under its containing block. Paint offsets of the | 75 // non-block ancestors under its containing block. Paint offsets of the |
77 // non-block ancestors should not be accumulated for the floating object. | 76 // non-block ancestors should not be accumulated for the floating object. |
78 LayoutPoint paint_offset_for_float; | 77 LayoutPoint paint_offset_for_float; |
79 | 78 |
80 // The effect hierarchy is applied by the stacking context tree. It is | 79 // The effect hierarchy is applied by the stacking context tree. It is |
81 // guaranteed that every DOM descendant is also a stacking context descendant. | 80 // guaranteed that every DOM descendant is also a stacking context descendant. |
82 // Therefore, we don't need extra bookkeeping for effect nodes and can | 81 // Therefore, we don't need extra bookkeeping for effect nodes and can |
83 // generate the effect tree from a DOM-order traversal. | 82 // generate the effect tree from a DOM-order traversal. |
84 const EffectPaintPropertyNode* current_effect; | 83 const EffectPaintPropertyNode* current_effect; |
85 // Some effects are spatial, i.e. may refer to input pixels outside of output | 84 // Some effects are spatial, i.e. may refer to input pixels outside of output |
86 // clip. The cull rect for its input shall be derived from its output clip. | 85 // clip. The cull rect for its input shall be derived from its output clip. |
87 // This variable represents the input cull of current effect, also serves as | 86 // This variable represents the input cull of current effect, also serves as |
88 // output clip of child effects that don't have a hard clip. | 87 // output clip of child effects that don't have a hard clip. |
89 const ClipPaintPropertyNode* input_clip_of_current_effect; | 88 const ClipPaintPropertyNode* input_clip_of_current_effect; |
| 89 }; |
| 90 |
| 91 struct PaintPropertyTreeBuilderContext { |
| 92 PaintPropertyTreeBuilderContext() |
| 93 : container_for_absolute_position(nullptr), |
| 94 force_subtree_update(false) |
| 95 #if DCHECK_IS_ON() |
| 96 , |
| 97 is_actually_needed(true) |
| 98 #endif |
| 99 { |
| 100 } |
| 101 PaintPropertyTreeBuilderContext( |
| 102 const PaintPropertyTreeBuilderContext& other) { |
| 103 fragments = other.fragments; |
| 104 // for (auto& fragment : other.fragments) |
| 105 // fragments.push_back(fragment); |
| 106 container_for_absolute_position = other.container_for_absolute_position; |
| 107 force_subtree_update = other.force_subtree_update; |
| 108 #if DCHECK_IS_ON() |
| 109 is_actually_needed = other.is_actually_needed; |
| 110 #endif |
| 111 } |
| 112 Vector<PaintPropertyTreeBuilderFragmentContext> fragments; |
| 113 const LayoutObject* container_for_absolute_position; |
90 | 114 |
91 // True if a change has forced all properties in a subtree to be updated. This | 115 // True if a change has forced all properties in a subtree to be updated. This |
92 // can be set due to paint offset changes or when the structure of the | 116 // can be set due to paint offset changes or when the structure of the |
93 // property tree changes (i.e., a node is added or removed). | 117 // property tree changes (i.e., a node is added or removed). |
94 bool force_subtree_update; | 118 bool force_subtree_update; |
95 | 119 |
96 #if DCHECK_IS_ON() | 120 #if DCHECK_IS_ON() |
97 // When DCHECK_IS_ON() we create PaintPropertyTreeBuilderContext even if not | 121 // When DCHECK_IS_ON() we create PaintPropertyTreeBuilderContext even if not |
98 // needed. See FindPaintOffsetAndVisualRectNeedingUpdate.h. | 122 // needed. See FindPaintOffsetAndVisualRectNeedingUpdate.h. |
99 bool is_actually_needed = true; | 123 bool is_actually_needed; |
100 #endif | 124 #endif |
101 }; | 125 }; |
102 | 126 |
103 // Creates paint property tree nodes for special things in the layout tree. | 127 // Creates paint property tree nodes for special things in the layout tree. |
104 // Special things include but not limit to: overflow clip, transform, fixed-pos, | 128 // Special things include but not limit to: overflow clip, transform, fixed-pos, |
105 // animation, mask, filter, ... etc. | 129 // animation, mask, filter, ... etc. |
106 // It expects to be invoked for each layout tree node in DOM order during | 130 // It expects to be invoked for each layout tree node in DOM order during |
107 // InPrePaint phase. | 131 // InPrePaint phase. |
108 class PaintPropertyTreeBuilder { | 132 class PaintPropertyTreeBuilder { |
109 public: | 133 public: |
110 // Update the paint properties for a frame and ensure the context is up to | 134 // Update the paint properties for a frame and ensure the context is up to |
111 // date. | 135 // date. |
112 void UpdateProperties(FrameView&, PaintPropertyTreeBuilderContext&); | 136 void UpdateProperties(FrameView&, PaintPropertyTreeBuilderContext&); |
113 | 137 |
114 // Update the paint properties that affect this object (e.g., properties like | 138 // Update the paint properties that affect this object (e.g., properties like |
115 // paint offset translation) and ensure the context is up to date. Also | 139 // paint offset translation) and ensure the context is up to date. Also |
116 // handles updating the object's paintOffset. | 140 // handles updating the object's paintOffset. |
117 void UpdatePropertiesForSelf(const LayoutObject&, | 141 void UpdatePropertiesForSelf(const LayoutObject&, |
118 PaintPropertyTreeBuilderContext&); | 142 PaintPropertyTreeBuilderContext&); |
119 // Update the paint properties that affect children of this object (e.g., | 143 // Update the paint properties that affect children of this object (e.g., |
120 // scroll offset transform) and ensure the context is up to date. | 144 // scroll offset transform) and ensure the context is up to date. |
121 void UpdatePropertiesForChildren(const LayoutObject&, | 145 void UpdatePropertiesForChildren(const LayoutObject&, |
122 PaintPropertyTreeBuilderContext&); | 146 PaintPropertyTreeBuilderContext&); |
123 | 147 |
124 private: | 148 private: |
125 ALWAYS_INLINE static void UpdatePaintOffset(const LayoutBoxModelObject&, | 149 ALWAYS_INLINE static void UpdatePaintOffset( |
126 PaintPropertyTreeBuilderContext&); | 150 const LayoutBoxModelObject&, |
| 151 PaintPropertyTreeBuilderFragmentContext&, |
| 152 const LayoutObject* container_for_absolute_position); |
127 ALWAYS_INLINE static void UpdatePaintOffsetTranslation( | 153 ALWAYS_INLINE static void UpdatePaintOffsetTranslation( |
128 const LayoutBoxModelObject&, | 154 const LayoutBoxModelObject&, |
129 PaintPropertyTreeBuilderContext&); | 155 PaintPropertyTreeBuilderFragmentContext&, |
| 156 bool& force_subtree_update); |
130 ALWAYS_INLINE static void UpdateForObjectLocationAndSize( | 157 ALWAYS_INLINE static void UpdateForObjectLocationAndSize( |
131 const LayoutObject&, | 158 const LayoutObject&, |
132 PaintPropertyTreeBuilderContext&); | 159 const LayoutObject* container_for_absolute_position, |
133 ALWAYS_INLINE static void UpdateTransform(const LayoutObject&, | 160 bool& is_actually_needed, |
134 PaintPropertyTreeBuilderContext&); | 161 PaintPropertyTreeBuilderFragmentContext&, |
| 162 bool& force_subtree_update); |
| 163 ALWAYS_INLINE static void UpdateTransform( |
| 164 const LayoutObject&, |
| 165 PaintPropertyTreeBuilderFragmentContext&, |
| 166 bool& force_subtree_update); |
135 ALWAYS_INLINE static void UpdateTransformForNonRootSVG( | 167 ALWAYS_INLINE static void UpdateTransformForNonRootSVG( |
136 const LayoutObject&, | 168 const LayoutObject&, |
137 PaintPropertyTreeBuilderContext&); | 169 PaintPropertyTreeBuilderFragmentContext&, |
138 ALWAYS_INLINE static void UpdateEffect(const LayoutObject&, | 170 bool& force_subtree_update); |
139 PaintPropertyTreeBuilderContext&); | 171 ALWAYS_INLINE static void UpdateEffect( |
140 ALWAYS_INLINE static void UpdateFilter(const LayoutObject&, | 172 const LayoutObject&, |
141 PaintPropertyTreeBuilderContext&); | 173 PaintPropertyTreeBuilderFragmentContext&, |
142 ALWAYS_INLINE static void UpdateCssClip(const LayoutObject&, | 174 bool& force_subtree_update); |
143 PaintPropertyTreeBuilderContext&); | 175 ALWAYS_INLINE static void UpdateFilter( |
| 176 const LayoutObject&, |
| 177 PaintPropertyTreeBuilderFragmentContext&, |
| 178 bool& force_subtree_update); |
| 179 ALWAYS_INLINE static void UpdateCssClip( |
| 180 const LayoutObject&, |
| 181 PaintPropertyTreeBuilderFragmentContext&, |
| 182 bool& force_subtree_update); |
144 ALWAYS_INLINE static void UpdateLocalBorderBoxContext( | 183 ALWAYS_INLINE static void UpdateLocalBorderBoxContext( |
145 const LayoutObject&, | 184 const LayoutObject&, |
146 PaintPropertyTreeBuilderContext&); | 185 PaintPropertyTreeBuilderFragmentContext&, |
| 186 bool& force_subtree_update); |
147 ALWAYS_INLINE static void UpdateScrollbarPaintOffset( | 187 ALWAYS_INLINE static void UpdateScrollbarPaintOffset( |
148 const LayoutObject&, | 188 const LayoutObject&, |
149 PaintPropertyTreeBuilderContext&); | 189 PaintPropertyTreeBuilderFragmentContext&, |
| 190 bool& force_subtree_update); |
150 ALWAYS_INLINE static void UpdateOverflowClip( | 191 ALWAYS_INLINE static void UpdateOverflowClip( |
151 const LayoutObject&, | 192 const LayoutObject&, |
152 PaintPropertyTreeBuilderContext&); | 193 PaintPropertyTreeBuilderFragmentContext&, |
153 ALWAYS_INLINE static void UpdatePerspective(const LayoutObject&, | 194 bool& force_subtree_update); |
154 PaintPropertyTreeBuilderContext&); | 195 ALWAYS_INLINE static void UpdatePerspective( |
| 196 const LayoutObject&, |
| 197 PaintPropertyTreeBuilderFragmentContext&, |
| 198 bool& force_subtree_update); |
155 ALWAYS_INLINE static void UpdateSvgLocalToBorderBoxTransform( | 199 ALWAYS_INLINE static void UpdateSvgLocalToBorderBoxTransform( |
156 const LayoutObject&, | 200 const LayoutObject&, |
157 PaintPropertyTreeBuilderContext&); | 201 PaintPropertyTreeBuilderFragmentContext&, |
| 202 bool& force_subtree_update); |
158 ALWAYS_INLINE static void UpdateScrollAndScrollTranslation( | 203 ALWAYS_INLINE static void UpdateScrollAndScrollTranslation( |
159 const LayoutObject&, | 204 const LayoutObject&, |
160 PaintPropertyTreeBuilderContext&); | 205 PaintPropertyTreeBuilderFragmentContext&, |
| 206 bool& force_subtree_update); |
161 ALWAYS_INLINE static void UpdateOutOfFlowContext( | 207 ALWAYS_INLINE static void UpdateOutOfFlowContext( |
162 const LayoutObject&, | 208 const LayoutObject&, |
163 PaintPropertyTreeBuilderContext&); | 209 PaintPropertyTreeBuilderFragmentContext&, |
| 210 bool& force_subtree_update); |
164 | 211 |
165 // Ensure the ObjectPaintProperties object is created if it will be needed, or | 212 // Ensure the ObjectPaintProperties object is created if it will be needed, or |
166 // cleared otherwise. | 213 // cleared otherwise. |
167 ALWAYS_INLINE static void UpdatePaintProperties( | 214 ALWAYS_INLINE static void CollectFragments(const LayoutObject&, |
168 const LayoutObject&, | 215 PaintPropertyTreeBuilderContext&); |
169 PaintPropertyTreeBuilderContext&); | |
170 }; | 216 }; |
171 | 217 |
172 } // namespace blink | 218 } // namespace blink |
173 | 219 |
174 #endif // PaintPropertyTreeBuilder_h | 220 #endif // PaintPropertyTreeBuilder_h |
OLD | NEW |