Commit 852b79ac authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Stop excluding clips when computing filter bounding boxes

The code was added not for this use case, but to ensure that
composited bounds were optimized to avoid parts of descendants
that were clipped out.

This change also unblocks deleting some code and removing one
cache slot, which will save memory on PaintLayer.

Change-Id: I0ca7592ab3609a784bedd095e0c7fb4315b7527a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353872Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798251}
parent 423fd591
......@@ -24,10 +24,6 @@ enum ClipRectsCacheSlot {
// crbug.com/783532.
kAbsoluteClipRectsIgnoringViewportClip,
// Relative to painting ancestor. Used for pre-CompositeAfterPaint
// compositing.
kPaintingClipRects,
kNumberOfClipRectsCacheSlots,
kUncachedClipRects,
};
......
......@@ -440,8 +440,6 @@ bool PaintLayerCompositor::AllocateOrClearCompositedLayerMapping(
if (!composited_layer_mapping_changed)
return false;
layer->ClearClipRects(kPaintingClipRects);
return true;
}
......
......@@ -2703,7 +2703,7 @@ void PaintLayer::ExpandRectForStackingChildren(
PhysicalRect PaintLayer::BoundingBoxForCompositing() const {
return BoundingBoxForCompositingInternal(
*this, nullptr, kMaybeIncludeTransformForAncestorLayer);
*this, nullptr, kIncludeClipsAndMaybeIncludeTransformForAncestorLayer);
}
bool PaintLayer::ShouldApplyTransformToBoundingBox(
......@@ -2716,7 +2716,7 @@ bool PaintLayer::ShouldApplyTransformToBoundingBox(
if (PaintsWithTransform(kGlobalPaintNormalPhase)) {
if (this != &composited_layer)
return true;
if (options == kMaybeIncludeTransformForAncestorLayer)
if (options == kIncludeClipsAndMaybeIncludeTransformForAncestorLayer)
return true;
}
return false;
......@@ -2754,21 +2754,21 @@ PhysicalRect PaintLayer::BoundingBoxForCompositingInternal(
if (GetLayoutObject().IsLayoutFlowThread())
return PhysicalRect();
// If there is a clip applied by an ancestor to this PaintLayer but below or
// equal to |ancestorLayer|, apply that clip.
//
// There are two callsites to BoundingBoxForCompositingInternal: one in
// pre-paint for filter bouonding boxes, and one in compositing. The former
// can't use GeometryMapper yet because of circularity between
// LocalBorderBoxProperties and filters being set on the property trees.
PhysicalRect result =
Clipper((GetLayoutObject().GetDocument().Lifecycle().GetState() ==
DocumentLifecycle::kInCompositingAssignmentsUpdate)
? GeometryMapperOption::kUseGeometryMapper
: GeometryMapperOption::kDoNotUseGeometryMapper)
.LocalClipRect(composited_layer);
result.Intersect(LocalBoundingBox());
PhysicalRect result;
if (options == kIncludeClipsAndMaybeIncludeTransformForAncestorLayer) {
// If there is a clip applied by an ancestor to this PaintLayer but below or
// equal to |ancestorLayer|, apply that clip. This optimizes the size
// of the composited layer to exclude clipped-out regions of descendants.
result = Clipper((GetLayoutObject().GetDocument().Lifecycle().GetState() ==
DocumentLifecycle::kInCompositingAssignmentsUpdate)
? GeometryMapperOption::kUseGeometryMapper
: GeometryMapperOption::kUseGeometryMapper)
.LocalClipRect(composited_layer);
result.Intersect(LocalBoundingBox());
} else {
result = LocalBoundingBox();
}
ExpandRectForStackingChildren(composited_layer, result, options);
......
......@@ -461,7 +461,7 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
// |ancestorLayer| may be applied to the bounding box, in particular if
// paintsWithTransform() is true.
enum CalculateBoundsOptions {
kMaybeIncludeTransformForAncestorLayer,
kIncludeClipsAndMaybeIncludeTransformForAncestorLayer,
kIncludeTransformsAndCompositedChildLayers,
};
......
......@@ -218,56 +218,40 @@ void PaintLayerClipper::ClearClipRectsIncludingDescendants(
PhysicalRect PaintLayerClipper::LocalClipRect(
const PaintLayer& clipping_root_layer) const {
DCHECK(use_geometry_mapper_);
ClipRectsContext context(
&clipping_root_layer,
&clipping_root_layer.GetLayoutObject().FirstFragment(),
kPaintingClipRects);
if (use_geometry_mapper_) {
ClipRect clip_rect;
CalculateBackgroundClipRectWithGeometryMapper(
context, layer_.GetLayoutObject().FirstFragment(), kRespectOverflowClip,
clip_rect);
if (clip_rect.IsInfinite())
return clip_rect.Rect();
PhysicalRect premapped_rect = clip_rect.Rect();
// The rect now needs to be transformed to the local space of this
// PaintLayer.
// TODO(chrishtr): not correct for fragmentation.
premapped_rect.Move(context.root_fragment->PaintOffset());
const auto& clip_root_layer_transform =
context.root_fragment->LocalBorderBoxProperties().Transform();
const auto& layer_transform = layer_.GetLayoutObject()
.FirstFragment()
.LocalBorderBoxProperties()
.Transform();
FloatRect clipped_rect_in_local_space(premapped_rect);
GeometryMapper::SourceToDestinationRect(clip_root_layer_transform,
layer_transform,
clipped_rect_in_local_space);
// TODO(chrishtr): not correct for fragmentation.
clipped_rect_in_local_space.MoveBy(
-FloatPoint(layer_.GetLayoutObject().FirstFragment().PaintOffset()));
return PhysicalRect::FastAndLossyFromFloatRect(clipped_rect_in_local_space);
}
PhysicalRect layer_bounds;
ClipRect background_rect, foreground_rect;
CalculateRects(context, nullptr, nullptr, layer_bounds, background_rect,
foreground_rect);
kUncachedClipRects);
if (background_rect.IsInfinite())
return background_rect.Rect();
PhysicalRect clip_rect = background_rect.Rect();
PhysicalOffset clipping_root_offset;
layer_.ConvertToLayerCoords(&clipping_root_layer, clipping_root_offset);
clip_rect.Move(-clipping_root_offset);
return clip_rect;
ClipRect clip_rect;
CalculateBackgroundClipRectWithGeometryMapper(
context, layer_.GetLayoutObject().FirstFragment(), kRespectOverflowClip,
clip_rect);
if (clip_rect.IsInfinite())
return clip_rect.Rect();
PhysicalRect premapped_rect = clip_rect.Rect();
// The rect now needs to be transformed to the local space of this
// PaintLayer.
// TODO(chrishtr): not correct for fragmentation.
premapped_rect.Move(context.root_fragment->PaintOffset());
const auto& clip_root_layer_transform =
context.root_fragment->LocalBorderBoxProperties().Transform();
const auto& layer_transform = layer_.GetLayoutObject()
.FirstFragment()
.LocalBorderBoxProperties()
.Transform();
FloatRect clipped_rect_in_local_space(premapped_rect);
GeometryMapper::SourceToDestinationRect(
clip_root_layer_transform, layer_transform, clipped_rect_in_local_space);
// TODO(chrishtr): not correct for fragmentation.
clipped_rect_in_local_space.MoveBy(
-FloatPoint(layer_.GetLayoutObject().FirstFragment().PaintOffset()));
return PhysicalRect::FastAndLossyFromFloatRect(clipped_rect_in_local_space);
}
void PaintLayerClipper::CalculateRectsWithGeometryMapper(
......
......@@ -336,7 +336,7 @@ TEST_F(PaintLayerClipperTest, ContainPaintClip) {
PaintLayer* layer =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context(
layer, &layer->GetLayoutObject().FirstFragment(), kPaintingClipRects,
layer, &layer->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect layer_bounds;
ClipRect background_rect, foreground_rect;
......@@ -373,7 +373,7 @@ TEST_F(PaintLayerClipperTest, NestedContainPaintClip) {
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context(
layer->Parent(), &layer->Parent()->GetLayoutObject().FirstFragment(),
kPaintingClipRects, kIgnorePlatformOverlayScrollbarSize,
kUncachedClipRects, kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClip);
PhysicalRect layer_bounds;
ClipRect background_rect, foreground_rect;
......@@ -623,7 +623,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithCSSClip) {
PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects,
root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect);
......@@ -658,7 +658,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithOverflowClip) {
PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects,
root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect);
......@@ -694,7 +694,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithBothClip) {
PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects,
root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment