mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: C++ ComputedTimingFunction
uses Rust's timing function calculation
This was made economical by having Rust's computed `easing::TimingFunction` use a fully resolved function for `linear(...)` easing, as per draft resolution from https://github.com/w3c/csswg-drafts/issues/7415 Differential Revision: https://phabricator.services.mozilla.com/D151295
This commit is contained in:
parent
bb0f857dfa
commit
af058e6332
5 changed files with 134 additions and 85 deletions
|
@ -7,31 +7,16 @@
|
|||
use euclid::approxeq::ApproxEq;
|
||||
|
||||
use crate::bezier::Bezier;
|
||||
use crate::piecewise_linear::{PiecewiseLinearFunction, PiecewiseLinearFunctionBuildParameters};
|
||||
use crate::values::computed::{Integer, Number, Percentage};
|
||||
use crate::piecewise_linear::PiecewiseLinearFunction;
|
||||
use crate::values::computed::{Integer, Number};
|
||||
use crate::values::generics::easing::{self, BeforeFlag, StepPosition, TimingKeyword};
|
||||
|
||||
/// A computed timing function.
|
||||
pub type ComputedTimingFunction = easing::TimingFunction<Integer, Number, Percentage>;
|
||||
pub type ComputedTimingFunction = easing::TimingFunction<Integer, Number, PiecewiseLinearFunction>;
|
||||
|
||||
/// An alias of the computed timing function.
|
||||
pub type TimingFunction = ComputedTimingFunction;
|
||||
|
||||
/// A computed linear easing entry.
|
||||
pub type ComputedLinearStop = easing::LinearStop<Number, Percentage>;
|
||||
|
||||
impl ComputedLinearStop {
|
||||
/// Convert this type to entries that can be used to build PiecewiseLinearFunction.
|
||||
pub fn to_piecewise_linear_build_parameters(
|
||||
x: &ComputedLinearStop,
|
||||
) -> PiecewiseLinearFunctionBuildParameters {
|
||||
(
|
||||
x.output,
|
||||
x.input.into_rust().map(|x| x.0),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputedTimingFunction {
|
||||
fn calculate_step_output(
|
||||
steps: i32,
|
||||
|
@ -91,17 +76,7 @@ impl ComputedTimingFunction {
|
|||
TimingFunction::Steps(steps, pos) => {
|
||||
Self::calculate_step_output(*steps, *pos, progress, before_flag)
|
||||
},
|
||||
TimingFunction::LinearFunction(elements) => {
|
||||
// TODO(dshin): For servo, which uses this code path, constructing the function
|
||||
// every time the animation advances seem... expensive.
|
||||
PiecewiseLinearFunction::from_iter(
|
||||
elements
|
||||
.iter()
|
||||
.map(ComputedLinearStop::to_piecewise_linear_build_parameters),
|
||||
)
|
||||
.at(progress as f32)
|
||||
.into()
|
||||
},
|
||||
TimingFunction::LinearFunction(function) => function.at(progress as f32).into(),
|
||||
TimingFunction::Keyword(keyword) => match keyword {
|
||||
TimingKeyword::Linear => return progress,
|
||||
TimingKeyword::Ease => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue