Bug 1337889 - Add CompositorAnimationsId for layer animations, r?hiro draft
authorpeter chang <pchang@mozilla.com>
Wed, 08 Feb 2017 14:31:45 -0500
changeset 485181 66f40ebeb0aed056112c213cf6a5b3cb0149f6cd
parent 480671 34521aa2e278eb7e1873cdda07b88526bcd42ef3
child 485182 8fbd705964a02d42ff4f1d38d963d01ec063ce51
push id45669
push userbmo:howareyou322@gmail.com
push dateThu, 16 Feb 2017 09:54:30 +0000
reviewershiro
bugs1337889
milestone54.0a1
Bug 1337889 - Add CompositorAnimationsId for layer animations, r?hiro MozReview-Commit-ID: 4r9VhF4Vp2l
gfx/layers/AnimationHelper.cpp
gfx/layers/AnimationHelper.h
gfx/layers/Layers.cpp
gfx/layers/Layers.h
gfx/layers/ipc/LayerTransactionParent.cpp
gfx/layers/ipc/LayersMessages.ipdlh
gfx/layers/ipc/ShadowLayers.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -409,10 +409,22 @@ AnimationHelper::SetAnimations(Animation
     InfallibleTArray<StyleAnimationValue>& endValues = data->mEndValues;
     for (const AnimationSegment& segment : segments) {
       startValues.AppendElement(ToStyleAnimationValue(segment.startState()));
       endValues.AppendElement(ToStyleAnimationValue(segment.endState()));
     }
   }
 }
 
+uint64_t
+AnimationHelper::GetNextCompositorAnimationsId()
+{
+  static uint32_t sNextId = 0;
+  ++sNextId;
+
+  uint32_t procId = static_cast<uint32_t>(base::GetCurrentProcId());
+  uint64_t nextId = procId;
+  nextId = nextId << 32 | sNextId;
+  return nextId;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/AnimationHelper.h
+++ b/gfx/layers/AnimationHelper.h
@@ -34,14 +34,15 @@ public:
                              InfallibleTArray<AnimData>& aAnimationData,
                              StyleAnimationValue& aAnimationValue,
                              bool& aHasInEffectAnimations);
 
   static void
   SetAnimations(AnimationArray& aAnimations,
                 InfallibleTArray<AnimData>& aAnimData,
                 StyleAnimationValue& aBaseAnimationStyle);
+  static uint64_t GetNextCompositorAnimationsId();
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // mozilla_layers_AnimationHelper_h
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -185,32 +185,39 @@ LayerManager::RemoveUserData(void* aKey)
 // Layer
 
 Layer::Layer(LayerManager* aManager, void* aImplData) :
   mManager(aManager),
   mParent(nullptr),
   mNextSibling(nullptr),
   mPrevSibling(nullptr),
   mImplData(aImplData),
+  mCompositorAnimationsId(0),
   mUseTileSourceRect(false),
 #ifdef DEBUG
   mDebugColorIndex(0),
 #endif
   mAnimationGeneration(0)
 {
 }
 
 Layer::~Layer()
 {
 }
 
 Animation*
 Layer::AddAnimation()
 {
-  MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) AddAnimation", this));
+  // Here generates a new id when the first animation is added and
+  // this id is used to represent the animations in this layer.
+  if (!mCompositorAnimationsId) {
+    mCompositorAnimationsId = AnimationHelper::GetNextCompositorAnimationsId();
+  }
+
+  MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) AddAnimation with id %llu", this, mCompositorAnimationsId));
 
   MOZ_ASSERT(!mPendingAnimations, "should have called ClearAnimations first");
 
   Animation* anim = mAnimations.AppendElement();
 
   Mutated();
   return anim;
 }
@@ -221,16 +228,17 @@ Layer::ClearAnimations()
   mPendingAnimations = nullptr;
 
   if (mAnimations.IsEmpty() && mAnimationData.IsEmpty()) {
     return;
   }
 
   MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ClearAnimations", this));
   mAnimations.Clear();
+  mCompositorAnimationsId = 0;
   mAnimationData.Clear();
   Mutated();
 }
 
 Animation*
 Layer::AddAnimationForNextTransaction()
 {
   MOZ_ASSERT(mPendingAnimations,
@@ -248,21 +256,22 @@ Layer::ClearAnimationsForNextTransaction
   if (!mPendingAnimations) {
     mPendingAnimations = new AnimationArray;
   }
 
   mPendingAnimations->Clear();
 }
 
 void
-Layer::SetAnimations(const AnimationArray& aAnimations)
+Layer::SetCompositorAnimations(const CompositorAnimations& aCompositorAnimations)
 {
-  MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) SetAnimations", this));
+  MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) SetCompositorAnimations with id %llu", this, mCompositorAnimationsId));
 
-  mAnimations = aAnimations;
+  mAnimations = aCompositorAnimations.animations();
+  mCompositorAnimationsId = aCompositorAnimations.id();
   mAnimationData.Clear();
   AnimationHelper::SetAnimations(mAnimations,
                                  mAnimationData,
                                  mBaseAnimationStyle);
 
   Mutated();
 }
 
@@ -1904,17 +1913,19 @@ Layer::PrintInfo(std::stringstream& aStr
   }
   for (uint32_t i = 0; i < mScrollMetadata.Length(); i++) {
     if (!mScrollMetadata[i].IsDefault()) {
       aStream << nsPrintfCString(" [metrics%d=", i).get();
       AppendToString(aStream, mScrollMetadata[i], "", "]");
     }
   }
   if (!mAnimations.IsEmpty()) {
-    aStream << nsPrintfCString(" [%d animations]", (int) mAnimations.Length()).get();
+    aStream << nsPrintfCString(" [%d animations with id=%llu ]",
+                               (int) mAnimations.Length(),
+                               mCompositorAnimationsId).get();
   }
 }
 
 // The static helper function sets the transform matrix into the packet
 static void
 DumpTransform(layerscope::LayersPacket::Layer::Matrix* aLayerMatrix, const Matrix4x4& aMatrix)
 {
   aLayerMatrix->set_is2d(aMatrix.Is2D());
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -79,16 +79,17 @@ class AsyncPanZoomController;
 class BasicLayerManager;
 class ClientLayerManager;
 class Layer;
 class LayerMetricsWrapper;
 class PaintedLayer;
 class ContainerLayer;
 class ImageLayer;
 class ColorLayer;
+class CompositorAnimations;
 class CompositorBridgeChild;
 class TextLayer;
 class CanvasLayer;
 class BorderLayer;
 class ReadbackLayer;
 class ReadbackProcessor;
 class RefLayer;
 class HostLayer;
@@ -1206,17 +1207,17 @@ public:
   // Call AddAnimation to add a new animation to this layer from layout code.
   // Caller must fill in all the properties of the returned animation.
   // A later animation overrides an earlier one.
   Animation* AddAnimation();
   // ClearAnimations clears animations on this layer.
   void ClearAnimations();
   // This is only called when the layer tree is updated. Do not call this from
   // layout code.  To add an animation to this layer, use AddAnimation.
-  void SetAnimations(const AnimationArray& aAnimations);
+  void SetCompositorAnimations(const CompositorAnimations& aCompositorAnimations);
   // Go through all animations in this layer and its children and, for
   // any animations with a null start time, update their start time such
   // that at |aReadyTime| the animation's current time corresponds to its
   // 'initial current time' value.
   void StartPendingAnimations(const TimeStamp& aReadyTime);
 
   // These are a parallel to AddAnimation and clearAnimations, except
   // they add pending animations that apply only when the next
@@ -1396,16 +1397,17 @@ public:
    *  traversal.
    */
   bool GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
                                            nsIntPoint* aLayerOffset);
 
   // Note that all lengths in animation data are either in CSS pixels or app
   // units and must be converted to device pixels by the compositor.
   AnimationArray& GetAnimations() { return mAnimations; }
+  uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
   InfallibleTArray<AnimData>& GetAnimationData() { return mAnimationData; }
 
   uint64_t GetAnimationGeneration() { return mAnimationGeneration; }
   void SetAnimationGeneration(uint64_t aCount) { mAnimationGeneration = aCount; }
 
   bool HasTransformAnimation() const;
 
   StyleAnimationValue GetBaseAnimationStyle() const
@@ -1898,16 +1900,17 @@ protected:
   nsTArray<ScrollMetadata> mScrollMetadata;
   EventRegions mEventRegions;
   // A mutation of |mTransform| that we've queued to be applied at the
   // end of the next transaction (if nothing else overrides it in the
   // meantime).
   nsAutoPtr<gfx::Matrix4x4> mPendingTransform;
   gfx::Matrix4x4 mEffectiveTransform;
   AnimationArray mAnimations;
+  uint64_t mCompositorAnimationsId;
   // See mPendingTransform above.
   nsAutoPtr<AnimationArray> mPendingAnimations;
   InfallibleTArray<AnimData> mAnimationData;
   Maybe<ParentLayerIntRect> mClipRect;
   gfx::IntRect mTileSourceRect;
   gfx::TiledIntRegion mInvalidRegion;
   nsTArray<RefPtr<AsyncPanZoomController> > mApzcs;
   bool mUseTileSourceRect;
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -530,17 +530,17 @@ LayerTransactionParent::SetLayerAttribut
   layer->SetVisibleRegion(common.visibleRegion());
   layer->SetEventRegions(common.eventRegions());
   layer->SetClipRect(common.useClipRect() ? Some(common.clipRect()) : Nothing());
   if (LayerHandle maskLayer = common.maskLayer()) {
     layer->SetMaskLayer(AsLayer(maskLayer));
   } else {
     layer->SetMaskLayer(nullptr);
   }
-  layer->SetAnimations(common.animations());
+  layer->SetCompositorAnimations(common.compositorAnimations());
   layer->SetScrollMetadata(common.scrollMetadata());
   layer->SetDisplayListLog(common.displayListLog().get());
 
   // The updated invalid region is added to the existing one, since we can
   // update multiple times before the next composite.
   layer->AddInvalidRegion(common.invalidRegion());
 
   nsTArray<RefPtr<Layer>> maskLayers;
--- a/gfx/layers/ipc/LayersMessages.ipdlh
+++ b/gfx/layers/ipc/LayersMessages.ipdlh
@@ -226,26 +226,33 @@ struct Animation {
   bool isNotPlaying;
   // The base style that animations should composite with. This is only set for
   // animations with a composite mode of additive or accumulate, and only for
   // the first animation in the set (i.e. the animation that is lowest in the
   // stack). In all other cases the value is null_t.
   Animatable baseStyle;
 };
 
+struct CompositorAnimations {
+  Animation[] animations;
+  // This id is used to map the layer animations between content
+  // and compositor side
+  uint64_t id;
+};
+
 // Change a layer's attributes
 struct CommonLayerAttributes {
   LayerIntRegion visibleRegion;
   EventRegions eventRegions;
   bool useClipRect;
   ParentLayerIntRect clipRect;
   LayerHandle maskLayer;
   LayerHandle[] ancestorMaskLayers;
   // Animated colors will only honored for ColorLayers.
-  Animation[] animations;
+  CompositorAnimations compositorAnimations;
   nsIntRegion invalidRegion;
   ScrollMetadata[] scrollMetadata;
   nsCString displayListLog;
 };
 
 struct PaintedLayerAttributes {
   nsIntRegion validRegion;
 };
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -659,17 +659,18 @@ ShadowLayerForwarder::EndTransaction(con
     common.useClipRect() = !!mutant->GetClipRect();
     common.clipRect() = (common.useClipRect() ?
                          *mutant->GetClipRect() : ParentLayerIntRect());
     if (Layer* maskLayer = mutant->GetMaskLayer()) {
       common.maskLayer() = Shadow(maskLayer->AsShadowableLayer());
     } else {
       common.maskLayer() = LayerHandle();
     }
-    common.animations() = mutant->GetAnimations();
+    common.compositorAnimations().id() = mutant->GetCompositorAnimationsId();
+    common.compositorAnimations().animations() = mutant->GetAnimations();
     common.invalidRegion() = mutant->GetInvalidRegion().GetRegion();
     common.scrollMetadata() = mutant->GetAllScrollMetadata();
     for (size_t i = 0; i < mutant->GetAncestorMaskLayerCount(); i++) {
       auto layer = Shadow(mutant->GetAncestorMaskLayerAt(i)->AsShadowableLayer());
       common.ancestorMaskLayers().AppendElement(layer);
     }
     nsCString log;
     mutant->GetDisplayListLog(log);