Bug 1250490 - Part 2. Remove DetermineMaskUsage and ComputeOpacity from nsSVGIntegrationUtils. r=mstange
authorcku <cku@mozilla.com>
Thu, 03 Nov 2016 11:16:46 +0800
changeset 348514 3e671abe2ce40107a94e4ddcb6f162c2d22494b3
parent 348513 7de1853a0dfb0736ec34818e0d576994ab2e8442
child 348515 0f4dfee8460a8df29d2e2b49d9e9e43be2b8be8b
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1250490
milestone52.0a1
Bug 1250490 - Part 2. Remove DetermineMaskUsage and ComputeOpacity from nsSVGIntegrationUtils. r=mstange MozReview-Commit-ID: 4gHW7PyMNhd
layout/base/nsDisplayList.cpp
layout/svg/nsSVGIntegrationUtils.cpp
layout/svg/nsSVGIntegrationUtils.h
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -7085,18 +7085,18 @@ nsDisplayMask::GetLayerState(nsDisplayLi
 }
 
 bool nsDisplayMask::ShouldPaintOnMaskLayer(LayerManager* aManager)
 {
   if (!aManager->IsCompositingCheap()) {
     return false;
   }
 
-  nsSVGIntegrationUtils::MaskUsage maskUsage;
-  nsSVGIntegrationUtils::DetermineMaskUsage(mFrame, mHandleOpacity, maskUsage);
+  nsSVGUtils::MaskUsage maskUsage;
+  nsSVGUtils::DetermineMaskUsage(mFrame, mHandleOpacity, maskUsage);
 
   if (!maskUsage.shouldGenerateMaskLayer ||
       maskUsage.opacity != 1.0 || maskUsage.shouldApplyClipPath ||
       maskUsage.shouldApplyBasicShape ||
       maskUsage.shouldGenerateClipMaskLayer) {
     return false;
   }
 
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -571,29 +571,16 @@ CreateAndPaintMaskSurface(const PaintFra
   if (!aOutMaskTransform.Invert()) {
     return DrawResult::SUCCESS;
   }
 
   aOutMaskSurface = maskDT->Snapshot();
   return DrawResult::SUCCESS;
 }
 
-static float
-ComputeOpacity(nsIFrame* aFrame, bool aHandleOpacity)
-{
-  float opacity = aFrame->StyleEffects()->mOpacity;
-
-  if (opacity != 1.0f &&
-      (nsSVGUtils::CanOptimizeOpacity(aFrame) || !aHandleOpacity)) {
-    return 1.0f;
-  }
-
-  return opacity;
-}
-
 static bool
 ValidateSVGFrame(nsIFrame* aFrame)
 {
 #ifdef DEBUG
   NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
                (NS_SVGDisplayListPaintingEnabled() &&
                 !(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)),
                "Should not use nsSVGIntegrationUtils on this SVG frame");
@@ -680,82 +667,16 @@ SetupContextMatrix(nsIFrame* aFrame, con
     nsRect clipRect =
       aParams.frame->GetVisualOverflowRectRelativeToSelf() + toUserSpace;
     context.Clip(NSRectToSnappedRect(clipRect,
                                   aFrame->PresContext()->AppUnitsPerDevPixel(),
                                   *context.GetDrawTarget()));
   }
 }
 
-void
-nsSVGIntegrationUtils::DetermineMaskUsage(nsIFrame* aFrame,
-                                          bool aHandleOpacity,
-                                          MaskUsage& aUsage)
-{
-  aUsage.opacity = ComputeOpacity(aFrame, aHandleOpacity);
-
-  nsIFrame* firstFrame =
-    nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
-
-  nsSVGEffects::EffectProperties effectProperties =
-    nsSVGEffects::GetEffectProperties(firstFrame);
-  const nsStyleSVGReset *svgReset = firstFrame->StyleSVGReset();
-
-  nsTArray<nsSVGMaskFrame*> maskFrames = effectProperties.GetMaskFrames();
-
-#ifdef MOZ_ENABLE_MASK_AS_SHORTHAND
-  // For a HTML doc:
-  //   According to css-masking spec, always create a mask surface when we
-  //   have any item in maskFrame even if all of those items are
-  //   non-resolvable <mask-sources> or <images>, we still need to create a
-  //   transparent black mask layer under this condition.
-  // For a SVG doc:
-  //   SVG 1.1 say that  if we fail to resolve a mask, we should draw the
-  //   object unmasked.
-  aUsage.shouldGenerateMaskLayer =
-    (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)
-      ? maskFrames.Length() == 1 && maskFrames[0]
-      : maskFrames.Length() > 0;
-#else
-  // Since we do not support image mask so far, we should treat any
-  // unresolvable mask as no mask. Otherwise, any object with a valid image
-  // mask, e.g. url("xxx.png"), will become invisible just because we can not
-  // handle image mask correctly. (See bug 1294171)
-  aUsage.shouldGenerateMaskLayer = maskFrames.Length() == 1 && maskFrames[0];
-#endif
-
-  bool isOK = effectProperties.HasNoFilterOrHasValidFilter();
-  nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
-  MOZ_ASSERT_IF(clipPathFrame,
-                svgReset->mClipPath.GetType() == StyleShapeSourceType::URL);
-
-  switch (svgReset->mClipPath.GetType()) {
-    case StyleShapeSourceType::URL:
-      if (clipPathFrame) {
-        if (clipPathFrame->IsTrivial()) {
-          aUsage.shouldApplyClipPath = true;
-        } else {
-          aUsage.shouldGenerateClipMaskLayer = true;
-        }
-      }
-      break;
-    case StyleShapeSourceType::Shape:
-    case StyleShapeSourceType::Box:
-      aUsage.shouldApplyBasicShape = true;
-      break;
-    case StyleShapeSourceType::None:
-      MOZ_ASSERT(!aUsage.shouldGenerateClipMaskLayer &&
-                 !aUsage.shouldApplyClipPath && !aUsage.shouldApplyBasicShape);
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("Unsupported clip-path type.");
-      break;
-  }
-}
-
 bool
 nsSVGIntegrationUtils::IsMaskResourceReady(nsIFrame* aFrame)
 {
   nsIFrame* firstFrame =
     nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
   nsSVGEffects::EffectProperties effectProperties =
     nsSVGEffects::GetEffectProperties(firstFrame);
   nsTArray<nsSVGMaskFrame*> maskFrames = effectProperties.GetMaskFrames();
@@ -775,18 +696,19 @@ nsSVGIntegrationUtils::IsMaskResourceRea
 
   // Either all mask resources are ready, or no mask resource is needed.
   return true;
 }
 
 DrawResult
 nsSVGIntegrationUtils::PaintMask(const PaintFramesParams& aParams)
 {
-  MaskUsage maskUsage;
-  DetermineMaskUsage(aParams.frame, aParams.handleOpacity, maskUsage);
+  nsSVGUtils::MaskUsage maskUsage;
+  nsSVGUtils::DetermineMaskUsage(aParams.frame, aParams.handleOpacity,
+                                 maskUsage);
   MOZ_ASSERT(maskUsage.shouldGenerateMaskLayer);
 
   nsIFrame* frame = aParams.frame;
   if (!ValidateSVGFrame(frame)) {
     return DrawResult::SUCCESS;
   }
 
   if (maskUsage.opacity == 0.0f) {
@@ -836,18 +758,19 @@ nsSVGIntegrationUtils::PaintMaskAndClipP
    * + Merge opacity and masking if both used together.
    */
   nsIFrame* frame = aParams.frame;
   DrawResult result = DrawResult::SUCCESS;
   if (!ValidateSVGFrame(frame)) {
     return result;
   }
 
-  MaskUsage maskUsage;
-  DetermineMaskUsage(aParams.frame, aParams.handleOpacity, maskUsage);
+  nsSVGUtils::MaskUsage maskUsage;
+  nsSVGUtils::DetermineMaskUsage(aParams.frame, aParams.handleOpacity,
+                                 maskUsage);
 
   if (maskUsage.opacity == 0.0f) {
     return DrawResult::SUCCESS;
   }
 
   gfxContext& context = aParams.ctx;
   gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(&context);
 
@@ -1002,17 +925,17 @@ nsSVGIntegrationUtils::PaintFilter(const
   MOZ_ASSERT(aParams.frame->StyleEffects()->HasFilters(),
              "Should not use this method when no filter effect on this frame");
 
   nsIFrame* frame = aParams.frame;
   if (!ValidateSVGFrame(frame)) {
     return DrawResult::SUCCESS;
   }
 
-  float opacity = ComputeOpacity(frame, aParams.handleOpacity);
+  float opacity = nsSVGUtils::ComputeOpacity(frame, aParams.handleOpacity);
   if (opacity == 0.0f) {
     return DrawResult::SUCCESS;
   }
 
   /* Properties are added lazily and may have been removed by a restyle,
      so make sure all applicable ones are set again. */
   nsIFrame* firstFrame =
     nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
--- a/layout/svg/nsSVGIntegrationUtils.h
+++ b/layout/svg/nsSVGIntegrationUtils.h
@@ -162,32 +162,16 @@ public:
 
   /**
    * Paint mask of non-SVG frame onto a given context, aParams.ctx.
    * aParams.ctx must contain an A8 surface.
    */
   static DrawResult
   PaintMask(const PaintFramesParams& aParams);
 
-  struct MaskUsage {
-    bool shouldGenerateMaskLayer;
-    bool shouldGenerateClipMaskLayer;
-    bool shouldApplyClipPath;
-    bool shouldApplyBasicShape;
-    float opacity;
-
-    MaskUsage()
-      : shouldGenerateMaskLayer(false), shouldGenerateClipMaskLayer(false),
-        shouldApplyClipPath(false), shouldApplyBasicShape(false), opacity(0.0)
-    { }
-  };
-
-  static void
-  DetermineMaskUsage(nsIFrame* aFrame, bool aHandleOpacity, MaskUsage& aUsage);
-
   /**
    * Return true if all the mask resource of aFrame are ready.
    */
   static bool
   IsMaskResourceReady(nsIFrame* aFrame);
 
   /**
    * Paint non-SVG frame with filter and opacity effect.