Bug 1730682 - Flatten opacity before setting up clips. r=miko

Pushing the clip for the opacity item into the clip manager has a non-trivial cost, so we get better performance if we handle flattening the item before that.

Differential Revision: https://phabricator.services.mozilla.com/D125633
This commit is contained in:
Matt Woodrow 2021-09-27 19:49:31 +00:00
parent a8494d482c
commit 56ed4f6cd9
2 changed files with 31 additions and 24 deletions

View File

@ -1728,6 +1728,37 @@ void WebRenderCommandBuilder::CreateWebRenderCommandsFromDisplayList(
DisplayItemType itemType = item->GetType();
// If this is a new (not retained/reused) item, then we need to disable
// the display item cache for descendants, since it's possible that some of
// them got cached with a flattened opacity values., which may no longer be
// applied.
Maybe<AutoDisplayItemCacheSuppressor> cacheSuppressor;
if (itemType == DisplayItemType::TYPE_OPACITY) {
nsDisplayOpacity* opacity = static_cast<nsDisplayOpacity*>(item);
if (!opacity->IsReused()) {
cacheSuppressor.emplace(aBuilder.GetDisplayItemCache());
}
if (opacity->CanApplyOpacityToChildren(
mManager->GetRenderRootStateManager()->LayerManager(),
aDisplayListBuilder, aBuilder.GetInheritedOpacity())) {
// If all our children support handling the opacity directly, then push
// the opacity and clip onto the builder and skip creating a stacking
// context.
float oldOpacity = aBuilder.GetInheritedOpacity();
aBuilder.SetInheritedOpacity(oldOpacity * opacity->GetOpacity());
CreateWebRenderCommandsFromDisplayList(opacity->GetChildren(), item,
aDisplayListBuilder, aSc,
aBuilder, aResources, false);
aBuilder.SetInheritedOpacity(oldOpacity);
continue;
}
}
// If this is an unscrolled background color item, in the root display list
// for the parent process, consider doing opaque checks.
if (XRE_IsParentProcess() && !aWrappingItem &&

View File

@ -4984,30 +4984,6 @@ bool nsDisplayOpacity::CreateWebRenderCommands(
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
const StackingContextHelper& aSc, RenderRootStateManager* aManager,
nsDisplayListBuilder* aDisplayListBuilder) {
// If this is a new (not retained/reused) item, then we need to disable
// the display item cache for descendants, since it's possible that some of
// them got cached with a flattened opacity values., which may no longer be
// applied.
Maybe<AutoDisplayItemCacheSuppressor> cacheSuppressor;
if (!IsReused()) {
cacheSuppressor.emplace(aBuilder.GetDisplayItemCache());
}
if (CanApplyOpacityToChildren(aManager->LayerManager(), aDisplayListBuilder,
aBuilder.GetInheritedOpacity())) {
// If all our children support handling the opacity directly, then push
// the opacity and clip onto the builder and skip creating a stacking
// context.
float oldOpacity = aBuilder.GetInheritedOpacity();
aBuilder.SetInheritedOpacity(oldOpacity * mOpacity);
aManager->CommandBuilder().CreateWebRenderCommandsFromDisplayList(
&mList, this, aDisplayListBuilder, aSc, aBuilder, aResources, false);
aBuilder.SetInheritedOpacity(oldOpacity);
return true;
}
MOZ_ASSERT(mChildOpacityState != ChildOpacityState::Applied);
float oldOpacity = aBuilder.GetInheritedOpacity();
aBuilder.SetInheritedOpacity(1.0f);