Bug 1202317. Optimize away identity ColorMatrix nodes. r=mstange
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 07 Sep 2015 17:11:35 +1200
changeset 294079 76240ee211cae9cfe4194ae58f0d81fc6940989a
parent 294078 e3a099db7378d957698b73d61aca929fb830adc6
child 294080 f088e6dbb1ba6f27e0fb6bd42ba090b464d3a5df
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1202317
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1202317. Optimize away identity ColorMatrix nodes. r=mstange
gfx/src/FilterSupport.cpp
--- a/gfx/src/FilterSupport.cpp
+++ b/gfx/src/FilterSupport.cpp
@@ -342,38 +342,38 @@ FilterCachedColorModels::WrapForColorMod
   RefPtr<FilterNode> unpremultipliedOriginal =
     ForColorModel(ColorModel(mOriginalColorModel.mColorSpace, AlphaModel::Unpremultiplied));
   if (aColorModel.mColorSpace == ColorSpace::LinearRGB) {
     return FilterWrappers::SRGBToLinearRGB(mDT, unpremultipliedOriginal);
   }
   return FilterWrappers::LinearRGBToSRGB(mDT, unpremultipliedOriginal);
 }
 
+static const float identityMatrix[] =
+  { 1, 0, 0, 0, 0,
+    0, 1, 0, 0, 0,
+    0, 0, 1, 0, 0,
+    0, 0, 0, 1, 0 };
+
 // When aAmount == 0, the identity matrix is returned.
 // When aAmount == 1, aToMatrix is returned.
 // When aAmount > 1, an exaggerated version of aToMatrix is returned. This can
 // be useful in certain cases, such as producing a color matrix to oversaturate
 // an image.
 //
 // This function is a shortcut of a full matrix addition and a scalar multiply,
 // and it assumes that the following elements in aToMatrix are 0 and 1:
 //   x x x 0 0
 //   x x x 0 0
 //   x x x 0 0
 //   0 0 0 1 0
 static void
 InterpolateFromIdentityMatrix(const float aToMatrix[20], float aAmount,
                               float aOutMatrix[20])
 {
-  static const float identityMatrix[] =
-    { 1, 0, 0, 0, 0,
-      0, 1, 0, 0, 0,
-      0, 0, 1, 0, 0,
-      0, 0, 0, 1, 0 };
-
   PodCopy(aOutMatrix, identityMatrix, 20);
 
   float oneMinusAmount = 1 - aAmount;
 
   aOutMatrix[0] = aAmount * aToMatrix[0] + oneMinusAmount;
   aOutMatrix[1] = aAmount * aToMatrix[1];
   aOutMatrix[2] = aAmount * aToMatrix[2];
 
@@ -387,22 +387,16 @@ InterpolateFromIdentityMatrix(const floa
 }
 
 // Create a 4x5 color matrix for the different ways to specify color matrices
 // in SVG.
 static nsresult
 ComputeColorMatrix(uint32_t aColorMatrixType, const nsTArray<float>& aValues,
                    float aOutMatrix[20])
 {
-  static const float identityMatrix[] =
-    { 1, 0, 0, 0, 0,
-      0, 1, 0, 0, 0,
-      0, 0, 1, 0, 0,
-      0, 0, 0, 1, 0 };
-
   // Luminance coefficients.
   static const float lumR = 0.2126f;
   static const float lumG = 0.7152f;
   static const float lumB = 0.0722f;
 
   static const float oneMinusLumR = 1 - lumR;
   static const float oneMinusLumG = 1 - lumG;
   static const float oneMinusLumB = 1 - lumB;
@@ -755,17 +749,18 @@ FilterNodeFromPrimitiveDescription(const
       return filter.forget();
     }
 
     case PrimitiveType::ColorMatrix:
     {
       float colorMatrix[20];
       uint32_t type = atts.GetUint(eColorMatrixType);
       const nsTArray<float>& values = atts.GetFloats(eColorMatrixValues);
-      if (NS_FAILED(ComputeColorMatrix(type, values, colorMatrix))) {
+      if (NS_FAILED(ComputeColorMatrix(type, values, colorMatrix)) ||
+          PodEqual(colorMatrix, identityMatrix)) {
         RefPtr<FilterNode> filter(aSources[0]);
         return filter.forget();
       }
       Matrix5x4 matrix(colorMatrix[0], colorMatrix[5], colorMatrix[10],  colorMatrix[15],
                        colorMatrix[1], colorMatrix[6], colorMatrix[11],  colorMatrix[16],
                        colorMatrix[2], colorMatrix[7], colorMatrix[12],  colorMatrix[17],
                        colorMatrix[3], colorMatrix[8], colorMatrix[13],  colorMatrix[18],
                        colorMatrix[4], colorMatrix[9], colorMatrix[14],  colorMatrix[19]);