Move non-gfx things out of gfx_traits and create a base crate (#32296)

For a long time, `gfx_traits` has held a lot of things unrelated to graphics
and also unrelated to the `gfx` crate (which is mostly about fonts).
This is a cleanup which does a few things:

1. Move non `gfx` crate things out of `gfx_traits`. This is important in
   order to prevent dependency cycles with a different integration between
   layout, script, and fonts.
2. Rename the `msg` crate to `base`. It didn't really contain anything
   to do with messages and instead mostly holds ids, which are used
   across many different crates in Servo. This new crate will hold the
   *rare* data types that are widely used.

Details:

 - All BackgroundHangMonitor-related things from base to a new
   `background_hang_monitor_api` crate.
 - Moved `TraversalDirection` to `script_traits`
 - Moved `Epoch`-related things from `gfx_traits` to `base`.
 - Moved `PrintTree` to base. This should be widely useful in Servo.
 - Moved `WebrenderApi` from `base` to `webrender_traits` and renamed it
   to `WebRenderFontApi`.
This commit is contained in:
Martin Robinson 2024-05-17 14:28:58 +02:00 committed by GitHub
parent 1017533297
commit 3398fc017b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
163 changed files with 709 additions and 632 deletions

View file

@ -11,6 +11,7 @@ name = "script_layout_interface"
path = "lib.rs"
[dependencies]
base = { workspace = true }
app_units = { workspace = true }
atomic_refcell = { workspace = true }
canvas_traits = { workspace = true }
@ -24,12 +25,12 @@ libc = { workspace = true }
malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true }
metrics = { path = "../../metrics" }
msg = { workspace = true }
net_traits = { workspace = true }
profile_traits = { workspace = true }
range = { path = "../../range" }
script_traits = { workspace = true }
selectors = { workspace = true }
serde = { workspace = true }
servo_arc = { workspace = true }
servo_atoms = { workspace = true }
servo_url = { path = "../../url" }

View file

@ -12,22 +12,22 @@ pub mod wrapper_traits;
use std::any::Any;
use std::borrow::Cow;
use std::sync::atomic::AtomicIsize;
use std::sync::atomic::{AtomicIsize, AtomicU64, Ordering};
use std::sync::Arc;
use app_units::Au;
use atomic_refcell::AtomicRefCell;
use base::id::{BrowsingContextId, PipelineId};
use base::Epoch;
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use crossbeam_channel::Sender;
use euclid::default::{Point2D, Rect};
use euclid::Size2D;
use gfx::font_cache_thread::FontCacheThread;
use gfx_traits::Epoch;
use ipc_channel::ipc::IpcSender;
use libc::c_void;
use malloc_size_of_derive::MallocSizeOf;
use metrics::PaintTimeMetrics;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image_cache::{ImageCache, PendingImageId};
use profile_traits::mem::Report;
use profile_traits::time;
@ -35,6 +35,7 @@ use script_traits::{
ConstellationControlMsg, InitialScriptState, LayoutControlMsg, LayoutMsg, LoadData, Painter,
ScrollState, UntrustedNodeAddress, WebrenderIpcSender, WindowSizeData,
};
use serde::{Deserialize, Serialize};
use servo_arc::Arc as ServoArc;
use servo_url::{ImmutableOrigin, ServoUrl};
use style::animation::DocumentAnimationSet;
@ -413,3 +414,50 @@ pub struct PendingRestyle {
/// Any explicit restyles damage that have been accumulated for this element.
pub damage: RestyleDamage,
}
/// The type of fragment that a scroll root is created for.
///
/// This can only ever grow to maximum 4 entries. That's because we cram the value of this enum
/// into the lower 2 bits of the `ScrollRootId`, which otherwise contains a 32-bit-aligned
/// heap address.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
pub enum FragmentType {
/// A StackingContext for the fragment body itself.
FragmentBody,
/// A StackingContext created to contain ::before pseudo-element content.
BeforePseudoContent,
/// A StackingContext created to contain ::after pseudo-element content.
AfterPseudoContent,
}
/// The next ID that will be used for a special scroll root id.
///
/// A special scroll root is a scroll root that is created for generated content.
static NEXT_SPECIAL_SCROLL_ROOT_ID: AtomicU64 = AtomicU64::new(0);
/// If none of the bits outside this mask are set, the scroll root is a special scroll root.
/// Note that we assume that the top 16 bits of the address space are unused on the platform.
const SPECIAL_SCROLL_ROOT_ID_MASK: u64 = 0xffff;
/// Returns a new scroll root ID for a scroll root.
fn next_special_id() -> u64 {
// We shift this left by 2 to make room for the fragment type ID.
((NEXT_SPECIAL_SCROLL_ROOT_ID.fetch_add(1, Ordering::SeqCst) + 1) << 2) &
SPECIAL_SCROLL_ROOT_ID_MASK
}
pub fn combine_id_with_fragment_type(id: usize, fragment_type: FragmentType) -> u64 {
debug_assert_eq!(id & (fragment_type as usize), 0);
if fragment_type == FragmentType::FragmentBody {
id as u64
} else {
next_special_id() | (fragment_type as u64)
}
}
pub fn node_id_from_scroll_id(id: usize) -> Option<usize> {
if (id as u64 & !SPECIAL_SCROLL_ROOT_ID_MASK) != 0 {
return Some(id & !3);
}
None
}

View file

@ -9,9 +9,9 @@ use std::fmt::Debug;
use std::sync::Arc as StdArc;
use atomic_refcell::AtomicRef;
use gfx_traits::{ByteIndex, FragmentType};
use base::id::{BrowsingContextId, PipelineId};
use gfx_traits::ByteIndex;
use html5ever::{local_name, namespace_url, ns, LocalName, Namespace};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image::base::{Image, ImageMetadata};
use range::Range;
use servo_arc::Arc;
@ -25,7 +25,8 @@ use style::selector_parser::{PseudoElement, PseudoElementCascadeType, SelectorIm
use style::stylist::RuleInclusion;
use crate::{
GenericLayoutData, HTMLCanvasData, HTMLMediaData, LayoutNodeType, SVGSVGData, StyleData,
FragmentType, GenericLayoutData, HTMLCanvasData, HTMLMediaData, LayoutNodeType, SVGSVGData,
StyleData,
};
pub trait LayoutDataTrait: Default + Send + Sync + 'static {}