Truly independent web browser
LibWeb: Remove the resumable font drive
Andreas Kling4373b71e5539
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rsindex ebf3013523d..a4df7f3d973 100644--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs@@ -4949,13 +4949,11 @@ pub(crate) fn with_default_seed<R>(defaults: &DefaultGroups, compute: impl FnOnc}/// The groups an element's values start from, one of each index: its parent's or the initial-/// style's, or those a writer holds a reference to, as one waiting on a font does. Written values-/// stay beside these until the group's allocation takes them, as a style struct stays borrowed until-/// it is first mutated.+/// style's. Written values stay beside these until the group's allocation takes them, as a style+/// struct stays borrowed until it is first mutated.+#[derive(Clone)]struct SeedGroups<'a> {pointers: [*const c_void; group_index::COUNT],- /// Whether these hold a reference to each group.- holds_references: bool,styles: std::marker::PhantomData<&'a StyleGroups>,}@@ -5029,27 +5027,6 @@ impl Drop for HeldGroup {}}-impl Clone for SeedGroups<'_> {- fn clone(&self) -> Self {- if self.holds_references {- for (group, &pointer) in self.pointers.iter().enumerate() {- retain_group_payload(group, pointer);- }- }- Self { ..*self }- }-}--impl Drop for SeedGroups<'_> {- fn drop(&mut self) {- if self.holds_references {- for (group, &pointer) in self.pointers.iter().enumerate() {- release_group_payload(group, pointer);- }- }- }-}-impl<'a> SeedGroups<'a> {/// The value at `place`.fn value(&self, place: LonghandPlace) -> &RetainedStyleValueData {@@ -5066,10 +5043,6 @@ impl<'a> SeedGroups<'a> {/// These groups, but with `seed` as the group at `group`.fn replace(&mut self, group: usize, seed: GroupPayloadRef<'a>) {- if self.holds_references {- retain_group_payload(group, seed.as_ptr());- release_group_payload(group, self.pointers[group]);- }self.pointers[group] = seed.as_ptr();}@@ -5466,7 +5439,6 @@ impl<'a> GroupValuesWriter<'a> {}let seeded = SeedGroups {pointers,- holds_references: false,styles: std::marker::PhantomData,};Self {@@ -5521,49 +5493,6 @@ impl<'a> GroupValuesWriter<'a> {}}- /// This writer, holding a reference to each group it borrowed, so that it outlives the- /// groups it was seeded with, as a drive waiting on a font does.- pub(crate) fn detached(self) -> GroupValuesWriter<'static> {- let Self {- seeded,- writes,- written_groups,- written_longhands,- bits,- seeded_inheritance_dependent_values,- inheritance_dependent_values,- effective_zoom,- display_before_box_type_transformation,- effective_color_scheme,- flags,- dependency_flags,- } = self;- let seeded = std::mem::ManuallyDrop::new(seeded);- if !seeded.holds_references {- for (group, &pointer) in seeded.pointers.iter().enumerate() {- retain_group_payload(group, pointer);- }- }- GroupValuesWriter {- seeded: SeedGroups {- pointers: seeded.pointers,- holds_references: true,- styles: std::marker::PhantomData,- },- writes,- written_groups,- written_longhands,- bits,- seeded_inheritance_dependent_values,- inheritance_dependent_values,- effective_zoom,- display_before_box_type_transformation,- effective_color_scheme,- flags,- dependency_flags,- }- }-fn was_written(&self, property: u16) -> bool {self.flags.is_evaluated(property)}diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs b/Libraries/LibWeb/Rust/src/css/style/bridge/records.rsindex b5f01d70a03..e966f2a7ca3 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs@@ -358,7 +358,7 @@ pub unsafe extern "C" fn style_engine_declared_only_record(if !engine.has_live_style() {return None;}- engine.declared_only_record(subject, declared).ok()+ engine.declared_only_record(subject, declared)})});record.map_or(std::ptr::null(), |record| std::sync::Arc::into_raw(record).cast())diff --git a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rsindex 56735292ec7..8792d700c5c 100644--- a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs+++ b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs@@ -64,8 +64,6 @@ define_counters! {// Physical work, including drives whose output is later abandoned.FontRefillRounds => "fontRefillRounds",FontResolutionRequests => "fontResolutionRequests",- FontRefillResumedDrives => "fontRefillResumedDrives",- FontRefillPreservedLonghands => "fontRefillPreservedLonghands",FontRefillBlockedDepth => "fontRefillBlockedDepth",EngineFullDrivesStarted => "engineFullDrivesStarted",EnginePhysicalLonghandEvaluations => "enginePhysicalLonghandEvaluations",diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rsindex 4d8069a35a2..aa163552858 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs@@ -10,7 +10,7 @@ use super::super::process_style::{InitialGroupsInputs, SharedInitialGroups};use super::super::publication::pseudo_kind;use super::super::*;use super::cascade::Winner;-use super::drive::{self, Drive, Suspension, Unanswered, drive_font_metric};+use super::drive::{self, drive_font_metric};use super::winner_store::{self, WinnerDeclaration, WinnerStore, WinnerValue, shorthand_longhand_data};use crate::css::computed_longhand_table::FONT_METRICS_DEPEND_ON_VIEWPORT_METRICS;use crate::css::computed_values::{GroupValueLayout, GroupValues, GroupValuesWriter, StyleGroupMasks};@@ -119,6 +119,14 @@ impl RootFontInputs {}}+/// What the drive of the initial values waits on, which can only be a font: they have no parent+/// and no declarations.+fn initial_drive_font_request(+ suspended_font: Option<font_resolution::FontRequest>,+) -> Box<font_resolution::FontRequest> {+ Box::new(suspended_font.expect("an unanswered initial drive waits on a font"))+}+impl RetainedState {/// The engine: the computed initial values, as an element with no declarations and no parent/// computes them, with the groups they assemble into, each holding one reference, and the@@ -128,7 +136,7 @@ impl RetainedState {pub(in crate::css::style) fn initial_style(&self,root: StyleNodeID,- ) -> Result<ComputedInitialStyle, Option<Box<font_resolution::FontRequest>>> {+ ) -> Result<ComputedInitialStyle, Box<font_resolution::FontRequest>> {let inputs = InitialGroupsInputs::of(&self.document_style_computation_inputs);match self.process_style.initial_groups_of(&inputs) {Some(shared) => self.initial_style_over(root, &shared),@@ -140,7 +148,7 @@ impl RetainedState {fn initial_style_driven(&self,root: StyleNodeID,- ) -> Result<ComputedInitialStyle, Option<Box<font_resolution::FontRequest>>> {+ ) -> Result<ComputedInitialStyle, Box<font_resolution::FontRequest>> {let subject = DriveSubject {target: computed::ComputedStyleTarget::new(root, u8::MAX),parent: None,@@ -148,7 +156,7 @@ impl RetainedState {};let store = WinnerStore::new(Vec::new());let inputs = self.document_style_computation_inputs;- let mut font_scratch = drive::FontDriveScratch::default();+ let mut suspended_font = None;// The initial values compute from nothing: from the default groups, which hold no values.crate::css::computed_values::with_default_seed(&self.process_style.default_groups, |seed| {let mut writer = GroupValuesWriter::seeded_for_child(@@ -158,11 +166,8 @@ impl RetainedState {crate::css::computed_longhand_table::LonghandTableFlags::empty(),0,);- match self.engine_full_drive(subject, &mut writer, &store, &inputs, &mut font_scratch) {- Ok(drive::DrivenValues {- length,- font: Some(font),- }) => {+ match self.engine_drive_with(self, subject, &mut writer, None, &store, &inputs, &mut suspended_font) {+ Some(drive::DrivenValues { length, font }) => {let (values, flags, dependency_flags) = writer.finish(&[]);let source = crate::css::table_group_builder::LonghandSource::Values {values: &values,@@ -207,10 +212,7 @@ impl RetainedState {font: initial_font,})}- Err(Unanswered::Suspended(Suspension::Font)) => {- Err(Some(Box::new(font_scratch.take_suspended_request())))- }- _ => Err(None),+ None => Err(initial_drive_font_request(suspended_font)),}})}@@ -221,7 +223,7 @@ impl RetainedState {&self,root: StyleNodeID,shared: &Arc<SharedInitialGroups>,- ) -> Result<ComputedInitialStyle, Option<Box<font_resolution::FontRequest>>> {+ ) -> Result<ComputedInitialStyle, Box<font_resolution::FontRequest>> {use crate::css::computed_values::StyleGroupIndex;use crate::css::table_group_builder::group_index;let subject = DriveSubject {@@ -231,7 +233,7 @@ impl RetainedState {};let store = WinnerStore::new(Vec::new());let inputs = self.document_style_computation_inputs;- let mut font_scratch = drive::FontDriveScratch::default();+ let mut suspended_font = None;let held = shared.values();let seed = crate::css::computed_values::GroupSeed::new(shared.seed_groups(), &held.value_facts);let mut writer = GroupValuesWriter::seeded_for_child(@@ -242,24 +244,16 @@ impl RetainedState {held.dependency_flags,);let selected = [0_u64; crate::css::property_metadata::LONGHAND_WORD_COUNT];- let driven = self.engine_drive_with(+ let Some(drive::DrivenValues { length, font }) = self.engine_drive_with(self,subject,&mut writer,Some(&selected),&store,&inputs,- &mut font_scratch,- );- let (length, font) = match driven {- Ok(drive::DrivenValues {- length,- font: Some(font),- }) => (length, font),- Err(Unanswered::Suspended(Suspension::Font)) => {- return Err(Some(Box::new(font_scratch.take_suspended_request())));- }- _ => return Err(None),+ &mut suspended_font,+ ) else {+ return Err(initial_drive_font_request(suspended_font));};let (values, _, _) = writer.finish(&[seed]);let source = crate::css::table_group_builder::LonghandSource::Values {@@ -399,7 +393,7 @@ impl RetainedState {target_pseudo_element: super::PseudoElementTarget,root_font: Option<RootFontInputs>,group_seeds: GroupSeeds<'_>,- ) -> Drive<ComputedElement> {+ ) -> Option<ComputedElement> {use crate::css::property_metadata::{FIRST_LONGHAND_PROPERTY_ID, LONGHAND_WORD_COUNT, property_id as prop};use crate::css::style_compute::{DIRECTION_COUNT, LOGICAL_ALIAS_BIT, PHYSICAL_TO_LOGICAL_BIT, WRITING_MODE_COUNT,@@ -418,7 +412,7 @@ impl RetainedState {parent: seeded_parent,} = group_seeds;let parent_view = match parent {- Some((parent, _)) => Some(records.assigned_record_view(parent).ok_or(Unanswered::AwaitsParent)?),+ Some((parent, _)) => Some(records.assigned_record_view(parent)?),None => None,};let parent_longhands = parent_view.as_ref().map(computed::StyleRecordView::longhands);@@ -833,28 +827,22 @@ impl RetainedState {let undrawn = store.undrawn_random_keys(self, node);if !undrawn.is_empty() {random_requests.extend(undrawn);- return Err(Unanswered::Suspended(Suspension::RandomBaseValues));+ return None;}let subject = DriveSubject {target: computed::ComputedStyleTarget::of_pseudo_element(node, target_pseudo_element),parent: parent.map(|(parent, _)| parent),facts,};- let mut font_scratch = drive::FontDriveScratch::default();- let driven = self.engine_drive_with(+ let drive::DrivenValues { length, font } = self.engine_drive_with(records,subject,&mut writer,(!drives_everything).then_some(&selected[..]),&store,&inputs,- &mut font_scratch,- );- if matches!(driven, Err(Unanswered::Suspended(Suspension::Font))) {- *suspended_font = Some(font_scratch.take_suspended_request());- }- let drive::DrivenValues { length, font } = driven?;- let font = font.expect("the style engine answers every row");+ suspended_font,+ )?;let scheme = u8::try_from(writer.effective_color_scheme()).ok();// A drive of every longhand computed the winners that compute directly too.if !drives_everything@@ -1148,7 +1136,7 @@ impl RetainedState {drop(assembled);let style_bits = values.style_bits();let value_facts = values.into_facts();- Ok(ComputedElement {+ Some(ComputedElement {flags,facts,value_facts,@@ -1670,7 +1658,7 @@ impl RetainedState {&crate::css::style_compute::FfiLengthResolutionContext,) -> bool,suspended_font: &mut Option<font_resolution::FontRequest>,- ) -> Drive<(+ ) -> Option<(crate::css::table_group_builder::FfiFontGroupBuildInputs,crate::css::style_compute::FfiLengthResolutionContext,)> {@@ -1681,7 +1669,7 @@ impl RetainedState {);let Some(resolved) = self.resolved_font(request) else {*suspended_font = Some(font_resolution::FontRequest::new(request));- return Err(Unanswered::Suspended(Suspension::Font));+ return None;};let own_length = |line_height: f64| {let font_metrics = crate::css::style_compute::FfiFontMetrics {@@ -1712,7 +1700,7 @@ impl RetainedState {unreachable!("the style engine answers every row");}let line_height = engine_sample::used_line_height(|property| values.get(property), &request, &resolved);- Ok((+ Some((engine_sample::font_group_build_inputs(|property| values.get(property), &request, line_height, &resolved),own_length(line_height),))@@ -2592,8 +2580,7 @@ fn is_logical_counterpart(property: u16, other: u16) -> bool {/// adjustments read.#[derive(Clone, Copy)]pub(in crate::css::style) struct DriveSubject {- /// What is being driven, element or pseudo-element. A drive that suspends to wait for a font- /// names it, so the suspended drive can only be resumed by the one it belongs to.+ /// What is being driven, element or pseudo-element.pub(in crate::css::style) target: computed::ComputedStyleTarget,/// The flat-tree parent the element inherits from; the document element has none and/// inherits from the initial values.diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rsindex b7dfa194225..00057bd7db7 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs@@ -14,7 +14,6 @@ use super::custom_properties::{CustomPropertyStores, DrivenWithRegisteredProperties, SubstitutingSubject, SubstitutionCache,drive_with_registered_properties,};-use super::drive::Drive;use super::records::Record;use std::sync::Arc;@@ -53,7 +52,7 @@ impl StyleEngine {&mut self,subject: StyleNodeID,declared: DeclaredOnly,- ) -> Drive<Arc<Record>> {+ ) -> Option<Arc<Record>> {let live = self.retained.live_style@@ -84,7 +83,7 @@ impl StyleEngine {.record_in_environment(&record, custom_property_environment).into_owned();record.settle_view_dependency_flags(computed::record_dependency_flags(&record.facts(), &record.payloads));- Ok(record)+ Some(record)}}@@ -99,7 +98,7 @@ impl RetainedState {node: StyleNodeID,font_requests: &mut Vec<font_resolution::FontRequest>,random_requests: &mut Vec<super::super::random_bases::RandomBaseRequest>,- ) -> Drive<Arc<Record>> {+ ) -> Option<Arc<Record>> {let initial = &live.initial;let subject = DeclaredOnlySubject { state: self, node };let substitutions = std::cell::RefCell::new(SubstitutionCache::default());@@ -137,7 +136,7 @@ impl RetainedState {initial.group_seeds(None),);font_requests.extend(suspended_font);- let mut computed = driven?;+ let mut computed = driven.ok_or(())?;let registered = self.registered_custom_property_store(node,None,@@ -148,12 +147,13 @@ impl RetainedState {random_requests,);// NB: Where base values of random functions are still to be drawn, the caller draws them and asks again.- Ok(DrivenWithRegisteredProperties {+ Ok::<_, ()>(DrivenWithRegisteredProperties {computed,registered,computes_again: false,})- })?;+ })+ .ok()?;let custom_properties = registered.unwrap_or(custom_properties);let value_of = |property| computed.groups.value(property);let counter_style_environment_identity = self.values_counter_style_environment_identity(@@ -166,7 +166,7 @@ impl RetainedState {},);let table_flags = Arc::new(computed.flags);- Ok(Arc::new(Record {+ Some(Arc::new(Record {header: super::records::RecordHeader::new(computed.facts),payloads: computed.groupsdiff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rsindex ae62b9c000e..1a166b537c9 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs@@ -45,31 +45,8 @@ impl DriveRecords for RetainedState {}}-/// Why a row has no record yet. A suspended row waits on a request the host-/// services between passes, and the same row resumes once that request is answered.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(in crate::css::style) enum Unanswered {- Suspended(Suspension),- /// The row inherits from a parent that holds no record yet: one the host styles in the same- /// update. The style pass settles the row in its next wave, once the host installed the rows- /// before it.- AwaitsParent,-}--/// What a suspended row waits on. The request itself stays where the host's service reads it.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(in crate::css::style) enum Suspension {- /// The drive's font is not resolved yet; `FontDriveScratch::request` names it.- Font,- /// A random function's base value is not drawn yet; the drive named its random caching key.- RandomBaseValues,-}--/// A row's answer from the engine, or why there is none.-pub(in crate::css::style) type Drive<T> = Result<T, Unanswered>;-/// What the monospace font-size recascade answers for a drive target.-pub(in crate::css::style) enum MonospaceRecascade {+enum MonospaceRecascade {/// The font size the recascade reaches, and whether reaching it read the viewport.Size(i32, bool),/// A length in the ancestor chain resolves against the monospace font at the size reached so@@ -77,68 +54,10 @@ pub(in crate::css::style) enum MonospaceRecascade {AwaitsFont(bridge::FfiFontResolutionRequest),}-/// Driven values, with the length context they were driven against and the font a full drive-/// resolved.+/// Driven values, with the length context they were driven against and the font the drive resolved.pub(in crate::css::style) struct DrivenValues {pub(in crate::css::style) length: crate::css::style_compute::FfiLengthResolutionContext,- pub(in crate::css::style) font: Option<crate::css::table_group_builder::FfiFontGroupBuildInputs>,-}--#[derive(Clone, Default)]-pub(in crate::css::style) struct FontDriveScratch {- request: Option<font_resolution::FontRequest>,- pending: Option<PendingFontDrive>,-}--impl FontDriveScratch {- /// Suspend the drive for `target` on a font: the request and the drive it suspends are set- /// together, so a retry always knows it resumes a drive whose entry gates passed.- fn suspend(- &mut self,- target: computed::ComputedStyleTarget,- request: bridge::FfiFontResolutionRequest,- progress: Option<DriveProgress>,- ) -> Unanswered {- self.request = Some(font_resolution::FontRequest::new(request));- self.pending = Some(PendingFontDrive { target, progress });- Unanswered::Suspended(Suspension::Font)- }-- /// The font request a drive suspended on.- pub(in crate::css::style) fn take_suspended_request(&mut self) -> font_resolution::FontRequest {- self.request- .take()- .expect("a drive suspended on a font names its request")- }-}--/// A drive left for its target's retry. No parent/context borrow survives refill; the caller-/// resumes the same subject before evaluating any later canonical element.-#[derive(Clone)]-struct PendingFontDrive {- /// What the suspended drive belongs to. The record loop can settle that element another way- /// before the retry comes, which leaves the drive behind; whoever is driven next must not- /// take up someone else's table.- target: computed::ComputedStyleTarget,- /// What the drive completed, or nothing when the monospace recascade waited on a font before- /// the drive began: the retry then starts the drive afresh.- progress: Option<DriveProgress>,-}--/// The completed font phase owns its values, holding a reference to each group they were seeded-/// from.-#[derive(Clone)]-struct DriveProgress {- root_font_complete: bool,- /// Whether the color-scheme phase ran too, as it has for a drive awaiting its registered- /// context.- color_scheme_complete: bool,- /// The monospace recascade's size the values already hold, which the remaining phases read.- recascaded_font_size: Option<i32>,- writer: GroupValuesWriter<'static>,- results: crate::css::style_compute::LonghandDriverResults,- effective_color_scheme: i16,- resolved_viewport_relative_length: bool,+ pub(in crate::css::style) font: crate::css::table_group_builder::FfiFontGroupBuildInputs,}impl RetainedState {@@ -147,7 +66,7 @@ impl RetainedState {records: &impl DriveRecords,target: computed::ComputedStyleTarget,inputs: &bridge::FfiDocumentStyleComputationInputs,- ) -> Option<MonospaceRecascade> {+ ) -> MonospaceRecascade {use crate::css::css_pixels::CssPixels;use crate::css::style_compute::{FfiFontMetrics, FfiLengthResolutionContext, FontSizeRecascadeDocumentInputs, FontSizeRecascadeStatus,@@ -254,7 +173,7 @@ impl RetainedState {font_environment_generation: inputs.font_environment_generation,};let Some(resolved) = self.resolved_font(request) else {- return Some(MonospaceRecascade::AwaitsFont(request));+ return MonospaceRecascade::AwaitsFont(request);};// NB: The ancestor's own font is the one being recascaded; its line height is the one it// inherits, or the initial font's normal line height when there is no parent.@@ -321,16 +240,12 @@ impl RetainedState {document_inputs,Some(&context),);- // The context resolves every length a cascaded font-size holds.- if batch.status == FontSizeRecascadeStatus::NeedsCppLengthResolution {- debug_assert!(false, "the recascade left a font-size length unresolved");- return None;- }+ assert!(+ batch.status != FontSizeRecascadeStatus::NeedsCppLengthResolution,+ "the context resolves every length a cascaded font-size holds"+ );}- Some(MonospaceRecascade::Size(- batch.current_size_raw,- batch.depends_on_viewport_metrics,- ))+ MonospaceRecascade::Size(batch.current_size_raw, batch.depends_on_viewport_metrics)}/// The tree scope whose `@font-feature-values` an element's `font-variant-alternates` names@@ -419,27 +334,13 @@ impl RetainedState {}}- /// Drive a record through every phase: the font phase against the parent's metrics, the- /// element's font resolved through the document's resolver, line-height and color-scheme- /// against that font, and the remaining phase with the element facts the box-type- /// transformation reads. Root-input preparation finishes only the font and line-height- /// phases and preserves them for completion.- #[allow(clippy::too_many_arguments, clippy::too_many_lines)]- pub(in crate::css::style) fn engine_full_drive(- &self,- subject: DriveSubject,- writer: &mut GroupValuesWriter<'_>,- store: &WinnerStore,- inputs: &bridge::FfiDocumentStyleComputationInputs,- font_scratch: &mut FontDriveScratch,- ) -> Drive<DrivenValues> {- self.engine_drive_with(self, subject, writer, None, store, inputs, font_scratch)- }-- /// Drive a record as [`Self::engine_full_drive`] does, into `writer`, reading the records it- /// computes against from `records`. With a `selected` set of longhands, the drive evaluates- /// only those, beside the inputs every drive evaluates, and keeps the writer's values for the- /// rest.+ /// Drive a record through every phase, into `writer`, reading the records it computes against+ /// from `records`: the font phase against the parent's metrics, the element's font resolved+ /// through the document's resolver, line-height and color-scheme against that font, and the+ /// remaining phase with the element facts the box-type transformation reads. With a `selected`+ /// set of longhands, the drive evaluates only those, beside the inputs every drive evaluates,+ /// and keeps the writer's values for the rest. Answers nothing where the parent holds no record+ /// yet or where the drive waits on a font, which `suspended_font` then names.#[allow(clippy::too_many_arguments, clippy::too_many_lines)]pub(in crate::css::style) fn engine_drive_with(&self,@@ -449,8 +350,8 @@ impl RetainedState {selected: Option<&[u64]>,store: &WinnerStore,inputs: &bridge::FfiDocumentStyleComputationInputs,- font_scratch: &mut FontDriveScratch,- ) -> Drive<DrivenValues> {+ suspended_font: &mut Option<font_resolution::FontRequest>,+ ) -> Option<DrivenValues> {let random_base_values = store.drive_random_base_values(self, subject.target.node()).expect("a random function's base values are drawn before the row is driven");@@ -478,39 +379,25 @@ impl RetainedState {// the whole ancestor chain against a 13px default instead of the 16px one, which// changes what a keyword size an ancestor declared means.let mut recascaded_font_size_reads_viewport = false;- let recascaded_font_size = if let Some(progress) = font_scratch- .pending- .as_ref()- .filter(|pending| pending.target == target)- .and_then(|pending| pending.progress.as_ref())- {- progress.recascaded_font_size- } else if store+ let recascaded_font_size = if store.winning_declaration(prop::FONT_FAMILY).is_some_and(|(value, ..)| font_family_is_monospace(value.data())){match self.monospace_recascaded_font_size_with(records, target, inputs) {- Some(MonospaceRecascade::Size(recascaded, reads_viewport)) => {+ MonospaceRecascade::Size(recascaded, reads_viewport) => {recascaded_font_size_reads_viewport = reads_viewport;Some(recascaded)}- Some(MonospaceRecascade::AwaitsFont(request)) => {- return Err(font_scratch.suspend(target, request, None));- }- None => {- unreachable!("the style engine answers every row");+ MonospaceRecascade::AwaitsFont(request) => {+ *suspended_font = Some(font_resolution::FontRequest::new(request));+ return None;}}} else {None};let parent_view = match parent {- Some(parent) => {- let Some(parent_view) = records.assigned_record_view(parent) else {- return Err(Unanswered::AwaitsParent);- };- Some(parent_view)- }+ Some(parent) => Some(records.assigned_record_view(parent)?),None => None,};// The document element inherits from the initial values and resolves its font against@@ -630,8 +517,6 @@ impl RetainedState {default_font_size_raw: inputs.default_font_size_raw,root_effective_zoom: inputs.root_effective_zoom,};- let mut resolved_viewport_relative_length = false;- let resolved_viewport_relative_length_pointer = &raw mut resolved_viewport_relative_length;// The root metrics a phase resolves against: the document's, except for the document// element itself, whose font phase reads the initial font and whose line-height phase// reads its own font; its remaining phase reads the document's metrics as they stand,@@ -654,7 +539,7 @@ impl RetainedState {container_width_basis_depends_on_viewport_metrics: false,container_height_basis_depends_on_viewport_metrics: false,subject_inline_axis_is_horizontal,- resolved_viewport_relative_length: resolved_viewport_relative_length_pointer,+ resolved_viewport_relative_length: std::ptr::null_mut(),zoom: 1.0,};if let Some(bases) = &container_unit_bases {@@ -662,33 +547,9 @@ impl RetainedState {}length};- // A drive another row left behind is dropped rather than taken up.- let resumed = font_scratch- .pending- .take()- .filter(|pending| pending.target == target)- .and_then(|pending| pending.progress);- let resuming = resumed.is_some();- let root_font_complete = resumed.as_ref().is_some_and(|pending| pending.root_font_complete);- let color_scheme_complete = resumed.as_ref().is_some_and(|pending| pending.color_scheme_complete);- if !resuming {- self.counters.bump(Counter::EngineFullDrivesStarted);- }- let (mut results, mut effective_color_scheme) = match resumed {- Some(pending) => {- resolved_viewport_relative_length = pending.resolved_viewport_relative_length;- if !pending.root_font_complete {- self.counters.bump(Counter::FontRefillResumedDrives);- self.counters.add(- Counter::FontRefillPreservedLonghands,- u64::from(pending.results.longhand_evaluations),- );- }- *writer = pending.writer;- (pending.results, pending.effective_color_scheme)- }- None => (empty_longhand_driver_results(), -1),- };+ self.counters.bump(Counter::EngineFullDrivesStarted);+ let mut results = empty_longhand_driver_results();+ let mut effective_color_scheme = -1;let drive = |counters: &Counters,writer: &mut GroupValuesWriter<'_>,results: &mut crate::css::style_compute::LonghandDriverResults,@@ -726,35 +587,33 @@ impl RetainedState {inputs.root_font_metrics_depend_on_viewport_metrics,)};- if !resuming {- // The recascaded size stands in for the element's cascaded `font-size`, which the drive- // then leaves alone, exactly as C++ writes it into the working set before driving. An- // element that declares its own `font-size` still has that declaration win, because the- // drive reads a winning declaration before it consults this.- if let Some(recascaded) = recascaded_font_size {- writer.set_computed(- prop::FONT_SIZE,- StyleValueData::Length {- value: CssPixels::from_raw(recascaded).to_double(),- unit: crate::css::style_compute::px_length_unit(),- },- );- }- drive(- &self.counters,- writer,- &mut results,- &mut effective_color_scheme,- LONGHAND_DRIVE_PHASE_FONT,- Some(&font_length),- None,+ // The recascaded size stands in for the element's cascaded `font-size`, which the drive+ // then leaves alone, exactly as C++ writes it into the working set before driving. An+ // element that declares its own `font-size` still has that declaration win, because the+ // drive reads a winning declaration before it consults this.+ if let Some(recascaded) = recascaded_font_size {+ writer.set_computed(+ prop::FONT_SIZE,+ StyleValueData::Length {+ value: CssPixels::from_raw(recascaded).to_double(),+ unit: crate::css::style_compute::px_length_unit(),+ },);- // A recascaded size that read the viewport makes the element's style and font metrics- // read it, as C++ marks them beside the size it writes.- if recascaded_font_size_reads_viewport {- results.depends_on_viewport_metrics = true;- results.font_metrics_depend_on_viewport_metrics = true;- }+ }+ drive(+ &self.counters,+ writer,+ &mut results,+ &mut effective_color_scheme,+ LONGHAND_DRIVE_PHASE_FONT,+ Some(&font_length),+ None,+ );+ // A recascaded size that read the viewport makes the element's style and font metrics+ // read it, as C++ marks them beside the size it writes.+ if recascaded_font_size_reads_viewport {+ results.depends_on_viewport_metrics = true;+ results.font_metrics_depend_on_viewport_metrics = true;}// The element's own font, resolved as the C++ font computer would for these values.@@ -765,16 +624,8 @@ impl RetainedState {);let font_size = request.font_size();let Some(resolved) = self.resolved_font(request) else {- let progress = DriveProgress {- root_font_complete: false,- color_scheme_complete: false,- recascaded_font_size,- writer: writer.clone().detached(),- results,- effective_color_scheme,- resolved_viewport_relative_length,- };- return Err(font_scratch.suspend(target, request, Some(progress)));+ *suspended_font = Some(font_resolution::FontRequest::new(request));+ return None;};if request.font_size_adjust == bridge::FontSizeAdjustKind::FromFont {writer.set_computed(@@ -805,31 +656,27 @@ impl RetainedState {inputs.root_font_metrics_depend_on_viewport_metrics,)};- if !root_font_complete {- drive(- &self.counters,- writer,- &mut results,- &mut effective_color_scheme,- LONGHAND_DRIVE_PHASE_LINE_HEIGHT,- Some(&line_height_length),- None,- );- }+ drive(+ &self.counters,+ writer,+ &mut results,+ &mut effective_color_scheme,+ LONGHAND_DRIVE_PHASE_LINE_HEIGHT,+ Some(&line_height_length),+ None,+ );let line_height_before_adjustments =engine_sample::used_line_height(|property| Some(writer.effective_value(property)), &request, &resolved);- if !color_scheme_complete {- drive(- &self.counters,- writer,- &mut results,- &mut effective_color_scheme,- LONGHAND_DRIVE_PHASE_COLOR_SCHEME,- None,- None,- );- }+ drive(+ &self.counters,+ writer,+ &mut results,+ &mut effective_color_scheme,+ LONGHAND_DRIVE_PHASE_COLOR_SCHEME,+ None,+ None,+ );effective_color_scheme = writer.effective_color_scheme();let remaining_length = length_context(@@ -873,13 +720,9 @@ impl RetainedState {let values = |property| Some(writer.effective_value(property));let line_height_used_after = engine_sample::used_line_height(values, &request, &resolved);let font = engine_sample::font_group_build_inputs(values, &request, line_height_used_after, &resolved);- let length = FfiLengthResolutionContext {- resolved_viewport_relative_length: std::ptr::null_mut(),- ..remaining_length- };- Ok(DrivenValues {- length,- font: Some(font),+ Some(DrivenValues {+ length: remaining_length,+ font,})}}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rsindex 14519c242de..eb88a2a63ab 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs@@ -237,12 +237,11 @@ impl StyleEngine {}// NB: An engine no host published its fonts to yet, such as a test's bare engine, has no resolver// to ask, and its initial style waits on fonts it cannot resolve yet.- Err(Some(_)) if engine.host.font_resolver.is_none() => Ok(None),- Err(Some(request)) => Err(Waits {+ Err(_) if engine.host.font_resolver.is_none() => Ok(None),+ Err(request) => Err(Waits {fonts: vec![*request],random_bases: Vec::new(),}),- Err(None) => Ok(None),}}).flatten()diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rsindex fb278481d87..dfcc84da98d 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs@@ -1403,7 +1403,7 @@ impl<'a> Scratch<'a> {if let Some(request) = suspended_font {self.statistics.font_requests.push(request);}- let Ok(mut computed) = driven else {+ let Some(mut computed) = driven else {return Err(match self.pseudo_element_waits(node, requested) {true => PseudoElementOutcome::Waiting,false => PseudoElementOutcome::Declined,@@ -1438,7 +1438,7 @@ impl<'a> Scratch<'a> {group_seeds,);computed.reads.display_none_is_animated = ignoring_animations- .is_ok_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));+ .is_some_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));}let registered = state.registered_custom_property_store(node,@@ -1824,7 +1824,7 @@ impl<'a> Scratch<'a> {self.statistics.font_requests.push(request);}self.waits(node, requested);- let Ok(mut computed) = driven else {+ let Some(mut computed) = driven else {return Err(Outcome::ComputeDeclined);};computed.element_dependent |= custom_properties_read_subject;@@ -1861,7 +1861,7 @@ impl<'a> Scratch<'a> {group_seeds,);computed.reads.display_none_is_animated = ignoring_animations- .is_ok_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));+ .is_some_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));}let registered = state.registered_custom_property_store(node,diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex 96ae77d43d7..d5498dbe174 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -3612,7 +3612,6 @@ fn keyframe_parent_snapshot_of_record(}/// Results of one longhand drive that remain outside the Rust longhand table.-#[derive(Clone)]pub struct LonghandDriverResults {/// Longhands whose specified-to-computed evaluation ran in this drive.pub longhand_evaluations: u32,