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 FindPropertiesNeedingUpdate_h | |
| 6 #define FindPropertiesNeedingUpdate_h | |
| 7 | |
| 8 #if DCHECK_IS_ON() | |
| 9 namespace blink { | |
| 10 | |
| 11 #define DCHECK_PTR_VAL_EQ(ptrA, ptrB) \ | |
| 12 DCHECK((!!ptrA == !!ptrB) && ((!ptrA && !ptrB) || (*ptrA == *ptrB))); | |
| 13 | |
| 14 // This file contains two scope classes for catching cases where paint | |
| 15 // properties need an update but where not marked as such. If paint properties | |
| 16 // will change, the object must be marked as needing a paint property update | |
| 17 // using {FrameView, LayoutObject}::setNeedsPaintPropertyUpdate(). | |
| 18 // | |
| 19 // Both scope classes work by recording the paint property state of an object | |
| 20 // before rebuilding properties, forcing the properties to get updated, then | |
| 21 // checking that the updated properties match the original properties. | |
| 22 | |
| 23 class FindFrameViewPropertiesNeedingUpdateScope { | |
| 24 public: | |
| 25 static std::unique_ptr<FindFrameViewPropertiesNeedingUpdateScope> create( | |
| 26 FrameView* view) { | |
| 27 if (!view->needsPaintPropertyUpdate()) | |
| 28 return wrapUnique(new FindFrameViewPropertiesNeedingUpdateScope(view)); | |
| 29 return nullptr; | |
| 30 } | |
|
Xianzhu
2016/10/26 19:21:51
Can you just use the constructor at the call sites
pdr.
2016/10/26 23:10:19
Good idea, done.
| |
| 31 | |
| 32 FindFrameViewPropertiesNeedingUpdateScope(FrameView* frameView) | |
| 33 : m_frameView(frameView) { | |
| 34 // Mark the properties as needing an update to ensure they are rebuilt. | |
| 35 m_frameView->setNeedsPaintPropertyUpdate(); | |
| 36 if (auto* preTranslation = m_frameView->preTranslation()) | |
| 37 m_preTranslation = preTranslation->clone(); | |
| 38 if (auto* contentClip = m_frameView->contentClip()) | |
| 39 m_contentClip = contentClip->clone(); | |
| 40 if (auto* scrollTranslation = m_frameView->scrollTranslation()) | |
| 41 m_scrollTranslation = scrollTranslation->clone(); | |
| 42 if (auto* scroll = m_frameView->scroll()) | |
| 43 m_scroll = scroll->clone(); | |
| 44 } | |
| 45 | |
| 46 ~FindFrameViewPropertiesNeedingUpdateScope() { | |
| 47 // If paint properties are not marked as needing an update but still change, | |
| 48 // we are missing a call to FrameView::setNeedsPaintPropertyUpdate(). | |
| 49 DCHECK_PTR_VAL_EQ(m_preTranslation, m_frameView->preTranslation()); | |
| 50 DCHECK_PTR_VAL_EQ(m_contentClip, m_frameView->contentClip()); | |
| 51 DCHECK_PTR_VAL_EQ(m_scrollTranslation, m_frameView->scrollTranslation()); | |
| 52 DCHECK_PTR_VAL_EQ(m_scroll, m_frameView->scroll()); | |
| 53 // Restore original clean bit. | |
| 54 m_frameView->clearNeedsPaintPropertyUpdate(); | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 Persistent<FrameView> m_frameView; | |
| 59 RefPtr<TransformPaintPropertyNode> m_preTranslation; | |
| 60 RefPtr<ClipPaintPropertyNode> m_contentClip; | |
| 61 RefPtr<TransformPaintPropertyNode> m_scrollTranslation; | |
| 62 RefPtr<ScrollPaintPropertyNode> m_scroll; | |
| 63 }; | |
| 64 | |
| 65 class FindObjectPropertiesNeedingUpdateScope { | |
| 66 public: | |
| 67 static std::unique_ptr<FindObjectPropertiesNeedingUpdateScope> create( | |
| 68 const LayoutObject& object) { | |
| 69 if (!object.needsPaintPropertyUpdate()) | |
| 70 return wrapUnique(new FindObjectPropertiesNeedingUpdateScope(object)); | |
| 71 return nullptr; | |
| 72 } | |
| 73 | |
| 74 FindObjectPropertiesNeedingUpdateScope(const LayoutObject& object) | |
| 75 : m_object(object) { | |
| 76 // Mark the properties as needing an update to ensure they are rebuilt. | |
| 77 const_cast<LayoutObject&>(m_object).setNeedsPaintPropertyUpdate(); | |
| 78 if (const auto* properties = m_object.paintProperties()) | |
| 79 m_properties = properties->clone(); | |
| 80 } | |
| 81 | |
| 82 ~FindObjectPropertiesNeedingUpdateScope() { | |
| 83 // If paint properties are not marked as needing an update but still change, | |
| 84 // we are missing a call to LayoutObject::setNeedsPaintPropertyUpdate(). | |
| 85 const auto* objectProperties = m_object.paintProperties(); | |
| 86 if (m_properties && objectProperties) { | |
| 87 DCHECK_PTR_VAL_EQ(m_properties->paintOffsetTranslation(), | |
| 88 objectProperties->paintOffsetTranslation()); | |
| 89 DCHECK_PTR_VAL_EQ(m_properties->transform(), | |
| 90 objectProperties->transform()); | |
| 91 DCHECK_PTR_VAL_EQ(m_properties->effect(), objectProperties->effect()); | |
| 92 DCHECK_PTR_VAL_EQ(m_properties->cssClip(), objectProperties->cssClip()); | |
| 93 DCHECK_PTR_VAL_EQ(m_properties->cssClipFixedPosition(), | |
| 94 objectProperties->cssClipFixedPosition()); | |
| 95 DCHECK_PTR_VAL_EQ(m_properties->innerBorderRadiusClip(), | |
| 96 objectProperties->innerBorderRadiusClip()); | |
| 97 DCHECK_PTR_VAL_EQ(m_properties->overflowClip(), | |
| 98 objectProperties->overflowClip()); | |
| 99 DCHECK_PTR_VAL_EQ(m_properties->perspective(), | |
| 100 objectProperties->perspective()); | |
| 101 DCHECK_PTR_VAL_EQ(m_properties->svgLocalToBorderBoxTransform(), | |
| 102 objectProperties->svgLocalToBorderBoxTransform()); | |
| 103 DCHECK_PTR_VAL_EQ(m_properties->scrollTranslation(), | |
| 104 objectProperties->scrollTranslation()); | |
| 105 DCHECK_PTR_VAL_EQ(m_properties->scrollbarPaintOffset(), | |
| 106 objectProperties->scrollbarPaintOffset()); | |
| 107 const auto* borderBox = m_properties->localBorderBoxProperties(); | |
| 108 const auto* objectBorderBox = | |
| 109 objectProperties->localBorderBoxProperties(); | |
| 110 if (borderBox && objectBorderBox) { | |
| 111 DCHECK(borderBox->paintOffset == objectBorderBox->paintOffset); | |
| 112 DCHECK_EQ(borderBox->propertyTreeState.transform(), | |
| 113 objectBorderBox->propertyTreeState.transform()); | |
| 114 DCHECK_EQ(borderBox->propertyTreeState.clip(), | |
| 115 objectBorderBox->propertyTreeState.clip()); | |
| 116 DCHECK_EQ(borderBox->propertyTreeState.effect(), | |
| 117 objectBorderBox->propertyTreeState.effect()); | |
| 118 DCHECK_EQ(borderBox->propertyTreeState.scroll(), | |
| 119 objectBorderBox->propertyTreeState.scroll()); | |
| 120 } else { | |
| 121 DCHECK_EQ(!!borderBox, !!objectBorderBox); | |
| 122 } | |
| 123 } else { | |
| 124 DCHECK_EQ(!!m_properties, !!objectProperties); | |
| 125 } | |
| 126 // Restore original clean bit. | |
| 127 const_cast<LayoutObject&>(m_object).clearNeedsPaintPropertyUpdate(); | |
| 128 } | |
| 129 | |
| 130 private: | |
| 131 const LayoutObject& m_object; | |
| 132 std::unique_ptr<const ObjectPaintProperties> m_properties; | |
| 133 }; | |
| 134 | |
| 135 } // namespace blink | |
| 136 #endif // DCHECK_IS_ON() | |
| 137 | |
| 138 #endif // FindPropertiesNeedingUpdate_h | |
| OLD | NEW |