Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp

Issue 1833493003: Remove ForceHorriblySlowRectMapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pi
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp
diff --git a/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp b/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp
index e3d37835b40a06b4c82fc24c0c9cf7bb1f0d791e..3d362b9feb3320e8e1a8473e527d57036aeacc8e 100644
--- a/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp
+++ b/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp
@@ -31,6 +31,10 @@ void assertRectsEqual(const LayoutObject& object, const LayoutBoxModelObject& an
if (object.isLayoutView())
return;
+ // We ignore ancestor clipping for FixedPosition in fast path.
+ 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.
+ return;
+
// TODO(crbug.com/597903): Fast path and slow path should generate equal empty rects.
if (rect.isEmpty() && slowPathRect.isEmpty())
return;
@@ -58,36 +62,28 @@ void assertRectsEqual(const LayoutObject& object, const LayoutBoxModelObject& an
}
#endif
-static bool isAbsolutePositionUnderRelativePositionInline(const LayoutObject& object)
-{
- if (object.styleRef().position() != AbsolutePosition)
- return false;
- if (LayoutObject* container = object.container())
- return container->isAnonymousBlock() && container->styleRef().position() == RelativePosition;
- return false;
-}
-
static bool supportsCachedOffsets(const LayoutObject& object)
{
- // TODO(wangxianzhu): Move some conditions to fast path if possible.
return !object.hasTransformRelatedProperty()
&& !object.hasReflection()
&& !object.hasFilterInducingProperty()
&& !object.isLayoutFlowThread()
&& !object.isLayoutMultiColumnSpannerPlaceholder()
- && object.styleRef().position() != FixedPosition
&& !object.styleRef().isFlippedBlocksWritingMode()
- // TODO(crbug.com/598094): Handle this in fast path.
- && !isAbsolutePositionUnderRelativePositionInline(object);
+ && !(object.isLayoutBlock() && object.isSVG());
}
PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>& pendingDelayedPaintInvalidations)
: m_currentObject(layoutView)
- , m_clipped(false)
- , m_cachedOffsetsEnabled(true)
, m_forcedSubtreeInvalidationWithinContainer(false)
, m_forcedSubtreeInvalidationRectUpdateWithinContainer(false)
- , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation())
+ , m_clipped(false)
+ , m_clippedForAbsolutePosition(false)
+ , m_cachedOffsetsEnabled(true)
+ , m_cachedOffsetsForAbsolutePositionEnabled(true)
+ , m_paintInvalidationContainer(&layoutView.containerForPaintInvalidation())
+ , m_paintInvalidationContainerForStackedContents(m_paintInvalidationContainer)
+ , m_containerForAbsolutePosition(layoutView)
, m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations)
, m_enclosingSelfPaintingLayer(*layoutView.layer())
#if ENABLE(ASSERT)
@@ -99,41 +95,26 @@ PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec
return;
}
- FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates);
+ FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), m_paintInvalidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates);
m_paintOffset = LayoutSize(point.x(), point.y());
-}
-
-// TODO(wangxianzhu): This is temporary for positioned object whose paintInvalidationContainer is different from
-// the one we find during tree walk. Remove this after we fix the issue with tree walk in DOM-order.
-PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& parentState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject& paintInvalidationContainer)
- : m_currentObject(currentObject)
- , m_clipped(parentState.m_clipped)
- , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
- , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer)
- , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer)
- , m_clipRect(parentState.m_clipRect)
- , m_paintOffset(parentState.m_paintOffset)
- , m_paintInvalidationContainer(paintInvalidationContainer)
- , m_svgTransform(parentState.m_svgTransform)
- , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets())
- , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject))
-#if ENABLE(ASSERT)
- , m_didUpdateForChildren(true)
-#endif
-{
- ASSERT(parentState.m_didUpdateForChildren);
- ASSERT(!m_cachedOffsetsEnabled);
+ m_paintOffsetForAbsolutePosition = m_paintOffset;
}
PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& parentState, const LayoutObject& currentObject)
: m_currentObject(currentObject)
- , m_clipped(parentState.m_clipped)
- , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
, m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer)
, m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer)
+ , m_clipped(parentState.m_clipped)
+ , m_clippedForAbsolutePosition(parentState.m_clippedForAbsolutePosition)
, m_clipRect(parentState.m_clipRect)
+ , m_clipRectForAbsolutePosition(parentState.m_clipRectForAbsolutePosition)
, m_paintOffset(parentState.m_paintOffset)
- , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContainer)
+ , m_paintOffsetForAbsolutePosition(parentState.m_paintOffsetForAbsolutePosition)
+ , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
+ , m_cachedOffsetsForAbsolutePositionEnabled(parentState.m_cachedOffsetsForAbsolutePositionEnabled)
+ , m_paintInvalidationContainer(parentState.m_paintInvalidationContainer)
+ , m_paintInvalidationContainerForStackedContents(parentState.m_paintInvalidationContainerForStackedContents)
+ , m_containerForAbsolutePosition(currentObject.canContainAbsolutePositionObjects() ? currentObject : parentState.m_containerForAbsolutePosition)
, m_svgTransform(parentState.m_svgTransform)
, m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets())
, m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject))
@@ -153,11 +134,41 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
ASSERT(parentState.m_didUpdateForChildren);
+ EPosition position = currentObject.styleRef().position();
+
+ if (currentObject.isPaintInvalidationContainer()) {
+ m_paintInvalidationContainer = toLayoutBoxModelObject(&currentObject);
+ if (currentObject.styleRef().isStackingContext()) {
+ m_paintInvalidationContainerForStackedContents = toLayoutBoxModelObject(&currentObject);
+ // Adjust cached offsets for absolute-position to be relative to this new paintInvalidationContainer.
+ if (m_cachedOffsetsForAbsolutePositionEnabled && m_cachedOffsetsEnabled) {
+ m_paintOffsetForAbsolutePosition -= m_paintOffset;
+ if (m_clippedForAbsolutePosition)
+ m_clipRectForAbsolutePosition.move(-m_paintOffset);
+ }
+ }
+ } else if (currentObject.isLayoutView()) {
+ // m_paintInvalidationContainerForStackedContents is only for stacked descendants in its own frame,
+ // because it doesn't establish stacking context for stacked contents in sub-frames.
+ // Contents stacked in the root stacking context in this frame should use this frame's paintInvalidationContainer.
+ m_paintInvalidationContainerForStackedContents = m_paintInvalidationContainer;
+ } else if (currentObject.styleRef().isStacked()
+ // This is to exclude some objects (e.g. LayoutText) inheriting stacked style from parent but aren't actually stacked.
+ && currentObject.hasLayer()
+ && m_paintInvalidationContainer != m_paintInvalidationContainerForStackedContents) {
+ // The current object is stacked, so we should use m_paintInvalidationContainerForStackedContents as its
+ // paint invalidation container on which the current object is painted.
+ m_paintInvalidationContainer = m_paintInvalidationContainerForStackedContents;
+ // We are changing paintInvalidationContainer to m_paintInvalidationContainerForStackedContents. 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
+ // cached offsets because we didn't track paint offset from m_paintInvalidationContainerForStackedContents.
+ m_cachedOffsetsEnabled = false;
+ }
+
if (!currentObject.isBoxModelObject() && !currentObject.isSVG())
return;
- if (m_cachedOffsetsEnabled && !supportsCachedOffsets(currentObject))
- m_cachedOffsetsEnabled = false;
+ if (m_cachedOffsetsEnabled || currentObject == m_paintInvalidationContainer)
+ m_cachedOffsetsEnabled = supportsCachedOffsets(currentObject);
if (currentObject.isSVG()) {
if (currentObject.isSVGRoot()) {
@@ -195,6 +206,35 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par
return;
}
+ if (position == FixedPosition) {
+ if (m_paintInvalidationContainer != currentObject.view() && m_paintInvalidationContainer->view() == currentObject.view()) {
+ // TODO(crbug.com/598762): localToAncestorPoint() is incorrect for fixed-position when paintInvalidationContainer
+ // is under the containing LayoutView.
+ m_cachedOffsetsEnabled = false;
+ return;
+ }
+ FloatPoint fixedOffset = currentObject.localToAncestorPoint(FloatPoint(), m_paintInvalidationContainer, TraverseDocumentBoundaries);
+ m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y());
+ // Ancestor clippings are ignored for simplicity.
+ m_clipped = false;
+ return;
+ }
+
+ if (position == AbsolutePosition) {
+ m_cachedOffsetsEnabled = m_cachedOffsetsForAbsolutePositionEnabled;
+ if (!m_cachedOffsetsEnabled)
+ return;
+
+ m_paintOffset = m_paintOffsetForAbsolutePosition;
+ m_clipped = m_clippedForAbsolutePosition;
+ m_clipRect = m_clipRectForAbsolutePosition;
+
+ // Handle absolute-position block under relative-position inline.
+ const LayoutObject& container = parentState.m_containerForAbsolutePosition;
+ if (container.isInFlowPositioned() && container.isLayoutInline())
+ m_paintOffset += toLayoutInline(container).offsetForInFlowPositionedInline(toLayoutBox(m_currentObject));
+ }
+
if (currentObject.isBox())
m_paintOffset += toLayoutBox(currentObject).locationOffset();
@@ -209,6 +249,27 @@ void PaintInvalidationState::updateForChildren()
m_didUpdateForChildren = true;
#endif
+ updateForNormalChildren();
+
+ if (m_currentObject == m_containerForAbsolutePosition) {
+ if (m_paintInvalidationContainer == m_paintInvalidationContainerForStackedContents) {
+ m_cachedOffsetsForAbsolutePositionEnabled = m_cachedOffsetsEnabled;
+ if (m_cachedOffsetsEnabled) {
+ m_paintOffsetForAbsolutePosition = m_paintOffset;
+ m_clippedForAbsolutePosition = m_clipped;
+ m_clipRectForAbsolutePosition = m_clipRect;
+ }
+ } else {
+ // Cached offsets for absolute-position are from m_paintInvalidationContainer,
+ // which can't be used if the absolute-position descendants will use a different
+ // paintInvalidationContainer.
+ m_cachedOffsetsForAbsolutePositionEnabled = false;
Xianzhu 2016/04/01 17:07:21 There are also optimization opportunities here lik
+ }
+ }
+}
+
+void PaintInvalidationState::updateForNormalChildren()
+{
if (!m_cachedOffsetsEnabled)
return;
@@ -261,7 +322,7 @@ LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking(
ASSERT(!m_didUpdateForChildren);
FloatPoint point;
- if (m_paintInvalidationContainer != m_currentObject) {
+ if (m_paintInvalidationContainer != &m_currentObject) {
if (m_cachedOffsetsEnabled) {
if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot())
point = m_svgTransform.mapPoint(point);
@@ -271,12 +332,12 @@ LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking(
// ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m_paintInvalidationContainer, FloatPoint());
#endif
} else {
- point = slowLocalToAncestorPoint(m_currentObject, m_paintInvalidationContainer, FloatPoint());
+ point = slowLocalToAncestorPoint(m_currentObject, *m_paintInvalidationContainer, FloatPoint());
}
}
- if (m_paintInvalidationContainer.layer()->groupedMapping())
- PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, point);
+ if (m_paintInvalidationContainer->layer()->groupedMapping())
+ PaintLayer::mapPointInPaintInvalidationContainerToBacking(*m_paintInvalidationContainer, point);
return LayoutPoint(point);
}
@@ -304,7 +365,7 @@ LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG()
rect.intersect(m_clipRect);
#if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH
// TODO(crbug.com/597902): Slow path misses clipping of paintInvalidationContainer.
- LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, m_paintInvalidationContainer);
+ LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, *m_paintInvalidationContainer);
if (m_clipped)
slowPathRect.intersect(m_clipRect);
assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, slowPathRect);
@@ -312,11 +373,11 @@ LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG()
} else {
// TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't mean we can't use cached
// m_svgTransform. We can use hybrid fast-path (for SVG) and slow-path (for things above the SVGRoot).
- rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, m_paintInvalidationContainer);
+ rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, *m_paintInvalidationContainer);
}
- if (m_paintInvalidationContainer.layer()->groupedMapping())
- PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect);
+ if (m_paintInvalidationContainer->layer()->groupedMapping())
+ PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalidationContainer, rect);
return rect;
}
@@ -344,7 +405,7 @@ void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect&
if (m_cachedOffsetsEnabled) {
#if ASSERT_SAME_RESULT_SLOW_AND_FAST_PATH
LayoutRect slowPathRect(rect);
- slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationContainer, slowPathRect);
+ slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidationContainer, slowPathRect);
#endif
rect.move(m_paintOffset);
if (m_clipped)
@@ -353,14 +414,14 @@ void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect&
// TODO(crbug.com/597902): Slow path misses clipping of paintInvalidationContainer.
if (m_clipped)
slowPathRect.intersect(m_clipRect);
- assertRectsEqual(m_currentObject, m_paintInvalidationContainer, rect, slowPathRect);
+ assertRectsEqual(m_currentObject, *m_paintInvalidationContainer, rect, slowPathRect);
#endif
} else {
- slowMapToVisualRectInAncestorSpace(m_currentObject, m_paintInvalidationContainer, rect);
+ slowMapToVisualRectInAncestorSpace(m_currentObject, *m_paintInvalidationContainer, rect);
}
- if (m_paintInvalidationContainer.layer()->groupedMapping())
- PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect);
+ if (m_paintInvalidationContainer->layer()->groupedMapping())
+ PaintLayer::mapRectInPaintInvalidationContainerToBacking(*m_paintInvalidationContainer, rect);
}
void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect)

Powered by Google App Engine
This is Rietveld 408576698