| 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" |
| 8 #include "core/frame/Settings.h" |
| 7 #include "core/layout/LayoutInline.h" | 9 #include "core/layout/LayoutInline.h" |
| 10 #include "core/layout/LayoutPart.h" |
| 8 #include "core/layout/LayoutView.h" | 11 #include "core/layout/LayoutView.h" |
| 9 #include "core/layout/svg/LayoutSVGModelObject.h" | 12 #include "core/layout/svg/LayoutSVGModelObject.h" |
| 10 #include "core/layout/svg/LayoutSVGRoot.h" | 13 #include "core/layout/svg/LayoutSVGRoot.h" |
| 14 #include "core/layout/svg/SVGLayoutSupport.h" |
| 11 #include "core/paint/PaintLayer.h" | 15 #include "core/paint/PaintLayer.h" |
| 12 | 16 |
| 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 |
| 19 // making fast-path and slow-path always return the same result. |
| 20 #define ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH (0 && ENABLE(ASSERT)) |
| 21 |
| 13 namespace blink { | 22 namespace blink { |
| 14 | 23 |
| 15 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec
tor<LayoutObject*>& pendingDelayedPaintInvalidations, const PaintInvalidationSta
te* ownerPaintInvalidationState) | 24 static bool isAbsolutePositionUnderRelativePositionInline(const LayoutObject& ob
ject) |
| 25 { |
| 26 if (object.styleRef().position() != AbsolutePosition) |
| 27 return false; |
| 28 if (LayoutObject* container = object.container()) |
| 29 return container->isAnonymousBlock() && container->styleRef().position()
== RelativePosition; |
| 30 return false; |
| 31 } |
| 32 |
| 33 static bool supportsCachedOffsets(const LayoutObject& object) |
| 34 { |
| 35 // TODO(wangxianzhu): Move some conditions to fast path if possible. |
| 36 return !object.hasTransformRelatedProperty() |
| 37 && !object.hasReflection() |
| 38 && !object.hasFilter() |
| 39 && !object.isLayoutFlowThread() |
| 40 && !object.isLayoutMultiColumnSpannerPlaceholder() |
| 41 && object.styleRef().position() != FixedPosition |
| 42 && !object.styleRef().isFlippedBlocksWritingMode() |
| 43 // TODO(crbug.com/598094): Handle this in fast path. |
| 44 && !isAbsolutePositionUnderRelativePositionInline(object); |
| 45 } |
| 46 |
| 47 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec
tor<LayoutObject*>& pendingDelayedPaintInvalidations) |
| 16 : m_currentObject(layoutView) | 48 : m_currentObject(layoutView) |
| 17 , m_clipped(false) | 49 , m_clipped(false) |
| 18 , m_cachedOffsetsEnabled(true) | 50 , m_cachedOffsetsEnabled(true) |
| 19 , m_forcedSubtreeInvalidationWithinContainer(false) | 51 , m_forcedSubtreeInvalidationWithinContainer(false) |
| 20 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) | 52 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) |
| 21 , m_viewClippingAndScrollOffsetDisabled(false) | |
| 22 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) | 53 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) |
| 23 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) | 54 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) |
| 24 , m_enclosingSelfPaintingLayer(*layoutView.layer()) | 55 , m_enclosingSelfPaintingLayer(*layoutView.layer()) |
| 25 #if ENABLE(ASSERT) | 56 #if ENABLE(ASSERT) |
| 26 , m_didUpdatePaintOffsetAndClipForChildren(true) | 57 , m_didUpdateForChildren(false) |
| 27 #endif | 58 #endif |
| 28 { | 59 { |
| 29 ASSERT(!ownerPaintInvalidationState || ownerPaintInvalidationState->m_didUpd
atePaintOffsetAndClipForChildren); | 60 if (!supportsCachedOffsets(layoutView)) { |
| 61 m_cachedOffsetsEnabled = false; |
| 62 return; |
| 63 } |
| 30 | 64 |
| 31 bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidati
onContainer; | 65 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInv
alidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates); |
| 32 if (!establishesPaintInvalidationContainer) { | 66 m_paintOffset = LayoutSize(point.x(), point.y()); |
| 33 if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cach
edOffsetsEnabled) | |
| 34 || !layoutView.supportsPaintInvalidationStateCachedOffsets()) { | |
| 35 m_cachedOffsetsEnabled = false; | |
| 36 return; | |
| 37 } | |
| 38 if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forced
SubtreeInvalidationWithinContainer) | |
| 39 m_forcedSubtreeInvalidationWithinContainer = true; | |
| 40 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_pain
tInvalidationContainer, TraverseDocumentBoundaries); | |
| 41 m_paintOffset = LayoutSize(point.x(), point.y()); | |
| 42 } | |
| 43 m_clipRect = layoutView.viewRect(); | |
| 44 m_clipRect.move(m_paintOffset); | |
| 45 m_clipped = true; | |
| 46 } | 67 } |
| 47 | 68 |
| 48 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid
ationContainer is different from | 69 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid
ationContainer is different from |
| 49 // the one we find during tree walk. Remove this after we fix the issue with tre
e walk in DOM-order. | 70 // the one we find during tree walk. Remove this after we fix the issue with tre
e walk in DOM-order. |
| 50 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject&
paintInvalidationContainer) | 71 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject&
paintInvalidationContainer) |
| 51 : m_currentObject(currentObject) | 72 : m_currentObject(currentObject) |
| 52 , m_clipped(parentState.m_clipped) | 73 , m_clipped(parentState.m_clipped) |
| 53 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) | 74 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
| 54 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) | 75 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) |
| 55 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) | 76 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) |
| 56 , m_viewClippingAndScrollOffsetDisabled(false) | |
| 57 , m_clipRect(parentState.m_clipRect) | 77 , m_clipRect(parentState.m_clipRect) |
| 58 , m_paintOffset(parentState.m_paintOffset) | 78 , m_paintOffset(parentState.m_paintOffset) |
| 59 , m_paintInvalidationContainer(paintInvalidationContainer) | 79 , m_paintInvalidationContainer(paintInvalidationContainer) |
| 60 , m_svgTransform(parentState.m_svgTransform) | 80 , m_svgTransform(parentState.m_svgTransform) |
| 61 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) | 81 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) |
| 62 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) | 82 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) |
| 63 #if ENABLE(ASSERT) | 83 #if ENABLE(ASSERT) |
| 64 , m_didUpdatePaintOffsetAndClipForChildren(true) | 84 , m_didUpdateForChildren(true) |
| 65 #endif | 85 #endif |
| 66 { | 86 { |
| 67 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); | 87 ASSERT(parentState.m_didUpdateForChildren); |
| 68 ASSERT(!m_cachedOffsetsEnabled); | 88 ASSERT(!m_cachedOffsetsEnabled); |
| 69 } | 89 } |
| 70 | 90 |
| 71 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutObject& currentObject) | 91 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
entState, const LayoutObject& currentObject) |
| 72 : m_currentObject(currentObject) | 92 : m_currentObject(currentObject) |
| 73 , m_clipped(parentState.m_clipped) | 93 , m_clipped(parentState.m_clipped) |
| 74 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) | 94 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
| 75 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) | 95 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva
lidationWithinContainer) |
| 76 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) | 96 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS
ubtreeInvalidationRectUpdateWithinContainer) |
| 77 , m_viewClippingAndScrollOffsetDisabled(false) | |
| 78 , m_clipRect(parentState.m_clipRect) | 97 , m_clipRect(parentState.m_clipRect) |
| 79 , m_paintOffset(parentState.m_paintOffset) | 98 , m_paintOffset(parentState.m_paintOffset) |
| 80 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer()
? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain
er) | 99 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer()
? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain
er) |
| 81 , m_svgTransform(parentState.m_svgTransform) | 100 , m_svgTransform(parentState.m_svgTransform) |
| 82 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) | 101 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida
tionTargets()) |
| 83 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) | 102 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren
tObject)) |
| 84 #if ENABLE(ASSERT) | 103 #if ENABLE(ASSERT) |
| 85 , m_didUpdatePaintOffsetAndClipForChildren(false) | 104 , m_didUpdateForChildren(false) |
| 86 #endif | 105 #endif |
| 87 { | 106 { |
| 88 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); | 107 if (currentObject == parentState.m_currentObject) { |
| 89 } | 108 // Sometimes we create a new PaintInvalidationState from parentState on
the same object |
| 90 | 109 // (e.g. LayoutView, and the HorriblySlowRectMapping cases in LayoutBloc
k::invalidatePaintOfSubtreesIfNeeded()). |
| 91 void PaintInvalidationState::updatePaintOffsetAndClipForChildren() | 110 // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPai
ntInvalidationEnabled(). |
| 92 { | |
| 93 #if ENABLE(ASSERT) | 111 #if ENABLE(ASSERT) |
| 94 ASSERT(!m_didUpdatePaintOffsetAndClipForChildren); | 112 m_didUpdateForChildren = parentState.m_didUpdateForChildren; |
| 95 m_didUpdatePaintOffsetAndClipForChildren = true; | |
| 96 #endif | 113 #endif |
| 97 | |
| 98 bool establishesPaintInvalidationContainer = m_currentObject == m_paintInval
idationContainer; | |
| 99 | |
| 100 if (!m_currentObject.isBoxModelObject()) { | |
| 101 // TODO(wangxianzhu): SVG could probably benefit from a stack-based opti
mization like html does. crbug.com/391054. | |
| 102 ASSERT(m_currentObject.isSVG()); | |
| 103 ASSERT(!establishesPaintInvalidationContainer); | |
| 104 if (m_cachedOffsetsEnabled) | |
| 105 m_svgTransform = AffineTransform(m_svgTransform * m_currentObject.lo
calToSVGParentTransform()); | |
| 106 return; | 114 return; |
| 107 } | 115 } |
| 108 | 116 |
| 109 bool fixed = m_currentObject.style()->position() == FixedPosition; | 117 ASSERT(parentState.m_didUpdateForChildren); |
| 110 | 118 |
| 111 if (!m_currentObject.supportsPaintInvalidationStateCachedOffsets()) | 119 if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) |
| 120 return; |
| 121 |
| 122 if (m_cachedOffsetsEnabled && !supportsCachedOffsets(currentObject)) |
| 112 m_cachedOffsetsEnabled = false; | 123 m_cachedOffsetsEnabled = false; |
| 113 if (establishesPaintInvalidationContainer) { | 124 |
| 125 if (currentObject.isSVG()) { |
| 126 if (currentObject.isSVGRoot()) { |
| 127 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran
sform(); |
| 128 // Don't early return here, because the SVGRoot object needs to exec
ute the later code |
| 129 // as a normal LayoutBox. |
| 130 } else { |
| 131 ASSERT(currentObject != m_paintInvalidationContainer); |
| 132 m_svgTransform *= currentObject.localToSVGParentTransform(); |
| 133 return; |
| 134 } |
| 135 } |
| 136 |
| 137 if (currentObject == m_paintInvalidationContainer) { |
| 114 // When we hit a new paint invalidation container, we don't need to | 138 // When we hit a new paint invalidation container, we don't need to |
| 115 // continue forcing a check for paint invalidation, since we're | 139 // continue forcing a check for paint invalidation, since we're |
| 116 // descending into a different invalidation container. (For instance if | 140 // descending into a different invalidation container. (For instance if |
| 117 // our parents were moved, the entire container will just move.) | 141 // our parents were moved, the entire container will just move.) |
| 118 m_forcedSubtreeInvalidationWithinContainer = false; | 142 m_forcedSubtreeInvalidationWithinContainer = false; |
| 119 m_forcedSubtreeInvalidationRectUpdateWithinContainer = false; | 143 m_forcedSubtreeInvalidationRectUpdateWithinContainer = false; |
| 120 | 144 |
| 121 m_clipped = false; // Will be updated in applyClipIfNeeded(). | 145 m_clipped = false; // Will be updated in updateForChildren(). |
| 122 m_paintOffset = LayoutSize(); | 146 m_paintOffset = LayoutSize(); |
| 123 } else { | 147 return; |
| 124 if (m_cachedOffsetsEnabled) { | 148 } |
| 125 if (fixed) { | 149 |
| 126 FloatPoint fixedOffset = m_currentObject.localToAncestorPoint(Fl
oatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); | 150 if (!m_cachedOffsetsEnabled) |
| 127 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); | 151 return; |
| 128 } else if (m_currentObject.isBox() && !m_currentObject.isTableRow())
{ | 152 |
| 129 // We don't add locationOffset of table row because the child ce
lls' location offsets include the row's location offset. | 153 if (currentObject.isLayoutView()) { |
| 130 m_paintOffset += toLayoutBox(m_currentObject).locationOffset(); | 154 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame
()->ownerLayoutObject()); |
| 155 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs
et(); |
| 156 return; |
| 157 } |
| 158 |
| 159 if (currentObject.isBox()) |
| 160 m_paintOffset += toLayoutBox(currentObject).locationOffset(); |
| 161 |
| 162 if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) |
| 163 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo
rInFlowPosition(); |
| 164 } |
| 165 |
| 166 void PaintInvalidationState::updateForChildren() |
| 167 { |
| 168 #if ENABLE(ASSERT) |
| 169 ASSERT(!m_didUpdateForChildren); |
| 170 m_didUpdateForChildren = true; |
| 171 #endif |
| 172 |
| 173 if (!m_cachedOffsetsEnabled) |
| 174 return; |
| 175 |
| 176 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) |
| 177 return; |
| 178 |
| 179 if (m_currentObject.isLayoutView()) { |
| 180 if (!m_currentObject.document().settings() || !m_currentObject.document(
).settings()->rootLayerScrolls()) { |
| 181 if (m_currentObject != m_paintInvalidationContainer) { |
| 182 m_paintOffset -= toLayoutView(m_currentObject).frameView()->scro
llOffset(); |
| 183 addClipRectRelativeToPaintOffset(toLayoutView(m_currentObject).v
iewRect()); |
| 131 } | 184 } |
| 132 | 185 return; |
| 133 if (m_currentObject.isOutOfFlowPositioned() && !fixed) { | |
| 134 if (LayoutObject* container = m_currentObject.container()) { | |
| 135 if (container->isInFlowPositioned() && container->isLayoutIn
line()) | |
| 136 m_paintOffset += toLayoutInline(container)->offsetForInF
lowPositionedInline(toLayoutBox(m_currentObject)); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 if (m_currentObject.isInFlowPositioned() && m_currentObject.hasLayer
()) | |
| 141 m_paintOffset += toLayoutBoxModelObject(m_currentObject).layer()
->offsetForInFlowPosition(); | |
| 142 } | 186 } |
| 143 | 187 } else if (m_currentObject.isSVGRoot()) { |
| 144 m_clipped = !fixed && m_clipped; | |
| 145 } | |
| 146 | |
| 147 if (m_cachedOffsetsEnabled && m_currentObject.isSVGRoot()) { | |
| 148 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject); | 188 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject); |
| 149 m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform()); | |
| 150 if (svgRoot.shouldApplyViewportClip()) | 189 if (svgRoot.shouldApplyViewportClip()) |
| 151 addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize
())); | 190 addClipRectRelativeToPaintOffset(LayoutRect(LayoutPoint(), LayoutSiz
e(svgRoot.pixelSnappedSize()))); |
| 152 } | 191 } else if (m_currentObject.isTableRow()) { |
| 153 | 192 // Child table cell's locationOffset() includes its row's locationOffset
(). |
| 154 applyClipIfNeeded(); | 193 m_paintOffset -= toLayoutBox(m_currentObject).locationOffset(); |
| 155 | 194 } |
| 156 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip
if present. | 195 |
| 157 } | |
| 158 | |
| 159 bool PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object,
const LayoutBoxModelObject* ancestor, LayoutRect& rect, VisibleRectFlags visibl
eRectFlags) const | |
| 160 { | |
| 161 ASSERT(canMapToAncestor(ancestor)); | |
| 162 | |
| 163 if (ancestor == &object) { | |
| 164 if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode()) | |
| 165 toLayoutBox(object).flipForWritingMode(rect); | |
| 166 return true; | |
| 167 } | |
| 168 | |
| 169 if (object.hasLayer()) { | |
| 170 if (const TransformationMatrix* transform = toLayoutBoxModelObject(objec
t).layer()->transform()) | |
| 171 rect = LayoutRect(transform->mapRect(pixelSnappedIntRect(rect))); | |
| 172 | |
| 173 if (object.isInFlowPositioned()) | |
| 174 rect.move(toLayoutBoxModelObject(object).layer()->offsetForInFlowPos
ition()); | |
| 175 } | |
| 176 | |
| 177 if (object.isBox()) | |
| 178 rect.moveBy(toLayoutBox(object).location()); | |
| 179 | |
| 180 rect.move(m_paintOffset); | |
| 181 | |
| 182 if (m_clipped) { | |
| 183 if (visibleRectFlags & EdgeInclusive) | |
| 184 return rect.inclusiveIntersect(m_clipRect); | |
| 185 rect.intersect(m_clipRect); | |
| 186 } | |
| 187 | |
| 188 return !rect.isEmpty(); | |
| 189 } | |
| 190 | |
| 191 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize&
clipSize) | |
| 192 { | |
| 193 LayoutRect clipRect(toPoint(m_paintOffset), clipSize); | |
| 194 if (m_clipped) { | |
| 195 m_clipRect.intersect(clipRect); | |
| 196 } else { | |
| 197 m_clipRect = clipRect; | |
| 198 m_clipped = true; | |
| 199 } | |
| 200 } | |
| 201 | |
| 202 void PaintInvalidationState::applyClipIfNeeded() | |
| 203 { | |
| 204 if (!m_currentObject.hasOverflowClip()) | 196 if (!m_currentObject.hasOverflowClip()) |
| 205 return; | 197 return; |
| 206 | 198 |
| 207 const LayoutBox& box = toLayoutBox(m_currentObject); | 199 const LayoutBox& box = toLayoutBox(m_currentObject); |
| 208 | 200 |
| 209 // Do not clip scroll layer contents because the compositor expects the whol
e layer | 201 // Do not clip scroll layer contents because the compositor expects the whol
e layer |
| 210 // to be always invalidated in-time. | 202 // to be always invalidated in-time. |
| 211 if (box.usesCompositedScrolling()) | 203 if (box.usesCompositedScrolling()) |
| 212 ASSERT(!m_clipped); // The box should establish paint invalidation conta
iner, so no m_clipped inherited. | 204 ASSERT(!m_clipped); // The box should establish paint invalidation conta
iner, so no m_clipped inherited. |
| 213 else | 205 else |
| 214 addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); | 206 addClipRectRelativeToPaintOffset(LayoutRect(LayoutPoint(), LayoutSize(bo
x.layer()->size()))); |
| 215 | 207 |
| 216 m_paintOffset -= box.scrolledContentOffset(); | 208 m_paintOffset -= box.scrolledContentOffset(); |
| 209 |
| 210 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip
if present. |
| 211 } |
| 212 |
| 213 static FloatPoint slowLocalToAncestorPoint(const LayoutObject& object, const Lay
outBoxModelObject& ancestor, const FloatPoint& point) |
| 214 { |
| 215 if (object.isLayoutView()) |
| 216 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave
rseDocumentBoundaries | InputIsInFrameCoordinates); |
| 217 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar
ies); |
| 218 } |
| 219 |
| 220 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking(
) const |
| 221 { |
| 222 ASSERT(!m_didUpdateForChildren); |
| 223 |
| 224 FloatPoint point; |
| 225 if (m_paintInvalidationContainer != m_currentObject) { |
| 226 if (m_cachedOffsetsEnabled) { |
| 227 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 228 point = m_svgTransform.mapPoint(point); |
| 229 point += FloatPoint(m_paintOffset); |
| 230 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 231 // TODO(wangxianzhu): We can't enable this ASSERT for now because of
crbug.com/597745. |
| 232 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m
_paintInvalidationContainer, FloatPoint()); |
| 233 #endif |
| 234 } else { |
| 235 point = slowLocalToAncestorPoint(m_currentObject, m_paintInvalidatio
nContainer, FloatPoint()); |
| 236 } |
| 237 } |
| 238 |
| 239 if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| 240 PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalid
ationContainer, point); |
| 241 |
| 242 return LayoutPoint(point); |
| 243 } |
| 244 |
| 245 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const |
| 246 { |
| 247 ASSERT(!m_didUpdateForChildren); |
| 248 |
| 249 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| 250 return computePaintInvalidationRectInBackingForSVG(); |
| 251 |
| 252 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); |
| 253 mapLocalRectToPaintInvalidationBacking(rect); |
| 254 return rect; |
| 255 } |
| 256 |
| 257 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG()
const |
| 258 { |
| 259 LayoutRect rect; |
| 260 if (m_cachedOffsetsEnabled) { |
| 261 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat
ion(m_currentObject); |
| 262 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject,
m_svgTransform, svgRect); |
| 263 rect.move(m_paintOffset); |
| 264 if (m_clipped) |
| 265 rect.intersect(m_clipRect); |
| 266 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 267 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI
nvalidation(m_currentObject, m_paintInvalidationContainer); |
| 268 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. |
| 269 if (m_clipped) |
| 270 slowPathRect.intersect(m_clipRect); |
| 271 // TODO(crbug.com/597903): Fast path and slow path should generate equal
empty rects. |
| 272 ASSERT((rect.isEmpty() && slowPathRect.isEmpty()) || rect == slowPathRec
t); |
| 273 #endif |
| 274 } else { |
| 275 // TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't me
an we can't use cached |
| 276 // m_svgTransform. We can use hybrid fast-path (for SVG) and slow-path (
for things above the SVGRoot). |
| 277 rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_curre
ntObject, m_paintInvalidationContainer); |
| 278 } |
| 279 |
| 280 if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| 281 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida
tionContainer, rect); |
| 282 return rect; |
| 283 } |
| 284 |
| 285 static void slowMapToVisibleRectInAncestorSpace(const LayoutObject& object, cons
t LayoutBoxModelObject& ancestor, LayoutRect& rect) |
| 286 { |
| 287 // TODO(crbug.com/597965): LayoutBox::mapToVisibleRectInAncestorSpace() inco
rrectly flips a rect |
| 288 // in its own space for writing mode. Here flip to workaround the flip. |
| 289 if (object.isBox() && (toLayoutBox(object).isWritingModeRoot() || (ancestor
== object && object.styleRef().isFlippedBlocksWritingMode()))) |
| 290 toLayoutBox(object).flipForWritingMode(rect); |
| 291 |
| 292 if (object.isLayoutView()) { |
| 293 toLayoutView(object).mapToVisibleRectInAncestorSpace(&ancestor, rect, In
putIsInFrameCoordinates, DefaultVisibleRectFlags); |
| 294 } else if (object.isSVGRoot()) { |
| 295 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La
youtSVGRoot::mapVisibleRectInAncestorSpace(). |
| 296 toLayoutSVGRoot(object).LayoutReplaced::mapToVisibleRectInAncestorSpace(
&ancestor, rect); |
| 297 } else { |
| 298 object.mapToVisibleRectInAncestorSpace(&ancestor, rect); |
| 299 } |
| 300 } |
| 301 |
| 302 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect&
rect) const |
| 303 { |
| 304 ASSERT(!m_didUpdateForChildren); |
| 305 |
| 306 if (m_cachedOffsetsEnabled) { |
| 307 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 308 LayoutRect slowPathRect(rect); |
| 309 slowMapToVisibleRectInAncestorSpace(m_currentObject, m_paintInvalidation
Container, slowPathRect); |
| 310 #endif |
| 311 rect.move(m_paintOffset); |
| 312 if (m_clipped) |
| 313 rect.intersect(m_clipRect); |
| 314 #if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH |
| 315 // Make sure that the fast path and the slow path generate the same rect
. |
| 316 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio
nContainer. |
| 317 if (m_clipped) |
| 318 slowPathRect.intersect(m_clipRect); |
| 319 // TODO(wangxianzhu): The isLayoutView() condition is for cases that a s
ub-frame creates a |
| 320 // root PaintInvalidationState which doesn't inherit clip from ancestor
frames. |
| 321 // Remove the condition when we eliminate the latter case of PaintInvali
dationState(const LayoutView&, ...). |
| 322 // TODO(crbug.com/597903): Fast path and slow path should generate equal
empty rects. |
| 323 ASSERT(m_currentObject.isLayoutView() || (rect.isEmpty() && slowPathRect
.isEmpty()) || rect == slowPathRect); |
| 324 #endif |
| 325 } else { |
| 326 slowMapToVisibleRectInAncestorSpace(m_currentObject, m_paintInvalidation
Container, rect); |
| 327 } |
| 328 |
| 329 if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| 330 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida
tionContainer, rect); |
| 331 } |
| 332 |
| 333 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect&
localClipRect) |
| 334 { |
| 335 LayoutRect clipRect = localClipRect; |
| 336 clipRect.move(m_paintOffset); |
| 337 if (m_clipped) { |
| 338 m_clipRect.intersect(clipRect); |
| 339 } else { |
| 340 m_clipRect = clipRect; |
| 341 m_clipped = true; |
| 342 } |
| 217 } | 343 } |
| 218 | 344 |
| 219 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec
t& layoutObject) const | 345 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec
t& layoutObject) const |
| 220 { | 346 { |
| 221 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP
aintingLayer()) | 347 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP
aintingLayer()) |
| 222 return *toLayoutBoxModelObject(layoutObject).layer(); | 348 return *toLayoutBoxModelObject(layoutObject).layer(); |
| 223 | 349 |
| 224 return m_enclosingSelfPaintingLayer; | 350 return m_enclosingSelfPaintingLayer; |
| 225 } | 351 } |
| 226 | 352 |
| 227 } // namespace blink | 353 } // namespace blink |
| OLD | NEW |