Bug 1528464 - Convert NS_STYLE_MASK_MODE_* to enum class r=emilio
authorscharing <al.dick@live.de>
Tue, 19 Feb 2019 16:54:52 +0000
changeset 459915 38d48c5261aa495655c1d4c27deb68bee0719911
parent 459914 93a4c9ff0cb515dc5ee5963675cdea4199c0a491
child 459916 85192f61b49ebcfaf20bb55e4ea77da3eb69d6c3
push id35580
push userdvarga@mozilla.com
push dateWed, 20 Feb 2019 04:03:23 +0000
treeherdermozilla-central@62a8571d3b92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1528464
milestone67.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 1528464 - Convert NS_STYLE_MASK_MODE_* to enum class r=emilio Differential Revision: https://phabricator.services.mozilla.com/D20063
layout/painting/nsImageRenderer.cpp
layout/painting/nsImageRenderer.h
layout/style/ServoBindings.toml
layout/style/nsComputedDOMStyle.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/svg/nsSVGMaskFrame.cpp
layout/svg/nsSVGMaskFrame.h
layout/svg/nsSVGUtils.cpp
servo/components/style/properties/longhands/svg.mako.rs
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -56,17 +56,17 @@ nsImageRenderer::nsImageRenderer(nsIFram
       mType(aImage->GetType()),
       mImageContainer(nullptr),
       mGradientData(nullptr),
       mPaintServerFrame(nullptr),
       mPrepareResult(ImgDrawResult::NOT_READY),
       mSize(0, 0),
       mFlags(aFlags),
       mExtendMode(ExtendMode::CLAMP),
-      mMaskOp(NS_STYLE_MASK_MODE_MATCH_SOURCE) {}
+      mMaskOp(StyleMaskMode::MatchSource) {}
 
 static bool ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage,
                                                  uint32_t aFlags) {
   if (!(aFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES)) {
     return false;
   }
 
   if (aImage->GetType() != eStyleImageType_Image) {
@@ -423,17 +423,17 @@ ImgDrawResult nsImageRenderer::Draw(nsPr
 
   SamplingFilter samplingFilter =
       nsLayoutUtils::GetSamplingFilterForFrame(mForFrame);
   ImgDrawResult result = ImgDrawResult::SUCCESS;
   RefPtr<gfxContext> ctx = &aRenderingContext;
   IntRect tmpDTRect;
 
   if (ctx->CurrentOp() != CompositionOp::OP_OVER ||
-      mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
+      mMaskOp == StyleMaskMode::Luminance) {
     gfxRect clipRect = ctx->GetClipExtents(gfxContext::eDeviceSpace);
     tmpDTRect = RoundedOut(ToRect(clipRect));
     if (tmpDTRect.IsEmpty()) {
       return ImgDrawResult::SUCCESS;
     }
     RefPtr<DrawTarget> tempDT =
         gfxPlatform::GetPlatform()->CreateSimilarSoftwareDrawTarget(
             ctx->GetDrawTarget(), tmpDTRect.Size(), SurfaceFormat::B8G8R8A8);
@@ -488,17 +488,17 @@ ImgDrawResult nsImageRenderer::Draw(nsPr
     default:
       break;
   }
 
   if (!tmpDTRect.IsEmpty()) {
     DrawTarget* dt = aRenderingContext.GetDrawTarget();
     Matrix oldTransform = dt->GetTransform();
     dt->SetTransform(Matrix());
-    if (mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
+    if (mMaskOp == StyleMaskMode::Luminance) {
       RefPtr<SourceSurface> surf = ctx->GetDrawTarget()->IntoLuminanceSource(
           LuminanceType::LUMINANCE, 1.0f);
       dt->MaskSurface(ColorPattern(Color(0, 0, 0, 1.0f)), surf,
                       tmpDTRect.TopLeft(),
                       DrawOptions(1.0f, aRenderingContext.CurrentOp()));
     } else {
       RefPtr<SourceSurface> surf = ctx->GetDrawTarget()->Snapshot();
       dt->DrawSurface(
--- a/layout/painting/nsImageRenderer.h
+++ b/layout/painting/nsImageRenderer.h
@@ -244,17 +244,17 @@ class nsImageRenderer {
   /// Retrieves the image associated with this nsImageRenderer, if there is one.
   already_AddRefed<imgIContainer> GetImage();
 
   bool IsImageContainerAvailable(layers::LayerManager* aManager,
                                  uint32_t aFlags);
   bool IsReady() const { return mPrepareResult == ImgDrawResult::SUCCESS; }
   ImgDrawResult PrepareResult() const { return mPrepareResult; }
   void SetExtendMode(mozilla::gfx::ExtendMode aMode) { mExtendMode = aMode; }
-  void SetMaskOp(uint8_t aMaskOp) { mMaskOp = aMaskOp; }
+  void SetMaskOp(mozilla::StyleMaskMode aMaskOp) { mMaskOp = aMaskOp; }
   void PurgeCacheForViewportChange(
       const mozilla::Maybe<nsSize>& aSVGViewportSize, const bool aHasRatio);
   nsStyleImageType GetType() const { return mType; }
   already_AddRefed<nsStyleGradient> GetGradientData();
 
  private:
   /**
    * Draws the image to the target rendering context.
@@ -300,14 +300,14 @@ class nsImageRenderer {
   nsCOMPtr<imgIContainer> mImageContainer;
   RefPtr<nsStyleGradient> mGradientData;
   nsIFrame* mPaintServerFrame;
   nsLayoutUtils::SurfaceFromElementResult mImageElementSurface;
   ImgDrawResult mPrepareResult;
   nsSize mSize;  // unscaled size of the image, in app units
   uint32_t mFlags;
   mozilla::gfx::ExtendMode mExtendMode;
-  uint8_t mMaskOp;
+  mozilla::StyleMaskMode mMaskOp;
 };
 
 }  // namespace mozilla
 
 #endif /* nsImageRenderer_h__ */
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -139,16 +139,17 @@ rusty-enums = [
     "nsStyleSVGFallbackType",
     "nsINode_BooleanFlag",
     "mozilla::PseudoStyleType",
     "mozilla::LookAndFeel_ColorID",
     "mozilla::LookAndFeel_FontID",
     "nsStyleTransformMatrix::MatrixTransformOperator",
     "mozilla::StyleGeometryBox",
     "mozilla::SystemColor",
+    "mozilla::StyleMaskMode",
 ]
 whitelist-vars = [
     "NS_AUTHOR_SPECIFIED_.*",
     "NS_THEME_.*",
     "NS_ATTRVALUE_.*",
     "NODE_.*",
     "ELEMENT_.*",
     "NS_FONT_.*",
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -3503,17 +3503,17 @@ already_AddRefed<CSSValue> nsComputedDOM
 
   // Mask is now a shorthand, but it used to be a longhand, so that we
   // need to support computed style for the cases where it used to be
   // a longhand.
   if (svg->mMask.mImageCount > 1 ||
       firstLayer.mClip != StyleGeometryBox::BorderBox ||
       firstLayer.mOrigin != StyleGeometryBox::BorderBox ||
       firstLayer.mComposite != NS_STYLE_MASK_COMPOSITE_ADD ||
-      firstLayer.mMaskMode != NS_STYLE_MASK_MODE_MATCH_SOURCE ||
+      firstLayer.mMaskMode != StyleMaskMode::MatchSource ||
       !nsStyleImageLayers::IsInitialPositionForLayerType(
           firstLayer.mPosition, nsStyleImageLayers::LayerType::Mask) ||
       !firstLayer.mRepeat.IsInitialValue() ||
       !firstLayer.mSize.IsInitialValue() ||
       !(firstLayer.mImage.GetType() == eStyleImageType_Null ||
         firstLayer.mImage.GetType() == eStyleImageType_Image ||
         firstLayer.mImage.GetType() == eStyleImageType_URL)) {
     return nullptr;
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -269,19 +269,21 @@ enum class StyleImageLayerRepeat : uint8
   RepeatX,
   RepeatY,
   Repeat,
   Space,
   Round
 };
 
 // Mask mode
-#define NS_STYLE_MASK_MODE_ALPHA 0
-#define NS_STYLE_MASK_MODE_LUMINANCE 1
-#define NS_STYLE_MASK_MODE_MATCH_SOURCE 2
+enum class StyleMaskMode : uint8_t {
+  Alpha = 0,
+  Luminance,
+  MatchSource
+};
 
 // See nsStyleTable
 #define NS_STYLE_BORDER_COLLAPSE 0
 #define NS_STYLE_BORDER_SEPARATE 1
 
 // border-image-repeat
 enum class StyleBorderImageRepeat : uint8_t { Stretch, Repeat, Round, Space };
 
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -2666,17 +2666,17 @@ static bool SizeDependsOnPositioningArea
 
 nsStyleImageLayers::Layer::Layer()
     : mSize(StyleBackgroundSize::ExplicitSize(LengthPercentageOrAuto::Auto(),
                                               LengthPercentageOrAuto::Auto())),
       mClip(StyleGeometryBox::BorderBox),
       mAttachment(StyleImageLayerAttachment::Scroll),
       mBlendMode(NS_STYLE_BLEND_NORMAL),
       mComposite(NS_STYLE_MASK_COMPOSITE_ADD),
-      mMaskMode(NS_STYLE_MASK_MODE_MATCH_SOURCE) {
+      mMaskMode(StyleMaskMode::MatchSource) {
   mImage.SetNull();
 }
 
 nsStyleImageLayers::Layer::~Layer() {}
 
 void nsStyleImageLayers::Layer::Initialize(
     nsStyleImageLayers::LayerType aType) {
   mRepeat.SetInitialValues();
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -547,18 +547,18 @@ struct nsStyleImageLayers {
 
     // This property is used for mask layer only.
     // For a background layer, it should always be the initial value, which is
     // NS_STYLE_COMPOSITE_MODE_ADD.
     uint8_t mComposite;  // NS_STYLE_MASK_COMPOSITE_*
 
     // mask-only property. This property is used for mask layer only. For a
     // background layer, it should always be the initial value, which is
-    // NS_STYLE_MASK_MODE_MATCH_SOURCE.
-    uint8_t mMaskMode;  // NS_STYLE_MASK_MODE_*
+    // StyleMaskMode::MatchSource.
+    mozilla::StyleMaskMode mMaskMode;
 
     Repeat mRepeat;
 
     // This constructor does not initialize mRepeat or mOrigin and Initialize()
     // must be called to do that.
     Layer();
     ~Layer();
 
--- a/layout/svg/nsSVGMaskFrame.cpp
+++ b/layout/svg/nsSVGMaskFrame.cpp
@@ -69,20 +69,20 @@ already_AddRefed<SourceSurface> nsSVGMas
 
   if (resultOverflows || maskSurfaceSize.IsEmpty()) {
     // Return value other then ImgDrawResult::SUCCESS, so the caller can skip
     // painting the masked frame(aParams.maskedFrame).
     return nullptr;
   }
 
   uint8_t maskType;
-  if (aParams.maskMode == NS_STYLE_MASK_MODE_MATCH_SOURCE) {
+  if (aParams.maskMode == StyleMaskMode::MatchSource) {
     maskType = StyleSVGReset()->mMaskType;
   } else {
-    maskType = aParams.maskMode == NS_STYLE_MASK_MODE_LUMINANCE
+    maskType = aParams.maskMode == StyleMaskMode::Luminance
                    ? NS_STYLE_MASK_TYPE_LUMINANCE
                    : NS_STYLE_MASK_TYPE_ALPHA;
   }
 
   RefPtr<DrawTarget> maskDT;
   if (maskType == NS_STYLE_MASK_TYPE_LUMINANCE) {
     maskDT = context->GetDrawTarget()->CreateSimilarDrawTarget(
         maskSurfaceSize, SurfaceFormat::B8G8R8A8);
--- a/layout/svg/nsSVGMaskFrame.h
+++ b/layout/svg/nsSVGMaskFrame.h
@@ -35,22 +35,22 @@ class nsSVGMaskFrame final : public nsSV
   NS_DECL_FRAMEARENA_HELPERS(nsSVGMaskFrame)
 
   struct MaskParams {
     gfxContext* ctx;
     nsIFrame* maskedFrame;
     const gfxMatrix& toUserSpace;
     float opacity;
     Matrix* maskTransform;
-    uint8_t maskMode;
+    mozilla::StyleMaskMode maskMode;
     imgDrawingParams& imgParams;
 
     explicit MaskParams(gfxContext* aCtx, nsIFrame* aMaskedFrame,
                         const gfxMatrix& aToUserSpace, float aOpacity,
-                        Matrix* aMaskTransform, uint8_t aMaskMode,
+                        Matrix* aMaskTransform, mozilla::StyleMaskMode aMaskMode,
                         imgDrawingParams& aImgParams)
         : ctx(aCtx),
           maskedFrame(aMaskedFrame),
           toUserSpace(aToUserSpace),
           opacity(aOpacity),
           maskTransform(aMaskTransform),
           maskMode(aMaskMode),
           imgParams(aImgParams) {}
--- a/layout/svg/nsSVGUtils.cpp
+++ b/layout/svg/nsSVGUtils.cpp
@@ -692,17 +692,17 @@ void nsSVGUtils::PaintFrameWithEffects(n
 
     // maskFrame can be nullptr even if maskUsage.shouldGenerateMaskLayer is
     // true. That happens when a user gives an unresolvable mask-id, such as
     //   mask:url()
     //   mask:url(#id-which-does-not-exist)
     // Since we only uses nsSVGUtils with SVG elements, not like mask on an
     // HTML element, we should treat an unresolvable mask as no-mask here.
     if (maskUsage.shouldGenerateMaskLayer && maskFrame) {
-      uint8_t maskMode = aFrame->StyleSVGReset()->mMask.mLayers[0].mMaskMode;
+      StyleMaskMode maskMode = aFrame->StyleSVGReset()->mMask.mLayers[0].mMaskMode;
       nsSVGMaskFrame::MaskParams params(&aContext, aFrame, aTransform,
                                         maskUsage.opacity, &maskTransform,
                                         maskMode, aImgParams);
       maskSurface = maskFrame->GetMaskForMaskedFrame(params);
 
       if (!maskSurface) {
         // Either entire surface is clipped out, or gfx buffer allocation
         // failure in nsSVGMaskFrame::GetMaskForMaskedFrame.
--- a/servo/components/style/properties/longhands/svg.mako.rs
+++ b/servo/components/style/properties/longhands/svg.mako.rs
@@ -91,16 +91,17 @@
     animation_value_type="basic_shape::ClippingShape",
     flags="CREATES_STACKING_CONTEXT",
     spec="https://drafts.fxtf.org/css-masking/#propdef-clip-path",
 )}
 
 ${helpers.single_keyword(
     "mask-mode",
     "match-source alpha luminance",
+    gecko_enum_prefix="StyleMaskMode",
     vector=True,
     products="gecko",
     animation_value_type="discrete",
     spec="https://drafts.fxtf.org/css-masking/#propdef-mask-mode",
 )}
 
 ${helpers.predefined_type(
     "mask-repeat",