Truly independent web browser
LibWeb: Tell animation samples apart by what they animate
Andreas Klinge58285a3d76d
diff --git a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs b/Libraries/LibWeb/Rust/src/css/animated_overlay.rsindex 353317df19f..513dbf0d1a2 100644--- a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs+++ b/Libraries/LibWeb/Rust/src/css/animated_overlay.rs@@ -142,6 +142,20 @@ impl AnimatedOverlay {&self.entries}+ /// A hash of what the overlay animates, which overlays holding the same values hash alike, in whatever order they+ /// hold them.+ pub(crate) fn content_hash(&self) -> u64 {+ use std::hash::Hasher;+ self.entries.iter().fold(0, |hash: u64, entry| {+ let mut hasher = crate::css::style::fast_hash::fast_hasher();+ hasher.write_u16(entry.property);+ hasher.write_u64(crate::css::style_value::style_value_content_hash(+ entry.value_handle().optional_data(),+ ));+ hash.wrapping_add(hasher.finish())+ })+ }+pub(crate) fn get(&self, property: u16) -> Option<&FfiAnimatedOverlayEntry> {self.entries.iter().find(|entry| entry.property == property)}diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rsindex 9d171f3a65b..f39a5f055fc 100644--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs@@ -1085,14 +1085,15 @@ impl ComputedGroupSets {FinalStyleRecordID::installed(self.installed.install(record, dependency_flags))}- /// Take a slot for a record derived for what no element is, or answer one holding the same.- /// `dependency_flags` says what the view of a record in a new slot depends on.+ /// Take a slot for a record derived for what no element is, or answer one holding the same, found with `key_salt`+ /// as [`InstalledRecords::install_derived`] finds it. `dependency_flags` says what the view of a record in a new slot depends on.pub(super) fn install_derived_record(&mut self,record: &std::sync::Arc<super::pipeline::Record>,+ key_salt: u64,dependency_flags: impl FnOnce() -> u8,) -> FinalStyleRecordID {- FinalStyleRecordID::installed(self.installed.install_derived(record, dependency_flags))+ FinalStyleRecordID::installed(self.installed.install_derived(record, key_salt, dependency_flags))}/// The identity `record` holds already, if it holds one.@@ -1969,7 +1970,7 @@ mod tests {pseudo_element_styles,)).with_test_dependency_flags(dependency_flags);- sets.install_derived_record(&record, || 0)+ sets.install_derived_record(&record, 0, || 0)}/// Assigns `target` a record installed as [`install`] installs it.diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rsindex 222f4ad7031..fe9279b31fb 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs@@ -542,7 +542,7 @@ impl super::StyleEngine {return Err(NeedsHost);}// The sample holds the longhands of the record it composes over, as the host's does.- let sampled = self.install_record_derived(&base, groups, None);+ let sampled = self.install_sample_record(&base, groups, overlay.content_hash());release_rebuilt_overlay_payloads(&payloads, rebuilt.groups);Ok(super::layout_style::DerivedStyleRecord::pin(self, sampled.raw()))}diff --git a/Libraries/LibWeb/Rust/src/css/style/installed_records.rs b/Libraries/LibWeb/Rust/src/css/style/installed_records.rsindex c782bf64d2f..472d5c74e9f 100644--- a/Libraries/LibWeb/Rust/src/css/style/installed_records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/installed_records.rs@@ -177,10 +177,13 @@ impl InstalledRecords {}/// The identity the record `record`, derived for what no element is, is installed under: that of a slot holding- /// the same, or a new slot as [`Self::install`] takes.+ /// the same, or a new slot as [`Self::install`] takes. `key_salt` goes into the key the record is found under, as the+ /// hash of what a sample animates does: the longhands of a sample are those of the record it composes over, so its+ /// samples would all share one key, of which a task that sees no sweep can gather many.pub(super) fn install_derived(&mut self,record: &Arc<Record>,+ key_salt: u64,dependency_flags: impl FnOnce() -> u8,) -> InstalledRecordID {if let Some(id) = self.named_by(record) {@@ -188,7 +191,7 @@ impl InstalledRecords {}// NB: The key reads a few longhands, so records that differ in others share it: each takes the next key free. A// sweep can open a gap in such a run, which costs a record past it no more than a slot of its own.- let mut content_key = Self::content_key(record);+ let mut content_key = Self::content_key(record) ^ key_salt;while let Some(&slot) = self.derived_by_content.get(&content_key) {if self.slots[slot.index()].as_ref()@@ -351,12 +354,29 @@ mod tests {#[test]fn derived_records_whose_content_shares_a_key_each_keep_a_slot() {let mut records = InstalledRecords::default();- let first = records.install_derived(&record(1), || 0);- let second = records.install_derived(&record(2), || 0);+ let first = records.install_derived(&record(1), 0, || 0);+ let second = records.install_derived(&record(2), 0, || 0);assert_ne!(first, second);- assert_eq!(records.install_derived(&record(1), || 0), first);- assert_eq!(records.install_derived(&record(2), || 0), second);+ assert_eq!(records.install_derived(&record(1), 0, || 0), first);+ assert_eq!(records.install_derived(&record(2), 0, || 0), second);+ }++ #[test]+ fn samples_are_found_under_the_hash_of_what_they_animate() {+ let mut records = InstalledRecords::default();+ let first = records.install_derived(&record(1), 1, || 0);+ let second = records.install_derived(&record(2), 2, || 0);++ assert_ne!(first, second);+ // NB: The two records hash alike by their longhands, so each takes the key its overlay hash mixes in, and+ // neither probes past the other.+ let content_key = InstalledRecords::content_key(&record(1));+ assert_eq!(InstalledRecords::content_key(&record(2)), content_key);+ assert_eq!(records.derived_by_content.get(&(content_key ^ 1)), Some(&first.slot));+ assert_eq!(records.derived_by_content.get(&(content_key ^ 2)), Some(&second.slot));+ assert_eq!(records.install_derived(&record(1), 1, || 0), first);+ assert_eq!(records.install_derived(&record(2), 2, || 0), second);}#[test]diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rsindex 5510f0a7758..b166fa5bb0d 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs@@ -1002,7 +1002,7 @@ mod tests {state.custom_property_environments.adopt_engine_environment(store.clone(), None, 0, None, registry);- let installed = state.computed_group_sets.install_derived_record(&record, || {+ let installed = state.computed_group_sets.install_derived_record(&record, 0, || {computed::record_dependency_flags(&record.facts(), &record.payloads)});state.computed_group_sets.assign_installed_record(nodes[0], installed);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rsindex 325c7bae0e6..86650c7b46e 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs@@ -1165,7 +1165,7 @@ impl RetainedState {.map(|live| live.initial.clone()).expect("a style the host made inherits from one a pass styled");let record = Record::of_initial(&initial, payloads, counter_style_environment_identity);- self.install_new_record(Arc::new(record))+ self.install_new_record(Arc::new(record), 0)}/// Install the record of a style derived from that of the record `source` is or composes@@ -1196,11 +1196,23 @@ impl RetainedState {rare.counter_style_environment_identity = identity;}}));- self.install_new_record(record)+ self.install_new_record(record, 0)}- fn install_new_record(&mut self, record: Arc<Record>) -> computed::FinalStyleRecordID {- self.computed_group_sets.install_derived_record(&record, || {+ /// Install the record of a sample composed over `source`, holding `payloads`, found by `overlay_hash`, the hash of+ /// what the sample animates, and answer its identity. Nothing holds the record yet: the next sweep frees it unless+ /// a holder pins it first.+ pub(in super::super) fn install_sample_record(+ &mut self,+ source: &Record,+ payloads: &crate::css::computed_values::StyleGroups,+ overlay_hash: u64,+ ) -> computed::FinalStyleRecordID {+ self.install_new_record(Arc::new(Record::derived(source, payloads)), overlay_hash)+ }++ fn install_new_record(&mut self, record: Arc<Record>, key_salt: u64) -> computed::FinalStyleRecordID {+ self.computed_group_sets.install_derived_record(&record, key_salt, || {computed::record_dependency_flags(&record.facts(), &record.payloads)})}diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex 4c2c6ac9a2b..8fa51ba8bf4 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -566,7 +566,7 @@ impl RetainedState {.unwrap_or_else(|| self.default_groups().groups().clone());let record = std::sync::Arc::new(super::pipeline::Record::derived(&source, &payloads)).with_pseudo_element_styles(super::pipeline::PseudoElementStyles::from_bits(pseudo_element_styles));- let identity = self.computed_group_sets.install_derived_record(&record, || {+ let identity = self.computed_group_sets.install_derived_record(&record, 0, || {computed::record_dependency_flags(&record.facts(), &record.payloads)});match target.is_pseudo() {