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

Side by Side Diff: Source/core/animation/KeyframeEffectModel.cpp

Issue 851693007: Prepare for responsive CSS animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Compositor restarts after style change Created 5 years, 11 months 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 15 matching lines...) Expand all
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 "config.h" 31 #include "config.h"
32 #include "core/animation/KeyframeEffectModel.h" 32 #include "core/animation/KeyframeEffectModel.h"
33 33
34 #include "core/StylePropertyShorthand.h" 34 #include "core/StylePropertyShorthand.h"
35 #include "core/animation/AnimationNode.h" 35 #include "core/animation/AnimationNode.h"
36 #include "core/animation/css/CSSAnimatableValueFactory.h"
37 #include "core/animation/css/CSSPropertyEquality.h"
38 #include "core/css/resolver/StyleResolver.h"
36 #include "platform/animation/AnimationUtilities.h" 39 #include "platform/animation/AnimationUtilities.h"
37 #include "platform/geometry/FloatBox.h" 40 #include "platform/geometry/FloatBox.h"
38 #include "platform/transforms/TransformationMatrix.h" 41 #include "platform/transforms/TransformationMatrix.h"
39 #include "wtf/text/StringHash.h" 42 #include "wtf/text/StringHash.h"
40 43
41 namespace blink { 44 namespace blink {
42 45
43 PropertySet KeyframeEffectModelBase::properties() const 46 PropertySet KeyframeEffectModelBase::properties() const
44 { 47 {
45 PropertySet result; 48 PropertySet result;
46 for (const auto& keyframe : m_keyframes) { 49 for (const auto& keyframe : m_keyframes) {
47 for (const auto& property : keyframe->properties()) 50 for (const auto& property : keyframe->properties())
48 result.add(property); 51 result.add(property);
49 } 52 }
50 return result; 53 return result;
51 } 54 }
52 55
53 void KeyframeEffectModelBase::sample(int iteration, double fraction, double iter ationDuration, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolat ion>>>& result) const 56 void KeyframeEffectModelBase::sample(int iteration, double fraction, double iter ationDuration, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolat ion>>>& result) const
54 { 57 {
55 ASSERT(iteration >= 0); 58 ASSERT(iteration >= 0);
56 ASSERT(!isNull(fraction)); 59 ASSERT(!isNull(fraction));
57 ensureKeyframeGroups(); 60 ensureKeyframeGroups();
58 ensureInterpolationEffect(); 61 ensureInterpolationEffect();
59 62
60 return m_interpolationEffect->getActiveInterpolations(fraction, iterationDur ation, result); 63 return m_interpolationEffect->getActiveInterpolations(fraction, iterationDur ation, result);
61 } 64 }
62 65
66 void KeyframeEffectModelBase::snapshotCompositableProperties(const Element* elem ent, const RenderStyle& style)
67 {
68 if (affects(CSSPropertyOpacity))
69 snapshotCompositableProperty(CSSPropertyOpacity, element, style);
70 if (affects(CSSPropertyTransform))
71 snapshotCompositableProperty(CSSPropertyTransform, element, style);
72 if (affects(CSSPropertyWebkitFilter))
73 snapshotCompositableProperty(CSSPropertyWebkitFilter, element, style);
74 }
75
76 bool KeyframeEffectModelBase::snapshotCompositablePropertiesIfNeeded(const Eleme nt* element, const RenderStyle& oldStyle, const RenderStyle& newStyle)
77 {
78 bool changed = false;
79
80 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyOpacity, oldStyle, newS tyle) && affects(CSSPropertyOpacity)) {
81 snapshotCompositableProperty(CSSPropertyOpacity, element, newStyle);
82 changed = true;
83 }
84
85 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyTransform, oldStyle, ne wStyle) && affects(CSSPropertyTransform)) {
86 snapshotCompositableProperty(CSSPropertyTransform, element, newStyle);
87 changed = true;
88 }
89
90 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyWebkitFilter, oldStyle, newStyle) && affects(CSSPropertyWebkitFilter)) {
91 snapshotCompositableProperty(CSSPropertyWebkitFilter, element, newStyle) ;
92 changed = true;
93 }
94
95 return changed;
96 }
97
98 void KeyframeEffectModelBase::snapshotCompositableProperty(CSSPropertyID propert y, const Element* element, const RenderStyle& style)
99 {
100 auto& keyframes = m_keyframeGroups->get(property)->m_keyframes;
101 for (size_t i = 0; i < keyframes.size(); i++) {
102 auto& keyframe = toStringPropertySpecificKeyframe(*keyframes[i]);
103 if (!keyframe.value())
104 keyframe.setAnimatableValue(CSSAnimatableValueFactory::create(proper ty, style));
105 else if (!keyframe.getAnimatableValue())
106 keyframe.setAnimatableValue(StyleResolver::createAnimatableValueSnap shot(const_cast<Element&>(*element), property, *keyframe.value()));
107 }
108 }
109
63 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes) 110 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes)
64 { 111 {
65 double lastOffset = 0; 112 double lastOffset = 0;
66 KeyframeVector result; 113 KeyframeVector result;
67 result.reserveCapacity(keyframes.size()); 114 result.reserveCapacity(keyframes.size());
68 115
69 for (const auto& keyframe : keyframes) { 116 for (const auto& keyframe : keyframes) {
70 double offset = keyframe->offset(); 117 double offset = keyframe->offset();
71 if (!isNull(offset)) { 118 if (!isNull(offset)) {
72 ASSERT(offset >= 0); 119 ASSERT(offset >= 0);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 180 }
134 181
135 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const 182 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const
136 { 183 {
137 if (m_interpolationEffect) 184 if (m_interpolationEffect)
138 return; 185 return;
139 m_interpolationEffect = InterpolationEffect::create(); 186 m_interpolationEffect = InterpolationEffect::create();
140 187
141 for (const auto& entry : *m_keyframeGroups) { 188 for (const auto& entry : *m_keyframeGroups) {
142 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes (); 189 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes ();
143 ASSERT(keyframes[0]->composite() == AnimationEffect::CompositeReplace); 190 ASSERT(keyframes[0]->composite() == AnimationEffect::CompositeReplace || keyframes[0]->composite() == AnimationEffect::CompositeAdd);
144 for (size_t i = 0; i < keyframes.size() - 1; i++) { 191 for (size_t i = 0; i < keyframes.size() - 1; i++) {
145 ASSERT(keyframes[i + 1]->composite() == AnimationEffect::CompositeRe place); 192 ASSERT(keyframes[i + 1]->composite() == AnimationEffect::CompositeRe place || keyframes[i + 1]->composite() == AnimationEffect::CompositeAdd);
146 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity()); 193 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity());
147 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); 194 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset();
148 if (applyTo == 1) 195 if (applyTo == 1)
149 applyTo = std::numeric_limits<double>::infinity(); 196 applyTo = std::numeric_limits<double>::infinity();
150 197
151 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo); 198 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo);
152 } 199 }
153 } 200 }
154 } 201 }
155 202
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 273 }
227 274
228 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor) 275 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor)
229 { 276 {
230 #if ENABLE(OILPAN) 277 #if ENABLE(OILPAN)
231 visitor->trace(m_keyframes); 278 visitor->trace(m_keyframes);
232 #endif 279 #endif
233 } 280 }
234 281
235 } // namespace 282 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698