Bug 1343436 - Fix filter result for baseFrequency="0" type="fractalNoise". r=longsonr+218550
authorMarkus Stange <mstange@themasta.com>
Wed, 01 Mar 2017 10:03:15 -0500
changeset 374504 55aa0d9957fbecf0808c0ad34ceac81a6466a1b2
parent 374503 3a149a84ce479c5afb8c4e9b965fc1facd86a612
child 374505 f0960b4bd9c435b25c575448e74d8fa0b1b158a4
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1343436, 218550
milestone54.0a1
Bug 1343436 - Fix filter result for baseFrequency="0" type="fractalNoise". r=longsonr+218550 MozReview-Commit-ID: LLAr9ifux98
dom/svg/SVGFETurbulenceElement.cpp
layout/reftests/svg/filters/feTurbulence-zero-baseFreq-ref.svg
layout/reftests/svg/filters/feTurbulence-zero-baseFreq.svg
layout/reftests/svg/filters/reftest.list
--- a/dom/svg/SVGFETurbulenceElement.cpp
+++ b/dom/svg/SVGFETurbulenceElement.cpp
@@ -128,17 +128,24 @@ SVGFETurbulenceElement::GetPrimitiveDesc
   float fX = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eFirst);
   float fY = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eSecond);
   float seed = mNumberAttributes[OCTAVES].GetAnimValue();
   uint32_t octaves = clamped(mIntegerAttributes[OCTAVES].GetAnimValue(), 0, MAX_OCTAVES);
   uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
   uint16_t stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
 
   if (fX == 0 || fY == 0) {
-    return FilterPrimitiveDescription(PrimitiveType::Empty);
+    // A base frequency of zero results in transparent black for
+    // type="turbulence" and in 50% alpha 50% gray for type="fractalNoise".
+    if (type == SVG_TURBULENCE_TYPE_TURBULENCE) {
+      return FilterPrimitiveDescription(PrimitiveType::Empty);
+    }
+    FilterPrimitiveDescription descr(PrimitiveType::Flood);
+    descr.Attributes().Set(eFloodColor, Color(0.5, 0.5, 0.5, 0.5));
+    return descr;
   }
 
   // We interpret the base frequency as relative to user space units. In other
   // words, we consider one turbulence base period to be 1 / fX user space
   // units wide and 1 / fY user space units high. We do not scale the frequency
   // depending on the filter primitive region.
   gfxRect firstPeriodInUserSpace(0, 0, 1 / fX, 1 / fY);
   gfxRect firstPeriodInFilterSpace = aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/filters/feTurbulence-zero-baseFreq-ref.svg
@@ -0,0 +1,13 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!--
+     This is the reference image for feTurbulence-zero-baseFreq.svg.
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+  <rect x="0" y="0" width="400" height="100" fill="blue"/>
+  <rect x="0" y="100" width="400" height="100" fill="lime"/>
+  <!-- nothing in place of the type="turbulence" filter -->
+  <rect x="200" y="50" width="100" height="100" fill="rgba(128, 128, 128, 0.5)"/>
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/filters/feTurbulence-zero-baseFreq.svg
@@ -0,0 +1,23 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!--
+     This test verifies that feTurbulence with baseFrequency="0" creates
+     a transparent black result for type="turbulence" and a 50% alpha
+     50% gray result for type="fractalNoise".
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+  <filter id="filterTurbulence" primitiveUnits="objectBoundingBox" color-interpolation-filters="sRGB">
+    <feTurbulence type="turbulence" baseFrequency="0" numOctaves="1"
+                  x="0%" y="0%" width="100%" height="100%"/>
+  </filter>
+  <filter id="filterFractalNoise" primitiveUnits="objectBoundingBox" color-interpolation-filters="sRGB">
+    <feTurbulence type="fractalNoise" baseFrequency="0" numOctaves="1"
+                  x="0%" y="0%" width="100%" height="100%"/>
+  </filter>
+  <rect x="0" y="0" width="400" height="100" fill="blue"/>
+  <rect x="0" y="100" width="400" height="100" fill="lime"/>
+  <rect x="50" y="50" width="100" height="100" filter="url(#filterTurbulence)"/>
+  <rect x="200" y="50" width="100" height="100" filter="url(#filterFractalNoise)"/>
+</svg>
--- a/layout/reftests/svg/filters/reftest.list
+++ b/layout/reftests/svg/filters/reftest.list
@@ -114,12 +114,13 @@ fuzzy(1,217) == feDiffuseLighting-1.svg 
 
 fuzzy(2,2659) skip-if(d2d) == feSpecularLighting-1.svg feSpecularLighting-1-ref.svg
 
 == filter-lighting-region.svg filter-lighting-region-ref.svg
 
 == fePointLight-zoomed-page.svg fePointLight-zoomed-page-ref.svg
 
 == feTurbulence-offset.svg feTurbulence-offset-ref.svg
+fuzzy(1,10000) == feTurbulence-zero-baseFreq.svg feTurbulence-zero-baseFreq-ref.svg
 
 == outside-sourcegraphic-1.svg outside-sourcegraphic-ref.svg
 == outside-sourcegraphic-2.svg outside-sourcegraphic-ref.svg
 == outside-sourcegraphic-3.svg outside-sourcegraphic-ref.svg