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

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

Issue 2522823002: Blink Animation: Rename AnimationStack to EffectStack. (Closed)
Patch Set: Rename getter and data (and locals) Created 4 years 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
(Empty)
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 #include "core/animation/AnimationStack.h"
32
33 #include "core/animation/CompositorAnimations.h"
34 #include "core/animation/InvalidatableInterpolation.h"
35 #include "core/animation/css/CSSAnimations.h"
36 #include "platform/RuntimeEnabledFeatures.h"
37 #include "wtf/NonCopyingSort.h"
38 #include <algorithm>
39
40 namespace blink {
41
42 namespace {
43
44 void copyToActiveInterpolationsMap(
45 const Vector<RefPtr<Interpolation>>& source,
46 AnimationStack::PropertyHandleFilter propertyHandleFilter,
47 ActiveInterpolationsMap& target) {
48 for (const auto& interpolation : source) {
49 PropertyHandle property = interpolation->getProperty();
50 if (propertyHandleFilter && !propertyHandleFilter(property))
51 continue;
52 ActiveInterpolationsMap::AddResult entry =
53 target.add(property, ActiveInterpolations(1));
54 ActiveInterpolations& activeInterpolations = entry.storedValue->value;
55 if (!entry.isNewEntry &&
56 (RuntimeEnabledFeatures::stackedCSSPropertyAnimationsEnabled() ||
57 !property.isCSSProperty() || property.isPresentationAttribute()) &&
58 interpolation->isInvalidatableInterpolation() &&
59 toInvalidatableInterpolation(*interpolation)
60 .dependsOnUnderlyingValue()) {
61 activeInterpolations.append(interpolation.get());
62 } else {
63 activeInterpolations.at(0) = interpolation.get();
64 }
65 }
66 }
67
68 bool compareSampledEffects(const Member<SampledEffect>& sampledEffect1,
69 const Member<SampledEffect>& sampledEffect2) {
70 DCHECK(sampledEffect1 && sampledEffect2);
71 return sampledEffect1->sequenceNumber() < sampledEffect2->sequenceNumber();
72 }
73
74 void copyNewAnimationsToActiveInterpolationsMap(
75 const HeapVector<Member<const InertEffect>>& newAnimations,
76 AnimationStack::PropertyHandleFilter propertyHandleFilter,
77 ActiveInterpolationsMap& result) {
78 for (const auto& newAnimation : newAnimations) {
79 Vector<RefPtr<Interpolation>> sample;
80 newAnimation->sample(sample);
81 if (!sample.isEmpty())
82 copyToActiveInterpolationsMap(sample, propertyHandleFilter, result);
83 }
84 }
85
86 } // namespace
87
88 AnimationStack::AnimationStack() {}
89
90 bool AnimationStack::hasActiveAnimationsOnCompositor(
91 CSSPropertyID property) const {
92 for (const auto& sampledEffect : m_sampledEffects) {
93 // TODO(dstockwell): move the playing check into AnimationEffectReadOnly and
94 // expose both hasAnimations and hasActiveAnimations
95 if (sampledEffect->effect() &&
96 sampledEffect->effect()->animation()->playing() &&
97 sampledEffect->effect()->hasActiveAnimationsOnCompositor(property))
98 return true;
99 }
100 return false;
101 }
102
103 ActiveInterpolationsMap AnimationStack::activeInterpolations(
104 AnimationStack* animationStack,
105 const HeapVector<Member<const InertEffect>>* newAnimations,
106 const HeapHashSet<Member<const Animation>>* suppressedAnimations,
107 KeyframeEffectReadOnly::Priority priority,
108 PropertyHandleFilter propertyHandleFilter) {
109 ActiveInterpolationsMap result;
110
111 if (animationStack) {
112 HeapVector<Member<SampledEffect>>& sampledEffects =
113 animationStack->m_sampledEffects;
114 // std::sort doesn't work with OwnPtrs
115 nonCopyingSort(sampledEffects.begin(), sampledEffects.end(),
116 compareSampledEffects);
117 animationStack->removeRedundantSampledEffects();
118 for (const auto& sampledEffect : sampledEffects) {
119 if (sampledEffect->priority() != priority ||
120 (suppressedAnimations && sampledEffect->effect() &&
121 suppressedAnimations->contains(
122 sampledEffect->effect()->animation())))
123 continue;
124 copyToActiveInterpolationsMap(sampledEffect->interpolations(),
125 propertyHandleFilter, result);
126 }
127 }
128
129 if (newAnimations)
130 copyNewAnimationsToActiveInterpolationsMap(*newAnimations,
131 propertyHandleFilter, result);
132
133 return result;
134 }
135
136 void AnimationStack::removeRedundantSampledEffects() {
137 HashSet<PropertyHandle> replacedProperties;
138 for (size_t i = m_sampledEffects.size(); i--;) {
139 SampledEffect& sampledEffect = *m_sampledEffects[i];
140 if (sampledEffect.willNeverChange()) {
141 sampledEffect.removeReplacedInterpolations(replacedProperties);
142 sampledEffect.updateReplacedProperties(replacedProperties);
143 }
144 }
145
146 size_t newSize = 0;
147 for (auto& sampledEffect : m_sampledEffects) {
148 if (!sampledEffect->interpolations().isEmpty())
149 m_sampledEffects[newSize++].swap(sampledEffect);
150 else if (sampledEffect->effect())
151 sampledEffect->effect()->notifySampledEffectRemovedFromAnimationStack();
152 }
153 m_sampledEffects.shrink(newSize);
154 }
155
156 DEFINE_TRACE(AnimationStack) {
157 visitor->trace(m_sampledEffects);
158 }
159
160 bool AnimationStack::getAnimatedBoundingBox(FloatBox& box,
161 CSSPropertyID property) const {
162 FloatBox originalBox(box);
163 for (const auto& sampledEffect : m_sampledEffects) {
164 if (sampledEffect->effect() &&
165 sampledEffect->effect()->affects(PropertyHandle(property))) {
166 KeyframeEffectReadOnly* effect = sampledEffect->effect();
167 const Timing& timing = effect->specifiedTiming();
168 double startRange = 0;
169 double endRange = 1;
170 timing.timingFunction->range(&startRange, &endRange);
171 FloatBox expandingBox(originalBox);
172 if (!CompositorAnimations::getAnimatedBoundingBox(
173 expandingBox, *effect->model(), startRange, endRange))
174 return false;
175 box.expandTo(expandingBox);
176 }
177 }
178 return true;
179 }
180
181 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698