From cf4510011fb4bf1ea8f95b7b0874aa952ae99e44 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Wed, 24 Jun 2020 16:19:36 +0200 Subject: [PATCH] animations: Don't convert linear easing to a bezier This conversion can lead to floating point errors and extra work when computing animations. Avoiding it allows animation-iteration-count-009.html to pass. --- components/style/animation.rs | 14 +++++++++++--- components/style/values/generics/easing.rs | 16 ---------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/components/style/animation.rs b/components/style/animation.rs index 6632ce856b7e..57ce98141a71 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -27,7 +27,9 @@ use crate::stylesheets::keyframes_rule::{KeyframesAnimation, KeyframesStep, Keyf use crate::values::animated::{Animate, Procedure}; use crate::values::computed::{Time, TimingFunction}; use crate::values::generics::box_::AnimationIterationCount; -use crate::values::generics::easing::{StepPosition, TimingFunction as GenericTimingFunction}; +use crate::values::generics::easing::{ + StepPosition, TimingFunction as GenericTimingFunction, TimingKeyword, +}; use crate::Atom; use fxhash::FxHashMap; use parking_lot::RwLock; @@ -125,8 +127,14 @@ impl PropertyAnimation { (current_step as f64) / (jumps as f64) }, GenericTimingFunction::Keyword(keyword) => { - let (x1, x2, y1, y2) = keyword.to_bezier(); - Bezier::new(x1, x2, y1, y2).solve(progress, epsilon) + let bezier = match keyword { + TimingKeyword::Linear => return progress, + TimingKeyword::Ease => Bezier::new(0.25, 0.1, 0.25, 1.), + TimingKeyword::EaseIn => Bezier::new(0.42, 0., 1., 1.), + TimingKeyword::EaseOut => Bezier::new(0., 0., 0.58, 1.), + TimingKeyword::EaseInOut => Bezier::new(0.42, 0., 0.58, 1.), + }; + bezier.solve(progress, epsilon) }, } } diff --git a/components/style/values/generics/easing.rs b/components/style/values/generics/easing.rs index b234b6a54e00..02c8d3485470 100644 --- a/components/style/values/generics/easing.rs +++ b/components/style/values/generics/easing.rs @@ -6,7 +6,6 @@ //! https://drafts.csswg.org/css-easing/#timing-functions use crate::parser::ParserContext; -use crate::values::CSSFloat; /// A generic easing function. #[derive( @@ -118,18 +117,3 @@ impl TimingFunction { TimingFunction::Keyword(TimingKeyword::Ease) } } - -impl TimingKeyword { - /// Returns the keyword as a quadruplet of Bezier point coordinates - /// `(x1, y1, x2, y2)`. - #[inline] - pub fn to_bezier(self) -> (CSSFloat, CSSFloat, CSSFloat, CSSFloat) { - match self { - TimingKeyword::Linear => (0., 0., 1., 1.), - TimingKeyword::Ease => (0.25, 0.1, 0.25, 1.), - TimingKeyword::EaseIn => (0.42, 0., 1., 1.), - TimingKeyword::EaseOut => (0., 0., 0.58, 1.), - TimingKeyword::EaseInOut => (0.42, 0., 0.58, 1.), - } - } -}