Bug 1479234 - Introduce a generic function to get an animation value on the compositor. r=boris,froydnj
On the compositor we store animation values in a hash table and the hash is the compositor animation id which is a unique id for each property respectively. So we can get the corresponding animation value for the given property. In this patch there are lots of duplicated code, but they will be removed in the next patch. MozReview-Commit-ID: 7EboVcculcg
This commit is contained in:
@@ -3679,8 +3679,7 @@ nsDOMWindowUtils::GetOMTAStyle(Element* aElement,
|
||||
}
|
||||
|
||||
if (aProperty.EqualsLiteral("opacity")) {
|
||||
float value = 0;
|
||||
bool hadAnimatedOpacity = false;
|
||||
OMTAValue value;
|
||||
|
||||
Layer* layer =
|
||||
FrameLayerBuilder::GetDedicatedLayer(frame, DisplayItemType::TYPE_OPACITY);
|
||||
@@ -3688,26 +3687,23 @@ nsDOMWindowUtils::GetOMTAStyle(Element* aElement,
|
||||
ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
|
||||
if (forwarder && forwarder->HasShadowManager()) {
|
||||
forwarder->GetShadowManager()->
|
||||
SendGetAnimationOpacity(layer->GetCompositorAnimationsId(),
|
||||
&value,
|
||||
&hadAnimatedOpacity);
|
||||
SendGetAnimationValue(layer->GetCompositorAnimationsId(), &value);
|
||||
}
|
||||
} else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
|
||||
RefPtr<WebRenderAnimationData> animationData =
|
||||
GetWebRenderUserData<WebRenderAnimationData>(frame, (uint32_t)DisplayItemType::TYPE_OPACITY);
|
||||
if (animationData) {
|
||||
wrbc->SendGetAnimationOpacity(
|
||||
wrbc->SendGetAnimationValue(
|
||||
animationData->GetAnimationInfo().GetCompositorAnimationsId(),
|
||||
&value,
|
||||
&hadAnimatedOpacity);
|
||||
&value);
|
||||
}
|
||||
}
|
||||
if (hadAnimatedOpacity) {
|
||||
if (value.type() == OMTAValue::Tfloat) {
|
||||
cssValue = new nsROCSSPrimitiveValue;
|
||||
cssValue->SetNumber(value);
|
||||
cssValue->SetNumber(value.get_float());
|
||||
}
|
||||
} else if (aProperty.EqualsLiteral("transform")) {
|
||||
MaybeTransform transform;
|
||||
OMTAValue value;
|
||||
|
||||
Layer* layer =
|
||||
FrameLayerBuilder::GetDedicatedLayer(frame, DisplayItemType::TYPE_TRANSFORM);
|
||||
@@ -3715,20 +3711,19 @@ nsDOMWindowUtils::GetOMTAStyle(Element* aElement,
|
||||
ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
|
||||
if (forwarder && forwarder->HasShadowManager()) {
|
||||
forwarder->GetShadowManager()->
|
||||
SendGetAnimationTransform(layer->GetCompositorAnimationsId(), &transform);
|
||||
SendGetAnimationValue(layer->GetCompositorAnimationsId(), &value);
|
||||
}
|
||||
} else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
|
||||
RefPtr<WebRenderAnimationData> animationData =
|
||||
GetWebRenderUserData<WebRenderAnimationData>(frame, (uint32_t)DisplayItemType::TYPE_TRANSFORM);
|
||||
if (animationData) {
|
||||
wrbc->SendGetAnimationTransform(
|
||||
wrbc->SendGetAnimationValue(
|
||||
animationData->GetAnimationInfo().GetCompositorAnimationsId(),
|
||||
&transform);
|
||||
&value);
|
||||
}
|
||||
}
|
||||
if (transform.type() == MaybeTransform::TMatrix4x4) {
|
||||
Matrix4x4 matrix = transform.get_Matrix4x4();
|
||||
cssValue = nsComputedDOMStyle::MatrixToCSSValue(matrix);
|
||||
if (value.type() == OMTAValue::TMatrix4x4) {
|
||||
cssValue = nsComputedDOMStyle::MatrixToCSSValue(value.get_Matrix4x4());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,47 @@ CompositorAnimationStorage::GetAnimationTransform(const uint64_t& aId) const
|
||||
return Some(transform);
|
||||
}
|
||||
|
||||
OMTAValue
|
||||
CompositorAnimationStorage::GetOMTAValue(const uint64_t& aId) const
|
||||
{
|
||||
OMTAValue omtaValue = mozilla::null_t();
|
||||
auto animatedValue = GetAnimatedValue(aId);
|
||||
if (!animatedValue) {
|
||||
return omtaValue;
|
||||
}
|
||||
|
||||
switch (animatedValue->mType) {
|
||||
case AnimatedValue::OPACITY:
|
||||
omtaValue = animatedValue->mOpacity;
|
||||
break;
|
||||
case AnimatedValue::TRANSFORM: {
|
||||
gfx::Matrix4x4 transform = animatedValue->mTransform.mFrameTransform;
|
||||
const TransformData& data = animatedValue->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;
|
||||
omtaValue = transform;
|
||||
break;
|
||||
}
|
||||
case AnimatedValue::NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
return omtaValue;
|
||||
}
|
||||
|
||||
void
|
||||
CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
|
||||
gfx::Matrix4x4&& aTransformInDevSpace,
|
||||
|
||||
@@ -146,6 +146,8 @@ public:
|
||||
*/
|
||||
Maybe<gfx::Matrix4x4> GetAnimationTransform(const uint64_t& aId) const;
|
||||
|
||||
OMTAValue GetOMTAValue(const uint64_t& aId) const;
|
||||
|
||||
/**
|
||||
* Return the iterator of animated value table
|
||||
*/
|
||||
|
||||
@@ -733,6 +733,29 @@ LayerTransactionParent::RecvGetAnimationTransform(const uint64_t& aCompositorAni
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
LayerTransactionParent::RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId,
|
||||
OMTAValue* aValue)
|
||||
{
|
||||
if (mDestroyed || !mLayerManager || mLayerManager->IsDestroyed()) {
|
||||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
|
||||
// Make sure we apply the latest animation style or else we can end up with
|
||||
// a race between when we temporarily clear the animation transform (in
|
||||
// CompositorBridgeParent::SetShadowProperties) and when animation recalculates
|
||||
// the value.
|
||||
mCompositorBridge->ApplyAsyncProperties(
|
||||
this, CompositorBridgeParentBase::TransformsToSkip::APZ);
|
||||
|
||||
if (!mAnimStorage) {
|
||||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
|
||||
*aValue = mAnimStorage->GetOMTAValue(aCompositorAnimationsId);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
LayerTransactionParent::RecvGetTransform(const LayerHandle& aLayerHandle,
|
||||
MaybeTransform* aTransform)
|
||||
|
||||
@@ -130,6 +130,8 @@ protected:
|
||||
bool* aHasAnimationOpacity) override;
|
||||
mozilla::ipc::IPCResult RecvGetAnimationTransform(const uint64_t& aCompositorAnimationsId,
|
||||
MaybeTransform* aTransform) override;
|
||||
mozilla::ipc::IPCResult RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId,
|
||||
OMTAValue* aValue) override;
|
||||
mozilla::ipc::IPCResult RecvGetTransform(const LayerHandle& aHandle,
|
||||
MaybeTransform* aTransform) override;
|
||||
mozilla::ipc::IPCResult RecvSetAsyncScrollOffset(const FrameMetrics::ViewID& aId,
|
||||
|
||||
@@ -570,5 +570,11 @@ union MaybeTransform {
|
||||
void_t;
|
||||
};
|
||||
|
||||
union OMTAValue {
|
||||
null_t;
|
||||
float;
|
||||
Matrix4x4;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -16,6 +16,7 @@ include "mozilla/layers/LayersMessageUtils.h";
|
||||
|
||||
using struct mozilla::layers::TextureInfo from "mozilla/layers/CompositorTypes.h";
|
||||
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
|
||||
using class mozilla::layers::APZTestData from "mozilla/layers/APZTestData.h";
|
||||
using mozilla::layers::FrameMetrics::ViewID from "FrameMetrics.h";
|
||||
using struct mozilla::layers::ScrollableLayerGuid from "FrameMetrics.h";
|
||||
@@ -76,6 +77,9 @@ parent:
|
||||
// Leave test mode and resume normal compositing
|
||||
sync LeaveTestMode();
|
||||
|
||||
// Returns |OMTAValue| applied to the layer.
|
||||
sync GetAnimationValue(uint64_t aCompositorAnimationId) returns (OMTAValue value);
|
||||
|
||||
// Returns the value of the opacity applied to the layer by animation.
|
||||
// |hasAnimationOpacity| is true if the layer has an opacity value
|
||||
// specified by animation. If it's false, |opacity| value is indefinite.
|
||||
|
||||
@@ -70,6 +70,7 @@ parent:
|
||||
// More copied from PLayerTransaction, but these are only used for testing.
|
||||
sync SetTestSampleTime(TimeStamp sampleTime);
|
||||
sync LeaveTestMode();
|
||||
sync GetAnimationValue(uint64_t aCompositorAnimationsId) returns (OMTAValue value);
|
||||
sync GetAnimationOpacity(uint64_t aCompositorAnimationsId) returns (float opacity,
|
||||
bool hasAnimationOpacity);
|
||||
sync GetAnimationTransform(uint64_t aCompositorAnimationId) returns (MaybeTransform transform);
|
||||
|
||||
@@ -1360,6 +1360,25 @@ WebRenderBridgeParent::RecvLeaveTestMode()
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
WebRenderBridgeParent::RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId,
|
||||
OMTAValue* aValue)
|
||||
{
|
||||
if (mDestroyed) {
|
||||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mAnimStorage);
|
||||
if (RefPtr<WebRenderBridgeParent> root = GetRootWebRenderBridgeParent()) {
|
||||
root->AdvanceAnimations();
|
||||
} else {
|
||||
AdvanceAnimations();
|
||||
}
|
||||
|
||||
*aValue = mAnimStorage->GetOMTAValue(aCompositorAnimationsId);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
WebRenderBridgeParent::RecvGetAnimationOpacity(const uint64_t& aCompositorAnimationsId,
|
||||
float* aOpacity,
|
||||
|
||||
@@ -118,6 +118,8 @@ public:
|
||||
|
||||
mozilla::ipc::IPCResult RecvSetTestSampleTime(const TimeStamp& aTime) override;
|
||||
mozilla::ipc::IPCResult RecvLeaveTestMode() override;
|
||||
mozilla::ipc::IPCResult RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId,
|
||||
OMTAValue* aValue) override;
|
||||
mozilla::ipc::IPCResult RecvGetAnimationOpacity(const uint64_t& aCompositorAnimationsId,
|
||||
float* aOpacity,
|
||||
bool* aHasAnimationOpacity) override;
|
||||
|
||||
@@ -999,6 +999,8 @@ description =
|
||||
description =
|
||||
[PLayerTransaction::GetAnimationTransform]
|
||||
description =
|
||||
[PLayerTransaction::GetAnimationValue]
|
||||
description = test only
|
||||
[PLayerTransaction::GetTransform]
|
||||
description = test only
|
||||
[PLayerTransaction::SetAsyncScrollOffset]
|
||||
@@ -1025,6 +1027,8 @@ description =
|
||||
description = test only
|
||||
[PWebRenderBridge::LeaveTestMode]
|
||||
description = test only
|
||||
[PWebRenderBridge::GetAnimationValue]
|
||||
description = test only
|
||||
[PWebRenderBridge::GetAnimationOpacity]
|
||||
description = test only
|
||||
[PWebRenderBridge::GetAnimationTransform]
|
||||
|
||||
Reference in New Issue
Block a user