Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "nsTHashtable.h"
10 #include "nsString.h"
11 #include "nsSMILAnimationFunction.h"
12 #include "nsSMILTargetIdentifier.h"
13 #include "nsSMILCompositorTable.h"
14 #include "pldhash.h"
16 //----------------------------------------------------------------------
17 // nsSMILCompositor
18 //
19 // Performs the composition of the animation sandwich by combining the results
20 // of a series animation functions according to the rules of SMIL composition
21 // including prioritising animations.
23 class nsSMILCompositor : public PLDHashEntryHdr
24 {
25 public:
26 typedef nsSMILTargetIdentifier KeyType;
27 typedef const KeyType& KeyTypeRef;
28 typedef const KeyType* KeyTypePointer;
30 explicit nsSMILCompositor(KeyTypePointer aKey)
31 : mKey(*aKey),
32 mForceCompositing(false)
33 { }
34 nsSMILCompositor(const nsSMILCompositor& toCopy)
35 : mKey(toCopy.mKey),
36 mAnimationFunctions(toCopy.mAnimationFunctions),
37 mForceCompositing(false)
38 { }
39 ~nsSMILCompositor() { }
41 // PLDHashEntryHdr methods
42 KeyTypeRef GetKey() const { return mKey; }
43 bool KeyEquals(KeyTypePointer aKey) const;
44 static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
45 static PLDHashNumber HashKey(KeyTypePointer aKey);
46 enum { ALLOW_MEMMOVE = false };
48 // Adds the given animation function to this Compositor's list of functions
49 void AddAnimationFunction(nsSMILAnimationFunction* aFunc);
51 // Composes the attribute's current value with the list of animation
52 // functions, and assigns the resulting value to this compositor's target
53 // attribute
54 void ComposeAttribute();
56 // Clears animation effects on my target attribute
57 void ClearAnimationEffects();
59 // Cycle-collection support
60 void Traverse(nsCycleCollectionTraversalCallback* aCallback);
62 // Toggles a bit that will force us to composite (bypassing early-return
63 // optimizations) when we hit ComposeAttribute.
64 void ToggleForceCompositing() { mForceCompositing = true; }
66 // Transfers |aOther|'s mCachedBaseValue to |this|
67 void StealCachedBaseValue(nsSMILCompositor* aOther) {
68 mCachedBaseValue = aOther->mCachedBaseValue;
69 }
71 private:
72 // Create a nsISMILAttr for my target, on the heap. Caller is responsible
73 // for deallocating the returned object.
74 nsISMILAttr* CreateSMILAttr();
76 // Finds the index of the first function that will affect our animation
77 // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any
78 // (used) functions have changed.
79 uint32_t GetFirstFuncToAffectSandwich();
81 // If the passed-in base value differs from our cached base value, this
82 // method updates the cached value (and toggles the 'mForceCompositing' flag)
83 void UpdateCachedBaseValue(const nsSMILValue& aBaseValue);
85 // Static callback methods
86 static PLDHashOperator DoComposeAttribute(
87 nsSMILCompositor* aCompositor, void *aData);
89 // The hash key (tuple of element/attributeName/attributeType)
90 KeyType mKey;
92 // Hash Value: List of animation functions that animate the specified attr
93 nsTArray<nsSMILAnimationFunction*> mAnimationFunctions;
95 // Member data for detecting when we need to force-recompose
96 // ---------------------------------------------------------
97 // Flag for tracking whether we need to compose. Initialized to false, but
98 // gets flipped to true if we detect that something has changed.
99 bool mForceCompositing;
101 // Cached base value, so we can detect & force-recompose when it changes
102 // from one sample to the next. (nsSMILAnimationController copies this
103 // forward from the previous sample's compositor.)
104 nsAutoPtr<nsSMILValue> mCachedBaseValue;
105 };
107 #endif // NS_SMILCOMPOSITOR_H_