/src/mozilla-central/dom/smil/nsSMILCompositor.h
Line | Count | Source (jump to first uncovered line) |
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 NS_SMILCOMPOSITOR_H_ |
8 | | #define NS_SMILCOMPOSITOR_H_ |
9 | | |
10 | | #include "mozilla/Move.h" |
11 | | #include "mozilla/UniquePtr.h" |
12 | | #include "nsTHashtable.h" |
13 | | #include "nsString.h" |
14 | | #include "nsSMILAnimationFunction.h" |
15 | | #include "nsSMILTargetIdentifier.h" |
16 | | #include "nsSMILCompositorTable.h" |
17 | | #include "PLDHashTable.h" |
18 | | |
19 | | //---------------------------------------------------------------------- |
20 | | // nsSMILCompositor |
21 | | // |
22 | | // Performs the composition of the animation sandwich by combining the results |
23 | | // of a series animation functions according to the rules of SMIL composition |
24 | | // including prioritising animations. |
25 | | |
26 | | class nsSMILCompositor : public PLDHashEntryHdr |
27 | | { |
28 | | public: |
29 | | typedef nsSMILTargetIdentifier KeyType; |
30 | | typedef const KeyType& KeyTypeRef; |
31 | | typedef const KeyType* KeyTypePointer; |
32 | | |
33 | | explicit nsSMILCompositor(KeyTypePointer aKey) |
34 | | : mKey(*aKey), |
35 | | mForceCompositing(false) |
36 | 0 | { } |
37 | | nsSMILCompositor(nsSMILCompositor&& toMove) |
38 | | : PLDHashEntryHdr(std::move(toMove)), |
39 | | mKey(std::move(toMove.mKey)), |
40 | | mAnimationFunctions(std::move(toMove.mAnimationFunctions)), |
41 | | mForceCompositing(false) |
42 | 0 | { } |
43 | 0 | ~nsSMILCompositor() { } |
44 | | |
45 | | // PLDHashEntryHdr methods |
46 | 0 | KeyTypeRef GetKey() const { return mKey; } |
47 | | bool KeyEquals(KeyTypePointer aKey) const; |
48 | 0 | static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; } |
49 | | static PLDHashNumber HashKey(KeyTypePointer aKey); |
50 | | enum { ALLOW_MEMMOVE = false }; |
51 | | |
52 | | // Adds the given animation function to this Compositor's list of functions |
53 | | void AddAnimationFunction(nsSMILAnimationFunction* aFunc); |
54 | | |
55 | | // Composes the attribute's current value with the list of animation |
56 | | // functions, and assigns the resulting value to this compositor's target |
57 | | // attribute. If a change is made that might produce style updates, |
58 | | // aMightHavePendingStyleUpdates is set to true. Otherwise it is not modified. |
59 | | void ComposeAttribute(bool& aMightHavePendingStyleUpdates); |
60 | | |
61 | | // Clears animation effects on my target attribute |
62 | | void ClearAnimationEffects(); |
63 | | |
64 | | // Cycle-collection support |
65 | | void Traverse(nsCycleCollectionTraversalCallback* aCallback); |
66 | | |
67 | | // Toggles a bit that will force us to composite (bypassing early-return |
68 | | // optimizations) when we hit ComposeAttribute. |
69 | 0 | void ToggleForceCompositing() { mForceCompositing = true; } |
70 | | |
71 | | // Transfers |aOther|'s mCachedBaseValue to |this| |
72 | 0 | void StealCachedBaseValue(nsSMILCompositor* aOther) { |
73 | 0 | mCachedBaseValue = std::move(aOther->mCachedBaseValue); |
74 | 0 | } |
75 | | |
76 | | private: |
77 | | // Create a nsISMILAttr for my target, on the heap. |
78 | | // |
79 | | // @param aBaseComputedStyle An optional ComputedStyle which, if set, will be |
80 | | // used when fetching the base style. |
81 | | mozilla::UniquePtr<nsISMILAttr> |
82 | | CreateSMILAttr(mozilla::ComputedStyle* aBaseComputedStyle); |
83 | | |
84 | | // Returns the CSS property this compositor should animate, or |
85 | | // eCSSProperty_UNKNOWN if this compositor does not animate a CSS property. |
86 | | nsCSSPropertyID GetCSSPropertyToAnimate() const; |
87 | | |
88 | | // Returns true if we might need to refer to base styles (i.e. we are |
89 | | // targeting a CSS property and have one or more animation functions that |
90 | | // don't just replace the underlying value). |
91 | | // |
92 | | // This might return true in some cases where we don't actually need the base |
93 | | // style since it doesn't build up the animation sandwich to check if the |
94 | | // functions that appear to need the base style are actually replaced by |
95 | | // a function further up the stack. |
96 | | bool MightNeedBaseStyle() const; |
97 | | |
98 | | // Finds the index of the first function that will affect our animation |
99 | | // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any |
100 | | // (used) functions have changed. |
101 | | uint32_t GetFirstFuncToAffectSandwich(); |
102 | | |
103 | | // If the passed-in base value differs from our cached base value, this |
104 | | // method updates the cached value (and toggles the 'mForceCompositing' flag) |
105 | | void UpdateCachedBaseValue(const nsSMILValue& aBaseValue); |
106 | | |
107 | | // The hash key (tuple of element and attributeName) |
108 | | KeyType mKey; |
109 | | |
110 | | // Hash Value: List of animation functions that animate the specified attr |
111 | | nsTArray<nsSMILAnimationFunction*> mAnimationFunctions; |
112 | | |
113 | | // Member data for detecting when we need to force-recompose |
114 | | // --------------------------------------------------------- |
115 | | // Flag for tracking whether we need to compose. Initialized to false, but |
116 | | // gets flipped to true if we detect that something has changed. |
117 | | bool mForceCompositing; |
118 | | |
119 | | // Cached base value, so we can detect & force-recompose when it changes |
120 | | // from one sample to the next. (nsSMILAnimationController moves this |
121 | | // forward from the previous sample's compositor by calling |
122 | | // StealCachedBaseValue.) |
123 | | nsSMILValue mCachedBaseValue; |
124 | | }; |
125 | | |
126 | | #endif // NS_SMILCOMPOSITOR_H_ |