Bug 1195788 - Set arithmetic composite clamp to true for D2D filter node. r=bas a=sylvestre
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 29 Dec 2015 09:48:37 +1100
changeset 310591 df26cbee3d0c43a7bac2a9ff1b6441a83a4b7a9a
parent 310590 a02979f26a2ff26f006cef5bf42756efc9d718b4
child 310592 f872e1fe79591384e191747c3e630ef9f1433bae
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, sylvestre
bugs1195788
milestone45.0a2
Bug 1195788 - Set arithmetic composite clamp to true for D2D filter node. r=bas a=sylvestre
gfx/2d/FilterNodeD2D1.cpp
layout/reftests/svg/filters/feComposite-2-ref.svg
layout/reftests/svg/filters/feComposite-2.svg
--- a/gfx/2d/FilterNodeD2D1.cpp
+++ b/gfx/2d/FilterNodeD2D1.cpp
@@ -570,16 +570,20 @@ FilterNodeD2D1::Create(ID2D1DeviceContex
 
   hr = aDC->CreateEffect(GetCLDIDForFilterType(aType), getter_AddRefs(effect));
 
   if (FAILED(hr) || !effect) {
     gfxCriticalErrorOnce() << "Failed to create effect for FilterType: " << hexa(hr);
     return nullptr;
   }
 
+  if (aType == FilterType::ARITHMETIC_COMBINE) {
+    effect->SetValue(D2D1_ARITHMETICCOMPOSITE_PROP_CLAMP_OUTPUT, TRUE);
+  }
+
   RefPtr<FilterNodeD2D1> filter = new FilterNodeD2D1(effect, aType);
 
   if (HasUnboundedOutputRegion(aType)) {
     // These filters can produce non-transparent output from transparent
     // input pixels, and we want them to have an unbounded output region.
     filter = new FilterNodeExtendInputAdapterD2D1(aDC, filter, aType);
   }
 
--- a/layout/reftests/svg/filters/feComposite-2-ref.svg
+++ b/layout/reftests/svg/filters/feComposite-2-ref.svg
@@ -1,7 +1,9 @@
 <svg xmlns="http://www.w3.org/2000/svg">
 
 <rect x="0" y="0" width="50" height="100" fill="#00ff00"/>
 <rect x="0" y="0" width="50" height="100" fill="#ff0000" opacity="0.5"/>
 <rect x="50" y="0" width="50" height="100" fill="#ff0000" opacity="0.5"/>
 
+<rect x="100" y="0" width="50" height="100" fill="#808080"/>
+
 </svg>
--- a/layout/reftests/svg/filters/feComposite-2.svg
+++ b/layout/reftests/svg/filters/feComposite-2.svg
@@ -5,9 +5,23 @@
   <feComposite style="color-interpolation-filters:sRGB"
    in="flood" operator="over" in2="SourceGraphic"/>
 </filter>
 <g filter="url(#f1)">
   <rect x="0" y="0" width="50" height="100" fill="#00ff00"/>
   <rect x="50" y="0" width="50" height="100" fill="#00ff00" opacity="0"/>
 </g>
 
+<!-- Test that the arithmetic operator actually clamp the result -->
+<filter id="f2" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse" style="color-interpolation-filters:sRGB">
+  <feFlood flood-color="#ffffff" result="flood" x="100" y="0" width="50" height="100"/>
+  <feComposite result="c" in="SourceGraphic" in2="flood" operator="arithmetic" k2="1" k3="1"/>
+  <feComponentTransfer in="c">
+    <feFuncR type="linear" slope="0.5"/>
+    <feFuncG type="linear" slope="0.5"/>
+    <feFuncB type="linear" slope="0.5"/>
+  </feComponentTransfer>
+</filter>
+<g filter="url(#f2)">
+  <rect x="100" y="0" width="50" height="100" fill="#ff0000"/>
+</g>
+
 </svg>