| 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 #include "core/layout/PaintInvalidationState.h" | 5 #include "core/layout/PaintInvalidationState.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/layout/LayoutInline.h" | 9 #include "core/layout/LayoutInline.h" |
| 10 #include "core/layout/LayoutPart.h" | 10 #include "core/layout/LayoutPart.h" |
| 11 #include "core/layout/LayoutView.h" | 11 #include "core/layout/LayoutView.h" |
| 12 #include "core/layout/svg/LayoutSVGModelObject.h" | 12 #include "core/layout/svg/LayoutSVGModelObject.h" |
| 13 #include "core/layout/svg/LayoutSVGRoot.h" | 13 #include "core/layout/svg/LayoutSVGRoot.h" |
| 14 #include "core/layout/svg/SVGLayoutSupport.h" | 14 #include "core/layout/svg/SVGLayoutSupport.h" |
| 15 #include "core/paint/PaintLayer.h" | 15 #include "core/paint/PaintLayer.h" |
| 16 | 16 |
| 17 // We can't enable this by default because saturated operations of LayoutUnit | 17 // We can't enable this by default because saturated operations of LayoutUnit |
| 18 // don't conform commutative law for overflowing results, preventing us from | 18 // don't conform commutative law for overflowing results, preventing us from |
| 19 // making fast-path and slow-path always return the same result. | 19 // making fast path and slow path always return the same result. |
| 20 #define ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH (0 && ENABLE(ASSERT)) | 20 #define ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH (0 && ENABLE(ASSERT)) |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 | 23 |
| 24 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 24 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 25 // Make sure that the fast path and the slow path generate the same rect. | 25 // Make sure that the fast path and the slow path generate the same rect. |
| 26 void assertRectsEqual(const LayoutObject& object, const LayoutBoxModelObject& an
cestor, const LayoutRect& rect, const LayoutRect& slowPathRect) | 26 void assertRectsEqual(const LayoutObject& object, const LayoutBoxModelObject& an
cestor, const LayoutRect& rect, const LayoutRect& slowPathRect) |
| 27 { | 27 { |
| 28 // TODO(wangxianzhu): This is for cases that a sub-frame creates a root Pain
tInvalidationState | 28 // TODO(wangxianzhu): This is for cases that a sub-frame creates a root Pain
tInvalidationState |
| 29 // which doesn't inherit clip from ancestor frames. | 29 // which doesn't inherit clip from ancestor frames. |
| 30 // Remove the condition when we eliminate the latter case of PaintInvalidati
onState(const LayoutView&, ...). | 30 // Remove the condition when we eliminate the latter case of PaintInvalidati
onState(const LayoutView&, ...). |
| 31 if (object.isLayoutView()) | 31 if (object.isLayoutView()) |
| 32 return; | 32 return; |
| 33 | 33 |
| 34 // We ignore ancestor clipping for FixedPosition in fast path. |
| 35 if (object.styleRef().position() == FixedPosition) |
| 36 return; |
| 37 |
| 34 // TODO(crbug.com/597903): Fast path and slow path should generate equal emp
ty rects. | 38 // TODO(crbug.com/597903): Fast path and slow path should generate equal emp
ty rects. |
| 35 if (rect.isEmpty() && slowPathRect.isEmpty()) | 39 if (rect.isEmpty() && slowPathRect.isEmpty()) |
| 36 return; | 40 return; |
| 37 | 41 |
| 38 if (rect == slowPathRect) | 42 if (rect == slowPathRect) |
| 39 return; | 43 return; |
| 40 | 44 |
| 41 // Tolerate the difference between the two paths when crossing frame boundar
ies. | 45 // Tolerate the difference between the two paths when crossing frame boundar
ies. |
| 42 if (object.view() != ancestor.view()) { | 46 if (object.view() != ancestor.view()) { |
| 43 LayoutRect inflatedRect = rect; | 47 LayoutRect inflatedRect = rect; |
| 44 inflatedRect.inflate(1); | 48 inflatedRect.inflate(1); |
| 45 if (inflatedRect.contains(slowPathRect)) | 49 if (inflatedRect.contains(slowPathRect)) |
| 46 return; | 50 return; |
| 47 LayoutRect inflatedSlowPathRect = slowPathRect; | 51 LayoutRect inflatedSlowPathRect = slowPathRect; |
| 48 inflatedSlowPathRect.inflate(1); | 52 inflatedSlowPathRect.inflate(1); |
| 49 if (inflatedSlowPathRect.contains(rect)) | 53 if (inflatedSlowPathRect.contains(rect)) |
| 50 return; | 54 return; |
| 51 } | 55 } |
| 52 | 56 |
| 53 #ifndef NDEBUG | 57 #ifndef NDEBUG |
| 54 WTFLogAlways("Fast-path paint invalidation rect differs from slow-path: %s v
s %s", rect.toString().ascii().data(), slowPathRect.toString().ascii().data()); | 58 WTFLogAlways("Fast path paint invalidation rect differs from slow path: %s v
s %s", rect.toString().ascii().data(), slowPathRect.toString().ascii().data()); |
| 55 showLayoutTree(&object); | 59 showLayoutTree(&object); |
| 56 #endif | 60 #endif |
| 57 ASSERT_NOT_REACHED(); | 61 ASSERT_NOT_REACHED(); |
| 58 } | 62 } |
| 59 #endif | 63 #endif |
| 60 | 64 |
| 61 static bool isAbsolutePositionUnderRelativePositionInline(const LayoutObject& ob
ject) | |
| 62 { | |
| 63 if (object.styleRef().position() != AbsolutePosition) | |
| 64 return false; | |
| 65 if (LayoutObject* container = object.container()) | |
| 66 return container->isAnonymousBlock() && container->styleRef().position()
== RelativePosition; | |
| 67 return false; | |
| 68 } | |
| 69 | |
| 70 static bool supportsCachedOffsets(const LayoutObject& object) | 65 static bool supportsCachedOffsets(const LayoutObject& object) |
| 71 { | 66 { |
| 72 // TODO(wangxianzhu): Move some conditions to fast path if possible. | |
| 73 return !object.hasTransformRelatedProperty() | 67 return !object.hasTransformRelatedProperty() |
| 74 && !object.hasReflection() | 68 && !object.hasReflection() |
| 75 && !object.hasFilterInducingProperty() | 69 && !object.hasFilterInducingProperty() |
| 76 && !object.isLayoutFlowThread() | 70 && !object.isLayoutFlowThread() |
| 77 && !object.isLayoutMultiColumnSpannerPlaceholder() | 71 && !object.isLayoutMultiColumnSpannerPlaceholder() |
| 78 && object.styleRef().position() != FixedPosition | |
| 79 && !object.styleRef().isFlippedBlocksWritingMode() | 72 && !object.styleRef().isFlippedBlocksWritingMode() |
| 80 // TODO(crbug.com/598094): Handle this in fast path. | 73 && !(object.isLayoutBlock() && object.isSVG()); |
| 81 && !isAbsolutePositionUnderRelativePositionInline(object); | |
| 82 } | 74 } |
| 83 | 75 |
| 84 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec
tor<LayoutObject*>& pendingDelayedPaintInvalidations) | 76 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec
tor<LayoutObject*>& pendingDelayedPaintInvalidations) |
| 85 : m_currentObject(layoutView) | 77 : m_currentObject(layoutView) |
| 86 , m_clipped(false) | |
| 87 , m_cachedOffsetsEnabled(true) | |
| 88 , m_forcedSubtreeInvalidationWithinContainer(false) | 78 , m_forcedSubtreeInvalidationWithinContainer(false) |
| 89 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) | 79 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) |
| 90 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) | 80 , m_clipped(false) |
| 81 , m_clippedForAbsolutePosition(false) |
| 82 , m_cachedOffsetsEnabled(true) |
| 83 , m_cachedOffsetsForAbsolutePositionEnabled(true) |
| 84 , m_paintInvalidationContainer(&layoutView.containerForPaintInvalidation()) |
| 85 , m_paintInvalidationContainerForStackedContents(m_paintInvalidationContaine
r) |
| 86 , m_containerForAbsolutePosition(layoutView) |
| 91 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) | 87 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) |
| 92 , m_enclosingSelfPaintingLayer(*layoutView.layer()) | 88 , m_enclosingSelfPaintingLayer(*layoutView.layer()) |
| 93 #if ENABLE(ASSERT) | 89 #if ENABLE(ASSERT) |
| 94 , m_didUpdateForChildren(false) | 90 , m_didUpdateForChildren(false) |
| 95 #endif | 91 #endif |
| 96 { | 92 { |
| 97 if (!supportsCachedOffsets(layoutView)) { | 93 if (!supportsCachedOffsets(layoutView)) { |
| 98 m_cachedOffsetsEnabled = false; | 94 m_cachedOffsetsEnabled = false; |
| 99 return; | 95 return; |
| 100 } | 96 } |
| 101 | 97 |
| 102 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInv
alidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates); | 98 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), m_paintInva
lidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates); |
| 103 m_paintOffset = LayoutSize(point.x(), point.y()); | 99 m_paintOffset = LayoutSize(point.x(), point.y()); |
| 104 } | 100 m_paintOffsetForAbsolutePosition = m_paintOffset; |
| 105 | |
| 106 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid
ationContainer is different from | |
| 107 // the one we find during tree walk. Remove this after we fix the issue with tre
e walk in DOM-order. | |
| 108 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject&
paintInvalidationContainer) | |
| 109 : m_currentObject(currentObject) | |
| 110 , m_clipped(parentState.m_clipped) | |
| 111 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) | |
| 112 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) | |
| 113 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) | |
| 114 , m_clipRect(parentState.m_clipRect) | |
| 115 , m_paintOffset(parentState.m_paintOffset) | |
| 116 , m_paintInvalidationContainer(paintInvalidationContainer) | |
| 117 , m_svgTransform(parentState.m_svgTransform) | |
| 118 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) | |
| 119 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) | |
| 120 #if ENABLE(ASSERT) | |
| 121 , m_didUpdateForChildren(true) | |
| 122 #endif | |
| 123 { | |
| 124 ASSERT(parentState.m_didUpdateForChildren); | |
| 125 ASSERT(!m_cachedOffsetsEnabled); | |
| 126 } | 101 } |
| 127 | 102 |
| 128 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutObject& currentObject) | 103 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutObject& currentObject) |
| 129 : m_currentObject(currentObject) | 104 : m_currentObject(currentObject) |
| 130 , m_clipped(parentState.m_clipped) | |
| 131 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) | |
| 132 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) | 105 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) |
| 133 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) | 106 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) |
| 107 , m_clipped(parentState.m_clipped) |
| 108 , m_clippedForAbsolutePosition(parentState.m_clippedForAbsolutePosition) |
| 134 , m_clipRect(parentState.m_clipRect) | 109 , m_clipRect(parentState.m_clipRect) |
| 110 , m_clipRectForAbsolutePosition(parentState.m_clipRectForAbsolutePosition) |
| 135 , m_paintOffset(parentState.m_paintOffset) | 111 , m_paintOffset(parentState.m_paintOffset) |
| 136 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer()
? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain
er) | 112 , m_paintOffsetForAbsolutePosition(parentState.m_paintOffsetForAbsolutePosit
ion) |
| 113 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
| 114 , m_cachedOffsetsForAbsolutePositionEnabled(parentState.m_cachedOffsetsForAb
solutePositionEnabled) |
| 115 , m_paintInvalidationContainer(parentState.m_paintInvalidationContainer) |
| 116 , m_paintInvalidationContainerForStackedContents(parentState.m_paintInvalida
tionContainerForStackedContents) |
| 117 , m_containerForAbsolutePosition(currentObject.canContainAbsolutePositionObj
ects() ? currentObject : parentState.m_containerForAbsolutePosition) |
| 137 , m_svgTransform(parentState.m_svgTransform) | 118 , m_svgTransform(parentState.m_svgTransform) |
| 138 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) | 119 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) |
| 139 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) | 120 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) |
| 140 #if ENABLE(ASSERT) | 121 #if ENABLE(ASSERT) |
| 141 , m_didUpdateForChildren(false) | 122 , m_didUpdateForChildren(false) |
| 142 #endif | 123 #endif |
| 143 { | 124 { |
| 144 if (currentObject == parentState.m_currentObject) { | 125 if (currentObject == parentState.m_currentObject) { |
| 145 // Sometimes we create a new PaintInvalidationState from parentState on
the same object | 126 // Sometimes we create a new PaintInvalidationState from parentState on
the same object |
| 146 // (e.g. LayoutView, and the HorriblySlowRectMapping cases in LayoutBloc
k::invalidatePaintOfSubtreesIfNeeded()). | 127 // (e.g. LayoutView, and the HorriblySlowRectMapping cases in LayoutBloc
k::invalidatePaintOfSubtreesIfNeeded()). |
| 147 // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPai
ntInvalidationEnabled(). | 128 // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPai
ntInvalidationEnabled(). |
| 148 #if ENABLE(ASSERT) | 129 #if ENABLE(ASSERT) |
| 149 m_didUpdateForChildren = parentState.m_didUpdateForChildren; | 130 m_didUpdateForChildren = parentState.m_didUpdateForChildren; |
| 150 #endif | 131 #endif |
| 151 return; | 132 return; |
| 152 } | 133 } |
| 153 | 134 |
| 154 ASSERT(parentState.m_didUpdateForChildren); | 135 ASSERT(parentState.m_didUpdateForChildren); |
| 155 | 136 |
| 137 EPosition position = currentObject.styleRef().position(); |
| 138 |
| 139 if (currentObject.isPaintInvalidationContainer()) { |
| 140 m_paintInvalidationContainer = toLayoutBoxModelObject(¤tObject); |
| 141 if (currentObject.styleRef().isStackingContext()) { |
| 142 m_paintInvalidationContainerForStackedContents = toLayoutBoxModelObj
ect(¤tObject); |
| 143 // Adjust cached offsets for absolute-position to be relative to thi
s new paintInvalidationContainer. |
| 144 if (m_cachedOffsetsForAbsolutePositionEnabled && m_cachedOffsetsEnab
led) { |
| 145 m_paintOffsetForAbsolutePosition -= m_paintOffset; |
| 146 if (m_clippedForAbsolutePosition) |
| 147 m_clipRectForAbsolutePosition.move(-m_paintOffset); |
| 148 } |
| 149 } |
| 150 } else if (currentObject.isLayoutView()) { |
| 151 // m_paintInvalidationContainerForStackedContents is only for stacked de
scendants in its own frame, |
| 152 // because it doesn't establish stacking context for stacked contents in
sub-frames. |
| 153 // Contents stacked in the root stacking context in this frame should us
e this frame's paintInvalidationContainer. |
| 154 m_paintInvalidationContainerForStackedContents = m_paintInvalidationCont
ainer; |
| 155 } else if (currentObject.styleRef().isStacked() |
| 156 // This is to exclude some objects (e.g. LayoutText) inheriting stacked
style from parent but aren't actually stacked. |
| 157 && currentObject.hasLayer() |
| 158 && m_paintInvalidationContainer != m_paintInvalidationContainerForStacke
dContents) { |
| 159 // The current object is stacked, so we should use m_paintInvalidationCo
ntainerForStackedContents as its |
| 160 // paint invalidation container on which the current object is painted. |
| 161 m_paintInvalidationContainer = m_paintInvalidationContainerForStackedCon
tents; |
| 162 // We are changing paintInvalidationContainer to m_paintInvalidationCont
ainerForStackedContents. Must disable |
| 163 // cached offsets because we didn't track paint offset from m_paintInval
idationContainerForStackedContents. |
| 164 // TODO(wangxianzhu): There are optimization opportunities: |
| 165 // - Like what we do for fixed-position, calculate the paint offset in s
low path and enable fast path for |
| 166 // descendants if possible; or |
| 167 // - Track offset between the two paintInvalidationContainers. |
| 168 m_cachedOffsetsEnabled = false; |
| 169 } |
| 170 |
| 156 if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) | 171 if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) |
| 157 return; | 172 return; |
| 158 | 173 |
| 159 if (m_cachedOffsetsEnabled && !supportsCachedOffsets(currentObject)) | 174 if (m_cachedOffsetsEnabled || currentObject == m_paintInvalidationContainer) |
| 160 m_cachedOffsetsEnabled = false; | 175 m_cachedOffsetsEnabled = supportsCachedOffsets(currentObject); |
| 161 | 176 |
| 162 if (currentObject.isSVG()) { | 177 if (currentObject.isSVG()) { |
| 163 if (currentObject.isSVGRoot()) { | 178 if (currentObject.isSVGRoot()) { |
| 164 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran
sform(); | 179 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran
sform(); |
| 165 // Don't early return here, because the SVGRoot object needs to exec
ute the later code | 180 // Don't early return here, because the SVGRoot object needs to exec
ute the later code |
| 166 // as a normal LayoutBox. | 181 // as a normal LayoutBox. |
| 167 } else { | 182 } else { |
| 168 ASSERT(currentObject != m_paintInvalidationContainer); | 183 ASSERT(currentObject != m_paintInvalidationContainer); |
| 169 m_svgTransform *= currentObject.localToSVGParentTransform(); | 184 m_svgTransform *= currentObject.localToSVGParentTransform(); |
| 170 return; | 185 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 188 return; | 203 return; |
| 189 | 204 |
| 190 if (currentObject.isLayoutView()) { | 205 if (currentObject.isLayoutView()) { |
| 191 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame
()->ownerLayoutObject()); | 206 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame
()->ownerLayoutObject()); |
| 192 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs
et(); | 207 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs
et(); |
| 193 // a LayoutView paints with a defined size but a pixel-rounded offset. | 208 // a LayoutView paints with a defined size but a pixel-rounded offset. |
| 194 m_paintOffset = LayoutSize(roundedIntSize(m_paintOffset)); | 209 m_paintOffset = LayoutSize(roundedIntSize(m_paintOffset)); |
| 195 return; | 210 return; |
| 196 } | 211 } |
| 197 | 212 |
| 213 if (position == FixedPosition) { |
| 214 if (m_paintInvalidationContainer != currentObject.view() && m_paintInval
idationContainer->view() == currentObject.view()) { |
| 215 // TODO(crbug.com/598762): localToAncestorPoint() is incorrect for f
ixed-position when paintInvalidationContainer |
| 216 // is under the containing LayoutView. |
| 217 m_cachedOffsetsEnabled = false; |
| 218 return; |
| 219 } |
| 220 // Use slow path to get the offset of the fixed-position, and enable fas
t path for descendants. |
| 221 FloatPoint fixedOffset = currentObject.localToAncestorPoint(FloatPoint()
, m_paintInvalidationContainer, TraverseDocumentBoundaries); |
| 222 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); |
| 223 // In the above way to get paint offset, we can't get accurate clip rect
, so just assume no clip. |
| 224 // Clip on fixed-position is rare, in case that paintInvalidationContain
er crosses frame boundary |
| 225 // and the LayoutView is clipped by something in owner document. |
| 226 m_clipped = false; |
| 227 return; |
| 228 } |
| 229 |
| 230 if (position == AbsolutePosition) { |
| 231 m_cachedOffsetsEnabled = m_cachedOffsetsForAbsolutePositionEnabled; |
| 232 if (!m_cachedOffsetsEnabled) |
| 233 return; |
| 234 |
| 235 m_paintOffset = m_paintOffsetForAbsolutePosition; |
| 236 m_clipped = m_clippedForAbsolutePosition; |
| 237 m_clipRect = m_clipRectForAbsolutePosition; |
| 238 |
| 239 // Handle absolute-position block under relative-position inline. |
| 240 const LayoutObject& container = parentState.m_containerForAbsolutePositi
on; |
| 241 if (container.isInFlowPositioned() && container.isLayoutInline()) |
| 242 m_paintOffset += toLayoutInline(container).offsetForInFlowPositioned
Inline(toLayoutBox(m_currentObject)); |
| 243 } |
| 244 |
| 198 if (currentObject.isBox()) | 245 if (currentObject.isBox()) |
| 199 m_paintOffset += toLayoutBox(currentObject).locationOffset(); | 246 m_paintOffset += toLayoutBox(currentObject).locationOffset(); |
| 200 | 247 |
| 201 if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) | 248 if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) |
| 202 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo
rInFlowPosition(); | 249 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo
rInFlowPosition(); |
| 203 } | 250 } |
| 204 | 251 |
| 205 void PaintInvalidationState::updateForChildren() | 252 void PaintInvalidationState::updateForChildren() |
| 206 { | 253 { |
| 207 #if ENABLE(ASSERT) | 254 #if ENABLE(ASSERT) |
| 208 ASSERT(!m_didUpdateForChildren); | 255 ASSERT(!m_didUpdateForChildren); |
| 209 m_didUpdateForChildren = true; | 256 m_didUpdateForChildren = true; |
| 210 #endif | 257 #endif |
| 211 | 258 |
| 259 updateForNormalChildren(); |
| 260 |
| 261 if (m_currentObject == m_containerForAbsolutePosition) { |
| 262 if (m_paintInvalidationContainer == m_paintInvalidationContainerForStack
edContents) { |
| 263 m_cachedOffsetsForAbsolutePositionEnabled = m_cachedOffsetsEnabled; |
| 264 if (m_cachedOffsetsEnabled) { |
| 265 m_paintOffsetForAbsolutePosition = m_paintOffset; |
| 266 m_clippedForAbsolutePosition = m_clipped; |
| 267 m_clipRectForAbsolutePosition = m_clipRect; |
| 268 } |
| 269 } else { |
| 270 // Cached offsets for absolute-position are from m_paintInvalidation
Container, |
| 271 // which can't be used if the absolute-position descendants will use
a different |
| 272 // paintInvalidationContainer. |
| 273 // TODO(wangxianzhu): Same optimization opportunities as under isSta
cked() condition |
| 274 // in the PaintInvalidationState::PaintInvalidationState(... LayoutO
bject&...). |
| 275 m_cachedOffsetsForAbsolutePositionEnabled = false; |
| 276 } |
| 277 } |
| 278 } |
| 279 |
| 280 void PaintInvalidationState::updateForNormalChildren() |
| 281 { |
| 212 if (!m_cachedOffsetsEnabled) | 282 if (!m_cachedOffsetsEnabled) |
| 213 return; | 283 return; |
| 214 | 284 |
| 215 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) | 285 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) |
| 216 return; | 286 return; |
| 217 | 287 |
| 218 if (m_currentObject.isLayoutView()) { | 288 if (m_currentObject.isLayoutView()) { |
| 219 if (!m_currentObject.document().settings() || !m_currentObject.document(
).settings()->rootLayerScrolls()) { | 289 if (!m_currentObject.document().settings() || !m_currentObject.document(
).settings()->rootLayerScrolls()) { |
| 220 if (m_currentObject != m_paintInvalidationContainer) { | 290 if (m_currentObject != m_paintInvalidationContainer) { |
| 221 m_paintOffset -= toLayoutView(m_currentObject).frameView()->scro
llOffset(); | 291 m_paintOffset -= toLayoutView(m_currentObject).frameView()->scro
llOffset(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (object.isLayoutView()) | 324 if (object.isLayoutView()) |
| 255 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave
rseDocumentBoundaries | InputIsInFrameCoordinates); | 325 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave
rseDocumentBoundaries | InputIsInFrameCoordinates); |
| 256 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar
ies); | 326 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar
ies); |
| 257 } | 327 } |
| 258 | 328 |
| 259 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking(
) const | 329 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking(
) const |
| 260 { | 330 { |
| 261 ASSERT(!m_didUpdateForChildren); | 331 ASSERT(!m_didUpdateForChildren); |
| 262 | 332 |
| 263 FloatPoint point; | 333 FloatPoint point; |
| 264 if (m_paintInvalidationContainer != m_currentObject) { | 334 if (m_paintInvalidationContainer != &m_currentObject) { |
| 265 if (m_cachedOffsetsEnabled) { | 335 if (m_cachedOffsetsEnabled) { |
| 266 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) | 336 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 267 point = m_svgTransform.mapPoint(point); | 337 point = m_svgTransform.mapPoint(point); |
| 268 point += FloatPoint(m_paintOffset); | 338 point += FloatPoint(m_paintOffset); |
| 269 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 339 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 270 // TODO(wangxianzhu): We can't enable this ASSERT for now because of
crbug.com/597745. | 340 // TODO(wangxianzhu): We can't enable this ASSERT for now because of
crbug.com/597745. |
| 271 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m
_paintInvalidationContainer, FloatPoint()); | 341 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m
_paintInvalidationContainer, FloatPoint()); |
| 272 #endif | 342 #endif |
| 273 } else { | 343 } else { |
| 274 point = slowLocalToAncestorPoint(m_currentObject, m_paintInvalidatio
nContainer, FloatPoint()); | 344 point = slowLocalToAncestorPoint(m_currentObject, *m_paintInvalidati
onContainer, FloatPoint()); |
| 275 } | 345 } |
| 276 } | 346 } |
| 277 | 347 |
| 278 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 348 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 279 PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalid
ationContainer, point); | 349 PaintLayer::mapPointInPaintInvalidationContainerToBacking(*m_paintInvali
dationContainer, point); |
| 280 | 350 |
| 281 return LayoutPoint(point); | 351 return LayoutPoint(point); |
| 282 } | 352 } |
| 283 | 353 |
| 284 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const | 354 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const |
| 285 { | 355 { |
| 286 ASSERT(!m_didUpdateForChildren); | 356 ASSERT(!m_didUpdateForChildren); |
| 287 | 357 |
| 288 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) | 358 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 289 return computePaintInvalidationRectInBackingForSVG(); | 359 return computePaintInvalidationRectInBackingForSVG(); |
| 290 | 360 |
| 291 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); | 361 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); |
| 292 mapLocalRectToPaintInvalidationBacking(rect); | 362 mapLocalRectToPaintInvalidationBacking(rect); |
| 293 return rect; | 363 return rect; |
| 294 } | 364 } |
| 295 | 365 |
| 296 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG()
const | 366 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG()
const |
| 297 { | 367 { |
| 298 LayoutRect rect; | 368 LayoutRect rect; |
| 299 if (m_cachedOffsetsEnabled) { | 369 if (m_cachedOffsetsEnabled) { |
| 300 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat
ion(m_currentObject); | 370 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat
ion(m_currentObject); |
| 301 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject,
m_svgTransform, svgRect); | 371 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject,
m_svgTransform, svgRect); |
| 302 rect.move(m_paintOffset); | 372 rect.move(m_paintOffset); |
| 303 if (m_clipped) | 373 if (m_clipped) |
| 304 rect.intersect(m_clipRect); | 374 rect.intersect(m_clipRect); |
| 305 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 375 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 306 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. | 376 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. |
| 307 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI
nvalidation(m_currentObject, m_paintInvalidationContainer); | 377 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI
nvalidation(m_currentObject, *m_paintInvalidationContainer); |
| 308 if (m_clipped) | 378 if (m_clipped) |
| 309 slowPathRect.intersect(m_clipRect); | 379 slowPathRect.intersect(m_clipRect); |
| 310 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl
owPathRect); | 380 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl
owPathRect); |
| 311 #endif | 381 #endif |
| 312 } else { | 382 } else { |
| 313 // TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't me
an we can't use cached | 383 // TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't me
an we can't use cached |
| 314 // m_svgTransform. We can use hybrid fast-path (for SVG) and slow-path (
for things above the SVGRoot). | 384 // m_svgTransform. We can use hybrid fast path (for SVG) and slow path (
for things above the SVGRoot). |
| 315 rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_curre
ntObject, m_paintInvalidationContainer); | 385 rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_curre
ntObject, *m_paintInvalidationContainer); |
| 316 } | 386 } |
| 317 | 387 |
| 318 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 388 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 319 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida
tionContainer, rect); | 389 PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalid
ationContainer, rect); |
| 320 return rect; | 390 return rect; |
| 321 } | 391 } |
| 322 | 392 |
| 323 static void slowMapToVisualRectInAncestorSpace(const LayoutObject& object, const
LayoutBoxModelObject& ancestor, LayoutRect& rect) | 393 static void slowMapToVisualRectInAncestorSpace(const LayoutObject& object, const
LayoutBoxModelObject& ancestor, LayoutRect& rect) |
| 324 { | 394 { |
| 325 if (object.isLayoutView()) { | 395 if (object.isLayoutView()) { |
| 326 toLayoutView(object).mapToVisualRectInAncestorSpace(&ancestor, rect, Inp
utIsInFrameCoordinates, DefaultVisualRectFlags); | 396 toLayoutView(object).mapToVisualRectInAncestorSpace(&ancestor, rect, Inp
utIsInFrameCoordinates, DefaultVisualRectFlags); |
| 327 } else if (object.isSVGRoot()) { | 397 } else if (object.isSVGRoot()) { |
| 328 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La
youtSVGRoot::mapVisibleRectInAncestorSpace(). | 398 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La
youtSVGRoot::mapVisibleRectInAncestorSpace(). |
| 329 toLayoutSVGRoot(object).LayoutReplaced::mapToVisualRectInAncestorSpace(&
ancestor, rect); | 399 toLayoutSVGRoot(object).LayoutReplaced::mapToVisualRectInAncestorSpace(&
ancestor, rect); |
| 330 } else { | 400 } else { |
| 331 object.mapToVisualRectInAncestorSpace(&ancestor, rect); | 401 object.mapToVisualRectInAncestorSpace(&ancestor, rect); |
| 332 } | 402 } |
| 333 } | 403 } |
| 334 | 404 |
| 335 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect&
rect) const | 405 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect&
rect) const |
| 336 { | 406 { |
| 337 ASSERT(!m_didUpdateForChildren); | 407 ASSERT(!m_didUpdateForChildren); |
| 338 | 408 |
| 339 if (m_cachedOffsetsEnabled) { | 409 if (m_cachedOffsetsEnabled) { |
| 340 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 410 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 341 LayoutRect slowPathRect(rect); | 411 LayoutRect slowPathRect(rect); |
| 342 slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationC
ontainer, slowPathRect); | 412 slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidation
Container, slowPathRect); |
| 343 #endif | 413 #endif |
| 344 rect.move(m_paintOffset); | 414 rect.move(m_paintOffset); |
| 345 if (m_clipped) | 415 if (m_clipped) |
| 346 rect.intersect(m_clipRect); | 416 rect.intersect(m_clipRect); |
| 347 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 417 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 348 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. | 418 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. |
| 349 if (m_clipped) | 419 if (m_clipped) |
| 350 slowPathRect.intersect(m_clipRect); | 420 slowPathRect.intersect(m_clipRect); |
| 351 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl
owPathRect); | 421 assertRectsEqual(m_currentObject, *m_paintInvalidationContainer, rect, s
lowPathRect); |
| 352 #endif | 422 #endif |
| 353 } else { | 423 } else { |
| 354 slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationC
ontainer, rect); | 424 slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidation
Container, rect); |
| 355 } | 425 } |
| 356 | 426 |
| 357 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 427 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 358 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida
tionContainer, rect); | 428 PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalid
ationContainer, rect); |
| 359 } | 429 } |
| 360 | 430 |
| 361 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect&
localClipRect) | 431 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect&
localClipRect) |
| 362 { | 432 { |
| 363 LayoutRect clipRect = localClipRect; | 433 LayoutRect clipRect = localClipRect; |
| 364 clipRect.move(m_paintOffset); | 434 clipRect.move(m_paintOffset); |
| 365 if (m_clipped) { | 435 if (m_clipped) { |
| 366 m_clipRect.intersect(clipRect); | 436 m_clipRect.intersect(clipRect); |
| 367 } else { | 437 } else { |
| 368 m_clipRect = clipRect; | 438 m_clipRect = clipRect; |
| 369 m_clipped = true; | 439 m_clipped = true; |
| 370 } | 440 } |
| 371 } | 441 } |
| 372 | 442 |
| 373 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec
t& layoutObject) const | 443 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec
t& layoutObject) const |
| 374 { | 444 { |
| 375 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP
aintingLayer()) | 445 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP
aintingLayer()) |
| 376 return *toLayoutBoxModelObject(layoutObject).layer(); | 446 return *toLayoutBoxModelObject(layoutObject).layer(); |
| 377 | 447 |
| 378 return m_enclosingSelfPaintingLayer; | 448 return m_enclosingSelfPaintingLayer; |
| 379 } | 449 } |
| 380 | 450 |
| 381 } // namespace blink | 451 } // namespace blink |
| OLD | NEW |