mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #17001 - birtles:accumulative-animation, r=hiro
Support accumulative animation These are the Servo side changes for [Mozilla bug 1353202](https://bugzilla.mozilla.org/show_bug.cgi?id=1353202). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17001) <!-- Reviewable:end -->
This commit is contained in:
commit
7f80d9cb45
6 changed files with 2138 additions and 1619 deletions
|
@ -2940,6 +2940,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_foreignObject: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms12fractalNoiseE"]
|
||||
pub static nsGkAtoms_fractalNoise: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms2frE"]
|
||||
pub static nsGkAtoms_fr: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms2fxE"]
|
||||
pub static nsGkAtoms_fx: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms2fyE"]
|
||||
|
@ -7957,6 +7959,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_foreignObject: *mut nsIAtom;
|
||||
#[link_name = "?fractalNoise@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_fractalNoise: *mut nsIAtom;
|
||||
#[link_name = "?fr@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_fr: *mut nsIAtom;
|
||||
#[link_name = "?fx@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_fx: *mut nsIAtom;
|
||||
#[link_name = "?fy@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
|
@ -12974,6 +12978,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_foreignObject: *mut nsIAtom;
|
||||
#[link_name = "\x01?fractalNoise@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_fractalNoise: *mut nsIAtom;
|
||||
#[link_name = "\x01?fr@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_fr: *mut nsIAtom;
|
||||
#[link_name = "\x01?fx@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_fx: *mut nsIAtom;
|
||||
#[link_name = "\x01?fy@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
|
@ -17994,6 +18000,8 @@ macro_rules! atom {
|
|||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_foreignObject as *mut _) } };
|
||||
("fractalNoise") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_fractalNoise as *mut _) } };
|
||||
("fr") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_fr as *mut _) } };
|
||||
("fx") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_fx as *mut _) } };
|
||||
("fy") =>
|
||||
|
|
|
@ -36,6 +36,7 @@ use gecko_bindings::structs::FontFamilyList;
|
|||
use gecko_bindings::structs::FontFamilyType;
|
||||
use gecko_bindings::structs::FontSizePrefs;
|
||||
use gecko_bindings::structs::GeckoFontMetrics;
|
||||
use gecko_bindings::structs::IterationCompositeOperation;
|
||||
use gecko_bindings::structs::Keyframe;
|
||||
use gecko_bindings::structs::ServoBundledURI;
|
||||
use gecko_bindings::structs::ServoElementSnapshot;
|
||||
|
@ -2261,8 +2262,12 @@ extern "C" {
|
|||
property: nsCSSPropertyID,
|
||||
animation_segment:
|
||||
RawGeckoAnimationPropertySegmentBorrowed,
|
||||
last_segment:
|
||||
RawGeckoAnimationPropertySegmentBorrowed,
|
||||
computed_timing:
|
||||
RawGeckoComputedTimingBorrowed);
|
||||
RawGeckoComputedTimingBorrowed,
|
||||
iteration_composite:
|
||||
IterationCompositeOperation);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_DeclarationBlock_PropertyIsSet(declarations:
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -680,6 +680,15 @@ pub trait Animatable: Sized {
|
|||
self.add_weighted(other, 1.0, 1.0)
|
||||
}
|
||||
|
||||
/// [Accumulates][animation-accumulation] this value onto itself (|count| - 1) times then
|
||||
/// accumulates |other| onto the result.
|
||||
/// If |count| is zero, the result will be |other|.
|
||||
///
|
||||
/// [animation-accumulation]: https://w3c.github.io/web-animations/#animation-accumulation
|
||||
fn accumulate(&self, other: &Self, count: u64) -> Result<Self, ()> {
|
||||
self.add_weighted(other, count as f64, 1.0)
|
||||
}
|
||||
|
||||
/// Compute distance between a value and another for a given property.
|
||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> { Err(()) }
|
||||
|
||||
|
@ -1364,11 +1373,16 @@ impl Animatable for FontWeight {
|
|||
/// https://drafts.csswg.org/css-fonts/#font-stretch-prop
|
||||
impl Animatable for FontStretch {
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||
-> Result<Self, ()>
|
||||
{
|
||||
let from = f64::from(*self);
|
||||
let to = f64::from(*other);
|
||||
let interpolated_mapped_index = ((from * self_portion + to * other_portion) + 0.5).floor();
|
||||
Ok(interpolated_mapped_index.into())
|
||||
let to = f64::from(*other);
|
||||
// FIXME: When `const fn` is available in release rust, make |normal|, below, const.
|
||||
let normal = f64::from(FontStretch::normal);
|
||||
let result = (from - normal) * self_portion + (to - normal) * other_portion + normal;
|
||||
|
||||
Ok(result.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1401,11 +1415,11 @@ impl From<FontStretch> for f64 {
|
|||
impl Into<FontStretch> for f64 {
|
||||
fn into(self) -> FontStretch {
|
||||
use properties::longhands::font_stretch::computed_value::T::*;
|
||||
debug_assert!(self >= 1.0 && self <= 9.0);
|
||||
let index = (self + 0.5).floor().min(9.0).max(1.0);
|
||||
static FONT_STRETCH_ENUM_MAP: [FontStretch; 9] =
|
||||
[ ultra_condensed, extra_condensed, condensed, semi_condensed, normal,
|
||||
semi_expanded, expanded, extra_expanded, ultra_expanded ];
|
||||
FONT_STRETCH_ENUM_MAP[(self - 1.0) as usize]
|
||||
FONT_STRETCH_ENUM_MAP[(index - 1.0) as usize]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1659,6 +1673,21 @@ fn build_identity_transform_list(list: &[TransformOperation]) -> Vec<TransformOp
|
|||
result
|
||||
}
|
||||
|
||||
/// A wrapper for calling add_weighted that interpolates the distance of the two values from
|
||||
/// an initial_value and uses that to produce an interpolated value.
|
||||
/// This is used for values such as 'scale' where the initial value is 1 and where if we interpolate
|
||||
/// the absolute values, we will produce odd results for accumulation.
|
||||
fn add_weighted_with_initial_val<T: Animatable>(a: &T,
|
||||
b: &T,
|
||||
a_portion: f64,
|
||||
b_portion: f64,
|
||||
initial_val: &T) -> Result<T, ()> {
|
||||
let a = try!(a.add_weighted(&initial_val, 1.0, -1.0));
|
||||
let b = try!(b.add_weighted(&initial_val, 1.0, -1.0));
|
||||
let result = try!(a.add_weighted(&b, a_portion, b_portion));
|
||||
result.add_weighted(&initial_val, 1.0, 1.0)
|
||||
}
|
||||
|
||||
/// Add two transform lists.
|
||||
/// http://dev.w3.org/csswg/css-transforms/#interpolation-of-transforms
|
||||
fn add_weighted_transform_lists(from_list: &[TransformOperation],
|
||||
|
@ -1696,9 +1725,12 @@ fn add_weighted_transform_lists(from_list: &[TransformOperation],
|
|||
}
|
||||
(&TransformOperation::Scale(fx, fy, fz),
|
||||
&TransformOperation::Scale(tx, ty, tz)) => {
|
||||
let ix = fx.add_weighted(&tx, self_portion, other_portion).unwrap();
|
||||
let iy = fy.add_weighted(&ty, self_portion, other_portion).unwrap();
|
||||
let iz = fz.add_weighted(&tz, self_portion, other_portion).unwrap();
|
||||
let ix = add_weighted_with_initial_val(&fx, &tx, self_portion,
|
||||
other_portion, &1.0).unwrap();
|
||||
let iy = add_weighted_with_initial_val(&fy, &ty, self_portion,
|
||||
other_portion, &1.0).unwrap();
|
||||
let iz = add_weighted_with_initial_val(&fz, &tz, self_portion,
|
||||
other_portion, &1.0).unwrap();
|
||||
result.push(TransformOperation::Scale(ix, iy, iz));
|
||||
}
|
||||
(&TransformOperation::Rotate(fx, fy, fz, fa),
|
||||
|
@ -1808,10 +1840,12 @@ pub struct MatrixDecomposed2D {
|
|||
impl Animatable for InnerMatrix2D {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
Ok(InnerMatrix2D {
|
||||
m11: try!(self.m11.add_weighted(&other.m11, self_portion, other_portion)),
|
||||
m11: try!(add_weighted_with_initial_val(&self.m11, &other.m11,
|
||||
self_portion, other_portion, &1.0)),
|
||||
m12: try!(self.m12.add_weighted(&other.m12, self_portion, other_portion)),
|
||||
m21: try!(self.m21.add_weighted(&other.m21, self_portion, other_portion)),
|
||||
m22: try!(self.m22.add_weighted(&other.m22, self_portion, other_portion)),
|
||||
m22: try!(add_weighted_with_initial_val(&self.m22, &other.m22,
|
||||
self_portion, other_portion, &1.0)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1828,8 +1862,8 @@ impl Animatable for Translate2D {
|
|||
impl Animatable for Scale2D {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
Ok(Scale2D(
|
||||
try!(self.0.add_weighted(&other.0, self_portion, other_portion)),
|
||||
try!(self.1.add_weighted(&other.1, self_portion, other_portion))
|
||||
try!(add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)),
|
||||
try!(add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -2229,9 +2263,9 @@ impl Animatable for Translate3D {
|
|||
impl Animatable for Scale3D {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
Ok(Scale3D(
|
||||
try!(self.0.add_weighted(&other.0, self_portion, other_portion)),
|
||||
try!(self.1.add_weighted(&other.1, self_portion, other_portion)),
|
||||
try!(self.2.add_weighted(&other.2, self_portion, other_portion))
|
||||
try!(add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)),
|
||||
try!(add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0)),
|
||||
try!(add_weighted_with_initial_val(&self.2, &other.2, self_portion, other_portion, &1.0))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -2252,7 +2286,7 @@ impl Animatable for Perspective {
|
|||
try!(self.0.add_weighted(&other.0, self_portion, other_portion)),
|
||||
try!(self.1.add_weighted(&other.1, self_portion, other_portion)),
|
||||
try!(self.2.add_weighted(&other.2, self_portion, other_portion)),
|
||||
try!(self.3.add_weighted(&other.3, self_portion, other_portion))
|
||||
try!(add_weighted_with_initial_val(&self.3, &other.3, self_portion, other_portion, &1.0))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -2261,8 +2295,9 @@ impl Animatable for MatrixDecomposed3D {
|
|||
/// https://drafts.csswg.org/css-transforms/#interpolation-of-decomposed-3d-matrix-values
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||
-> Result<Self, ()> {
|
||||
assert!(self_portion + other_portion == 1.0f64,
|
||||
"add_weighted should only be used for interpolating transforms");
|
||||
assert!(self_portion + other_portion == 1.0f64 ||
|
||||
other_portion == 1.0f64,
|
||||
"add_weighted should only be used for interpolating or accumulating transforms");
|
||||
|
||||
let mut sum = *self;
|
||||
|
||||
|
@ -2275,30 +2310,63 @@ impl Animatable for MatrixDecomposed3D {
|
|||
self_portion, other_portion));
|
||||
|
||||
// Add quaternions using spherical linear interpolation (Slerp).
|
||||
let mut product = self.quaternion.0 * other.quaternion.0 +
|
||||
self.quaternion.1 * other.quaternion.1 +
|
||||
self.quaternion.2 * other.quaternion.2 +
|
||||
self.quaternion.3 * other.quaternion.3;
|
||||
//
|
||||
// We take a specialized code path for accumulation (where other_portion is 1)
|
||||
if other_portion == 1.0 {
|
||||
if self_portion == 0.0 {
|
||||
return Ok(*other)
|
||||
}
|
||||
|
||||
// Clamp product to -1.0 <= product <= 1.0
|
||||
product = product.min(1.0);
|
||||
product = product.max(-1.0);
|
||||
let clamped_w = self.quaternion.3.min(1.0).max(-1.0);
|
||||
|
||||
if product == 1.0 {
|
||||
return Ok(sum);
|
||||
// Determine the scale factor.
|
||||
let mut theta = clamped_w.acos();
|
||||
let mut scale = if theta == 0.0 { 0.0 } else { 1.0 / theta.sin() };
|
||||
theta *= self_portion as f32;
|
||||
scale *= theta.sin();
|
||||
|
||||
// Scale the self matrix by self_portion.
|
||||
let mut scaled_self = *self;
|
||||
% for i in range(3):
|
||||
scaled_self.quaternion.${i} *= scale;
|
||||
% endfor
|
||||
scaled_self.quaternion.3 = theta.cos();
|
||||
|
||||
// Multiply scaled-self by other.
|
||||
let a = &scaled_self.quaternion;
|
||||
let b = &other.quaternion;
|
||||
sum.quaternion = Quaternion(
|
||||
a.3 * b.0 + a.0 * b.3 + a.1 * b.2 - a.2 * b.1,
|
||||
a.3 * b.1 - a.0 * b.2 + a.1 * b.3 + a.2 * b.0,
|
||||
a.3 * b.2 + a.0 * b.1 - a.1 * b.0 + a.2 * b.3,
|
||||
a.3 * b.3 - a.0 * b.0 - a.1 * b.1 - a.2 * b.2,
|
||||
);
|
||||
} else {
|
||||
let mut product = self.quaternion.0 * other.quaternion.0 +
|
||||
self.quaternion.1 * other.quaternion.1 +
|
||||
self.quaternion.2 * other.quaternion.2 +
|
||||
self.quaternion.3 * other.quaternion.3;
|
||||
|
||||
// Clamp product to -1.0 <= product <= 1.0
|
||||
product = product.min(1.0);
|
||||
product = product.max(-1.0);
|
||||
|
||||
if product == 1.0 {
|
||||
return Ok(sum);
|
||||
}
|
||||
|
||||
let theta = product.acos();
|
||||
let w = (other_portion as f32 * theta).sin() * 1.0 / (1.0 - product * product).sqrt();
|
||||
|
||||
let mut a = *self;
|
||||
let mut b = *other;
|
||||
% for i in range(4):
|
||||
a.quaternion.${i} *= (other_portion as f32 * theta).cos() - product * w;
|
||||
b.quaternion.${i} *= w;
|
||||
sum.quaternion.${i} = a.quaternion.${i} + b.quaternion.${i};
|
||||
% endfor
|
||||
}
|
||||
|
||||
let theta = product.acos();
|
||||
let w = (other_portion as f32 * theta).sin() * 1.0 / (1.0 - product * product).sqrt();
|
||||
|
||||
let mut a = *self;
|
||||
let mut b = *other;
|
||||
% for i in range(4):
|
||||
a.quaternion.${i} *= (other_portion as f32 * theta).cos() - product * w;
|
||||
b.quaternion.${i} *= w;
|
||||
sum.quaternion.${i} = a.quaternion.${i} + b.quaternion.${i};
|
||||
% endfor
|
||||
|
||||
Ok(sum)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue