Skip to content

Commit

Permalink
Move non-gfx things out of gfx_traits and create a base crate (#3…
Browse files Browse the repository at this point in the history
…2296)

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`.
  • Loading branch information
mrobinson committed May 17, 2024
1 parent 1017533 commit 3398fc0
Show file tree
Hide file tree
Showing 163 changed files with 709 additions and 632 deletions.
92 changes: 57 additions & 35 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ app_units = "0.7"
arrayvec = "0.7"
async-tungstenite = { version = "0.23", features = ["tokio-rustls-webpki-roots"] }
atomic_refcell = "0.1.13"
background_hang_monitor_api = { path = "components/shared/background_hang_monitor" }
backtrace = "0.3"
base = { path = "components/shared/base" }
base64 = "0.21.7"
bitflags = "2.5"
bluetooth_traits = { path = "components/shared/bluetooth" }
Expand Down Expand Up @@ -68,7 +70,6 @@ malloc_size_of_derive = "0.1"
mime = "0.3.13"
mime_guess = "2.0.3"
mozangle = "0.5.1"
msg = { path = "components/shared/msg" }
net_traits = { path = "components/shared/net" }
num-traits = "0.2"
num_cpus = "1.1.0"
Expand Down
3 changes: 2 additions & 1 deletion components/background_hang_monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ test = false
doctest = false

[dependencies]
background_hang_monitor_api = { workspace = true }
backtrace = { workspace = true }
base = { workspace = true }
crossbeam-channel = { workspace = true }
ipc-channel = { workspace = true }
libc = { workspace = true }
log = { workspace = true }
msg = { workspace = true }
serde_json = { workspace = true }

[dev-dependencies]
Expand Down
10 changes: 5 additions & 5 deletions components/background_hang_monitor/background_hang_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::sync::{Arc, Weak};
use std::thread;
use std::time::{Duration, Instant};

use crossbeam_channel::{after, never, select, unbounded, Receiver, Sender};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use log::warn;
use msg::constellation_msg::{
use background_hang_monitor_api::{
BackgroundHangMonitor, BackgroundHangMonitorClone, BackgroundHangMonitorControlMsg,
BackgroundHangMonitorExitSignal, BackgroundHangMonitorRegister, HangAlert, HangAnnotation,
HangMonitorAlert, MonitoredComponentId,
};
use crossbeam_channel::{after, never, select, unbounded, Receiver, Sender};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use log::warn;

use crate::sampler::{NativeStack, Sampler};

Expand Down
2 changes: 1 addition & 1 deletion components/background_hang_monitor/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::ptr;

use msg::constellation_msg::{HangProfile, HangProfileSymbol};
use background_hang_monitor_api::{HangProfile, HangProfileSymbol};

const MAX_NATIVE_FRAMES: usize = 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use std::thread;
use std::time::Duration;

use background_hang_monitor::HangMonitorRegister;
use ipc_channel::ipc;
use msg::constellation_msg::{
use background_hang_monitor_api::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorExitSignal, HangAlert, HangAnnotation,
HangMonitorAlert, MonitoredComponentId, MonitoredComponentType, ScriptHangAnnotation,
TEST_PIPELINE_ID,
};
use base::id::TEST_PIPELINE_ID;
use ipc_channel::ipc;

lazy_static::lazy_static! {
static ref SERIAL: Mutex<()> = Mutex::new(());
Expand Down
2 changes: 1 addition & 1 deletion components/compositing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ default = []
multiview = []

[dependencies]
base = { workspace = true }
canvas = { path = "../canvas" }
compositing_traits = { workspace = true }
crossbeam-channel = { workspace = true }
Expand All @@ -30,7 +31,6 @@ ipc-channel = { workspace = true }
keyboard-types = { workspace = true }
libc = { workspace = true }
log = { workspace = true }
msg = { workspace = true }
net_traits = { workspace = true }
pixels = { path = "../pixels" }
profile_traits = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::iter::once;
use std::rc::Rc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base::id::{PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::{Epoch, WebRenderEpochToU16};
use canvas::canvas_paint_thread::ImageUpdate;
use compositing_traits::{
CanvasToCompositorMsg, CompositionPipeline, CompositorMsg, CompositorReceiver,
Expand All @@ -21,12 +23,10 @@ use embedder_traits::Cursor;
use euclid::{Point2D, Rect, Scale, Transform3D, Vector2D};
use fnv::{FnvHashMap, FnvHashSet};
use gfx::rendering_context::RenderingContext;
use gfx_traits::{Epoch, WebRenderEpochToU16};
use image::{DynamicImage, ImageFormat};
use ipc_channel::ipc;
use libc::c_void;
use log::{debug, error, info, trace, warn};
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId, WebViewId};
use net_traits::image::base::Image;
use net_traits::image_cache::CorsStatus;
use pixels::PixelFormat;
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::collections::HashMap;

use msg::constellation_msg::{PipelineId, WebViewId};
use base::id::{PipelineId, WebViewId};
use webrender_api::units::DeviceRect;

#[derive(Debug, Default)]
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<WebView> WebViewManager<WebView> {
mod test {
use std::num::NonZeroU32;

use msg::constellation_msg::{
use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId,
TopLevelBrowsingContextId,
};
Expand Down
5 changes: 3 additions & 2 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use std::fmt::{Debug, Error, Formatter};
use std::time::Duration;

use base::id::{PipelineId, TopLevelBrowsingContextId};
use embedder_traits::{EmbedderProxy, EventLoopWaker};
use euclid::Scale;
use gfx::rendering_context::RenderingContext;
use keyboard_types::KeyboardEvent;
use libc::c_void;
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId, TraversalDirection};
use script_traits::{
GamepadEvent, MediaSessionActionType, MouseButton, TouchEventType, TouchId, WheelDelta,
GamepadEvent, MediaSessionActionType, MouseButton, TouchEventType, TouchId, TraversalDirection,
WheelDelta,
};
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
Expand Down
3 changes: 2 additions & 1 deletion components/constellation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ default = []
multiview = []

[dependencies]
background_hang_monitor_api = { workspace = true }
background_hang_monitor = { path = "../background_hang_monitor" }
backtrace = { workspace = true }
base = { workspace = true }
bluetooth_traits = { workspace = true }
canvas_traits = { workspace = true }
compositing_traits = { workspace = true }
Expand All @@ -32,7 +34,6 @@ keyboard-types = { workspace = true }
log = { workspace = true }
media = { path = "../media" }
metrics = { path = "../metrics" }
msg = { workspace = true }
net = { path = "../net" }
net_traits = { workspace = true }
parking_lot = { workspace = true }
Expand Down
4 changes: 1 addition & 3 deletions components/constellation/browsingcontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use std::collections::{HashMap, HashSet};

use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use euclid::Size2D;
use log::warn;
use msg::constellation_msg::{
BrowsingContextGroupId, BrowsingContextId, PipelineId, TopLevelBrowsingContextId,
};
use style_traits::CSSPixel;

use crate::pipeline::Pipeline;
Expand Down
20 changes: 11 additions & 9 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ use std::sync::{Arc, Mutex};
use std::{process, thread};

use background_hang_monitor::HangMonitorRegister;
use background_hang_monitor_api::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, HangMonitorAlert,
};
use base::id::{
BroadcastChannelRouterId, BrowsingContextGroupId, BrowsingContextId, HistoryStateId,
MessagePortId, MessagePortRouterId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId, WebViewId,
};
use base::Epoch;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use canvas_traits::webgl::WebGLThreads;
Expand All @@ -113,20 +122,13 @@ use embedder_traits::{
use euclid::default::Size2D as UntypedSize2D;
use euclid::Size2D;
use gfx::font_cache_thread::FontCacheThread;
use gfx_traits::Epoch;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use ipc_channel::Error as IpcError;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
use keyboard_types::KeyboardEvent;
use log::{debug, error, info, trace, warn};
use media::{GLPlayerThreads, WindowGLContext};
use msg::constellation_msg::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, BroadcastChannelRouterId,
BrowsingContextGroupId, BrowsingContextId, HangMonitorAlert, HistoryStateId, MessagePortId,
MessagePortRouterId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId, TraversalDirection, WebViewId,
};
use net_traits::pub_domains::reg_host;
use net_traits::request::{Referrer, RequestBuilder};
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
Expand All @@ -142,8 +144,8 @@ use script_traits::{
LoadData, LoadOrigin, LogEntry, MediaSessionActionType, MessagePortMsg, MouseEventType,
PortMessageTask, SWManagerMsg, SWManagerSenders, ScriptMsg as FromScriptMsg,
ScriptToConstellationChan, ServiceWorkerManagerFactory, ServiceWorkerMsg,
StructuredSerializedData, TimerSchedulerMsg, UpdatePipelineIdReason, WebDriverCommandMsg,
WindowSizeData, WindowSizeType,
StructuredSerializedData, TimerSchedulerMsg, TraversalDirection, UpdatePipelineIdReason,
WebDriverCommandMsg, WindowSizeData, WindowSizeType,
};
use serde::{Deserialize, Serialize};
use servo_config::{opts, pref};
Expand Down
2 changes: 1 addition & 1 deletion components/constellation/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::sync::Arc;
use std::thread;

use backtrace::Backtrace;
use base::id::TopLevelBrowsingContextId;
use compositing_traits::ConstellationMsg as FromCompositorMsg;
use crossbeam_channel::Sender;
use log::{Level, LevelFilter, Log, Metadata, Record};
use msg::constellation_msg::TopLevelBrowsingContextId;
use parking_lot::ReentrantMutex;
use script_traits::{LogEntry, ScriptMsg as FromScriptMsg, ScriptToConstellationChan};

Expand Down
2 changes: 1 addition & 1 deletion components/constellation/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//! Any redirects that are encountered are followed. Whenever a non-redirect
//! response is received, it is forwarded to the appropriate script thread.

use base::id::PipelineId;
use crossbeam_channel::Sender;
use http::HeaderMap;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use log::warn;
use msg::constellation_msg::PipelineId;
use net::http_loader::{set_default_accept, set_default_accept_language};
use net_traits::request::{Destination, Referrer, RequestBuilder};
use net_traits::response::ResponseInit;
Expand Down
14 changes: 8 additions & 6 deletions components/constellation/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ use std::rc::Rc;
use std::sync::Arc;

use background_hang_monitor::HangMonitorRegister;
use background_hang_monitor_api::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, HangMonitorAlert,
};
use base::id::{
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId,
};
use base::Epoch;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLPipeline;
use compositing_traits::{CompositionPipeline, CompositorMsg, CompositorProxy};
use crossbeam_channel::{unbounded, Sender};
use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg};
use embedder_traits::EventLoopWaker;
use gfx::font_cache_thread::FontCacheThread;
use gfx_traits::Epoch;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use ipc_channel::Error;
use log::{debug, error, warn};
use media::WindowGLContext;
use msg::constellation_msg::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, BrowsingContextId,
HangMonitorAlert, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId,
};
use net::image_cache::ImageCacheImpl;
use net_traits::image_cache::ImageCache;
use net_traits::ResourceThreads;
Expand Down
4 changes: 1 addition & 3 deletions components/constellation/session_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
use std::cmp::PartialEq;
use std::fmt;

use base::id::{BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId};
use euclid::Size2D;
use log::debug;
use msg::constellation_msg::{
BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId,
};
use script_traits::LoadData;
use servo_url::ServoUrl;
use style_traits::CSSPixel;
Expand Down
4 changes: 2 additions & 2 deletions components/constellation/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::collections::HashMap;

use msg::constellation_msg::TopLevelBrowsingContextId;
use base::id::TopLevelBrowsingContextId;

#[derive(Debug)]
pub struct WebViewManager<WebView> {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<WebView> WebViewManager<WebView> {
mod test {
use std::num::NonZeroU32;

use msg::constellation_msg::{
use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId,
TopLevelBrowsingContextId, WebViewId,
};
Expand Down
2 changes: 1 addition & 1 deletion components/devtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "lib.rs"
chrono = "0.4"

[dependencies]
base = { workspace = true }
chrono = "0.4"
crossbeam-channel = { workspace = true }
devtools_traits = { workspace = true }
Expand All @@ -22,7 +23,6 @@ headers = { workspace = true }
http = { workspace = true }
ipc-channel = { workspace = true }
log = { workspace = true }
msg = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
servo_config = { path = "../config" }
Expand Down
2 changes: 1 addition & 1 deletion components/devtools/actors/browsing_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::net::TcpStream;

use base::id::{BrowsingContextId, PipelineId};
use devtools_traits::DevtoolScriptControlMsg::{self, WantsLiveNotifications};
use devtools_traits::{DevtoolsPageInfo, NavigationState};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use serde::Serialize;
use serde_json::{Map, Value};

Expand Down
2 changes: 1 addition & 1 deletion components/devtools/actors/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::collections::HashMap;
use std::net::TcpStream;
use std::time::{SystemTime, UNIX_EPOCH};

use base::id::TEST_PIPELINE_ID;
use devtools_traits::EvaluateJSReply::{
ActorValue, BooleanValue, NullValue, NumberValue, StringValue, VoidValue,
};
Expand All @@ -20,7 +21,6 @@ use devtools_traits::{
};
use ipc_channel::ipc::{self, IpcSender};
use log::debug;
use msg::constellation_msg::TEST_PIPELINE_ID;
use serde::Serialize;
use serde_json::{self, Map, Number, Value};
use uuid::Uuid;
Expand Down
2 changes: 1 addition & 1 deletion components/devtools/actors/framerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use std::mem;
use std::net::TcpStream;

use base::id::PipelineId;
use devtools_traits::DevtoolScriptControlMsg;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use serde_json::{Map, Value};

use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
Expand Down
2 changes: 1 addition & 1 deletion components/devtools/actors/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use std::cell::RefCell;
use std::net::TcpStream;

use base::id::PipelineId;
use devtools_traits::DevtoolScriptControlMsg::{
GetChildren, GetDocumentElement, GetLayout, GetRootNode, ModifyAttribute,
};
use devtools_traits::{ComputedNodeLayout, DevtoolScriptControlMsg, NodeInfo};
use ipc_channel::ipc::{self, IpcSender};
use msg::constellation_msg::PipelineId;
use serde::Serialize;
use serde_json::{self, Map, Value};

Expand Down

0 comments on commit 3398fc0

Please sign in to comment.