Bug 1442190 - Part 3: Add functionality to know whether nsDisplayOpacity::ShouldFlattenAway() applied opacity to children r=mattwoodrow

MozReview-Commit-ID: Bns788u5wmM

--HG--
extra : rebase_source : c8da49ae5ac2d4db1f2d0966ca6538867ed791ec
This commit is contained in:
Miko Mynttinen 2018-03-21 12:19:57 +01:00
Родитель 8b458da113
Коммит 4dd4bfd525
2 изменённых файлов: 48 добавлений и 21 удалений

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

@ -6409,6 +6409,7 @@ nsDisplayOpacity::nsDisplayOpacity(nsDisplayListBuilder* aBuilder,
: nsDisplayWrapList(aBuilder, aFrame, aList, aActiveScrolledRoot, true)
, mOpacity(aFrame->StyleEffects()->mOpacity)
, mForEventsAndPluginsOnly(aForEventsAndPluginsOnly)
, mOpacityAppliedToChildren(false)
{
MOZ_COUNT_CTOR(nsDisplayOpacity);
mState.mOpacity = mOpacity;
@ -6544,27 +6545,8 @@ CollectItemsWithOpacity(nsDisplayList* aList,
}
bool
nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
nsDisplayOpacity::ApplyOpacityToChildren(nsDisplayListBuilder* aBuilder)
{
if (mFrame->GetPrevContinuation() ||
mFrame->GetNextContinuation()) {
// If we've been split, then we might need to merge, so
// don't flatten us away.
return false;
}
if (NeedsActiveLayer(aBuilder, mFrame) || mOpacity == 0.0) {
// If our opacity is zero then we'll discard all descendant display items
// except for layer event regions, so there's no point in doing this
// optimization (and if we do do it, then invalidations of those descendants
// might trigger repainting).
return false;
}
if (mList.IsEmpty()) {
return false;
}
// Only try folding our opacity down if we have at most kMaxChildCount
// children that don't overlap and can all apply the opacity to themselves.
static const size_t kMaxChildCount = 3;
@ -6601,9 +6583,38 @@ nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
children[i].item->ApplyOpacity(aBuilder, mOpacity, mClipChain);
}
mOpacityAppliedToChildren = true;
return true;
}
bool
nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
{
// ShouldFlattenAway() should be called only once during painting.
MOZ_ASSERT(!mOpacityAppliedToChildren);
if (mFrame->GetPrevContinuation() ||
mFrame->GetNextContinuation()) {
// If we've been split, then we might need to merge, so
// don't flatten us away.
return false;
}
if (NeedsActiveLayer(aBuilder, mFrame) || mOpacity == 0.0) {
// If our opacity is zero then we'll discard all descendant display items
// except for layer event regions, so there's no point in doing this
// optimization (and if we do do it, then invalidations of those descendants
// might trigger repainting).
return false;
}
if (mList.IsEmpty()) {
return false;
}
return ApplyOpacityToChildren(aBuilder);
}
nsDisplayItem::LayerState
nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
LayerManager* aManager,

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

@ -5246,12 +5246,18 @@ public:
nsDisplayList* aList,
const ActiveScrolledRoot* aActiveScrolledRoot,
bool aForEventsAndPluginsOnly);
nsDisplayOpacity(nsDisplayListBuilder* aBuilder,
const nsDisplayOpacity& aOther)
: nsDisplayWrapList(aBuilder, aOther)
, mOpacity(aOther.mOpacity)
, mForEventsAndPluginsOnly(aOther.mForEventsAndPluginsOnly)
{}
, mOpacityAppliedToChildren(false)
{
// We should not try to merge flattened opacities.
MOZ_ASSERT(!aOther.mOpacityAppliedToChildren);
}
#ifdef NS_BUILD_REFCNT_LOGGING
virtual ~nsDisplayOpacity();
#endif
@ -5260,6 +5266,7 @@ public:
{
nsDisplayItem::RestoreState();
mOpacity = mState.mOpacity;
mOpacityAppliedToChildren = false;
}
virtual nsDisplayWrapList* Clone(nsDisplayListBuilder* aBuilder) const override
@ -5308,6 +5315,12 @@ public:
const DisplayItemClipChain* aClip) override;
virtual bool CanApplyOpacity() const override;
virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override;
/**
* Returns true if ShouldFlattenAway() applied opacity to children.
*/
bool OpacityAppliedToChildren() const { return mOpacityAppliedToChildren; }
static bool NeedsActiveLayer(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame);
NS_DISPLAY_DECL_NAME("Opacity", TYPE_OPACITY)
virtual void WriteDebugInfo(std::stringstream& aStream) override;
@ -5323,8 +5336,11 @@ public:
float GetOpacity() { return mOpacity; }
private:
bool ApplyOpacityToChildren(nsDisplayListBuilder* aBuilder);
float mOpacity;
bool mForEventsAndPluginsOnly;
bool mOpacityAppliedToChildren;
struct {
float mOpacity;