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

Unified Diff: Source/core/paint/DeprecatedPaintLayerPainter.cpp

Issue 1284203004: Generate scroll/clip display item hierarchy for SPv2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix failing test. Update test expectation. Created 5 years, 3 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: Source/core/paint/DeprecatedPaintLayerPainter.cpp
diff --git a/Source/core/paint/DeprecatedPaintLayerPainter.cpp b/Source/core/paint/DeprecatedPaintLayerPainter.cpp
index ace09e2b1946d1f33dde9ef549a71ba6ceb29e76..b82f52b9568a4d312bafcda92de0edb903bb3cfd 100644
--- a/Source/core/paint/DeprecatedPaintLayerPainter.cpp
+++ b/Source/core/paint/DeprecatedPaintLayerPainter.cpp
@@ -22,10 +22,12 @@
#include "core/paint/ScrollRecorder.h"
#include "core/paint/ScrollableAreaPainter.h"
#include "core/paint/Transform3DRecorder.h"
+#include "core/paint/TransformRecorder.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/graphics/paint/ClipPathRecorder.h"
#include "platform/graphics/paint/ClipRecorder.h"
#include "platform/graphics/paint/CompositingDisplayItem.h"
+#include "platform/graphics/paint/FixedPositionContainerDisplayItem.h"
#include "platform/graphics/paint/SubsequenceRecorder.h"
#include "platform/graphics/paint/Transform3DDisplayItem.h"
#include "wtf/Optional.h"
@@ -91,8 +93,6 @@ void DeprecatedPaintLayerPainter::paintLayer(GraphicsContext* context, const Dep
if (m_paintLayer.paintsWithTransparency(paintingInfo.globalPaintFlags()))
paintFlags |= PaintLayerHaveTransparency;
- LayerFixedPositionRecorder fixedPositionRecorder(*context, *m_paintLayer.layoutObject());
-
// PaintLayerAppliedTransform is used in LayoutReplica, to avoid applying the transform twice.
if (m_paintLayer.paintsWithTransform(paintingInfo.globalPaintFlags()) && !(paintFlags & PaintLayerAppliedTransform)) {
paintLayerWithTransform(context, paintingInfo, paintFlags);
@@ -120,7 +120,7 @@ void DeprecatedPaintLayerPainter::paintLayerContentsAndReflection(GraphicsContex
class ClipPathHelper {
public:
- ClipPathHelper(GraphicsContext* context, const DeprecatedPaintLayer& paintLayer, const DeprecatedPaintLayerPaintingInfo& paintingInfo, LayoutRect& rootRelativeBounds, bool& rootRelativeBoundsComputed,
+ ClipPathHelper(GraphicsContext* context, const DeprecatedPaintLayer& paintLayer, const LayoutRect& interestRect, LayoutRect& rootRelativeBounds, bool& rootRelativeBoundsComputed,
const LayoutPoint& offsetFromRoot, PaintLayerFlags paintFlags)
: m_resourceClipper(0), m_paintLayer(paintLayer), m_context(context)
{
@@ -139,7 +139,7 @@ public:
ShapeClipPathOperation* clipPath = toShapeClipPathOperation(style.clipPath());
if (clipPath->isValid()) {
if (!rootRelativeBoundsComputed) {
- rootRelativeBounds = paintLayer.physicalBoundingBoxIncludingReflectionAndStackingChildren(paintingInfo.rootLayer, offsetFromRoot);
+ rootRelativeBounds = paintLayer.physicalBoundingBoxIncludingReflectionAndStackingChildren(offsetFromRoot);
rootRelativeBoundsComputed = true;
}
m_clipPathRecorder.emplace(*context, *paintLayer.layoutObject(), clipPath->path(FloatRect(rootRelativeBounds)));
@@ -151,13 +151,13 @@ public:
Element* element = document.getElementById(referenceClipPathOperation->fragment());
if (isSVGClipPathElement(element) && element->layoutObject()) {
if (!rootRelativeBoundsComputed) {
- rootRelativeBounds = paintLayer.physicalBoundingBoxIncludingReflectionAndStackingChildren(paintingInfo.rootLayer, offsetFromRoot);
+ rootRelativeBounds = paintLayer.physicalBoundingBoxIncludingReflectionAndStackingChildren(offsetFromRoot);
rootRelativeBoundsComputed = true;
}
m_resourceClipper = toLayoutSVGResourceClipper(toLayoutSVGResourceContainer(element->layoutObject()));
if (!SVGClipPainter(*m_resourceClipper).prepareEffect(*paintLayer.layoutObject(), FloatRect(rootRelativeBounds),
- FloatRect(paintingInfo.paintDirtyRect), context, m_clipperState)) {
+ FloatRect(interestRect), context, m_clipperState)) {
// No need to post-apply the clipper if this failed.
m_resourceClipper = 0;
}
@@ -206,20 +206,38 @@ void DeprecatedPaintLayerPainter::paintLayerContents(GraphicsContext* context, c
// Ensure our lists are up-to-date.
m_paintLayer.stackingNode()->updateLayerListsIfNeeded();
- LayoutPoint offsetFromRoot;
- m_paintLayer.convertToLayerCoords(paintingInfo.rootLayer, offsetFromRoot);
-
- if (m_paintLayer.compositingState() == PaintsIntoOwnBacking)
- offsetFromRoot.move(m_paintLayer.subpixelAccumulation());
+ LayoutPoint offsetFromRoot = toLayoutPoint(paintingInfo.subPixelAccumulation);
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
+ m_paintLayer.convertToLayerCoords(paintingInfo.rootLayer, offsetFromRoot, DeprecatedPaintLayer::ExcludeScroll);
else
- offsetFromRoot.move(paintingInfo.subPixelAccumulation);
+ m_paintLayer.convertToLayerCoords(paintingInfo.rootLayer, offsetFromRoot);
LayoutRect rootRelativeBounds;
bool rootRelativeBoundsComputed = false;
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && !context->displayItemList()->displayItemConstructionIsDisabled()) {
+ if (paintingInfo.rootLayer == &m_paintLayer) {
+ // A counter scroll needs to be applied in non-rootLayerScrolls mode,
pdr. 2015/09/03 06:16:59 Can you add a test for this?
trchen 2015/09/04 06:10:15 I think it is a bit too early. This is only a work
+ // because we are supposed to paint in absolute space.
+ // (i.e. Impl-side scrolling would be impossible.)
+ // With rootLayerScrolls enabled, we are in the viewport space instead.
+ AffineTransform counterScroll;
+ if (m_paintLayer.layoutObject()->isLayoutView()) {
+ Settings* settings = m_paintLayer.layoutObject()->document().settings();
+ if (settings && settings->rootLayerScrolls()) {
+ IntSize scrollOffset = static_cast<LayoutView*>(m_paintLayer.layoutObject())->frameView()->scrollOffset();
+ counterScroll.translate(scrollOffset.width(), scrollOffset.height());
+ }
+ }
+ TransformRecorder frameScrollWorkaround(*context, *m_paintLayer.layoutObject(), counterScroll);
+
+ context->displayItemList()->createAndAppend<FixedPositionContainerDisplayItem>(*m_paintLayer.layoutObject());
+ }
+ }
+
// These helpers output clip and compositing operations using a RAII pattern. Stack-allocated-varibles are destructed in the reverse order of construction,
// so they are nested properly.
- ClipPathHelper clipPathHelper(context, m_paintLayer, paintingInfo, rootRelativeBounds, rootRelativeBoundsComputed, offsetFromRoot, paintFlags);
+ ClipPathHelper clipPathHelper(context, m_paintLayer, paintingInfo.paintDirtyRect, rootRelativeBounds, rootRelativeBoundsComputed, offsetFromRoot, paintFlags);
Optional<CompositingRecorder> compositingRecorder;
// Blending operations must be performed only with the nearest ancestor stacking context.
@@ -233,34 +251,56 @@ void DeprecatedPaintLayerPainter::paintLayerContents(GraphicsContext* context, c
m_paintLayer.layoutObject()->opacity(), &compositingBounds);
}
- DeprecatedPaintLayerPaintingInfo localPaintingInfo(paintingInfo);
- if (m_paintLayer.compositingState() == PaintsIntoOwnBacking)
- localPaintingInfo.subPixelAccumulation = m_paintLayer.subpixelAccumulation();
-
DeprecatedPaintLayerFragments layerFragments;
if (shouldPaintContent || shouldPaintOutline || isPaintingOverlayScrollbars) {
// Collect the fragments. This will compute the clip rectangles and paint offsets for each layer fragment.
ClipRectsCacheSlot cacheSlot = (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects;
ShouldRespectOverflowClip respectOverflowClip = shouldRespectOverflowClip(paintFlags, m_paintLayer.layoutObject());
- if (fragmentPolicy == ForceSingleFragment)
- m_paintLayer.appendSingleFragmentIgnoringPagination(layerFragments, localPaintingInfo.rootLayer, localPaintingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflowClip, &offsetFromRoot, localPaintingInfo.subPixelAccumulation);
- else
- m_paintLayer.collectFragments(layerFragments, localPaintingInfo.rootLayer, localPaintingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflowClip, &offsetFromRoot, localPaintingInfo.subPixelAccumulation);
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
+ // TODO(trchen): Need to handle layer fragmentation.
+ DeprecatedPaintLayerFragment fragment;
+ fragment.layerBounds = LayoutRect(offsetFromRoot, LayoutSize(m_paintLayer.size()));
+ fragment.backgroundRect = LayoutRect::infiniteRect();
+ fragment.foregroundRect = LayoutRect::infiniteRect();
+ fragment.outlineRect = LayoutRect::infiniteRect();
+ layerFragments.append(fragment);
+ } else if (fragmentPolicy == ForceSingleFragment) {
+ m_paintLayer.appendSingleFragmentIgnoringPagination(layerFragments, paintingInfo.rootLayer, paintingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflowClip, &offsetFromRoot, paintingInfo.subPixelAccumulation);
+ } else {
+ m_paintLayer.collectFragments(layerFragments, paintingInfo.rootLayer, paintingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflowClip, &offsetFromRoot, paintingInfo.subPixelAccumulation);
+ }
+
if (shouldPaintContent)
- shouldPaintContent = atLeastOneFragmentIntersectsDamageRect(layerFragments, localPaintingInfo, paintFlags, offsetFromRoot);
+ shouldPaintContent = atLeastOneFragmentIntersectsDamageRect(layerFragments, paintingInfo, paintFlags, offsetFromRoot);
}
- bool selectionOnly = localPaintingInfo.globalPaintFlags() & GlobalPaintSelectionOnly;
+ bool selectionOnly = paintingInfo.globalPaintFlags() & GlobalPaintSelectionOnly;
// If this layer's layoutObject is a child of the paintingRoot, we paint unconditionally, which
// is done by passing a nil paintingRoot down to our layoutObject (as if no paintingRoot was ever set).
// Else, our layout tree may or may not contain the painting root, so we pass that root along
// so it will be tested against as we descend through the layoutObjects.
LayoutObject* paintingRootForLayoutObject = 0;
- if (localPaintingInfo.paintingRoot && !m_paintLayer.layoutObject()->isDescendantOf(localPaintingInfo.paintingRoot))
- paintingRootForLayoutObject = localPaintingInfo.paintingRoot;
+ if (paintingInfo.paintingRoot && !m_paintLayer.layoutObject()->isDescendantOf(paintingInfo.paintingRoot))
+ paintingRootForLayoutObject = paintingInfo.paintingRoot;
{ // Begin block for the lifetime of any filter.
- FilterPainter filterPainter(m_paintLayer, context, offsetFromRoot, layerFragments.isEmpty() ? ClipRect() : layerFragments[0].backgroundRect, localPaintingInfo, paintFlags,
+ // FilterRecorder may mutate paintingInfo.
pdr. 2015/09/03 06:16:59 FilterRecorder -> FilterPainter, but I agree about
trchen 2015/09/04 06:10:14 Revert done.
+ DeprecatedPaintLayerPaintingInfo localPaintingInfo(paintingInfo);
+ localPaintingInfo.clipToDirtyRect = true;
+ ClipRect compositingBound;
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
trchen 2015/09/02 22:55:37 This change is unnecessary at this moment. Probabl
+ // Similar to transparency clip above, for SPv2 the compositing bound is only
+ // known since layerization and impl-side animation has been applied.
+ compositingBound = localPaintingInfo.paintDirtyRect;
+ } else if (!layerFragments.isEmpty()) {
+ // TODO(trchen): Using layerFragments[0].backgroundRect as compositing bound is
+ // incorrect. Using the union of the fragment clip rects could be a workaround
+ // but is still wrong in operation order. Conceptually it should be equivalent
+ // as painting the filtered stacking context as a whole, then cut the results into
+ // fragments for pasting.
+ compositingBound = layerFragments[0].backgroundRect;
+ }
+ FilterPainter filterPainter(m_paintLayer, context, offsetFromRoot, compositingBound, localPaintingInfo, paintFlags,
rootRelativeBounds, rootRelativeBoundsComputed);
bool shouldPaintBackground = isPaintingCompositedBackground && shouldPaintContent && !selectionOnly;
@@ -270,15 +310,15 @@ void DeprecatedPaintLayerPainter::paintLayerContents(GraphicsContext* context, c
bool shouldPaintOverlayScrollbars = isPaintingOverlayScrollbars;
if (shouldPaintBackground) {
- paintBackgroundForFragments(layerFragments, context, paintingInfo.paintDirtyRect,
+ paintBackgroundForFragments(layerFragments, context, localPaintingInfo.paintDirtyRect,
localPaintingInfo, paintingRootForLayoutObject, paintFlags);
}
if (shouldPaintNegZOrderList)
- paintChildren(NegativeZOrderChildren, context, paintingInfo, paintFlags);
+ paintChildren(NegativeZOrderChildren, context, localPaintingInfo, paintFlags);
if (shouldPaintOwnContents) {
- paintForegroundForFragments(layerFragments, context, paintingInfo.paintDirtyRect,
+ paintForegroundForFragments(layerFragments, context, localPaintingInfo.paintDirtyRect,
localPaintingInfo, paintingRootForLayoutObject, selectionOnly, paintFlags);
}
@@ -286,7 +326,7 @@ void DeprecatedPaintLayerPainter::paintLayerContents(GraphicsContext* context, c
paintOutlineForFragments(layerFragments, context, localPaintingInfo, paintingRootForLayoutObject, paintFlags);
if (shouldPaintNormalFlowAndPosZOrderLists)
- paintChildren(NormalFlowChildren | PositiveZOrderChildren, context, paintingInfo, paintFlags);
+ paintChildren(NormalFlowChildren | PositiveZOrderChildren, context, localPaintingInfo, paintFlags);
if (shouldPaintOverlayScrollbars)
paintOverflowControlsForFragments(layerFragments, context, localPaintingInfo, paintFlags);
@@ -296,15 +336,18 @@ void DeprecatedPaintLayerPainter::paintLayerContents(GraphicsContext* context, c
bool shouldPaintClippingMask = (paintFlags & PaintLayerPaintingChildClippingMaskPhase) && shouldPaintContent && !selectionOnly;
if (shouldPaintMask)
- paintMaskForFragments(layerFragments, context, localPaintingInfo, paintingRootForLayoutObject, paintFlags);
+ paintMaskForFragments(layerFragments, context, paintingInfo, paintingRootForLayoutObject, paintFlags);
if (shouldPaintClippingMask) {
// Paint the border radius mask for the fragments.
- paintChildClippingMaskForFragments(layerFragments, context, localPaintingInfo, paintingRootForLayoutObject, paintFlags);
+ paintChildClippingMaskForFragments(layerFragments, context, paintingInfo, paintingRootForLayoutObject, paintFlags);
}
}
bool DeprecatedPaintLayerPainter::needsToClip(const DeprecatedPaintLayerPaintingInfo& localPaintingInfo, const ClipRect& clipRect)
{
+ // With SPv2 a layer clips its descendants so a layer never clips itself.
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
+ return false;
return clipRect.rect() != localPaintingInfo.paintDirtyRect || clipRect.hasRadius();
}
@@ -323,7 +366,7 @@ bool DeprecatedPaintLayerPainter::atLeastOneFragmentIntersectsDamageRect(Depreca
// (i.e. only contains an overflow portion of the layer), intersection will fail. The reason
// for this is that fragment.layerBounds is set to the border box, not the bounding box, of
// the layer.
- if (m_paintLayer.intersectsDamageRect(fragment.layerBounds, fragment.backgroundRect.rect(), localPaintingInfo.rootLayer, &newOffsetFromRoot))
+ if (m_paintLayer.intersectsDamageRect(fragment.layerBounds, fragment.backgroundRect.rect(), nullptr, &newOffsetFromRoot))
return true;
}
return false;
@@ -421,6 +464,11 @@ void DeprecatedPaintLayerPainter::paintChildren(unsigned childrenToVisit, Graphi
LayerListMutationDetector mutationChecker(m_paintLayer.stackingNode());
#endif
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
+ paintChildrenWithFullScrollClipChain(childrenToVisit, context, paintingInfo, paintFlags);
+ return;
+ }
+
IntSize scrollOffsetAccumulation = paintingInfo.scrollOffsetAccumulation;
if (m_paintLayer.layoutObject()->hasOverflowClip())
scrollOffsetAccumulation += m_paintLayer.layoutBox()->scrolledContentOffset();
@@ -445,6 +493,77 @@ void DeprecatedPaintLayerPainter::paintChildren(unsigned childrenToVisit, Graphi
}
}
+static void recursivelyScrollAndPaintChildLayer(Vector<DeprecatedPaintLayer*>& clippingAncestors, DeprecatedPaintLayer& child, GraphicsContext& context, const DeprecatedPaintLayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags)
+{
pdr. 2015/09/03 06:16:59 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enab
trchen 2015/09/04 06:10:15 Done.
+ if (clippingAncestors.isEmpty()) {
+ DeprecatedPaintLayerPainter(child).paintLayer(&context, paintingInfo, paintFlags);
+ return;
+ }
+ DeprecatedPaintLayer* layer = clippingAncestors.last();
+ clippingAncestors.removeLast();
+
+ ASSERT(layer->layoutObject()->hasOverflowClip() && layer->layoutObject()->isBox());
+ LayoutPoint paintOffset = toLayoutPoint(paintingInfo.subPixelAccumulation);
+ // TODO(trchen): Hey this is slow. We should be able to calculate this on traversal.
+ layer->convertToLayerCoords(paintingInfo.rootLayer, paintOffset, DeprecatedPaintLayer::ExcludeScroll);
+ LayerClipRecorder clipRecorder(context, *layer->layoutBox(), paintOffset);
+
+ IntSize scrollOffset = layer->layoutBox()->scrolledContentOffset();
pdr. 2015/09/03 06:16:59 Don't we need to emit a scroll recorder even if th
trchen 2015/09/04 06:10:15 Isn't it the first clause on line 513?
+ Optional<ScrollRecorder> scrollRecorder;
+ if (layer->scrollsOverflow() || !scrollOffset.isZero())
+ scrollRecorder.emplace(context, *layer->layoutObject(), PaintPhaseBlockBackground, scrollOffset);
+ recursivelyScrollAndPaintChildLayer(clippingAncestors, child, context, paintingInfo, paintFlags);
+}
+
+// TODO(trchen): Measure performance of this and implement display item de-duping if needed.
+// For the pessimistic case this function will generate O(n^2) of clip/scroll pairs, for example:
+// <div style="overflow:scroll;"> * repeat 100 times
+// <div style="position:relative;"></div> * repeat 100 times
+// We will need to generate 100 clip/scroll pairs for each of the in-flow positioned children.
+void DeprecatedPaintLayerPainter::paintChildrenWithFullScrollClipChain(unsigned childrenToVisit, GraphicsContext* context, const DeprecatedPaintLayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags)
+{
+ ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
+
+ DeprecatedPaintLayerStackingNodeIterator iterator(*m_paintLayer.stackingNode(), childrenToVisit);
+ while (DeprecatedPaintLayerStackingNode* childNode = iterator.next()) {
+ DeprecatedPaintLayer* child = childNode->layer();
+ EPosition childPosition = child->layoutObject()->style()->position();
+ if (childPosition == FixedPosition) {
+ ASSERT(paintingInfo.rootLayer == child->enclosingPositionedAncestor());
+ // TODO(trchen): Handle the insanity with reflection + fixed position.
+ LayerFixedPositionRecorder fixedPositionRecorder(*context, *child->layoutObject(), *paintingInfo.rootLayer->layoutObject());
+ DeprecatedPaintLayerPainter(*child).paintLayer(context, paintingInfo, paintFlags);
+ continue;
+ }
+
+ Vector<DeprecatedPaintLayer*> clippingAncestors;
+ DeprecatedPaintLayer* currentLayer = child;
+ while (currentLayer && currentLayer != &m_paintLayer) {
+ EPosition position = currentLayer->layoutObject()->style()->position();
+ ASSERT(position != FixedPosition);
+
+ DeprecatedPaintLayer* container = nullptr;
+ if (position == AbsolutePosition) {
+ bool ranPastThisLayer;
+ container = currentLayer->enclosingPositionedAncestor(&m_paintLayer, &ranPastThisLayer);
+ if (ranPastThisLayer)
+ break;
+ } else {
+ container = currentLayer->parent();
+ }
+ if (!container)
+ break;
+
+ if (container->layoutObject()->hasOverflowClip())
+ clippingAncestors.append(container);
+
+ currentLayer = container;
+ }
+
+ recursivelyScrollAndPaintChildLayer(clippingAncestors, *child, *context, paintingInfo, paintFlags);
+ }
+}
+
// FIXME: inline this.
static bool paintForFixedRootBackground(const DeprecatedPaintLayer* layer, PaintLayerFlags paintFlags)
{
@@ -482,6 +601,13 @@ void DeprecatedPaintLayerPainter::paintFragmentWithPhase(PaintPhase phase, const
{
ASSERT(m_paintLayer.isSelfPaintingLayer());
+ if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
+ PaintInfo paintInfo(context, enclosingIntRect(paintingInfo.paintDirtyRect), phase, paintingInfo.globalPaintFlags(), paintFlags, paintingRootForLayoutObject, paintingInfo.rootLayer->layoutObject());
+ LayoutPoint paintOffset = toPoint(fragment.layerBounds.location() - m_paintLayer.layoutBoxLocation());
+ m_paintLayer.layoutObject()->paint(paintInfo, paintOffset);
+ return;
+ }
+
Optional<LayerClipRecorder> clipRecorder;
if (clipState != HasClipped && paintingInfo.clipToDirtyRect && needsToClip(paintingInfo, clipRect)) {
DisplayItem::Type clipType = DisplayItem::paintPhaseToClipLayerFragmentType(phase);

Powered by Google App Engine
This is Rietveld 408576698