fonts: Simplify FontContext in two ways that affect the unit test (#33541)

This is done by no longer forwarding compositor-bound messages through
SystemFontService and making `FontContext` non-generic:

- Messages from the `FontContext` to the `Compositor` no longer need to be
  forwarded through the `SystemFontService`. Instead send these messages
  directly through the script IPC channel to the `Compositor`.

- Instead of adding a mock `SystemFontServiceProxy`, simply implement a
  mock `SystemFontService` on the other side of an IPC channel in the
  `font_context` unit test. This allows making `FontContext`
  non-generic, greatly simplifying the code. The extra complexity moves
  into the unit test.

These changes necessitate adding a new kind of `FontIdentifier`,
`FontIdentifier::Mock` due to the fact that local fonts have
platform-specific identifiers. This avoids having to pretend like the
system font service can have web fonts -- which was always a bit of a
hack.

These two changes are combined into one PR because they both require
extensive and similar chages in the font_context unit test which
dependended on the details of both of them.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-09-25 22:15:47 +02:00 committed by GitHub
parent 1daa0b4fc7
commit ac567645a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 482 additions and 425 deletions

View file

@ -11,7 +11,7 @@ use std::thread;
use base::id::PipelineId;
use fnv::FnvHasher;
use fonts::{FontContext, SystemFontServiceProxy};
use fonts::FontContext;
use net_traits::image_cache::{
ImageCache, ImageCacheResult, ImageOrMetadataAvailable, UsePlaceholder,
};
@ -24,8 +24,6 @@ use style::context::{RegisteredSpeculativePainter, SharedStyleContext};
use crate::display_list::items::{OpaqueNode, WebRenderImageInfo};
pub type LayoutFontContext = FontContext<SystemFontServiceProxy>;
type WebrenderImageCache =
HashMap<(ServoUrl, UsePlaceholder), WebRenderImageInfo, BuildHasherDefault<FnvHasher>>;
@ -44,7 +42,7 @@ pub struct LayoutContext<'a> {
pub image_cache: Arc<dyn ImageCache>,
/// A FontContext to be used during layout.
pub font_context: Arc<FontContext<SystemFontServiceProxy>>,
pub font_context: Arc<FontContext>,
/// A cache of WebRender image info.
pub webrender_image_cache: Arc<RwLock<WebrenderImageCache>>,

View file

@ -11,7 +11,7 @@ use app_units::{Au, MIN_AU};
use base::print_tree::PrintTree;
use bitflags::bitflags;
use euclid::default::{Point2D, Rect, Size2D};
use fonts::FontMetrics;
use fonts::{FontContext, FontMetrics};
use log::debug;
use range::{int_range_index, Range, RangeIndex};
use script_layout_interface::wrapper_traits::PseudoElementType;
@ -33,7 +33,7 @@ use style::values::specified::text::TextOverflowSide;
use unicode_bidi as bidi;
use crate::block::AbsoluteAssignBSizesTraversal;
use crate::context::{LayoutContext, LayoutFontContext};
use crate::context::LayoutContext;
use crate::display_list::items::{DisplayListSection, OpaqueNode};
use crate::display_list::{
BorderPaintingMode, DisplayListBuildState, StackingContextCollectionState,
@ -1239,7 +1239,7 @@ impl InlineFlow {
/// `style` is the style of the block.
pub fn minimum_line_metrics(
&self,
font_context: &LayoutFontContext,
font_context: &FontContext,
style: &ComputedValues,
) -> LineMetrics {
InlineFlow::minimum_line_metrics_for_fragments(
@ -1255,7 +1255,7 @@ impl InlineFlow {
/// `style` is the style of the block that these fragments belong to.
pub fn minimum_line_metrics_for_fragments(
fragments: &[Fragment],
font_context: &LayoutFontContext,
font_context: &FontContext,
style: &ComputedValues,
) -> LineMetrics {
// As a special case, if this flow contains only hypothetical fragments, then the entire

View file

@ -11,7 +11,7 @@ use std::sync::Arc;
use app_units::Au;
use base::text::is_bidi_control;
use fonts::{
self, ByteIndex, FontIdentifier, FontMetrics, FontRef, RunMetrics, ShapingFlags,
self, ByteIndex, FontContext, FontIdentifier, FontMetrics, FontRef, RunMetrics, ShapingFlags,
ShapingOptions, LAST_RESORT_GLYPH_ADVANCE,
};
use log::{debug, warn};
@ -28,7 +28,6 @@ use unicode_bidi as bidi;
use unicode_script::Script;
use xi_unicode::LineBreakLeafIter;
use crate::context::LayoutFontContext;
use crate::fragment::{
Fragment, ScannedTextFlags, ScannedTextFragmentInfo, SpecificFragmentInfo,
UnscannedTextFragmentInfo,
@ -71,7 +70,7 @@ impl TextRunScanner {
pub fn scan_for_runs(
&mut self,
font_context: &LayoutFontContext,
font_context: &FontContext,
mut fragments: LinkedList<Fragment>,
) -> InlineFragments {
debug!(
@ -151,7 +150,7 @@ impl TextRunScanner {
/// be adjusted.
fn flush_clump_to_list(
&mut self,
font_context: &LayoutFontContext,
font_context: &FontContext,
out_fragments: &mut Vec<Fragment>,
paragraph_bytes_processed: &mut usize,
bidi_levels: Option<&[bidi::Level]>,
@ -538,7 +537,7 @@ fn bounding_box_for_run_metrics(
/// Panics if no font can be found for the given font style.
#[inline]
pub fn font_metrics_for_style(
font_context: &LayoutFontContext,
font_context: &FontContext,
style: crate::ServoArc<FontStyleStruct>,
) -> FontMetrics {
let font_group = font_context.font_group(style);