Truly independent web browser
LibWeb+LibCompositing: Record glyph runs without copying their glyphs
Aliaksandr Kalenikc1e8ad6d3cc0
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rsindex 6843cecd09f..2b8a24cbede 100644--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs@@ -565,6 +565,15 @@ pub struct DisplayListGlyph {}ffi_bytes_fields!(DisplayListGlyph { position, glyph_id });+impl From<&text_layout::DrawGlyph> for DisplayListGlyph {+ fn from(glyph: &text_layout::DrawGlyph) -> Self {+ Self {+ position: FloatPoint { x: glyph.x, y: glyph.y },+ glyph_id: glyph.glyph_id,+ }+ }+}+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]#[repr(u8)]pub enum CompositorScrollNodeKind {diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rsindex a6574893a03..3602124b949 100644--- a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs+++ b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs@@ -246,10 +246,10 @@ pub struct StrokePathParams<'a> {pub should_anti_alias: ShouldAntiAlias,}-pub struct GlyphRunForRecording<'a> {+pub struct GlyphRunForRecording<Glyphs: IntoIterator<Item = DisplayListGlyph>> {pub font_smoothing: u8,pub font_id: FontResourceId,- pub glyphs: &'a [DisplayListGlyph],+ pub glyphs: Glyphs,}pub struct IsolatedGroupEffects {@@ -1054,7 +1054,7 @@ impl DisplayListRecorder {pub fn draw_glyph_run(&mut self,baseline_start: FloatPoint,- run: GlyphRunForRecording<'_>,+ run: GlyphRunForRecording<impl IntoIterator<Item = DisplayListGlyph>>,color: Color,rect: IntRect,scale: f64,@@ -1067,7 +1067,7 @@ impl DisplayListRecorder {}let color = self.resolve_color(color, force_dark_role);let mut payload = CommandPayloadBuilder::new::<DrawGlyphRun>(&self.builder);- let glyphs = payload.append_objects(run.glyphs.iter().copied());+ let glyphs = payload.append_objects(run.glyphs);let command = DrawGlyphRun {font_smoothing: run.font_smoothing,font_id: run.font_id,@@ -1133,13 +1133,13 @@ impl DisplayListRecorder {shadows_bounding_rect: IntRect,rect: IntRect,translation: FloatPoint,- run: GlyphRunForRecording<'_>,+ run: GlyphRunForRecording<impl IntoIterator<Item = DisplayListGlyph>>,glyph_run_scale: f64,orientation: Orientation,force_dark_role: ForceDarkRole,) {let mut payload = CommandPayloadBuilder::new::<PaintTextShadow>(&self.builder);- let glyphs = payload.append_objects(run.glyphs.iter().copied());+ let glyphs = payload.append_objects(run.glyphs);let layers = payload.append_objects(layers.iter().map(|layer| TextShadowLayer {color: self.resolve_color(layer.color, force_dark_role),..*layerdiff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/background.rsindex 14903d77845..4c18aee0e13 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs@@ -1036,7 +1036,10 @@ fn append_text_clip_paths<O: Observer>(recorder: &mut PaintRecorder<'_, O>, pain.inherited_text().font_smoothing,font_id: crate::painting::display_list::commands::FontResourceId(font_id),- glyphs: &emission.glyphs,+ glyphs: run+ .glyphs+ .iter()+ .map(crate::painting::display_list::commands::DisplayListGlyph::from),},libgfx_rust::Color::from_rgb(0, 0, 0),fragment_absolute_device_rect,diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/inspector_overlay.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/inspector_overlay.rsindex 90040b20aeb..137db897c61 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/inspector_overlay.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/inspector_overlay.rs@@ -470,7 +470,7 @@ struct OverlayLabel {device_ascent: f32,device_descent: f32,blob_bounds: [f32; 4],- glyphs: Vec<DisplayListGlyph>,+ glyphs: libgfx_rust::text_layout::GlyphBuffer,}fn shape_overlay_label<O: Observer>(@@ -492,14 +492,6 @@ fn shape_overlay_label<O: Observer>(let device_ascent = device_font.facts().ascent;let device_descent = device_font.facts().descent;let font_id = recorder.register_font(device_font);- let glyphs = shaped- .glyphs()- .iter()- .map(|glyph| DisplayListGlyph {- position: FloatPoint { x: glyph.x, y: glyph.y },- glyph_id: glyph.glyph_id,- })- .collect();OverlayLabel {font_id,css_width: css_font.measure_text_width(text),@@ -508,7 +500,7 @@ fn shape_overlay_label<O: Observer>(device_ascent,device_descent,blob_bounds,- glyphs,+ glyphs: shaped.into_glyphs(),}}@@ -538,7 +530,7 @@ fn draw_label<O: Observer>(recorder: &mut PaintRecorder<'_, O>, label: &OverlayLGlyphRunForRecording {font_smoothing: crate::css::css_enums::font_smoothing::AUTO,font_id: FontResourceId(label.font_id),- glyphs: &label.glyphs,+ glyphs: label.glyphs.iter().map(DisplayListGlyph::from),},color,rect,diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/math.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/math.rsindex 50e2c848f05..a797ef1b5b4 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/math.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/math.rs@@ -59,24 +59,19 @@ pub(crate) fn paint_foreground<O: Observer>(let font_id = recorder.register_font(&run.font);// NB: Display list glyphs are positioned by the top of the font's ascent rather than by their baseline.let ascent = run.font.facts().ascent;- let glyphs: Vec<DisplayListGlyph> = run- .glyphs- .iter()- .map(|glyph| DisplayListGlyph {- position: FloatPoint {- x: glyph.x,- y: glyph.y - ascent,- },- glyph_id: glyph.glyph_id,- })- .collect();let ink_rect = converter.enclosing_device_rect(run.ink_bounds.translated_by(content_box.location()));recorder.recorder.draw_glyph_run(origin,GlyphRunForRecording {font_smoothing,font_id: FontResourceId(font_id),- glyphs: &glyphs,+ glyphs: run.glyphs.iter().map(|glyph| DisplayListGlyph {+ position: FloatPoint {+ x: glyph.x,+ y: glyph.y - ascent,+ },+ glyph_id: glyph.glyph_id,+ }),},glyph_color,ink_rect,diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/text.rsindex ae1c575fdfb..7343fa7abaa 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs@@ -17,6 +17,7 @@ use crate::painting::record::PaintRecorder;use crate::painting::record::inputs::CaretTarget;use crate::painting::selection::{HighlightPseudoElement, SelectionRange};use crate::painting::text_fragment::{self, SelectionOffsets};+use libgfx_rust::text_layout::DrawGlyph;use libgfx_rust::{Color, FloatPoint, IntPoint, IntRect, Orientation};use std::sync::Arc;@@ -362,18 +363,7 @@ fn compute_render_spans<O: Observer>(spans}-fn glyphs_of(run: &crate::painting::paintable_data::GlyphRunRecord) -> Vec<DisplayListGlyph> {- run.glyphs- .iter()- .map(|glyph| DisplayListGlyph {- position: FloatPoint { x: glyph.x, y: glyph.y },- glyph_id: glyph.glyph_id,- })- .collect()-}-pub(crate) struct GlyphRunEmission {- pub glyphs: Vec<DisplayListGlyph>,pub baseline_start: FloatPoint,pub orientation: Orientation,pub glyph_bounding_rect: IntRect,@@ -420,7 +410,6 @@ pub(crate) fn glyph_run_emission(Orientation::Vertical => vertical_glyph_bounds(horizontal_bounds, fragment_device_rect),};GlyphRunEmission {- glyphs: glyphs_of(run),baseline_start,orientation,glyph_bounding_rect,@@ -547,14 +536,13 @@ fn paint_text_shadow<O: Observer>(let fragment_device_rect = converter.enclosing_device_rect(fragment_absolute_rect);let font_id = recorder.register_font(&run.font);let GlyphRunEmission {- glyphs,baseline_start,orientation,..} = glyph_run_emission(fragment, run, fragment_absolute_rect, fragment_device_rect, scale);// If this is a partial span, slice the glyph run to only include the relevant glyphs.- let mut span_glyphs = glyphs.as_slice();+ let mut span_glyphs: &[DrawGlyph] = &run.glyphs;if span.start_code_unit != 0 || span.end_code_unit != fragment.length_in_code_units {let mut start_glyph = 0usize;let mut glyph_count = 0usize;@@ -570,7 +558,7 @@ fn paint_text_shadow<O: Observer>(}}if glyph_count > 0 {- span_glyphs = &glyphs[start_glyph..start_glyph + glyph_count];+ span_glyphs = &run.glyphs[start_glyph..start_glyph + glyph_count];}}@@ -622,7 +610,7 @@ fn paint_text_shadow<O: Observer>(.inherited_text().font_smoothing,font_id: FontResourceId(font_id),- glyphs: span_glyphs,+ glyphs: span_glyphs.iter().map(DisplayListGlyph::from),},scale,orientation,@@ -680,7 +668,6 @@ fn paint_text_fragment<O: Observer>(let fragment_device_rect = converter.enclosing_device_rect(fragment_absolute_rect);let font_id = recorder.register_font(&run.font);let GlyphRunEmission {- glyphs,baseline_start,orientation,glyph_bounding_rect,@@ -693,7 +680,7 @@ fn paint_text_fragment<O: Observer>(.inherited_text().font_smoothing,font_id: FontResourceId(font_id),- glyphs: &glyphs,+ glyphs: run.glyphs.iter().map(DisplayListGlyph::from),};// Paint text, clipped to span range if not full fragment.