Bug 1419851 - Part1. Add a static function to get AnimationInfo. r=kats draft
authorEthan Lin <ethlin@mozilla.com>
Sat, 25 Nov 2017 00:56:33 +0800
changeset 707307 c771cbb1f3fbb814f5a238b259b8fdec6ce522c3
parent 707249 f2cf6d1473808039be5ecd8727cc3791d5d7d2d4
child 707308 c039a3864bb6a652cd459c9cdeeb8cfc9a999e3c
push id92085
push userbmo:ethlin@mozilla.com
push dateTue, 05 Dec 2017 05:11:05 +0000
reviewerskats
bugs1419851
milestone59.0a1
Bug 1419851 - Part1. Add a static function to get AnimationInfo. r=kats MozReview-Commit-ID: ID5vQx4XJjC
gfx/layers/AnimationInfo.cpp
gfx/layers/AnimationInfo.h
--- a/gfx/layers/AnimationInfo.cpp
+++ b/gfx/layers/AnimationInfo.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "AnimationInfo.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/AnimationHelper.h"
+#include "nsContentUtils.h"
 
 namespace mozilla {
 namespace layers {
 
 AnimationInfo::AnimationInfo(LayerManager* aManager) :
   mManager(aManager),
   mCompositorAnimationsId(0),
   mAnimationGeneration(0),
@@ -158,10 +159,38 @@ AnimationInfo::HasTransformAnimation() c
   for (uint32_t i = 0; i < mAnimations.Length(); i++) {
     if (mAnimations[i].property() == eCSSProperty_transform) {
       return true;
     }
   }
   return false;
 }
 
+/* static */ AnimationInfo*
+AnimationInfo::GetFromFrame(nsIFrame* aFrame,
+                            DisplayItemType aDisplayItemKey,
+                            nsIPresShell* aPresShell)
+{
+  AnimationInfo* info = nullptr;
+  layers::Layer* layer =
+    FrameLayerBuilder::GetDedicatedLayer(aFrame, aDisplayItemKey);
+  if (layer) {
+    info = &layer->GetAnimationInfo();
+  } else {
+    RefPtr<LayerManager> widgetLayerManager;
+    if (nsIWidget* widget = nsContentUtils::GetWidget(aPresShell, nullptr)) {
+      widgetLayerManager = widget->GetLayerManager();
+    }
+    if (WebRenderLayerManager *wrlm = widgetLayerManager ?
+          widgetLayerManager->AsWebRenderLayerManager() : nullptr) {
+      RefPtr<WebRenderAnimationData> animationData = wrlm->CommandBuilder()
+          .GetWebRenderUserData<WebRenderAnimationData>(aFrame, (uint32_t)aDisplayItemKey);
+      if (animationData) {
+        info = &animationData->GetAnimationInfo();
+      }
+    }
+  }
+
+  return info;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/AnimationInfo.h
+++ b/gfx/layers/AnimationInfo.h
@@ -3,16 +3,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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_ANIMATIONINFO_H
 #define GFX_ANIMATIONINFO_H
 
 #include "mozilla/StyleAnimationValue.h"
+#include "nsDisplayItemTypes.h"
+
+class nsIPresShell;
 
 namespace mozilla {
 namespace layers {
 
 class Animation;
 class CompositorAnimations;
 class Layer;
 class LayerManager;
@@ -53,16 +56,21 @@ public:
   uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
   AnimationValue GetBaseAnimationStyle() const { return mBaseAnimationStyle; }
   InfallibleTArray<AnimData>& GetAnimationData() { return mAnimationData; }
   AnimationArray& GetAnimations() { return mAnimations; }
   bool ApplyPendingUpdatesForThisTransaction();
   bool HasOpacityAnimation() const;
   bool HasTransformAnimation() const;
 
+  // The returned pointer might be turned into garbage if the frame is destroyed.
+  static AnimationInfo* GetFromFrame(nsIFrame* aFrame,
+                                     DisplayItemType aDisplayItemKey,
+                                     nsIPresShell* aPresShell);
+
 protected:
   LayerManager* mManager;
   AnimationArray mAnimations;
   uint64_t mCompositorAnimationsId;
   nsAutoPtr<AnimationArray> mPendingAnimations;
   InfallibleTArray<AnimData> mAnimationData;
   // If this layer is used for OMTA, then this counter is used to ensure we
   // stay in sync with the animation manager