Bug 1342302 - Part 2. Implement ImageLayerClipState::IsValid. r=mstange
authorcku <cku@mozilla.com>
Fri, 24 Feb 2017 18:52:53 +0800
changeset 373907 f4ac43e3f67db80ac8a10fe00eb247c028ce7d4b
parent 373906 14fd552c865b6492e84a8a71ede89e534c529b10
child 373908 a1deec7b451aaf446d02bf454b296dc5fe959c13
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1342302
milestone54.0a1
Bug 1342302 - Part 2. Implement ImageLayerClipState::IsValid. r=mstange 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);