mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Use strum
to iterate through enum variants and get their names (#35933)
`strum` allows us to avoid manually listing enum variant names and also to get their names as static strings. We cannot use this for all cases due to https://github.com/Peternator7/strum/issues/152, but we can still use it to remove a lot of code. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
959720db0a
commit
294a649a6c
17 changed files with 51 additions and 285 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1123,6 +1123,7 @@ dependencies = [
|
|||
"pixels",
|
||||
"script_traits",
|
||||
"servo_url",
|
||||
"strum_macros",
|
||||
"style_traits",
|
||||
"webrender_api",
|
||||
"webrender_traits",
|
||||
|
@ -1907,6 +1908,7 @@ dependencies = [
|
|||
"serde",
|
||||
"servo_malloc_size_of",
|
||||
"servo_url",
|
||||
"strum_macros",
|
||||
"style_traits",
|
||||
"url",
|
||||
"webdriver",
|
||||
|
@ -5854,6 +5856,7 @@ dependencies = [
|
|||
"serde",
|
||||
"servo_config",
|
||||
"signpost",
|
||||
"strum_macros",
|
||||
"time",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -6349,6 +6352,8 @@ dependencies = [
|
|||
"servo_rand",
|
||||
"servo_url",
|
||||
"smallvec",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"style",
|
||||
"style_traits",
|
||||
"stylo_atoms",
|
||||
|
@ -6466,6 +6471,7 @@ dependencies = [
|
|||
"serde",
|
||||
"servo_malloc_size_of",
|
||||
"servo_url",
|
||||
"strum_macros",
|
||||
"style_traits",
|
||||
"stylo_atoms",
|
||||
"uuid",
|
||||
|
|
|
@ -131,6 +131,8 @@ smallvec = "1.14"
|
|||
static_assertions = "1.1"
|
||||
string_cache = "0.8"
|
||||
string_cache_codegen = "0.5"
|
||||
strum = "0.26"
|
||||
strum_macros = "0.26"
|
||||
style = { git = "https://github.com/servo/stylo", branch = "2025-03-11", features = ["servo"] }
|
||||
stylo_config = { git = "https://github.com/servo/stylo", branch = "2025-03-11" }
|
||||
stylo_dom = { git = "https://github.com/servo/stylo", branch = "2025-03-11" }
|
||||
|
|
|
@ -85,57 +85,8 @@ impl Formattable for ProfilerCategory {
|
|||
ProfilerCategory::LayoutTextShaping => "| + ",
|
||||
_ => "",
|
||||
};
|
||||
let name = match *self {
|
||||
ProfilerCategory::Compositing => "Compositing",
|
||||
ProfilerCategory::LayoutPerform => "Layout",
|
||||
ProfilerCategory::LayoutStyleRecalc => "Style Recalc",
|
||||
ProfilerCategory::LayoutTextShaping => "Text Shaping",
|
||||
ProfilerCategory::LayoutRestyleDamagePropagation => "Restyle Damage Propagation",
|
||||
ProfilerCategory::LayoutGeneratedContent => "Generated Content Resolution",
|
||||
ProfilerCategory::LayoutFloatPlacementSpeculation => "Float Placement Speculation",
|
||||
ProfilerCategory::LayoutMain => "Primary Layout Pass",
|
||||
ProfilerCategory::LayoutStoreOverflow => "Store Overflow",
|
||||
ProfilerCategory::LayoutParallelWarmup => "Parallel Warmup",
|
||||
ProfilerCategory::LayoutDispListBuild => "Display List Construction",
|
||||
ProfilerCategory::ImageSaving => "Image Saving",
|
||||
ProfilerCategory::ScriptAttachLayout => "Script Attach Layout",
|
||||
ProfilerCategory::ScriptConstellationMsg => "Script Constellation Msg",
|
||||
ProfilerCategory::ScriptDevtoolsMsg => "Script Devtools Msg",
|
||||
ProfilerCategory::ScriptDocumentEvent => "Script Document Event",
|
||||
ProfilerCategory::ScriptEvaluate => "Script JS Evaluate",
|
||||
ProfilerCategory::ScriptFileRead => "Script File Read",
|
||||
ProfilerCategory::ScriptFontLoading => "Script Font Loading",
|
||||
ProfilerCategory::ScriptHistoryEvent => "Script History Event",
|
||||
ProfilerCategory::ScriptImageCacheMsg => "Script Image Cache Msg",
|
||||
ProfilerCategory::ScriptInputEvent => "Script Input Event",
|
||||
ProfilerCategory::ScriptNetworkEvent => "Script Network Event",
|
||||
ProfilerCategory::ScriptParseHTML => "Script Parse HTML",
|
||||
ProfilerCategory::ScriptParseXML => "Script Parse XML",
|
||||
ProfilerCategory::ScriptPlannedNavigation => "Script Planned Navigation",
|
||||
ProfilerCategory::ScriptPortMessage => "Script Port Message",
|
||||
ProfilerCategory::ScriptRendering => "Script Rendering",
|
||||
ProfilerCategory::ScriptResize => "Script Resize",
|
||||
ProfilerCategory::ScriptEvent => "Script Event",
|
||||
ProfilerCategory::ScriptUpdateReplacedElement => "Script Update Replaced Element",
|
||||
ProfilerCategory::ScriptSetScrollState => "Script Set Scroll State",
|
||||
ProfilerCategory::ScriptSetViewport => "Script Set Viewport",
|
||||
ProfilerCategory::ScriptTimerEvent => "Script Timer Event",
|
||||
ProfilerCategory::ScriptStylesheetLoad => "Script Stylesheet Load",
|
||||
ProfilerCategory::ScriptWebSocketEvent => "Script Web Socket Event",
|
||||
ProfilerCategory::ScriptWorkerEvent => "Script Worker Event",
|
||||
ProfilerCategory::ScriptServiceWorkerEvent => "Script Service Worker Event",
|
||||
ProfilerCategory::ScriptEnterFullscreen => "Script Enter Fullscreen",
|
||||
ProfilerCategory::ScriptExitFullscreen => "Script Exit Fullscreen",
|
||||
ProfilerCategory::ScriptWorkletEvent => "Script Worklet Event",
|
||||
ProfilerCategory::ScriptPerformanceEvent => "Script Performance Event",
|
||||
ProfilerCategory::ScriptWebGPUMsg => "Script WebGPU Message",
|
||||
ProfilerCategory::TimeToFirstPaint => "Time To First Paint",
|
||||
ProfilerCategory::TimeToFirstContentfulPaint => "Time To First Contentful Paint",
|
||||
ProfilerCategory::TimeToInteractive => "Time to Interactive",
|
||||
ProfilerCategory::IpcReceiver => "Blocked at IPC Receive",
|
||||
ProfilerCategory::IpcBytesReceiver => "Blocked at IPC Bytes Receive",
|
||||
};
|
||||
format!("{}{}", padding, name)
|
||||
let name: &'static str = self.into();
|
||||
format!("{padding}{name}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,8 @@ servo_url = { path = "../url" }
|
|||
smallvec = { workspace = true, features = ["union"] }
|
||||
style_malloc_size_of = { workspace = true }
|
||||
glow = { workspace = true }
|
||||
strum = { workspace = true }
|
||||
strum_macros = { workspace = true }
|
||||
style = { workspace = true }
|
||||
stylo_dom = { workspace = true }
|
||||
style_traits = { workspace = true }
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::cell::Ref;
|
|||
use std::collections::HashMap;
|
||||
|
||||
use base::id::PipelineId;
|
||||
use strum::VariantArray;
|
||||
|
||||
use crate::messaging::ScriptEventLoopSender;
|
||||
use crate::task::TaskCanceller;
|
||||
|
@ -36,7 +37,7 @@ impl TaskCancellers {
|
|||
Self::OnePerTaskSource(..) => {
|
||||
// We must create the canceller if they aren't created because we want future
|
||||
// tasks to be ignored completely.
|
||||
for task_source_name in TaskSourceName::all() {
|
||||
for task_source_name in TaskSourceName::VARIANTS.iter() {
|
||||
self.get(*task_source_name)
|
||||
.cancelled
|
||||
.store(true, Ordering::SeqCst)
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::default::Default;
|
|||
|
||||
use base::id::PipelineId;
|
||||
use crossbeam_channel::{self, Receiver, Sender};
|
||||
use strum::VariantArray;
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::worker::TrustedWorkerAddress;
|
||||
|
@ -211,8 +212,7 @@ impl<T: QueuedTaskConversion> TaskQueue<T> {
|
|||
self.process_incoming_tasks(first_msg, &fully_active);
|
||||
let mut throttled = self.throttled.borrow_mut();
|
||||
let mut throttled_length: usize = throttled.values().map(|queue| queue.len()).sum();
|
||||
let task_source_names = TaskSourceName::all();
|
||||
let mut task_source_cycler = task_source_names.iter().cycle();
|
||||
let mut task_source_cycler = TaskSourceName::VARIANTS.iter().cycle();
|
||||
// "being busy", is defined as having more than x tasks for this loop's iteration.
|
||||
// As long as we're not busy, and there are throttled tasks left:
|
||||
loop {
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::fmt;
|
|||
|
||||
use base::id::PipelineId;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use strum_macros::VariantArray;
|
||||
use stylo_atoms::Atom;
|
||||
|
||||
use crate::dom::bindings::refcounted::Trusted;
|
||||
|
@ -19,10 +20,7 @@ use crate::task_manager::TaskManager;
|
|||
/// The names of all task sources, used to differentiate TaskCancellers. Note: When adding a task
|
||||
/// source, update this enum. Note: The HistoryTraversalTaskSource is not part of this, because it
|
||||
/// doesn't implement TaskSource.
|
||||
///
|
||||
/// Note: When adding or removing a [`TaskSourceName`], be sure to also update the return value of
|
||||
/// [`TaskSourceName::all`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, MallocSizeOf, PartialEq, VariantArray)]
|
||||
pub(crate) enum TaskSourceName {
|
||||
Canvas,
|
||||
DOMManipulation,
|
||||
|
@ -68,28 +66,6 @@ impl From<TaskSourceName> for ScriptThreadEventCategory {
|
|||
}
|
||||
}
|
||||
|
||||
impl TaskSourceName {
|
||||
pub(crate) fn all() -> &'static [TaskSourceName] {
|
||||
&[
|
||||
TaskSourceName::Canvas,
|
||||
TaskSourceName::DOMManipulation,
|
||||
TaskSourceName::FileReading,
|
||||
TaskSourceName::FontLoading,
|
||||
TaskSourceName::HistoryTraversal,
|
||||
TaskSourceName::Networking,
|
||||
TaskSourceName::PerformanceTimeline,
|
||||
TaskSourceName::PortMessage,
|
||||
TaskSourceName::UserInteraction,
|
||||
TaskSourceName::RemoteEvent,
|
||||
TaskSourceName::Rendering,
|
||||
TaskSourceName::MediaElement,
|
||||
TaskSourceName::WebSocket,
|
||||
TaskSourceName::Timer,
|
||||
TaskSourceName::Gamepad,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct TaskSource<'task_manager> {
|
||||
pub(crate) task_manager: &'task_manager TaskManager,
|
||||
pub(crate) name: TaskSourceName,
|
||||
|
|
|
@ -22,6 +22,7 @@ log = { workspace = true }
|
|||
pixels = { path = '../../pixels' }
|
||||
script_traits = { workspace = true }
|
||||
servo_url = { path = "../../url" }
|
||||
strum_macros = { workspace = true }
|
||||
style_traits = { workspace = true }
|
||||
webrender_api = { workspace = true }
|
||||
webrender_traits = { workspace = true }
|
||||
|
|
|
@ -14,9 +14,11 @@ use embedder_traits::{
|
|||
use ipc_channel::ipc::IpcSender;
|
||||
use script_traits::{AnimationTickType, LogEntry, WindowSizeData, WindowSizeType};
|
||||
use servo_url::ServoUrl;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use webrender_traits::CompositorHitTestResult;
|
||||
|
||||
/// Messages to the constellation.
|
||||
#[derive(IntoStaticStr)]
|
||||
pub enum ConstellationMsg {
|
||||
/// Exit the constellation.
|
||||
Exit,
|
||||
|
@ -77,41 +79,7 @@ pub enum ConstellationMsg {
|
|||
|
||||
impl fmt::Debug for ConstellationMsg {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "ConstellationMsg::{}", self.variant_name())
|
||||
}
|
||||
}
|
||||
|
||||
impl ConstellationMsg {
|
||||
/// Return the variant name, for error logging that happens after the message is consumed.
|
||||
pub fn variant_name(&self) -> &'static str {
|
||||
use self::ConstellationMsg::*;
|
||||
match *self {
|
||||
Exit => "Exit",
|
||||
GetBrowsingContext(..) => "GetBrowsingContext",
|
||||
GetPipeline(..) => "GetPipeline",
|
||||
GetFocusTopLevelBrowsingContext(..) => "GetFocusTopLevelBrowsingContext",
|
||||
IsReadyToSaveImage(..) => "IsReadyToSaveImage",
|
||||
AllowNavigationResponse(..) => "AllowNavigationResponse",
|
||||
LoadUrl(..) => "LoadUrl",
|
||||
TraverseHistory(..) => "TraverseHistory",
|
||||
WindowSize(..) => "WindowSize",
|
||||
ThemeChange(..) => "ThemeChange",
|
||||
TickAnimation(..) => "TickAnimation",
|
||||
WebDriverCommand(..) => "WebDriverCommand",
|
||||
Reload(..) => "Reload",
|
||||
LogEntry(..) => "LogEntry",
|
||||
NewWebView(..) => "NewWebView",
|
||||
CloseWebView(..) => "CloseWebView",
|
||||
FocusWebView(..) => "FocusWebView",
|
||||
BlurWebView => "BlurWebView",
|
||||
SendError(..) => "SendError",
|
||||
ForwardInputEvent(..) => "ForwardEvent",
|
||||
SetCursor(..) => "SetCursor",
|
||||
ToggleProfiler(..) => "EnableProfiler",
|
||||
ExitFullScreen(..) => "ExitFullScreen",
|
||||
MediaSessionAction(..) => "MediaSessionAction",
|
||||
SetWebViewThrottled(..) => "SetWebViewThrottled",
|
||||
ClearCache => "ClearCache",
|
||||
}
|
||||
let variant_string: &'static str = self.into();
|
||||
write!(formatter, "ConstellationMsg::{variant_string}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ use ipc_channel::ipc::IpcSender;
|
|||
use log::warn;
|
||||
use pixels::Image;
|
||||
use script_traits::{AnimationState, ScriptThreadMessage, TouchEventResult};
|
||||
use strum_macros::IntoStaticStr;
|
||||
use style_traits::CSSPixel;
|
||||
use webrender_api::DocumentId;
|
||||
use webrender_traits::{CrossProcessCompositorApi, CrossProcessCompositorMessage};
|
||||
|
@ -57,6 +58,7 @@ impl CompositorReceiver {
|
|||
}
|
||||
|
||||
/// Messages from (or via) the constellation thread to the compositor.
|
||||
#[derive(IntoStaticStr)]
|
||||
pub enum CompositorMsg {
|
||||
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
|
||||
ChangeRunningAnimationsState(WebViewId, PipelineId, AnimationState),
|
||||
|
@ -112,24 +114,8 @@ pub struct CompositionPipeline {
|
|||
}
|
||||
|
||||
impl Debug for CompositorMsg {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
match *self {
|
||||
CompositorMsg::ChangeRunningAnimationsState(_, _, state) => {
|
||||
write!(f, "ChangeRunningAnimationsState({:?})", state)
|
||||
},
|
||||
CompositorMsg::CreateOrUpdateWebView(..) => write!(f, "CreateOrUpdateWebView"),
|
||||
CompositorMsg::RemoveWebView(..) => write!(f, "RemoveWebView"),
|
||||
CompositorMsg::TouchEventProcessed(..) => write!(f, "TouchEventProcessed"),
|
||||
CompositorMsg::CreatePng(..) => write!(f, "CreatePng"),
|
||||
CompositorMsg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
|
||||
CompositorMsg::SetThrottled(..) => write!(f, "SetThrottled"),
|
||||
CompositorMsg::PipelineExited(..) => write!(f, "PipelineExited"),
|
||||
CompositorMsg::NewWebRenderFrameReady(..) => write!(f, "NewWebRenderFrameReady"),
|
||||
CompositorMsg::PendingPaintMetric(..) => write!(f, "PendingPaintMetric"),
|
||||
CompositorMsg::LoadComplete(..) => write!(f, "LoadComplete"),
|
||||
CompositorMsg::WebDriverMouseButtonEvent(..) => write!(f, "WebDriverMouseButtonEvent"),
|
||||
CompositorMsg::WebDriverMouseMoveEvent(..) => write!(f, "WebDriverMouseMoveEvent"),
|
||||
CompositorMsg::CrossProcess(..) => write!(f, "CrossProcess"),
|
||||
}
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
|
||||
let string: &'static str = self.into();
|
||||
write!(formatter, "{string}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ num-traits = { workspace = true }
|
|||
pixels = { path = "../../pixels" }
|
||||
serde = { workspace = true }
|
||||
servo_url = { path = "../../url" }
|
||||
strum_macros = { workspace = true }
|
||||
style_traits = { workspace = true }
|
||||
url = { workspace = true }
|
||||
webdriver = { workspace = true }
|
||||
|
|
|
@ -19,6 +19,7 @@ use malloc_size_of_derive::MallocSizeOf;
|
|||
use num_derive::FromPrimitive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use url::Url;
|
||||
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
|
||||
|
||||
|
@ -213,7 +214,7 @@ pub enum AllowOrDeny {
|
|||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum EmbedderMsg {
|
||||
/// A status message to be displayed by the browser chrome.
|
||||
Status(WebViewId, Option<String>),
|
||||
|
@ -322,49 +323,9 @@ pub enum EmbedderMsg {
|
|||
}
|
||||
|
||||
impl Debug for EmbedderMsg {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
match *self {
|
||||
EmbedderMsg::Status(..) => write!(f, "Status"),
|
||||
EmbedderMsg::ChangePageTitle(..) => write!(f, "ChangePageTitle"),
|
||||
EmbedderMsg::MoveTo(..) => write!(f, "MoveTo"),
|
||||
EmbedderMsg::ResizeTo(..) => write!(f, "ResizeTo"),
|
||||
EmbedderMsg::ShowSimpleDialog(..) => write!(f, "ShowSimpleDialog"),
|
||||
EmbedderMsg::RequestAuthentication(..) => write!(f, "RequestAuthentication"),
|
||||
EmbedderMsg::AllowUnload(..) => write!(f, "AllowUnload"),
|
||||
EmbedderMsg::AllowNavigationRequest(..) => write!(f, "AllowNavigationRequest"),
|
||||
EmbedderMsg::Keyboard(..) => write!(f, "Keyboard"),
|
||||
EmbedderMsg::ClearClipboard(..) => write!(f, "ClearClipboard"),
|
||||
EmbedderMsg::GetClipboardText(..) => write!(f, "GetClipboardText"),
|
||||
EmbedderMsg::SetClipboardText(..) => write!(f, "SetClipboardText"),
|
||||
EmbedderMsg::SetCursor(..) => write!(f, "SetCursor"),
|
||||
EmbedderMsg::NewFavicon(..) => write!(f, "NewFavicon"),
|
||||
EmbedderMsg::HistoryChanged(..) => write!(f, "HistoryChanged"),
|
||||
EmbedderMsg::NotifyFullscreenStateChanged(..) => {
|
||||
write!(f, "NotifyFullscreenStateChanged")
|
||||
},
|
||||
EmbedderMsg::NotifyLoadStatusChanged(_, status) => {
|
||||
write!(f, "NotifyLoadStatusChanged({status:?})")
|
||||
},
|
||||
EmbedderMsg::WebResourceRequested(..) => write!(f, "WebResourceRequested"),
|
||||
EmbedderMsg::Panic(..) => write!(f, "Panic"),
|
||||
EmbedderMsg::GetSelectedBluetoothDevice(..) => write!(f, "GetSelectedBluetoothDevice"),
|
||||
EmbedderMsg::SelectFiles(..) => write!(f, "SelectFiles"),
|
||||
EmbedderMsg::PromptPermission(..) => write!(f, "PromptPermission"),
|
||||
EmbedderMsg::ShowIME(..) => write!(f, "ShowIME"),
|
||||
EmbedderMsg::HideIME(..) => write!(f, "HideIME"),
|
||||
EmbedderMsg::AllowOpeningWebView(..) => write!(f, "AllowOpeningWebView"),
|
||||
EmbedderMsg::WebViewClosed(..) => write!(f, "WebViewClosed"),
|
||||
EmbedderMsg::WebViewFocused(..) => write!(f, "WebViewFocused"),
|
||||
EmbedderMsg::WebViewBlurred => write!(f, "WebViewBlurred"),
|
||||
EmbedderMsg::ReportProfile(..) => write!(f, "ReportProfile"),
|
||||
EmbedderMsg::MediaSessionEvent(..) => write!(f, "MediaSessionEvent"),
|
||||
EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"),
|
||||
EmbedderMsg::RequestDevtoolsConnection(..) => write!(f, "RequestDevtoolsConnection"),
|
||||
EmbedderMsg::ShowContextMenu(..) => write!(f, "ShowContextMenu"),
|
||||
EmbedderMsg::PlayGamepadHapticEffect(..) => write!(f, "PlayGamepadHapticEffect"),
|
||||
EmbedderMsg::StopGamepadHapticEffect(..) => write!(f, "StopGamepadHapticEffect"),
|
||||
EmbedderMsg::ShutdownComplete => write!(f, "ShutdownComplete"),
|
||||
}
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
|
||||
let string: &'static str = self.into();
|
||||
write!(formatter, "{string}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,5 +22,6 @@ log = { workspace = true }
|
|||
serde = { workspace = true }
|
||||
servo_config = { path = "../../config" }
|
||||
signpost = { git = "https://github.com/pcwalton/signpost.git" }
|
||||
strum_macros = { workspace = true }
|
||||
time = { workspace = true }
|
||||
tracing = { workspace = true, optional = true }
|
||||
|
|
|
@ -7,6 +7,7 @@ use ipc_channel::ipc::IpcSender;
|
|||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_config::opts;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use time::Duration;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
|
@ -57,7 +58,9 @@ pub enum ProfilerMsg {
|
|||
|
||||
/// Usage sites of variants marked “Rust tracing only” are not visible to rust-analyzer.
|
||||
#[repr(u32)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Deserialize, Eq, Hash, IntoStaticStr, Ord, PartialEq, PartialOrd, Serialize,
|
||||
)]
|
||||
pub enum ProfilerCategory {
|
||||
/// The compositor is rasterising or presenting.
|
||||
///
|
||||
|
|
|
@ -39,6 +39,7 @@ net_traits = { workspace = true }
|
|||
pixels = { path = "../../pixels" }
|
||||
profile_traits = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
strum_macros = { workspace = true }
|
||||
stylo_atoms = { workspace = true }
|
||||
servo_url = { path = "../../url" }
|
||||
style_traits = { workspace = true }
|
||||
|
|
|
@ -50,6 +50,7 @@ use pixels::PixelFormat;
|
|||
use profile_traits::{mem, time as profile_time};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use strum_macros::IntoStaticStr;
|
||||
use style_traits::{CSSPixel, SpeculativePainter};
|
||||
use stylo_atoms::Atom;
|
||||
#[cfg(feature = "webgpu")]
|
||||
|
@ -288,7 +289,7 @@ pub enum UpdatePipelineIdReason {
|
|||
|
||||
/// Messages sent to the `ScriptThread` event loop from the `Constellation`, `Compositor`, and (for
|
||||
/// now) `Layout`.
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum ScriptThreadMessage {
|
||||
/// Takes the associated window proxy out of "delaying-load-events-mode",
|
||||
/// used if a scheduled navigated was refused by the embedder.
|
||||
|
@ -408,44 +409,8 @@ pub enum ScriptThreadMessage {
|
|||
|
||||
impl fmt::Debug for ScriptThreadMessage {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::ScriptThreadMessage::*;
|
||||
let variant = match *self {
|
||||
StopDelayingLoadEventsMode(..) => "StopDelayingLoadsEventMode",
|
||||
AttachLayout(..) => "AttachLayout",
|
||||
Resize(..) => "Resize",
|
||||
ThemeChange(..) => "ThemeChange",
|
||||
ResizeInactive(..) => "ResizeInactive",
|
||||
UnloadDocument(..) => "UnloadDocument",
|
||||
ExitPipeline(..) => "ExitPipeline",
|
||||
ExitScriptThread => "ExitScriptThread",
|
||||
SendInputEvent(..) => "SendInputEvent",
|
||||
Viewport(..) => "Viewport",
|
||||
GetTitle(..) => "GetTitle",
|
||||
SetDocumentActivity(..) => "SetDocumentActivity",
|
||||
SetThrottled(..) => "SetThrottled",
|
||||
SetThrottledInContainingIframe(..) => "SetThrottledInContainingIframe",
|
||||
NavigateIframe(..) => "NavigateIframe",
|
||||
PostMessage { .. } => "PostMessage",
|
||||
UpdatePipelineId(..) => "UpdatePipelineId",
|
||||
UpdateHistoryState(..) => "UpdateHistoryState",
|
||||
RemoveHistoryStates(..) => "RemoveHistoryStates",
|
||||
FocusIFrame(..) => "FocusIFrame",
|
||||
WebDriverScriptCommand(..) => "WebDriverScriptCommand",
|
||||
TickAllAnimations(..) => "TickAllAnimations",
|
||||
WebFontLoaded(..) => "WebFontLoaded",
|
||||
DispatchIFrameLoadEvent { .. } => "DispatchIFrameLoadEvent",
|
||||
DispatchStorageEvent(..) => "DispatchStorageEvent",
|
||||
ReportCSSError(..) => "ReportCSSError",
|
||||
Reload(..) => "Reload",
|
||||
PaintMetric(..) => "PaintMetric",
|
||||
ExitFullScreen(..) => "ExitFullScreen",
|
||||
MediaSessionAction(..) => "MediaSessionAction",
|
||||
#[cfg(feature = "webgpu")]
|
||||
SetWebGPUPort(..) => "SetWebGPUPort",
|
||||
SetScrollStates(..) => "SetScrollStates",
|
||||
SetEpochPaintTime(..) => "SetEpochPaintTime",
|
||||
};
|
||||
write!(formatter, "ConstellationControlMsg::{}", variant)
|
||||
let variant_string: &'static str = self.into();
|
||||
write!(formatter, "ConstellationControlMsg::{variant_string}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ use net_traits::CoreResourceMsg;
|
|||
use net_traits::storage_thread::StorageType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use strum_macros::IntoStaticStr;
|
||||
use style_traits::CSSPixel;
|
||||
#[cfg(feature = "webgpu")]
|
||||
use webgpu::{WebGPU, WebGPUResponse, wgc};
|
||||
|
@ -46,7 +47,7 @@ pub struct IFrameSizeMsg {
|
|||
}
|
||||
|
||||
/// Messages from the layout to the constellation.
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum LayoutMsg {
|
||||
/// Requests that the constellation inform the compositor that it needs to record
|
||||
/// the time when the frame with the given ID (epoch) is painted.
|
||||
|
@ -55,11 +56,8 @@ pub enum LayoutMsg {
|
|||
|
||||
impl fmt::Debug for LayoutMsg {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::LayoutMsg::*;
|
||||
let variant = match *self {
|
||||
PendingPaintMetric(..) => "PendingPaintMetric",
|
||||
};
|
||||
write!(formatter, "LayoutMsg::{}", variant)
|
||||
let variant_string: &'static str = self.into();
|
||||
write!(formatter, "LayoutMsg::{variant_string}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +84,7 @@ pub enum LogEntry {
|
|||
}
|
||||
|
||||
/// Messages from the script to the constellation.
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum ScriptMsg {
|
||||
/// Request to complete the transfer of a set of ports to a router.
|
||||
CompleteMessagePortTransfer(MessagePortRouterId, Vec<MessagePortId>),
|
||||
|
@ -252,65 +250,8 @@ pub enum ScriptMsg {
|
|||
|
||||
impl fmt::Debug for ScriptMsg {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::ScriptMsg::*;
|
||||
let variant = match *self {
|
||||
CompleteMessagePortTransfer(..) => "CompleteMessagePortTransfer",
|
||||
MessagePortTransferResult(..) => "MessagePortTransferResult",
|
||||
NewMessagePortRouter(..) => "NewMessagePortRouter",
|
||||
RemoveMessagePortRouter(..) => "RemoveMessagePortRouter",
|
||||
NewMessagePort(..) => "NewMessagePort",
|
||||
RerouteMessagePort(..) => "RerouteMessagePort",
|
||||
RemoveMessagePort(..) => "RemoveMessagePort",
|
||||
MessagePortShipped(..) => "MessagePortShipped",
|
||||
EntanglePorts(..) => "EntanglePorts",
|
||||
NewBroadcastChannelRouter(..) => "NewBroadcastChannelRouter",
|
||||
RemoveBroadcastChannelRouter(..) => "RemoveBroadcastChannelRouter",
|
||||
RemoveBroadcastChannelNameInRouter(..) => "RemoveBroadcastChannelNameInRouter",
|
||||
NewBroadcastChannelNameInRouter(..) => "NewBroadcastChannelNameInRouter",
|
||||
ScheduleBroadcast(..) => "ScheduleBroadcast",
|
||||
ForwardToEmbedder(..) => "ForwardToEmbedder",
|
||||
BroadcastStorageEvent(..) => "BroadcastStorageEvent",
|
||||
ChangeRunningAnimationsState(..) => "ChangeRunningAnimationsState",
|
||||
CreateCanvasPaintThread(..) => "CreateCanvasPaintThread",
|
||||
Focus => "Focus",
|
||||
GetBrowsingContextInfo(..) => "GetBrowsingContextInfo",
|
||||
GetTopForBrowsingContext(..) => "GetParentBrowsingContext",
|
||||
GetChildBrowsingContextId(..) => "GetChildBrowsingContextId",
|
||||
LoadComplete => "LoadComplete",
|
||||
LoadUrl(..) => "LoadUrl",
|
||||
AbortLoadUrl => "AbortLoadUrl",
|
||||
PostMessage { .. } => "PostMessage",
|
||||
NavigatedToFragment(..) => "NavigatedToFragment",
|
||||
TraverseHistory(..) => "TraverseHistory",
|
||||
PushHistoryState(..) => "PushHistoryState",
|
||||
ReplaceHistoryState(..) => "ReplaceHistoryState",
|
||||
JointSessionHistoryLength(..) => "JointSessionHistoryLength",
|
||||
RemoveIFrame(..) => "RemoveIFrame",
|
||||
SetThrottledComplete(..) => "SetThrottledComplete",
|
||||
ScriptLoadedURLInIFrame(..) => "ScriptLoadedURLInIFrame",
|
||||
ScriptNewIFrame(..) => "ScriptNewIFrame",
|
||||
CreateAuxiliaryWebView(..) => "ScriptNewAuxiliary",
|
||||
ActivateDocument => "ActivateDocument",
|
||||
SetDocumentState(..) => "SetDocumentState",
|
||||
SetLayoutEpoch(..) => "SetLayoutEpoch",
|
||||
SetFinalUrl(..) => "SetFinalUrl",
|
||||
TouchEventProcessed(..) => "TouchEventProcessed",
|
||||
LogEntry(..) => "LogEntry",
|
||||
DiscardDocument => "DiscardDocument",
|
||||
DiscardTopLevelBrowsingContext => "DiscardTopLevelBrowsingContext",
|
||||
PipelineExited => "PipelineExited",
|
||||
ForwardDOMMessage(..) => "ForwardDOMMessage",
|
||||
ScheduleJob(..) => "ScheduleJob",
|
||||
MediaSessionEvent(..) => "MediaSessionEvent",
|
||||
#[cfg(feature = "webgpu")]
|
||||
RequestAdapter(..) => "RequestAdapter",
|
||||
#[cfg(feature = "webgpu")]
|
||||
GetWebGPUChan(..) => "GetWebGPUChan",
|
||||
TitleChanged(..) => "TitleChanged",
|
||||
IFrameSizes(..) => "IFramSizes",
|
||||
ReportMemory(..) => "ReportMemory",
|
||||
};
|
||||
write!(formatter, "ScriptMsg::{}", variant)
|
||||
let variant_string: &'static str = self.into();
|
||||
write!(formatter, "ScriptMsg::{variant_string}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue