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 FindPropertiesNeedingUpdate_h | 5 #ifndef FindPropertiesNeedingUpdate_h |
6 #define FindPropertiesNeedingUpdate_h | 6 #define FindPropertiesNeedingUpdate_h |
7 | 7 |
8 #if DCHECK_IS_ON() | 8 #if DCHECK_IS_ON() |
9 | 9 |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
11 #include "core/layout/LayoutObject.h" | 11 #include "core/layout/LayoutObject.h" |
12 #include "core/paint/ObjectPaintProperties.h" | 12 #include "core/paint/ObjectPaintProperties.h" |
13 #include "core/paint/PaintPropertyTreeBuilder.h" | 13 #include "core/paint/PaintPropertyTreeBuilder.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 // This file contains two scope classes for catching cases where paint | 17 // This file contains two scope classes for catching cases where paint |
18 // properties needed an update but were not marked as such. If paint properties | 18 // properties needed an update but were not marked as such. If paint properties |
19 // will change, the object must be marked as needing a paint property update | 19 // will change, the object must be marked as needing a paint property update |
20 // using {FrameView, LayoutObject}::setNeedsPaintPropertyUpdate() or by forcing | 20 // using {FrameView, LayoutObject}::setNeedsPaintPropertyUpdate() or by forcing |
21 // a subtree update (see: PaintPropertyTreeBuilderContext::forceSubtreeUpdate). | 21 // a subtree update (see: |
| 22 // PaintPropertyTreeBuilderContext::force_subtree_update). |
22 // | 23 // |
23 // Both scope classes work by recording the paint property state of an object | 24 // Both scope classes work by recording the paint property state of an object |
24 // before rebuilding properties, forcing the properties to get updated, then | 25 // before rebuilding properties, forcing the properties to get updated, then |
25 // checking that the updated properties match the original properties. | 26 // checking that the updated properties match the original properties. |
26 | 27 |
27 #define DUMP_PROPERTIES(original, updated) \ | 28 #define DUMP_PROPERTIES(original, updated) \ |
28 "\nOriginal:\n" \ | 29 "\nOriginal:\n" \ |
29 << (original ? (original)->ToString().Ascii().data() : "null") \ | 30 << (original ? (original)->ToString().Ascii().data() : "null") \ |
30 << "\nUpdated:\n" \ | 31 << "\nUpdated:\n" \ |
31 << (updated ? (updated)->ToString().Ascii().data() : "null") | 32 << (updated ? (updated)->ToString().Ascii().data() : "null") |
(...skipping 10 matching lines...) Expand all Loading... |
42 << " needing a paint property update." \ | 43 << " needing a paint property update." \ |
43 << DUMP_PROPERTIES(original, updated); \ | 44 << DUMP_PROPERTIES(original, updated); \ |
44 } \ | 45 } \ |
45 } while (0) | 46 } while (0) |
46 | 47 |
47 #define DCHECK_FRAMEVIEW_PROPERTY_EQ(original, updated) \ | 48 #define DCHECK_FRAMEVIEW_PROPERTY_EQ(original, updated) \ |
48 CHECK_PROPERTY_EQ("the FrameView", original, updated) | 49 CHECK_PROPERTY_EQ("the FrameView", original, updated) |
49 | 50 |
50 class FindFrameViewPropertiesNeedingUpdateScope { | 51 class FindFrameViewPropertiesNeedingUpdateScope { |
51 public: | 52 public: |
52 FindFrameViewPropertiesNeedingUpdateScope( | 53 FindFrameViewPropertiesNeedingUpdateScope(FrameView* frame_view, |
53 FrameView* frame_view, | 54 bool force_subtree_update) |
54 PaintPropertyTreeBuilderContext& context) | |
55 : frame_view_(frame_view), | 55 : frame_view_(frame_view), |
56 needed_paint_property_update_(frame_view->NeedsPaintPropertyUpdate()), | 56 needed_paint_property_update_(frame_view->NeedsPaintPropertyUpdate()), |
57 needed_forced_subtree_update_(context.force_subtree_update) { | 57 needed_forced_subtree_update_(force_subtree_update) { |
58 // No need to check if an update was already needed. | 58 // No need to check if an update was already needed. |
59 if (needed_paint_property_update_ || needed_forced_subtree_update_) | 59 if (needed_paint_property_update_ || needed_forced_subtree_update_) |
60 return; | 60 return; |
61 | 61 |
62 // Mark the properties as needing an update to ensure they are rebuilt. | 62 // Mark the properties as needing an update to ensure they are rebuilt. |
63 frame_view_->SetOnlyThisNeedsPaintPropertyUpdateForTesting(); | 63 frame_view_->SetOnlyThisNeedsPaintPropertyUpdateForTesting(); |
64 | 64 |
65 if (auto* pre_translation = frame_view_->PreTranslation()) | 65 if (auto* pre_translation = frame_view_->PreTranslation()) |
66 original_pre_translation_ = pre_translation->Clone(); | 66 original_pre_translation_ = pre_translation->Clone(); |
67 if (auto* content_clip = frame_view_->ContentClip()) | 67 if (auto* content_clip = frame_view_->ContentClip()) |
68 original_content_clip_ = content_clip->Clone(); | 68 original_content_clip_ = content_clip->Clone(); |
69 if (auto* scroll_translation = frame_view_->ScrollTranslation()) | 69 if (auto* scroll_translation = frame_view_->ScrollTranslation()) |
70 original_scroll_translation_ = scroll_translation->Clone(); | 70 original_scroll_translation_ = scroll_translation->Clone(); |
71 } | 71 } |
72 | 72 |
73 ~FindFrameViewPropertiesNeedingUpdateScope() { | 73 ~FindFrameViewPropertiesNeedingUpdateScope() { |
74 // No need to check if an update was already needed. | 74 // No need to check if an update was already needed. |
75 if (needed_paint_property_update_ || needed_forced_subtree_update_) | 75 if (needed_paint_property_update_ || needed_forced_subtree_update_) |
76 return; | 76 return; |
77 | 77 |
78 // If these checks fail, the paint properties changed unexpectedly. This is | 78 // If these checks fail, the paint properties changed unexpectedly. This is |
79 // due to missing one of these paint property invalidations: | 79 // due to missing one of these paint property invalidations: |
80 // 1) The FrameView should have been marked as needing an update with | 80 // 1) The FrameView should have been marked as needing an update with |
81 // FrameView::setNeedsPaintPropertyUpdate(). | 81 // FrameView::setNeedsPaintPropertyUpdate(). |
82 // 2) The PrePaintTreeWalk should have had a forced subtree update (see: | 82 // 2) The PrePaintTreeWalk should have had a forced subtree update (see: |
83 // PaintPropertyTreeBuilderContext::forceSubtreeUpdate). | 83 // PaintPropertyTreeBuilderContext::force_subtree_update). |
84 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_pre_translation_, | 84 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_pre_translation_, |
85 frame_view_->PreTranslation()); | 85 frame_view_->PreTranslation()); |
86 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_content_clip_, | 86 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_content_clip_, |
87 frame_view_->ContentClip()); | 87 frame_view_->ContentClip()); |
88 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_scroll_translation_, | 88 DCHECK_FRAMEVIEW_PROPERTY_EQ(original_scroll_translation_, |
89 frame_view_->ScrollTranslation()); | 89 frame_view_->ScrollTranslation()); |
90 | 90 |
91 // Restore original clean bit. | 91 // Restore original clean bit. |
92 frame_view_->ClearNeedsPaintPropertyUpdate(); | 92 frame_view_->ClearNeedsPaintPropertyUpdate(); |
93 } | 93 } |
94 | 94 |
95 private: | 95 private: |
96 Persistent<FrameView> frame_view_; | 96 Persistent<FrameView> frame_view_; |
97 bool needed_paint_property_update_; | 97 bool needed_paint_property_update_; |
98 bool needed_forced_subtree_update_; | 98 bool needed_forced_subtree_update_; |
99 RefPtr<const TransformPaintPropertyNode> original_pre_translation_; | 99 RefPtr<const TransformPaintPropertyNode> original_pre_translation_; |
100 RefPtr<const ClipPaintPropertyNode> original_content_clip_; | 100 RefPtr<const ClipPaintPropertyNode> original_content_clip_; |
101 RefPtr<const TransformPaintPropertyNode> original_scroll_translation_; | 101 RefPtr<const TransformPaintPropertyNode> original_scroll_translation_; |
102 }; | 102 }; |
103 | 103 |
104 #define DCHECK_OBJECT_PROPERTY_EQ(object, original, updated) \ | 104 #define DCHECK_OBJECT_PROPERTY_EQ(object, original, updated) \ |
105 CHECK_PROPERTY_EQ("the layout object (" << object.DebugName() << ")", \ | 105 CHECK_PROPERTY_EQ("the layout object (" << object.DebugName() << ")", \ |
106 original, updated) | 106 original, updated) |
107 | 107 |
108 class FindObjectPropertiesNeedingUpdateScope { | 108 class FindObjectPropertiesNeedingUpdateScope { |
109 public: | 109 public: |
110 FindObjectPropertiesNeedingUpdateScope( | 110 FindObjectPropertiesNeedingUpdateScope(const LayoutObject& object, |
111 const LayoutObject& object, | 111 bool force_subtree_update) |
112 PaintPropertyTreeBuilderContext& context) | |
113 : object_(object), | 112 : object_(object), |
114 needed_paint_property_update_(object.NeedsPaintPropertyUpdate()), | 113 needed_paint_property_update_(object.NeedsPaintPropertyUpdate()), |
115 needed_forced_subtree_update_(context.force_subtree_update), | 114 needed_forced_subtree_update_(force_subtree_update), |
116 original_paint_offset_(object.PaintOffset()) { | 115 original_paint_offset_(object.PaintOffset()) { |
117 // No need to check if an update was already needed. | 116 // No need to check if an update was already needed. |
118 if (needed_paint_property_update_ || needed_forced_subtree_update_) | 117 if (needed_paint_property_update_ || needed_forced_subtree_update_) |
119 return; | 118 return; |
120 | 119 |
121 // Mark the properties as needing an update to ensure they are rebuilt. | 120 // Mark the properties as needing an update to ensure they are rebuilt. |
122 object_.GetMutableForPainting() | 121 object_.GetMutableForPainting() |
123 .SetOnlyThisNeedsPaintPropertyUpdateForTesting(); | 122 .SetOnlyThisNeedsPaintPropertyUpdateForTesting(); |
124 | 123 |
125 if (const auto* properties = object_.PaintProperties()) | 124 if (const auto* properties = object_.PaintProperties()) |
(...skipping 20 matching lines...) Expand all Loading... |
146 | 145 |
147 // No need to check if an update was already needed. | 146 // No need to check if an update was already needed. |
148 if (needed_paint_property_update_ || needed_forced_subtree_update_) | 147 if (needed_paint_property_update_ || needed_forced_subtree_update_) |
149 return; | 148 return; |
150 | 149 |
151 // If these checks fail, the paint properties changed unexpectedly. This is | 150 // If these checks fail, the paint properties changed unexpectedly. This is |
152 // due to missing one of these paint property invalidations: | 151 // due to missing one of these paint property invalidations: |
153 // 1) The LayoutObject should have been marked as needing an update with | 152 // 1) The LayoutObject should have been marked as needing an update with |
154 // LayoutObject::setNeedsPaintPropertyUpdate(). | 153 // LayoutObject::setNeedsPaintPropertyUpdate(). |
155 // 2) The PrePaintTreeWalk should have had a forced subtree update (see: | 154 // 2) The PrePaintTreeWalk should have had a forced subtree update (see: |
156 // PaintPropertyTreeBuilderContext::forceSubtreeUpdate). | 155 // PaintPropertyTreeBuilderContext::force_subtree_update). |
157 if (original_properties_ && object_properties) { | 156 if (original_properties_ && object_properties) { |
158 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Transform(), | 157 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Transform(), |
159 object_properties->Transform()); | 158 object_properties->Transform()); |
160 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Effect(), | 159 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Effect(), |
161 object_properties->Effect()); | 160 object_properties->Effect()); |
162 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Filter(), | 161 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Filter(), |
163 object_properties->Filter()); | 162 object_properties->Filter()); |
164 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Mask(), | 163 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->Mask(), |
165 object_properties->Mask()); | 164 object_properties->Mask()); |
166 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->MaskClip(), | 165 DCHECK_OBJECT_PROPERTY_EQ(object_, original_properties_->MaskClip(), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 LayoutPoint original_paint_offset_; | 217 LayoutPoint original_paint_offset_; |
219 std::unique_ptr<const ObjectPaintProperties> original_properties_; | 218 std::unique_ptr<const ObjectPaintProperties> original_properties_; |
220 std::unique_ptr<const PropertyTreeState> | 219 std::unique_ptr<const PropertyTreeState> |
221 original_local_border_box_properties_; | 220 original_local_border_box_properties_; |
222 }; | 221 }; |
223 | 222 |
224 } // namespace blink | 223 } // namespace blink |
225 #endif // DCHECK_IS_ON() | 224 #endif // DCHECK_IS_ON() |
226 | 225 |
227 #endif // FindPropertiesNeedingUpdate_h | 226 #endif // FindPropertiesNeedingUpdate_h |
OLD | NEW |