Skip to content

Commit 4b267e8

Browse files
committed
corner-shape: backdrop-filter is clipped to the rounded rect, ignoring corner-shape
https://bugs.webkit.org/show_bug.cgi?id=322509 rdar://185813432 Reviewed by Simon Fraser. Give the backdrop layer its own shape path, set from the outer contour when the corners aren't round, and drop the corners from backdropFiltersRect so a shape reaching outside the radius isn't clipped back to it. Passes existing tests * Source/WebCore/platform/graphics/GraphicsLayer.h: (WebCore::GraphicsLayer::setBackdropFiltersShapePath): (WebCore::GraphicsLayer::backdropFiltersShapePath const): * Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::shapePathsAreEqual): (WebCore::GraphicsLayerCA::setContentsClipShapePath): (WebCore::GraphicsLayerCA::setBackdropFiltersShapePath): (WebCore::GraphicsLayerCA::updateBackdropFiltersRect): (WebCore::GraphicsLayerCA::ensureStructuralLayer): (WebCore::contentsClipShapePathsAreEqual): Deleted. * Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h: * Source/WebCore/rendering/RenderLayerBacking.cpp: (WebCore::RenderLayerBacking::updateBackdropFiltersGeometry): * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter-overflow.html: * LayoutTests/imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter.html: * Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.cpp: (WebCore::SkiaCompositingLayer::paintBackdrop): * Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.h: * Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedPlatformLayer.cpp: (WebCore::CoordinatedPlatformLayer::setBackdropShapePath): (WebCore::CoordinatedPlatformLayer::flushCompositingStateOnTarget): (WebCore::CoordinatedPlatformLayer::flushCompositingStateOnSkiaTarget): * Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedPlatformLayer.h: * Source/WebCore/platform/graphics/texmap/coordinated/GraphicsLayerCoordinated.cpp: (WebCore::GraphicsLayerCoordinated::setBackdropFiltersShapePath): (WebCore::GraphicsLayerCoordinated::commitLayerChanges): * Source/WebCore/platform/graphics/texmap/coordinated/GraphicsLayerCoordinated.h: Canonical link: https://commits.webkit.org/320063@main
1 parent d95a22a commit 4b267e8

13 files changed

Lines changed: 87 additions & 15 deletions

File tree

‎LayoutTests/TestExpectations‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6745,9 +6745,7 @@ webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape
67456745
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-stroke-from-border.html [ ImageOnlyFailure ]
67466746
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-two-shapes-shadow.html [ ImageOnlyFailure ]
67476747
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-outline-double.html [ ImageOnlyFailure ]
6748-
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter-overflow.html [ ImageOnlyFailure ]
67496748
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter-video-overflow.html [ ImageOnlyFailure Pass ]
6750-
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter.html [ ImageOnlyFailure ]
67516749
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-clips-background.html [ ImageOnlyFailure ]
67526750
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-collapsed-shape-clips-background.html [ ImageOnlyFailure ]
67536751
webkit.org/b/277912 imported/w3c/web-platform-tests/css/css-borders/border-shape/border-shape-geometry-box.html [ ImageOnlyFailure ]

‎LayoutTests/imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter-overflow.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<head>
33
<link rel="match" href="corner-shape-backdrop-filter-overflow-ref.html">
44
<link rel="help" href="https://drafts.csswg.org/css-borders-4/#corner-shaping">
5-
<meta name="fuzzy" content="maxDifference=0-64;totalPixels=0-360">
5+
<meta name="fuzzy" content="maxDifference=0-93;totalPixels=0-360">
66
<style>
77
.target {
88
width: 200px;

‎LayoutTests/imported/w3c/web-platform-tests/css/css-borders/corner-shape/corner-shape-backdrop-filter.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<head>
33
<link rel="help" href="https://drafts.csswg.org/css-borders-4/#corner-shaping">
44
<link rel="match" href="corner-shape-backdrop-filter-ref.html">
5-
<meta name="fuzzy" content="maxDifference=0-64;totalPixels=0-360">
5+
<meta name="fuzzy" content="maxDifference=0-111;totalPixels=0-381">
66
<style>
77
.target {
88
width: 200px;

‎Source/WebCore/platform/graphics/GraphicsLayer.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ class GraphicsLayer : public RefCountedAndCanMakeWeakPtr<GraphicsLayer> {
316316
virtual void setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect) { m_backdropFiltersRect = backdropFiltersRect; }
317317
const FloatRoundedRect& backdropFiltersRect() const LIFETIME_BOUND { return m_backdropFiltersRect; }
318318

319+
Path backdropFiltersShapePath() const { return m_backdropFiltersShapePath; }
320+
virtual void setBackdropFiltersShapePath(const Path& path) { m_backdropFiltersShapePath = path; }
321+
319322
BlendMode blendMode() const { return m_blendMode; }
320323
virtual void setBlendMode(BlendMode blendMode) { m_blendMode = blendMode; }
321324

@@ -699,6 +702,7 @@ class GraphicsLayer : public RefCountedAndCanMakeWeakPtr<GraphicsLayer> {
699702
ScalingFilter m_contentsMinificationFilter = ScalingFilter::Linear;
700703
ScalingFilter m_contentsMagnificationFilter = ScalingFilter::Linear;
701704
FloatRoundedRect m_backdropFiltersRect;
705+
Path m_backdropFiltersShapePath;
702706
std::optional<FloatRect> m_animationExtent;
703707

704708
EventRegion m_eventRegion;

‎Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void GraphicsLayerCA::setContentsClippingRect(const FloatRoundedRect& rect)
10711071
noteLayerPropertyChanged(ContentsRectsChanged);
10721072
}
10731073

1074-
static bool contentsClipShapePathsAreEqual(const Path& a, const Path& b)
1074+
static bool shapePathsAreEqual(const Path& a, const Path& b)
10751075
{
10761076
if (a.isEmpty() || b.isEmpty())
10771077
return a.isEmpty() && b.isEmpty();
@@ -1083,13 +1083,22 @@ static bool contentsClipShapePathsAreEqual(const Path& a, const Path& b)
10831083

10841084
void GraphicsLayerCA::setContentsClipShapePath(const Path& path)
10851085
{
1086-
if (contentsClipShapePathsAreEqual(contentsClipShapePath(), path))
1086+
if (shapePathsAreEqual(contentsClipShapePath(), path))
10871087
return;
10881088

10891089
GraphicsLayer::setContentsClipShapePath(path);
10901090
noteLayerPropertyChanged(ContentsRectsChanged);
10911091
}
10921092

1093+
void GraphicsLayerCA::setBackdropFiltersShapePath(const Path& path)
1094+
{
1095+
if (shapePathsAreEqual(backdropFiltersShapePath(), path))
1096+
return;
1097+
1098+
GraphicsLayer::setBackdropFiltersShapePath(path);
1099+
noteLayerPropertyChanged(BackdropFiltersRectChanged);
1100+
}
1101+
10931102
void GraphicsLayerCA::setContentsRectClipsDescendants(bool contentsRectClipsDescendants)
10941103
{
10951104
if (contentsRectClipsDescendants == m_contentsRectClipsDescendants)
@@ -2804,7 +2813,7 @@ void GraphicsLayerCA::updateBackdropFiltersRect()
28042813

28052814
auto backdropRectRelativeToBackdropLayer = m_backdropFiltersRect;
28062815
backdropRectRelativeToBackdropLayer.setLocation({ });
2807-
updateClippingStrategy(*backdropLayer, m_backdropClippingLayer, backdropRectRelativeToBackdropLayer);
2816+
updateClippingStrategy(*backdropLayer, m_backdropClippingLayer, backdropRectRelativeToBackdropLayer, m_backdropFiltersShapePath);
28082817

28092818
if (m_layerClones) {
28102819
for (auto& clone : m_layerClones->backdropLayerClones) {
@@ -2816,7 +2825,7 @@ void GraphicsLayerCA::updateBackdropFiltersRect()
28162825
RefPtr<PlatformCALayer> backdropClippingLayerClone = m_layerClones->backdropClippingLayerClones.get(cloneID);
28172826

28182827
bool hadBackdropClippingLayer = backdropClippingLayerClone;
2819-
updateClippingStrategy(backdropCloneLayer, backdropClippingLayerClone, backdropRectRelativeToBackdropLayer);
2828+
updateClippingStrategy(backdropCloneLayer, backdropClippingLayerClone, backdropRectRelativeToBackdropLayer, m_backdropFiltersShapePath);
28202829

28212830
if (!backdropClippingLayerClone)
28222831
m_layerClones->backdropClippingLayerClones.remove(cloneID);
@@ -3257,9 +3266,9 @@ void GraphicsLayerCA::updateContentsColorLayer()
32573266

32583267
// The clipping strategy depends on whether the rounded rect has equal corner radii.
32593268
// roundedRect is in the coordinate space of clippingLayer.
3260-
void GraphicsLayerCA::updateClippingStrategy(PlatformCALayer& clippingLayer, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect& roundedRect)
3269+
void GraphicsLayerCA::updateClippingStrategy(PlatformCALayer& clippingLayer, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect& roundedRect, const Path& shapePath)
32613270
{
3262-
bool hasShapePath = !contentsClipShapePath().isEmpty();
3271+
bool hasShapePath = !shapePath.isEmpty();
32633272

32643273
#if HAVE(CORE_ANIMATION_SEPARATED_LAYERS)
32653274
if (!hasShapePath && m_isSeparated && roundedRect.radii().hasEvenCorners() && clippingLayer.bounds() == roundedRect.rect()) {
@@ -3296,7 +3305,7 @@ void GraphicsLayerCA::updateClippingStrategy(PlatformCALayer& clippingLayer, Ref
32963305
shapeMaskLayer->setBounds(shapeBounds);
32973306

32983307
if (hasShapePath) {
3299-
auto localPath = contentsClipShapePath();
3308+
auto localPath = shapePath;
33003309
localPath.translate(-toFloatSize(rectLocation));
33013310
shapeMaskLayer->setShapePath(localPath);
33023311
} else {
@@ -3336,7 +3345,7 @@ void GraphicsLayerCA::updateContentsRects()
33363345
contentsClippingLayer->setPosition(m_contentsClippingRect.rect().location());
33373346
contentsClippingLayer->setBounds(m_contentsClippingRect.rect());
33383347

3339-
updateClippingStrategy(contentsClippingLayer, m_contentsShapeMaskLayer, m_contentsClippingRect);
3348+
updateClippingStrategy(contentsClippingLayer, m_contentsShapeMaskLayer, m_contentsClippingRect, contentsClipShapePath());
33403349

33413350
if (RefPtr contentsLayer = m_contentsLayer; contentsLayer && gainedOrLostClippingLayer) {
33423351
contentsLayer->removeFromSuperlayer();
@@ -3379,7 +3388,7 @@ void GraphicsLayerCA::updateContentsRects()
33793388
RefPtr<PlatformCALayer> shapeMaskLayerClone = m_layerClones->contentsShapeMaskLayerClones.get(cloneID);
33803389

33813390
bool hadShapeMask = shapeMaskLayerClone;
3382-
updateClippingStrategy(Ref { clone.value }, shapeMaskLayerClone, m_contentsClippingRect);
3391+
updateClippingStrategy(Ref { clone.value }, shapeMaskLayerClone, m_contentsClippingRect, contentsClipShapePath());
33833392

33843393
if (!shapeMaskLayerClone)
33853394
m_layerClones->contentsShapeMaskLayerClones.remove(cloneID);

‎Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
150150
WEBCORE_EXPORT void setContentsRect(const FloatRect&) override;
151151
WEBCORE_EXPORT void setContentsClippingRect(const FloatRoundedRect&) override;
152152
WEBCORE_EXPORT void setContentsClipShapePath(const Path&) override;
153+
WEBCORE_EXPORT void setBackdropFiltersShapePath(const Path&) override;
153154
WEBCORE_EXPORT void setContentsRectClipsDescendants(bool) override;
154155

155156
WEBCORE_EXPORT void setVideoGravity(MediaPlayerVideoGravity) override;
@@ -388,7 +389,7 @@ class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
388389
void setupContentsLayer(PlatformCALayer*, CompositingCoordinatesOrientation = defaultContentsOrientation);
389390
PlatformCALayer* contentsLayer() const { return m_contentsLayer.get(); }
390391

391-
void updateClippingStrategy(PlatformCALayer&, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect&);
392+
void updateClippingStrategy(PlatformCALayer&, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect&, const Path& shapePath);
392393

393394
WEBCORE_EXPORT void setReplicatedByLayer(RefPtr<GraphicsLayer>&&) override;
394395

‎Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,10 @@ void SkiaCompositingLayer::paintBackdrop(SkCanvas& canvas, PaintContext& context
11891189

11901190
SkAutoCanvasRestore autoRestore(&canvas, true);
11911191
const auto clipTransform = combinedTransform(context);
1192-
clipRect(canvas, m_backdrop.clipRect, clipTransform);
1192+
if (m_backdrop.clipPath)
1193+
canvas.clipPath(m_backdrop.clipPath->makeTransform(SkM44(clipTransform).asM33()), true);
1194+
else
1195+
clipRect(canvas, m_backdrop.clipRect, clipTransform);
11931196

11941197
// Paint the backdrop root's subtree into a fresh surface (spec step 1),
11951198
// apply the backdrop filter (step 2), and composite via SrcOver so the

‎Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SkiaCompositingLayer final : public RefCountedAndCanMakeWeakPtr<SkiaCompos
9696
void setFilters(const FilterOperations&);
9797
void setBackdropFilters(const FilterOperations&);
9898
void setBackdropFiltersRect(const FloatRoundedRect&);
99+
void setBackdropFiltersClipPath(std::optional<SkPath>&& clipPath) { m_backdrop.clipPath = WTF::move(clipPath); }
99100
void setIsBackdropRoot(bool isBackdropRoot) { m_isBackdropRoot = isBackdropRoot; }
100101
void setChildren(Vector<Ref<SkiaCompositingLayer>>&&);
101102

@@ -352,6 +353,7 @@ class SkiaCompositingLayer final : public RefCountedAndCanMakeWeakPtr<SkiaCompos
352353
struct {
353354
sk_sp<SkImageFilter> filter;
354355
FloatRoundedRect clipRect;
356+
std::optional<SkPath> clipPath;
355357
} m_backdrop;
356358
bool m_isBackdropRoot { false };
357359
bool m_shouldBlend { false };

‎Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedPlatformLayer.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,18 @@ void CoordinatedPlatformLayer::setBackdropRect(const FloatRoundedRect& backdropR
727727
notifyCompositionRequired();
728728
}
729729

730+
void CoordinatedPlatformLayer::setBackdropShapePath(const Path& path)
731+
{
732+
assertIsHeld(m_lock);
733+
if (m_backdropShapePath.definitelyEqual(path))
734+
return;
735+
736+
m_backdropShapePath = path;
737+
m_pendingChanges.add(Change::BackdropShapePath);
738+
damageWholeLayer();
739+
notifyCompositionRequired();
740+
}
741+
730742
void CoordinatedPlatformLayer::setIsBackdropRoot(bool isBackdropRoot)
731743
{
732744
assertIsHeld(m_lock);
@@ -1235,6 +1247,13 @@ void CoordinatedPlatformLayer::flushCompositingStateOnTarget(const OptionSet<Com
12351247
m_pendingChanges.remove(Change::BackdropRect);
12361248
}
12371249

1250+
// FIXME: clip the backdrop to the corner-shape contour here too. TextureMapper::beginClip()
1251+
// takes a ClipPath, a triangulated vertex buffer, so this needs a Path tessellation step that
1252+
// does not exist yet; until then a non-round corner shape on a backdrop filter is clipped only
1253+
// by the rounded rect above. The Skia compositor, which GTK and WPE use by default, clips to
1254+
// the contour.
1255+
m_pendingChanges.remove(Change::BackdropShapePath);
1256+
12381257
if (m_pendingChanges.contains(Change::Animations)) {
12391258
layer.setAnimations(m_animations);
12401259
m_pendingChanges.remove(Change::Animations);
@@ -1440,6 +1459,17 @@ void CoordinatedPlatformLayer::flushCompositingStateOnSkiaTarget(const OptionSet
14401459
m_pendingChanges.remove(Change::BackdropRect);
14411460
}
14421461

1462+
if (m_pendingChanges.contains(Change::BackdropShapePath)) {
1463+
if (m_backdropShapePath.isEmpty())
1464+
layer.setBackdropFiltersClipPath(std::nullopt);
1465+
else {
1466+
auto backdropClipPath = *m_backdropShapePath.platformPath();
1467+
backdropClipPath.setFillType(SkPathFillType::kWinding);
1468+
layer.setBackdropFiltersClipPath(WTF::move(backdropClipPath));
1469+
}
1470+
m_pendingChanges.remove(Change::BackdropShapePath);
1471+
}
1472+
14431473
if (m_pendingChanges.contains(Change::BackdropRoot)) {
14441474
layer.setIsBackdropRoot(m_isBackdropRoot);
14451475
m_pendingChanges.remove(Change::BackdropRoot);

‎Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedPlatformLayer.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class CoordinatedPlatformLayer : public ThreadSafeRefCountedAndCanMakeThreadSafe
179179
void setBackdrop(CoordinatedPlatformLayer*) WTF_REQUIRES_LOCK(m_lock);
180180
void notifyBackdropFiltersChanged() WTF_REQUIRES_LOCK(m_lock);
181181
void setBackdropRect(const FloatRoundedRect&) WTF_REQUIRES_LOCK(m_lock);
182+
void setBackdropShapePath(const Path&) WTF_REQUIRES_LOCK(m_lock);
182183
void setIsBackdropRoot(bool) WTF_REQUIRES_LOCK(m_lock);
183184

184185
void setAnimations(const TextureMapperAnimations&) WTF_REQUIRES_LOCK(m_lock);
@@ -241,6 +242,7 @@ class CoordinatedPlatformLayer : public ThreadSafeRefCountedAndCanMakeThreadSafe
241242
Backdrop,
242243
BackdropRect,
243244
BackdropRoot,
245+
BackdropShapePath,
244246
BackfaceVisibility,
245247
BackgroundColor,
246248
BackingStore,
@@ -343,6 +345,7 @@ class CoordinatedPlatformLayer : public ThreadSafeRefCountedAndCanMakeThreadSafe
343345
RefPtr<CoordinatedPlatformLayer> m_replica WTF_GUARDED_BY_LOCK(m_lock);
344346
RefPtr<CoordinatedPlatformLayer> m_backdrop WTF_GUARDED_BY_LOCK(m_lock);
345347
FloatRoundedRect m_backdropRect WTF_GUARDED_BY_LOCK(m_lock);
348+
Path m_backdropShapePath WTF_GUARDED_BY_LOCK(m_lock);
346349
bool m_isBackdropRoot WTF_GUARDED_BY_LOCK(m_lock) { false };
347350
TextureMapperAnimations m_animations WTF_GUARDED_BY_LOCK(m_lock);
348351
ThreadSafeWeakPtr<CoordinatedPlatformLayer> m_parent WTF_GUARDED_BY_LOCK(m_lock);

0 commit comments

Comments
 (0)