Bug 1301245 - Part 2. Remove Layer::mSourceURI. draft
authorcku <cku@mozilla.com>
Thu, 30 Mar 2017 19:47:14 +0800
changeset 553708 349712551c4d8d033ce3b7993842d5fe4c50fcd1
parent 553707 72049d97a156fa522862b59890799baea23e654b
child 622151 a8f035550ef7a66e9fd3d9f955e10eef3790d4ef
push id51730
push userbmo:cku@mozilla.com
push dateThu, 30 Mar 2017 14:08:11 +0000
bugs1301245
milestone55.0a1
Bug 1301245 - Part 2. Remove Layer::mSourceURI. There are several advantage to remove Layer::mSourceURI 1. Redue the size of nsStyleImage::Layer. In part 1, we store url in nsStyleImage's union, which means the size of nsStyleImage does not increase. 2. Since style image and url information are all stored in nsStyleImage, many verbose comments can be removed. Since we do not need to explain why we use mSourceURI here, or why we use nsStyleImage there. MozReview-Commit-ID: 7aTQobddTB1
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/svg/nsSVGEffects.cpp
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2319,50 +2319,34 @@ nsComputedDOMStyle::SetValueToStyleImage
                                    elementId +
                                    NS_LITERAL_STRING(")");
       aValue->SetString(elementString);
       break;
     }
     case eStyleImageType_Null:
       aValue->SetIdent(eCSSKeyword_none);
       break;
+    case eStyleImageType_Url:
+      SetValueToURLValue(aStyleImage.GetURLValueData(), aValue);
+      break;
     default:
       NS_NOTREACHED("unexpected image type");
       break;
   }
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetImageLayerImage(const nsStyleImageLayers& aLayers)
 {
   RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = aLayers.mImageCount; i < i_end; ++i) {
     RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
-    const nsStyleImage& image = aLayers.mLayers[i].mImage;
-    // Layer::mImage::GetType() returns eStyleImageType_Null in two conditions:
-    // 1. The value of mask-image/bg-image is 'none'.
-    //    Since this layer does not refer to any source, Layer::mSourceURI must
-    //    be nullptr too.
-    // 2. This layer refers to a local resource, e.g. mask-image:url(#mymask).
-    //    For local references, there is no need to download any external
-    //    resource, so Layer::mImage is not used.
-    //    Instead, we store the local URI in one place -- on Layer::mSourceURI.
-    //    Hence, we must serialize using mSourceURI (instead of
-    //    SetValueToStyleImage()/mImage) in this case.
-    if (aLayers.mLayers[i].mSourceURI &&
-        aLayers.mLayers[i].mSourceURI->IsLocalRef()) {
-      // This is how we represent a 'mask-image' reference for a local URI,
-      // such as 'mask-image:url(#mymask)' or 'mask:url(#mymask)'
-      SetValueToURLValue(aLayers.mLayers[i].mSourceURI, val);
-    } else {
-      SetValueToStyleImage(image, val);
-    }
-
+    SetValueToStyleImage(aLayers.mLayers[i].mImage, val);
     valueList->AppendCSSValue(val.forget());
   }
 
   return valueList.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetImageLayerPosition(const nsStyleImageLayers& aLayers)
@@ -6379,17 +6363,17 @@ nsComputedDOMStyle::DoGetMask()
       !firstLayer.mSize.IsInitialValue() ||
       !(firstLayer.mImage.GetType() == eStyleImageType_Null ||
         firstLayer.mImage.GetType() == eStyleImageType_Image)) {
     return nullptr;
   }
 
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
-  SetValueToURLValue(firstLayer.mSourceURI, val);
+  SetValueToURLValue(firstLayer.mImage.GetURLValueData(), val);
 
   return val.forget();
 }
 
 #ifdef MOZ_ENABLE_MASK_AS_SHORTHAND
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetMaskClip()
 {
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -9441,19 +9441,16 @@ nsRuleNode::FillAllMaskLists(nsStyleImag
   aMask.mLayers.TruncateLengthNonZero(aMaxItemCount);
 
   uint32_t fillCount = aMask.mImageCount;
 
   FillImageLayerList(aMask.mLayers,
                      &nsStyleImageLayers::Layer::mImage,
                      aMask.mImageCount, fillCount);
   FillImageLayerList(aMask.mLayers,
-                     &nsStyleImageLayers::Layer::mSourceURI,
-                     aMask.mImageCount, fillCount);
-  FillImageLayerList(aMask.mLayers,
                      &nsStyleImageLayers::Layer::mRepeat,
                      aMask.mRepeatCount, fillCount);
   FillImageLayerList(aMask.mLayers,
                      &nsStyleImageLayers::Layer::mClip,
                      aMask.mClipCount, fillCount);
   FillImageLayerList(aMask.mLayers,
                      &nsStyleImageLayers::Layer::mOrigin,
                      aMask.mOriginCount, fillCount);
@@ -10098,24 +10095,16 @@ nsRuleNode::ComputeSVGResetData(void* aS
   nsStyleImage initialImage;
   SetImageLayerList(aContext, *aRuleData->ValueForMaskImage(),
                     svgReset->mMask.mLayers,
                     parentSVGReset->mMask.mLayers,
                     &nsStyleImageLayers::Layer::mImage,
                     initialImage, parentSVGReset->mMask.mImageCount,
                     svgReset->mMask.mImageCount,
                     maxItemCount, rebuild, conditions);
-  SetImageLayerList(aContext, *aRuleData->ValueForMaskImage(),
-                    svgReset->mMask.mLayers,
-                    parentSVGReset->mMask.mLayers,
-                    &nsStyleImageLayers::Layer::mSourceURI,
-                    RefPtr<css::URLValueData>(),
-                    parentSVGReset->mMask.mImageCount,
-                    svgReset->mMask.mImageCount,
-                    maxItemCount, rebuild, conditions);
 
   // mask-repeat: enum, inherit, initial [pair list]
   nsStyleImageLayers::Repeat initialRepeat;
   initialRepeat.SetInitialValues();
   SetImageLayerPairList(aContext, *aRuleData->ValueForMaskRepeat(),
                         svgReset->mMask.mLayers,
                         parentSVGReset->mMask.mLayers,
                         &nsStyleImageLayers::Layer::mRepeat,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1231,24 +1231,17 @@ nsStyleSVGReset::CalcDifference(const ns
 
   return hint;
 }
 
 bool
 nsStyleSVGReset::HasMask() const
 {
   for (uint32_t i = 0; i < mMask.mImageCount; i++) {
-    // mMask.mLayers[i].mSourceURI can be nullptr if mask-image prop value is
-    // <element-reference> or <gradient>.
-    // mMask.mLayers[i].mImage can be empty if mask-image prop value is a
-    // reference to SVG mask element.
-    //
-    // So we need to test both mSourceURI and mImage.
-    if ((mMask.mLayers[i].mSourceURI && mMask.mLayers[i].mSourceURI->GetURI()) ||
-        !mMask.mLayers[i].mImage.IsEmpty()) {
+    if (!mMask.mLayers[i].mImage.IsEmpty()) {
       return true;
     }
   }
 
   return false;
 }
 
 // nsStyleSVGPaint implementation
@@ -2789,17 +2782,18 @@ bool nsStyleImageLayers::operator==(cons
   }
 
   if (mLayers.Length() != aOther.mLayers.Length()) {
     return false;
   }
 
   for (uint32_t i = 0; i < mLayers.Length(); i++) {
     if (mLayers[i].mPosition != aOther.mLayers[i].mPosition ||
-        !DefinitelyEqualURIs(mLayers[i].mSourceURI, aOther.mLayers[i].mSourceURI) ||
+        !DefinitelyEqualURIs(mLayers[i].mImage.GetURLValueData(),
+                             aOther.mLayers[i].mImage.GetURLValueData()) ||
         mLayers[i].mImage != aOther.mLayers[i].mImage ||
         mLayers[i].mSize != aOther.mLayers[i].mSize ||
         mLayers[i].mClip != aOther.mLayers[i].mClip ||
         mLayers[i].mOrigin != aOther.mLayers[i].mOrigin ||
         mLayers[i].mAttachment != aOther.mLayers[i].mAttachment ||
         mLayers[i].mBlendMode != aOther.mLayers[i].mBlendMode ||
         mLayers[i].mComposite != aOther.mLayers[i].mComposite ||
         mLayers[i].mMaskMode != aOther.mLayers[i].mMaskMode ||
@@ -3004,44 +2998,48 @@ nsStyleImageLayers::Layer::operator==(co
          mOrigin == aOther.mOrigin &&
          mRepeat == aOther.mRepeat &&
          mBlendMode == aOther.mBlendMode &&
          mPosition == aOther.mPosition &&
          mSize == aOther.mSize &&
          mImage == aOther.mImage &&
          mMaskMode == aOther.mMaskMode &&
          mComposite == aOther.mComposite &&
-         DefinitelyEqualURIs(mSourceURI, aOther.mSourceURI);
+         DefinitelyEqualURIs(mImage.GetURLValueData(),
+                             aOther.mImage.GetURLValueData());
 }
 
 nsChangeHint
 nsStyleImageLayers::Layer::CalcDifference(const nsStyleImageLayers::Layer& aNewLayer) const
 {
   nsChangeHint hint = nsChangeHint(0);
-  if (!DefinitelyEqualURIs(mSourceURI, aNewLayer.mSourceURI)) {
+  if (!DefinitelyEqualURIs(mImage.GetURLValueData(),
+                           aNewLayer.mImage.GetURLValueData())) {
     hint |= nsChangeHint_RepaintFrame | nsChangeHint_UpdateEffects;
 
     // If Layer::mSourceURI links to a SVG mask, it has a fragment. Not vice
     // versa. Here are examples of URI contains a fragment, two of them link
     // to a SVG mask:
     //   mask:url(a.svg#maskID); // The fragment of this URI is an ID of a mask
     //                           // element in a.svg.
     //   mask:url(#localMaskID); // The fragment of this URI is an ID of a mask
     //                           // element in local document.
     //   mask:url(b.svg#viewBoxID); // The fragment of this URI is an ID of a
     //                              // viewbox defined in b.svg.
     // That is, if mSourceURI has a fragment, it may link to a SVG mask; If
     // not, it "must" not link to a SVG mask.
     bool maybeSVGMask = false;
-    if (mSourceURI) {
-      maybeSVGMask = mSourceURI->HasRef();
+    css::URLValueData* oldData = mImage.GetURLValueData();
+    if (oldData) {
+      maybeSVGMask = oldData->HasRef();
     }
 
-    if (!maybeSVGMask && aNewLayer.mSourceURI) {
-      maybeSVGMask = aNewLayer.mSourceURI->HasRef();
+    css::URLValueData* newData = aNewLayer.mImage.GetURLValueData();
+    if (!maybeSVGMask && newData) {
+      maybeSVGMask = newData->HasRef();
     }
 
     // Return nsChangeHint_UpdateOverflow if either URI might link to an SVG
     // mask.
     if (maybeSVGMask) {
       // Mask changes require that we update the PreEffectsBBoxProperty,
       // which is done during overflow computation.
       hint |= nsChangeHint_UpdateOverflow;
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -728,24 +728,16 @@ struct nsStyleImageLayers {
   };
 
   struct Layer;
   friend struct Layer;
   struct Layer {
     typedef mozilla::StyleGeometryBox StyleGeometryBox;
 
     nsStyleImage  mImage;         // [reset]
-    RefPtr<mozilla::css::URLValueData> mSourceURI;  // [reset]
-                                  // mask-only property
-                                  // This property is used for mask layer only.
-                                  // For a background layer, it should always
-                                  // be the initial value, which is nullptr.
-                                  // Store mask-image URI so that we can resolve
-                                  // SVG mask path later.  (Might be a URLValue
-                                  // or an ImageValue.)
     mozilla::Position mPosition;  // [reset]
     Size          mSize;          // [reset]
     StyleGeometryBox  mClip;      // [reset] See nsStyleConsts.h
     MOZ_INIT_OUTSIDE_CTOR
       StyleGeometryBox mOrigin;   // [reset] See nsStyleConsts.h
     uint8_t       mAttachment;    // [reset] See nsStyleConsts.h
                                   // background-only property
                                   // This property is used for background layer
@@ -3618,16 +3610,18 @@ private:
 template<>
 struct nsTArray_CopyChooser<nsStyleFilter>
 {
   typedef nsTArray_CopyWithConstructors<nsStyleFilter> Type;
 };
 
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset
 {
+  typedef mozilla::css::URLValueData URLValueData;
+
   explicit nsStyleSVGReset(const nsPresContext* aContext);
   nsStyleSVGReset(const nsStyleSVGReset& aSource);
   ~nsStyleSVGReset();
 
   // Resolves and tracks the images in mMask.  Only called with a Servo-backed
   // style system, where those images must be resolved later than the OMT
   // nsStyleSVGReset constructor call.
   void FinishStyle(nsPresContext* aPresContext);
--- a/layout/svg/nsSVGEffects.cpp
+++ b/layout/svg/nsSVGEffects.cpp
@@ -1013,11 +1013,12 @@ nsSVGEffects::GetPaintURI(nsIFrame* aFra
 }
 
 already_AddRefed<nsIURI>
 nsSVGEffects::GetMaskURI(nsIFrame* aFrame, uint32_t aIndex)
 {
   const nsStyleSVGReset* svgReset = aFrame->StyleSVGReset();
   MOZ_ASSERT(svgReset->mMask.mLayers.Length() > aIndex);
 
-  return ResolveURLUsingLocalRef(aFrame,
-                                 svgReset->mMask.mLayers[aIndex].mSourceURI);
+  mozilla::css::URLValueData* data =
+    svgReset->mMask.mLayers[aIndex].mImage.GetURLValueData();
+  return ResolveURLUsingLocalRef(aFrame, data);
 }