commit b1ef8e49dd8db810cf5aef0f17fb8dee7e6587b9
parent deac8c7da7d2f66b18f20a95b12a0e867185ca7d
Author: longsonr <longsonr@gmail.com>
Date: Sat, 1 Nov 2025 00:32:17 +0000
Bug 1997670 - feMorphology should work if one of the radii is zero and the other is not r=layout-reviewers,dshin
Differential Revision: https://phabricator.services.mozilla.com/D270916
Diffstat:
5 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/gfx/src/FilterSupport.cpp b/gfx/src/FilterSupport.cpp
@@ -771,15 +771,15 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
int32_t rx = radii.width;
int32_t ry = radii.height;
- // Is one of the radii zero or negative, return the input image
- if (rx <= 0 || ry <= 0) {
+ // Are both of the radii zero or negative, return the input image
+ if (rx <= 0 && ry <= 0) {
RefPtr<FilterNode> filter(mSources[0]);
return filter.forget();
}
// Clamp radii to prevent completely insane values:
- rx = std::min(rx, kMorphologyMaxRadius);
- ry = std::min(ry, kMorphologyMaxRadius);
+ rx = std::clamp(rx, 0, kMorphologyMaxRadius);
+ ry = std::clamp(ry, 0, kMorphologyMaxRadius);
MorphologyOperator op = aMorphology.mOperator == SVG_OPERATOR_ERODE
? MORPHOLOGY_OPERATOR_ERODE
diff --git a/layout/reftests/svg/filters/feMorphology-radius-negative-01.svg b/layout/reftests/svg/filters/feMorphology-radius-negative-01.svg
@@ -14,10 +14,6 @@
<filter id="f1">
<feMorphology operator="erode" radius="-1"/>
</filter>
- <filter id="f2">
- <feMorphology operator="erode" radius="-1 50"/>
- </filter>
<rect width="100%" height="100%" fill="red"/>
- <rect width="50%" height="100%" fill="lime" filter="url(#f1)"/>
- <rect x="50%" width="50%" height="100%" fill="lime" filter="url(#f2)"/>
+ <rect width="100%" height="100%" fill="lime" filter="url(#f1)"/>
</svg>
diff --git a/layout/reftests/svg/filters/feMorphology-radius-zero-01.svg b/layout/reftests/svg/filters/feMorphology-radius-zero-01.svg
@@ -14,10 +14,6 @@
<filter id="f1">
<feMorphology operator="erode" radius="0"/>
</filter>
- <filter id="f2">
- <feMorphology operator="erode" radius="0 50"/>
- </filter>
<rect width="100%" height="100%" fill="red"/>
- <rect width="50%" height="100%" fill="lime" filter="url(#f1)"/>
- <rect x="50%" width="50%" height="100%" fill="lime" filter="url(#f2)"/>
+ <rect width="100%" height="100%" fill="lime" filter="url(#f1)"/>
</svg>
diff --git a/layout/reftests/svg/filters/feMorphology-radius-zero-03.svg b/layout/reftests/svg/filters/feMorphology-radius-zero-03.svg
@@ -0,0 +1,23 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+ <title>Test 'feMorphology' with a zero value for its 'radius'</title>
+ <!--
+ From https://bugzilla.mozilla.org/show_bug.cgi?id=1997670
+
+ A single zero value should not disable the primitive effect.
+ -->
+ <filter id="f1">
+ <feMorphology operator="erode" radius="0 50"/>
+ <feMorphology operator="erode" radius="50 0"/>
+ </filter>
+ <filter id="f2">
+ <feMorphology operator="erode" radius="50 50"/>
+ </filter>
+ <rect width="100%" height="100%" fill="none" stroke="lime" stroke-width="100"/>
+
+ <rect width="100%" height="100%" fill="red" filter="url(#f1)"/>
+ <rect width="100%" height="100%" fill="lime" filter="url(#f2)"/>
+</svg>
diff --git a/layout/reftests/svg/filters/reftest.list b/layout/reftests/svg/filters/reftest.list
@@ -124,6 +124,7 @@ fuzzy(0-21,0-1000000) == feGaussianBlur-alpha-01.svg feGaussianBlur-alpha-01-ref
== feMorphology-radius-negative-02.svg pass.svg
== feMorphology-radius-zero-01.svg pass.svg
== feMorphology-radius-zero-02.svg pass.svg
+== feMorphology-radius-zero-03.svg pass.svg
== feTile-large-01.svg pass.svg
== feTile-large-02.svg feTile-large-02-ref.svg