Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef GFX_ANIMATIONINFO_H
8
#define GFX_ANIMATIONINFO_H
9
10
#include "nsCSSPropertyIDSet.h"
11
#include "nsDisplayItemTypes.h"
12
#include "mozilla/Array.h"
13
#include "mozilla/UniquePtr.h"
14
#include "mozilla/layers/LayersMessages.h" // for TransformData
15
16
struct RawServoAnimationValue;
17
class nsIContent;
18
class nsIFrame;
19
20
namespace mozilla {
21
namespace gfx {
22
class Path;
23
} // namespace gfx
24
25
namespace layers {
26
27
class Animation;
28
class CompositorAnimations;
29
class Layer;
30
class LayerManager;
31
struct CompositorAnimationData;
32
struct PropertyAnimationGroup;
33
34
class AnimationInfo final {
35
typedef nsTArray<Animation> AnimationArray;
36
37
public:
38
AnimationInfo();
39
~AnimationInfo();
40
41
// Ensure that this AnimationInfo has a valid (non-zero) animations id. This
42
// value is unique across layers.
43
void EnsureAnimationsId();
44
45
// Call AddAnimation to add a new animation to this layer from layout code.
46
// Caller must fill in all the properties of the returned animation.
47
// A later animation overrides an earlier one.
48
Animation* AddAnimation();
49
50
// These are a parallel to AddAnimation and clearAnimations, except
51
// they add pending animations that apply only when the next
52
// transaction is begun. (See also
53
// SetBaseTransformForNextTransaction.)
54
Animation* AddAnimationForNextTransaction();
55
56
void SetAnimationGeneration(uint64_t aCount) {
57
mAnimationGeneration = Some(aCount);
58
}
59
Maybe<uint64_t> GetAnimationGeneration() const {
60
return mAnimationGeneration;
61
}
62
63
// ClearAnimations clears animations on this layer.
64
void ClearAnimations();
65
void ClearAnimationsForNextTransaction();
66
void SetCompositorAnimations(
67
const CompositorAnimations& aCompositorAnimations);
68
bool StartPendingAnimations(const TimeStamp& aReadyTime);
69
void TransferMutatedFlagToLayer(Layer* aLayer);
70
71
uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
72
// Note: We don't set mAnimations on the compositor thread, so this will
73
// always return an empty array on the compositor thread.
74
AnimationArray& GetAnimations() { return mAnimations; }
75
nsTArray<PropertyAnimationGroup>& GetPropertyAnimationGroups() {
76
return mPropertyAnimationGroups;
77
}
78
const Maybe<TransformData>& GetTransformData() const {
79
return mTransformData;
80
}
81
bool ApplyPendingUpdatesForThisTransaction();
82
bool HasTransformAnimation() const;
83
84
gfx::Path* CachedMotionPath() { return mCachedMotionPath; }
85
86
// In case of continuation, |aFrame| must be the first or the last
87
// continuation frame, otherwise this function might return Nothing().
88
static Maybe<uint64_t> GetGenerationFromFrame(
89
nsIFrame* aFrame, DisplayItemType aDisplayItemKey);
90
91
using CompositorAnimatableDisplayItemTypes =
92
Array<DisplayItemType,
93
nsCSSPropertyIDSet::CompositorAnimatableDisplayItemCount()>;
94
using AnimationGenerationCallback = std::function<bool(
95
const Maybe<uint64_t>& aGeneration, DisplayItemType aDisplayItemType)>;
96
// Enumerates animation generations on |aFrame| for the given display item
97
// types and calls |aCallback| with the animation generation.
98
//
99
// The enumeration stops if |aCallback| returns false.
100
static void EnumerateGenerationOnFrame(
101
const nsIFrame* aFrame, const nsIContent* aContent,
102
const CompositorAnimatableDisplayItemTypes& aDisplayItemTypes,
103
const AnimationGenerationCallback& aCallback);
104
105
protected:
106
// mAnimations (and mPendingAnimations) are only set on the main thread.
107
//
108
// Once the animations are received on the compositor thread/process we
109
// use AnimationHelper::ExtractAnimations to transform the rather compact
110
// representation of animation data we transfer into something we can more
111
// readily use for sampling and then store it in mPropertyAnimationGroups
112
// (below) or CompositorAnimationStorage.mAnimations for WebRender.
113
AnimationArray mAnimations;
114
UniquePtr<AnimationArray> mPendingAnimations;
115
116
uint64_t mCompositorAnimationsId;
117
// The extracted data produced by AnimationHelper::ExtractAnimations().
118
//
119
// Each entry in the array represents an animation list for one property. For
120
// transform-like properties (e.g. transform, rotate etc.), there may be
121
// multiple entries depending on how many transform-like properties we have.
122
// Note: we don't use AnimationStorageData here becuase including
123
// AnimationHelper.h causes build errors (because other modules may include
124
// this file but cannot see LayersMessages.h).
125
nsTArray<PropertyAnimationGroup> mPropertyAnimationGroups;
126
Maybe<TransformData> mTransformData;
127
// For motion path. We cached the gfx path for optimization.
128
RefPtr<gfx::Path> mCachedMotionPath;
129
// If this layer is used for OMTA, then this counter is used to ensure we
130
// stay in sync with the animation manager
131
Maybe<uint64_t> mAnimationGeneration;
132
bool mMutated;
133
};
134
135
} // namespace layers
136
} // namespace mozilla
137
138
#endif // GFX_ANIMATIONINFO_H