1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_EFFECT_STACK_H_
32 #define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_EFFECT_STACK_H_
33 
34 #include "base/macros.h"
35 #include "third_party/blink/renderer/core/animation/animation.h"
36 #include "third_party/blink/renderer/core/animation/effect_model.h"
37 #include "third_party/blink/renderer/core/animation/keyframe_effect.h"
38 #include "third_party/blink/renderer/core/animation/property_handle.h"
39 #include "third_party/blink/renderer/core/animation/sampled_effect.h"
40 #include "third_party/blink/renderer/core/core_export.h"
41 #include "third_party/blink/renderer/core/css/properties/css_bitset.h"
42 #include "third_party/blink/renderer/platform/geometry/float_box.h"
43 #include "third_party/blink/renderer/platform/wtf/hash_set.h"
44 #include "third_party/blink/renderer/platform/wtf/vector.h"
45 
46 namespace blink {
47 
48 class InertEffect;
49 
50 // Represents the order in which a sequence of SampledEffects should apply.
51 // This sequence is broken down to per PropertyHandle granularity.
52 class CORE_EXPORT EffectStack {
53   DISALLOW_NEW();
54 
55  public:
56   EffectStack();
57 
Add(SampledEffect * sampled_effect)58   void Add(SampledEffect* sampled_effect) {
59     sampled_effects_.push_back(sampled_effect);
60   }
61   static bool CompareSampledEffects(const Member<SampledEffect>&,
62                                     const Member<SampledEffect>&);
IsEmpty()63   bool IsEmpty() const { return sampled_effects_.IsEmpty(); }
64   bool HasActiveAnimationsOnCompositor(const PropertyHandle&) const;
65 
66   using PropertyHandleFilter = bool (*)(const PropertyHandle&);
67   bool AffectsProperties(PropertyHandleFilter) const;
68   bool AffectsProperties(const CSSBitset&,
69                          KeyframeEffect::Priority priority) const;
70   bool HasRevert() const;
71 
72   // Produces a map of properties to active effects.
73   // |effect_stack| contains the sequence of sample effects for an element.
74   // |new_animations| is an optional list of animations to be explicitly added
75   // to the active animations map.
76   // |suppressed_animations| is an optional list of animations to ignore.
77   // |priority| is for matching the effect priority and may be kDefaultPriority
78   // or kTransitionPriority.
79   // |property_handle_filter| is an optional filter for determining which
80   // properties to include in the interpolations map.
81   // |partial_effect_stack_cutoff| is an optional cutoff point, used to create
82   // a partial effect stack.
83   static ActiveInterpolationsMap ActiveInterpolations(
84       EffectStack* effect_stack,
85       const HeapVector<Member<const InertEffect>>* new_animations,
86       const HeapHashSet<Member<const Animation>>* suppressed_animations,
87       KeyframeEffect::Priority priority,
88       PropertyHandleFilter property_handle_filter = nullptr,
89       KeyframeEffect* partial_effect_stack_cutoff = nullptr);
90 
91   void Trace(Visitor*) const;
92 
93  private:
94   void RemoveRedundantSampledEffects();
95 
96   // Effects sorted by priority. Lower priority at the start of the list.
97   HeapVector<Member<SampledEffect>> sampled_effects_;
98 
99   friend class AnimationEffectStackTest;
100   DISALLOW_COPY_AND_ASSIGN(EffectStack);
101 };
102 
103 }  // namespace blink
104 
105 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_EFFECT_STACK_H_
106