Bug 1508843 - Factor out common processes to send animations to the compositor for WebRender. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 22 Nov 2018 03:57:21 +0000
changeset 504090 e117fa83228d64be9b7ba16ef80196f332a90828
parent 504089 56460b8902bc75a17685c28423d5fcff7ee9c681
child 504091 9f240dd3f954faf06753b6b6d24ce1a4f684d6ca
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1508843
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1508843 - Factor out common processes to send animations to the compositor for WebRender. r=birtles Depends on D12483 Differential Revision: https://phabricator.services.mozilla.com/D12484
layout/painting/nsDisplayList.cpp
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -726,16 +726,52 @@ AddAnimationsForProperty(nsIFrame* aFram
     }
 
     AddAnimationForProperty(
       aFrame, *property, anim, aAnimationInfo, data, aSendFlag);
     keyframeEffect->SetIsRunningOnCompositor(aProperty, true);
   }
 }
 
+static uint64_t
+AddAnimationsForWebRender(
+  nsDisplayItem* aItem,
+  nsCSSPropertyID aProperty,
+  mozilla::layers::WebRenderLayerManager* aManager,
+  nsDisplayListBuilder* aDisplayListBuilder)
+{
+  RefPtr<WebRenderAnimationData> animationData =
+    aManager->CommandBuilder()
+      .CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(aItem);
+  AnimationInfo& animationInfo = animationData->GetAnimationInfo();
+  AddAnimationsForProperty(aItem->Frame(),
+                           aDisplayListBuilder,
+                           aItem,
+                           aProperty,
+                           animationInfo,
+                           Send::Immediate,
+                           layers::LayersBackend::LAYERS_WR);
+  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
+
+  // Note that animationsId can be 0 (uninitialized in AnimationInfo) if there
+  // are no active animations.
+  uint64_t animationsId = animationInfo.GetCompositorAnimationsId();
+  if (!animationInfo.GetAnimations().IsEmpty()) {
+    OpAddCompositorAnimations anim(
+      CompositorAnimations(animationInfo.GetAnimations(), animationsId));
+    aManager->WrBridge()->AddWebRenderParentCommand(anim);
+    aManager->AddActiveCompositorAnimationId(animationsId);
+  } else if (animationsId) {
+    aManager->AddCompositorAnimationsIdForDiscard(animationsId);
+    animationsId = 0;
+  }
+
+  return animationsId;
+}
+
 static bool
 GenerateAndPushTextMask(nsIFrame* aFrame,
                         gfxContext* aContext,
                         const nsRect& aFillRect,
                         nsDisplayListBuilder* aBuilder)
 {
   if (aBuilder->IsForGenerateGlyphMask() ||
       aBuilder->IsForPaintingSelectionBG()) {
@@ -6739,46 +6775,24 @@ nsDisplayOpacity::CreateWebRenderCommand
   mozilla::wr::DisplayListBuilder& aBuilder,
   mozilla::wr::IpcResourceUpdateQueue& aResources,
   const StackingContextHelper& aSc,
   mozilla::layers::WebRenderLayerManager* aManager,
   nsDisplayListBuilder* aDisplayListBuilder)
 {
   float* opacityForSC = &mOpacity;
 
-  RefPtr<WebRenderAnimationData> animationData =
-    aManager->CommandBuilder()
-      .CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(this);
-  AnimationInfo& animationInfo = animationData->GetAnimationInfo();
-  AddAnimationsForProperty(Frame(),
-                           aDisplayListBuilder,
-                           this,
-                           eCSSProperty_opacity,
-                           animationInfo,
-                           Send::Immediate,
-                           layers::LayersBackend::LAYERS_WR);
-  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
-
-  // Note that animationsId can be 0 (uninitialized in AnimationInfo) if there
-  // are no active animations.
-  uint64_t animationsId = animationInfo.GetCompositorAnimationsId();
-  wr::WrAnimationProperty prop;
-
-  if (!animationInfo.GetAnimations().IsEmpty()) {
-    prop.id = animationsId;
-    prop.effect_type = wr::WrAnimationType::Opacity;
-
-    OpAddCompositorAnimations anim(
-      CompositorAnimations(animationInfo.GetAnimations(), animationsId));
-    aManager->WrBridge()->AddWebRenderParentCommand(anim);
-    aManager->AddActiveCompositorAnimationId(animationsId);
-  } else if (animationsId) {
-    aManager->AddCompositorAnimationsIdForDiscard(animationsId);
-    animationsId = 0;
-  }
+  uint64_t animationsId = AddAnimationsForWebRender(this,
+                                                    eCSSProperty_opacity,
+                                                    aManager,
+                                                    aDisplayListBuilder);
+  wr::WrAnimationProperty prop {
+    wr::WrAnimationType::Opacity,
+    animationsId,
+  };
 
   nsTArray<mozilla::wr::WrFilterOp> filters;
   StackingContextHelper sc(aSc,
                            GetActiveScrolledRoot(),
                            aBuilder,
                            filters,
                            LayoutDeviceRect(),
                            nullptr,
@@ -8824,46 +8838,24 @@ nsDisplayTransform::CreateWebRenderComma
   gfx::Matrix4x4* transformForSC = &newTransformMatrix;
   if (newTransformMatrix.IsIdentity()) {
     // If the transform is an identity transform, strip it out so that WR
     // doesn't turn this stacking context into a reference frame, as it
     // affects positioning. Bug 1345577 tracks a better fix.
     transformForSC = nullptr;
   }
 
-  RefPtr<WebRenderAnimationData> animationData =
-    aManager->CommandBuilder()
-      .CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(this);
-
-  AnimationInfo& animationInfo = animationData->GetAnimationInfo();
-  AddAnimationsForProperty(Frame(),
-                           aDisplayListBuilder,
-                           this,
-                           eCSSProperty_transform,
-                           animationInfo,
-                           Send::Immediate,
-                           layers::LayersBackend::LAYERS_WR);
-  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
-
-  // Note that animationsId can be 0 (uninitialized in AnimationInfo) if there
-  // are no active animations.
-  uint64_t animationsId = animationInfo.GetCompositorAnimationsId();
-  wr::WrAnimationProperty prop;
-  if (!animationInfo.GetAnimations().IsEmpty()) {
-    prop.id = animationsId;
-    prop.effect_type = wr::WrAnimationType::Transform;
-
-    OpAddCompositorAnimations anim(
-      CompositorAnimations(animationInfo.GetAnimations(), animationsId));
-    aManager->WrBridge()->AddWebRenderParentCommand(anim);
-    aManager->AddActiveCompositorAnimationId(animationsId);
-  } else if (animationsId) {
-    aManager->AddCompositorAnimationsIdForDiscard(animationsId);
-    animationsId = 0;
-  }
+  uint64_t animationsId = AddAnimationsForWebRender(this,
+                                                    eCSSProperty_transform,
+                                                    aManager,
+                                                    aDisplayListBuilder);
+  wr::WrAnimationProperty prop {
+    wr::WrAnimationType::Transform,
+    animationsId,
+  };
 
   nsTArray<mozilla::wr::WrFilterOp> filters;
   Maybe<nsDisplayTransform*> deferredTransformItem;
   if (!mFrame->HasPerspective()) {
     // If it has perspective, we create a new scroll data via the
     // UpdateScrollData call because that scenario is more complex. Otherwise
     // we can just stash the transform on the StackingContextHelper and
     // apply it to any scroll data that are created inside this