1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NS_SMILCOMPOSITOR_H_
7 #define NS_SMILCOMPOSITOR_H_
9 #include "mozilla/Move.h"
10 #include "nsTHashtable.h"
12 #include "nsSMILAnimationFunction.h"
13 #include "nsSMILTargetIdentifier.h"
14 #include "nsSMILCompositorTable.h"
17 //----------------------------------------------------------------------
20 // Performs the composition of the animation sandwich by combining the results
21 // of a series animation functions according to the rules of SMIL composition
22 // including prioritising animations.
24 class nsSMILCompositor
: public PLDHashEntryHdr
27 typedef nsSMILTargetIdentifier KeyType
;
28 typedef const KeyType
& KeyTypeRef
;
29 typedef const KeyType
* KeyTypePointer
;
31 explicit nsSMILCompositor(KeyTypePointer aKey
)
33 mForceCompositing(false)
35 nsSMILCompositor(const nsSMILCompositor
& toCopy
)
37 mAnimationFunctions(toCopy
.mAnimationFunctions
),
38 mForceCompositing(false)
40 ~nsSMILCompositor() { }
42 // PLDHashEntryHdr methods
43 KeyTypeRef
GetKey() const { return mKey
; }
44 bool KeyEquals(KeyTypePointer aKey
) const;
45 static KeyTypePointer
KeyToPointer(KeyTypeRef aKey
) { return &aKey
; }
46 static PLDHashNumber
HashKey(KeyTypePointer aKey
);
47 enum { ALLOW_MEMMOVE
= false };
49 // Adds the given animation function to this Compositor's list of functions
50 void AddAnimationFunction(nsSMILAnimationFunction
* aFunc
);
52 // Composes the attribute's current value with the list of animation
53 // functions, and assigns the resulting value to this compositor's target
55 void ComposeAttribute();
57 // Clears animation effects on my target attribute
58 void ClearAnimationEffects();
60 // Cycle-collection support
61 void Traverse(nsCycleCollectionTraversalCallback
* aCallback
);
63 // Toggles a bit that will force us to composite (bypassing early-return
64 // optimizations) when we hit ComposeAttribute.
65 void ToggleForceCompositing() { mForceCompositing
= true; }
67 // Transfers |aOther|'s mCachedBaseValue to |this|
68 void StealCachedBaseValue(nsSMILCompositor
* aOther
) {
69 mCachedBaseValue
= mozilla::Move(aOther
->mCachedBaseValue
);
73 // Create a nsISMILAttr for my target, on the heap. Caller is responsible
74 // for deallocating the returned object.
75 nsISMILAttr
* CreateSMILAttr();
77 // Finds the index of the first function that will affect our animation
78 // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any
79 // (used) functions have changed.
80 uint32_t GetFirstFuncToAffectSandwich();
82 // If the passed-in base value differs from our cached base value, this
83 // method updates the cached value (and toggles the 'mForceCompositing' flag)
84 void UpdateCachedBaseValue(const nsSMILValue
& aBaseValue
);
86 // Static callback methods
87 static PLDHashOperator
DoComposeAttribute(
88 nsSMILCompositor
* aCompositor
, void *aData
);
90 // The hash key (tuple of element/attributeName/attributeType)
93 // Hash Value: List of animation functions that animate the specified attr
94 nsTArray
<nsSMILAnimationFunction
*> mAnimationFunctions
;
96 // Member data for detecting when we need to force-recompose
97 // ---------------------------------------------------------
98 // Flag for tracking whether we need to compose. Initialized to false, but
99 // gets flipped to true if we detect that something has changed.
100 bool mForceCompositing
;
102 // Cached base value, so we can detect & force-recompose when it changes
103 // from one sample to the next. (nsSMILAnimationController copies this
104 // forward from the previous sample's compositor.)
105 nsAutoPtr
<nsSMILValue
> mCachedBaseValue
;
108 #endif // NS_SMILCOMPOSITOR_H_