Bug 1375497 - Extract helper methods to read animation values. r?pchang
MozReview-Commit-ID: EusfcwPVGkL
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -7,16 +7,17 @@
#include "AnimationHelper.h"
#include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction
#include "mozilla/dom/AnimationEffectReadOnlyBinding.h" // for dom::FillMode
#include "mozilla/dom/KeyframeEffectBinding.h" // for dom::IterationComposite
#include "mozilla/dom/KeyframeEffectReadOnly.h" // for dom::KeyFrameEffectReadOnly
#include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder
#include "mozilla/layers/LayerAnimationUtils.h" // for TimingFunctionToComputedTimingFunction
#include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
+#include "nsDeviceContext.h" // for AppUnitsPerCSSPixel
#include "nsDisplayList.h" // for nsDisplayTransform, etc
namespace mozilla {
namespace layers {
struct StyleAnimationValueCompositePair {
StyleAnimationValue mValue;
dom::CompositeOperation mComposite;
@@ -42,16 +43,56 @@ CompositorAnimationStorage::ClearById(co
AnimatedValue*
CompositorAnimationStorage::GetAnimatedValue(const uint64_t& aId) const
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
return mAnimatedValues.Get(aId);
}
+Maybe<float>
+CompositorAnimationStorage::GetAnimationOpacity(const uint64_t& aId) const
+{
+ auto value = GetAnimatedValue(aId);
+ if (!value || value->mType != AnimatedValue::OPACITY) {
+ return Nothing();
+ }
+
+ return Some(value->mOpacity);
+}
+
+Maybe<gfx::Matrix4x4>
+CompositorAnimationStorage::GetAnimationTransform(const uint64_t& aId) const
+{
+ auto value = GetAnimatedValue(aId);
+ if (!value || value->mType != AnimatedValue::TRANSFORM) {
+ return Nothing();
+ }
+
+ gfx::Matrix4x4 transform = value->mTransform.mFrameTransform;
+ const TransformData& data = value->mTransform.mData;
+ float scale = data.appUnitsPerDevPixel();
+ gfx::Point3D transformOrigin = data.transformOrigin();
+
+ // Undo the rebasing applied by
+ // nsDisplayTransform::GetResultingTransformMatrixInternal
+ transform.ChangeBasis(-transformOrigin);
+
+ // Convert to CSS pixels (this undoes the operations performed by
+ // nsStyleTransformMatrix::ProcessTranslatePart which is called from
+ // nsDisplayTransform::GetResultingTransformMatrix)
+ double devPerCss =
+ double(scale) / double(nsDeviceContext::AppUnitsPerCSSPixel());
+ transform._41 *= devPerCss;
+ transform._42 *= devPerCss;
+ transform._43 *= devPerCss;
+
+ return Some(transform);
+}
+
void
CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
gfx::Matrix4x4&& aTransformInDevSpace,
gfx::Matrix4x4&& aFrameTransform,
const TransformData& aData)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
AnimatedValue* value = new AnimatedValue(Move(aTransformInDevSpace),
--- a/gfx/layers/AnimationHelper.h
+++ b/gfx/layers/AnimationHelper.h
@@ -104,16 +104,30 @@ public:
void SetAnimatedValue(uint64_t aId, const float& aOpacity);
/**
* Return the animated value if a given id can map to its animated value
*/
AnimatedValue* GetAnimatedValue(const uint64_t& aId) const;
/**
+ * Like GetAnimatedValue(), but ensures the value is an opacity and returns
+ * the float value if possible, or Nothing() otherwise.
+ */
+ Maybe<float> GetAnimationOpacity(const uint64_t& aId) const;
+
+ /**
+ * Like GetAnimatedValue(), but ensures the value is a transform and returns
+ * the transform matrix if possible, or Nothing() otherwise. It also does
+ * some post-processing on the transform matrix as well. See the comments
+ * inside the function for details.
+ */
+ Maybe<gfx::Matrix4x4> GetAnimationTransform(const uint64_t& aId) const;
+
+ /**
* Return the iterator of animated value table
*/
AnimatedValueTable::Iterator ConstAnimatedValueTableIter() const
{
return mAnimatedValues.ConstIter();
}
uint32_t AnimatedValueCount() const
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -27,17 +27,16 @@
#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
#include "mozilla/layers/PaintedLayerComposite.h"
#include "mozilla/mozalloc.h" // for operator delete, etc
#include "mozilla/SizePrintfMacros.h"
#include "mozilla/Unused.h"
#include "nsCoord.h" // for NSAppUnitsToFloatPixels
#include "nsDebug.h" // for NS_RUNTIMEABORT
-#include "nsDeviceContext.h" // for AppUnitsPerCSSPixel
#include "nsISupportsImpl.h" // for Layer::Release, etc
#include "nsLayoutUtils.h" // for nsLayoutUtils
#include "nsMathUtils.h" // for NS_round
#include "nsPoint.h" // for nsPoint
#include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc
#include "TreeTraversal.h" // for ForEachNode
#include "GeckoProfiler.h"
#include "mozilla/layers/TextureHost.h"
@@ -716,24 +715,21 @@ LayerTransactionParent::RecvGetAnimation
CompositorAnimationStorage* storage =
mCompositorBridge->GetAnimationStorage(GetId());
if (!storage) {
return IPC_FAIL_NO_REASON(this);
}
- auto value = storage->GetAnimatedValue(aCompositorAnimationsId);
-
- if (!value || value->mType != AnimatedValue::OPACITY) {
- return IPC_OK();
+ Maybe<float> opacity = storage->GetAnimationOpacity(aCompositorAnimationsId);
+ if (opacity) {
+ *aOpacity = *opacity;
+ *aHasAnimationOpacity = true;
}
-
- *aOpacity = value->mOpacity;
- *aHasAnimationOpacity = true;
return IPC_OK();
}
mozilla::ipc::IPCResult
LayerTransactionParent::RecvGetAnimationTransform(const uint64_t& aCompositorAnimationsId,
MaybeTransform* aTransform)
{
if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
@@ -748,42 +744,22 @@ LayerTransactionParent::RecvGetAnimation
CompositorAnimationStorage* storage =
mCompositorBridge->GetAnimationStorage(GetId());
if (!storage) {
return IPC_FAIL_NO_REASON(this);
}
- auto value = storage->GetAnimatedValue(aCompositorAnimationsId);
-
- if (!value || value->mType != AnimatedValue::TRANSFORM) {
+ Maybe<Matrix4x4> transform = storage->GetAnimationTransform(aCompositorAnimationsId);
+ if (transform) {
+ *aTransform = *transform;
+ } else {
*aTransform = mozilla::void_t();
- return IPC_OK();
}
-
- Matrix4x4 transform = value->mTransform.mFrameTransform;
- const TransformData& data = value->mTransform.mData;
- float scale = data.appUnitsPerDevPixel();
- Point3D transformOrigin = data.transformOrigin();
-
- // Undo the rebasing applied by
- // nsDisplayTransform::GetResultingTransformMatrixInternal
- transform.ChangeBasis(-transformOrigin);
-
- // Convert to CSS pixels (this undoes the operations performed by
- // nsStyleTransformMatrix::ProcessTranslatePart which is called from
- // nsDisplayTransform::GetResultingTransformMatrix)
- double devPerCss =
- double(scale) / double(nsDeviceContext::AppUnitsPerCSSPixel());
- transform._41 *= devPerCss;
- transform._42 *= devPerCss;
- transform._43 *= devPerCss;
-
- *aTransform = transform;
return IPC_OK();
}
static AsyncPanZoomController*
GetAPZCForViewID(Layer* aLayer, FrameMetrics::ViewID aScrollID)
{
AsyncPanZoomController* resultApzc = nullptr;
ForEachNode<ForwardIterator>(