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 { ...@@ -24,10 +24,6 @@ enum ClipRectsCacheSlot {
// crbug.com/783532. // crbug.com/783532.
kAbsoluteClipRectsIgnoringViewportClip, kAbsoluteClipRectsIgnoringViewportClip,
// Relative to painting ancestor. Used for pre-CompositeAfterPaint
// compositing.
kPaintingClipRects,
kNumberOfClipRectsCacheSlots, kNumberOfClipRectsCacheSlots,
kUncachedClipRects, kUncachedClipRects,
}; };
......
...@@ -440,8 +440,6 @@ bool PaintLayerCompositor::AllocateOrClearCompositedLayerMapping( ...@@ -440,8 +440,6 @@ bool PaintLayerCompositor::AllocateOrClearCompositedLayerMapping(
if (!composited_layer_mapping_changed) if (!composited_layer_mapping_changed)
return false; return false;
layer->ClearClipRects(kPaintingClipRects);
return true; return true;
} }
......
...@@ -2703,7 +2703,7 @@ void PaintLayer::ExpandRectForStackingChildren( ...@@ -2703,7 +2703,7 @@ void PaintLayer::ExpandRectForStackingChildren(
PhysicalRect PaintLayer::BoundingBoxForCompositing() const { PhysicalRect PaintLayer::BoundingBoxForCompositing() const {
return BoundingBoxForCompositingInternal( return BoundingBoxForCompositingInternal(
*this, nullptr, kMaybeIncludeTransformForAncestorLayer); *this, nullptr, kIncludeClipsAndMaybeIncludeTransformForAncestorLayer);
} }
bool PaintLayer::ShouldApplyTransformToBoundingBox( bool PaintLayer::ShouldApplyTransformToBoundingBox(
...@@ -2716,7 +2716,7 @@ bool PaintLayer::ShouldApplyTransformToBoundingBox( ...@@ -2716,7 +2716,7 @@ bool PaintLayer::ShouldApplyTransformToBoundingBox(
if (PaintsWithTransform(kGlobalPaintNormalPhase)) { if (PaintsWithTransform(kGlobalPaintNormalPhase)) {
if (this != &composited_layer) if (this != &composited_layer)
return true; return true;
if (options == kMaybeIncludeTransformForAncestorLayer) if (options == kIncludeClipsAndMaybeIncludeTransformForAncestorLayer)
return true; return true;
} }
return false; return false;
...@@ -2754,21 +2754,21 @@ PhysicalRect PaintLayer::BoundingBoxForCompositingInternal( ...@@ -2754,21 +2754,21 @@ PhysicalRect PaintLayer::BoundingBoxForCompositingInternal(
if (GetLayoutObject().IsLayoutFlowThread()) if (GetLayoutObject().IsLayoutFlowThread())
return PhysicalRect(); return PhysicalRect();
// If there is a clip applied by an ancestor to this PaintLayer but below or PhysicalRect result;
// equal to |ancestorLayer|, apply that clip. if (options == kIncludeClipsAndMaybeIncludeTransformForAncestorLayer) {
// // If there is a clip applied by an ancestor to this PaintLayer but below or
// There are two callsites to BoundingBoxForCompositingInternal: one in // equal to |ancestorLayer|, apply that clip. This optimizes the size
// pre-paint for filter bouonding boxes, and one in compositing. The former // of the composited layer to exclude clipped-out regions of descendants.
// can't use GeometryMapper yet because of circularity between result = Clipper((GetLayoutObject().GetDocument().Lifecycle().GetState() ==
// LocalBorderBoxProperties and filters being set on the property trees. DocumentLifecycle::kInCompositingAssignmentsUpdate)
PhysicalRect result = ? GeometryMapperOption::kUseGeometryMapper
Clipper((GetLayoutObject().GetDocument().Lifecycle().GetState() == : GeometryMapperOption::kUseGeometryMapper)
DocumentLifecycle::kInCompositingAssignmentsUpdate) .LocalClipRect(composited_layer);
? GeometryMapperOption::kUseGeometryMapper
: GeometryMapperOption::kDoNotUseGeometryMapper) result.Intersect(LocalBoundingBox());
.LocalClipRect(composited_layer); } else {
result = LocalBoundingBox();
result.Intersect(LocalBoundingBox()); }
ExpandRectForStackingChildren(composited_layer, result, options); ExpandRectForStackingChildren(composited_layer, result, options);
......
...@@ -461,7 +461,7 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient { ...@@ -461,7 +461,7 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
// |ancestorLayer| may be applied to the bounding box, in particular if // |ancestorLayer| may be applied to the bounding box, in particular if
// paintsWithTransform() is true. // paintsWithTransform() is true.
enum CalculateBoundsOptions { enum CalculateBoundsOptions {
kMaybeIncludeTransformForAncestorLayer, kIncludeClipsAndMaybeIncludeTransformForAncestorLayer,
kIncludeTransformsAndCompositedChildLayers, kIncludeTransformsAndCompositedChildLayers,
}; };
......
...@@ -218,56 +218,40 @@ void PaintLayerClipper::ClearClipRectsIncludingDescendants( ...@@ -218,56 +218,40 @@ void PaintLayerClipper::ClearClipRectsIncludingDescendants(
PhysicalRect PaintLayerClipper::LocalClipRect( PhysicalRect PaintLayerClipper::LocalClipRect(
const PaintLayer& clipping_root_layer) const { const PaintLayer& clipping_root_layer) const {
DCHECK(use_geometry_mapper_);
ClipRectsContext context( ClipRectsContext context(
&clipping_root_layer, &clipping_root_layer,
&clipping_root_layer.GetLayoutObject().FirstFragment(), &clipping_root_layer.GetLayoutObject().FirstFragment(),
kPaintingClipRects); kUncachedClipRects);
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);
if (background_rect.IsInfinite()) ClipRect clip_rect;
return background_rect.Rect(); CalculateBackgroundClipRectWithGeometryMapper(
context, layer_.GetLayoutObject().FirstFragment(), kRespectOverflowClip,
PhysicalRect clip_rect = background_rect.Rect(); clip_rect);
PhysicalOffset clipping_root_offset;
layer_.ConvertToLayerCoords(&clipping_root_layer, clipping_root_offset); if (clip_rect.IsInfinite())
clip_rect.Move(-clipping_root_offset); return clip_rect.Rect();
return clip_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( void PaintLayerClipper::CalculateRectsWithGeometryMapper(
......
...@@ -336,7 +336,7 @@ TEST_F(PaintLayerClipperTest, ContainPaintClip) { ...@@ -336,7 +336,7 @@ TEST_F(PaintLayerClipperTest, ContainPaintClip) {
PaintLayer* layer = PaintLayer* layer =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer(); ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context( ClipRectsContext context(
layer, &layer->GetLayoutObject().FirstFragment(), kPaintingClipRects, layer, &layer->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip); kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect layer_bounds; PhysicalRect layer_bounds;
ClipRect background_rect, foreground_rect; ClipRect background_rect, foreground_rect;
...@@ -373,7 +373,7 @@ TEST_F(PaintLayerClipperTest, NestedContainPaintClip) { ...@@ -373,7 +373,7 @@ TEST_F(PaintLayerClipperTest, NestedContainPaintClip) {
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer(); ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context( ClipRectsContext context(
layer->Parent(), &layer->Parent()->GetLayoutObject().FirstFragment(), layer->Parent(), &layer->Parent()->GetLayoutObject().FirstFragment(),
kPaintingClipRects, kIgnorePlatformOverlayScrollbarSize, kUncachedClipRects, kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClip); kIgnoreOverflowClip);
PhysicalRect layer_bounds; PhysicalRect layer_bounds;
ClipRect background_rect, foreground_rect; ClipRect background_rect, foreground_rect;
...@@ -623,7 +623,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithCSSClip) { ...@@ -623,7 +623,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithCSSClip) {
PaintLayer* target = PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer(); ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context( ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects, root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip); kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect()); PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect); PhysicalRect layer_bounds(infinite_rect);
...@@ -658,7 +658,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithOverflowClip) { ...@@ -658,7 +658,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithOverflowClip) {
PaintLayer* target = PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer(); ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context( ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects, root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip); kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect()); PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect); PhysicalRect layer_bounds(infinite_rect);
...@@ -694,7 +694,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithBothClip) { ...@@ -694,7 +694,7 @@ TEST_F(PaintLayerClipperTest, IgnoreRootLayerClipWithBothClip) {
PaintLayer* target = PaintLayer* target =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer(); ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ClipRectsContext context( ClipRectsContext context(
root, &root->GetLayoutObject().FirstFragment(), kPaintingClipRects, root, &root->GetLayoutObject().FirstFragment(), kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip); kIgnorePlatformOverlayScrollbarSize, kIgnoreOverflowClip);
PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect()); PhysicalRect infinite_rect(LayoutRect::InfiniteIntRect());
PhysicalRect layer_bounds(infinite_rect); 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