Bug 630657 - masks should respect color-interpolation. r=jwatt
authorRobert Longson <longsonr@gmail.com>
Thu, 29 Sep 2011 15:03:21 +0100
changeset 77857 d8ec90b0a18444be4890dbe127a1e0e7d70f9ede
parent 77856 934fd93abd8678d0215ee8296995cb5b296288bf
child 77858 39d5bb6c6d4d3165dcb10bded80a2aa9da7cb98e
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjwatt
bugs630657
milestone10.0a1
Bug 630657 - masks should respect color-interpolation. r=jwatt
content/svg/content/src/nsSVGMaskElement.cpp
layout/reftests/svg/mask-basic-02-ref.svg
layout/reftests/svg/mask-basic-02.svg
layout/reftests/svg/reftest.list
layout/svg/base/src/nsSVGMaskFrame.cpp
layout/svg/base/src/nsSVGMaskFrame.h
--- a/content/svg/content/src/nsSVGMaskElement.cpp
+++ b/content/svg/content/src/nsSVGMaskElement.cpp
@@ -152,16 +152,17 @@ nsSVGMaskElement::GetEnumInfo()
 NS_IMETHODIMP_(bool)
 nsSVGMaskElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sFEFloodMap,
     sFiltersMap,
     sFontSpecificationMap,
     sGradientStopMap,
+    sGraphicsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
     nsSVGMaskElementBase::IsAttributeMapped(name);
 }
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/mask-basic-02-ref.svg
@@ -0,0 +1,11 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+
+  <title>Reference that mask defaults to sRGB</title>
+
+  <rect width="100" height="100" x="100" y="100"  fill="#FFC0C0"/>
+
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/mask-basic-02.svg
@@ -0,0 +1,17 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+
+  <title>Testcase that mask defaults to sRGB</title>
+
+  <defs>
+    <mask id="mask" maskContentUnits="objectBoundingBox">
+        <rect width="1" height="1" fill="#3f3f3f" />
+    </mask>
+  </defs>
+
+  <rect width="100" height="100" x="100" y="100" mask="url(#mask)" fill="#FF0000"/>
+
+</svg>
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -140,16 +140,17 @@ random == dynamic-use-nested-01.svg dyna
 fails == inline-in-xul-basic-01.xul pass.svg
 == invalid-text-01.svg pass.svg
 == linearGradient-basic-01.svg pass.svg
 == linearGradient-basic-02.svg pass.svg
 == markers-and-group-opacity-01.svg markers-and-group-opacity-01-ref.svg
 == marker-attribute-01.svg pass.svg
 == marker-viewBox-01.svg marker-viewBox-01-ref.svg
 == mask-basic-01.svg pass.svg
+== mask-basic-02.svg mask-basic-02-ref.svg
 == mask-containing-masked-content-01.svg pass.svg
 == mask-transformed-01.svg mask-transformed-01-ref.svg
 == nested-viewBox-01.svg pass.svg
 == nesting-invalid-01.svg nesting-invalid-01-ref.svg
 == objectBoundingBox-and-clipPath.svg pass.svg
 # Bug 588684
 random-if(gtk2Widget) == objectBoundingBox-and-fePointLight-01.svg objectBoundingBox-and-fePointLight-01-ref.svg
 random-if(gtk2Widget) == objectBoundingBox-and-fePointLight-02.svg objectBoundingBox-and-fePointLight-02-ref.svg
--- a/layout/svg/base/src/nsSVGMaskFrame.cpp
+++ b/layout/svg/base/src/nsSVGMaskFrame.cpp
@@ -133,17 +133,20 @@ nsSVGMaskFrame::ComputeMaskAlpha(nsSVGRe
     nsSVGUtils::PaintFrameWithEffects(&tmpState, nsnull, kid);
   }
 
   PRUint8 *data   = image->Data();
   PRInt32  stride = image->Stride();
 
   nsIntRect rect(0, 0, surfaceSize.width, surfaceSize.height);
   nsSVGUtils::UnPremultiplyImageDataAlpha(data, stride, rect);
-  nsSVGUtils::ConvertImageDataToLinearRGB(data, stride, rect);
+  if (GetStyleSVG()->mColorInterpolation ==
+      NS_STYLE_COLOR_INTERPOLATION_LINEARRGB) {
+    nsSVGUtils::ConvertImageDataToLinearRGB(data, stride, rect);
+  }
 
   for (PRInt32 y = 0; y < surfaceSize.height; y++)
     for (PRInt32 x = 0; x < surfaceSize.width; x++) {
       PRUint8 *pixel = data + stride * y + 4 * x;
 
       /* linearRGB -> intensity */
       PRUint8 alpha =
         static_cast<PRUint8>
@@ -155,16 +158,23 @@ nsSVGMaskFrame::ComputeMaskAlpha(nsSVGRe
       memset(pixel, alpha, 4);
     }
 
   gfxPattern *retval = new gfxPattern(image);
   NS_IF_ADDREF(retval);
   return retval;
 }
 
+/* virtual */ void
+nsSVGMaskFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
+{
+  nsSVGEffects::InvalidateRenderingObservers(this);
+  nsSVGMaskFrameBase::DidSetStyleContext(aOldStyleContext);
+}
+
 NS_IMETHODIMP
 nsSVGMaskFrame::AttributeChanged(PRInt32  aNameSpaceID,
                                  nsIAtom* aAttribute,
                                  PRInt32  aModType)
 {
   if (aNameSpaceID == kNameSpaceID_None &&
       (aAttribute == nsGkAtoms::x ||
        aAttribute == nsGkAtoms::y ||
--- a/layout/svg/base/src/nsSVGMaskFrame.h
+++ b/layout/svg/base/src/nsSVGMaskFrame.h
@@ -58,16 +58,18 @@ public:
   NS_DECL_FRAMEARENA_HELPERS
 
   // nsSVGMaskFrame method:
   already_AddRefed<gfxPattern> ComputeMaskAlpha(nsSVGRenderState *aContext,
                                                 nsIFrame* aParent,
                                                 const gfxMatrix &aMatrix,
                                                 float aOpacity = 1.0f);
 
+  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
+
   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
                               nsIAtom*        aAttribute,
                               PRInt32         aModType);
 
 #ifdef DEBUG
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);