aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/script_layout
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-05-17 14:28:58 +0200
committerGitHub <noreply@github.com>2024-05-17 12:28:58 +0000
commit3398fc017b994fff113342baab47718a44a37752 (patch)
tree9ec5881db059b0bda7d374ad4d0abe96319e5c25 /components/shared/script_layout
parent1017533297889beca40be5f121629347963fbf27 (diff)
downloadservo-3398fc017b994fff113342baab47718a44a37752.tar.gz
servo-3398fc017b994fff113342baab47718a44a37752.zip
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`.
Diffstat (limited to 'components/shared/script_layout')
-rw-r--r--components/shared/script_layout/Cargo.toml3
-rw-r--r--components/shared/script_layout/lib.rs54
-rw-r--r--components/shared/script_layout/wrapper_traits.rs7
3 files changed, 57 insertions, 7 deletions
diff --git a/components/shared/script_layout/Cargo.toml b/components/shared/script_layout/Cargo.toml
index df526c9bec9..57c4059b859 100644
--- a/components/shared/script_layout/Cargo.toml
+++ b/components/shared/script_layout/Cargo.toml
@@ -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" }
diff --git a/components/shared/script_layout/lib.rs b/components/shared/script_layout/lib.rs
index d4ac0185306..7c1f4ee2162 100644
--- a/components/shared/script_layout/lib.rs
+++ b/components/shared/script_layout/lib.rs
@@ -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
+}
diff --git a/components/shared/script_layout/wrapper_traits.rs b/components/shared/script_layout/wrapper_traits.rs
index 846943414ae..0adb51be244 100644
--- a/components/shared/script_layout/wrapper_traits.rs
+++ b/components/shared/script_layout/wrapper_traits.rs
@@ -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 {}