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

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

Issue 1218943002: Compositor animations for Independent CSS Transform Properties (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add Manual Tests and fix bug with cancel tests Created 5 years, 5 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/animation/KeyframeEffect.h ('k') | Source/core/animation/KeyframeEffectModel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 ASSERT(animation()->source() == this); 122 ASSERT(animation()->source() == this);
123 animation()->setCompositorPending(true); 123 animation()->setCompositorPending(true);
124 } 124 }
125 } 125 }
126 126
127 static AnimationStack& ensureAnimationStack(Element* element) 127 static AnimationStack& ensureAnimationStack(Element* element)
128 { 128 {
129 return element->ensureElementAnimations().defaultStack(); 129 return element->ensureElementAnimations().defaultStack();
130 } 130 }
131 131
132 bool KeyframeEffect::hasMultipleTransformProperties() const
133 {
134 if (!m_target->computedStyle())
135 return false;
136
137 unsigned transformPropertyCount = 0;
138 if (m_target->computedStyle()->hasTransformOperations())
139 transformPropertyCount++;
140 if (m_target->computedStyle()->rotate())
141 transformPropertyCount++;
142 if (m_target->computedStyle()->scale())
143 transformPropertyCount++;
144 if (m_target->computedStyle()->translate())
145 transformPropertyCount++;
146 return transformPropertyCount > 1;
147 }
148
149 // Returns true if transform, translate, rotate or scale is composited
150 // and a motion path or other transform properties
151 // has been introduced on the element
152 bool KeyframeEffect::hasIncompatibleStyle()
153 {
154 if (!m_target->computedStyle())
155 return false;
156
157 bool affectsTransform = animation()->affects(*m_target, CSSPropertyTransform )
158 || animation()->affects(*m_target, CSSPropertyScale)
159 || animation()->affects(*m_target, CSSPropertyRotate)
160 || animation()->affects(*m_target, CSSPropertyTranslate);
161
162 if (animation()->hasActiveAnimationsOnCompositor()) {
163 if (m_target->computedStyle()->hasMotionPath() && affectsTransform)
164 return true;
165 return hasMultipleTransformProperties();
166 }
167
168 return false;
169 }
170
132 void KeyframeEffect::applyEffects() 171 void KeyframeEffect::applyEffects()
133 { 172 {
134 ASSERT(isInEffect()); 173 ASSERT(isInEffect());
135 ASSERT(animation()); 174 ASSERT(animation());
136 if (!m_target || !m_model) 175 if (!m_target || !m_model)
137 return; 176 return;
138 177
139 // Cancel composited animation of transform if a motion path, translate, 178 if (hasIncompatibleStyle())
140 // rotate or scale operation has been introduced on the element.
141 if (m_target->computedStyle()
142 && (m_target->computedStyle()->hasMotionPath()
143 || m_target->computedStyle()->translate()
144 || m_target->computedStyle()->rotate()
145 || m_target->computedStyle()->scale())
146 && animation()->hasActiveAnimationsOnCompositor()
147 && animation()->affects(*m_target, CSSPropertyTransform)) {
148 animation()->cancelAnimationOnCompositor(); 179 animation()->cancelAnimationOnCompositor();
149 }
150 180
151 double iteration = currentIteration(); 181 double iteration = currentIteration();
152 ASSERT(iteration >= 0); 182 ASSERT(iteration >= 0);
153 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation>>> inte rpolations = m_sampledEffect ? m_sampledEffect->mutableInterpolations() : nullpt r; 183 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation>>> inte rpolations = m_sampledEffect ? m_sampledEffect->mutableInterpolations() : nullpt r;
154 // FIXME: Handle iteration values which overflow int. 184 // FIXME: Handle iteration values which overflow int.
155 m_model->sample(static_cast<int>(iteration), timeFraction(), iterationDurati on(), interpolations); 185 m_model->sample(static_cast<int>(iteration), timeFraction(), iterationDurati on(), interpolations);
156 if (m_sampledEffect) { 186 if (m_sampledEffect) {
157 m_sampledEffect->setInterpolations(interpolations.release()); 187 m_sampledEffect->setInterpolations(interpolations.release());
158 } else if (interpolations && !interpolations->isEmpty()) { 188 } else if (interpolations && !interpolations->isEmpty()) {
159 OwnPtrWillBeRawPtr<SampledEffect> sampledEffect = SampledEffect::create( this, interpolations.release()); 189 OwnPtrWillBeRawPtr<SampledEffect> sampledEffect = SampledEffect::create( this, interpolations.release());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 clearEventDelegate(); 267 clearEventDelegate();
238 SampledEffect* sampledEffect = m_sampledEffect; 268 SampledEffect* sampledEffect = m_sampledEffect;
239 m_sampledEffect = nullptr; 269 m_sampledEffect = nullptr;
240 if (sampledEffect) 270 if (sampledEffect)
241 sampledEffect->clear(); 271 sampledEffect->clear();
242 } 272 }
243 #endif 273 #endif
244 274
245 bool KeyframeEffect::isCandidateForAnimationOnCompositor(double animationPlaybac kRate) const 275 bool KeyframeEffect::isCandidateForAnimationOnCompositor(double animationPlaybac kRate) const
246 { 276 {
277 // Do not put transforms on compositor if more than one of them are defined
278 // in computed style because they need to be explicitly ordered
247 if (!model() 279 if (!model()
248 || !m_target 280 || !m_target
249 || (m_target->computedStyle() && (m_target->computedStyle()->hasMotionPa th() || m_target->computedStyle()->translate() || m_target->computedStyle()->rot ate() || m_target->computedStyle()->scale()))) 281 || (m_target->computedStyle() && m_target->computedStyle()->hasMotionPat h())
282 || hasMultipleTransformProperties())
250 return false; 283 return false;
251 284
252 return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor (specifiedTiming(), *m_target, animation(), *model(), animationPlaybackRate); 285 return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor (specifiedTiming(), *m_target, animation(), *model(), animationPlaybackRate);
253 } 286 }
254 287
255 bool KeyframeEffect::maybeStartAnimationOnCompositor(int group, double startTime , double currentTime, double animationPlaybackRate) 288 bool KeyframeEffect::maybeStartAnimationOnCompositor(int group, double startTime , double currentTime, double animationPlaybackRate)
256 { 289 {
257 ASSERT(!hasActiveAnimationsOnCompositor()); 290 ASSERT(!hasActiveAnimationsOnCompositor());
258 if (!isCandidateForAnimationOnCompositor(animationPlaybackRate)) 291 if (!isCandidateForAnimationOnCompositor(animationPlaybackRate))
259 return false; 292 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 369
337 DEFINE_TRACE(KeyframeEffect) 370 DEFINE_TRACE(KeyframeEffect)
338 { 371 {
339 visitor->trace(m_target); 372 visitor->trace(m_target);
340 visitor->trace(m_model); 373 visitor->trace(m_model);
341 visitor->trace(m_sampledEffect); 374 visitor->trace(m_sampledEffect);
342 AnimationEffect::trace(visitor); 375 AnimationEffect::trace(visitor);
343 } 376 }
344 377
345 } // namespace blink 378 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/animation/KeyframeEffect.h ('k') | Source/core/animation/KeyframeEffectModel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698