Bug 1342302 - Part 2. Implement ImageLayerClipState::IsValid. draft
authorcku <cku@mozilla.com>
Fri, 24 Feb 2017 18:52:53 +0800
changeset 489596 7619e4c40eba475970d51518c63db8406f5593be
parent 489595 8e17fb38e43ecb71648d7e397c37cc398d5b5715
child 489597 303defc27980c0ea51037ebf131bf05dc04cbdf3
push id46865
push userbmo:cku@mozilla.com
push dateSat, 25 Feb 2017 05:23:41 +0000
bugs1342302
milestone54.0a1
Bug 1342302 - Part 2. Implement ImageLayerClipState::IsValid. MozReview-Commit-ID: 2Axr7buX1c4
layout/painting/nsCSSRendering.cpp
layout/painting/nsCSSRendering.h
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -1984,25 +1984,42 @@ ComputeBoxValue(nsIFrame* aForFrame, Sty
     if (IsHTMLStyleGeometryBox(aBox)) {
       return StyleGeometryBox::Fill;
     }
   }
 
   return aBox;
 }
 
+bool
+nsCSSRendering::ImageLayerClipState::IsValid() const
+{
+  // mDirtyRectGfx comes from mDirtyRect. If mDirtyRectGfx is not empty,
+  // mDirtyRect can never be empty.
+  if (!mDirtyRectGfx.IsEmpty() && mDirtyRect.IsEmpty()) {
+    return false;
+  }
+
+  if (mHasRoundedCorners == mClippedRadii.IsEmpty()) {
+    return false;
+  }
+
+  return true;
+}
+
 /* static */ void
 nsCSSRendering::GetImageLayerClip(const nsStyleImageLayers::Layer& aLayer,
                                   nsIFrame* aForFrame, const nsStyleBorder& aBorder,
                                   const nsRect& aBorderArea, const nsRect& aCallerDirtyRect,
                                   bool aWillPaintBorder, nscoord aAppUnitsPerPixel,
                                   /* out */ ImageLayerClipState* aClipState)
 {
   aClipState->mHasRoundedCorners = false;
   aClipState->mHasAdditionalBGClipArea = false;
+  aClipState->mAdditionalBGClipArea.SetEmpty();
   aClipState->mCustomClip = false;
 
   StyleGeometryBox layerClip = ComputeBoxValue(aForFrame, aLayer.mClip);
   if (IsSVGStyleGeometryBox(layerClip)) {
     MOZ_ASSERT(aForFrame->IsFrameOfType(nsIFrame::eSVG) &&
                (aForFrame->GetType() != nsGkAtoms::svgOuterSVGFrame));
 
     // The coordinate space of clipArea is svg user space.
@@ -2023,25 +2040,27 @@ nsCSSRendering::GetImageLayerClip(const 
     // coordiante space with aBorderArea. So we evaluate the position of clip
     // area base on the position of aBorderArea here.
     aClipState->mBGClipArea =
       clipAreaRelativeToStrokeBox + aBorderArea.TopLeft();
 
     SetupDirtyRects(aClipState->mBGClipArea, aCallerDirtyRect,
                     aAppUnitsPerPixel, &aClipState->mDirtyRect,
                     &aClipState->mDirtyRectGfx);
+    MOZ_ASSERT(aClipState->IsValid());
     return;
   }
 
   if (layerClip == StyleGeometryBox::NoClip) {
     aClipState->mBGClipArea = aCallerDirtyRect;
 
     SetupDirtyRects(aClipState->mBGClipArea, aCallerDirtyRect,
                     aAppUnitsPerPixel, &aClipState->mDirtyRect,
                     &aClipState->mDirtyRectGfx);
+    MOZ_ASSERT(aClipState->IsValid());
     return;
   }
 
   MOZ_ASSERT(!aForFrame->IsFrameOfType(nsIFrame::eSVG) ||
              aForFrame->GetType() == nsGkAtoms::svgOuterSVGFrame);
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aBorderArea.
@@ -2140,16 +2159,18 @@ nsCSSRendering::GetImageLayerClip(const 
     // Do the intersection here to account for the fast path(?) below.
     aClipState->mBGClipArea =
       aClipState->mBGClipArea.Intersect(aClipState->mAdditionalBGClipArea);
     aClipState->mHasAdditionalBGClipArea = false;
   }
 
   SetupDirtyRects(aClipState->mBGClipArea, aCallerDirtyRect, aAppUnitsPerPixel,
                   &aClipState->mDirtyRect, &aClipState->mDirtyRectGfx);
+
+  MOZ_ASSERT(aClipState->IsValid());
 }
 
 static void
 SetupImageLayerClip(nsCSSRendering::ImageLayerClipState& aClipState,
                     gfxContext *aCtx, nscoord aAppUnitsPerPixel,
                     gfxContextAutoSaveRestore* aAutoSR)
 {
   if (aClipState.mDirtyRectGfx.IsEmpty()) {
--- a/layout/painting/nsCSSRendering.h
+++ b/layout/painting/nsCSSRendering.h
@@ -612,16 +612,18 @@ struct nsCSSRendering {
 
     ImageLayerClipState()
      : mHasRoundedCorners(false),
        mHasAdditionalBGClipArea(false),
        mCustomClip(false)
     {
       memset(mRadii, 0, sizeof(nscoord) * 8);
     }
+
+    bool IsValid() const;
   };
 
   static void
   GetImageLayerClip(const nsStyleImageLayers::Layer& aLayer,
                     nsIFrame* aForFrame, const nsStyleBorder& aBorder,
                     const nsRect& aBorderArea, const nsRect& aCallerDirtyRect,
                     bool aWillPaintBorder, nscoord aAppUnitsPerPixel,
                     /* out */ ImageLayerClipState* aClipState);