Bug 1438990 - Remove common clip count code from FrameLayerBuilder, as it's no longer necessary now that we have ASRs. r=mstange

* * *
[mq]: fix

MozReview-Commit-ID: F3tlwtmGlvL
This commit is contained in:
Matt Woodrow 2018-03-07 15:40:42 +13:00
Родитель d0dd8f9f35
Коммит 9b38603602
5 изменённых файлов: 40 добавлений и 158 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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,

Просмотреть файл

@ -451,7 +451,6 @@ public:
mShouldPaintOnContentSide(false),
mDTCRequiresTargetConfirmation(false),
mImage(nullptr),
mCommonClipCount(-1),
mNewChildLayersIndex(-1)
{}
@ -663,24 +662,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.
@ -1387,12 +1372,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
@ -1412,8 +1393,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.
@ -1500,8 +1480,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),
@ -1513,19 +1491,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.
@ -1642,7 +1607,6 @@ struct MaskLayerUserData : public LayerUserData
, mAppUnitsPerDevPixel(-1)
{ }
MaskLayerUserData(const DisplayItemClip& aClip,
uint32_t aRoundedRectClipCount,
int32_t aAppUnitsPerDevPixel,
const ContainerLayerParameters& aParams)
: mScaleX(aParams.mXScale)
@ -1650,7 +1614,7 @@ struct MaskLayerUserData : public LayerUserData
, mOffset(aParams.mOffset)
, mAppUnitsPerDevPixel(aAppUnitsPerDevPixel)
{
aClip.AppendRoundedRects(&mRoundedClipRects, aRoundedRectClipCount);
aClip.AppendRoundedRects(&mRoundedClipRects);
}
void operator=(MaskLayerUserData&& aOther)
@ -2485,7 +2449,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.
@ -2748,18 +2711,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)
{
@ -3341,22 +3292,6 @@ 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);
} else {
// mask layer for image and color layers
SetupMaskLayer(layer, data->mItemClip);
@ -3999,8 +3934,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;
}
@ -4667,11 +4601,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) {
@ -4800,11 +4729,9 @@ 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->mGeometry->ComputeInvalidationRegion(),
aData->mClip.AddOffsetAndComputeDifference(shift, aData->mGeometry->ComputeInvalidationRegion(),
clip, geometry ? geometry->ComputeInvalidationRegion() :
aData->mGeometry->ComputeInvalidationRegion(),
&combined);
// Add in any rect that the frame specified
@ -5294,7 +5221,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);
@ -6020,8 +5947,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();
@ -6070,9 +5996,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();
}
}
@ -6235,8 +6159,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());
}
@ -6251,8 +6174,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());
@ -6326,26 +6248,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*
@ -6370,8 +6289,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
@ -6388,7 +6306,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();
}
@ -6468,9 +6386,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);

Просмотреть файл

@ -666,8 +666,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

Просмотреть файл

@ -51,7 +51,7 @@ fuzzy-if(/^Windows\x20NT\x206\.2/.test(http.oscpu),1,5) == clipping-5-image.html
fuzzy-if(/^Windows\x20NT\x206\.2/.test(http.oscpu),1,5) fuzzy-if(skiaContent,1,77) == clipping-5-overflow-hidden.html clipping-5-ref.html
fuzzy-if(/^Windows\x20NT\x206\.2/.test(http.oscpu),1,5) fuzzy-if(Android,5,21) fuzzy-if(skiaContent,1,97) == clipping-5-refi.html clipping-5-ref.html
fuzzy-if(true,1,7) fuzzy-if(d2d,55,95) fuzzy-if(cocoaWidget,1,99) fuzzy-if(Android,99,115) fuzzy-if(skiaContent,1,77) == clipping-5-refc.html clipping-5-ref.html # bug 732535
fuzzy-if(winWidget,105,71) fuzzy-if(Android,8,469) fuzzy-if(skiaContent,7,58) fuzzy-if(d3d11&&advancedLayers,120,319) fuzzy-if(winWidget&&stylo,144,319) == clipping-6.html clipping-6-ref.html # PaintedLayer and MaskLayer with transforms that aren't identical
fuzzy-if(winWidget,105,71) fuzzy-if(Android,8,469) fuzzy-if(skiaContent,16,74) fuzzy-if(d3d11&&advancedLayers,120,319) fuzzy-if(winWidget&&stylo,144,335) == clipping-6.html clipping-6-ref.html # PaintedLayer and MaskLayer with transforms that aren't identical
fuzzy-if(true,2,29) fuzzy-if(d2d,46,71) fuzzy-if(Android,255,586) fuzzy-if(skiaContent,28,96) == clipping-7.html clipping-7-ref.html # ColorLayer and MaskLayer with transforms that aren't identical. Reference image rendered without using layers (which causes fuzzy failures).
fuzzy-if(/^Windows\x20NT\x206\.2/.test(http.oscpu),1,5) == clipping-and-zindex-1.html clipping-and-zindex-1-ref.html
fuzzy-if(cocoaWidget,1,4) fuzzy-if(d2d,59,342) fuzzy-if(d3d11&&advancedLayers&&!d2d,30,3) == intersecting-clipping-1-canvas.html intersecting-clipping-1-refc.html