1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILCompositor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NS_SMILCOMPOSITOR_H_ 1.10 +#define NS_SMILCOMPOSITOR_H_ 1.11 + 1.12 +#include "nsTHashtable.h" 1.13 +#include "nsString.h" 1.14 +#include "nsSMILAnimationFunction.h" 1.15 +#include "nsSMILTargetIdentifier.h" 1.16 +#include "nsSMILCompositorTable.h" 1.17 +#include "pldhash.h" 1.18 + 1.19 +//---------------------------------------------------------------------- 1.20 +// nsSMILCompositor 1.21 +// 1.22 +// Performs the composition of the animation sandwich by combining the results 1.23 +// of a series animation functions according to the rules of SMIL composition 1.24 +// including prioritising animations. 1.25 + 1.26 +class nsSMILCompositor : public PLDHashEntryHdr 1.27 +{ 1.28 +public: 1.29 + typedef nsSMILTargetIdentifier KeyType; 1.30 + typedef const KeyType& KeyTypeRef; 1.31 + typedef const KeyType* KeyTypePointer; 1.32 + 1.33 + explicit nsSMILCompositor(KeyTypePointer aKey) 1.34 + : mKey(*aKey), 1.35 + mForceCompositing(false) 1.36 + { } 1.37 + nsSMILCompositor(const nsSMILCompositor& toCopy) 1.38 + : mKey(toCopy.mKey), 1.39 + mAnimationFunctions(toCopy.mAnimationFunctions), 1.40 + mForceCompositing(false) 1.41 + { } 1.42 + ~nsSMILCompositor() { } 1.43 + 1.44 + // PLDHashEntryHdr methods 1.45 + KeyTypeRef GetKey() const { return mKey; } 1.46 + bool KeyEquals(KeyTypePointer aKey) const; 1.47 + static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; } 1.48 + static PLDHashNumber HashKey(KeyTypePointer aKey); 1.49 + enum { ALLOW_MEMMOVE = false }; 1.50 + 1.51 + // Adds the given animation function to this Compositor's list of functions 1.52 + void AddAnimationFunction(nsSMILAnimationFunction* aFunc); 1.53 + 1.54 + // Composes the attribute's current value with the list of animation 1.55 + // functions, and assigns the resulting value to this compositor's target 1.56 + // attribute 1.57 + void ComposeAttribute(); 1.58 + 1.59 + // Clears animation effects on my target attribute 1.60 + void ClearAnimationEffects(); 1.61 + 1.62 + // Cycle-collection support 1.63 + void Traverse(nsCycleCollectionTraversalCallback* aCallback); 1.64 + 1.65 + // Toggles a bit that will force us to composite (bypassing early-return 1.66 + // optimizations) when we hit ComposeAttribute. 1.67 + void ToggleForceCompositing() { mForceCompositing = true; } 1.68 + 1.69 + // Transfers |aOther|'s mCachedBaseValue to |this| 1.70 + void StealCachedBaseValue(nsSMILCompositor* aOther) { 1.71 + mCachedBaseValue = aOther->mCachedBaseValue; 1.72 + } 1.73 + 1.74 + private: 1.75 + // Create a nsISMILAttr for my target, on the heap. Caller is responsible 1.76 + // for deallocating the returned object. 1.77 + nsISMILAttr* CreateSMILAttr(); 1.78 + 1.79 + // Finds the index of the first function that will affect our animation 1.80 + // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any 1.81 + // (used) functions have changed. 1.82 + uint32_t GetFirstFuncToAffectSandwich(); 1.83 + 1.84 + // If the passed-in base value differs from our cached base value, this 1.85 + // method updates the cached value (and toggles the 'mForceCompositing' flag) 1.86 + void UpdateCachedBaseValue(const nsSMILValue& aBaseValue); 1.87 + 1.88 + // Static callback methods 1.89 + static PLDHashOperator DoComposeAttribute( 1.90 + nsSMILCompositor* aCompositor, void *aData); 1.91 + 1.92 + // The hash key (tuple of element/attributeName/attributeType) 1.93 + KeyType mKey; 1.94 + 1.95 + // Hash Value: List of animation functions that animate the specified attr 1.96 + nsTArray<nsSMILAnimationFunction*> mAnimationFunctions; 1.97 + 1.98 + // Member data for detecting when we need to force-recompose 1.99 + // --------------------------------------------------------- 1.100 + // Flag for tracking whether we need to compose. Initialized to false, but 1.101 + // gets flipped to true if we detect that something has changed. 1.102 + bool mForceCompositing; 1.103 + 1.104 + // Cached base value, so we can detect & force-recompose when it changes 1.105 + // from one sample to the next. (nsSMILAnimationController copies this 1.106 + // forward from the previous sample's compositor.) 1.107 + nsAutoPtr<nsSMILValue> mCachedBaseValue; 1.108 +}; 1.109 + 1.110 +#endif // NS_SMILCOMPOSITOR_H_