Commit 0ed88b02 authored by Matt Woodrow's avatar Matt Woodrow
Browse files

Bug 1438990 - Remove common clip count code from FrameLayerBuilder, as it's no...

Bug 1438990 - Remove common clip count code from FrameLayerBuilder, as it's no longer necessary now that we have ASRs. r=mstange
parent 9ef90362
Loading
Loading
Loading
Loading
+12 −36
Original line number Diff line number Diff line
@@ -91,11 +91,10 @@ DisplayItemClip::IntersectWith(const DisplayItemClip& aOther)

void
DisplayItemClip::ApplyTo(gfxContext* aContext,
                         int32_t A2D,
                         uint32_t aBegin, uint32_t aEnd)
                         int32_t A2D)
{
  ApplyRectTo(aContext, A2D);
  ApplyRoundedRectClipsTo(aContext, A2D, aBegin, aEnd);
  ApplyRoundedRectClipsTo(aContext, A2D, 0, mRoundedClipRects.Length());
}

void
@@ -126,30 +125,27 @@ DisplayItemClip::ApplyRoundedRectClipsTo(gfxContext* aContext,
void
DisplayItemClip::FillIntersectionOfRoundedRectClips(gfxContext* aContext,
                                                    const Color& aColor,
                                                    int32_t aAppUnitsPerDevPixel,
                                                    uint32_t aBegin,
                                                    uint32_t aEnd) const
                                                    int32_t aAppUnitsPerDevPixel) const
{
  DrawTarget& aDrawTarget = *aContext->GetDrawTarget();

  aEnd = std::min<uint32_t>(aEnd, mRoundedClipRects.Length());

  if (aBegin >= aEnd) {
  uint32_t end = mRoundedClipRects.Length();
  if (!end) {
    return;
  }

  // Push clips for any rects that come BEFORE the rect at |aEnd - 1|, if any:
  ApplyRoundedRectClipsTo(aContext, aAppUnitsPerDevPixel, aBegin, aEnd - 1);
  ApplyRoundedRectClipsTo(aContext, aAppUnitsPerDevPixel, 0, end - 1);

  // Now fill the rect at |aEnd - 1|:
  RefPtr<Path> roundedRect = MakeRoundedRectPath(aDrawTarget,
                                                 aAppUnitsPerDevPixel,
                                                 mRoundedClipRects[aEnd - 1]);
                                                 mRoundedClipRects[end - 1]);
  ColorPattern color(ToDeviceColor(aColor));
  aDrawTarget.Fill(roundedRect, color);

  // Finally, pop any clips that we may have pushed:
  for (uint32_t i = aBegin; i < aEnd - 1; ++i) {
  for (uint32_t i = 0; i < end - 1; ++i) {
    aContext->PopClip();
  }
}
@@ -358,16 +354,13 @@ AccumulateRectDifference(const nsRect& aR1, const nsRect& aR2, const nsRect& aBo
}

void
DisplayItemClip::AddOffsetAndComputeDifference(uint32_t aStart,
                                               const nsPoint& aOffset,
DisplayItemClip::AddOffsetAndComputeDifference(const nsPoint& aOffset,
                                               const nsRect& aBounds,
                                               const DisplayItemClip& aOther,
                                               uint32_t aOtherStart,
                                               const nsRect& aOtherBounds,
                                               nsRegion* aDifference)
{
  if (mHaveClipRect != aOther.mHaveClipRect ||
      aStart != aOtherStart ||
      mRoundedClipRects.Length() != aOther.mRoundedClipRects.Length()) {
    aDifference->Or(*aDifference, aBounds);
    aDifference->Or(*aDifference, aOtherBounds);
@@ -378,7 +371,7 @@ DisplayItemClip::AddOffsetAndComputeDifference(uint32_t aStart,
                             aBounds.Union(aOtherBounds),
                             aDifference);
  }
  for (uint32_t i = aStart; i < mRoundedClipRects.Length(); ++i) {
  for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
    if (mRoundedClipRects[i] + aOffset != aOther.mRoundedClipRects[i]) {
      // The corners make it tricky so we'll just add both rects here.
      aDifference->Or(*aDifference, mRoundedClipRects[i].mRect.Intersect(aBounds));
@@ -387,27 +380,10 @@ DisplayItemClip::AddOffsetAndComputeDifference(uint32_t aStart,
  }
}

uint32_t
DisplayItemClip::GetCommonRoundedRectCount(const DisplayItemClip& aOther,
                                           uint32_t aMax) const
{
  uint32_t end = std::min(std::min(mRoundedClipRects.Length(), size_t(aMax)),
                          aOther.mRoundedClipRects.Length());
  uint32_t clipCount = 0;
  for (; clipCount < end; ++clipCount) {
    if (mRoundedClipRects[clipCount] !=
        aOther.mRoundedClipRects[clipCount]) {
      return clipCount;
    }
  }
  return clipCount;
}

void
DisplayItemClip::AppendRoundedRects(nsTArray<RoundedRect>* aArray, uint32_t aCount) const
DisplayItemClip::AppendRoundedRects(nsTArray<RoundedRect>* aArray) const
{
  size_t count = std::min(mRoundedClipRects.Length(), size_t(aCount));
  aArray->AppendElements(mRoundedClipRects.Elements(), count);
  aArray->AppendElements(mRoundedClipRects.Elements(), mRoundedClipRects.Length());
}

bool
+5 −14
Original line number Diff line number Diff line
@@ -81,8 +81,7 @@ public:
  // Apply this |DisplayItemClip| to the given gfxContext.  Any saving of state
  // or clearing of other clips must be done by the caller.
  // See aBegin/aEnd note on ApplyRoundedRectsTo.
  void ApplyTo(gfxContext* aContext, int32_t A2D,
               uint32_t aBegin = 0, uint32_t aEnd = UINT32_MAX);
  void ApplyTo(gfxContext* aContext, int32_t A2D);

  void ApplyRectTo(gfxContext* aContext, int32_t A2D) const;
  // Applies the rounded rects in this Clip to aContext
@@ -94,9 +93,7 @@ public:
  // Draw (fill) the rounded rects in this clip to aContext
  void FillIntersectionOfRoundedRectClips(gfxContext* aContext,
                                          const Color& aColor,
                                          int32_t aAppUnitsPerDevPixel,
                                          uint32_t aBegin,
                                          uint32_t aEnd) const;
                                          int32_t aAppUnitsPerDevPixel) const;
  // 'Draw' (create as a path, does not stroke or fill) aRoundRect to aContext
  already_AddRefed<Path> MakeRoundedRectPath(DrawTarget& aDrawTarget,
                                                  int32_t A2D,
@@ -148,8 +145,8 @@ public:

  // Adds the difference between Intersect(*this + aPoint, aBounds) and
  // Intersect(aOther, aOtherBounds) to aDifference (or a bounding-box thereof).
  void AddOffsetAndComputeDifference(uint32_t aStart, const nsPoint& aPoint, const nsRect& aBounds,
                                     const DisplayItemClip& aOther, uint32_t aOtherStart, const nsRect& aOtherBounds,
  void AddOffsetAndComputeDifference(const nsPoint& aPoint, const nsRect& aBounds,
                                     const DisplayItemClip& aOther, const nsRect& aOtherBounds,
                                     nsRegion* aDifference);

  bool operator==(const DisplayItemClip& aOther) const {
@@ -172,14 +169,8 @@ public:

  nsCString ToString() const;

  /**
   * Find the largest N such that the first N rounded rects in 'this' are
   * equal to the first N rounded rects in aOther, and N <= aMax.
   */
  uint32_t GetCommonRoundedRectCount(const DisplayItemClip& aOther,
                                     uint32_t aMax) const;
  uint32_t GetRoundedRectCount() const { return mRoundedClipRects.Length(); }
  void AppendRoundedRects(nsTArray<RoundedRect>* aArray, uint32_t aCount) const;
  void AppendRoundedRects(nsTArray<RoundedRect>* aArray) const;

  void ToComplexClipRegions(int32_t aAppUnitsPerDevPixel,
                              const layers::StackingContextHelper& aSc,
+22 −105
Original line number Diff line number Diff line
@@ -449,7 +449,6 @@ public:
    mShouldPaintOnContentSide(false),
    mDTCRequiresTargetConfirmation(false),
    mImage(nullptr),
    mCommonClipCount(-1),
    mNewChildLayersIndex(-1)
  {}

@@ -661,24 +660,10 @@ public:
   * no part at all.
   */
  DisplayItemClip mItemClip;
  /**
   * The first mCommonClipCount rounded rectangle clips are identical for
   * all items in the layer.
   * -1 if there are no items in the layer; must be >=0 by the time that this
   * data is popped from the stack.
   */
  int32_t mCommonClipCount;
  /**
   * Index of this layer in mNewChildLayers.
   */
  int32_t mNewChildLayersIndex;
  /*
   * Updates mCommonClipCount by checking for rounded rect clips in common
   * between the clip on a new item (aCurrentClip) and the common clips
   * on items already in the layer (the first mCommonClipCount rounded rects
   * in mItemClip).
   */
  void UpdateCommonClipCount(const DisplayItemClip& aCurrentClip);
  /**
   * The region of visible content above the layer and below the
   * next PaintedLayerData currently in the stack, if any.
@@ -1385,12 +1370,8 @@ protected:
   * aLayer is the layer to be clipped.
   * relative to the container reference frame
   * aRoundedRectClipCount is used when building mask layers for PaintedLayers,
   * SetupMaskLayer will build a mask layer for only the first
   * aRoundedRectClipCount rounded rects in aClip
   * Returns the number of rounded rects included in the mask layer.
   */
  uint32_t SetupMaskLayer(Layer *aLayer, const DisplayItemClip& aClip,
                          uint32_t aRoundedRectClipCount = UINT32_MAX);
  void SetupMaskLayer(Layer *aLayer, const DisplayItemClip& aClip);

  /**
   * If |aClip| has rounded corners, create a mask layer for them, and
@@ -1410,8 +1391,7 @@ protected:

  already_AddRefed<Layer> CreateMaskLayer(
    Layer *aLayer, const DisplayItemClip& aClip,
    const Maybe<size_t>& aForAncestorMaskLayer,
    uint32_t aRoundedRectClipCount = UINT32_MAX);
    const Maybe<size_t>& aForAncestorMaskLayer);

  /**
   * Get the display port for an AGR.
@@ -1498,8 +1478,6 @@ class PaintedDisplayItemLayerUserData : public LayerUserData
{
public:
  PaintedDisplayItemLayerUserData() :
    mMaskClipCount(0),
    mLastCommonClipCount(0),
    mForcedBackgroundColor(NS_RGBA(0,0,0,0)),
    mXScale(1.f), mYScale(1.f),
    mAppUnitsPerDevPixel(0),
@@ -1511,19 +1489,6 @@ public:

  NS_INLINE_DECL_REFCOUNTING(PaintedDisplayItemLayerUserData);

  /**
   * Record the number of clips in the PaintedLayer's mask layer.
   * Should not be reset when the layer is recycled since it is used to track
   * changes in the use of mask layers.
   */
  uint32_t mMaskClipCount;

  /**
   * Records the number of clips in the PaintedLayer's mask layer during
   * the previous paint. Used for invalidation.
   */
  uint32_t mLastCommonClipCount;

  /**
   * A color that should be painted over the bounds of the layer's visible
   * region before any other content is painted.
@@ -1640,7 +1605,6 @@ struct MaskLayerUserData : public LayerUserData
    , mAppUnitsPerDevPixel(-1)
  { }
  MaskLayerUserData(const DisplayItemClip& aClip,
                    uint32_t aRoundedRectClipCount,
                    int32_t aAppUnitsPerDevPixel,
                    const ContainerLayerParameters& aParams)
    : mScaleX(aParams.mXScale)
@@ -1648,7 +1612,7 @@ struct MaskLayerUserData : public LayerUserData
    , mOffset(aParams.mOffset)
    , mAppUnitsPerDevPixel(aAppUnitsPerDevPixel)
  {
    aClip.AppendRoundedRects(&mRoundedClipRects, aRoundedRectClipCount);
    aClip.AppendRoundedRects(&mRoundedClipRects);
  }

  void operator=(MaskLayerUserData&& aOther)
@@ -2500,7 +2464,6 @@ ContainerState::PreparePaintedLayerForUse(PaintedLayer* aLayer,

  aData->mLastPaintOffset = GetTranslationForPaintedLayer(aLayer);
  aData->mHasExplicitLastPaintOffset = true;
  aData->mLastCommonClipCount = aData->mMaskClipCount;

  // Set up transform so that 0,0 in the PaintedLayer corresponds to the
  // (pixel-snapped) top-left of the aAnimatedGeometryRoot.
@@ -2763,18 +2726,6 @@ PaintedLayerDataNode::FindOpaqueBackgroundColorInParentNode() const
  return mTree.UniformBackgroundColor();
}

void
PaintedLayerData::UpdateCommonClipCount(
    const DisplayItemClip& aCurrentClip)
{
  if (mCommonClipCount >= 0) {
    mCommonClipCount = mItemClip.GetCommonRoundedRectCount(aCurrentClip, mCommonClipCount);
  } else {
    // first item in the layer
    mCommonClipCount = aCurrentClip.GetRoundedRectCount();
  }
}

bool
PaintedLayerData::CanOptimizeToImageLayer(nsDisplayListBuilder* aBuilder)
{
@@ -3361,22 +3312,7 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB
      data->mLayer->InvalidateWholeLayer();
    }
    userData->mForcedBackgroundColor = backgroundColor;

    // use a mask layer for rounded rect clipping.
    // data->mCommonClipCount may be -1 if we haven't put any actual
    // drawable items in this layer (i.e. it's only catching events).
    uint32_t commonClipCount;
    commonClipCount = std::max(0, data->mCommonClipCount);

    // if the number of clips we are going to mask has decreased, then aLayer might have
    // cached graphics which assume the existence of a soon-to-be non-existent mask layer
    // in that case, invalidate the whole layer.
    if (commonClipCount < userData->mMaskClipCount) {
      PaintedLayer* painted = layer->AsPaintedLayer();
      painted->InvalidateWholeLayer();
    }

    userData->mMaskClipCount = SetupMaskLayer(layer, data->mItemClip, commonClipCount);
    SetupMaskLayer(layer, data->mItemClip);
  } else {
    // mask layer for image and color layers
    SetupMaskLayer(layer, data->mItemClip);
@@ -4019,8 +3955,7 @@ ContainerState::SetupMaskLayerForScrolledClip(Layer* aLayer,
{
  if (aClip.GetRoundedRectCount() > 0) {
    Maybe<size_t> maskLayerIndex = Some(aLayer->GetAncestorMaskLayerCount());
    if (RefPtr<Layer> maskLayer = CreateMaskLayer(aLayer, aClip, maskLayerIndex,
                                                  aClip.GetRoundedRectCount())) {
    if (RefPtr<Layer> maskLayer = CreateMaskLayer(aLayer, aClip, maskLayerIndex)) {
      aLayer->AddAncestorMaskLayer(maskLayer);
      return maskLayerIndex;
    }
@@ -4687,11 +4622,6 @@ ContainerState::ProcessDisplayItems(nsDisplayList* aList)
          static_cast<nsDisplayCompositorHitTestInfo*>(item);
        paintedLayerData->AccumulateHitTestInfo(this, hitTestInfo);
      } else {
        // check to see if the new item has rounded rect clips in common with
        // other items in the layer
        if (mManager->IsWidgetLayerManager()) {
          paintedLayerData->UpdateCommonClipCount(itemClip);
        }
        paintedLayerData->Accumulate(this, item, itemVisibleRect, itemClip, layerState, aList);

        if (!paintedLayerData->mLayer) {
@@ -4820,10 +4750,8 @@ FrameLayerBuilder::ComputeGeometryChangeForItem(DisplayItemData* aData)
    if (!combined.IsEmpty() || aData->mLayerState == LAYER_INACTIVE) {
      geometry = item->AllocateGeometry(mDisplayListBuilder);
    }
    aData->mClip.AddOffsetAndComputeDifference(layerData->mMaskClipCount,
                                               shift, aData->mGeometry->ComputeInvalidationRegion(),
                                               clip, layerData->mLastCommonClipCount,
                                               geometry ? geometry->ComputeInvalidationRegion() :
    aData->mClip.AddOffsetAndComputeDifference(shift, aData->mGeometry->ComputeInvalidationRegion(),
                                               clip, geometry ? geometry->ComputeInvalidationRegion() :
                                                                aData->mGeometry->ComputeInvalidationRegion(),
                                               &combined);

@@ -5308,7 +5236,7 @@ ContainerState::SetupScrollingMetadata(NewLayerEntry* aEntry)
      // layer as an additional, separate clip.
      Maybe<size_t> nextIndex = Some(maskLayers.Length());
      RefPtr<Layer> maskLayer =
        CreateMaskLayer(aEntry->mLayer, *clip, nextIndex, clip->GetRoundedRectCount());
        CreateMaskLayer(aEntry->mLayer, *clip, nextIndex);
      if (maskLayer) {
        MOZ_ASSERT(metadata->HasScrollClip());
        metadata->ScrollClip().SetMaskLayerIndex(nextIndex);
@@ -6034,8 +5962,7 @@ FrameLayerBuilder::PaintItems(nsTArray<AssignedDisplayItem>& aItems,
                              nsDisplayListBuilder* aBuilder,
                              nsPresContext* aPresContext,
                              const nsIntPoint& aOffset,
                              float aXScale, float aYScale,
                              int32_t aCommonClipCount)
                              float aXScale, float aYScale)
{
  DrawTarget& aDrawTarget = *aContext->GetDrawTarget();

@@ -6084,9 +6011,7 @@ FrameLayerBuilder::PaintItems(nsTArray<AssignedDisplayItem>& aItems,
      if (currentClipIsSetInContext) {
        currentClip = *clip;
        aContext->Save();
        NS_ASSERTION(aCommonClipCount < 100,
          "Maybe you really do have more than a hundred clipping rounded rects, or maybe something has gone wrong.");
        currentClip.ApplyTo(aContext, aPresContext->AppUnitsPerDevPixel(), aCommonClipCount);
        currentClip.ApplyTo(aContext, aPresContext->AppUnitsPerDevPixel());
        aContext->NewPath();
      }
    }
@@ -6249,8 +6174,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer,

      layerBuilder->PaintItems(userData->mItems, iterRect, aContext,
                               builder, presContext,
                               offset, userData->mXScale, userData->mYScale,
                               userData->mMaskClipCount);
                               offset, userData->mXScale, userData->mYScale);
      if (gfxPrefs::GfxLoggingPaintedPixelCountEnabled()) {
        aLayer->Manager()->AddPaintedPixelCount(iterRect.Area());
      }
@@ -6265,8 +6189,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer,

    layerBuilder->PaintItems(userData->mItems, aRegionToDraw.GetBounds(), aContext,
                             builder, presContext,
                             offset, userData->mXScale, userData->mYScale,
                             userData->mMaskClipCount);
                             offset, userData->mXScale, userData->mYScale);
    if (gfxPrefs::GfxLoggingPaintedPixelCountEnabled()) {
      aLayer->Manager()->AddPaintedPixelCount(
        aRegionToDraw.GetBounds().Area());
@@ -6343,26 +6266,23 @@ CalculateBounds(const nsTArray<DisplayItemClip::RoundedRect>& aRects, int32_t aA
  return gfx::Rect(bounds.ToNearestPixels(aAppUnitsPerDevPixel));
}

uint32_t
void
ContainerState::SetupMaskLayer(Layer *aLayer,
                               const DisplayItemClip& aClip,
                               uint32_t aRoundedRectClipCount)
                               const DisplayItemClip& aClip)
{
  // don't build an unnecessary mask
  if (aClip.GetRoundedRectCount() == 0 ||
      aRoundedRectClipCount == 0) {
    return 0;
  if (aClip.GetRoundedRectCount() == 0) {
    return;
  }

  RefPtr<Layer> maskLayer =
    CreateMaskLayer(aLayer, aClip, Nothing(), aRoundedRectClipCount);
    CreateMaskLayer(aLayer, aClip, Nothing());

  if (!maskLayer) {
    return 0;
    return;
  }

  aLayer->SetMaskLayer(maskLayer);
  return aRoundedRectClipCount;
}

static MaskLayerUserData*
@@ -6387,8 +6307,7 @@ SetMaskLayerUserData(Layer* aMaskLayer)
already_AddRefed<Layer>
ContainerState::CreateMaskLayer(Layer *aLayer,
                               const DisplayItemClip& aClip,
                               const Maybe<size_t>& aForAncestorMaskLayer,
                               uint32_t aRoundedRectClipCount)
                               const Maybe<size_t>& aForAncestorMaskLayer)
{
  // aLayer will never be the container layer created by an nsDisplayMask
  // because nsDisplayMask propagates the DisplayItemClip to its contents
@@ -6405,7 +6324,7 @@ ContainerState::CreateMaskLayer(Layer *aLayer,
  MaskLayerUserData* userData = GetMaskLayerUserData(maskLayer.get());

  int32_t A2D = mContainerFrame->PresContext()->AppUnitsPerDevPixel();
  MaskLayerUserData newData(aClip, aRoundedRectClipCount, A2D, mParameters);
  MaskLayerUserData newData(aClip, A2D, mParameters);
  if (*userData == newData) {
    return maskLayer.forget();
  }
@@ -6485,9 +6404,7 @@ ContainerState::CreateMaskLayer(Layer *aLayer,
    // paint the clipping rects with alpha to create the mask
    aClip.FillIntersectionOfRoundedRectClips(context,
                                             Color(1.f, 1.f, 1.f, 1.f),
                                             newData.mAppUnitsPerDevPixel,
                                             0,
                                             aRoundedRectClipCount);
                                             newData.mAppUnitsPerDevPixel);

    // build the image and container
    MOZ_ASSERT(aLayer->Manager() == mManager);
+1 −2
Original line number Diff line number Diff line
@@ -674,8 +674,7 @@ protected:
                  nsDisplayListBuilder* aBuilder,
                  nsPresContext* aPresContext,
                  const nsIntPoint& aOffset,
                  float aXScale, float aYScale,
                  int32_t aCommonClipCount);
                  float aXScale, float aYScale);

  /**
   * We accumulate ClippedDisplayItem elements in a hashtable during