michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_SMILCOMPOSITOR_H_ michael@0: #define NS_SMILCOMPOSITOR_H_ michael@0: michael@0: #include "nsTHashtable.h" michael@0: #include "nsString.h" michael@0: #include "nsSMILAnimationFunction.h" michael@0: #include "nsSMILTargetIdentifier.h" michael@0: #include "nsSMILCompositorTable.h" michael@0: #include "pldhash.h" michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsSMILCompositor michael@0: // michael@0: // Performs the composition of the animation sandwich by combining the results michael@0: // of a series animation functions according to the rules of SMIL composition michael@0: // including prioritising animations. michael@0: michael@0: class nsSMILCompositor : public PLDHashEntryHdr michael@0: { michael@0: public: michael@0: typedef nsSMILTargetIdentifier KeyType; michael@0: typedef const KeyType& KeyTypeRef; michael@0: typedef const KeyType* KeyTypePointer; michael@0: michael@0: explicit nsSMILCompositor(KeyTypePointer aKey) michael@0: : mKey(*aKey), michael@0: mForceCompositing(false) michael@0: { } michael@0: nsSMILCompositor(const nsSMILCompositor& toCopy) michael@0: : mKey(toCopy.mKey), michael@0: mAnimationFunctions(toCopy.mAnimationFunctions), michael@0: mForceCompositing(false) michael@0: { } michael@0: ~nsSMILCompositor() { } michael@0: michael@0: // PLDHashEntryHdr methods michael@0: KeyTypeRef GetKey() const { return mKey; } michael@0: bool KeyEquals(KeyTypePointer aKey) const; michael@0: static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; } michael@0: static PLDHashNumber HashKey(KeyTypePointer aKey); michael@0: enum { ALLOW_MEMMOVE = false }; michael@0: michael@0: // Adds the given animation function to this Compositor's list of functions michael@0: void AddAnimationFunction(nsSMILAnimationFunction* aFunc); michael@0: michael@0: // Composes the attribute's current value with the list of animation michael@0: // functions, and assigns the resulting value to this compositor's target michael@0: // attribute michael@0: void ComposeAttribute(); michael@0: michael@0: // Clears animation effects on my target attribute michael@0: void ClearAnimationEffects(); michael@0: michael@0: // Cycle-collection support michael@0: void Traverse(nsCycleCollectionTraversalCallback* aCallback); michael@0: michael@0: // Toggles a bit that will force us to composite (bypassing early-return michael@0: // optimizations) when we hit ComposeAttribute. michael@0: void ToggleForceCompositing() { mForceCompositing = true; } michael@0: michael@0: // Transfers |aOther|'s mCachedBaseValue to |this| michael@0: void StealCachedBaseValue(nsSMILCompositor* aOther) { michael@0: mCachedBaseValue = aOther->mCachedBaseValue; michael@0: } michael@0: michael@0: private: michael@0: // Create a nsISMILAttr for my target, on the heap. Caller is responsible michael@0: // for deallocating the returned object. michael@0: nsISMILAttr* CreateSMILAttr(); michael@0: michael@0: // Finds the index of the first function that will affect our animation michael@0: // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any michael@0: // (used) functions have changed. michael@0: uint32_t GetFirstFuncToAffectSandwich(); michael@0: michael@0: // If the passed-in base value differs from our cached base value, this michael@0: // method updates the cached value (and toggles the 'mForceCompositing' flag) michael@0: void UpdateCachedBaseValue(const nsSMILValue& aBaseValue); michael@0: michael@0: // Static callback methods michael@0: static PLDHashOperator DoComposeAttribute( michael@0: nsSMILCompositor* aCompositor, void *aData); michael@0: michael@0: // The hash key (tuple of element/attributeName/attributeType) michael@0: KeyType mKey; michael@0: michael@0: // Hash Value: List of animation functions that animate the specified attr michael@0: nsTArray mAnimationFunctions; michael@0: michael@0: // Member data for detecting when we need to force-recompose michael@0: // --------------------------------------------------------- michael@0: // Flag for tracking whether we need to compose. Initialized to false, but michael@0: // gets flipped to true if we detect that something has changed. michael@0: bool mForceCompositing; michael@0: michael@0: // Cached base value, so we can detect & force-recompose when it changes michael@0: // from one sample to the next. (nsSMILAnimationController copies this michael@0: // forward from the previous sample's compositor.) michael@0: nsAutoPtr mCachedBaseValue; michael@0: }; michael@0: michael@0: #endif // NS_SMILCOMPOSITOR_H_