forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1378602 - Part2. Move animation data from layer to AnimationInfo.…
… r=kats MozReview-Commit-ID: 4gv8EfPgsii
- Loading branch information
Showing
12 changed files
with
384 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* vim: sw=2 ts=8 et : | ||
*/ | ||
/* 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" | ||
|
||
namespace mozilla { | ||
namespace layers { | ||
|
||
AnimationInfo::AnimationInfo(LayerManager* aManager) : | ||
mManager(aManager), | ||
mCompositorAnimationsId(0), | ||
mAnimationGeneration(0), | ||
mMutated(false) | ||
{ | ||
} | ||
|
||
AnimationInfo::~AnimationInfo() | ||
{ | ||
} | ||
|
||
void | ||
AnimationInfo::EnsureAnimationsId() | ||
{ | ||
if (!mCompositorAnimationsId) { | ||
mCompositorAnimationsId = AnimationHelper::GetNextCompositorAnimationsId(); | ||
} | ||
} | ||
|
||
Animation* | ||
AnimationInfo::AddAnimation() | ||
{ | ||
// Here generates a new id when the first animation is added and | ||
// this id is used to represent the animations in this layer. | ||
EnsureAnimationsId(); | ||
|
||
MOZ_ASSERT(!mPendingAnimations, "should have called ClearAnimations first"); | ||
|
||
Animation* anim = mAnimations.AppendElement(); | ||
|
||
mMutated = true; | ||
|
||
return anim; | ||
} | ||
|
||
Animation* | ||
AnimationInfo::AddAnimationForNextTransaction() | ||
{ | ||
MOZ_ASSERT(mPendingAnimations, | ||
"should have called ClearAnimationsForNextTransaction first"); | ||
|
||
Animation* anim = mPendingAnimations->AppendElement(); | ||
|
||
return anim; | ||
} | ||
|
||
void | ||
AnimationInfo::ClearAnimations() | ||
{ | ||
mPendingAnimations = nullptr; | ||
|
||
if (mAnimations.IsEmpty() && mAnimationData.IsEmpty()) { | ||
return; | ||
} | ||
|
||
if (mManager->AsWebRenderLayerManager()) { | ||
mManager->AsWebRenderLayerManager()-> | ||
AddCompositorAnimationsIdForDiscard(mCompositorAnimationsId); | ||
} | ||
|
||
mAnimations.Clear(); | ||
mAnimationData.Clear(); | ||
|
||
mMutated = true; | ||
} | ||
|
||
void | ||
AnimationInfo::ClearAnimationsForNextTransaction() | ||
{ | ||
// Ensure we have a non-null mPendingAnimations to mark a future clear. | ||
if (!mPendingAnimations) { | ||
mPendingAnimations = new AnimationArray; | ||
} | ||
|
||
mPendingAnimations->Clear(); | ||
} | ||
|
||
void | ||
AnimationInfo::SetCompositorAnimations(const CompositorAnimations& aCompositorAnimations) | ||
{ | ||
mAnimations = aCompositorAnimations.animations(); | ||
mCompositorAnimationsId = aCompositorAnimations.id(); | ||
mAnimationData.Clear(); | ||
AnimationHelper::SetAnimations(mAnimations, | ||
mAnimationData, | ||
mBaseAnimationStyle); | ||
} | ||
|
||
bool | ||
AnimationInfo::StartPendingAnimations(const TimeStamp& aReadyTime) | ||
{ | ||
bool updated = false; | ||
for (size_t animIdx = 0, animEnd = mAnimations.Length(); | ||
animIdx < animEnd; animIdx++) { | ||
Animation& anim = mAnimations[animIdx]; | ||
|
||
// If the animation is play-pending, resolve the start time. | ||
// This mirrors the calculation in Animation::StartTimeFromReadyTime. | ||
if (anim.startTime().type() == MaybeTimeDuration::Tnull_t && | ||
!anim.originTime().IsNull() && | ||
!anim.isNotPlaying()) { | ||
TimeDuration readyTime = aReadyTime - anim.originTime(); | ||
anim.startTime() = | ||
anim.playbackRate() == 0 | ||
? readyTime | ||
: readyTime - anim.holdTime().MultDouble(1.0 / | ||
anim.playbackRate()); | ||
updated = true; | ||
} | ||
} | ||
return updated; | ||
} | ||
|
||
void | ||
AnimationInfo::TransferMutatedFlagToLayer(Layer* aLayer) | ||
{ | ||
if (mMutated) { | ||
aLayer->Mutated(); | ||
mMutated = false; | ||
} | ||
} | ||
|
||
bool | ||
AnimationInfo::ApplyPendingUpdatesForThisTransaction() | ||
{ | ||
if (mPendingAnimations) { | ||
mPendingAnimations->SwapElements(mAnimations); | ||
mPendingAnimations = nullptr; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool | ||
AnimationInfo::HasOpacityAnimation() const | ||
{ | ||
for (uint32_t i = 0; i < mAnimations.Length(); i++) { | ||
if (mAnimations[i].property() == eCSSProperty_opacity) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool | ||
AnimationInfo::HasTransformAnimation() const | ||
{ | ||
for (uint32_t i = 0; i < mAnimations.Length(); i++) { | ||
if (mAnimations[i].property() == eCSSProperty_transform) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} // namespace layers | ||
} // namespace mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* 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" | ||
|
||
namespace mozilla { | ||
namespace layers { | ||
|
||
class Animation; | ||
class CompositorAnimations; | ||
class Layer; | ||
class LayerManager; | ||
struct AnimData; | ||
|
||
class AnimationInfo | ||
{ | ||
typedef InfallibleTArray<Animation> AnimationArray; | ||
public: | ||
explicit AnimationInfo(LayerManager* aManager); | ||
virtual ~AnimationInfo(); | ||
|
||
// Ensure that this AnimationInfo has a valid (non-zero) animations id. This value is | ||
// unique across layers. | ||
void EnsureAnimationsId(); | ||
|
||
// Call AddAnimation to add a new animation to this layer from layout code. | ||
// Caller must fill in all the properties of the returned animation. | ||
// A later animation overrides an earlier one. | ||
Animation* AddAnimation(); | ||
|
||
// These are a parallel to AddAnimation and clearAnimations, except | ||
// they add pending animations that apply only when the next | ||
// transaction is begun. (See also | ||
// SetBaseTransformForNextTransaction.) | ||
Animation* AddAnimationForNextTransaction(); | ||
|
||
void SetAnimationGeneration(uint64_t aCount) { mAnimationGeneration = aCount; } | ||
uint64_t GetAnimationGeneration() { return mAnimationGeneration; } | ||
|
||
// ClearAnimations clears animations on this layer. | ||
void ClearAnimations(); | ||
void ClearAnimationsForNextTransaction(); | ||
void SetCompositorAnimations(const CompositorAnimations& aCompositorAnimations); | ||
bool StartPendingAnimations(const TimeStamp& aReadyTime); | ||
void TransferMutatedFlagToLayer(Layer* aLayer); | ||
|
||
uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; } | ||
StyleAnimationValue GetBaseAnimationStyle() const { return mBaseAnimationStyle; } | ||
InfallibleTArray<AnimData>& GetAnimationData() { return mAnimationData; } | ||
AnimationArray& GetAnimations() { return mAnimations; } | ||
bool ApplyPendingUpdatesForThisTransaction(); | ||
bool HasOpacityAnimation() const; | ||
bool HasTransformAnimation() const; | ||
|
||
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 | ||
uint64_t mAnimationGeneration; | ||
StyleAnimationValue mBaseAnimationStyle; | ||
bool mMutated; | ||
}; | ||
|
||
} // namespace layers | ||
} // namespace mozilla | ||
|
||
#endif // GFX_ANIMATIONINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.