Bug 1250490 - Part 2. Remove DetermineMaskUsage and ComputeOpacity from nsSVGIntegrationUtils. draft
authorcku <cku@mozilla.com>
Thu, 03 Nov 2016 11:16:46 +0800
changeset 435859 e729260c4c0bc1a1242e61d6b86d7b2b49430520
parent 435858 7cd22406f83d754c9607b08220d894244dc15b57
child 435860 4d483ddba4014889383b20523a31b1adf30113f0
push id35144
push userbmo:cku@mozilla.com
push dateWed, 09 Nov 2016 10:57:29 +0000
bugs1250490
milestone52.0a1
Bug 1250490 - Part 2. Remove DetermineMaskUsage and ComputeOpacity from nsSVGIntegrationUtils. 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);
 
@@ -990,17 +913,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.