Skip to content

Truly independent web browser

LibWeb: Pass animation samples between Rust functions as Rust types

Andreas Klingbc2399004427
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 817cb7e18b6..2c0e78b6be6 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -11,9 +11,7 @@
use std::sync::Arc;
-use crate::css::easing::{
- Easing, FfiEasingDescriptor, FfiEasingKind, FfiLinearEasingPoint, evaluate_easing_descriptor,
-};
+use crate::css::easing::{Easing, FfiEasingDescriptor, FfiLinearEasingPoint, evaluate_easing_descriptor};
use crate::css::property_metadata::{property_animation_type, property_numeric_ranges};
use crate::css::style_value::{
BasicShapeData, ColorBase, CssString, CssStringList, FILTER_KIND_BLUR, FILTER_KIND_COLOR, FILTER_KIND_DROP_SHADOW,
@@ -125,6 +123,7 @@ impl AnimationValueResult {
/// The descriptor and its control-point slice must remain valid during the call.
#[cfg(test)]
pub(crate) unsafe fn style_value_from_easing(descriptor: &FfiEasingDescriptor) -> *const StyleValueData {
+ use crate::css::easing::FfiEasingKind;
use crate::css::style_value::{RetainedLinearEasingStop, RetainedLinearEasingStopList};
let retain = |value| RetainedStyleValueData::from_arc(Arc::new(value));
let mut stops = Vec::new();
@@ -245,9 +244,9 @@ pub struct FfiAnimationLengthResolutionContext {
#[derive(Clone, Copy)]
#[repr(C)]
-pub struct FfiAnimationContext {
+pub struct FfiAnimationContext<'a> {
pub allow_discrete: bool,
- pub current_color: *const StyleValueData,
+ pub current_color: Option<&'a RetainedStyleValueData>,
pub has_length_resolution_context: bool,
pub length_resolution_context: FfiAnimationLengthResolutionContext,
pub has_transform_reference_box: bool,
@@ -255,7 +254,7 @@ pub struct FfiAnimationContext {
pub transform_reference_box_height: f64,
}
-impl FfiAnimationContext {
+impl FfiAnimationContext<'_> {
/// Has transforms interpolate against `reference_box`, where there is one.
pub(crate) fn set_transform_reference_box(&mut self, reference_box: Option<crate::css::css_pixels::CssPixelRect>) {
if let Some(reference_box) = reference_box {
@@ -266,24 +265,24 @@ impl FfiAnimationContext {
}
}
-#[repr(C)]
-pub struct FfiAnimationKeyframeValue {
- pub key: i64,
- pub value: *const StyleValueData,
- pub easing: FfiEasingDescriptor,
- pub composite: FfiCompositeOperation,
+/// One of the property-specific keyframes an animated value interpolates between.
+struct AnimationKeyframeValue {
+ /// The keyframe, by its index among the keyframe plans.
+ keyframe: usize,
+ /// The keyframe's computed value, or none where the keyframe leaves the property out.
+ value: RetainedStyleValueData,
}
-#[repr(C)]
-pub struct FfiAnimationValueInput {
- pub property_id: u16,
- pub custom_name_id: u32,
- pub result_of_transition: bool,
- pub underlying: *const StyleValueData,
- pub initial: *const StyleValueData,
- pub current_key: f64,
- pub keyframes: *const FfiAnimationKeyframeValue,
- pub keyframe_count: usize,
+struct AnimationValueInput<'a> {
+ property_id: u16,
+ custom_name_id: u32,
+ result_of_transition: bool,
+ underlying: Option<&'a StyleValueData>,
+ initial: Option<&'a StyleValueData>,
+ current_key: f64,
+ keyframes: &'a [AnimationKeyframeValue],
+ /// The keyframes the values' indices name.
+ keyframe_plans: &'a [AnimationKeyframePlan],
}
/// The version of an effect a preparation was made from.
@@ -303,34 +302,33 @@ pub struct FfiSampledAnimationEffect {
pub current_key: f64,
}
-#[repr(C)]
-pub struct FfiComputedAnimationBatch {
- pub context: FfiAnimationContext,
- pub sampled_effects: *const FfiSampledAnimationEffect,
- pub sampled_effect_count: usize,
+/// The declarations an element's effects resolved to, and the computed value of each, which a
+/// preparation is made from.
+pub(crate) struct AnimationPreparationInputs {
+ pub(crate) resolved: Box<ResolvedAnimationDeclarations>,
+ /// One computed value per resolved property.
+ pub(crate) computed_keyframe_values: Vec<RetainedStyleValueData>,
+}
+
+pub(crate) struct ComputedAnimationBatch<'a> {
+ pub(crate) context: FfiAnimationContext<'a>,
+ pub(crate) sampled_effects: &'a [FfiSampledAnimationEffect],
/// The identities of the custom-property environments of the element and of the one it
/// inherits from, which a preparation that substituted keyframe values against the element was
/// made under.
- pub custom_property_environments: [u64; 2],
- pub cache_preparation: bool,
+ pub(crate) custom_property_environments: [u64; 2],
+ pub(crate) cache_preparation: bool,
/// Whether the preparation substituted keyframe values against the element, so that it holds
/// only under the custom-property environments its key names.
- pub preparation_reads_custom_property_environments: bool,
- pub resolved_animation_storage: *mut std::ffi::c_void,
- pub computed_keyframe_storage: *mut std::ffi::c_void,
- pub underlying_longhand_table: *const std::ffi::c_void,
- pub overlay: *mut std::ffi::c_void,
- pub custom_underlying_values: *const *const StyleValueData,
- pub custom_initial_values: *const *const StyleValueData,
- pub custom_value_count: usize,
- pub custom_results: *mut FfiAnimatedCustomProperty,
- pub custom_result_count: *mut usize,
-}
-
-#[repr(C)]
-pub struct FfiAnimatedCustomProperty {
- pub custom_name_id: u32,
- pub value: *const StyleValueData,
+ pub(crate) preparation_reads_custom_property_environments: bool,
+ /// What a preparation is made from where the overlay holds none for the sampled effects.
+ pub(crate) preparation_inputs: Option<AnimationPreparationInputs>,
+ pub(crate) underlying_longhand_table: &'a crate::css::computed_longhand_table::ComputedLonghandTable,
+ pub(crate) overlay: &'a mut crate::css::animated_overlay::AnimatedOverlay,
+ /// What an animation of each custom property composes over, and what a keyframe saying
+ /// `initial` takes, indexed by the number the property animates under, less one.
+ pub(crate) custom_underlying_values: &'a [RetainedStyleValueData],
+ pub(crate) custom_initial_values: &'a [RetainedStyleValueData],
}
#[repr(C)]
@@ -341,13 +339,6 @@ pub struct FfiAnimationEffect {
pub result_of_transition: bool,
}
-#[repr(C)]
-pub struct FfiAnimationKeyframe {
- pub key: i64,
- pub easing: FfiEasingDescriptor,
- pub composite: FfiCompositeOperation,
-}
-
/// One animated property's effect value, and whether it applies at all.
struct AnimatedProperty {
value: Option<RetainedStyleValueData>,
@@ -379,17 +370,16 @@ impl FfiAnimationStyleSheetResourceContext {
}
}
-#[repr(C)]
-pub struct FfiAnimationDeclaration {
- pub keyframe_index: usize,
- pub property_id: u16,
- pub custom_name_id: u32,
- pub custom_is_inherited: bool,
- pub custom_is_important: bool,
- pub value: *const StyleValueData,
- pub style_sheet_resource_context: FfiAnimationStyleSheetResourceContext,
- pub use_initial: bool,
- pub is_transition: bool,
+struct AnimationDeclaration {
+ keyframe_index: usize,
+ property_id: u16,
+ custom_name_id: u32,
+ custom_is_inherited: bool,
+ custom_is_important: bool,
+ value: RetainedStyleValueData,
+ style_sheet_resource_context: FfiAnimationStyleSheetResourceContext,
+ use_initial: bool,
+ is_transition: bool,
}
struct AnimationPropertyConflictCandidate {
@@ -513,16 +503,15 @@ fn resolve_animation_property_conflicts(
}
}
-#[repr(C)]
-pub struct FfiResolvedAnimationProperty {
- pub keyframe_index: usize,
- pub physical_property_id: u16,
- pub custom_name_id: u32,
- pub source_longhand_id: u16,
- pub value: *const StyleValueData,
- pub value_source: FfiAnimationSpecifiedValueSource,
- pub style_sheet_resource_context: FfiAnimationStyleSheetResourceContext,
- pub is_transition: bool,
+pub(crate) struct ResolvedAnimationProperty {
+ pub(crate) keyframe_index: usize,
+ pub(crate) physical_property_id: u16,
+ pub(crate) custom_name_id: u32,
+ pub(crate) source_longhand_id: u16,
+ pub(crate) value: RetainedStyleValueData,
+ pub(crate) value_source: FfiAnimationSpecifiedValueSource,
+ pub(crate) style_sheet_resource_context: FfiAnimationStyleSheetResourceContext,
+ pub(crate) is_transition: bool,
}
/// The `SUBSTITUTION_MARK_*` bits of the arbitrary-substitution functions a written value holds.
@@ -554,17 +543,18 @@ fn substitution_marks_of(written: &StyleValueData) -> u8 {
.fold(0, |marks, (_, mark)| marks | mark)
}
-#[repr(C)]
-pub struct FfiAnimationUnfixedRandomSharing {
- pub source: *const StyleValueData,
- pub name: *const std::ffi::c_void,
- pub element_shared: bool,
+/// A random function's sharing value whose base value the element or document draws.
+pub(crate) struct AnimationUnfixedRandomSharing {
+ /// The sharing value, which keys its base value.
+ pub(crate) source: *const StyleValueData,
+ pub(crate) name: Vec<u16>,
+ pub(crate) element_shared: bool,
}
fn resolve_animation_declarations(
- declarations: &[FfiAnimationDeclaration],
+ declarations: &[AnimationDeclaration],
effects: &[FfiAnimationEffect],
- keyframes: &[FfiAnimationKeyframe],
+ keyframes: Vec<AnimationKeyframePlan>,
writing_mode: u8,
direction: u8,
important_property_bitmap: &[u8],
@@ -572,7 +562,7 @@ fn resolve_animation_declarations(
let mut candidates = Vec::new();
for declaration in declarations {
assert!(
- !declaration.value.is_null(),
+ declaration.value.optional_data().is_some(),
"animation declaration value must not be null"
);
if declaration.custom_name_id != 0 {
@@ -583,11 +573,7 @@ fn resolve_animation_declarations(
custom_is_inherited: declaration.custom_is_inherited,
source_property_id: declaration.property_id,
source_longhand_id: declaration.property_id,
- value: unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- declaration.value.cast(),
- ))
- },
+ value: declaration.value.clone(),
style_sheet_resource_context: declaration.style_sheet_resource_context,
use_initial: declaration.use_initial,
is_transition: declaration.is_transition,
@@ -597,7 +583,7 @@ fn resolve_animation_declarations(
}
crate::css::style_compute::expand_shorthands_with(
declaration.property_id,
- declaration.value.cast(),
+ declaration.value.pointer().cast(),
false,
&mut |longhand_id, data, _| {
let physical_property_id =
@@ -634,20 +620,18 @@ fn resolve_animation_declarations(
let mut value_sources = vec![FfiAnimationSpecifiedValueSource::Value; candidates.len()];
resolve_animation_property_conflicts(&candidates, &mut selected, &mut value_sources);
let mut properties = Vec::new();
- let mut retained_values = Vec::new();
for ((candidate, selected), value_source) in candidates.into_iter().zip(selected).zip(value_sources) {
if selected && !candidate.suppressed_by_important {
- properties.push(FfiResolvedAnimationProperty {
+ properties.push(ResolvedAnimationProperty {
keyframe_index: candidate.keyframe_index,
physical_property_id: candidate.physical_property_id,
custom_name_id: candidate.custom_name_id,
source_longhand_id: candidate.source_longhand_id,
- value: candidate.value.pointer(),
+ value: candidate.value,
value_source,
style_sheet_resource_context: candidate.style_sheet_resource_context,
is_transition: candidate.is_transition,
});
- retained_values.push(candidate.value);
}
}
let mut value_plans = Vec::new();
@@ -697,7 +681,7 @@ fn resolve_animation_declarations(
if property.custom_name_id != 0 {
continue;
}
- let value = unsafe { &*property.value };
+ let value = property.value.data();
if matches!(
value,
StyleValueData::Unresolved { .. } | StyleValueData::PendingSubstitution { .. }
@@ -719,17 +703,16 @@ fn resolve_animation_declarations(
let StyleValueData::RandomValueSharing { has_name, name, .. } = sharing else {
unreachable!();
};
- FfiAnimationUnfixedRandomSharing {
+ AnimationUnfixedRandomSharing {
source,
- name: if *has_name { name.as_ptr() } else { std::ptr::null() },
+ name: if *has_name { name.units().to_vec() } else { Vec::new() },
element_shared: crate::css::style_compute::random_caching_key(sharing).1,
}
})
.collect();
ResolvedAnimationDeclarations {
properties,
- _retained_values: retained_values,
- keyframes: keyframes.iter().map(AnimationKeyframePlan::from_ffi).collect(),
+ keyframes,
value_plans,
uses_tree_counting_function,
container_relative_length_unit_mask,
@@ -743,8 +726,7 @@ fn resolve_animation_declarations(
/// interpolates.
#[derive(Default)]
pub(crate) struct ResolvedAnimationDeclarations {
- pub(crate) properties: Vec<FfiResolvedAnimationProperty>,
- _retained_values: Vec<RetainedStyleValueData>,
+ pub(crate) properties: Vec<ResolvedAnimationProperty>,
/// The base URLs the properties' resource contexts point into.
_base_urls: Vec<std::sync::Arc<[u8]>>,
keyframes: Vec<AnimationKeyframePlan>,
@@ -752,7 +734,7 @@ pub(crate) struct ResolvedAnimationDeclarations {
pub(crate) uses_tree_counting_function: bool,
pub(crate) container_relative_length_unit_mask: u8,
pub(crate) needs_document_base_url: bool,
- pub(crate) unfixed_random_sharings: Vec<FfiAnimationUnfixedRandomSharing>,
+ pub(crate) unfixed_random_sharings: Vec<AnimationUnfixedRandomSharing>,
}
struct AnimationValuePlan {
@@ -765,55 +747,10 @@ struct AnimationValuePlan {
struct AnimationKeyframePlan {
key: i64,
- easing_kind: FfiEasingKind,
- linear_points: Vec<FfiLinearEasingPoint>,
- x1: f64,
- y1: f64,
- x2: f64,
- y2: f64,
- interval_count: i32,
- step_position: u8,
+ easing: Easing,
composite: FfiCompositeOperation,
}
-impl AnimationKeyframePlan {
- fn from_ffi(keyframe: &FfiAnimationKeyframe) -> Self {
- let easing = &keyframe.easing;
- let linear_points = if easing.linear_point_count == 0 {
- Vec::new()
- } else {
- assert!(!easing.linear_points.is_null());
- unsafe { std::slice::from_raw_parts(easing.linear_points, easing.linear_point_count) }.to_vec()
- };
- Self {
- key: keyframe.key,
- easing_kind: easing.kind,
- linear_points,
- x1: easing.x1,
- y1: easing.y1,
- x2: easing.x2,
- y2: easing.y2,
- interval_count: easing.interval_count,
- step_position: easing.step_position,
- composite: keyframe.composite,
- }
- }
-
- fn easing_descriptor(&self) -> FfiEasingDescriptor {
- FfiEasingDescriptor {
- kind: self.easing_kind,
- linear_points: self.linear_points.as_ptr(),
- linear_point_count: self.linear_points.len(),
- x1: self.x1,
- y1: self.y1,
- x2: self.x2,
- y2: self.y2,
- interval_count: self.interval_count,
- step_position: self.step_position,
- }
- }
-}
-
#[repr(u8)]
#[derive(Clone, Copy)]
#[expect(dead_code, reason = "C++ constructs the variants")]
@@ -5601,12 +5538,9 @@ fn resolve_animation_color(
if !use_current_color {
return Some(color.clone_retained());
}
- let current_color = context?.current_color;
- if current_color.is_null() {
- return None;
- }
- let retained = unsafe { crate::css::style_value::retain_style_value(current_color) };
- Some(unsafe { RetainedStyleValueData::from_retained_pointer(retained) })
+ let current_color = context?.current_color?;
+ current_color.optional_data()?;
+ Some(current_color.clone())
}
enum RootAnimationColor<'a> {
@@ -5630,11 +5564,8 @@ fn resolve_root_animation_color<'a>(
match color {
StyleValueData::ColorFunction { .. } => Some(RootAnimationColor::Borrowed(color)),
StyleValueData::Keyword { keyword } if *keyword == crate::css::style_compute::current_color_keyword() => {
- let current_color = context?.current_color;
- if current_color.is_null() {
- return None;
- }
- let (components, missing) = legacy_srgb_components(unsafe { &*current_color })?;
+ let current_color = context?.current_color?.optional_data()?;
+ let (components, missing) = legacy_srgb_components(current_color)?;
if missing.iter().any(|component| *component) {
return None;
}
@@ -6690,11 +6621,12 @@ fn composite_batch_value<'a>(
fn evaluate_animation_value(
context: &FfiAnimationContext,
- input: &FfiAnimationValueInput,
+ input: &AnimationValueInput,
underlying_override: Option<&StyleValueData>,
) -> AnimatedProperty {
- let keyframes = unsafe { std::slice::from_raw_parts(input.keyframes, input.keyframe_count) };
+ let keyframes = input.keyframes;
assert!(keyframes.len() >= 2);
+ let plan = |index: usize| &input.keyframe_plans[keyframes[index].keyframe];
// https://drafts.csswg.org/web-animations-1/#the-effect-value-of-a-keyframe-animation-effect
// 10. Let interval endpoints be an empty sequence of keyframes.
@@ -6707,7 +6639,7 @@ fn evaluate_animation_value(
let mut start_index = 0;
let mut end_index = 1;
for next_index in 2..keyframes.len() {
- if input.current_key < keyframes[end_index].key as f64 {
+ if input.current_key < plan(end_index).key as f64 {
break;
}
start_index = end_index;
@@ -6715,11 +6647,11 @@ fn evaluate_animation_value(
}
let start_keyframe = &keyframes[start_index];
let end_keyframe = &keyframes[end_index];
- let interval_progress =
- (input.current_key - start_keyframe.key as f64) / (end_keyframe.key - start_keyframe.key) as f64;
- let progress = evaluate_easing_descriptor(&start_keyframe.easing, interval_progress, false) as f32;
- if end_keyframe.value.is_null() {
- if start_keyframe.value.is_null() {
+ let (start_plan, end_plan) = (plan(start_index), plan(end_index));
+ let interval_progress = (input.current_key - start_plan.key as f64) / (end_plan.key - start_plan.key) as f64;
+ let progress = start_plan.easing.evaluate_at(interval_progress, false) as f32;
+ let Some(end) = end_keyframe.value.optional_data() else {
+ if start_keyframe.value.optional_data().is_none() {
return AnimatedProperty {
value: None,
#[cfg(test)]
@@ -6730,30 +6662,24 @@ fn evaluate_animation_value(
};
}
return AnimatedProperty {
- // SAFETY: Keyframe values are live shared style values for the batch's lifetime.
- value: Some(unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- start_keyframe.value,
- ))
- }),
+ value: Some(start_keyframe.value.clone()),
#[cfg(test)]
start_index,
#[cfg(test)]
end_index,
apply: true,
};
- }
- let underlying = underlying_override.unwrap_or_else(|| unsafe { &*input.underlying });
- let start = unsafe {
- if start_keyframe.value.is_null() {
- &*input.initial
- } else {
- &*start_keyframe.value
- }
};
- let end = unsafe { &*end_keyframe.value };
- let start = composite_batch_value(context, input.property_id, underlying, start, start_keyframe.composite);
- let end = composite_batch_value(context, input.property_id, underlying, end, end_keyframe.composite);
+ let underlying = underlying_override
+ .or(input.underlying)
+ .expect("an animated property must have an underlying value");
+ let start = start_keyframe
+ .value
+ .optional_data()
+ .or(input.initial)
+ .expect("an animated property must have an initial value");
+ let start = composite_batch_value(context, input.property_id, underlying, start, start_plan.composite);
+ let end = composite_batch_value(context, input.property_id, underlying, end, end_plan.composite);
let result = interpolate_value(Some(context), input.property_id, start.data(), end.data(), progress);
assert!(result.handled);
AnimatedProperty {
@@ -6829,10 +6755,6 @@ impl AnimatedCustomProperties {
self.names.len() as u32
}
- pub(crate) fn len(&self) -> usize {
- self.names.len()
- }
-
pub(crate) fn is_empty(&self) -> bool {
self.names.is_empty()
}
@@ -6899,7 +6821,7 @@ impl AnimatedCustomProperties {
pub(crate) fn computed_value(
&self,
registry: &Registry,
- property: &FfiResolvedAnimationProperty,
+ property: &ResolvedAnimationProperty,
finalization: &crate::css::custom_properties::CustomPropertyFinalization<'_>,
) -> RetainedStyleValueData {
let name_id = property.custom_name_id;
@@ -6907,12 +6829,7 @@ impl AnimatedCustomProperties {
FfiAnimationSpecifiedValueSource::Inherited => self.inherited_value(registry, name_id),
FfiAnimationSpecifiedValueSource::Initial => self.initial_value(registry, name_id),
FfiAnimationSpecifiedValueSource::Underlying => self.underlying_value(registry, name_id),
- // SAFETY: a resolved declaration's value is retained by the resolution's storage.
- FfiAnimationSpecifiedValueSource::Value => unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- property.value,
- ))
- },
+ FfiAnimationSpecifiedValueSource::Value => property.value.clone(),
};
if !registry.name_has_syntax(self.units(name_id)) {
return value;
@@ -7027,7 +6944,6 @@ pub(crate) fn resolve_published_animation_declarations(
let mut easings = Vec::new();
let mut effects = Vec::new();
let mut declarations = Vec::new();
- let mut values = Vec::new();
let mut base_urls = Vec::new();
for selection in selected {
let effect = selection.effect;
@@ -7092,18 +7008,17 @@ pub(crate) fn resolve_published_animation_declarations(
_ => (value.clone_retained(), false),
},
};
- declarations.push(FfiAnimationDeclaration {
+ declarations.push(AnimationDeclaration {
keyframe_index,
property_id: declaration.property_id,
custom_name_id: 0,
custom_is_inherited: false,
custom_is_important: false,
- value: value.pointer(),
+ value,
style_sheet_resource_context,
use_initial,
is_transition,
});
- values.push(value);
}
for declaration in effect.custom_declarations_of(keyframe) {
let name_id = custom_properties.mint(&declaration.name);
@@ -7121,18 +7036,17 @@ pub(crate) fn resolve_published_animation_declarations(
),
PublishedValue::Declared(value) => (value.clone_retained(), false),
};
- declarations.push(FfiAnimationDeclaration {
+ declarations.push(AnimationDeclaration {
keyframe_index,
property_id: crate::css::property_metadata::property_id::CUSTOM,
custom_name_id: name_id,
custom_is_inherited: registry.name_inherits(custom_properties.units(name_id)),
custom_is_important: custom_properties.is_important(name_id),
- value: value.pointer(),
+ value,
style_sheet_resource_context,
use_initial,
is_transition,
});
- values.push(value);
}
}
effects.push(FfiAnimationEffect {
@@ -7143,18 +7057,14 @@ pub(crate) fn resolve_published_animation_declarations(
});
}
let keyframes = keyframes
- .iter()
- .zip(&easings)
- .map(|(&(key, composite), easing)| FfiAnimationKeyframe {
- key,
- easing: easing_descriptor(easing),
- composite,
- })
- .collect::<Vec<_>>();
+ .into_iter()
+ .zip(easings)
+ .map(|((key, composite), easing)| AnimationKeyframePlan { key, easing, composite })
+ .collect();
let mut resolved = resolve_animation_declarations(
&declarations,
&effects,
- &keyframes,
+ keyframes,
writing_mode,
direction,
important_property_bitmap,
@@ -7185,37 +7095,6 @@ fn holds_arbitrary_substitution(value: &StyleValueData) -> bool {
)
}
-/// A descriptor borrowing an easing's control points.
-fn easing_descriptor(easing: &crate::css::easing::Easing) -> FfiEasingDescriptor {
- use crate::css::easing::Easing;
- let (linear_points, linear_point_count) = match easing {
- Easing::Linear(points) => (points.as_ptr(), points.len()),
- _ => (std::ptr::null(), 0),
- };
- let (x1, y1, x2, y2) = match *easing {
- Easing::CubicBezier { x1, y1, x2, y2 } => (x1, y1, x2, y2),
- _ => (0.0, 0.0, 0.0, 0.0),
- };
- let (interval_count, step_position) = match *easing {
- Easing::Steps {
- interval_count,
- position,
- } => (interval_count, position),
- _ => (0, 0),
- };
- FfiEasingDescriptor {
- kind: easing.kind(),
- linear_points,
- linear_point_count,
- x1,
- y1,
- x2,
- y2,
- interval_count,
- step_position,
- }
-}
-
struct AnimationPreparationKey {
effects: Box<[FfiAnimationPreparationEffect]>,
/// The custom-property environments a preparation that substituted keyframe values against the
@@ -7240,19 +7119,18 @@ impl AnimationPreparationKey {
pub(crate) struct PreparedAnimationBatch {
key: AnimationPreparationKey,
resolved: ResolvedAnimationDeclarations,
- // Retain the allocations referenced by `keyframes_by_value`.
- _computed_keyframe_values: Vec<RetainedStyleValueData>,
- keyframes_by_value: Vec<Vec<FfiAnimationKeyframeValue>>,
- context: FfiAnimationContext,
+ keyframes_by_value: Vec<Vec<AnimationKeyframeValue>>,
+ /// The context the preparation was made in, without the current color, which each sample
+ /// reads from its own working set.
+ context: FfiAnimationContext<'static>,
}
// SAFETY: A prepared batch is built once and never mutated: sampling reads its plans and copies
-// its context. The raw `*const StyleValueData` pointers it holds all name immutable style values
-// whose reference counts are `Arc`s, retained for the batch's lifetime by `_computed_keyframe_values`
-// and the resolved declarations' own retained values. An animated overlay caches one behind an
-// `Arc`, and an installed overlay is reachable from the computed catalog that every evaluation
-// worker borrows; nothing but the animation round, which runs on the engine's thread between
-// evaluation passes, ever constructs, replaces or reads one.
+// its context. The raw pointers its resolved declarations hold name the base URLs and random
+// sharing values those declarations retain for the batch's lifetime. An animated overlay caches
+// one behind an `Arc`, and an installed overlay is reachable from the computed catalog that every
+// evaluation worker borrows; nothing but the animation round, which runs on the engine's thread
+// between evaluation passes, ever constructs, replaces or reads one.
unsafe impl Send for PreparedAnimationBatch {}
unsafe impl Sync for PreparedAnimationBatch {}
@@ -7269,38 +7147,34 @@ pub(crate) fn animation_preparation_matches(
}
/// Complete the Rust-owned animation plan and compose every interval without
-/// consulting C++ or the DOM. On the first sample this consumes the Rust allocations produced by
-/// declaration resolution and keyframe longhand computation. Later samples can reuse that
-/// preparation from the animated overlay.
-///
-/// # Safety
-/// `computed` must point to a live batch. Its range of sampled effects must be readable. On a cache miss both storage pointers must be live, unconsumed results from their
-/// producing calls. `underlying_longhand_table` and `overlay` must point at live values, and the
-/// overlay must be uniquely owned for the duration of the call.
-pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -> usize {
+/// consulting C++ or the DOM. On the first sample this consumes the declarations and keyframe
+/// values the batch carries. Later samples can reuse that preparation from the animated overlay.
+/// Answers the final value of each custom property the effects animate, by the number it animates
+/// under, in that order.
+pub(crate) fn evaluate_animations(batch: ComputedAnimationBatch<'_>) -> Vec<(u32, RetainedStyleValueData)> {
crate::css::ffi_stats::note_animation_evaluation();
- assert!(!computed.underlying_longhand_table.is_null());
- assert!(!computed.overlay.is_null());
- let sampled = unsafe { std::slice::from_raw_parts(computed.sampled_effects, computed.sampled_effect_count) };
- let overlay = unsafe { &mut *computed.overlay.cast::<crate::css::animated_overlay::AnimatedOverlay>() };
+ let ComputedAnimationBatch {
+ context: sample_context,
+ sampled_effects: sampled,
+ custom_property_environments,
+ cache_preparation,
+ preparation_reads_custom_property_environments,
+ preparation_inputs,
+ underlying_longhand_table,
+ overlay,
+ custom_underlying_values,
+ custom_initial_values,
+ } = batch;
let preparation = overlay
.animation_preparation
.as_ref()
- .filter(|preparation| preparation.key.matches(sampled, computed.custom_property_environments))
+ .filter(|preparation| preparation.key.matches(sampled, custom_property_environments))
.cloned()
.unwrap_or_else(|| {
- assert!(!computed.resolved_animation_storage.is_null());
- assert!(!computed.computed_keyframe_storage.is_null());
- let resolved = *unsafe {
- Box::from_raw(
- computed
- .resolved_animation_storage
- .cast::<ResolvedAnimationDeclarations>(),
- )
- };
- let computed_keyframe_values = unsafe {
- crate::css::style_compute::take_animation_keyframe_longhand_values(computed.computed_keyframe_storage)
- };
+ let AnimationPreparationInputs {
+ resolved,
+ computed_keyframe_values,
+ } = preparation_inputs.expect("a sample without a matching preparation carries its inputs");
assert_eq!(computed_keyframe_values.len(), resolved.properties.len());
let keyframes_by_value = resolved
.value_plans
@@ -7308,15 +7182,9 @@ pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -
.map(|plan| {
plan.property_indices
.iter()
- .map(|&property_index| {
- let property = &resolved.properties[property_index];
- let keyframe = &resolved.keyframes[property.keyframe_index];
- FfiAnimationKeyframeValue {
- key: keyframe.key,
- value: computed_keyframe_values[property_index].pointer(),
- easing: keyframe.easing_descriptor(),
- composite: keyframe.composite,
- }
+ .map(|&property_index| AnimationKeyframeValue {
+ keyframe: resolved.properties[property_index].keyframe_index,
+ value: computed_keyframe_values[property_index].clone(),
})
.collect()
})
@@ -7324,65 +7192,67 @@ pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -
std::sync::Arc::new(PreparedAnimationBatch {
key: AnimationPreparationKey {
effects: sampled.iter().map(|sampled| sampled.effect).collect(),
- custom_property_environments: computed
- .preparation_reads_custom_property_environments
- .then_some(computed.custom_property_environments),
+ custom_property_environments: preparation_reads_custom_property_environments
+ .then_some(custom_property_environments),
},
- resolved,
- _computed_keyframe_values: computed_keyframe_values,
+ resolved: *resolved,
keyframes_by_value,
- context: computed.context,
+ context: FfiAnimationContext {
+ allow_discrete: sample_context.allow_discrete,
+ current_color: None,
+ has_length_resolution_context: sample_context.has_length_resolution_context,
+ length_resolution_context: sample_context.length_resolution_context,
+ has_transform_reference_box: sample_context.has_transform_reference_box,
+ transform_reference_box_width: sample_context.transform_reference_box_width,
+ transform_reference_box_height: sample_context.transform_reference_box_height,
+ },
})
});
- if computed.cache_preparation {
+ if cache_preparation {
overlay.animation_preparation = Some(preparation.clone());
} else {
overlay.animation_preparation = None;
}
let resolved = &preparation.resolved;
- let mut context = preparation.context;
- context.current_color = computed.context.current_color;
- context.has_transform_reference_box = computed.context.has_transform_reference_box;
- context.transform_reference_box_width = computed.context.transform_reference_box_width;
- context.transform_reference_box_height = computed.context.transform_reference_box_height;
- let underlying_longhand_table = unsafe {
- &*computed
- .underlying_longhand_table
- .cast::<crate::css::computed_longhand_table::ComputedLonghandTable>()
+ let context = FfiAnimationContext {
+ current_color: sample_context.current_color,
+ has_transform_reference_box: sample_context.has_transform_reference_box,
+ transform_reference_box_width: sample_context.transform_reference_box_width,
+ transform_reference_box_height: sample_context.transform_reference_box_height,
+ ..preparation.context
};
// https://www.w3.org/TR/web-animations-1/#effect-stacks
// NB: Inputs arrive in composite order. Keep each result as the underlying value for the
// next effect affecting the same property.
- let mut custom_final_values = Vec::<(u32, RetainedStyleValueData)>::new();
- let mut previous_values = Vec::<(u16, u32, *const StyleValueData)>::with_capacity(resolved.value_plans.len());
+ let mut custom_final_values = std::collections::BTreeMap::<u32, RetainedStyleValueData>::new();
+ let mut previous_values = Vec::<(u16, u32, RetainedStyleValueData)>::with_capacity(resolved.value_plans.len());
for (plan, keyframes) in resolved.value_plans.iter().zip(&preparation.keyframes_by_value) {
assert!(plan.effect_index < sampled.len());
let (underlying, initial) = if plan.custom_name_id != 0 {
let custom_index = (plan.custom_name_id - 1) as usize;
- assert!(custom_index < computed.custom_value_count);
(
- unsafe { *computed.custom_underlying_values.add(custom_index) },
- unsafe { *computed.custom_initial_values.add(custom_index) },
+ custom_underlying_values[custom_index].optional_data(),
+ custom_initial_values[custom_index].optional_data(),
)
} else {
let underlying = underlying_longhand_table
.get(plan.property_id)
.expect("an animated longhand must have an underlying computed value");
(
- underlying.pointer(),
- crate::css::style_compute::initial_value_data(plan.property_id),
+ underlying.optional_data(),
+ crate::css::style_compute::initial_value(plan.property_id),
)
};
- let input = FfiAnimationValueInput {
+ let input = AnimationValueInput {
property_id: plan.property_id,
custom_name_id: plan.custom_name_id,
result_of_transition: plan.result_of_transition,
underlying,
initial,
current_key: sampled[plan.effect_index].current_key,
- keyframes: keyframes.as_ptr(),
- keyframe_count: keyframes.len(),
+ keyframes,
+ keyframe_plans: &resolved.keyframes,
};
let previous_value = previous_values
.iter()
@@ -7390,7 +7260,7 @@ pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -
.find(|(property_id, custom_name_id, _)| {
*property_id == input.property_id && *custom_name_id == input.custom_name_id
})
- .map(|(_, _, value)| unsafe { &**value });
+ .and_then(|(_, _, value)| value.optional_data());
let result = evaluate_animation_value(&context, &input, previous_value);
if !result.apply {
assert!(result.value.is_none());
@@ -7398,13 +7268,13 @@ pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -
}
if input.custom_name_id != 0 {
if let Some(value) = result.value {
- previous_values.push((input.property_id, input.custom_name_id, value.pointer()));
- custom_final_values.push((input.custom_name_id, value));
+ previous_values.push((input.property_id, input.custom_name_id, value.clone()));
+ custom_final_values.insert(input.custom_name_id, value);
}
continue;
}
if let Some(value) = result.value {
- previous_values.push((input.property_id, input.custom_name_id, value.pointer()));
+ previous_values.push((input.property_id, input.custom_name_id, value.clone()));
overlay.set_owned(input.property_id, value, false, input.result_of_transition);
} else {
let value = RetainedStyleValueData::from_owned(StyleValueData::Keyword {
@@ -7418,29 +7288,7 @@ pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -
);
}
}
- if !custom_final_values.is_empty() {
- assert!(!computed.custom_results.is_null());
- assert!(!computed.custom_result_count.is_null());
- let mut final_by_name = std::collections::BTreeMap::<u32, RetainedStyleValueData>::new();
- for (custom_name_id, value) in custom_final_values {
- final_by_name.insert(custom_name_id, value);
- }
- let mut written = 0;
- for (custom_name_id, value) in final_by_name {
- assert!(written < computed.custom_value_count);
- let pointer = value.pointer();
- std::mem::forget(value);
- unsafe {
- computed.custom_results.add(written).write(FfiAnimatedCustomProperty {
- custom_name_id,
- value: pointer,
- });
- }
- written += 1;
- }
- unsafe { computed.custom_result_count.write(written) };
- }
- resolved.value_plans.len()
+ custom_final_values.into_iter().collect()
}
/// Attempt Rust-owned style value interpolation without consulting C++ or the DOM.
@@ -7476,6 +7324,7 @@ pub unsafe extern "C" fn rust_test_composite_style_value(
#[cfg(test)]
mod tests {
use super::*;
+ use crate::css::easing::FfiEasingKind;
#[test]
fn resolves_keyframe_property_conflicts_as_one_batch() {
@@ -7614,64 +7463,55 @@ mod tests {
Arc::new(StyleValueData::Number { value: 1.0 }),
];
let declarations = [
- FfiAnimationDeclaration {
+ AnimationDeclaration {
custom_name_id: 0,
custom_is_inherited: false,
custom_is_important: false,
keyframe_index: 0,
property_id: property_id::OPACITY,
- value: Arc::as_ptr(&values[0]),
+ value: RetainedStyleValueData::from_arc(values[0].clone()),
style_sheet_resource_context: FfiAnimationStyleSheetResourceContext::empty(),
use_initial: false,
is_transition: false,
},
- FfiAnimationDeclaration {
+ AnimationDeclaration {
custom_name_id: 0,
custom_is_inherited: false,
custom_is_important: false,
keyframe_index: 1,
property_id: property_id::COLOR,
- value: Arc::as_ptr(&values[1]),
+ value: RetainedStyleValueData::from_arc(values[1].clone()),
style_sheet_resource_context: FfiAnimationStyleSheetResourceContext::empty(),
use_initial: false,
is_transition: false,
},
- FfiAnimationDeclaration {
+ AnimationDeclaration {
custom_name_id: 0,
custom_is_inherited: false,
custom_is_important: false,
keyframe_index: 2,
property_id: property_id::OPACITY,
- value: Arc::as_ptr(&values[2]),
+ value: RetainedStyleValueData::from_arc(values[2].clone()),
style_sheet_resource_context: FfiAnimationStyleSheetResourceContext::empty(),
use_initial: false,
is_transition: false,
},
];
- let easing = || FfiEasingDescriptor {
- kind: FfiEasingKind::Linear,
- linear_points: std::ptr::null(),
- linear_point_count: 0,
- x1: 0.0,
- y1: 0.0,
- x2: 0.0,
- y2: 0.0,
- interval_count: 0,
- step_position: 0,
- };
- let keyframes = [0, 50, 100].map(|key| FfiAnimationKeyframe {
- key,
- easing: easing(),
- composite: FfiCompositeOperation::Replace,
- });
+ let keyframes = [0, 50, 100]
+ .map(|key| AnimationKeyframePlan {
+ key,
+ easing: Easing::default(),
+ composite: FfiCompositeOperation::Replace,
+ })
+ .into();
let effects = [FfiAnimationEffect {
first_keyframe_index: 0,
- keyframe_count: keyframes.len(),
+ keyframe_count: 3,
current_key: 50.0,
result_of_transition: false,
}];
- let resolved = resolve_animation_declarations(&declarations, &effects, &keyframes, 0, 0, &[]);
+ let resolved = resolve_animation_declarations(&declarations, &effects, keyframes, 0, 0, &[]);
assert_eq!(resolved.value_plans.len(), 1);
let plan = &resolved.value_plans[0];
assert_eq!(plan.property_id, property_id::OPACITY);
@@ -7686,22 +7526,22 @@ mod tests {
let pending = Arc::new(StyleValueData::PendingSubstitution {
original_shorthand_value: original,
});
- let declaration = FfiAnimationDeclaration {
+ let declaration = AnimationDeclaration {
keyframe_index: 0,
property_id: crate::css::property_metadata::property_id::BORDER,
custom_name_id: 0,
custom_is_inherited: false,
custom_is_important: false,
- value: &raw const *pending,
+ value: RetainedStyleValueData::from_arc(pending),
style_sheet_resource_context: FfiAnimationStyleSheetResourceContext::empty(),
use_initial: false,
is_transition: false,
};
- let resolved = resolve_animation_declarations(&[declaration], &[], &[], 0, 0, &[]);
+ let resolved = resolve_animation_declarations(&[declaration], &[], Vec::new(), 0, 0, &[]);
assert!(!resolved.properties.is_empty());
let mut found_synthesized = false;
for property in &resolved.properties {
- let value = unsafe { &*property.value };
+ let value = property.value.data();
if let StyleValueData::PendingSubstitution {
original_shorthand_value,
} = value
@@ -7729,7 +7569,7 @@ mod tests {
assert!(!property_is_important(FIRST_LONGHAND_PROPERTY_ID - 1, &bitmap));
}
- fn animation_context(allow_discrete: bool) -> FfiAnimationContext {
+ fn animation_context(allow_discrete: bool) -> FfiAnimationContext<'static> {
let font_metrics = || FfiAnimationFontMetrics {
font_size: 0.0,
x_height: 0.0,
@@ -7739,7 +7579,7 @@ mod tests {
};
FfiAnimationContext {
allow_discrete,
- current_color: std::ptr::null(),
+ current_color: None,
has_length_resolution_context: false,
length_resolution_context: FfiAnimationLengthResolutionContext {
viewport_width: 0.0,
@@ -7814,49 +7654,35 @@ mod tests {
#[test]
fn evaluates_composited_animation_value() {
let underlying = StyleValueData::Number { value: 2.0 };
- let start = StyleValueData::Number { value: 3.0 };
- let middle = StyleValueData::Number { value: 5.0 };
- let end = StyleValueData::Number { value: 9.0 };
- let linear_easing = || FfiEasingDescriptor {
- kind: FfiEasingKind::CubicBezier,
- linear_points: std::ptr::null(),
- linear_point_count: 0,
+ let number = |value| RetainedStyleValueData::from_arc(Arc::new(StyleValueData::Number { value }));
+ let linear_easing = || Easing::CubicBezier {
x1: 0.0,
y1: 0.0,
x2: 1.0,
y2: 1.0,
- interval_count: 0,
- step_position: 0,
};
- let keyframes = [
- FfiAnimationKeyframeValue {
- key: 0,
- value: &raw const start,
- easing: linear_easing(),
- composite: FfiCompositeOperation::Add,
- },
- FfiAnimationKeyframeValue {
- key: 50,
- value: &raw const middle,
- easing: linear_easing(),
- composite: FfiCompositeOperation::Add,
- },
- FfiAnimationKeyframeValue {
- key: 100,
- value: &raw const end,
- easing: linear_easing(),
- composite: FfiCompositeOperation::Add,
- },
- ];
- let input = FfiAnimationValueInput {
+ let plans = [0, 50, 100].map(|key| AnimationKeyframePlan {
+ key,
+ easing: linear_easing(),
+ composite: FfiCompositeOperation::Add,
+ });
+ let keyframes = [3.0, 5.0, 9.0]
+ .into_iter()
+ .enumerate()
+ .map(|(keyframe, value)| AnimationKeyframeValue {
+ keyframe,
+ value: number(value),
+ })
+ .collect::<Vec<_>>();
+ let input = AnimationValueInput {
property_id: crate::css::property_metadata::property_id::FLEX_GROW,
custom_name_id: 0,
result_of_transition: false,
- underlying: &raw const underlying,
- initial: &raw const underlying,
+ underlying: Some(&underlying),
+ initial: Some(&underlying),
current_key: 75.0,
- keyframes: keyframes.as_ptr(),
- keyframe_count: keyframes.len(),
+ keyframes: &keyframes,
+ keyframe_plans: &plans,
};
let result = evaluate_animation_value(&animation_context(true), &input, None);
assert!(result.apply);
@@ -7869,60 +7695,56 @@ mod tests {
#[test]
fn evaluates_missing_keyframe_values() {
- let underlying = Arc::new(StyleValueData::Number { value: 2.0 });
- let initial = Arc::new(StyleValueData::Number { value: 1.0 });
- let start = Arc::new(StyleValueData::Number { value: 3.0 });
- let end = Arc::new(StyleValueData::Number { value: 5.0 });
- let easing = || FfiEasingDescriptor {
- kind: FfiEasingKind::CubicBezier,
- linear_points: std::ptr::null(),
- linear_point_count: 0,
+ let underlying = StyleValueData::Number { value: 2.0 };
+ let initial = StyleValueData::Number { value: 1.0 };
+ let start = || RetainedStyleValueData::from_arc(Arc::new(StyleValueData::Number { value: 3.0 }));
+ let end = || RetainedStyleValueData::from_arc(Arc::new(StyleValueData::Number { value: 5.0 }));
+ let easing = || Easing::CubicBezier {
x1: 0.0,
y1: 0.0,
x2: 1.0,
y2: 1.0,
- interval_count: 0,
- step_position: 0,
};
+ let plans = [0, 100].map(|key| AnimationKeyframePlan {
+ key,
+ easing: easing(),
+ composite: FfiCompositeOperation::Replace,
+ });
let evaluate = |start_value, end_value| {
let keyframes = [
- FfiAnimationKeyframeValue {
- key: 0,
+ AnimationKeyframeValue {
+ keyframe: 0,
value: start_value,
- easing: easing(),
- composite: FfiCompositeOperation::Replace,
},
- FfiAnimationKeyframeValue {
- key: 100,
+ AnimationKeyframeValue {
+ keyframe: 1,
value: end_value,
- easing: easing(),
- composite: FfiCompositeOperation::Replace,
},
];
- let input = FfiAnimationValueInput {
+ let input = AnimationValueInput {
property_id: crate::css::property_metadata::property_id::FLEX_GROW,
custom_name_id: 0,
result_of_transition: false,
- underlying: Arc::as_ptr(&underlying),
- initial: Arc::as_ptr(&initial),
+ underlying: Some(&underlying),
+ initial: Some(&initial),
current_key: 50.0,
- keyframes: keyframes.as_ptr(),
- keyframe_count: keyframes.len(),
+ keyframes: &keyframes,
+ keyframe_plans: &plans,
};
evaluate_animation_value(&animation_context(true), &input, None)
};
- let result = evaluate(std::ptr::null(), Arc::as_ptr(&end));
+ let result = evaluate(RetainedStyleValueData::none(), end());
assert!(result.apply);
let value = result.value.unwrap().into_arc();
assert!(matches!(&*value, StyleValueData::Number { value } if *value == 3.0));
- let result = evaluate(Arc::as_ptr(&start), std::ptr::null());
+ let result = evaluate(start(), RetainedStyleValueData::none());
assert!(result.apply);
let value = result.value.unwrap().into_arc();
assert!(matches!(&*value, StyleValueData::Number { value } if *value == 3.0));
- let result = evaluate(std::ptr::null(), std::ptr::null());
+ let result = evaluate(RetainedStyleValueData::none(), RetainedStyleValueData::none());
assert!(!result.apply);
assert!(result.value.is_none());
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_handle.rs b/Libraries/LibWeb/Rust/src/css/style/engine_handle.rs
index 924bd87fd03..f46d47ce2c9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_handle.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_handle.rs
@@ -37,6 +37,7 @@ impl StyleEngineHandle {
}
/// A handle for an engine that its caller owns and keeps alive while the handle is used.
+ #[cfg(test)]
pub fn from_raw(engine: *mut StyleEngine) -> Self {
Self(engine)
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
index a9983802fbb..c07b6138769 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
@@ -23,8 +23,9 @@ use crate::css::css_pixels::CssPixels;
use crate::css::host_shared::{HostShared, SharedPayload};
use crate::css::property_metadata::property_id as prop;
use crate::css::style_compute::{
- FfiAnimationLengthContexts, FfiEffectiveColorSchemeInput, FfiFontMetrics, FfiHostAnimationSample,
- FfiLengthResolutionContext, FfiStyleComputationEnvironment, keyword, px_length_unit,
+ AnimationSampleInput, FfiAnimationLengthContexts, FfiEffectiveColorSchemeInput, FfiFontMetrics,
+ FfiLengthResolutionContext, FfiStyleComputationEnvironment, HostSampledEffects, keyword, px_length_unit,
+ working_set_current_color,
};
use crate::css::style_value::StyleValueData;
use crate::css::table_group_builder::{FfiFontGroupBuildInputs, TableGroupBuildInputs, group_index};
@@ -352,14 +353,6 @@ fn post_compute_adjusts(property: u16, facts: u32) -> bool {
}
/// The overlay a sample writes, which the host's working set would hold.
-extern "C" fn overlay_for_mutation(overlay: *mut std::ffi::c_void) -> *mut std::ffi::c_void {
- overlay
-}
-
-extern "C" fn no_host_length_contexts(_: *mut std::ffi::c_void, _: u8, _: *mut FfiAnimationLengthContexts) {
- unreachable!("a sample without the host builds its length contexts itself");
-}
-
impl super::StyleEngine {
/// Samples the animations of the element `node` names over `record`, the record the host installed
/// for it, with their timelines at `samples`, and composes them into a record no element holds,
@@ -612,12 +605,13 @@ impl super::StyleEngine {
transform_reference_box: Option<crate::css::css_pixels::CssPixelRect>,
timeline_samples: super::animations::AnimationTimelineSamples<'_>,
) -> Result<crate::css::style_compute::FfiHostAnimationSampleResult, NeedsHost> {
- let table = HostShared::from_option(
+ let table = HostShared::new(std::ptr::from_ref(
self.computed_group_sets
.style_record_view(record)
.ok_or(NeedsHost)?
- .longhand_table,
- );
+ .longhand_table
+ .ok_or(NeedsHost)?,
+ ));
// A keyframe substitutes against the custom properties of the element and of its parent, as the host's
// sample does, from the stores the engine holds for their environments throughout the sample.
let inheritance_parent = self.tree.inheritance_parent(node);
@@ -658,40 +652,38 @@ impl super::StyleEngine {
initial_font_size_raw: inputs.initial_font_size_raw,
default_font_size_raw: inputs.default_font_size_raw,
};
- let overlay_pointer = std::ptr::from_mut(overlay).cast::<std::ffi::c_void>();
- let input = FfiHostAnimationSample {
- host: std::ptr::null(),
+ // SAFETY: The record's table is frozen, and the record the caller holds keeps it alive throughout the
+ // sample, which writes only `overlay` and what the engine keeps of the element's animations.
+ let table = unsafe { table.deref() };
+ let input = AnimationSampleInput {
style_node: node.raw(),
pseudo_kind: crate::css::cascaded_properties::NO_PSEUDO_ELEMENT,
- effects: std::ptr::null(),
- effect_count: 0,
- longhand_table: table.cast_mut().cast_const().cast(),
- animated_overlay: overlay_pointer.cast_const(),
+ effects: HostSampledEffects::none(),
+ longhand_table: table,
+ has_animated_overlay: true,
+ current_color: working_set_current_color(table, Some(overlay)),
style_record: record,
- custom_property_store: store,
- // A sample that animates a custom property is the host's, so none composes over the element's own.
- base_custom_property_store: store,
- inheritance_custom_property_store: inheritance_store,
- element_declares_own_custom_properties: false,
+ stores: crate::css::animation::KeyframeStores {
+ substitution: store,
+ // A sample that animates a custom property is the host's, so none composes over the element's own.
+ base: store,
+ inheritance: inheritance_store,
+ element_declares_custom_properties: false,
+ },
custom_property_environments,
inheritance_parent_style_record,
- environment: &raw const environment,
+ environment: &environment,
element_box_slot: crate::layout::node_data::NodeSlotId::INVALID.index,
- callback_context: overlay_pointer,
- prepare_overlay_for_mutation: overlay_for_mutation,
- length_contexts: no_host_length_contexts,
};
- // SAFETY: Everything `input` names lives until the sample returns.
- unsafe {
- crate::css::style_compute::sample_without_host(
- &input,
- self,
- fresh,
- composed,
- transform_reference_box,
- timeline_samples,
- )
- }
+ crate::css::style_compute::sample_without_host(
+ &input,
+ overlay,
+ self,
+ fresh,
+ composed,
+ transform_reference_box,
+ timeline_samples,
+ )
}
/// The elements whose style a size query or container-relative unit decided below `container`, whose content box a
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 0cdb61e0fcd..b5be196d67f 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2787,28 +2787,6 @@ pub struct FfiDocumentLonghandInput {
pub viewport_height: f64,
}
-#[repr(C)]
-pub struct FfiAnimationKeyframeLonghandInput {
- pub underlying_longhand_table: *const ComputedLonghandTable,
- pub style_engine: crate::css::style::StyleEngineHandle,
- pub inheritance_parent_style_record: u64,
- pub resolved_properties: *const c_void,
- pub property_count: usize,
- pub environment: *const FfiStyleComputationEnvironment,
- pub font_length_resolution_context: *const FfiLengthResolutionContext,
- pub line_height_length_resolution_context: *const FfiLengthResolutionContext,
- pub remaining_length_resolution_context: *const FfiLengthResolutionContext,
- pub custom_property_values: *const *const c_void,
-}
-
-#[repr(C)]
-pub struct FfiAnimationKeyframeLonghandResult {
- pub value_count: usize,
- pub depends_on_viewport_metrics: bool,
- pub font_metrics_depend_on_viewport_metrics: bool,
- pub storage: *mut c_void,
-}
-
impl FfiEffectiveColorSchemeInput {
/// # Safety
/// The document-supported scheme storage must be valid for the returned
@@ -3070,21 +3048,26 @@ impl<'a> ParentSnapshot<'a> {
}
fn value(&self, property_id: u16) -> Option<&StyleValueData> {
+ self.value_handle(property_id).map(RetainedStyleValueData::data)
+ }
+
+ /// The handle that owns what [`Self::value`] answers.
+ fn value_handle(&self, property_id: u16) -> Option<&RetainedStyleValueData> {
if let Some(entry) = self
.inherited_value_overlay
.and_then(|overlay| overlay.get(property_id))
&& overlay_wins(entry, self.is_important(property_id))
{
- return Some(entry.value());
+ return Some(entry.value_handle());
}
for (property, value) in self.table.retained_inheritance_dependent_values() {
if property == property_id
&& crate::css::style_value::style_value_dependency_flags(value.pointer()) & 1 != 0
{
- return Some(value.data());
+ return Some(value);
}
}
- self.table.get(property_id).map(RetainedStyleValueData::data)
+ self.table.get(property_id)
}
}
@@ -5140,65 +5123,47 @@ pub unsafe extern "C" fn rust_intern_document_style(
})
}
+/// The values the keyframes of a sample compute to, one per resolved property, and what they read.
+pub(crate) struct AnimationKeyframeLonghands {
+ pub(crate) values: Vec<RetainedStyleValueData>,
+ pub(crate) depends_on_viewport_metrics: bool,
+ pub(crate) font_metrics_depend_on_viewport_metrics: bool,
+}
+
/// Computes every selected keyframe longhand through the Rust longhand driver.
/// Each keyframe gets a temporary table and the driver's coordination inputs
/// from the underlying style, then all of that keyframe's specified values are
-/// cascaded together before its selected properties are evaluated.
-///
-/// # Safety
-/// `input` and every range and pointer it contains must remain valid for the
-/// duration of the call. Every returned value transfers one strong reference
-/// to the caller.
-pub(crate) unsafe fn compute_animation_keyframe_longhands(
- input: &FfiAnimationKeyframeLonghandInput,
-) -> FfiAnimationKeyframeLonghandResult {
+/// cascaded together before its selected properties are evaluated. A custom
+/// property's value is the one `custom_property_values` holds at its index.
+pub(crate) fn compute_animation_keyframe_longhands(
+ underlying_longhand_table: &ComputedLonghandTable,
+ style_engine: &crate::css::style::StyleEngine,
+ inheritance_parent_style_record: u64,
+ properties: &[crate::css::animation::ResolvedAnimationProperty],
+ environment: &FfiStyleComputationEnvironment,
+ length_contexts: &FfiAnimationLengthContexts,
+ custom_property_values: &[Option<RetainedStyleValueData>],
+) -> AnimationKeyframeLonghands {
crate::css::ffi_stats::bump(crate::css::ffi_stats::FfiOp::AnimationKeyframeLonghandEntry);
use crate::css::property_metadata::{
FIRST_LONGHAND_PROPERTY_ID, LAST_LONGHAND_PROPERTY_ID, NUMBER_OF_LONGHAND_PROPERTIES,
};
- let properties = if input.property_count == 0 {
- &[][..]
- } else {
- unsafe {
- std::slice::from_raw_parts(
- input
- .resolved_properties
- .cast::<crate::css::animation::FfiResolvedAnimationProperty>(),
- input.property_count,
- )
- }
- };
if properties.is_empty() {
- return FfiAnimationKeyframeLonghandResult {
- value_count: 0,
+ return AnimationKeyframeLonghands {
+ values: Vec::new(),
depends_on_viewport_metrics: false,
font_metrics_depend_on_viewport_metrics: false,
- storage: std::ptr::null_mut(),
};
}
- assert!(!input.underlying_longhand_table.is_null());
- assert!(!input.environment.is_null());
- assert!(!input.font_length_resolution_context.is_null());
- assert!(!input.line_height_length_resolution_context.is_null());
- assert!(!input.remaining_length_resolution_context.is_null());
- let underlying_longhand_table = unsafe { &*input.underlying_longhand_table };
- let parent_snapshot = if input.inheritance_parent_style_record == 0 {
- None
- } else {
- let style_engine = unsafe { input.style_engine.get() };
- Some(keyframe_parent_snapshot_for_style_record(
- style_engine,
- input.inheritance_parent_style_record,
- ))
- };
+ let parent_snapshot = (inheritance_parent_style_record != 0)
+ .then(|| keyframe_parent_snapshot_for_style_record(style_engine, inheritance_parent_style_record));
let mut longhands_by_keyframe = std::collections::BTreeMap::<usize, Vec<usize>>::new();
for (index, property) in properties.iter().enumerate() {
if property.custom_name_id != 0 {
continue;
}
assert!((FIRST_LONGHAND_PROPERTY_ID..=LAST_LONGHAND_PROPERTY_ID).contains(&property.physical_property_id));
- assert!(!property.value.is_null());
longhands_by_keyframe
.entry(property.keyframe_index)
.or_default()
@@ -5213,14 +5178,10 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
if property.custom_name_id == 0 {
continue;
}
- assert!(!input.custom_property_values.is_null());
- let value = unsafe { *input.custom_property_values.add(index) };
- assert!(!value.is_null());
- values[index] = Some(unsafe {
- crate::css::style_value::RetainedStyleValueData::from_retained_pointer(
- crate::css::style_value::retain_style_value(value.cast()),
- )
- });
+ let value = custom_property_values[index]
+ .clone()
+ .expect("a custom property's keyframe has a computed value");
+ values[index] = Some(value);
}
let mut depends_on_viewport_metrics = false;
let mut font_metrics_depend_on_viewport_metrics = false;
@@ -5254,32 +5215,17 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
let property = &properties[index];
let value = match property.value_source {
- FfiAnimationSpecifiedValueSource::Value => unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- property.value.cast(),
- ))
- },
- FfiAnimationSpecifiedValueSource::Initial => unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- initial_value_data(property.source_longhand_id).cast(),
- ))
- },
+ FfiAnimationSpecifiedValueSource::Value => property.value.clone(),
+ FfiAnimationSpecifiedValueSource::Initial => initial_value_handle(property.source_longhand_id).clone(),
FfiAnimationSpecifiedValueSource::Underlying => underlying_longhand_table
.get(property.source_longhand_id)
.expect("an animated longhand must have an underlying value")
.clone_retained(),
- FfiAnimationSpecifiedValueSource::Inherited => {
- let inherited = parent_snapshot
- .as_ref()
- .and_then(|snapshot| snapshot.value(property.source_longhand_id));
- let inherited =
- inherited.unwrap_or_else(|| unsafe { &*initial_value_data(property.source_longhand_id) });
- unsafe {
- RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(
- std::ptr::from_ref(inherited).cast(),
- ))
- }
- }
+ FfiAnimationSpecifiedValueSource::Inherited => parent_snapshot
+ .as_ref()
+ .and_then(|snapshot| snapshot.value_handle(property.source_longhand_id))
+ .unwrap_or_else(|| initial_value_handle(property.source_longhand_id))
+ .clone(),
};
if property.is_transition {
values[index] = Some(value);
@@ -5311,7 +5257,7 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
if selected_longhands.iter().all(|word| *word == 0) {
continue;
}
- let mut environment = unsafe { *input.environment };
+ let mut environment = *environment;
environment.style_sheet_resource_contexts = style_sheet_resource_contexts.as_ptr();
environment.style_sheet_resource_context_count = style_sheet_resource_contexts.len();
@@ -5324,10 +5270,10 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
LONGHAND_DRIVE_PHASE_REMAINING,
] {
let length_resolution_context = match phase {
- LONGHAND_DRIVE_PHASE_FONT => input.font_length_resolution_context,
- LONGHAND_DRIVE_PHASE_LINE_HEIGHT => input.line_height_length_resolution_context,
- LONGHAND_DRIVE_PHASE_COLOR_SCHEME => std::ptr::null(),
- LONGHAND_DRIVE_PHASE_REMAINING => input.remaining_length_resolution_context,
+ LONGHAND_DRIVE_PHASE_FONT => Some(&length_contexts.font),
+ LONGHAND_DRIVE_PHASE_LINE_HEIGHT => Some(&length_contexts.line_height),
+ LONGHAND_DRIVE_PHASE_COLOR_SCHEME => None,
+ LONGHAND_DRIVE_PHASE_REMAINING => Some(&length_contexts.remaining),
_ => unreachable!(),
};
unsafe {
@@ -5339,7 +5285,7 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
&environment,
Some(&selected_longhands),
phase,
- length_resolution_context.as_ref(),
+ length_resolution_context,
None,
&mut results,
&mut effective_color_scheme,
@@ -5360,17 +5306,13 @@ pub(crate) unsafe fn compute_animation_keyframe_longhands(
}
}
- let values = Box::new(
- values
+ AnimationKeyframeLonghands {
+ values: values
.into_iter()
.map(|value| value.expect("the keyframe longhand drive must produce every requested value"))
- .collect::<Vec<_>>(),
- );
- FfiAnimationKeyframeLonghandResult {
- value_count: values.len(),
+ .collect(),
depends_on_viewport_metrics,
font_metrics_depend_on_viewport_metrics,
- storage: Box::into_raw(values).cast(),
}
}
@@ -5596,39 +5538,74 @@ pub(crate) fn animation_length_resolution_context(
}
}
-impl FfiHostAnimationSample {
- /// The working set's longhand table and its overlay before this sample.
- ///
+/// The effects a host samples, whose easings stay live for as long as the effects are borrowed.
+#[derive(Clone, Copy)]
+pub(crate) struct HostSampledEffects<'a>(&'a [FfiSampledAnimationEffect]);
+
+impl<'a> HostSampledEffects<'a> {
/// # Safety
- /// The sample's table and overlay must be live.
- unsafe fn working_set(&self) -> (&ComputedLonghandTable, Option<&AnimatedOverlay>) {
- // SAFETY: Guaranteed by the caller.
- unsafe {
- (
- &*self.longhand_table.cast::<ComputedLonghandTable>(),
- self.animated_overlay.cast::<AnimatedOverlay>().as_ref(),
- )
- }
+ /// The linear points each effect's easing names must be live for `'a`.
+ pub(crate) unsafe fn new(effects: &'a [FfiSampledAnimationEffect]) -> Self {
+ Self(effects)
+ }
+
+ pub(crate) fn none() -> Self {
+ Self(&[])
}
+ pub(crate) fn as_slice(&self) -> &'a [FfiSampledAnimationEffect] {
+ self.0
+ }
+}
+
+/// What a sample reads of the element it samples and of the working set it samples over.
+pub(crate) struct AnimationSampleInput<'a> {
+ pub(crate) style_node: u32,
+ /// The pseudo-element sampled, or `NO_PSEUDO_ELEMENT` for the element itself.
+ pub(crate) pseudo_kind: u8,
+ pub(crate) effects: HostSampledEffects<'a>,
+ /// The working set's longhand table, which the animations compose over.
+ pub(crate) longhand_table: &'a ComputedLonghandTable,
+ /// Whether the working set held an overlay before this sample.
+ pub(crate) has_animated_overlay: bool,
+ /// The working set's color before this sample, which `currentcolor` interpolates as.
+ pub(crate) current_color: RetainedStyleValueData,
+ /// The record the host holds for the element where the working set was reconstructed from it,
+ /// which the engine builds the length contexts over, or zero where the host builds them.
+ pub(crate) style_record: u64,
+ pub(crate) stores: crate::css::animation::KeyframeStores,
+ /// The identities of the element's custom-property environment and the one it inherits, under
+ /// which values substituted against the element hold.
+ pub(crate) custom_property_environments: [u64; 2],
+ pub(crate) inheritance_parent_style_record: u64,
+ /// The document's side of the environment keyframes compute in.
+ pub(crate) environment: &'a FfiStyleComputationEnvironment,
+ /// The slot of the row of the box of the sampled element, invalid where it has none.
+ pub(crate) element_box_slot: u32,
+}
+
+/// The color of a working set, as its longhand table and its overlay hold it.
+pub(crate) fn working_set_current_color(
+ table: &ComputedLonghandTable,
+ overlay: Option<&AnimatedOverlay>,
+) -> RetainedStyleValueData {
+ table
+ .effective_value_handle(overlay, crate::css::property_metadata::property_id::COLOR, true)
+ .0
+ .clone()
+}
+
+impl AnimationSampleInput<'_> {
/// The context the effects evaluate in, resolving lengths against `length_resolution_context`
/// where there is one, and transforms against `reference_box`.
- ///
- /// # Safety
- /// As for [`Self::working_set`].
- unsafe fn animation_context(
+ fn animation_context(
&self,
length_resolution_context: Option<&FfiLengthResolutionContext>,
reference_box: Option<CssPixelRect>,
- ) -> crate::css::animation::FfiAnimationContext {
- // SAFETY: Guaranteed by the caller.
- let (table, overlay) = unsafe { self.working_set() };
+ ) -> crate::css::animation::FfiAnimationContext<'_> {
let mut context = crate::css::animation::FfiAnimationContext {
allow_discrete: length_resolution_context.is_some(),
- current_color: table
- .effective_value(overlay, crate::css::property_metadata::property_id::COLOR, true)
- .value
- .cast(),
+ current_color: Some(&self.current_color),
has_length_resolution_context: length_resolution_context.is_some(),
length_resolution_context: length_resolution_context
.map(animation_length_resolution_context)
@@ -5640,6 +5617,90 @@ impl FfiHostAnimationSample {
context.set_transform_reference_box(reference_box);
context
}
+
+ fn pseudo(&self) -> Option<u8> {
+ (self.pseudo_kind != crate::css::cascaded_properties::NO_PSEUDO_ELEMENT).then_some(self.pseudo_kind)
+ }
+}
+
+/// Whoever holds the working set a sample writes into.
+pub(crate) trait AnimationSampleHost {
+ /// Makes the working set's overlay writable and hands it over, the moment a value is written.
+ fn overlay_for_mutation(&mut self) -> &mut AnimatedOverlay;
+
+ /// The element's length-resolution contexts, with the container bases `unit_mask` asks for.
+ fn length_contexts(&mut self, unit_mask: u8) -> FfiAnimationLengthContexts;
+}
+
+/// The host's side of a sample, through the callbacks its input names.
+struct HostSampleCallbacks {
+ context: *mut c_void,
+ prepare_overlay_for_mutation: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
+ length_contexts: unsafe extern "C" fn(*mut c_void, u8, *mut FfiAnimationLengthContexts),
+}
+
+impl AnimationSampleHost for HostSampleCallbacks {
+ fn overlay_for_mutation(&mut self) -> &mut AnimatedOverlay {
+ // SAFETY: The callbacks come from a host's input, whose callback hands over the working set's overlay,
+ // uniquely owned for the sample. The overlay is borrowed for as long as this is.
+ unsafe { &mut *(self.prepare_overlay_for_mutation)(self.context).cast::<AnimatedOverlay>() }
+ }
+
+ fn length_contexts(&mut self, unit_mask: u8) -> FfiAnimationLengthContexts {
+ let mut length_contexts = std::mem::MaybeUninit::<FfiAnimationLengthContexts>::uninit();
+ // SAFETY: The callbacks come from a host's input, whose callback writes every context.
+ unsafe {
+ (self.length_contexts)(self.context, unit_mask, length_contexts.as_mut_ptr());
+ length_contexts.assume_init()
+ }
+ }
+}
+
+impl FfiHostAnimationSample {
+ /// What the sample reads, and the callbacks through which it asks the host.
+ ///
+ /// # Safety
+ /// Every pointer and callback the input names must be live for the sample, and nothing but the
+ /// sample may write the working set's overlay while it runs.
+ unsafe fn adopt(&self) -> (AnimationSampleInput<'_>, HostSampleCallbacks) {
+ // SAFETY: Guaranteed by the caller.
+ let (longhand_table, animated_overlay, effects, environment) = unsafe {
+ (
+ &*self.longhand_table.cast::<ComputedLonghandTable>(),
+ self.animated_overlay.cast::<AnimatedOverlay>().as_ref(),
+ HostSampledEffects::new(crate::css::custom_properties::ffi_slice(
+ self.effects,
+ self.effect_count,
+ )),
+ &*self.environment,
+ )
+ };
+ let input = AnimationSampleInput {
+ style_node: self.style_node,
+ pseudo_kind: self.pseudo_kind,
+ effects,
+ longhand_table,
+ has_animated_overlay: animated_overlay.is_some(),
+ current_color: working_set_current_color(longhand_table, animated_overlay),
+ style_record: self.style_record,
+ stores: crate::css::animation::KeyframeStores {
+ substitution: self.custom_property_store,
+ base: self.base_custom_property_store,
+ inheritance: self.inheritance_custom_property_store,
+ element_declares_custom_properties: self.element_declares_own_custom_properties,
+ },
+ custom_property_environments: self.custom_property_environments,
+ inheritance_parent_style_record: self.inheritance_parent_style_record,
+ environment,
+ element_box_slot: self.element_box_slot,
+ };
+ let callbacks = HostSampleCallbacks {
+ context: self.callback_context,
+ prepare_overlay_for_mutation: self.prepare_overlay_for_mutation,
+ length_contexts: self.length_contexts,
+ };
+ (input, callbacks)
+ }
}
/// Sample one element's animation effects onto its working set's overlay.
@@ -5660,19 +5721,15 @@ pub unsafe extern "C" fn rust_sample_animation_effects(
use crate::css::style::engine_calls::{document_host, with_engine_and_arena};
// SAFETY: Guaranteed by the caller.
- // SAFETY: As above.
- let host = unsafe { document_host(input.host) };
+ let (host, (sample, mut callbacks)) = unsafe { (document_host(input.host), input.adopt()) };
// The first sample of the transitions a step just started rides the style job that decided the step.
- // SAFETY: As above.
- if let Some(result) = unsafe { host.answer_fresh_transition_sample(input) } {
+ if let Some(result) = host.answer_fresh_transition_sample(&sample, &mut callbacks) {
return result;
}
- // SAFETY: As above.
- let step = with_engine_and_arena(read, host, |engine, arena| unsafe {
- sample_in_engine(input, engine, arena)
+ let step = with_engine_and_arena(read, host, |engine, arena| {
+ sample_in_engine(&sample, &mut callbacks, engine, arena)
});
- // SAFETY: As above.
- unsafe { finish_sample_with_host(input, read, step) }
+ finish_sample_with_host(&sample, &mut callbacks, host, read, step)
}
/// Sample each of `count` elements' animation effects onto its working set's overlay, as
@@ -5703,25 +5760,25 @@ pub unsafe extern "C" fn rust_sample_animation_effects_each(
// SAFETY: As above.
let host = unsafe { document_host(first.host) };
// SAFETY: As above.
+ let mut samples: Vec<_> = inputs.iter().map(|input| unsafe { input.adopt() }).collect();
let steps: Vec<_> = with_engine_and_arena(read, host, |engine, arena| {
- inputs
- .iter()
- .map(|input| unsafe { sample_in_engine(input, engine, arena) })
+ samples
+ .iter_mut()
+ .map(|(sample, callbacks)| sample_in_engine(sample, callbacks, engine, arena))
.collect()
});
- for (index, (input, step)) in inputs.iter().zip(steps).enumerate() {
+ for (index, ((sample, callbacks), step)) in samples.iter_mut().zip(steps).enumerate() {
+ let result = finish_sample_with_host(sample, callbacks, host, read, step);
// SAFETY: As above.
- unsafe { results.add(index).write(finish_sample_with_host(input, read, step)) };
+ unsafe { results.add(index).write(result) };
}
}
/// Take the sample `input` asks for as far as one call of the engine goes: to its end, or to the
/// length contexts the host builds.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`].
-unsafe fn sample_in_engine(
- input: &FfiHostAnimationSample,
+fn sample_in_engine(
+ input: &AnimationSampleInput,
+ host: &mut dyn AnimationSampleHost,
engine: &mut crate::css::style::StyleEngine,
arena: &crate::layout::LayoutNodeArena,
) -> AnimationSampleStep {
@@ -5730,66 +5787,52 @@ unsafe fn sample_in_engine(
index: input.element_box_slot,
};
let reference_box = crate::painting::ffi::committed_transform_reference_box(&arena.paintable_rows(), element_box);
- // SAFETY: Guaranteed by the caller.
- unsafe {
- let composed = host_sampled_effects(input, engine);
- match begin_animation_sample(
- input,
- engine,
- described_effects(input, engine),
- composed,
- reference_box,
- Default::default(),
- ) {
- AnimationSampleStep::Resolved(sample) => match engine_length_contexts(input, engine, &sample) {
- Some(length_contexts) => AnimationSampleStep::Sampled(finish_animation_sample(
- input,
- engine,
- sample,
- &length_contexts,
- reference_box,
- )),
- None => AnimationSampleStep::Resolved(sample),
- },
- sampled => sampled,
- }
+ let composed = host_sampled_effects(input, engine);
+ match begin_animation_sample(
+ input,
+ host,
+ engine,
+ described_effects(input, engine),
+ composed,
+ reference_box,
+ Default::default(),
+ ) {
+ AnimationSampleStep::Resolved(sample) => match engine_length_contexts(input, engine, &sample) {
+ Some(length_contexts) => AnimationSampleStep::Sampled(finish_animation_sample(
+ input,
+ host,
+ engine,
+ sample,
+ &length_contexts,
+ reference_box,
+ )),
+ None => AnimationSampleStep::Resolved(sample),
+ },
+ sampled => sampled,
}
}
/// Finish a sample one call of the engine took to `step`: building the length contexts may read
/// the engine, so the host builds them between two calls of it, over what the first one resolved.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`].
-unsafe fn finish_sample_with_host(
- input: &FfiHostAnimationSample,
+fn finish_sample_with_host(
+ input: &AnimationSampleInput,
+ host: &mut dyn AnimationSampleHost,
+ document_host: &crate::render_state::DocumentHost,
read: &crate::render_state::BegunRead,
step: AnimationSampleStep,
) -> FfiHostAnimationSampleResult {
- use crate::css::style::engine_calls::{document_host, with_engine_and_arena};
-
let sample = match step {
AnimationSampleStep::Sampled(result) => return result,
AnimationSampleStep::Resolved(sample) => sample,
};
- let mut length_contexts = std::mem::MaybeUninit::<FfiAnimationLengthContexts>::uninit();
- // SAFETY: Guaranteed by the caller. The host writes every context.
- let length_contexts = unsafe {
- (input.length_contexts)(
- input.callback_context,
- sample.resolved.container_relative_length_unit_mask,
- length_contexts.as_mut_ptr(),
- );
- length_contexts.assume_init()
- };
+ let length_contexts = host.length_contexts(sample.resolved.container_relative_length_unit_mask);
let element_box = crate::layout::node_data::NodeSlotId {
index: input.element_box_slot,
};
- // SAFETY: As above.
- with_engine_and_arena(read, unsafe { document_host(input.host) }, |engine, arena| unsafe {
+ crate::css::style::engine_calls::with_engine_and_arena(read, document_host, |engine, arena| {
let reference_box =
crate::painting::ffi::committed_transform_reference_box(&arena.paintable_rows(), element_box);
- finish_animation_sample(input, engine, sample, &length_contexts, reference_box)
+ finish_animation_sample(input, host, engine, sample, &length_contexts, reference_box)
})
}
@@ -5807,15 +5850,14 @@ enum AnimationSampleStep {
/// need a container base: resolving one marks the container asked about and, before layout, has it
/// evaluated again after.
fn engine_length_contexts(
- input: &FfiHostAnimationSample,
+ input: &AnimationSampleInput,
engine: &crate::css::style::StyleEngine,
sample: &ResolvedAnimationSample,
) -> Option<FfiAnimationLengthContexts> {
if input.style_record == 0 || sample.resolved.container_relative_length_unit_mask != 0 {
return None;
}
- let pseudo = (input.pseudo_kind != crate::css::cascaded_properties::NO_PSEUDO_ELEMENT).then_some(input.pseudo_kind);
- engine.animation_sample_length_contexts(sample.node, pseudo, input.style_record)
+ engine.animation_sample_length_contexts(sample.node, input.pseudo(), input.style_record)
}
/// A sample whose declarations are resolved, which computes its keyframe values over the element's
@@ -5830,24 +5872,19 @@ struct ResolvedAnimationSample {
/// The effects the host samples that the sample composes, each at the key its timing gives at the time
/// the host sampled its timeline, keeping each timing for a sample at another time.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`].
-unsafe fn host_sampled_effects(
- input: &FfiHostAnimationSample,
- engine: &mut crate::css::style::StyleEngine,
-) -> SampledEffects {
+fn host_sampled_effects(input: &AnimationSampleInput, engine: &mut crate::css::style::StyleEngine) -> SampledEffects {
use crate::css::animation as anim;
let Some(node) = crate::css::style::tree::StyleNodeID::from_raw(input.style_node) else {
return SampledEffects::new();
};
let slot = animation_slot(input.pseudo_kind);
- let sampled = unsafe { crate::css::custom_properties::ffi_slice(input.effects, input.effect_count) };
- sampled
+ input
+ .effects
+ .as_slice()
.iter()
.filter_map(|effect| {
- // SAFETY: The host's easings are live for the call.
+ // SAFETY: The host's easings are live for as long as its effects are borrowed.
let key = unsafe {
engine.time_element_animation_effect(
node,
@@ -5880,7 +5917,7 @@ unsafe fn host_sampled_effects(
/// The effects the engine describes for the element or pseudo-element `input` samples.
fn described_effects<'a>(
- input: &FfiHostAnimationSample,
+ input: &AnimationSampleInput,
engine: &'a crate::css::style::StyleEngine,
) -> &'a [crate::css::style::effect_descriptions::PublishedEffect] {
crate::css::style::tree::StyleNodeID::from_raw(input.style_node).map_or(&[], |node| {
@@ -5919,11 +5956,9 @@ fn implicit_will_change_properties(
/// Take a sample of `composed`, effects `descriptions` describes, as far as the style engine goes
/// without the host: to its end, or to the length contexts its keyframes compute over.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`].
-unsafe fn begin_animation_sample(
- input: &FfiHostAnimationSample,
+fn begin_animation_sample(
+ input: &AnimationSampleInput,
+ host: &mut dyn AnimationSampleHost,
engine: &crate::css::style::StyleEngine,
descriptions: &[crate::css::style::effect_descriptions::PublishedEffect],
composed: SampledEffects,
@@ -5937,8 +5972,8 @@ unsafe fn begin_animation_sample(
let Some(node) = crate::css::style::tree::StyleNodeID::from_raw(input.style_node) else {
return finished(Cleared);
};
- let pseudo = (input.pseudo_kind != crate::css::cascaded_properties::NO_PSEUDO_ELEMENT).then_some(input.pseudo_kind);
- let table = unsafe { input.working_set() }.0;
+ let pseudo = input.pseudo();
+ let table = input.longhand_table;
let (writing_mode, direction) = computed_writing_mode_and_direction(table);
let description = |identity| descriptions.iter().find(|description| description.identity == identity);
let new_implicit_will_change_properties =
@@ -5946,8 +5981,7 @@ unsafe fn begin_animation_sample(
if composed.is_empty() && new_implicit_will_change_properties.is_empty() {
return finished(Cleared);
}
- let mutated_overlay =
- unsafe { &mut *(input.prepare_overlay_for_mutation)(input.callback_context).cast::<AnimatedOverlay>() };
+ let mutated_overlay = host.overlay_for_mutation();
if composed.is_empty() {
*mutated_overlay = mutated_overlay.clone_inherited();
}
@@ -5966,33 +6000,22 @@ unsafe fn begin_animation_sample(
// A preparation the overlay already holds for exactly these effects needs no declarations and
// no keyframe values at all.
if anim::animation_preparation_matches(Some(mutated_overlay), &composed, input.custom_property_environments) {
- let batch = anim::FfiComputedAnimationBatch {
- context: unsafe { input.animation_context(None, reference_box) },
- sampled_effects: composed.as_ptr(),
- sampled_effect_count: composed.len(),
+ anim::evaluate_animations(anim::ComputedAnimationBatch {
+ context: input.animation_context(None, reference_box),
+ sampled_effects: &composed,
custom_property_environments: input.custom_property_environments,
cache_preparation: true,
preparation_reads_custom_property_environments: false,
- resolved_animation_storage: std::ptr::null_mut(),
- computed_keyframe_storage: std::ptr::null_mut(),
+ preparation_inputs: None,
underlying_longhand_table: input.longhand_table,
- overlay: unsafe { (input.prepare_overlay_for_mutation)(input.callback_context) },
- custom_underlying_values: std::ptr::null(),
- custom_initial_values: std::ptr::null(),
- custom_value_count: 0,
- custom_results: std::ptr::null_mut(),
- custom_result_count: std::ptr::null_mut(),
- };
- unsafe { anim::evaluate_animations(&batch) };
+ overlay: mutated_overlay,
+ custom_underlying_values: &[],
+ custom_initial_values: &[],
+ });
return finished(Evaluated);
}
- let stores = anim::KeyframeStores {
- substitution: input.custom_property_store,
- base: input.base_custom_property_store,
- inheritance: input.inheritance_custom_property_store,
- element_declares_custom_properties: input.element_declares_own_custom_properties,
- };
+ let stores = input.stores;
let selected: smallvec::SmallVec<[anim::SelectedEffect; 4]> = composed
.iter()
.filter_map(|composed| {
@@ -6057,11 +6080,9 @@ unsafe fn begin_animation_sample(
/// Compute a resolved sample's keyframe values over the element's length contexts, and evaluate its
/// effects onto the working set's overlay.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`].
-unsafe fn finish_animation_sample(
- input: &FfiHostAnimationSample,
+fn finish_animation_sample(
+ input: &AnimationSampleInput,
+ host: &mut dyn AnimationSampleHost,
engine: &mut crate::css::style::StyleEngine,
sample: ResolvedAnimationSample,
length_contexts: &FfiAnimationLengthContexts,
@@ -6076,7 +6097,7 @@ unsafe fn finish_animation_sample(
custom_properties,
mut result,
} = sample;
- let (table, _) = unsafe { input.working_set() };
+ let table = input.longhand_table;
// The element's own side of the environment: its place among its siblings, and the random base
// value each random function a keyframe holds draws.
@@ -6086,18 +6107,12 @@ unsafe fn finish_animation_sample(
let random_base_values = resolved
.unfixed_random_sharings
.iter()
- .map(|sharing| {
- let StyleValueData::RandomValueSharing { has_name, name, .. } = (unsafe { &*sharing.source }) else {
- unreachable!("an unfixed random sharing names its sharing value");
- };
- let name = if *has_name { name.units() } else { &[] };
- FfiRandomBaseValue {
- source: sharing.source.cast(),
- value: engine.ensure_random_base_value(Some(node), name, sharing.element_shared),
- }
+ .map(|sharing| FfiRandomBaseValue {
+ source: sharing.source.cast(),
+ value: engine.ensure_random_base_value(Some(node), &sharing.name, sharing.element_shared),
})
.collect::<Vec<_>>();
- let mut environment = unsafe { std::ptr::read(input.environment) };
+ let mut environment = *input.environment;
environment.has_tree_counting_context = sibling_position.is_some();
environment.sibling_count = sibling_position.map_or(0, |(count, _)| u64::from(count));
environment.sibling_index = sibling_position.map_or(0, |(_, index)| u64::from(index));
@@ -6121,33 +6136,17 @@ unsafe fn finish_animation_sample(
_ => Some(custom_properties.computed_value(registry, property, &finalization)),
})
.collect::<Vec<_>>();
- let custom_value_pointers = custom_values
- .iter()
- .map(|value| value.as_ref().map_or(std::ptr::null(), |value| value.pointer().cast()))
- .collect::<Vec<*const c_void>>();
let (underlying_values, initial_values) = custom_properties.underlying_and_initial_values(registry);
- let underlying_pointers = underlying_values
- .iter()
- .map(RetainedStyleValueData::pointer)
- .collect::<Vec<_>>();
- let initial_pointers = initial_values
- .iter()
- .map(RetainedStyleValueData::pointer)
- .collect::<Vec<_>>();
- let keyframe_input = FfiAnimationKeyframeLonghandInput {
- underlying_longhand_table: input.longhand_table.cast(),
- style_engine: crate::css::style::StyleEngineHandle::from_raw(engine),
- inheritance_parent_style_record: input.inheritance_parent_style_record,
- resolved_properties: resolved.properties.as_ptr().cast(),
- property_count: resolved.properties.len(),
- environment: &raw const environment,
- font_length_resolution_context: &raw const length_contexts.font,
- line_height_length_resolution_context: &raw const length_contexts.line_height,
- remaining_length_resolution_context: &raw const length_contexts.remaining,
- custom_property_values: custom_value_pointers.as_ptr(),
- };
- let computed_keyframes = unsafe { compute_animation_keyframe_longhands(&keyframe_input) };
+ let computed_keyframes = compute_animation_keyframe_longhands(
+ input.longhand_table,
+ engine,
+ input.inheritance_parent_style_record,
+ &resolved.properties,
+ &environment,
+ length_contexts,
+ &custom_values,
+ );
result.depends_on_viewport_metrics = computed_keyframes.depends_on_viewport_metrics;
result.font_metrics_depend_on_viewport_metrics = computed_keyframes.font_metrics_depend_on_viewport_metrics;
// A custom property's keyframe that asks where the element sits among its siblings makes the
@@ -6156,17 +6155,10 @@ unsafe fn finish_animation_sample(
|| resolved.properties.iter().any(|property| {
property.custom_name_id != 0
&& property.value_source == anim::FfiAnimationSpecifiedValueSource::Value
- && matches!(unsafe { &*property.value }, StyleValueData::Unresolved { components, .. }
+ && matches!(property.value.data(), StyleValueData::Unresolved { components, .. }
if crate::css::parser::value_parser::contains_tree_counting_function(components.as_slice()))
});
- let mut custom_results = (0..custom_properties.len())
- .map(|_| anim::FfiAnimatedCustomProperty {
- custom_name_id: 0,
- value: std::ptr::null(),
- })
- .collect::<Vec<_>>();
- let mut custom_result_count = 0_usize;
// A preparation cached under these effects must hold for as long as they stand, so one that
// read anything outside them is not kept, and one that substituted against the element's
// custom-property environments is kept only under those.
@@ -6175,35 +6167,26 @@ unsafe fn finish_animation_sample(
&& resolved.container_relative_length_unit_mask == 0
&& !resolved.needs_document_base_url
&& resolved.unfixed_random_sharings.is_empty();
- let batch = anim::FfiComputedAnimationBatch {
- context: unsafe { input.animation_context(Some(&length_contexts.remaining), reference_box) },
- sampled_effects: composed.as_ptr(),
- sampled_effect_count: composed.len(),
+ let custom_results = anim::evaluate_animations(anim::ComputedAnimationBatch {
+ context: input.animation_context(Some(&length_contexts.remaining), reference_box),
+ sampled_effects: &composed,
custom_property_environments: input.custom_property_environments,
cache_preparation,
preparation_reads_custom_property_environments: result.substitution_marks != 0,
- resolved_animation_storage: Box::into_raw(resolved).cast(),
- computed_keyframe_storage: computed_keyframes.storage,
+ preparation_inputs: Some(anim::AnimationPreparationInputs {
+ resolved,
+ computed_keyframe_values: computed_keyframes.values,
+ }),
underlying_longhand_table: input.longhand_table,
- overlay: unsafe { (input.prepare_overlay_for_mutation)(input.callback_context) },
- custom_underlying_values: underlying_pointers.as_ptr(),
- custom_initial_values: initial_pointers.as_ptr(),
- custom_value_count: underlying_pointers.len(),
- custom_results: custom_results.as_mut_ptr(),
- custom_result_count: &raw mut custom_result_count,
- };
- unsafe { anim::evaluate_animations(&batch) };
+ overlay: host.overlay_for_mutation(),
+ custom_underlying_values: &underlying_values,
+ custom_initial_values: &initial_values,
+ });
result.outcome = FfiHostAnimationSampleOutcome::Evaluated;
- if custom_result_count != 0 {
- let retained = custom_results[..custom_result_count]
- .iter()
- .map(|result| {
- (
- custom_properties.name(result.custom_name_id).clone(),
- // SAFETY: the evaluation transfers one reference per written result.
- unsafe { RetainedStyleValueData::from_retained_pointer(result.value) },
- )
- })
+ if !custom_results.is_empty() {
+ let retained = custom_results
+ .into_iter()
+ .map(|(custom_name_id, value)| (custom_properties.name(custom_name_id).clone(), value))
.collect::<Vec<_>>();
let rows = retained
.iter()
@@ -6229,11 +6212,9 @@ unsafe fn finish_animation_sample(
/// size, a style query, an animated custom property, a document URL or a random base value. The effects
/// are the element's, or `fresh` ones the engine does not describe yet. What a keyframe substitutes the
/// host notes as its own sample substitutes it again.
-///
-/// # Safety
-/// As for [`rust_sample_animation_effects`], with `input` naming no callback but the overlay's.
-pub(crate) unsafe fn sample_without_host(
- input: &FfiHostAnimationSample,
+pub(crate) fn sample_without_host(
+ input: &AnimationSampleInput,
+ overlay: &mut AnimatedOverlay,
engine: &mut crate::css::style::StyleEngine,
fresh: Option<&[crate::css::style::effect_descriptions::PublishedEffect]>,
composed: SampledEffects,
@@ -6242,14 +6223,20 @@ pub(crate) unsafe fn sample_without_host(
) -> Result<FfiHostAnimationSampleResult, crate::css::style::engine_sample::NeedsHost> {
use crate::css::style::engine_sample::NeedsHost;
+ let mut host = EngineSampleHost(overlay);
let descriptions = fresh.unwrap_or_else(|| described_effects(input, engine));
- // SAFETY: Guaranteed by the caller.
- let sample =
- match unsafe { begin_animation_sample(input, engine, descriptions, composed, reference_box, timeline_samples) }
- {
- AnimationSampleStep::Sampled(result) => return Ok(result),
- AnimationSampleStep::Resolved(sample) => sample,
- };
+ let sample = match begin_animation_sample(
+ input,
+ &mut host,
+ engine,
+ descriptions,
+ composed,
+ reference_box,
+ timeline_samples,
+ ) {
+ AnimationSampleStep::Sampled(result) => return Ok(result),
+ AnimationSampleStep::Resolved(sample) => sample,
+ };
if !sample.result.style_query_dependencies.is_null() {
// SAFETY: The sample transferred the dependencies it resolved to its result.
drop(unsafe {
@@ -6272,18 +6259,23 @@ pub(crate) unsafe fn sample_without_host(
{
return Err(NeedsHost);
}
- // SAFETY: As above.
- let result = unsafe { finish_animation_sample(input, engine, sample, &length_contexts, reference_box) };
+ let result = finish_animation_sample(input, &mut host, engine, sample, &length_contexts, reference_box);
debug_assert!(result.animated_custom_properties_storage.is_null());
Ok(result)
}
-/// # Safety
-/// `storage` must be returned by `compute_animation_keyframe_longhands`
-/// and must not have been consumed before.
-pub(crate) unsafe fn take_animation_keyframe_longhand_values(storage: *mut c_void) -> Vec<RetainedStyleValueData> {
- assert!(!storage.is_null());
- *unsafe { Box::from_raw(storage.cast::<Vec<RetainedStyleValueData>>()) }
+/// The engine's side of a sample without the host, which holds the overlay the sample writes, and
+/// builds the length contexts itself.
+struct EngineSampleHost<'a>(&'a mut AnimatedOverlay);
+
+impl AnimationSampleHost for EngineSampleHost<'_> {
+ fn overlay_for_mutation(&mut self) -> &mut AnimatedOverlay {
+ self.0
+ }
+
+ fn length_contexts(&mut self, _: u8) -> FfiAnimationLengthContexts {
+ unreachable!("a sample without the host builds its length contexts itself");
+ }
}
fn apply_post_compute_adjustments(
diff --git a/Libraries/LibWeb/Rust/src/css/transition.rs b/Libraries/LibWeb/Rust/src/css/transition.rs
index f1002ce5575..a1df049c22a 100644
--- a/Libraries/LibWeb/Rust/src/css/transition.rs
+++ b/Libraries/LibWeb/Rust/src/css/transition.rs
@@ -517,10 +517,11 @@ impl TransitionDecision {
let after_overlay = after_overlay.or(record_after_overlay);
let mut context = crate::css::animation::FfiAnimationContext {
allow_discrete: false,
- current_color: after_table
- .effective_value(after_overlay, crate::css::property_metadata::property_id::COLOR, true)
- .value
- .cast(),
+ current_color: Some(
+ after_table
+ .effective_value_handle(after_overlay, crate::css::property_metadata::property_id::COLOR, true)
+ .0,
+ ),
has_length_resolution_context: length_resolution_context.is_some(),
length_resolution_context: length_resolution_context.unwrap_or_default(),
has_transform_reference_box: false,
@@ -1032,21 +1033,18 @@ impl FreshTransitionSample {
/// Answers the host's sample `input`, where it samples what this one did: the transitions the step started, over
/// the record it moved its element to, each at the key this one sampled it at. Writes the overlay into the working
/// set and answers what the sample found, with the timing each effect was sampled with, which the engine keeps.
- ///
- /// # Safety
- /// As for `rust_sample_animation_effects`.
- pub(crate) unsafe fn answer(
+ pub(crate) fn answer(
self,
- input: &crate::css::style_compute::FfiHostAnimationSample,
+ input: &crate::css::style_compute::AnimationSampleInput,
+ host: &mut dyn crate::css::style_compute::AnimationSampleHost,
) -> Option<(
crate::css::style_compute::FfiHostAnimationSampleResult,
crate::css::style::animations::SampledEffectTimings,
)> {
- if input.style_record != self.after || !input.animated_overlay.is_null() {
+ if input.style_record != self.after || input.has_animated_overlay {
return None;
}
- // SAFETY: Guaranteed by the caller.
- let effects = unsafe { crate::css::custom_properties::ffi_slice(input.effects, input.effect_count) };
+ let effects = input.effects.as_slice();
if effects.len() != self.keys.len() {
return None;
}
@@ -1057,7 +1055,7 @@ impl FreshTransitionSample {
effect.identity,
crate::css::style::animations::EffectTiming {
timing: effect.timing,
- // SAFETY: As above.
+ // SAFETY: The host's easings are live for as long as its effects are borrowed.
easing: unsafe { crate::css::easing::Easing::from_descriptor(&effect.easing) },
},
)
@@ -1076,10 +1074,7 @@ impl FreshTransitionSample {
return None;
}
if self.result.outcome == crate::css::style_compute::FfiHostAnimationSampleOutcome::Evaluated {
- // SAFETY: As above.
- let overlay = unsafe { (input.prepare_overlay_for_mutation)(input.callback_context) };
- // SAFETY: The working set hands over its overlay, uniquely owned for the sample.
- unsafe { *overlay.cast::<crate::css::animated_overlay::AnimatedOverlay>() = self.overlay };
+ *host.overlay_for_mutation() = self.overlay;
}
Some((self.result, timings))
}
@@ -1557,7 +1552,7 @@ pub unsafe extern "C" fn rust_transition_has_matching_entries(
mod tests {
use super::*;
- fn animation_context() -> crate::css::animation::FfiAnimationContext {
+ fn animation_context() -> crate::css::animation::FfiAnimationContext<'static> {
let font_metrics = || crate::css::animation::FfiAnimationFontMetrics {
font_size: 0.0,
x_height: 0.0,
@@ -1567,7 +1562,7 @@ mod tests {
};
crate::css::animation::FfiAnimationContext {
allow_discrete: false,
- current_color: std::ptr::null(),
+ current_color: None,
has_length_resolution_context: false,
length_resolution_context: crate::css::animation::FfiAnimationLengthResolutionContext {
viewport_width: 0.0,
diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rs
index dff982aa1e2..5a8d6fa9d60 100644
--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs
@@ -1226,19 +1226,16 @@ impl DocumentHost {
/// Answers the sample `input` from the transaction's first sample of the transitions the step the host read last
/// started, where it is the host's sample of them, and has the engine keep the timing each was sampled with.
- ///
- /// # Safety
- /// As for `rust_sample_animation_effects`.
- pub(crate) unsafe fn answer_fresh_transition_sample(
+ pub(crate) fn answer_fresh_transition_sample(
&self,
- input: &crate::css::style_compute::FfiHostAnimationSample,
+ input: &crate::css::style_compute::AnimationSampleInput,
+ host: &mut dyn crate::css::style_compute::AnimationSampleHost,
) -> Option<crate::css::style_compute::FfiHostAnimationSampleResult> {
let (node, sample) = self.fresh_transition_sample.take()?;
if node != input.style_node || input.pseudo_kind != crate::css::cascaded_properties::NO_PSEUDO_ELEMENT {
return None;
}
- // SAFETY: Guaranteed by the caller.
- let (result, timings) = unsafe { sample.answer(input) }?;
+ let (result, timings) = sample.answer(input, host)?;
self.queue_change(ArenaChange::Engine(
crate::css::style::engine_calls::EngineWrite::AnimationEffectTimings {
node: crate::css::style::tree::StyleNodeID::from_raw(node)?,