Chromium Code Reviews| 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" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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) | |
|
chrishtr
2016/04/01 16:38:13
Is there a bug for this?
Xianzhu
2016/04/01 17:07:21
I would not treat this as a bug, but a trade-off b
chrishtr
2016/04/01 17:10:36
Ok. Please document this in the code.
| |
| 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 | |
|
chrishtr
2016/04/01 16:38:13
Why can't we use the same approach here as line 14
Xianzhu
2016/04/01 17:07:21
This is because we don't track the offset from m_p
| |
| 163 // cached offsets because we didn't track paint offset from m_paintInval idationContainerForStackedContents. | |
| 164 m_cachedOffsetsEnabled = false; | |
| 165 } | |
| 166 | |
| 156 if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) | 167 if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) |
| 157 return; | 168 return; |
| 158 | 169 |
| 159 if (m_cachedOffsetsEnabled && !supportsCachedOffsets(currentObject)) | 170 if (m_cachedOffsetsEnabled || currentObject == m_paintInvalidationContainer) |
| 160 m_cachedOffsetsEnabled = false; | 171 m_cachedOffsetsEnabled = supportsCachedOffsets(currentObject); |
| 161 | 172 |
| 162 if (currentObject.isSVG()) { | 173 if (currentObject.isSVG()) { |
| 163 if (currentObject.isSVGRoot()) { | 174 if (currentObject.isSVGRoot()) { |
| 164 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran sform(); | 175 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran sform(); |
| 165 // Don't early return here, because the SVGRoot object needs to exec ute the later code | 176 // Don't early return here, because the SVGRoot object needs to exec ute the later code |
| 166 // as a normal LayoutBox. | 177 // as a normal LayoutBox. |
| 167 } else { | 178 } else { |
| 168 ASSERT(currentObject != m_paintInvalidationContainer); | 179 ASSERT(currentObject != m_paintInvalidationContainer); |
| 169 m_svgTransform *= currentObject.localToSVGParentTransform(); | 180 m_svgTransform *= currentObject.localToSVGParentTransform(); |
| 170 return; | 181 return; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 188 return; | 199 return; |
| 189 | 200 |
| 190 if (currentObject.isLayoutView()) { | 201 if (currentObject.isLayoutView()) { |
| 191 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame ()->ownerLayoutObject()); | 202 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame ()->ownerLayoutObject()); |
| 192 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs et(); | 203 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs et(); |
| 193 // a LayoutView paints with a defined size but a pixel-rounded offset. | 204 // a LayoutView paints with a defined size but a pixel-rounded offset. |
| 194 m_paintOffset = LayoutSize(roundedIntSize(m_paintOffset)); | 205 m_paintOffset = LayoutSize(roundedIntSize(m_paintOffset)); |
| 195 return; | 206 return; |
| 196 } | 207 } |
| 197 | 208 |
| 209 if (position == FixedPosition) { | |
| 210 if (m_paintInvalidationContainer != currentObject.view() && m_paintInval idationContainer->view() == currentObject.view()) { | |
| 211 // TODO(crbug.com/598762): localToAncestorPoint() is incorrect for f ixed-position when paintInvalidationContainer | |
| 212 // is under the containing LayoutView. | |
| 213 m_cachedOffsetsEnabled = false; | |
| 214 return; | |
| 215 } | |
| 216 FloatPoint fixedOffset = currentObject.localToAncestorPoint(FloatPoint() , m_paintInvalidationContainer, TraverseDocumentBoundaries); | |
| 217 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); | |
| 218 // Ancestor clippings are ignored for simplicity. | |
| 219 m_clipped = false; | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 if (position == AbsolutePosition) { | |
| 224 m_cachedOffsetsEnabled = m_cachedOffsetsForAbsolutePositionEnabled; | |
| 225 if (!m_cachedOffsetsEnabled) | |
| 226 return; | |
| 227 | |
| 228 m_paintOffset = m_paintOffsetForAbsolutePosition; | |
| 229 m_clipped = m_clippedForAbsolutePosition; | |
| 230 m_clipRect = m_clipRectForAbsolutePosition; | |
| 231 | |
| 232 // Handle absolute-position block under relative-position inline. | |
| 233 const LayoutObject& container = parentState.m_containerForAbsolutePositi on; | |
| 234 if (container.isInFlowPositioned() && container.isLayoutInline()) | |
| 235 m_paintOffset += toLayoutInline(container).offsetForInFlowPositioned Inline(toLayoutBox(m_currentObject)); | |
| 236 } | |
| 237 | |
| 198 if (currentObject.isBox()) | 238 if (currentObject.isBox()) |
| 199 m_paintOffset += toLayoutBox(currentObject).locationOffset(); | 239 m_paintOffset += toLayoutBox(currentObject).locationOffset(); |
| 200 | 240 |
| 201 if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) | 241 if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) |
| 202 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo rInFlowPosition(); | 242 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo rInFlowPosition(); |
| 203 } | 243 } |
| 204 | 244 |
| 205 void PaintInvalidationState::updateForChildren() | 245 void PaintInvalidationState::updateForChildren() |
| 206 { | 246 { |
| 207 #if ENABLE(ASSERT) | 247 #if ENABLE(ASSERT) |
| 208 ASSERT(!m_didUpdateForChildren); | 248 ASSERT(!m_didUpdateForChildren); |
| 209 m_didUpdateForChildren = true; | 249 m_didUpdateForChildren = true; |
| 210 #endif | 250 #endif |
| 211 | 251 |
| 252 updateForNormalChildren(); | |
| 253 | |
| 254 if (m_currentObject == m_containerForAbsolutePosition) { | |
| 255 if (m_paintInvalidationContainer == m_paintInvalidationContainerForStack edContents) { | |
| 256 m_cachedOffsetsForAbsolutePositionEnabled = m_cachedOffsetsEnabled; | |
| 257 if (m_cachedOffsetsEnabled) { | |
| 258 m_paintOffsetForAbsolutePosition = m_paintOffset; | |
| 259 m_clippedForAbsolutePosition = m_clipped; | |
| 260 m_clipRectForAbsolutePosition = m_clipRect; | |
| 261 } | |
| 262 } else { | |
| 263 // Cached offsets for absolute-position are from m_paintInvalidation Container, | |
| 264 // which can't be used if the absolute-position descendants will use a different | |
| 265 // paintInvalidationContainer. | |
| 266 m_cachedOffsetsForAbsolutePositionEnabled = false; | |
|
Xianzhu
2016/04/01 17:07:21
There are also optimization opportunities here lik
| |
| 267 } | |
| 268 } | |
| 269 } | |
| 270 | |
| 271 void PaintInvalidationState::updateForNormalChildren() | |
| 272 { | |
| 212 if (!m_cachedOffsetsEnabled) | 273 if (!m_cachedOffsetsEnabled) |
| 213 return; | 274 return; |
| 214 | 275 |
| 215 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) | 276 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) |
| 216 return; | 277 return; |
| 217 | 278 |
| 218 if (m_currentObject.isLayoutView()) { | 279 if (m_currentObject.isLayoutView()) { |
| 219 if (!m_currentObject.document().settings() || !m_currentObject.document( ).settings()->rootLayerScrolls()) { | 280 if (!m_currentObject.document().settings() || !m_currentObject.document( ).settings()->rootLayerScrolls()) { |
| 220 if (m_currentObject != m_paintInvalidationContainer) { | 281 if (m_currentObject != m_paintInvalidationContainer) { |
| 221 m_paintOffset -= toLayoutView(m_currentObject).frameView()->scro llOffset(); | 282 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()) | 315 if (object.isLayoutView()) |
| 255 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave rseDocumentBoundaries | InputIsInFrameCoordinates); | 316 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave rseDocumentBoundaries | InputIsInFrameCoordinates); |
| 256 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar ies); | 317 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar ies); |
| 257 } | 318 } |
| 258 | 319 |
| 259 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking( ) const | 320 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking( ) const |
| 260 { | 321 { |
| 261 ASSERT(!m_didUpdateForChildren); | 322 ASSERT(!m_didUpdateForChildren); |
| 262 | 323 |
| 263 FloatPoint point; | 324 FloatPoint point; |
| 264 if (m_paintInvalidationContainer != m_currentObject) { | 325 if (m_paintInvalidationContainer != &m_currentObject) { |
| 265 if (m_cachedOffsetsEnabled) { | 326 if (m_cachedOffsetsEnabled) { |
| 266 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) | 327 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 267 point = m_svgTransform.mapPoint(point); | 328 point = m_svgTransform.mapPoint(point); |
| 268 point += FloatPoint(m_paintOffset); | 329 point += FloatPoint(m_paintOffset); |
| 269 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 330 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 270 // TODO(wangxianzhu): We can't enable this ASSERT for now because of crbug.com/597745. | 331 // TODO(wangxianzhu): We can't enable this ASSERT for now because of crbug.com/597745. |
| 271 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m _paintInvalidationContainer, FloatPoint()); | 332 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m _paintInvalidationContainer, FloatPoint()); |
| 272 #endif | 333 #endif |
| 273 } else { | 334 } else { |
| 274 point = slowLocalToAncestorPoint(m_currentObject, m_paintInvalidatio nContainer, FloatPoint()); | 335 point = slowLocalToAncestorPoint(m_currentObject, *m_paintInvalidati onContainer, FloatPoint()); |
| 275 } | 336 } |
| 276 } | 337 } |
| 277 | 338 |
| 278 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 339 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 279 PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalid ationContainer, point); | 340 PaintLayer::mapPointInPaintInvalidationContainerToBacking(*m_paintInvali dationContainer, point); |
| 280 | 341 |
| 281 return LayoutPoint(point); | 342 return LayoutPoint(point); |
| 282 } | 343 } |
| 283 | 344 |
| 284 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const | 345 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const |
| 285 { | 346 { |
| 286 ASSERT(!m_didUpdateForChildren); | 347 ASSERT(!m_didUpdateForChildren); |
| 287 | 348 |
| 288 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) | 349 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 289 return computePaintInvalidationRectInBackingForSVG(); | 350 return computePaintInvalidationRectInBackingForSVG(); |
| 290 | 351 |
| 291 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); | 352 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); |
| 292 mapLocalRectToPaintInvalidationBacking(rect); | 353 mapLocalRectToPaintInvalidationBacking(rect); |
| 293 return rect; | 354 return rect; |
| 294 } | 355 } |
| 295 | 356 |
| 296 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG() const | 357 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG() const |
| 297 { | 358 { |
| 298 LayoutRect rect; | 359 LayoutRect rect; |
| 299 if (m_cachedOffsetsEnabled) { | 360 if (m_cachedOffsetsEnabled) { |
| 300 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat ion(m_currentObject); | 361 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat ion(m_currentObject); |
| 301 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject, m_svgTransform, svgRect); | 362 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject, m_svgTransform, svgRect); |
| 302 rect.move(m_paintOffset); | 363 rect.move(m_paintOffset); |
| 303 if (m_clipped) | 364 if (m_clipped) |
| 304 rect.intersect(m_clipRect); | 365 rect.intersect(m_clipRect); |
| 305 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 366 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 306 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer. | 367 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer. |
| 307 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI nvalidation(m_currentObject, m_paintInvalidationContainer); | 368 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI nvalidation(m_currentObject, *m_paintInvalidationContainer); |
| 308 if (m_clipped) | 369 if (m_clipped) |
| 309 slowPathRect.intersect(m_clipRect); | 370 slowPathRect.intersect(m_clipRect); |
| 310 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl owPathRect); | 371 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl owPathRect); |
| 311 #endif | 372 #endif |
| 312 } else { | 373 } else { |
| 313 // TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't me an we can't use cached | 374 // 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). | 375 // 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); | 376 rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_curre ntObject, *m_paintInvalidationContainer); |
| 316 } | 377 } |
| 317 | 378 |
| 318 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 379 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 319 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida tionContainer, rect); | 380 PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalid ationContainer, rect); |
| 320 return rect; | 381 return rect; |
| 321 } | 382 } |
| 322 | 383 |
| 323 static void slowMapToVisualRectInAncestorSpace(const LayoutObject& object, const LayoutBoxModelObject& ancestor, LayoutRect& rect) | 384 static void slowMapToVisualRectInAncestorSpace(const LayoutObject& object, const LayoutBoxModelObject& ancestor, LayoutRect& rect) |
| 324 { | 385 { |
| 325 // TODO(crbug.com/597965): LayoutBox::mapToVisualRectInAncestorSpace() incor rectly flips a rect | 386 // TODO(crbug.com/597965): LayoutBox::mapToVisualRectInAncestorSpace() incor rectly flips a rect |
| 326 // in its own space for writing mode. Here flip to workaround the flip. | 387 // in its own space for writing mode. Here flip to workaround the flip. |
| 327 if (object.isBox() && (toLayoutBox(object).isWritingModeRoot() || (ancestor == object && object.styleRef().isFlippedBlocksWritingMode()))) | 388 if (object.isBox() && (toLayoutBox(object).isWritingModeRoot() || (ancestor == object && object.styleRef().isFlippedBlocksWritingMode()))) |
| 328 toLayoutBox(object).flipForWritingMode(rect); | 389 toLayoutBox(object).flipForWritingMode(rect); |
| 329 | 390 |
| 330 if (object.isLayoutView()) { | 391 if (object.isLayoutView()) { |
| 331 toLayoutView(object).mapToVisualRectInAncestorSpace(&ancestor, rect, Inp utIsInFrameCoordinates, DefaultVisualRectFlags); | 392 toLayoutView(object).mapToVisualRectInAncestorSpace(&ancestor, rect, Inp utIsInFrameCoordinates, DefaultVisualRectFlags); |
| 332 } else if (object.isSVGRoot()) { | 393 } else if (object.isSVGRoot()) { |
| 333 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La youtSVGRoot::mapVisibleRectInAncestorSpace(). | 394 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La youtSVGRoot::mapVisibleRectInAncestorSpace(). |
| 334 toLayoutSVGRoot(object).LayoutReplaced::mapToVisualRectInAncestorSpace(& ancestor, rect); | 395 toLayoutSVGRoot(object).LayoutReplaced::mapToVisualRectInAncestorSpace(& ancestor, rect); |
| 335 } else { | 396 } else { |
| 336 object.mapToVisualRectInAncestorSpace(&ancestor, rect); | 397 object.mapToVisualRectInAncestorSpace(&ancestor, rect); |
| 337 } | 398 } |
| 338 } | 399 } |
| 339 | 400 |
| 340 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect& rect) const | 401 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect& rect) const |
| 341 { | 402 { |
| 342 ASSERT(!m_didUpdateForChildren); | 403 ASSERT(!m_didUpdateForChildren); |
| 343 | 404 |
| 344 if (m_cachedOffsetsEnabled) { | 405 if (m_cachedOffsetsEnabled) { |
| 345 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 406 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 346 LayoutRect slowPathRect(rect); | 407 LayoutRect slowPathRect(rect); |
| 347 slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationC ontainer, slowPathRect); | 408 slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidation Container, slowPathRect); |
| 348 #endif | 409 #endif |
| 349 rect.move(m_paintOffset); | 410 rect.move(m_paintOffset); |
| 350 if (m_clipped) | 411 if (m_clipped) |
| 351 rect.intersect(m_clipRect); | 412 rect.intersect(m_clipRect); |
| 352 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH | 413 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 353 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer. | 414 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer. |
| 354 if (m_clipped) | 415 if (m_clipped) |
| 355 slowPathRect.intersect(m_clipRect); | 416 slowPathRect.intersect(m_clipRect); |
| 356 assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, sl owPathRect); | 417 assertRectsEqual(m_currentObject, *m_paintInvalidationContainer, rect, s lowPathRect); |
| 357 #endif | 418 #endif |
| 358 } else { | 419 } else { |
| 359 slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationC ontainer, rect); | 420 slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidation Container, rect); |
| 360 } | 421 } |
| 361 | 422 |
| 362 if (m_paintInvalidationContainer.layer()->groupedMapping()) | 423 if (m_paintInvalidationContainer->layer()->groupedMapping()) |
| 363 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida tionContainer, rect); | 424 PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalid ationContainer, rect); |
| 364 } | 425 } |
| 365 | 426 |
| 366 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect) | 427 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect) |
| 367 { | 428 { |
| 368 LayoutRect clipRect = localClipRect; | 429 LayoutRect clipRect = localClipRect; |
| 369 clipRect.move(m_paintOffset); | 430 clipRect.move(m_paintOffset); |
| 370 if (m_clipped) { | 431 if (m_clipped) { |
| 371 m_clipRect.intersect(clipRect); | 432 m_clipRect.intersect(clipRect); |
| 372 } else { | 433 } else { |
| 373 m_clipRect = clipRect; | 434 m_clipRect = clipRect; |
| 374 m_clipped = true; | 435 m_clipped = true; |
| 375 } | 436 } |
| 376 } | 437 } |
| 377 | 438 |
| 378 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const | 439 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const |
| 379 { | 440 { |
| 380 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer()) | 441 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer()) |
| 381 return *toLayoutBoxModelObject(layoutObject).layer(); | 442 return *toLayoutBoxModelObject(layoutObject).layer(); |
| 382 | 443 |
| 383 return m_enclosingSelfPaintingLayer; | 444 return m_enclosingSelfPaintingLayer; |
| 384 } | 445 } |
| 385 | 446 |
| 386 } // namespace blink | 447 } // namespace blink |
| OLD | NEW |