Bug 1806483 - Enable TSAN cppunittests by default. r=jmaher
[gecko.git] / dom / smil / SMILCompositor.h
blob85ab14557a3548992392c6010e52e1bf3e9604d8
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/. */
7 #ifndef DOM_SMIL_SMILCOMPOSITOR_H_
8 #define DOM_SMIL_SMILCOMPOSITOR_H_
10 #include <utility>
12 #include "PLDHashTable.h"
13 #include "SMILTargetIdentifier.h"
14 #include "mozilla/SMILAnimationFunction.h"
15 #include "mozilla/SMILCompositorTable.h"
16 #include "mozilla/UniquePtr.h"
17 #include "nsCSSPropertyID.h"
18 #include "nsString.h"
19 #include "nsTHashtable.h"
21 namespace mozilla {
23 class ComputedStyle;
25 //----------------------------------------------------------------------
26 // SMILCompositor
28 // Performs the composition of the animation sandwich by combining the results
29 // of a series animation functions according to the rules of SMIL composition
30 // including prioritising animations.
32 class SMILCompositor : public PLDHashEntryHdr {
33 public:
34 using KeyType = SMILTargetIdentifier;
35 using KeyTypeRef = const KeyType&;
36 using KeyTypePointer = const KeyType*;
38 explicit SMILCompositor(KeyTypePointer aKey)
39 : mKey(*aKey), mForceCompositing(false) {}
40 SMILCompositor(SMILCompositor&& toMove) noexcept
41 : PLDHashEntryHdr(std::move(toMove)),
42 mKey(std::move(toMove.mKey)),
43 mAnimationFunctions(std::move(toMove.mAnimationFunctions)),
44 mForceCompositing(false) {}
46 // PLDHashEntryHdr methods
47 KeyTypeRef GetKey() const { return mKey; }
48 bool KeyEquals(KeyTypePointer aKey) const;
49 static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
50 static PLDHashNumber HashKey(KeyTypePointer aKey);
51 enum { ALLOW_MEMMOVE = false };
53 // Adds the given animation function to this Compositor's list of functions
54 void AddAnimationFunction(SMILAnimationFunction* aFunc);
56 // Composes the attribute's current value with the list of animation
57 // functions, and assigns the resulting value to this compositor's target
58 // attribute. If a change is made that might produce style updates,
59 // aMightHavePendingStyleUpdates is set to true. Otherwise it is not modified.
60 void ComposeAttribute(bool& aMightHavePendingStyleUpdates);
62 // Clears animation effects on my target attribute
63 void ClearAnimationEffects();
65 // Cycle-collection support
66 void Traverse(nsCycleCollectionTraversalCallback* aCallback);
68 // Toggles a bit that will force us to composite (bypassing early-return
69 // optimizations) when we hit ComposeAttribute.
70 void ToggleForceCompositing() { mForceCompositing = true; }
72 // Transfers |aOther|'s mCachedBaseValue to |this|
73 void StealCachedBaseValue(SMILCompositor* aOther) {
74 mCachedBaseValue = std::move(aOther->mCachedBaseValue);
77 private:
78 // Create a SMILAttr for my target, on the heap.
80 // @param aBaseComputedStyle An optional ComputedStyle which, if set, will be
81 // used when fetching the base style.
82 UniquePtr<SMILAttr> CreateSMILAttr(const ComputedStyle* aBaseComputedStyle);
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;
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).
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;
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();
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 SMILValue& aBaseValue);
107 // The hash key (tuple of element and attributeName)
108 KeyType mKey;
110 // Hash Value: List of animation functions that animate the specified attr
111 nsTArray<SMILAnimationFunction*> mAnimationFunctions;
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;
119 // Cached base value, so we can detect & force-recompose when it changes
120 // from one sample to the next. (SMILAnimationController moves this
121 // forward from the previous sample's compositor by calling
122 // StealCachedBaseValue.)
123 SMILValue mCachedBaseValue;
126 } // namespace mozilla
128 #endif // DOM_SMIL_SMILCOMPOSITOR_H_