Skip to content

Truly independent web browser

LibWeb: Retain custom property interval values after sampling

Callum Lawe6f901115be7
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 0912903f39f..55cea58aa43 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -8624,10 +8624,12 @@ pub(crate) struct CustomPropertyInterval {
pub(crate) cyclic: [bool; 2],
pub(crate) name: crate::css::retained_fly_string::RetainedUtf16FlyString,
pub(crate) declared_values: [RetainedStyleValueData; 2],
+ /// Fresh interval values awaiting cache insertion.
+ pub(crate) values_to_retain: Option<[RetainedStyleValueData; 2]>,
}
impl CustomPropertyInterval {
- fn declaration_indices(&self) -> [usize; 2] {
+ pub(crate) fn declaration_indices(&self) -> [usize; 2] {
self.interval_span.map(|lookup| lookup.declaration_index)
}
}
@@ -8640,6 +8642,7 @@ pub(crate) struct AnimatedCustomProperties {
names: Vec<crate::css::retained_fly_string::RetainedUtf16FlyString>,
units: Vec<Vec<u16>>,
pub(crate) intervals: Vec<CustomPropertyInterval>,
+ pub(crate) registration_generation: u64,
/// Whether any interval values are resolved afresh rather than retained across samples.
pub(crate) has_uncached_interval_values: bool,
}
@@ -8921,6 +8924,7 @@ fn select_contributing_custom_property_intervals(
_ => RetainedStyleValueData::none(),
}
}),
+ values_to_retain: None,
});
}
intervals_by_effect.push(intervals);
@@ -8953,6 +8957,7 @@ pub(crate) fn resolve_published_animation_declarations(
names: Vec::new(),
units: Vec::new(),
intervals: Vec::new(),
+ registration_generation: engine.custom_property_registration_generation(),
has_uncached_interval_values: false,
};
let substitution_marks = std::cell::Cell::new(0_u8);
@@ -9125,7 +9130,7 @@ pub(crate) fn resolve_published_animation_declarations(
});
}
}
- for interval in intervals {
+ for mut interval in intervals {
let name_id = interval.custom_name_id;
let important = custom_properties.is_important(name_id);
let name = custom_properties.units(name_id);
@@ -9155,12 +9160,8 @@ pub(crate) fn resolve_published_animation_declarations(
// SAFETY: The sample keeps the name alive while it is retained for the lookup.
let interned_name = unsafe { ak::Utf16FlyString::from_raw_borrowed(custom_properties.name(name_id).raw()) };
let custom_is_inherited = registry.name_inherits(&interned_name);
- if can_retain_interval_values && !has_retained_values {
- effect.update_retained_custom_property_interval_values(
- interval.declaration_indices(),
- interval_values.clone(),
- );
- }
+ interval.values_to_retain =
+ (can_retain_interval_values && !has_retained_values).then(|| interval_values.clone());
for (lookup, value) in interval.interval_span.into_iter().zip(interval_values) {
let declaration = effect.custom_declaration_at(lookup.declaration_index);
declarations.push(AnimationDeclaration {
@@ -9594,6 +9595,7 @@ mod tests {
names: Vec::new(),
units: Vec::new(),
intervals: Vec::new(),
+ registration_generation: 0,
has_uncached_interval_values: false,
};
diff --git a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
index 6c18a6153fd..c53b8c4ed52 100644
--- a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
@@ -20,7 +20,7 @@ use super::bridge::{
};
use super::tree::StyleNodeID;
use super::weak_pool::WeakPool;
-use crate::css::animation::FfiCompositeOperation;
+use crate::css::animation::{CustomPropertyInterval, FfiCompositeOperation};
use crate::css::custom_properties::CustomPropertyRegistry;
use crate::css::easing::{Easing, FfiEasingDescriptor, FfiEasingKind, FfiLinearEasingPoint};
use crate::css::retained_fly_string::RetainedUtf16FlyString;
@@ -449,11 +449,13 @@ impl PublishedEffect {
}
/// Retain freshly resolved values for an interval.
- pub(crate) fn update_retained_custom_property_interval_values(
- &self,
- declaration_indices: [usize; 2],
- values: [RetainedStyleValueData; 2],
- ) {
+ pub(crate) fn update_retained_custom_property_interval_values(&self, interval: CustomPropertyInterval) {
+ let declaration_indices = interval.declaration_indices();
+
+ let Some(values) = interval.values_to_retain else {
+ return;
+ };
+
self.custom_property_interval_values
.as_ref()
.expect("an effect interpolating custom properties keeps their interval values")
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index ec5ada3256d..ca2ae10e487 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -7375,6 +7375,22 @@ fn finish_animation_sample(
input.custom_property_registration_generation,
);
}
+ assert_eq!(
+ custom_properties.registration_generation,
+ engine.custom_property_registration_generation(),
+ "animation sampling preserves custom property registrations"
+ );
+ let current_effects = described_effects(input, engine);
+ for interval in custom_properties.intervals {
+ let sampled_effect = composed[interval.effect_index].effect;
+ let effect = current_effects
+ .iter()
+ .find(|effect| {
+ effect.identity == sampled_effect.identity && effect.generation == sampled_effect.generation
+ })
+ .expect("a sampled effect remains published with the same generation");
+ effect.update_retained_custom_property_interval_values(interval);
+ }
let rows = retained
.iter()
.map(|(name, value)| FfiAnimatedCustomPropertyResult {