Bug 1419851 - Part1. Add a static function to get AnimationInfo. r=kats
MozReview-Commit-ID: ID5vQx4XJjC
--- 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