2017-01-25 05:51:30 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "AnimationHelper.h"
|
|
|
|
#include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction
|
2018-05-07 05:15:16 +03:00
|
|
|
#include "mozilla/dom/AnimationEffectBinding.h" // for dom::FillMode
|
2017-01-26 10:04:16 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffectBinding.h" // for dom::IterationComposite
|
2018-05-07 05:07:06 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h" // for dom::KeyFrameEffectReadOnly
|
2018-04-05 20:42:42 +03:00
|
|
|
#include "mozilla/dom/Nullable.h" // for dom::Nullable
|
2017-02-10 01:30:11 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder
|
2017-01-26 10:04:16 +03:00
|
|
|
#include "mozilla/layers/LayerAnimationUtils.h" // for TimingFunctionToComputedTimingFunction
|
2018-04-19 07:50:14 +03:00
|
|
|
#include "mozilla/ServoBindings.h" // for Servo_ComposeAnimationSegment, etc
|
2017-01-25 05:51:30 +03:00
|
|
|
#include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
|
2017-06-28 03:29:06 +03:00
|
|
|
#include "nsDeviceContext.h" // for AppUnitsPerCSSPixel
|
2017-04-12 11:40:48 +03:00
|
|
|
#include "nsDisplayList.h" // for nsDisplayTransform, etc
|
2017-01-25 05:51:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2017-02-10 01:30:11 +03:00
|
|
|
void CompositorAnimationStorage::Clear() {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
|
|
|
mAnimatedValues.Clear();
|
|
|
|
mAnimations.Clear();
|
2017-04-12 11:40:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorAnimationStorage::ClearById(const uint64_t& aId) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2017-02-10 01:30:11 +03:00
|
|
|
|
2017-04-12 11:40:48 +03:00
|
|
|
mAnimatedValues.Remove(aId);
|
|
|
|
mAnimations.Remove(aId);
|
2017-02-10 01:30:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimatedValue* CompositorAnimationStorage::GetAnimatedValue(
|
|
|
|
const uint64_t& aId) const {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
return mAnimatedValues.Get(aId);
|
|
|
|
}
|
|
|
|
|
2018-07-31 00:13:15 +03:00
|
|
|
OMTAValue CompositorAnimationStorage::GetOMTAValue(const uint64_t& aId) const {
|
|
|
|
OMTAValue omtaValue = mozilla::null_t();
|
|
|
|
auto animatedValue = GetAnimatedValue(aId);
|
|
|
|
if (!animatedValue) {
|
|
|
|
return omtaValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (animatedValue->mType) {
|
2018-11-28 03:59:15 +03:00
|
|
|
case AnimatedValue::COLOR:
|
|
|
|
omtaValue = animatedValue->mColor;
|
|
|
|
break;
|
2018-07-31 00:13:15 +03:00
|
|
|
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)
|
2018-08-12 01:17:50 +03:00
|
|
|
double devPerCss = double(scale) / double(AppUnitsPerCSSPixel());
|
2018-07-31 00:13:15 +03:00
|
|
|
transform._41 *= devPerCss;
|
|
|
|
transform._42 *= devPerCss;
|
|
|
|
transform._43 *= devPerCss;
|
|
|
|
omtaValue = transform;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AnimatedValue::NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return omtaValue;
|
|
|
|
}
|
|
|
|
|
2017-02-10 01:30:11 +03:00
|
|
|
void CompositorAnimationStorage::SetAnimatedValue(
|
|
|
|
uint64_t aId, gfx::Matrix4x4&& aTransformInDevSpace,
|
|
|
|
gfx::Matrix4x4&& aFrameTransform, const TransformData& aData) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2018-04-24 09:13:10 +03:00
|
|
|
auto count = mAnimatedValues.Count();
|
|
|
|
AnimatedValue* value = mAnimatedValues.LookupOrAdd(
|
2018-05-30 22:15:35 +03:00
|
|
|
aId, std::move(aTransformInDevSpace), std::move(aFrameTransform), aData);
|
2018-04-24 09:13:10 +03:00
|
|
|
if (count == mAnimatedValues.Count()) {
|
|
|
|
MOZ_ASSERT(value->mType == AnimatedValue::TRANSFORM);
|
2018-05-30 22:15:35 +03:00
|
|
|
value->mTransform.mTransformInDevSpace = std::move(aTransformInDevSpace);
|
|
|
|
value->mTransform.mFrameTransform = std::move(aFrameTransform);
|
2018-04-24 09:13:10 +03:00
|
|
|
value->mTransform.mData = aData;
|
|
|
|
}
|
2017-04-25 06:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorAnimationStorage::SetAnimatedValue(
|
|
|
|
uint64_t aId, gfx::Matrix4x4&& aTransformInDevSpace) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
const TransformData dontCare = {};
|
2018-05-30 22:15:35 +03:00
|
|
|
SetAnimatedValue(aId, std::move(aTransformInDevSpace), gfx::Matrix4x4(),
|
2018-04-24 09:13:10 +03:00
|
|
|
dontCare);
|
2017-02-10 01:30:11 +03:00
|
|
|
}
|
|
|
|
|
2018-11-28 03:59:15 +03:00
|
|
|
void CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
|
|
|
|
nscolor aColor) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
auto count = mAnimatedValues.Count();
|
|
|
|
AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId, aColor);
|
|
|
|
if (count == mAnimatedValues.Count()) {
|
|
|
|
MOZ_ASSERT(value->mType == AnimatedValue::COLOR);
|
|
|
|
value->mColor = aColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 01:30:11 +03:00
|
|
|
void CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
|
|
|
|
const float& aOpacity) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2018-04-24 09:13:10 +03:00
|
|
|
auto count = mAnimatedValues.Count();
|
|
|
|
AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId, aOpacity);
|
|
|
|
if (count == mAnimatedValues.Count()) {
|
|
|
|
MOZ_ASSERT(value->mType == AnimatedValue::OPACITY);
|
|
|
|
value->mOpacity = aOpacity;
|
|
|
|
}
|
2017-02-10 01:30:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationArray* CompositorAnimationStorage::GetAnimations(
|
|
|
|
const uint64_t& aId) const {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
return mAnimations.Get(aId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorAnimationStorage::SetAnimations(uint64_t aId,
|
|
|
|
const AnimationArray& aValue) {
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
AnimationArray* value = new AnimationArray(aValue);
|
|
|
|
mAnimations.Put(aId, value);
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:01:48 +03:00
|
|
|
AnimationHelper::SampleResult AnimationHelper::SampleAnimationForEachNode(
|
2018-05-08 06:58:42 +03:00
|
|
|
TimeStamp aPreviousFrameTime, TimeStamp aCurrentFrameTime,
|
2017-09-21 12:01:48 +03:00
|
|
|
AnimationArray& aAnimations, InfallibleTArray<AnimData>& aAnimationData,
|
2018-05-08 10:58:06 +03:00
|
|
|
RefPtr<RawServoAnimationValue>& aAnimationValue,
|
|
|
|
const AnimatedValue* aPreviousValue) {
|
2018-04-17 07:20:33 +03:00
|
|
|
MOZ_ASSERT(!aAnimations.IsEmpty(), "Should be called with animations");
|
2017-01-26 10:04:16 +03:00
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
bool hasInEffectAnimations = false;
|
2018-04-28 12:09:27 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// In cases where this function returns a SampleResult::Skipped, we actually
|
|
|
|
// do populate aAnimationValue in debug mode, so that we can MOZ_ASSERT at the
|
|
|
|
// call site that the value that would have been computed matches the stored
|
|
|
|
// value that we end up using. This flag is used to ensure we populate
|
|
|
|
// aAnimationValue in this scenario.
|
|
|
|
bool shouldBeSkipped = false;
|
|
|
|
#endif
|
2017-01-26 10:04:16 +03:00
|
|
|
// Process in order, since later aAnimations override earlier ones.
|
|
|
|
for (size_t i = 0, iEnd = aAnimations.Length(); i < iEnd; ++i) {
|
|
|
|
Animation& animation = aAnimations[i];
|
|
|
|
AnimData& animData = aAnimationData[i];
|
|
|
|
|
2017-05-02 10:49:51 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
(!animation.originTime().IsNull() &&
|
2017-05-18 08:06:36 +03:00
|
|
|
animation.startTime().type() == MaybeTimeDuration::TTimeDuration) ||
|
2017-01-26 10:04:16 +03:00
|
|
|
animation.isNotPlaying(),
|
2017-05-02 10:49:51 +03:00
|
|
|
"If we are playing, we should have an origin time and a start"
|
|
|
|
" time");
|
2018-05-08 06:58:42 +03:00
|
|
|
|
2018-05-08 10:58:06 +03:00
|
|
|
// Determine if the animation was play-pending and used a ready time later
|
|
|
|
// than the previous frame time.
|
|
|
|
//
|
|
|
|
// To determine this, _all_ of the following consitions need to hold:
|
|
|
|
//
|
|
|
|
// * There was no previous animation value (i.e. this is the first frame for
|
|
|
|
// the animation since it was sent to the compositor), and
|
|
|
|
// * The animation is playing, and
|
|
|
|
// * There is a previous frame time, and
|
|
|
|
// * The ready time of the animation is ahead of the previous frame time.
|
|
|
|
//
|
|
|
|
bool hasFutureReadyTime = false;
|
|
|
|
if (!aPreviousValue && !animation.isNotPlaying() &&
|
|
|
|
!aPreviousFrameTime.IsNull()) {
|
|
|
|
// This is the inverse of the calculation performed in
|
|
|
|
// AnimationInfo::StartPendingAnimations to calculate the start time of
|
|
|
|
// play-pending animations.
|
2018-05-09 04:47:51 +03:00
|
|
|
// Note that we have to calculate (TimeStamp + TimeDuration) last to avoid
|
|
|
|
// underflow in the middle of the calulation.
|
2018-05-08 10:58:06 +03:00
|
|
|
const TimeStamp readyTime =
|
|
|
|
animation.originTime() +
|
2018-05-09 04:47:51 +03:00
|
|
|
(animation.startTime().get_TimeDuration() +
|
|
|
|
animation.holdTime().MultDouble(1.0 / animation.playbackRate()));
|
|
|
|
hasFutureReadyTime =
|
|
|
|
!readyTime.IsNull() && readyTime > aPreviousFrameTime;
|
2018-05-08 10:58:06 +03:00
|
|
|
}
|
|
|
|
// Use the previous vsync time to make main thread animations and compositor
|
|
|
|
// more closely aligned.
|
|
|
|
//
|
|
|
|
// On the first frame where we have animations the previous timestamp will
|
|
|
|
// not be set so we simply use the current timestamp. As a result we will
|
|
|
|
// end up painting the first frame twice. That doesn't appear to be
|
|
|
|
// noticeable, however.
|
|
|
|
//
|
|
|
|
// Likewise, if the animation is play-pending, it may have a ready time that
|
|
|
|
// is *after* |aPreviousFrameTime| (but *before* |aCurrentFrameTime|).
|
|
|
|
// To avoid flicker we need to use |aCurrentFrameTime| to avoid temporarily
|
|
|
|
// jumping backwards into the range prior to when the animation starts.
|
|
|
|
const TimeStamp& timeStamp =
|
|
|
|
aPreviousFrameTime.IsNull() || hasFutureReadyTime ? aCurrentFrameTime
|
|
|
|
: aPreviousFrameTime;
|
2018-05-08 06:58:42 +03:00
|
|
|
|
2017-05-18 08:06:36 +03:00
|
|
|
// If the animation is not currently playing, e.g. paused or
|
2017-01-26 10:04:16 +03:00
|
|
|
// finished, then use the hold time to stay at the same position.
|
2017-05-18 08:06:36 +03:00
|
|
|
TimeDuration elapsedDuration =
|
|
|
|
animation.isNotPlaying() ||
|
|
|
|
animation.startTime().type() != MaybeTimeDuration::TTimeDuration
|
2017-01-26 10:04:16 +03:00
|
|
|
? animation.holdTime()
|
2018-05-08 06:58:42 +03:00
|
|
|
: (timeStamp - animation.originTime() -
|
2017-05-02 10:49:51 +03:00
|
|
|
animation.startTime().get_TimeDuration())
|
|
|
|
.MultDouble(animation.playbackRate());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-07 05:15:16 +03:00
|
|
|
ComputedTiming computedTiming = dom::AnimationEffect::GetComputedTimingAt(
|
2018-04-24 03:27:53 +03:00
|
|
|
dom::Nullable<TimeDuration>(elapsedDuration), animData.mTiming,
|
2017-01-26 10:04:16 +03:00
|
|
|
animation.playbackRate());
|
|
|
|
|
|
|
|
if (computedTiming.mProgress.IsNull()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
dom::IterationCompositeOperation iterCompositeOperation =
|
|
|
|
static_cast<dom::IterationCompositeOperation>(
|
|
|
|
animation.iterationComposite());
|
|
|
|
|
|
|
|
// Skip caluculation if the progress hasn't changed since the last
|
|
|
|
// calculation.
|
|
|
|
// Note that we don't skip calculate this animation if there is another
|
|
|
|
// animation since the other animation might be 'accumulate' or 'add', or
|
|
|
|
// might have a missing keyframe (i.e. this animation value will be used in
|
|
|
|
// the missing keyframe).
|
|
|
|
// FIXME Bug 1455476: We should do this optimizations for the case where
|
|
|
|
// the layer has multiple animations.
|
2018-05-07 05:08:59 +03:00
|
|
|
if (iEnd == 1 && !dom::KeyframeEffect::HasComputedTimingChanged(
|
2018-04-24 03:27:54 +03:00
|
|
|
computedTiming, iterCompositeOperation,
|
|
|
|
animData.mProgressOnLastCompose,
|
|
|
|
animData.mCurrentIterationOnLastCompose)) {
|
2018-04-28 12:09:27 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
shouldBeSkipped = true;
|
|
|
|
#else
|
2018-04-24 03:27:54 +03:00
|
|
|
return SampleResult::Skipped;
|
2018-04-28 12:09:27 +03:00
|
|
|
#endif
|
2018-04-24 03:27:54 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:04:16 +03:00
|
|
|
uint32_t segmentIndex = 0;
|
|
|
|
size_t segmentSize = animation.segments().Length();
|
|
|
|
AnimationSegment* segment = animation.segments().Elements();
|
|
|
|
while (segment->endPortion() < computedTiming.mProgress.Value() &&
|
|
|
|
segmentIndex < segmentSize - 1) {
|
|
|
|
++segment;
|
|
|
|
++segmentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
double positionInSegment =
|
|
|
|
(computedTiming.mProgress.Value() - segment->startPortion()) /
|
|
|
|
(segment->endPortion() - segment->startPortion());
|
|
|
|
|
|
|
|
double portion = ComputedTimingFunction::GetPortion(
|
|
|
|
animData.mFunctions[segmentIndex], positionInSegment,
|
|
|
|
computedTiming.mBeforeFlag);
|
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
// Like above optimization, skip caluculation if the target segment isn't
|
|
|
|
// changed and if the portion in the segment isn't changed.
|
|
|
|
// This optimization is needed for CSS animations/transitions with step
|
|
|
|
// timing functions (e.g. the throbber animation on tab or frame based
|
|
|
|
// animations).
|
|
|
|
// FIXME Bug 1455476: Like the above optimization, we should apply this
|
|
|
|
// optimizations for multiple animation cases as well.
|
|
|
|
if (iEnd == 1 && animData.mSegmentIndexOnLastCompose == segmentIndex &&
|
|
|
|
!animData.mPortionInSegmentOnLastCompose.IsNull() &&
|
|
|
|
animData.mPortionInSegmentOnLastCompose.Value() == portion) {
|
2018-04-28 12:09:27 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
shouldBeSkipped = true;
|
|
|
|
#else
|
2018-04-24 03:27:54 +03:00
|
|
|
return SampleResult::Skipped;
|
2018-04-28 12:09:27 +03:00
|
|
|
#endif
|
2018-04-24 03:27:54 +03:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:09:11 +03:00
|
|
|
AnimationPropertySegment animSegment;
|
|
|
|
animSegment.mFromKey = 0.0;
|
|
|
|
animSegment.mToKey = 1.0;
|
2018-04-19 07:50:14 +03:00
|
|
|
animSegment.mFromValue =
|
|
|
|
AnimationValue(animData.mStartValues[segmentIndex]);
|
|
|
|
animSegment.mToValue = AnimationValue(animData.mEndValues[segmentIndex]);
|
2017-10-27 22:09:11 +03:00
|
|
|
animSegment.mFromComposite =
|
|
|
|
static_cast<dom::CompositeOperation>(segment->startComposite());
|
|
|
|
animSegment.mToComposite =
|
|
|
|
static_cast<dom::CompositeOperation>(segment->endComposite());
|
|
|
|
|
2017-01-26 10:04:16 +03:00
|
|
|
// interpolate the property
|
2018-04-19 07:50:14 +03:00
|
|
|
aAnimationValue =
|
2018-02-01 07:04:04 +03:00
|
|
|
Servo_ComposeAnimationSegment(
|
2018-04-19 07:50:14 +03:00
|
|
|
&animSegment, aAnimationValue, animData.mEndValues.LastElement(),
|
2018-02-01 07:04:04 +03:00
|
|
|
iterCompositeOperation, portion, computedTiming.mCurrentIteration)
|
|
|
|
.Consume();
|
2018-04-28 12:09:27 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (shouldBeSkipped) {
|
|
|
|
return SampleResult::Skipped;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
hasInEffectAnimations = true;
|
|
|
|
animData.mProgressOnLastCompose = computedTiming.mProgress;
|
|
|
|
animData.mCurrentIterationOnLastCompose = computedTiming.mCurrentIteration;
|
|
|
|
animData.mSegmentIndexOnLastCompose = segmentIndex;
|
|
|
|
animData.mPortionInSegmentOnLastCompose.SetValue(portion);
|
2017-01-26 10:04:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Sanity check that all of animation data are the same.
|
|
|
|
const AnimationData& lastData = aAnimations.LastElement().data();
|
|
|
|
for (const Animation& animation : aAnimations) {
|
|
|
|
const AnimationData& data = animation.data();
|
|
|
|
MOZ_ASSERT(data.type() == lastData.type(),
|
|
|
|
"The type of AnimationData should be the same");
|
|
|
|
if (data.type() == AnimationData::Tnull_t) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(data.type() == AnimationData::TTransformData);
|
|
|
|
const TransformData& transformData = data.get_TransformData();
|
|
|
|
const TransformData& lastTransformData = lastData.get_TransformData();
|
|
|
|
MOZ_ASSERT(transformData.origin() == lastTransformData.origin() &&
|
|
|
|
transformData.transformOrigin() ==
|
|
|
|
lastTransformData.transformOrigin() &&
|
|
|
|
transformData.bounds() == lastTransformData.bounds() &&
|
|
|
|
transformData.appUnitsPerDevPixel() ==
|
|
|
|
lastTransformData.appUnitsPerDevPixel(),
|
|
|
|
"All of members of TransformData should be the same");
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-24 03:27:54 +03:00
|
|
|
|
|
|
|
return hasInEffectAnimations ? SampleResult::Sampled : SampleResult::None;
|
2017-01-26 10:04:16 +03:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:02:10 +03:00
|
|
|
struct BogusAnimation {};
|
|
|
|
|
|
|
|
static inline Result<Ok, BogusAnimation> SetCSSAngle(const CSSAngle& aAngle,
|
2017-01-25 05:51:30 +03:00
|
|
|
nsCSSValue& aValue) {
|
|
|
|
aValue.SetFloatValue(aAngle.value(), nsCSSUnit(aAngle.unit()));
|
2018-03-23 02:02:10 +03:00
|
|
|
if (!aValue.IsAngularUnit()) {
|
|
|
|
NS_ERROR("Bogus animation from IPC");
|
|
|
|
return Err(BogusAnimation{});
|
|
|
|
}
|
|
|
|
return Ok();
|
2017-01-25 05:51:30 +03:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:02:10 +03:00
|
|
|
static Result<nsCSSValueSharedList*, BogusAnimation> CreateCSSValueList(
|
2017-01-25 05:51:30 +03:00
|
|
|
const InfallibleTArray<TransformFunction>& aFunctions) {
|
|
|
|
nsAutoPtr<nsCSSValueList> result;
|
|
|
|
nsCSSValueList** resultTail = getter_Transfers(result);
|
|
|
|
for (uint32_t i = 0; i < aFunctions.Length(); i++) {
|
|
|
|
RefPtr<nsCSSValue::Array> arr;
|
|
|
|
switch (aFunctions[i].type()) {
|
|
|
|
case TransformFunction::TRotationX: {
|
|
|
|
const CSSAngle& angle = aFunctions[i].get_RotationX().angle();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatex,
|
2018-03-23 02:02:10 +03:00
|
|
|
resultTail);
|
|
|
|
MOZ_TRY(SetCSSAngle(angle, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotationY: {
|
|
|
|
const CSSAngle& angle = aFunctions[i].get_RotationY().angle();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatey,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(angle, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotationZ: {
|
|
|
|
const CSSAngle& angle = aFunctions[i].get_RotationZ().angle();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatez,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(angle, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotation: {
|
|
|
|
const CSSAngle& angle = aFunctions[i].get_Rotation().angle();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotate,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(angle, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotation3D: {
|
|
|
|
float x = aFunctions[i].get_Rotation3D().x();
|
|
|
|
float y = aFunctions[i].get_Rotation3D().y();
|
|
|
|
float z = aFunctions[i].get_Rotation3D().z();
|
|
|
|
const CSSAngle& angle = aFunctions[i].get_Rotation3D().angle();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotate3d,
|
|
|
|
resultTail);
|
2017-01-25 05:51:30 +03:00
|
|
|
arr->Item(1).SetFloatValue(x, eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(y, eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(z, eCSSUnit_Number);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(angle, arr->Item(4)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TScale: {
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_scale3d,
|
|
|
|
resultTail);
|
2017-01-25 05:51:30 +03:00
|
|
|
arr->Item(1).SetFloatValue(aFunctions[i].get_Scale().x(),
|
|
|
|
eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(aFunctions[i].get_Scale().y(),
|
|
|
|
eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(aFunctions[i].get_Scale().z(),
|
|
|
|
eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TTranslation: {
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_translate3d,
|
|
|
|
resultTail);
|
2017-01-25 05:51:30 +03:00
|
|
|
arr->Item(1).SetFloatValue(aFunctions[i].get_Translation().x(),
|
|
|
|
eCSSUnit_Pixel);
|
|
|
|
arr->Item(2).SetFloatValue(aFunctions[i].get_Translation().y(),
|
|
|
|
eCSSUnit_Pixel);
|
|
|
|
arr->Item(3).SetFloatValue(aFunctions[i].get_Translation().z(),
|
|
|
|
eCSSUnit_Pixel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TSkewX: {
|
|
|
|
const CSSAngle& x = aFunctions[i].get_SkewX().x();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skewx,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(x, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TSkewY: {
|
|
|
|
const CSSAngle& y = aFunctions[i].get_SkewY().y();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skewy,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(y, arr->Item(1)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TSkew: {
|
|
|
|
const CSSAngle& x = aFunctions[i].get_Skew().x();
|
|
|
|
const CSSAngle& y = aFunctions[i].get_Skew().y();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skew,
|
|
|
|
resultTail);
|
2018-03-23 02:02:10 +03:00
|
|
|
MOZ_TRY(SetCSSAngle(x, arr->Item(1)));
|
|
|
|
MOZ_TRY(SetCSSAngle(y, arr->Item(2)));
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TTransformMatrix: {
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_matrix3d,
|
|
|
|
resultTail);
|
2017-01-25 05:51:30 +03:00
|
|
|
const gfx::Matrix4x4& matrix =
|
|
|
|
aFunctions[i].get_TransformMatrix().value();
|
|
|
|
arr->Item(1).SetFloatValue(matrix._11, eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(matrix._12, eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(matrix._13, eCSSUnit_Number);
|
|
|
|
arr->Item(4).SetFloatValue(matrix._14, eCSSUnit_Number);
|
|
|
|
arr->Item(5).SetFloatValue(matrix._21, eCSSUnit_Number);
|
|
|
|
arr->Item(6).SetFloatValue(matrix._22, eCSSUnit_Number);
|
|
|
|
arr->Item(7).SetFloatValue(matrix._23, eCSSUnit_Number);
|
|
|
|
arr->Item(8).SetFloatValue(matrix._24, eCSSUnit_Number);
|
|
|
|
arr->Item(9).SetFloatValue(matrix._31, eCSSUnit_Number);
|
|
|
|
arr->Item(10).SetFloatValue(matrix._32, eCSSUnit_Number);
|
|
|
|
arr->Item(11).SetFloatValue(matrix._33, eCSSUnit_Number);
|
|
|
|
arr->Item(12).SetFloatValue(matrix._34, eCSSUnit_Number);
|
|
|
|
arr->Item(13).SetFloatValue(matrix._41, eCSSUnit_Number);
|
|
|
|
arr->Item(14).SetFloatValue(matrix._42, eCSSUnit_Number);
|
|
|
|
arr->Item(15).SetFloatValue(matrix._43, eCSSUnit_Number);
|
|
|
|
arr->Item(16).SetFloatValue(matrix._44, eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TPerspective: {
|
|
|
|
float perspective = aFunctions[i].get_Perspective().value();
|
2017-10-17 08:11:19 +03:00
|
|
|
arr = AnimationValue::AppendTransformFunction(eCSSKeyword_perspective,
|
|
|
|
resultTail);
|
2017-01-25 05:51:30 +03:00
|
|
|
arr->Item(1).SetFloatValue(perspective, eCSSUnit_Pixel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(false, "All functions should be implemented?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aFunctions.Length() == 0) {
|
|
|
|
result = new nsCSSValueList();
|
|
|
|
result->mValue.SetNoneValue();
|
|
|
|
}
|
|
|
|
return new nsCSSValueSharedList(result.forget());
|
|
|
|
}
|
|
|
|
|
2018-04-19 07:50:14 +03:00
|
|
|
static already_AddRefed<RawServoAnimationValue> ToAnimationValue(
|
2018-11-28 03:58:46 +03:00
|
|
|
nsCSSPropertyID aProperty, const Animatable& aAnimatable) {
|
2018-04-19 07:50:14 +03:00
|
|
|
RefPtr<RawServoAnimationValue> result;
|
2017-01-25 05:51:30 +03:00
|
|
|
|
|
|
|
switch (aAnimatable.type()) {
|
|
|
|
case Animatable::Tnull_t:
|
|
|
|
break;
|
|
|
|
case Animatable::TArrayOfTransformFunction: {
|
2018-03-23 02:02:10 +03:00
|
|
|
const InfallibleTArray<TransformFunction>& transforms =
|
|
|
|
aAnimatable.get_ArrayOfTransformFunction();
|
|
|
|
auto listOrError = CreateCSSValueList(transforms);
|
|
|
|
if (listOrError.isOk()) {
|
|
|
|
RefPtr<nsCSSValueSharedList> list = listOrError.unwrap();
|
2017-10-27 22:06:30 +03:00
|
|
|
MOZ_ASSERT(list, "Transform list should be non null");
|
2018-04-19 07:50:14 +03:00
|
|
|
result = Servo_AnimationValue_Transform(*list).Consume();
|
2017-10-27 22:04:52 +03:00
|
|
|
}
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
2018-03-23 02:02:10 +03:00
|
|
|
}
|
2017-01-25 05:51:30 +03:00
|
|
|
case Animatable::Tfloat:
|
2018-04-19 07:50:14 +03:00
|
|
|
result = Servo_AnimationValue_Opacity(aAnimatable.get_float()).Consume();
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
2018-11-28 03:58:46 +03:00
|
|
|
case Animatable::Tnscolor:
|
|
|
|
result = Servo_AnimationValue_Color(aProperty, aAnimatable.get_nscolor())
|
|
|
|
.Consume();
|
|
|
|
break;
|
2017-01-25 05:51:30 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unsupported type");
|
|
|
|
}
|
2018-04-19 07:50:14 +03:00
|
|
|
return result.forget();
|
2017-01-25 05:51:30 +03:00
|
|
|
}
|
|
|
|
|
2018-04-19 07:50:14 +03:00
|
|
|
void AnimationHelper::SetAnimations(
|
|
|
|
AnimationArray& aAnimations, InfallibleTArray<AnimData>& aAnimData,
|
|
|
|
RefPtr<RawServoAnimationValue>& aBaseAnimationStyle) {
|
2017-01-25 05:51:30 +03:00
|
|
|
for (uint32_t i = 0; i < aAnimations.Length(); i++) {
|
|
|
|
Animation& animation = aAnimations[i];
|
2018-10-05 08:43:49 +03:00
|
|
|
// Adjust fill mode so that if the main thread is delayed in clearing
|
|
|
|
// this animation we don't introduce flicker by jumping back to the old
|
|
|
|
// underlying value.
|
2017-01-25 05:51:30 +03:00
|
|
|
switch (static_cast<dom::FillMode>(animation.fillMode())) {
|
|
|
|
case dom::FillMode::None:
|
2018-10-05 08:43:49 +03:00
|
|
|
if (animation.playbackRate() > 0) {
|
|
|
|
animation.fillMode() = static_cast<uint8_t>(dom::FillMode::Forwards);
|
|
|
|
} else if (animation.playbackRate() < 0) {
|
|
|
|
animation.fillMode() = static_cast<uint8_t>(dom::FillMode::Backwards);
|
|
|
|
}
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
case dom::FillMode::Backwards:
|
2018-10-05 08:43:49 +03:00
|
|
|
if (animation.playbackRate() > 0) {
|
|
|
|
animation.fillMode() = static_cast<uint8_t>(dom::FillMode::Both);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dom::FillMode::Forwards:
|
|
|
|
if (animation.playbackRate() < 0) {
|
|
|
|
animation.fillMode() = static_cast<uint8_t>(dom::FillMode::Both);
|
|
|
|
}
|
2017-01-25 05:51:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animation.baseStyle().type() != Animatable::Tnull_t) {
|
2018-11-28 03:58:46 +03:00
|
|
|
aBaseAnimationStyle =
|
|
|
|
ToAnimationValue(animation.property(), animation.baseStyle());
|
2017-01-25 05:51:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimData* data = aAnimData.AppendElement();
|
2018-04-24 03:27:53 +03:00
|
|
|
|
|
|
|
data->mTiming =
|
|
|
|
TimingParams{animation.duration(),
|
|
|
|
animation.delay(),
|
|
|
|
animation.endDelay(),
|
|
|
|
animation.iterations(),
|
|
|
|
animation.iterationStart(),
|
|
|
|
static_cast<dom::PlaybackDirection>(animation.direction()),
|
|
|
|
static_cast<dom::FillMode>(animation.fillMode()),
|
2018-06-01 18:59:07 +03:00
|
|
|
AnimationUtils::TimingFunctionToComputedTimingFunction(
|
|
|
|
animation.easingFunction())};
|
2017-01-25 05:51:30 +03:00
|
|
|
InfallibleTArray<Maybe<ComputedTimingFunction>>& functions =
|
|
|
|
data->mFunctions;
|
2018-04-19 07:50:14 +03:00
|
|
|
InfallibleTArray<RefPtr<RawServoAnimationValue>>& startValues =
|
|
|
|
data->mStartValues;
|
|
|
|
InfallibleTArray<RefPtr<RawServoAnimationValue>>& endValues =
|
|
|
|
data->mEndValues;
|
2017-09-14 06:59:06 +03:00
|
|
|
|
|
|
|
const InfallibleTArray<AnimationSegment>& segments = animation.segments();
|
2017-01-25 05:51:30 +03:00
|
|
|
for (const AnimationSegment& segment : segments) {
|
2018-11-28 03:58:46 +03:00
|
|
|
startValues.AppendElement(
|
|
|
|
ToAnimationValue(animation.property(), segment.startState()));
|
|
|
|
endValues.AppendElement(
|
|
|
|
ToAnimationValue(animation.property(), segment.endState()));
|
2017-09-14 06:59:06 +03:00
|
|
|
|
|
|
|
TimingFunction tf = segment.sampleFn();
|
|
|
|
Maybe<ComputedTimingFunction> ctf =
|
|
|
|
AnimationUtils::TimingFunctionToComputedTimingFunction(tf);
|
|
|
|
functions.AppendElement(ctf);
|
2017-01-25 05:51:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:31:45 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:40:48 +03:00
|
|
|
bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage,
|
2018-05-08 06:58:42 +03:00
|
|
|
TimeStamp aPreviousFrameTime,
|
|
|
|
TimeStamp aCurrentFrameTime) {
|
2017-04-12 11:40:48 +03:00
|
|
|
MOZ_ASSERT(aStorage);
|
2018-05-08 09:48:27 +03:00
|
|
|
bool isAnimating = false;
|
2017-04-12 11:40:48 +03:00
|
|
|
|
|
|
|
// Do nothing if there are no compositor animations
|
|
|
|
if (!aStorage->AnimationsCount()) {
|
2018-05-08 09:48:27 +03:00
|
|
|
return isAnimating;
|
2017-04-12 11:40:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sample the animations in CompositorAnimationStorage
|
|
|
|
for (auto iter = aStorage->ConstAnimationsTableIter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
AnimationArray* animations = iter.UserData();
|
2018-04-17 07:20:33 +03:00
|
|
|
if (animations->IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:48:27 +03:00
|
|
|
isAnimating = true;
|
2018-04-19 07:50:14 +03:00
|
|
|
RefPtr<RawServoAnimationValue> animationValue;
|
2017-04-12 11:40:48 +03:00
|
|
|
InfallibleTArray<AnimData> animationData;
|
|
|
|
AnimationHelper::SetAnimations(*animations, animationData, animationValue);
|
2018-05-08 10:58:06 +03:00
|
|
|
AnimatedValue* previousValue = aStorage->GetAnimatedValue(iter.Key());
|
2018-04-24 03:27:54 +03:00
|
|
|
AnimationHelper::SampleResult sampleResult =
|
2018-05-08 06:58:42 +03:00
|
|
|
AnimationHelper::SampleAnimationForEachNode(
|
|
|
|
aPreviousFrameTime, aCurrentFrameTime, *animations, animationData,
|
2018-05-08 10:58:06 +03:00
|
|
|
animationValue, previousValue);
|
2017-04-12 11:40:48 +03:00
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
if (sampleResult != AnimationHelper::SampleResult::Sampled) {
|
2017-04-12 11:40:48 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the AnimatedValue
|
|
|
|
Animation& animation = animations->LastElement();
|
|
|
|
switch (animation.property()) {
|
|
|
|
case eCSSProperty_opacity: {
|
2018-04-19 07:50:14 +03:00
|
|
|
aStorage->SetAnimatedValue(
|
|
|
|
iter.Key(), Servo_AnimationValue_GetOpacity(animationValue));
|
2017-04-12 11:40:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_transform: {
|
2018-04-19 07:50:14 +03:00
|
|
|
RefPtr<nsCSSValueSharedList> list;
|
|
|
|
Servo_AnimationValue_GetTransform(animationValue, &list);
|
2017-04-12 11:40:48 +03:00
|
|
|
const TransformData& transformData =
|
|
|
|
animation.data().get_TransformData();
|
|
|
|
nsPoint origin = transformData.origin();
|
|
|
|
// we expect all our transform data to arrive in device pixels
|
|
|
|
gfx::Point3D transformOrigin = transformData.transformOrigin();
|
2018-05-30 22:15:35 +03:00
|
|
|
nsDisplayTransform::FrameTransformProperties props(std::move(list),
|
2017-04-12 11:40:48 +03:00
|
|
|
transformOrigin);
|
|
|
|
|
|
|
|
gfx::Matrix4x4 transform =
|
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(
|
|
|
|
props, origin, transformData.appUnitsPerDevPixel(), 0,
|
|
|
|
&transformData.bounds());
|
|
|
|
gfx::Matrix4x4 frameTransform = transform;
|
2017-04-17 06:35:42 +03:00
|
|
|
// If the parent has perspective transform, then the offset into
|
|
|
|
// reference frame coordinates is already on this transform. If not,
|
2017-04-12 11:40:48 +03:00
|
|
|
// then we need to ask for it to be added here.
|
2017-04-17 06:35:42 +03:00
|
|
|
if (!transformData.hasPerspectiveParent()) {
|
|
|
|
nsLayoutUtils::PostTranslate(
|
|
|
|
transform, origin, transformData.appUnitsPerDevPixel(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
transform.PostScale(transformData.inheritedXScale(),
|
|
|
|
transformData.inheritedYScale(), 1);
|
2017-04-12 11:40:48 +03:00
|
|
|
|
|
|
|
aStorage->SetAnimatedValue(iter.Key(), std::move(transform),
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(frameTransform), transformData);
|
2017-04-12 11:40:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unhandled animated property");
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 09:48:27 +03:00
|
|
|
|
|
|
|
return isAnimating;
|
2017-04-12 11:40:48 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 05:51:30 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|