Bug 1378602 - Part3. Add OMTA support for nsDisplayTransform and nsDisplayOpacity. r=kats
authorEthan Lin <ethlin@mozilla.com>
Fri, 21 Jul 2017 14:21:47 +0800
changeset 369932 d38d77c05d52f905fc4b2755834cf2cf270e909f
parent 369931 13c0405ebb3327eab9b9c0b4b11f721e245c460e
child 369933 ba3c77118fd3593e21e0d822e4b3a9b87c901869
push id92798
push userethlin@mozilla.com
push dateFri, 21 Jul 2017 06:28:23 +0000
treeherdermozilla-inbound@ba3c77118fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1378602
milestone56.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 1378602 - Part3. Add OMTA support for nsDisplayTransform and nsDisplayOpacity. r=kats MozReview-Commit-ID: CP4WEZgy83a
gfx/layers/wr/WebRenderUserData.cpp
gfx/layers/wr/WebRenderUserData.h
layout/painting/nsDisplayList.cpp
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -164,10 +164,16 @@ WebRenderFallbackData::GetGeometry()
 }
 
 void
 WebRenderFallbackData::SetGeometry(nsAutoPtr<nsDisplayItemGeometry> aGeometry)
 {
   mGeometry = aGeometry;
 }
 
+WebRenderAnimationData::WebRenderAnimationData(WebRenderLayerManager* aWRManager)
+  : WebRenderUserData(aWRManager),
+    mAnimationInfo(aWRManager)
+{
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderUserData.h
+++ b/gfx/layers/wr/WebRenderUserData.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_WEBRENDERUSERDATA_H
 #define GFX_WEBRENDERUSERDATA_H
 
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/webrender/WebRenderAPI.h"
+#include "mozilla/layers/AnimationInfo.h"
 
 class nsDisplayItemGeometry;
 
 namespace mozilla {
 namespace layers {
 class ImageClient;
 class ImageContainer;
 class WebRenderBridgeChild;
@@ -28,16 +29,17 @@ public:
     : mWRManager(aWRManager)
   { }
 
   virtual WebRenderImageData* AsImageData() { return nullptr; }
 
   enum class UserDataType {
     eImage,
     eFallback,
+    eAnimation,
   };
 
   virtual UserDataType GetType() = 0;
 
 protected:
   virtual ~WebRenderUserData() {}
 
   WebRenderBridgeChild* WrBridge() const;
@@ -95,12 +97,26 @@ public:
   nsRect GetBounds() { return mBounds; }
   void SetBounds(const nsRect& aRect) { mBounds = aRect; }
 
 protected:
   nsAutoPtr<nsDisplayItemGeometry> mGeometry;
   nsRect mBounds;
 };
 
+class WebRenderAnimationData : public WebRenderUserData
+{
+public:
+  explicit WebRenderAnimationData(WebRenderLayerManager* aWRManager);
+  virtual ~WebRenderAnimationData() {}
+
+  virtual UserDataType GetType() override { return UserDataType::eAnimation; }
+  static UserDataType Type() { return UserDataType::eAnimation; }
+  AnimationInfo& GetAnimationInfo() { return mAnimationInfo; }
+
+protected:
+  AnimationInfo mAnimationInfo;
+};
+
 } // namespace layers
 } // namespace mozilla
 
 #endif /* GFX_WEBRENDERUSERDATA_H */
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -6059,26 +6059,45 @@ nsDisplayOpacity::CreateWebRenderCommand
 {
   nsRect itemBounds = mList.GetClippedBoundsWithRespectToASR(aDisplayListBuilder, mActiveScrolledRoot);
   nsRect childrenVisible = GetVisibleRectForChildren();
   nsRect visibleRect = itemBounds.Intersect(childrenVisible);
   float appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   LayerRect bounds = ViewAs<LayerPixel>(LayoutDeviceRect::FromAppUnits(visibleRect, appUnitsPerDevPixel),
                                         PixelCastJustification::WebRenderHasUnitResolution);
   LayerPoint origin = bounds.TopLeft();
-
-  // TODO: generate animationsId for OMTA.
+  float* opacityForSC = &mOpacity;
+
+  RefPtr<WebRenderAnimationData> animationData = aManager->CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(this);
+  AnimationInfo& animationInfo = animationData->GetAnimationInfo();
+  AddAnimationsForProperty(Frame(), aDisplayListBuilder,
+                           this, eCSSProperty_opacity,
+                           animationInfo, false);
+  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
   uint64_t animationsId = 0;
-  nsTArray<WrFilterOp> filters;
+
+  if (gfxPrefs::WebRenderOMTAEnabled() &&
+      !animationInfo.GetAnimations().IsEmpty()) {
+    animationsId = animationInfo.GetCompositorAnimationsId();
+    opacityForSC = nullptr;
+    OptionalOpacity opacityForCompositor = mOpacity;
+
+    OpAddCompositorAnimations
+      anim(CompositorAnimations(animationInfo.GetAnimations(), animationsId),
+           void_t(), opacityForCompositor);
+    aManager->WrBridge()->AddWebRenderParentCommand(anim);
+  }
+
+  nsTArray<mozilla::wr::WrFilterOp> filters;
   StackingContextHelper sc(aSc,
                            aBuilder,
                            bounds,
                            origin,
                            animationsId,
-                           &mOpacity,
+                           opacityForSC,
                            nullptr,
                            filters);
 
   aManager->CreateWebRenderCommandsFromDisplayList(&mList,
                                                    aDisplayListBuilder,
                                                    sc,
                                                    aBuilder);
   return true;
@@ -7609,19 +7628,45 @@ nsDisplayTransform::CreateWebRenderComma
   boundTransform._41 = 0.0f;
   boundTransform._42 = 0.0f;
   boundTransform._43 = 0.0f;
   if (!boundTransform.IsIdentity()) {
     // WR will only apply the 'translate' of the transform, so we need to do the scale/rotation manually.
     bounds.MoveTo(boundTransform.TransformPoint(bounds.TopLeft()));
   }
 
-  // TODO: generate animationsId for OMTA.
+  RefPtr<WebRenderAnimationData> animationData = aManager->CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(this);
+
+  AnimationInfo& animationInfo = animationData->GetAnimationInfo();
+  AddAnimationsForProperty(Frame(), aDisplayListBuilder,
+                           this, eCSSProperty_transform,
+                           animationInfo, false);
+  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
   uint64_t animationsId = 0;
-  nsTArray<wr::WrFilterOp> filters;
+
+  if (gfxPrefs::WebRenderOMTAEnabled() &&
+      !animationInfo.GetAnimations().IsEmpty()) {
+    animationsId = animationInfo.GetCompositorAnimationsId();
+
+    // Update transfrom as nullptr in stacking context if there exists
+    // transform animation, the transform value will be resolved
+    // after animation sampling on the compositor
+    transformForSC = nullptr;
+
+    // Pass default transform to compositor in case gecko fails to
+    // get animated value after animation sampling.
+    OptionalTransform transformForCompositor = newTransformMatrix;
+
+    OpAddCompositorAnimations
+      anim(CompositorAnimations(animationInfo.GetAnimations(), animationsId),
+           transformForCompositor, void_t());
+    aManager->WrBridge()->AddWebRenderParentCommand(anim);
+  }
+
+  nsTArray<mozilla::wr::WrFilterOp> filters;
   StackingContextHelper sc(aSc,
                            aBuilder,
                            bounds,
                            origin,
                            animationsId,
                            nullptr,
                            transformForSC,
                            filters);