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 ca464ab93c3cb9394109bdd14c06d0e99660266c..78e56b6f47c7d13033fcd4d9342c25be077759d1 100644 |
--- a/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
+++ b/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
@@ -8,41 +8,54 @@ |
#include "core/layout/LayoutView.h" |
#include "core/layout/svg/LayoutSVGModelObject.h" |
#include "core/layout/svg/LayoutSVGRoot.h" |
+#include "core/layout/svg/SVGLayoutSupport.h" |
#include "core/paint/PaintLayer.h" |
namespace blink { |
-PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>& pendingDelayedPaintInvalidations, const PaintInvalidationState* ownerPaintInvalidationState) |
+static LayoutSize computeViewPaintOffset(const LayoutView& layoutView, const LayoutBoxModelObject& paintInvalidationContainer) |
+{ |
+ LayoutView::setViewClippingAndScrollOffsetDisabled(true); |
+ FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &paintInvalidationContainer, TraverseDocumentBoundaries); |
+ LayoutView::setViewClippingAndScrollOffsetDisabled(false); |
+ return LayoutSize(point.x(), point.y()); |
+} |
+ |
+static bool supportsCachedOffsets(const LayoutObject& object) |
+{ |
+ // TODO(wangxianzhu): Move some conditions to fast path if possible. |
+ return !object.hasTransformRelatedProperty() |
+ && !object.hasReflection() |
+ && !object.hasFilter() |
+ && object.styleRef().position() != FixedPosition; |
+} |
+ |
+static bool supportsCachedOffsetsForChildren(const LayoutObject& object) |
+{ |
+ // TODO(wangxianzhu): Move some conditions to fast path if possible. |
+ return !object.styleRef().isFlippedBlocksWritingMode() |
+ && !object.isLayoutFlowThread(); |
+} |
+ |
+PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>& pendingDelayedPaintInvalidations) |
: m_currentObject(layoutView) |
, m_clipped(false) |
, m_cachedOffsetsEnabled(true) |
, m_forcedSubtreeInvalidationWithinContainer(false) |
, m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) |
- , m_viewClippingAndScrollOffsetDisabled(false) |
, m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) |
, m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) |
, m_enclosingSelfPaintingLayer(*layoutView.layer()) |
#if ENABLE(ASSERT) |
- , m_didUpdatePaintOffsetAndClipForChildren(true) |
+ , m_didUpdateForChildren(false) |
#endif |
{ |
- ASSERT(!ownerPaintInvalidationState || ownerPaintInvalidationState->m_didUpdatePaintOffsetAndClipForChildren); |
- |
- bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidationContainer; |
- if (!establishesPaintInvalidationContainer) { |
- if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cachedOffsetsEnabled) |
- || !layoutView.supportsPaintInvalidationStateCachedOffsets()) { |
- m_cachedOffsetsEnabled = false; |
- return; |
- } |
- if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forcedSubtreeInvalidationWithinContainer) |
- m_forcedSubtreeInvalidationWithinContainer = true; |
- FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
- m_paintOffset = LayoutSize(point.x(), point.y()); |
+ if (!supportsCachedOffsets(layoutView)) { |
+ m_cachedOffsetsEnabled = false; |
+ return; |
} |
- m_clipRect = layoutView.viewRect(); |
- m_clipRect.move(m_paintOffset); |
- m_clipped = true; |
+ |
+ m_paintOffset = computeViewPaintOffset(layoutView, m_paintInvalidationContainer); |
} |
// TODO(wangxianzhu): This is temporary for positioned object whose paintInvalidationContainer is different from |
@@ -53,7 +66,6 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
, m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
, m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer) |
, m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer) |
- , m_viewClippingAndScrollOffsetDisabled(false) |
, m_clipRect(parentState.m_clipRect) |
, m_paintOffset(parentState.m_paintOffset) |
, m_paintInvalidationContainer(paintInvalidationContainer) |
@@ -61,10 +73,10 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
, m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets()) |
, m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject)) |
#if ENABLE(ASSERT) |
- , m_didUpdatePaintOffsetAndClipForChildren(true) |
+ , m_didUpdateForChildren(true) |
#endif |
{ |
- ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); |
+ ASSERT(parentState.m_didUpdateForChildren); |
ASSERT(!m_cachedOffsetsEnabled); |
} |
@@ -74,7 +86,6 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
, m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
, m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer) |
, m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer) |
- , m_viewClippingAndScrollOffsetDisabled(false) |
, m_clipRect(parentState.m_clipRect) |
, m_paintOffset(parentState.m_paintOffset) |
, m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContainer) |
@@ -82,34 +93,36 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
, m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets()) |
, m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject)) |
#if ENABLE(ASSERT) |
- , m_didUpdatePaintOffsetAndClipForChildren(false) |
+ , m_didUpdateForChildren(false) |
#endif |
{ |
- ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); |
-} |
- |
-void PaintInvalidationState::updatePaintOffsetAndClipForChildren() |
-{ |
+ if (currentObject == parentState.m_currentObject) { |
+ // Sometimes we create a new PaintInvalidationState from parentState on the same object. |
+ // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled(). |
#if ENABLE(ASSERT) |
- ASSERT(!m_didUpdatePaintOffsetAndClipForChildren); |
- m_didUpdatePaintOffsetAndClipForChildren = true; |
+ m_didUpdateForChildren = parentState.m_didUpdateForChildren; |
#endif |
+ return; |
+ } |
+ |
+ ASSERT(parentState.m_didUpdateForChildren); |
- bool establishesPaintInvalidationContainer = m_currentObject == m_paintInvalidationContainer; |
+ if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) |
+ return; |
+ |
+ bool establishesPaintInvalidationContainer = currentObject == m_paintInvalidationContainer; |
- if (!m_currentObject.isBoxModelObject()) { |
+ if (currentObject.isSVG() && !currentObject.isSVGRoot()) { |
// TODO(wangxianzhu): SVG could probably benefit from a stack-based optimization like html does. crbug.com/391054. |
- ASSERT(m_currentObject.isSVG()); |
ASSERT(!establishesPaintInvalidationContainer); |
if (m_cachedOffsetsEnabled) |
- m_svgTransform = AffineTransform(m_svgTransform * m_currentObject.localToSVGParentTransform()); |
+ m_svgTransform = AffineTransform(m_svgTransform * currentObject.localToSVGParentTransform()); |
return; |
} |
- bool fixed = m_currentObject.style()->position() == FixedPosition; |
- |
- if (!m_currentObject.supportsPaintInvalidationStateCachedOffsets()) |
+ if (!supportsCachedOffsets(currentObject)) |
m_cachedOffsetsEnabled = false; |
+ |
if (establishesPaintInvalidationContainer) { |
// When we hit a new paint invalidation container, we don't need to |
// continue forcing a check for paint invalidation, since we're |
@@ -120,67 +133,152 @@ void PaintInvalidationState::updatePaintOffsetAndClipForChildren() |
m_clipped = false; // Will be updated in applyClipIfNeeded(). |
m_paintOffset = LayoutSize(); |
- } else { |
- if (m_cachedOffsetsEnabled) { |
- if (fixed) { |
- FloatPoint fixedOffset = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
- m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); |
- } else if (m_currentObject.isBox() && !m_currentObject.isTableRow()) { |
- // We don't add locationOffset of table row because the child cells' location offsets include the row's location offset. |
- m_paintOffset += toLayoutBox(m_currentObject).locationOffset(); |
- } |
+ } else if (m_cachedOffsetsEnabled) { |
+ if (currentObject.isLayoutView()) { |
+ m_paintOffset = computeViewPaintOffset(toLayoutView(currentObject), m_paintInvalidationContainer); |
+ return; |
+ } |
- if (m_currentObject.isOutOfFlowPositioned() && !fixed) { |
- if (LayoutObject* container = m_currentObject.container()) { |
- if (container->isInFlowPositioned() && container->isLayoutInline()) |
- m_paintOffset += toLayoutInline(container)->offsetForInFlowPositionedInline(toLayoutBox(m_currentObject)); |
- } |
+ if (currentObject.styleRef().position() == FixedPosition) { |
+ // TODO(wangxianzhu): Replace localToAncestorPoint with fast path. |
+ FloatPoint fixedOffset = currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
+ m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); |
+ m_clipped = false; |
+ } else if (currentObject.isBox()) { |
+ m_paintOffset += toLayoutBox(currentObject).locationOffset(); |
+ if (currentObject.isTableCell()) { |
+ // A table cell's locationOffset() includes its row's locationOffset(). |
+ m_paintOffset -= toLayoutBox(currentObject.parent())->locationOffset(); |
} |
+ } |
- if (m_currentObject.isInFlowPositioned() && m_currentObject.hasLayer()) |
- m_paintOffset += toLayoutBoxModelObject(m_currentObject).layer()->offsetForInFlowPosition(); |
+ if (currentObject.styleRef().position() == AbsolutePosition) { |
+ if (LayoutObject* container = currentObject.container()) { |
+ if (container->isInFlowPositioned() && container->isLayoutInline()) |
+ m_paintOffset += toLayoutInline(container)->offsetForInFlowPositionedInline(toLayoutBox(currentObject)); |
+ } |
} |
- m_clipped = !fixed && m_clipped; |
+ if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) |
+ m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetForInFlowPosition(); |
} |
- if (m_cachedOffsetsEnabled && m_currentObject.isSVGRoot()) { |
+ if (m_cachedOffsetsEnabled && currentObject.isSVGRoot()) |
+ m_svgTransform = AffineTransform(toLayoutSVGRoot(currentObject).localToBorderBoxTransform()); |
+} |
+ |
+void PaintInvalidationState::updateForChildren() |
+{ |
+#if ENABLE(ASSERT) |
+ ASSERT(!m_didUpdateForChildren); |
+ m_didUpdateForChildren = true; |
+#endif |
+ |
+ if (!m_cachedOffsetsEnabled) |
+ return; |
+ |
+ if (!supportsCachedOffsetsForChildren(m_currentObject)) { |
+ m_cachedOffsetsEnabled = false; |
+ return; |
+ } |
+ |
+ if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) |
+ return; |
+ |
+ if (m_currentObject.isLayoutView()) { |
+ if (m_currentObject != m_paintInvalidationContainer) { |
+ // TODO(wangxianzhu): Replace localToAncestorPoint with fast path. |
+ FloatPoint viewOffset = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
+ m_paintOffset = LayoutSize(viewOffset.x(), viewOffset.y()); |
+ m_clipRect = toLayoutView(m_currentObject).viewRect(); |
+ m_clipRect.move(m_paintOffset); |
+ m_clipped = true; |
+ return; |
+ } |
+ } else if (m_currentObject.isSVGRoot()) { |
const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject); |
- m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform()); |
if (svgRoot.shouldApplyViewportClip()) |
addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize())); |
} |
- applyClipIfNeeded(); |
+ if (!m_currentObject.hasOverflowClip()) |
+ return; |
+ |
+ const LayoutBox& box = toLayoutBox(m_currentObject); |
+ |
+ // Do not clip scroll layer contents because the compositor expects the whole layer |
+ // to be always invalidated in-time. |
+ if (box.usesCompositedScrolling()) |
+ ASSERT(!m_clipped); // The box should establish paint invalidation container, so no m_clipped inherited. |
+ else |
+ addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); |
+ |
+ m_paintOffset -= box.scrolledContentOffset(); |
// FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. |
} |
-void PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object, const LayoutBoxModelObject* ancestor, LayoutRect& rect) const |
+LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking() const |
{ |
- ASSERT(canMapToAncestor(ancestor)); |
- |
- if (ancestor == &object) { |
- if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode()) |
- toLayoutBox(object).flipForWritingMode(rect); |
- return; |
+ FloatPoint point; |
+ if (m_paintInvalidationContainer != m_currentObject) { |
+ if (m_cachedOffsetsEnabled) { |
+ if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
+ point = m_svgTransform.mapPoint(point); |
+ point += FloatPoint(m_paintOffset); |
+ } else { |
+ // Fallback to slow path. |
+ point = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer); |
+ } |
} |
- if (object.hasLayer()) { |
- if (const TransformationMatrix* transform = toLayoutBoxModelObject(object).layer()->transform()) |
- rect = LayoutRect(transform->mapRect(pixelSnappedIntRect(rect))); |
+ if (m_paintInvalidationContainer.layer()->groupedMapping()) |
+ PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, point); |
+ |
+ return LayoutPoint(point); |
+} |
+ |
+LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const |
+{ |
+ if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
+ return computePaintInvalidationRectInBackingForSVG(); |
+ |
+ LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); |
+ mapLocalRectToPaintInvalidationBacking(rect); |
+ return rect; |
+} |
- if (object.isInFlowPositioned()) |
- rect.move(toLayoutBoxModelObject(object).layer()->offsetForInFlowPosition()); |
+LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG() const |
+{ |
+ LayoutRect rect; |
+ if (m_cachedOffsetsEnabled) { |
+ FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(m_currentObject); |
+ rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject, m_svgTransform, svgRect); |
+ rect.move(m_paintOffset); |
+ if (m_clipped) |
+ rect.intersect(m_clipRect); |
+ } else { |
+ rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, m_paintInvalidationContainer); |
} |
- if (object.isBox()) |
- rect.moveBy(toLayoutBox(object).location()); |
+ if (m_paintInvalidationContainer.layer()->groupedMapping()) |
+ PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect); |
+ return rect; |
+} |
- rect.move(m_paintOffset); |
+void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect& rect) const |
+{ |
+ if (m_cachedOffsetsEnabled) { |
+ rect.move(m_paintOffset); |
+ if (m_clipped) |
+ rect.intersect(m_clipRect); |
+ } else { |
+ // Fallback to slow path. |
+ m_currentObject.mapToVisibleRectInAncestorSpace(&m_paintInvalidationContainer, rect); |
+ } |
- if (m_clipped) |
- rect.intersect(m_clipRect); |
+ if (m_paintInvalidationContainer.layer()->groupedMapping()) |
+ PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect); |
} |
void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize& clipSize) |
@@ -194,23 +292,6 @@ void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize& |
} |
} |
-void PaintInvalidationState::applyClipIfNeeded() |
-{ |
- if (!m_currentObject.hasOverflowClip()) |
- return; |
- |
- const LayoutBox& box = toLayoutBox(m_currentObject); |
- |
- // Do not clip scroll layer contents because the compositor expects the whole layer |
- // to be always invalidated in-time. |
- if (box.usesCompositedScrolling()) |
- ASSERT(!m_clipped); // The box should establish paint invalidation container, so no m_clipped inherited. |
- else |
- addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); |
- |
- m_paintOffset -= box.scrolledContentOffset(); |
-} |
- |
PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObject& layoutObject) const |
{ |
if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfPaintingLayer()) |