Commit 56ed4f6c authored by Matt Woodrow's avatar Matt Woodrow
Browse files

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
parent a8494d48
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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 &&
+0 −24
Original line number Diff line number Diff line
@@ -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);