Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: third_party/WebKit/Source/core/animation/EffectStack.cpp

Issue 2522823002: Blink Animation: Rename AnimationStack to EffectStack. (Closed)
Patch Set: Rename getter and data (and locals) Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/animation/AnimationStack.h" 31 #include "core/animation/EffectStack.h"
32 32
33 #include "core/animation/CompositorAnimations.h" 33 #include "core/animation/CompositorAnimations.h"
34 #include "core/animation/InvalidatableInterpolation.h" 34 #include "core/animation/InvalidatableInterpolation.h"
35 #include "core/animation/css/CSSAnimations.h" 35 #include "core/animation/css/CSSAnimations.h"
36 #include "platform/RuntimeEnabledFeatures.h" 36 #include "platform/RuntimeEnabledFeatures.h"
37 #include "wtf/NonCopyingSort.h" 37 #include "wtf/NonCopyingSort.h"
38 #include <algorithm> 38 #include <algorithm>
39 39
40 namespace blink { 40 namespace blink {
41 41
42 namespace { 42 namespace {
43 43
44 void copyToActiveInterpolationsMap( 44 void copyToActiveInterpolationsMap(
45 const Vector<RefPtr<Interpolation>>& source, 45 const Vector<RefPtr<Interpolation>>& source,
46 AnimationStack::PropertyHandleFilter propertyHandleFilter, 46 EffectStack::PropertyHandleFilter propertyHandleFilter,
47 ActiveInterpolationsMap& target) { 47 ActiveInterpolationsMap& target) {
48 for (const auto& interpolation : source) { 48 for (const auto& interpolation : source) {
49 PropertyHandle property = interpolation->getProperty(); 49 PropertyHandle property = interpolation->getProperty();
50 if (propertyHandleFilter && !propertyHandleFilter(property)) 50 if (propertyHandleFilter && !propertyHandleFilter(property))
51 continue; 51 continue;
52 ActiveInterpolationsMap::AddResult entry = 52 ActiveInterpolationsMap::AddResult entry =
53 target.add(property, ActiveInterpolations(1)); 53 target.add(property, ActiveInterpolations(1));
54 ActiveInterpolations& activeInterpolations = entry.storedValue->value; 54 ActiveInterpolations& activeInterpolations = entry.storedValue->value;
55 if (!entry.isNewEntry && 55 if (!entry.isNewEntry &&
56 (RuntimeEnabledFeatures::stackedCSSPropertyAnimationsEnabled() || 56 (RuntimeEnabledFeatures::stackedCSSPropertyAnimationsEnabled() ||
57 !property.isCSSProperty() || property.isPresentationAttribute()) && 57 !property.isCSSProperty() || property.isPresentationAttribute()) &&
58 interpolation->isInvalidatableInterpolation() && 58 interpolation->isInvalidatableInterpolation() &&
59 toInvalidatableInterpolation(*interpolation) 59 toInvalidatableInterpolation(*interpolation)
60 .dependsOnUnderlyingValue()) { 60 .dependsOnUnderlyingValue()) {
61 activeInterpolations.append(interpolation.get()); 61 activeInterpolations.append(interpolation.get());
62 } else { 62 } else {
63 activeInterpolations.at(0) = interpolation.get(); 63 activeInterpolations.at(0) = interpolation.get();
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 bool compareSampledEffects(const Member<SampledEffect>& sampledEffect1, 68 bool compareSampledEffects(const Member<SampledEffect>& sampledEffect1,
69 const Member<SampledEffect>& sampledEffect2) { 69 const Member<SampledEffect>& sampledEffect2) {
70 DCHECK(sampledEffect1 && sampledEffect2); 70 DCHECK(sampledEffect1 && sampledEffect2);
71 return sampledEffect1->sequenceNumber() < sampledEffect2->sequenceNumber(); 71 return sampledEffect1->sequenceNumber() < sampledEffect2->sequenceNumber();
72 } 72 }
73 73
74 void copyNewAnimationsToActiveInterpolationsMap( 74 void copyNewAnimationsToActiveInterpolationsMap(
75 const HeapVector<Member<const InertEffect>>& newAnimations, 75 const HeapVector<Member<const InertEffect>>& newAnimations,
76 AnimationStack::PropertyHandleFilter propertyHandleFilter, 76 EffectStack::PropertyHandleFilter propertyHandleFilter,
77 ActiveInterpolationsMap& result) { 77 ActiveInterpolationsMap& result) {
78 for (const auto& newAnimation : newAnimations) { 78 for (const auto& newAnimation : newAnimations) {
79 Vector<RefPtr<Interpolation>> sample; 79 Vector<RefPtr<Interpolation>> sample;
80 newAnimation->sample(sample); 80 newAnimation->sample(sample);
81 if (!sample.isEmpty()) 81 if (!sample.isEmpty())
82 copyToActiveInterpolationsMap(sample, propertyHandleFilter, result); 82 copyToActiveInterpolationsMap(sample, propertyHandleFilter, result);
83 } 83 }
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 AnimationStack::AnimationStack() {} 88 EffectStack::EffectStack() {}
89 89
90 bool AnimationStack::hasActiveAnimationsOnCompositor( 90 bool EffectStack::hasActiveAnimationsOnCompositor(
91 CSSPropertyID property) const { 91 CSSPropertyID property) const {
92 for (const auto& sampledEffect : m_sampledEffects) { 92 for (const auto& sampledEffect : m_sampledEffects) {
93 // TODO(dstockwell): move the playing check into AnimationEffectReadOnly and 93 // TODO(dstockwell): move the playing check into AnimationEffectReadOnly and
94 // expose both hasAnimations and hasActiveAnimations 94 // expose both hasAnimations and hasActiveAnimations
95 if (sampledEffect->effect() && 95 if (sampledEffect->effect() &&
96 sampledEffect->effect()->animation()->playing() && 96 sampledEffect->effect()->animation()->playing() &&
97 sampledEffect->effect()->hasActiveAnimationsOnCompositor(property)) 97 sampledEffect->effect()->hasActiveAnimationsOnCompositor(property))
98 return true; 98 return true;
99 } 99 }
100 return false; 100 return false;
101 } 101 }
102 102
103 ActiveInterpolationsMap AnimationStack::activeInterpolations( 103 ActiveInterpolationsMap EffectStack::activeInterpolations(
104 AnimationStack* animationStack, 104 EffectStack* effectStack,
105 const HeapVector<Member<const InertEffect>>* newAnimations, 105 const HeapVector<Member<const InertEffect>>* newAnimations,
106 const HeapHashSet<Member<const Animation>>* suppressedAnimations, 106 const HeapHashSet<Member<const Animation>>* suppressedAnimations,
107 KeyframeEffectReadOnly::Priority priority, 107 KeyframeEffectReadOnly::Priority priority,
108 PropertyHandleFilter propertyHandleFilter) { 108 PropertyHandleFilter propertyHandleFilter) {
109 ActiveInterpolationsMap result; 109 ActiveInterpolationsMap result;
110 110
111 if (animationStack) { 111 if (effectStack) {
112 HeapVector<Member<SampledEffect>>& sampledEffects = 112 HeapVector<Member<SampledEffect>>& sampledEffects =
113 animationStack->m_sampledEffects; 113 effectStack->m_sampledEffects;
114 // std::sort doesn't work with OwnPtrs 114 // std::sort doesn't work with OwnPtrs
115 nonCopyingSort(sampledEffects.begin(), sampledEffects.end(), 115 nonCopyingSort(sampledEffects.begin(), sampledEffects.end(),
116 compareSampledEffects); 116 compareSampledEffects);
117 animationStack->removeRedundantSampledEffects(); 117 effectStack->removeRedundantSampledEffects();
118 for (const auto& sampledEffect : sampledEffects) { 118 for (const auto& sampledEffect : sampledEffects) {
119 if (sampledEffect->priority() != priority || 119 if (sampledEffect->priority() != priority ||
120 (suppressedAnimations && sampledEffect->effect() && 120 (suppressedAnimations && sampledEffect->effect() &&
121 suppressedAnimations->contains( 121 suppressedAnimations->contains(
122 sampledEffect->effect()->animation()))) 122 sampledEffect->effect()->animation())))
123 continue; 123 continue;
124 copyToActiveInterpolationsMap(sampledEffect->interpolations(), 124 copyToActiveInterpolationsMap(sampledEffect->interpolations(),
125 propertyHandleFilter, result); 125 propertyHandleFilter, result);
126 } 126 }
127 } 127 }
128 128
129 if (newAnimations) 129 if (newAnimations) {
130 copyNewAnimationsToActiveInterpolationsMap(*newAnimations, 130 copyNewAnimationsToActiveInterpolationsMap(*newAnimations,
131 propertyHandleFilter, result); 131 propertyHandleFilter, result);
132 132 }
133 return result; 133 return result;
134 } 134 }
135 135
136 void AnimationStack::removeRedundantSampledEffects() { 136 void EffectStack::removeRedundantSampledEffects() {
137 HashSet<PropertyHandle> replacedProperties; 137 HashSet<PropertyHandle> replacedProperties;
138 for (size_t i = m_sampledEffects.size(); i--;) { 138 for (size_t i = m_sampledEffects.size(); i--;) {
139 SampledEffect& sampledEffect = *m_sampledEffects[i]; 139 SampledEffect& sampledEffect = *m_sampledEffects[i];
140 if (sampledEffect.willNeverChange()) { 140 if (sampledEffect.willNeverChange()) {
141 sampledEffect.removeReplacedInterpolations(replacedProperties); 141 sampledEffect.removeReplacedInterpolations(replacedProperties);
142 sampledEffect.updateReplacedProperties(replacedProperties); 142 sampledEffect.updateReplacedProperties(replacedProperties);
143 } 143 }
144 } 144 }
145 145
146 size_t newSize = 0; 146 size_t newSize = 0;
147 for (auto& sampledEffect : m_sampledEffects) { 147 for (auto& sampledEffect : m_sampledEffects) {
148 if (!sampledEffect->interpolations().isEmpty()) 148 if (!sampledEffect->interpolations().isEmpty())
149 m_sampledEffects[newSize++].swap(sampledEffect); 149 m_sampledEffects[newSize++].swap(sampledEffect);
150 else if (sampledEffect->effect()) 150 else if (sampledEffect->effect())
151 sampledEffect->effect()->notifySampledEffectRemovedFromAnimationStack(); 151 sampledEffect->effect()->notifySampledEffectRemovedFromEffectStack();
152 } 152 }
153 m_sampledEffects.shrink(newSize); 153 m_sampledEffects.shrink(newSize);
154 } 154 }
155 155
156 DEFINE_TRACE(AnimationStack) { 156 DEFINE_TRACE(EffectStack) {
157 visitor->trace(m_sampledEffects); 157 visitor->trace(m_sampledEffects);
158 } 158 }
159 159
160 bool AnimationStack::getAnimatedBoundingBox(FloatBox& box, 160 bool EffectStack::getAnimatedBoundingBox(FloatBox& box,
161 CSSPropertyID property) const { 161 CSSPropertyID property) const {
162 FloatBox originalBox(box); 162 FloatBox originalBox(box);
163 for (const auto& sampledEffect : m_sampledEffects) { 163 for (const auto& sampledEffect : m_sampledEffects) {
164 if (sampledEffect->effect() && 164 if (sampledEffect->effect() &&
165 sampledEffect->effect()->affects(PropertyHandle(property))) { 165 sampledEffect->effect()->affects(PropertyHandle(property))) {
166 KeyframeEffectReadOnly* effect = sampledEffect->effect(); 166 KeyframeEffectReadOnly* effect = sampledEffect->effect();
167 const Timing& timing = effect->specifiedTiming(); 167 const Timing& timing = effect->specifiedTiming();
168 double startRange = 0; 168 double startRange = 0;
169 double endRange = 1; 169 double endRange = 1;
170 timing.timingFunction->range(&startRange, &endRange); 170 timing.timingFunction->range(&startRange, &endRange);
171 FloatBox expandingBox(originalBox); 171 FloatBox expandingBox(originalBox);
172 if (!CompositorAnimations::getAnimatedBoundingBox( 172 if (!CompositorAnimations::getAnimatedBoundingBox(
173 expandingBox, *effect->model(), startRange, endRange)) 173 expandingBox, *effect->model(), startRange, endRange))
174 return false; 174 return false;
175 box.expandTo(expandingBox); 175 box.expandTo(expandingBox);
176 } 176 }
177 } 177 }
178 return true; 178 return true;
179 } 179 }
180 180
181 } // namespace blink 181 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/EffectStack.h ('k') | third_party/WebKit/Source/core/animation/EffectStackTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698