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

Side by Side Diff: Source/core/animation/css/CSSAnimations.cpp

Issue 110123005: Web Animations CSS: Record if style recalc is for animation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Ignore new interrupted immediately test when testing legacy animations engine Created 7 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
« no previous file with comments | « Source/core/animation/css/CSSAnimations.h ('k') | Source/core/dom/Element.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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 RefPtr<Player> player = element->document().transitionTimeline()->create Player(transition.get()); 512 RefPtr<Player> player = element->document().transitionTimeline()->create Player(transition.get());
513 player->update(); 513 player->update();
514 element->document().cssPendingAnimations().add(player.get()); 514 element->document().cssPendingAnimations().add(player.get());
515 runningTransition.transition = transition.get(); 515 runningTransition.transition = transition.get();
516 m_transitions.set(id, runningTransition); 516 m_transitions.set(id, runningTransition);
517 ASSERT(id != CSSPropertyInvalid); 517 ASSERT(id != CSSPropertyInvalid);
518 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); 518 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id));
519 } 519 }
520 } 520 }
521 521
522 void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const CSSAnimationData* anim, const RenderStyle& oldStyle, const RenderStyle& style, const TransitionMap* activeTransitions, CSSAnimationUpdate* update) 522 void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const CSSAnimationData* anim, const RenderStyle& oldStyle, const RenderStyle& style, const TransitionMap* activeTransitions, CSSAnimationUpdate* update, const Elemen t* element)
523 { 523 {
524 if (CSSPropertyAnimation::propertiesEqual(id, &oldStyle, &style)) 524 RefPtr<AnimatableValue> to;
525 return;
526
527 RefPtr<AnimatableValue> to = CSSAnimatableValueFactory::create(id, style);
528
529 if (activeTransitions) { 525 if (activeTransitions) {
530 TransitionMap::const_iterator activeTransitionIter = activeTransitions-> find(id); 526 TransitionMap::const_iterator activeTransitionIter = activeTransitions-> find(id);
531 if (activeTransitionIter != activeTransitions->end()) { 527 if (activeTransitionIter != activeTransitions->end()) {
528 to = CSSAnimatableValueFactory::create(id, style);
532 const AnimatableValue* activeTo = activeTransitionIter->value.to; 529 const AnimatableValue* activeTo = activeTransitionIter->value.to;
533 if (to->equals(activeTo)) 530 if (to->equals(activeTo))
534 return; 531 return;
535 update->cancelTransition(id); 532 update->cancelTransition(id);
533 ASSERT(!element->activeAnimations() || !element->activeAnimations()- >isAnimationStyleChange());
536 } 534 }
537 } 535 }
536 if (CSSPropertyAnimation::propertiesEqual(id, &oldStyle, &style))
537 return;
538 if (!to)
539 to = CSSAnimatableValueFactory::create(id, style);
538 540
539 RefPtr<AnimatableValue> from = CSSAnimatableValueFactory::create(id, oldStyl e); 541 RefPtr<AnimatableValue> from = CSSAnimatableValueFactory::create(id, oldStyl e);
540 // If we have multiple transitions on the same property, we will use the 542 // If we have multiple transitions on the same property, we will use the
541 // last one since we iterate over them in order. 543 // last one since we iterate over them in order.
542 if (AnimatableValue::usesDefaultInterpolation(to.get(), from.get())) 544 if (AnimatableValue::usesDefaultInterpolation(to.get(), from.get()))
543 return; 545 return;
544 546
545 KeyframeAnimationEffect::KeyframeVector keyframes; 547 KeyframeAnimationEffect::KeyframeVector keyframes;
546 548
547 RefPtr<Keyframe> startKeyframe = Keyframe::create(); 549 RefPtr<Keyframe> startKeyframe = Keyframe::create();
(...skipping 10 matching lines...) Expand all
558 560
559 Timing timing; 561 Timing timing;
560 bool isPaused; 562 bool isPaused;
561 RefPtr<TimingFunction> timingFunction = timingFromAnimationData(anim, timing , isPaused); 563 RefPtr<TimingFunction> timingFunction = timingFromAnimationData(anim, timing , isPaused);
562 ASSERT(!isPaused); 564 ASSERT(!isPaused);
563 timing.timingFunction = timingFunction; 565 timing.timingFunction = timingFunction;
564 // Note that the backwards part is required for delay to work. 566 // Note that the backwards part is required for delay to work.
565 timing.fillMode = Timing::FillModeBoth; 567 timing.fillMode = Timing::FillModeBoth;
566 568
567 update->startTransition(id, from.get(), to.get(), InertAnimation::create(eff ect, timing, isPaused)); 569 update->startTransition(id, from.get(), to.get(), InertAnimation::create(eff ect, timing, isPaused));
570 ASSERT(!element->activeAnimations() || !element->activeAnimations()->isAnima tionStyleChange());
568 } 571 }
569 572
570 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const Element* element, const RenderStyle& style) 573 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const Element* element, const RenderStyle& style)
571 { 574 {
572 ActiveAnimations* activeAnimations = element->activeAnimations(); 575 ActiveAnimations* activeAnimations = element->activeAnimations();
573 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation s->cssAnimations().m_transitions : 0; 576 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation s->cssAnimations().m_transitions : 0;
574 577
578 #if ASSERT_DISABLED
579 // In release builds we avoid the cost of checking for new and interrupted t ransitions if the style recalc is due to animation.
580 const bool animationStyleRecalc = activeAnimations && activeAnimations->isAn imationStyleChange();
581 #else
582 // In debug builds we verify that it would have been safe to avoid populatin g and testing listedProperties if the style recalc is due to animation.
583 const bool animationStyleRecalc = false;
584 #endif
585
575 BitArray<numCSSProperties> listedProperties; 586 BitArray<numCSSProperties> listedProperties;
576 bool anyTransitionHadAnimateAll = false; 587 bool anyTransitionHadAnimateAll = false;
577 const RenderObject* renderer = element->renderer(); 588 const RenderObject* renderer = element->renderer();
578 if (style.display() != NONE && renderer && renderer->style() && style.transi tions()) { 589 if (!animationStyleRecalc && style.display() != NONE && renderer && renderer ->style() && style.transitions()) {
579 const RenderStyle& oldStyle = *renderer->style(); 590 const RenderStyle& oldStyle = *renderer->style();
580 591
581 for (size_t i = 0; i < style.transitions()->size(); ++i) { 592 for (size_t i = 0; i < style.transitions()->size(); ++i) {
582 const CSSAnimationData* anim = style.transitions()->animation(i); 593 const CSSAnimationData* anim = style.transitions()->animation(i);
583 CSSAnimationData::AnimationMode mode = anim->animationMode(); 594 CSSAnimationData::AnimationMode mode = anim->animationMode();
584 if (anim->duration() + anim->delay() <= 0 || mode == CSSAnimationDat a::AnimateNone) 595 if (anim->duration() + anim->delay() <= 0 || mode == CSSAnimationDat a::AnimateNone)
585 continue; 596 continue;
586 597
587 bool animateAll = mode == CSSAnimationData::AnimateAll; 598 bool animateAll = mode == CSSAnimationData::AnimateAll;
588 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty ); 599 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty );
589 if (animateAll) 600 if (animateAll)
590 anyTransitionHadAnimateAll = true; 601 anyTransitionHadAnimateAll = true;
591 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati ons::animatableProperties() : shorthandForProperty(anim->property()); 602 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati ons::animatableProperties() : shorthandForProperty(anim->property());
592 // If not a shorthand we only execute one iteration of this loop, an d refer to the property directly. 603 // If not a shorthand we only execute one iteration of this loop, an d refer to the property directly.
593 for (unsigned j = 0; !j || j < propertyList.length(); ++j) { 604 for (unsigned j = 0; !j || j < propertyList.length(); ++j) {
594 CSSPropertyID id = propertyList.length() ? propertyList.properti es()[j] : anim->property(); 605 CSSPropertyID id = propertyList.length() ? propertyList.properti es()[j] : anim->property();
595 606
596 if (!animateAll) { 607 if (!animateAll) {
597 if (CSSAnimations::isAnimatableProperty(id)) 608 if (CSSAnimations::isAnimatableProperty(id))
598 listedProperties.set(id); 609 listedProperties.set(id);
599 else 610 else
600 continue; 611 continue;
601 } 612 }
602 613
603 // FIXME: We should transition if an !important property changes even when an animation is running, 614 // FIXME: We should transition if an !important property changes even when an animation is running,
604 // but this is a bit hard to do with the current applyMatchedPro perties system. 615 // but this is a bit hard to do with the current applyMatchedPro perties system.
605 if (!update->compositableValuesForAnimations().contains(id) 616 if (!update->compositableValuesForAnimations().contains(id)
606 && (!activeAnimations || !activeAnimations->cssAnimations(). m_previousCompositableValuesForAnimations.contains(id))) { 617 && (!activeAnimations || !activeAnimations->cssAnimations(). m_previousCompositableValuesForAnimations.contains(id))) {
607 calculateTransitionUpdateForProperty(id, anim, oldStyle, sty le, activeTransitions, update); 618 calculateTransitionUpdateForProperty(id, anim, oldStyle, sty le, activeTransitions, update, element);
608 } 619 }
609 } 620 }
610 } 621 }
611 } 622 }
612 623
613 if (activeTransitions) { 624 if (activeTransitions) {
614 for (TransitionMap::const_iterator iter = activeTransitions->begin(); it er != activeTransitions->end(); ++iter) { 625 for (TransitionMap::const_iterator iter = activeTransitions->begin(); it er != activeTransitions->end(); ++iter) {
615 const TimedItem* timedItem = iter->value.transition; 626 const TimedItem* timedItem = iter->value.transition;
616 CSSPropertyID id = iter->key; 627 CSSPropertyID id = iter->key;
617 if (timedItem->phase() == TimedItem::PhaseAfter || (!anyTransitionHa dAnimateAll && !listedProperties.get(id))) 628 if (timedItem->phase() == TimedItem::PhaseAfter || (!anyTransitionHa dAnimateAll && !animationStyleRecalc && !listedProperties.get(id))) {
629 ASSERT(timedItem->phase() == TimedItem::PhaseAfter || !(activeAn imations && activeAnimations->isAnimationStyleChange()));
618 update->cancelTransition(id); 630 update->cancelTransition(id);
631 }
619 } 632 }
620 } 633 }
621 } 634 }
622 635
623 void CSSAnimations::cancel() 636 void CSSAnimations::cancel()
624 { 637 {
625 for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animation s.end(); ++iter) { 638 for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animation s.end(); ++iter) {
626 const HashSet<RefPtr<Player> >& players = iter->value; 639 const HashSet<RefPtr<Player> >& players = iter->value;
627 for (HashSet<RefPtr<Player> >::const_iterator animationsIter = players.b egin(); animationsIter != players.end(); ++animationsIter) 640 for (HashSet<RefPtr<Player> >::const_iterator animationsIter = players.b egin(); animationsIter != players.end(); ++animationsIter)
628 (*animationsIter)->cancel(); 641 (*animationsIter)->cancel();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 CSSPropertyID id = convertToCSSPropertyID(i); 893 CSSPropertyID id = convertToCSSPropertyID(i);
881 if (isAnimatableProperty(id)) 894 if (isAnimatableProperty(id))
882 properties.append(id); 895 properties.append(id);
883 } 896 }
884 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size()); 897 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size());
885 } 898 }
886 return propertyShorthand; 899 return propertyShorthand;
887 } 900 }
888 901
889 } // namespace WebCore 902 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/css/CSSAnimations.h ('k') | Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698