Bug 1166585 - Check for CreateFilter() call returning NULL. r=mstange, a=sledru
authorKyle <kfung@mozilla.com>
Thu, 28 May 2015 14:50:15 -0400
changeset 275037 b2b196031bea2c2e9268a04f9568065394c266d5
parent 275036 64a3afdba9ec9e4a00aa2ea8f9661bc4f79fb8bc
child 275038 4dd61213c4677cac242f4b4423148465cf4bf7b5
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, sledru
bugs1166585
milestone40.0a2
Bug 1166585 - Check for CreateFilter() call returning NULL. r=mstange, a=sledru
gfx/2d/FilterNodeD2D1.cpp
gfx/src/FilterSupport.cpp
--- a/gfx/2d/FilterNodeD2D1.cpp
+++ b/gfx/2d/FilterNodeD2D1.cpp
@@ -544,18 +544,18 @@ FilterNodeD2D1::Create(ID2D1DeviceContex
     return new FilterNodeConvolveD2D1(aDC);
   }
 
   RefPtr<ID2D1Effect> effect;
   HRESULT hr;
 
   hr = aDC->CreateEffect(GetCLDIDForFilterType(aType), byRef(effect));
 
-  if (FAILED(hr)) {
-    gfxWarning() << "Failed to create effect for FilterType: " << hexa(hr);
+  if (FAILED(hr) || !effect) {
+    gfxCriticalErrorOnce() << "Failed to create effect for FilterType: " << hexa(hr);
     return nullptr;
   }
 
   RefPtr<FilterNodeD2D1> filter = new FilterNodeD2D1(effect, aType);
 
   if (IsTransferFilterType(aType) || aType == FilterType::COLOR_MATRIX) {
     // These filters can produce non-transparent output from transparent
     // input pixels, and we want them to have an unbounded output region.
--- a/gfx/src/FilterSupport.cpp
+++ b/gfx/src/FilterSupport.cpp
@@ -97,133 +97,165 @@ namespace gfx {
 // Some convenience FilterNode creation functions.
 
 namespace FilterWrappers {
 
   static TemporaryRef<FilterNode>
   Unpremultiply(DrawTarget* aDT, FilterNode* aInput)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::UNPREMULTIPLY);
-    filter->SetInput(IN_UNPREMULTIPLY_IN, aInput);
-    return filter;
+    if (filter) {
+      filter->SetInput(IN_UNPREMULTIPLY_IN, aInput);
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   Premultiply(DrawTarget* aDT, FilterNode* aInput)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::PREMULTIPLY);
-    filter->SetInput(IN_PREMULTIPLY_IN, aInput);
-    return filter;
+    if (filter) {
+      filter->SetInput(IN_PREMULTIPLY_IN, aInput);
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   LinearRGBToSRGB(DrawTarget* aDT, FilterNode* aInput)
   {
     RefPtr<FilterNode> transfer = aDT->CreateFilter(FilterType::DISCRETE_TRANSFER);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, glinearRGBTosRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, glinearRGBTosRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, glinearRGBTosRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
-    transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
-    return transfer;
+    if (transfer) {
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, glinearRGBTosRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, glinearRGBTosRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, glinearRGBTosRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
+      transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
+      return transfer.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   SRGBToLinearRGB(DrawTarget* aDT, FilterNode* aInput)
   {
     RefPtr<FilterNode> transfer = aDT->CreateFilter(FilterType::DISCRETE_TRANSFER);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, gsRGBToLinearRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, gsRGBToLinearRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, gsRGBToLinearRGBMap, 256);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
-    transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
-    return transfer;
+    if (transfer) {
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, gsRGBToLinearRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, gsRGBToLinearRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, gsRGBToLinearRGBMap, 256);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
+      transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
+      return transfer.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   Crop(DrawTarget* aDT, FilterNode* aInputFilter, const IntRect& aRect)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::CROP);
-    filter->SetAttribute(ATT_CROP_RECT, Rect(aRect));
-    filter->SetInput(IN_CROP_IN, aInputFilter);
-    return filter;
+    if (filter) {
+      filter->SetAttribute(ATT_CROP_RECT, Rect(aRect));
+      filter->SetInput(IN_CROP_IN, aInputFilter);
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   Offset(DrawTarget* aDT, FilterNode* aInputFilter, const IntPoint& aOffset)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::TRANSFORM);
-    filter->SetAttribute(ATT_TRANSFORM_MATRIX, Matrix::Translation(aOffset.x, aOffset.y));
-    filter->SetInput(IN_TRANSFORM_IN, aInputFilter);
-    return filter;
+    if (filter) {
+      filter->SetAttribute(ATT_TRANSFORM_MATRIX, Matrix::Translation(aOffset.x, aOffset.y));
+      filter->SetInput(IN_TRANSFORM_IN, aInputFilter);
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   GaussianBlur(DrawTarget* aDT, FilterNode* aInputFilter, const Size& aStdDeviation)
   {
     float stdX = float(std::min(aStdDeviation.width, kMaxStdDeviation));
     float stdY = float(std::min(aStdDeviation.height, kMaxStdDeviation));
     if (stdX == stdY) {
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::GAUSSIAN_BLUR);
-      filter->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION, stdX);
-      filter->SetInput(IN_GAUSSIAN_BLUR_IN, aInputFilter);
-      return filter;
+      if (filter) {
+        filter->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION, stdX);
+        filter->SetInput(IN_GAUSSIAN_BLUR_IN, aInputFilter);
+        return filter.forget();
+      }
+      return nullptr;
     }
     RefPtr<FilterNode> filterH = aDT->CreateFilter(FilterType::DIRECTIONAL_BLUR);
     RefPtr<FilterNode> filterV = aDT->CreateFilter(FilterType::DIRECTIONAL_BLUR);
-    filterH->SetAttribute(ATT_DIRECTIONAL_BLUR_DIRECTION, (uint32_t)BLUR_DIRECTION_X);
-    filterH->SetAttribute(ATT_DIRECTIONAL_BLUR_STD_DEVIATION, stdX);
-    filterV->SetAttribute(ATT_DIRECTIONAL_BLUR_DIRECTION, (uint32_t)BLUR_DIRECTION_Y);
-    filterV->SetAttribute(ATT_DIRECTIONAL_BLUR_STD_DEVIATION, stdY);
-    filterH->SetInput(IN_DIRECTIONAL_BLUR_IN, aInputFilter);
-    filterV->SetInput(IN_DIRECTIONAL_BLUR_IN, filterH);
-    return filterV;
+    if (filterH && filterV) {
+      filterH->SetAttribute(ATT_DIRECTIONAL_BLUR_DIRECTION, (uint32_t)BLUR_DIRECTION_X);
+      filterH->SetAttribute(ATT_DIRECTIONAL_BLUR_STD_DEVIATION, stdX);
+      filterV->SetAttribute(ATT_DIRECTIONAL_BLUR_DIRECTION, (uint32_t)BLUR_DIRECTION_Y);
+      filterV->SetAttribute(ATT_DIRECTIONAL_BLUR_STD_DEVIATION, stdY);
+      filterH->SetInput(IN_DIRECTIONAL_BLUR_IN, aInputFilter);
+      filterV->SetInput(IN_DIRECTIONAL_BLUR_IN, filterH);
+      return filterV.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   Clear(DrawTarget* aDT)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::FLOOD);
-    filter->SetAttribute(ATT_FLOOD_COLOR, Color(0,0,0,0));
-    return filter;
+    if (filter) {
+      filter->SetAttribute(ATT_FLOOD_COLOR, Color(0, 0, 0, 0));
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   ForSurface(DrawTarget* aDT, SourceSurface* aSurface,
              const IntPoint& aSurfacePosition)
   {
     RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::TRANSFORM);
-    filter->SetAttribute(ATT_TRANSFORM_MATRIX,
-      Matrix::Translation(aSurfacePosition.x, aSurfacePosition.y));
-    filter->SetInput(IN_TRANSFORM_IN, aSurface);
-    return filter;
+    if (filter) {
+      filter->SetAttribute(ATT_TRANSFORM_MATRIX,
+        Matrix::Translation(aSurfacePosition.x, aSurfacePosition.y));
+      filter->SetInput(IN_TRANSFORM_IN, aSurface);
+      return filter.forget();
+    }
+    return nullptr;
   }
 
   static TemporaryRef<FilterNode>
   ToAlpha(DrawTarget* aDT, FilterNode* aInput)
   {
     float zero = 0.0f;
     RefPtr<FilterNode> transfer = aDT->CreateFilter(FilterType::DISCRETE_TRANSFER);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, &zero, 1);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, &zero, 1);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, &zero, 1);
-    transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
-    transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
-    return transfer;
+    if (transfer) {
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_R, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_R, &zero, 1);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_G, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_G, &zero, 1);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_B, false);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_TABLE_B, &zero, 1);
+      transfer->SetAttribute(ATT_DISCRETE_TRANSFER_DISABLE_A, true);
+      transfer->SetInput(IN_DISCRETE_TRANSFER_IN, aInput);
+      return transfer.forget();
+    }
+    return nullptr;
   }
-
 }
 
 // A class that wraps a FilterNode and handles conversion between different
 // color models. Create FilterCachedColorModels with your original filter and
 // the color model that this filter outputs in natively, and then call
 // ->ForColorModel(colorModel) in order to get a FilterNode which outputs to
 // the specified colorModel.
 // Internally, this is achieved by wrapping the original FilterNode with
@@ -529,16 +561,19 @@ ConvertComponentTransferFunctionToFilter
   {
     const nsTArray<float>& tableValues =
       aFunctionAttributes.GetFloats(eComponentTransferFunctionTableValues);
     if (tableValues.Length() < 2)
       return;
 
     if (!aTableTransfer) {
       aTableTransfer = aDT->CreateFilter(FilterType::TABLE_TRANSFER);
+      if (!aTableTransfer) {
+        return;
+      }
       DisableAllTransfers(aTableTransfer);
     }
     filter = aTableTransfer;
     static const TableTransferAtts tableAtt[4] = {
       ATT_TABLE_TRANSFER_TABLE_R,
       ATT_TABLE_TRANSFER_TABLE_G,
       ATT_TABLE_TRANSFER_TABLE_B,
       ATT_TABLE_TRANSFER_TABLE_A
@@ -552,16 +587,19 @@ ConvertComponentTransferFunctionToFilter
   {
     const nsTArray<float>& tableValues =
       aFunctionAttributes.GetFloats(eComponentTransferFunctionTableValues);
     if (tableValues.Length() < 1)
       return;
 
     if (!aDiscreteTransfer) {
       aDiscreteTransfer = aDT->CreateFilter(FilterType::DISCRETE_TRANSFER);
+      if (!aDiscreteTransfer) {
+        return;
+      }
       DisableAllTransfers(aDiscreteTransfer);
     }
     filter = aDiscreteTransfer;
     static const DiscreteTransferAtts tableAtt[4] = {
       ATT_DISCRETE_TRANSFER_TABLE_R,
       ATT_DISCRETE_TRANSFER_TABLE_G,
       ATT_DISCRETE_TRANSFER_TABLE_B,
       ATT_DISCRETE_TRANSFER_TABLE_A
@@ -583,16 +621,19 @@ ConvertComponentTransferFunctionToFilter
     static const LinearTransferAtts interceptAtt[4] = {
       ATT_LINEAR_TRANSFER_INTERCEPT_R,
       ATT_LINEAR_TRANSFER_INTERCEPT_G,
       ATT_LINEAR_TRANSFER_INTERCEPT_B,
       ATT_LINEAR_TRANSFER_INTERCEPT_A
     };
     if (!aLinearTransfer) {
       aLinearTransfer = aDT->CreateFilter(FilterType::LINEAR_TRANSFER);
+      if (!aLinearTransfer) {
+        return;
+      }
       DisableAllTransfers(aLinearTransfer);
     }
     filter = aLinearTransfer;
     filter->SetAttribute(disableAtt[aChannel], false);
     float slope = aFunctionAttributes.GetFloat(eComponentTransferFunctionSlope);
     float intercept = aFunctionAttributes.GetFloat(eComponentTransferFunctionIntercept);
     filter->SetAttribute(slopeAtt[aChannel], slope);
     filter->SetAttribute(interceptAtt[aChannel], intercept);
@@ -616,16 +657,19 @@ ConvertComponentTransferFunctionToFilter
     static const GammaTransferAtts offsetAtt[4] = {
       ATT_GAMMA_TRANSFER_OFFSET_R,
       ATT_GAMMA_TRANSFER_OFFSET_G,
       ATT_GAMMA_TRANSFER_OFFSET_B,
       ATT_GAMMA_TRANSFER_OFFSET_A
     };
     if (!aGammaTransfer) {
       aGammaTransfer = aDT->CreateFilter(FilterType::GAMMA_TRANSFER);
+      if (!aGammaTransfer) {
+        return;
+      }
       DisableAllTransfers(aGammaTransfer);
     }
     filter = aGammaTransfer;
     filter->SetAttribute(disableAtt[aChannel], false);
     float amplitude = aFunctionAttributes.GetFloat(eComponentTransferFunctionAmplitude);
     float exponent = aFunctionAttributes.GetFloat(eComponentTransferFunctionExponent);
     float offset = aFunctionAttributes.GetFloat(eComponentTransferFunctionOffset);
     filter->SetAttribute(amplitudeAtt[aChannel], amplitude);
@@ -666,20 +710,26 @@ FilterNodeFromPrimitiveDescription(const
     {
       uint32_t mode = atts.GetUint(eBlendBlendmode);
       RefPtr<FilterNode> filter;
       if (mode == SVG_FEBLEND_MODE_UNKNOWN) {
         return nullptr;
       }
       if (mode == SVG_FEBLEND_MODE_NORMAL) {
         filter = aDT->CreateFilter(FilterType::COMPOSITE);
+        if (!filter) {
+          return nullptr;
+        }
         filter->SetInput(IN_COMPOSITE_IN_START, aSources[1]);
         filter->SetInput(IN_COMPOSITE_IN_START + 1, aSources[0]);
       } else {
         filter = aDT->CreateFilter(FilterType::BLEND);
+        if (!filter) {
+          return nullptr;
+        }
         static const uint8_t blendModes[SVG_FEBLEND_MODE_LUMINOSITY + 1] = {
           0,
           0,
           BLEND_MODE_MULTIPLY,
           BLEND_MODE_SCREEN,
           BLEND_MODE_DARKEN,
           BLEND_MODE_LIGHTEN,
           BLEND_MODE_OVERLAY,
@@ -710,16 +760,19 @@ FilterNodeFromPrimitiveDescription(const
         return aSources[0];
       }
       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]);
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::COLOR_MATRIX);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_COLOR_MATRIX_MATRIX, matrix);
       filter->SetAttribute(ATT_COLOR_MATRIX_ALPHA_MODE, (uint32_t)ALPHA_MODE_STRAIGHT);
       filter->SetInput(IN_COLOR_MATRIX_IN, aSources[0]);
       return filter;
     }
 
     case PrimitiveType::Morphology:
     {
@@ -737,33 +790,42 @@ FilterNodeFromPrimitiveDescription(const
       // Clamp radii to prevent completely insane values:
       rx = std::min(rx, kMorphologyMaxRadius);
       ry = std::min(ry, kMorphologyMaxRadius);
 
       MorphologyOperator op = atts.GetUint(eMorphologyOperator) == SVG_OPERATOR_ERODE ?
         MORPHOLOGY_OPERATOR_ERODE : MORPHOLOGY_OPERATOR_DILATE;
 
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::MORPHOLOGY);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_MORPHOLOGY_RADII, IntSize(rx, ry));
       filter->SetAttribute(ATT_MORPHOLOGY_OPERATOR, (uint32_t)op);
       filter->SetInput(IN_MORPHOLOGY_IN, aSources[0]);
       return filter;
     }
 
     case PrimitiveType::Flood:
     {
       Color color = atts.GetColor(eFloodColor);
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::FLOOD);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_FLOOD_COLOR, color);
       return filter;
     }
 
     case PrimitiveType::Tile:
     {
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::TILE);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_TILE_SOURCE_RECT, aSourceRegions[0]);
       filter->SetInput(IN_TILE_IN, aSources[0]);
       return filter;
     }
 
     case PrimitiveType::ComponentTransfer:
     {
       RefPtr<FilterNode> filters[4]; // one for each FILTER_*_TRANSFER type
@@ -790,16 +852,19 @@ FilterNodeFromPrimitiveDescription(const
       }
 
       return lastFilter;
     }
 
     case PrimitiveType::ConvolveMatrix:
     {
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::CONVOLVE_MATRIX);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_SIZE, atts.GetIntSize(eConvolveMatrixKernelSize));
       const nsTArray<float>& matrix = atts.GetFloats(eConvolveMatrixKernelMatrix);
       filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_MATRIX,
                            matrix.Elements(), matrix.Length());
       filter->SetAttribute(ATT_CONVOLVE_MATRIX_DIVISOR,
                            atts.GetFloat(eConvolveMatrixDivisor));
       filter->SetAttribute(ATT_CONVOLVE_MATRIX_BIAS,
                            atts.GetFloat(eConvolveMatrixBias));
@@ -827,16 +892,19 @@ FilterNodeFromPrimitiveDescription(const
     {
       return FilterWrappers::Offset(aDT, aSources[0],
                                     atts.GetIntPoint(eOffsetOffset));
     }
 
     case PrimitiveType::DisplacementMap:
     {
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::DISPLACEMENT_MAP);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_DISPLACEMENT_MAP_SCALE,
                            atts.GetFloat(eDisplacementMapScale));
       static const uint8_t channel[SVG_CHANNEL_A+1] = {
         COLOR_CHANNEL_R, // SVG_CHANNEL_UNKNOWN
         COLOR_CHANNEL_R, // SVG_CHANNEL_R
         COLOR_CHANNEL_G, // SVG_CHANNEL_G
         COLOR_CHANNEL_B, // SVG_CHANNEL_B
         COLOR_CHANNEL_A  // SVG_CHANNEL_A
@@ -848,16 +916,19 @@ FilterNodeFromPrimitiveDescription(const
       filter->SetInput(IN_DISPLACEMENT_MAP_IN, aSources[0]);
       filter->SetInput(IN_DISPLACEMENT_MAP_IN2, aSources[1]);
       return filter;
     }
 
     case PrimitiveType::Turbulence:
     {
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::TURBULENCE);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_TURBULENCE_BASE_FREQUENCY,
                            atts.GetSize(eTurbulenceBaseFrequency));
       filter->SetAttribute(ATT_TURBULENCE_NUM_OCTAVES,
                            atts.GetUint(eTurbulenceNumOctaves));
       filter->SetAttribute(ATT_TURBULENCE_STITCHABLE,
                            atts.GetBool(eTurbulenceStitchable));
       filter->SetAttribute(ATT_TURBULENCE_SEED,
                            (uint32_t)atts.GetFloat(eTurbulenceSeed));
@@ -874,23 +945,29 @@ FilterNodeFromPrimitiveDescription(const
     }
 
     case PrimitiveType::Composite:
     {
       RefPtr<FilterNode> filter;
       uint32_t op = atts.GetUint(eCompositeOperator);
       if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) {
         filter = aDT->CreateFilter(FilterType::ARITHMETIC_COMBINE);
+        if (!filter) {
+          return nullptr;
+        }
         const nsTArray<float>& coefficients = atts.GetFloats(eCompositeCoefficients);
         filter->SetAttribute(ATT_ARITHMETIC_COMBINE_COEFFICIENTS,
                              coefficients.Elements(), coefficients.Length());
         filter->SetInput(IN_ARITHMETIC_COMBINE_IN, aSources[0]);
         filter->SetInput(IN_ARITHMETIC_COMBINE_IN2, aSources[1]);
       } else {
         filter = aDT->CreateFilter(FilterType::COMPOSITE);
+        if (!filter) {
+          return nullptr;
+        }
         static const uint8_t operators[SVG_FECOMPOSITE_OPERATOR_ARITHMETIC] = {
           COMPOSITE_OPERATOR_OVER, // SVG_FECOMPOSITE_OPERATOR_UNKNOWN
           COMPOSITE_OPERATOR_OVER, // SVG_FECOMPOSITE_OPERATOR_OVER
           COMPOSITE_OPERATOR_IN,   // SVG_FECOMPOSITE_OPERATOR_IN
           COMPOSITE_OPERATOR_OUT,  // SVG_FECOMPOSITE_OPERATOR_OUT
           COMPOSITE_OPERATOR_ATOP, // SVG_FECOMPOSITE_OPERATOR_ATOP
           COMPOSITE_OPERATOR_XOR   // SVG_FECOMPOSITE_OPERATOR_XOR
         };
@@ -905,16 +982,19 @@ FilterNodeFromPrimitiveDescription(const
     {
       if (aSources.Length() == 0) {
         return nullptr;
       }
       if (aSources.Length() == 1) {
         return aSources[0];
       }
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::COMPOSITE);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_COMPOSITE_OPERATOR, (uint32_t)COMPOSITE_OPERATOR_OVER);
       for (size_t i = 0; i < aSources.Length(); i++) {
         filter->SetInput(IN_COMPOSITE_IN_START + i, aSources[i]);
       }
       return filter;
     }
 
     case PrimitiveType::GaussianBlur:
@@ -926,31 +1006,40 @@ FilterNodeFromPrimitiveDescription(const
     case PrimitiveType::DropShadow:
     {
       RefPtr<FilterNode> alpha = FilterWrappers::ToAlpha(aDT, aSources[0]);
       RefPtr<FilterNode> blur = FilterWrappers::GaussianBlur(aDT, alpha,
                                   atts.GetSize(eDropShadowStdDeviation));
       RefPtr<FilterNode> offsetBlur = FilterWrappers::Offset(aDT, blur,
                                         atts.GetIntPoint(eDropShadowOffset));
       RefPtr<FilterNode> flood = aDT->CreateFilter(FilterType::FLOOD);
+      if (!flood) {
+        return nullptr;
+      }
       Color color = atts.GetColor(eDropShadowColor);
       if (aDescription.InputColorSpace(0) == ColorSpace::LinearRGB) {
         color = Color(gsRGBToLinearRGBMap[uint8_t(color.r * 255)],
                       gsRGBToLinearRGBMap[uint8_t(color.g * 255)],
                       gsRGBToLinearRGBMap[uint8_t(color.b * 255)],
                       color.a);
       }
       flood->SetAttribute(ATT_FLOOD_COLOR, color);
 
       RefPtr<FilterNode> composite = aDT->CreateFilter(FilterType::COMPOSITE);
+      if (!composite) {
+        return nullptr;
+      }
       composite->SetAttribute(ATT_COMPOSITE_OPERATOR, (uint32_t)COMPOSITE_OPERATOR_IN);
       composite->SetInput(IN_COMPOSITE_IN_START, offsetBlur);
       composite->SetInput(IN_COMPOSITE_IN_START + 1, flood);
 
       RefPtr<FilterNode> filter = aDT->CreateFilter(FilterType::COMPOSITE);
+      if (!filter) {
+        return nullptr;
+      }
       filter->SetAttribute(ATT_COMPOSITE_OPERATOR, (uint32_t)COMPOSITE_OPERATOR_OVER);
       filter->SetInput(IN_COMPOSITE_IN_START, composite);
       filter->SetInput(IN_COMPOSITE_IN_START + 1, aSources[0]);
       return filter;
     }
 
     case PrimitiveType::DiffuseLighting:
     case PrimitiveType::SpecularLighting:
@@ -973,16 +1062,19 @@ FilterNodeFromPrimitiveDescription(const
       }
 
       static const FilterType filterType[2][DISTANT+1] = {
         { FilterType::POINT_DIFFUSE, FilterType::SPOT_DIFFUSE, FilterType::DISTANT_DIFFUSE },
         { FilterType::POINT_SPECULAR, FilterType::SPOT_SPECULAR, FilterType::DISTANT_SPECULAR }
       };
       RefPtr<FilterNode> filter =
         aDT->CreateFilter(filterType[isSpecular][lightType]);
+      if (!filter) {
+        return nullptr;
+      }
 
       filter->SetAttribute(ATT_LIGHTING_COLOR,
                            atts.GetColor(eLightingColor));
       filter->SetAttribute(ATT_LIGHTING_SURFACE_SCALE,
                            atts.GetFloat(eLightingSurfaceScale));
       filter->SetAttribute(ATT_LIGHTING_KERNEL_UNIT_LENGTH,
                            atts.GetSize(eLightingKernelUnitLength));
 
@@ -1032,16 +1124,19 @@ FilterNodeFromPrimitiveDescription(const
       }
 
       // Pull the image from the additional image list using the index that's
       // stored in the primitive description.
       RefPtr<SourceSurface> inputImage =
         aInputImages[atts.GetUint(eImageInputIndex)];
 
       RefPtr<FilterNode> transform = aDT->CreateFilter(FilterType::TRANSFORM);
+      if (!transform) {
+        return nullptr;
+      }
       transform->SetInput(IN_TRANSFORM_IN, inputImage);
       transform->SetAttribute(ATT_TRANSFORM_MATRIX, TM);
       transform->SetAttribute(ATT_TRANSFORM_FILTER, atts.GetUint(eImageFilter));
       return transform;
     }
 
     case PrimitiveType::ToAlpha:
     {
@@ -1242,17 +1337,20 @@ FilterSupport::RenderFilterDescription(D
                                        nsTArray<RefPtr<SourceSurface>>& aAdditionalImages,
                                        const Point& aDestPoint,
                                        const DrawOptions& aOptions)
 {
   RefPtr<FilterNode> resultFilter =
     FilterNodeGraphFromDescription(aDT, aFilter, aRenderRect,
                                    aSourceGraphic, aSourceGraphicRect, aFillPaint, aFillPaintRect,
                                    aStrokePaint, aStrokePaintRect, aAdditionalImages);
-
+  if (!resultFilter) {
+    gfxWarning() << "Filter is NULL.";
+    return;
+  }
   aDT->DrawFilter(resultFilter, aRenderRect, aDestPoint, aOptions);
 }
 
 static nsIntRegion
 UnionOfRegions(const nsTArray<nsIntRegion>& aRegions)
 {
   nsIntRegion result;
   for (size_t i = 0; i < aRegions.Length(); i++) {