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

Side by Side Diff: Source/core/rendering/animation/WebAnimationProvider.cpp

Issue 23431021: Refactoring animation code in accelerated path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rename createAnimationAndStoreId from appendAnimation. Add some ASSERTs. Created 7 years, 3 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
« no previous file with comments | « Source/core/rendering/animation/WebAnimationProvider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Intel Corporation. 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #include "core/rendering/animation/WebAnimationProvider.h"
29
30 #include "core/platform/animation/AnimationTranslationUtil.h"
31 #include "core/platform/animation/CSSAnimationData.h"
32 #include "core/rendering/style/KeyframeList.h"
33 #include "core/rendering/style/RenderStyle.h"
34 #include "public/platform/WebAnimation.h"
35 #include "wtf/text/StringBuilder.h"
36
37 using WebKit::WebAnimation;
38
39 namespace WebCore {
40
41 namespace {
42
43 String animationNameForTransition(AnimatedPropertyID property)
44 {
45 // | is not a valid identifier character in CSS, so this can never conflict with a keyframe identifier.
46 StringBuilder id;
47 id.appendLiteral("-|transition");
48 id.appendNumber(static_cast<int>(property));
49 id.append('-');
50 return id.toString();
51 }
52
53 AnimatedPropertyID cssToGraphicsLayerProperty(CSSPropertyID cssProperty)
54 {
55 switch (cssProperty) {
56 case CSSPropertyWebkitTransform:
57 return AnimatedPropertyWebkitTransform;
58 case CSSPropertyOpacity:
59 return AnimatedPropertyOpacity;
60 case CSSPropertyBackgroundColor:
61 ASSERT_NOT_REACHED(); // Chromiumn compositor cannot accelerate backgrou nd color yet.
62 return AnimatedPropertyBackgroundColor;
63 case CSSPropertyWebkitFilter:
64 ASSERT_NOT_REACHED(); // Chromiumn compositor cannot accelerate filter y et.
dshwang 2013/09/19 16:10:48 Add ASSERT
Ian Vollick 2013/09/19 17:00:19 typo: s/Chromiumn/Chromium/
65 return AnimatedPropertyWebkitFilter;
66 default:
67 // It's fine if we see other css properties here; they are just not acce lerated.
68 break;
69 }
70 return AnimatedPropertyInvalid;
71 }
72
73 } // namespace
74
75 WebAnimations::WebAnimations()
76 {
77 }
78
79 WebAnimations::~WebAnimations()
80 {
81 }
82
83 // Copy constructor is needed to use this struct as a return value. It actually moves the ownership, not copy.
84 WebAnimations::WebAnimations(const WebAnimations& other)
85 {
86 ASSERT(isEmpty());
87 m_transformAnimation.swap(const_cast<OwnPtr<WebAnimation>& >(other.m_transfo rmAnimation));
88 m_opacityAnimation.swap(const_cast<OwnPtr<WebAnimation>& >(other.m_opacityAn imation));
89 m_filterAnimation.swap(const_cast<OwnPtr<WebAnimation>& >(other.m_filterAnim ation));
90 ASSERT(other.isEmpty());
91 }
92
93 bool WebAnimations::isEmpty() const
94 {
95 return !m_transformAnimation && !m_opacityAnimation && !m_filterAnimation;
96 }
97
98 WebAnimationProvider::WebAnimationProvider()
99 {
100 }
101
102 WebAnimationProvider::~WebAnimationProvider()
103 {
104 }
105
106 int WebAnimationProvider::getWebAnimationId(const String& animationName) const
107 {
108 if (!m_animationIdMap.contains(animationName))
109 return 0;
110 return m_animationIdMap.get(animationName);
111 }
112
113 int WebAnimationProvider::getWebAnimationId(CSSPropertyID property) const
114 {
115 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
116 if (animatedProperty == AnimatedPropertyInvalid)
117 return 0;
118 return getWebAnimationId(animationNameForTransition(animatedProperty));
119 }
120
121 WebAnimations WebAnimationProvider::startAnimation(double timeOffset, const CSSA nimationData* anim, const KeyframeList& keyframes, bool hasTransform, const IntS ize& boxSize)
122 {
123 ASSERT(hasTransform || boxSize.isEmpty());
124 bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
125 bool hasFilter = keyframes.containsProperty(CSSPropertyWebkitFilter);
126
127 if (!hasOpacity && !hasTransform && !hasFilter)
128 return WebAnimations();
129
130 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
131 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
132 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
133
134 size_t numKeyframes = keyframes.size();
135 for (size_t i = 0; i < numKeyframes; ++i) {
136 const KeyframeValue& currentKeyframe = keyframes[i];
137 const RenderStyle* keyframeStyle = currentKeyframe.style();
138 double key = currentKeyframe.key();
139
140 if (!keyframeStyle)
141 continue;
142
143 // Get timing function.
144 RefPtr<TimingFunction> tf = KeyframeValue::timingFunction(keyframeStyle, keyframes.animationName());
145
146 bool isFirstOrLastKeyframe = !key || key == 1;
147 if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsP roperty(CSSPropertyWebkitTransform))
148 transformVector.insert(adoptPtr(new TransformAnimationValue(key, &(k eyframeStyle->transform()), tf)));
149
150 if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsPro perty(CSSPropertyOpacity))
151 opacityVector.insert(adoptPtr(new FloatAnimationValue(key, keyframeS tyle->opacity(), tf)));
152
153 if ((hasFilter && isFirstOrLastKeyframe) || currentKeyframe.containsProp erty(CSSPropertyWebkitFilter))
154 filterVector.insert(adoptPtr(new FilterAnimationValue(key, &(keyfram eStyle->filter()), tf)));
155 }
156 WebAnimations resultAnimations;
157 if (hasTransform)
158 resultAnimations.m_transformAnimation = createWebAnimationAndStoreId(tra nsformVector, boxSize, anim, keyframes.animationName(), timeOffset);
159 if (hasOpacity)
160 resultAnimations.m_opacityAnimation = createWebAnimationAndStoreId(opaci tyVector, IntSize(), anim, keyframes.animationName(), timeOffset);
161 if (hasFilter)
162 resultAnimations.m_filterAnimation = createWebAnimationAndStoreId(filter Vector, IntSize(), anim, keyframes.animationName(), timeOffset);
163
164 return resultAnimations;
165 }
166
167 WebAnimations WebAnimationProvider::startTransition(double timeOffset, CSSProper tyID property, const RenderStyle* fromStyle, const RenderStyle* toStyle, bool ha sTransform, bool hasFilter, const IntSize& boxSize, float fromOpacity, float toO pacity)
168 {
169 ASSERT(property != CSSPropertyInvalid);
170 ASSERT(property == CSSPropertyOpacity || (!fromOpacity && !toOpacity));
171
172 WebAnimations resultAnimations;
173 if (property == CSSPropertyOpacity) {
174 const CSSAnimationData* opacityAnim = toStyle->transitionForProperty(CSS PropertyOpacity);
175 if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
176 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
177 opacityVector.insert(adoptPtr(new FloatAnimationValue(0, fromOpacity )));
178 opacityVector.insert(adoptPtr(new FloatAnimationValue(1, toOpacity)) );
179 resultAnimations.m_opacityAnimation = createWebAnimationAndStoreId(o pacityVector, IntSize(), opacityAnim, animationNameForTransition(AnimatedPropert yOpacity), timeOffset);
180 }
181 }
182 if (property == CSSPropertyWebkitTransform && hasTransform) {
183 const CSSAnimationData* transformAnim = toStyle->transitionForProperty(C SSPropertyWebkitTransform);
184 if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) {
185 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
186 transformVector.insert(adoptPtr(new TransformAnimationValue(0, &from Style->transform())));
187 transformVector.insert(adoptPtr(new TransformAnimationValue(1, &toSt yle->transform())));
188 resultAnimations.m_transformAnimation = createWebAnimationAndStoreId (transformVector, boxSize, transformAnim, animationNameForTransition(AnimatedPro pertyWebkitTransform), timeOffset);
189 }
190 }
191 if (property == CSSPropertyWebkitFilter && hasFilter) {
192 const CSSAnimationData* filterAnim = toStyle->transitionForProperty(CSSP ropertyWebkitFilter);
193 if (filterAnim && !filterAnim->isEmptyOrZeroDuration()) {
194 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
195 filterVector.insert(adoptPtr(new FilterAnimationValue(0, &fromStyle- >filter())));
196 filterVector.insert(adoptPtr(new FilterAnimationValue(1, &toStyle->f ilter())));
197 resultAnimations.m_filterAnimation = createWebAnimationAndStoreId(fi lterVector, IntSize(), filterAnim, animationNameForTransition(AnimatedPropertyWe bkitFilter), timeOffset);
198 }
199 }
200
201 return resultAnimations;
202 }
203
204 PassOwnPtr<WebAnimation> WebAnimationProvider::createWebAnimationAndStoreId(cons t KeyframeValueList& values, const IntSize& boxSize, const CSSAnimationData* ani mation, const String& animationName, double timeOffset)
205 {
206 int animationId = getWebAnimationId(animationName);
207 OwnPtr<WebAnimation> webAnimation(createWebAnimation(values, animation, anim ationId, timeOffset, boxSize));
dshwang 2013/09/19 16:10:48 rename createWebAnimationAndStoreId. I cannot use
Ian Vollick 2013/09/19 17:00:19 sgtm.
208 if (!webAnimation)
209 return PassOwnPtr<WebAnimation>();
210
211 if (!animationId)
212 m_animationIdMap.set(animationName, webAnimation->id());
213 return webAnimation.release();
214 }
215
216 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/animation/WebAnimationProvider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698