Skip to content

Commit

Permalink
Bug 1378602 - Part2. Move animation data from layer to AnimationInfo.…
Browse files Browse the repository at this point in the history
… r=kats

MozReview-Commit-ID: 4gv8EfPgsii
  • Loading branch information
demo99 committed Jul 21, 2017
1 parent 3ce1a02 commit d9a4a64
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 264 deletions.
173 changes: 173 additions & 0 deletions gfx/layers/AnimationInfo.cpp
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
76 changes: 76 additions & 0 deletions gfx/layers/AnimationInfo.h
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
2 changes: 1 addition & 1 deletion gfx/layers/ImageLayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSu
// Snap image edges to pixel boundaries
gfxRect sourceRect(0, 0, 0, 0);
if (mContainer) {
sourceRect.SizeTo(SizeDouble(mContainer->GetCurrentSize()));
sourceRect.SizeTo(gfx::SizeDouble(mContainer->GetCurrentSize()));
}
// Snap our local transform first, and snap the inherited transform as well.
// This makes our snapping equivalent to what would happen if our content
Expand Down
Loading

0 comments on commit d9a4a64

Please sign in to comment.