diff options
Diffstat (limited to 'components/shared')
-rw-r--r-- | components/shared/base/id.rs | 2 | ||||
-rw-r--r-- | components/shared/compositing/lib.rs | 12 | ||||
-rw-r--r-- | components/shared/constellation/Cargo.toml | 1 | ||||
-rw-r--r-- | components/shared/constellation/from_script_message.rs | 3 | ||||
-rw-r--r-- | components/shared/constellation/structured_data/mod.rs | 7 | ||||
-rw-r--r-- | components/shared/constellation/structured_data/serializable.rs | 35 | ||||
-rw-r--r-- | components/shared/constellation/structured_data/transferable.rs | 2 | ||||
-rw-r--r-- | components/shared/embedder/Cargo.toml | 1 | ||||
-rw-r--r-- | components/shared/embedder/input_events.rs | 56 | ||||
-rw-r--r-- | components/shared/embedder/webdriver.rs | 26 | ||||
-rw-r--r-- | components/shared/net/storage_thread.rs | 4 | ||||
-rw-r--r-- | components/shared/profile/Cargo.toml | 1 | ||||
-rw-r--r-- | components/shared/script/Cargo.toml | 1 | ||||
-rw-r--r-- | components/shared/script_layout/Cargo.toml | 3 | ||||
-rw-r--r-- | components/shared/script_layout/lib.rs | 103 |
15 files changed, 240 insertions, 17 deletions
diff --git a/components/shared/base/id.rs b/components/shared/base/id.rs index b6ad1b3de9b..a091311d237 100644 --- a/components/shared/base/id.rs +++ b/components/shared/base/id.rs @@ -371,6 +371,8 @@ namespace_id! {DomExceptionId, DomExceptionIndex, "DomException"} namespace_id! {HistoryStateId, HistoryStateIndex, "HistoryState"} +namespace_id! {ImageBitmapId, ImageBitmapIndex, "ImageBitmap"} + // We provide ids just for unit testing. pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234); #[allow(unsafe_code)] diff --git a/components/shared/compositing/lib.rs b/components/shared/compositing/lib.rs index 061dfe023df..d88217142cc 100644 --- a/components/shared/compositing/lib.rs +++ b/components/shared/compositing/lib.rs @@ -10,6 +10,7 @@ use base::id::{PipelineId, WebViewId}; use crossbeam_channel::Sender; use embedder_traits::{ AnimationState, EventLoopWaker, MouseButton, MouseButtonAction, TouchEventResult, + WebDriverMessageId, }; use euclid::Rect; use ipc_channel::ipc::IpcSender; @@ -101,9 +102,16 @@ pub enum CompositorMsg { /// The load of a page has completed LoadComplete(WebViewId), /// WebDriver mouse button event - WebDriverMouseButtonEvent(WebViewId, MouseButtonAction, MouseButton, f32, f32), + WebDriverMouseButtonEvent( + WebViewId, + MouseButtonAction, + MouseButton, + f32, + f32, + WebDriverMessageId, + ), /// WebDriver mouse move event - WebDriverMouseMoveEvent(WebViewId, f32, f32), + WebDriverMouseMoveEvent(WebViewId, f32, f32, WebDriverMessageId), // Webdriver wheel scroll event WebDriverWheelScrollEvent(WebViewId, f32, f32, f64, f64), diff --git a/components/shared/constellation/Cargo.toml b/components/shared/constellation/Cargo.toml index 53a4307df60..3b093b3f684 100644 --- a/components/shared/constellation/Cargo.toml +++ b/components/shared/constellation/Cargo.toml @@ -17,7 +17,6 @@ webgpu = ["wgpu-core"] [dependencies] base = { workspace = true } -bitflags = { workspace = true } canvas_traits = { workspace = true } devtools_traits = { workspace = true } embedder_traits = { workspace = true } diff --git a/components/shared/constellation/from_script_message.rs b/components/shared/constellation/from_script_message.rs index a5424abe6d1..fa391f93859 100644 --- a/components/shared/constellation/from_script_message.rs +++ b/components/shared/constellation/from_script_message.rs @@ -17,6 +17,7 @@ use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, Worke use embedder_traits::{ AnimationState, EmbedderMsg, FocusSequenceNumber, JSValue, JavaScriptEvaluationError, JavaScriptEvaluationId, MediaSessionEvent, TouchEventResult, ViewportDetails, + WebDriverMessageId, }; use euclid::default::Size2D as UntypedSize2D; use http::{HeaderMap, Method}; @@ -652,6 +653,8 @@ pub enum ScriptToConstellationMessage { JavaScriptEvaluationId, Result<JSValue, JavaScriptEvaluationError>, ), + /// Notify the completion of a webdriver command. + WebDriverInputComplete(WebDriverMessageId), } impl fmt::Debug for ScriptToConstellationMessage { diff --git a/components/shared/constellation/structured_data/mod.rs b/components/shared/constellation/structured_data/mod.rs index 81e3849e476..3ea0d78eaf3 100644 --- a/components/shared/constellation/structured_data/mod.rs +++ b/components/shared/constellation/structured_data/mod.rs @@ -10,7 +10,7 @@ mod transferable; use std::collections::HashMap; -use base::id::{BlobId, DomExceptionId, DomPointId, MessagePortId}; +use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId, MessagePortId}; use log::warn; use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; @@ -34,6 +34,10 @@ pub struct StructuredSerializedData { pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>, /// Transform streams transferred objects. pub transform_streams: Option<HashMap<MessagePortId, TransformStreamData>>, + /// Serialized image bitmap objects. + pub image_bitmaps: Option<HashMap<ImageBitmapId, SerializableImageBitmap>>, + /// Transferred image bitmap objects. + pub transferred_image_bitmaps: Option<HashMap<ImageBitmapId, SerializableImageBitmap>>, } impl StructuredSerializedData { @@ -42,6 +46,7 @@ impl StructuredSerializedData { field.as_ref().is_some_and(|h| h.is_empty()) } match val { + Transferrable::ImageBitmap => is_field_empty(&self.transferred_image_bitmaps), Transferrable::MessagePort => is_field_empty(&self.ports), Transferrable::ReadableStream => is_field_empty(&self.ports), Transferrable::WritableStream => is_field_empty(&self.ports), diff --git a/components/shared/constellation/structured_data/serializable.rs b/components/shared/constellation/structured_data/serializable.rs index 22370087665..cbb932c52ec 100644 --- a/components/shared/constellation/structured_data/serializable.rs +++ b/components/shared/constellation/structured_data/serializable.rs @@ -11,7 +11,7 @@ use std::cell::RefCell; use std::collections::HashMap; use std::path::PathBuf; -use base::id::{BlobId, DomExceptionId, DomPointId}; +use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId}; use malloc_size_of_derive::MallocSizeOf; use net_traits::filemanager_thread::RelativePos; use serde::{Deserialize, Serialize}; @@ -47,6 +47,8 @@ pub enum Serializable { DomPointReadOnly, /// The `DOMException` interface. DomException, + /// The `ImageBitmap` interface. + ImageBitmap, } impl Serializable { @@ -62,6 +64,9 @@ impl Serializable { Serializable::DomException => { StructuredSerializedData::clone_all_of_type::<DomException> }, + Serializable::ImageBitmap => { + StructuredSerializedData::clone_all_of_type::<SerializableImageBitmap> + }, } } } @@ -312,3 +317,31 @@ impl BroadcastClone for DomException { Some(self.clone()) } } + +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] +/// A serializable version of the ImageBitmap interface. +pub struct SerializableImageBitmap { + pub width: u32, + pub height: u32, + pub bitmap_data: Vec<u8>, +} + +impl BroadcastClone for SerializableImageBitmap { + type Id = ImageBitmapId; + + fn source( + data: &StructuredSerializedData, + ) -> &Option<std::collections::HashMap<Self::Id, Self>> { + &data.image_bitmaps + } + + fn destination( + data: &mut StructuredSerializedData, + ) -> &mut Option<std::collections::HashMap<Self::Id, Self>> { + &mut data.image_bitmaps + } + + fn clone_for_broadcast(&self) -> Option<Self> { + Some(self.clone()) + } +} diff --git a/components/shared/constellation/structured_data/transferable.rs b/components/shared/constellation/structured_data/transferable.rs index 3210a41a538..bce10420182 100644 --- a/components/shared/constellation/structured_data/transferable.rs +++ b/components/shared/constellation/structured_data/transferable.rs @@ -24,6 +24,8 @@ pub struct TransformStreamData { /// All the DOM interfaces that can be transferred. #[derive(Clone, Copy, Debug, EnumIter)] pub enum Transferrable { + /// The `ImageBitmap` interface. + ImageBitmap, /// The `MessagePort` interface. MessagePort, /// The `ReadableStream` interface. diff --git a/components/shared/embedder/Cargo.toml b/components/shared/embedder/Cargo.toml index d938169d37a..4904adf6447 100644 --- a/components/shared/embedder/Cargo.toml +++ b/components/shared/embedder/Cargo.toml @@ -18,7 +18,6 @@ baked-default-resources = [] [dependencies] base = { workspace = true } -cfg-if = { workspace = true } cookie = { workspace = true } crossbeam-channel = { workspace = true } euclid = { workspace = true } diff --git a/components/shared/embedder/input_events.rs b/components/shared/embedder/input_events.rs index acaa9afb3ff..869c4eee004 100644 --- a/components/shared/embedder/input_events.rs +++ b/components/shared/embedder/input_events.rs @@ -8,6 +8,8 @@ use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; use webrender_api::units::DevicePoint; +use crate::WebDriverMessageId; + /// An input event that is sent from the embedder to Servo. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum InputEvent { @@ -42,6 +44,38 @@ impl InputEvent { InputEvent::Wheel(event) => Some(event.point), } } + + pub fn webdriver_message_id(&self) -> Option<WebDriverMessageId> { + match self { + InputEvent::EditingAction(..) => None, + InputEvent::Gamepad(..) => None, + InputEvent::Ime(..) => None, + InputEvent::Keyboard(..) => None, + InputEvent::MouseButton(event) => event.webdriver_id, + InputEvent::MouseMove(event) => event.webdriver_id, + InputEvent::Touch(..) => None, + InputEvent::Wheel(..) => None, + } + } + + pub fn with_webdriver_message_id(self, webdriver_id: Option<WebDriverMessageId>) -> Self { + match self { + InputEvent::EditingAction(..) => {}, + InputEvent::Gamepad(..) => {}, + InputEvent::Ime(..) => {}, + InputEvent::Keyboard(..) => {}, + InputEvent::MouseButton(mut event) => { + event.webdriver_id = webdriver_id; + }, + InputEvent::MouseMove(mut event) => { + event.webdriver_id = webdriver_id; + }, + InputEvent::Touch(..) => {}, + InputEvent::Wheel(..) => {}, + }; + + self + } } #[derive(Clone, Copy, Debug, Deserialize, Serialize)] @@ -49,6 +83,18 @@ pub struct MouseButtonEvent { pub action: MouseButtonAction, pub button: MouseButton, pub point: DevicePoint, + webdriver_id: Option<WebDriverMessageId>, +} + +impl MouseButtonEvent { + pub fn new(action: MouseButtonAction, button: MouseButton, point: DevicePoint) -> Self { + Self { + action, + button, + point, + webdriver_id: None, + } + } } #[derive(Clone, Copy, Debug, Deserialize, Serialize)] @@ -102,6 +148,16 @@ pub enum MouseButtonAction { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct MouseMoveEvent { pub point: DevicePoint, + webdriver_id: Option<WebDriverMessageId>, +} + +impl MouseMoveEvent { + pub fn new(point: DevicePoint) -> Self { + Self { + point, + webdriver_id: None, + } + } } /// The type of input represented by a multi-touch event. diff --git a/components/shared/embedder/webdriver.rs b/components/shared/embedder/webdriver.rs index 3716a29951a..e7118d32737 100644 --- a/components/shared/embedder/webdriver.rs +++ b/components/shared/embedder/webdriver.rs @@ -24,6 +24,9 @@ use webrender_api::units::DeviceIntSize; use crate::{MouseButton, MouseButtonAction}; +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] +pub struct WebDriverMessageId(pub usize); + /// Messages to the constellation originating from the WebDriver server. #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverCommandMsg { @@ -41,9 +44,23 @@ pub enum WebDriverCommandMsg { /// Act as if keys were pressed or release in the browsing context with the given ID. KeyboardAction(BrowsingContextId, KeyboardEvent), /// Act as if the mouse was clicked in the browsing context with the given ID. - MouseButtonAction(WebViewId, MouseButtonAction, MouseButton, f32, f32), + MouseButtonAction( + WebViewId, + MouseButtonAction, + MouseButton, + f32, + f32, + WebDriverMessageId, + IpcSender<WebDriverCommandResponse>, + ), /// Act as if the mouse was moved in the browsing context with the given ID. - MouseMoveAction(WebViewId, f32, f32), + MouseMoveAction( + WebViewId, + f32, + f32, + WebDriverMessageId, + IpcSender<WebDriverCommandResponse>, + ), /// Act as if the mouse wheel is scrolled in the browsing context given the given ID. WheelScrollAction(WebViewId, f32, f32, f64, f64), /// Set the window size. @@ -189,6 +206,11 @@ pub enum WebDriverFrameId { } #[derive(Debug, Deserialize, Serialize)] +pub struct WebDriverCommandResponse { + pub id: WebDriverMessageId, +} + +#[derive(Debug, Deserialize, Serialize)] pub enum WebDriverLoadStatus { Complete, Timeout, diff --git a/components/shared/net/storage_thread.rs b/components/shared/net/storage_thread.rs index 0253603016e..2ba0aa12445 100644 --- a/components/shared/net/storage_thread.rs +++ b/components/shared/net/storage_thread.rs @@ -4,6 +4,7 @@ use ipc_channel::ipc::IpcSender; use malloc_size_of_derive::MallocSizeOf; +use profile_traits::mem::ReportsChan; use serde::{Deserialize, Serialize}; use servo_url::ServoUrl; @@ -45,4 +46,7 @@ pub enum StorageThreadMsg { /// send a reply when done cleaning up thread resources and then shut it down Exit(IpcSender<()>), + + /// Measure memory used by this thread and send the report over the provided channel. + CollectMemoryReport(ReportsChan), } diff --git a/components/shared/profile/Cargo.toml b/components/shared/profile/Cargo.toml index 8086bf17ba2..68a7df28c00 100644 --- a/components/shared/profile/Cargo.toml +++ b/components/shared/profile/Cargo.toml @@ -25,6 +25,5 @@ serde = { workspace = true } servo_allocator = { path = "../../allocator" } servo_config = { path = "../../config" } signpost = { git = "https://github.com/pcwalton/signpost.git" } -strum_macros = { workspace = true } time = { workspace = true } tracing = { workspace = true, optional = true } diff --git a/components/shared/script/Cargo.toml b/components/shared/script/Cargo.toml index 0d3690188fe..69438867cc0 100644 --- a/components/shared/script/Cargo.toml +++ b/components/shared/script/Cargo.toml @@ -26,7 +26,6 @@ crossbeam-channel = { workspace = true } devtools_traits = { workspace = true } embedder_traits = { workspace = true } euclid = { workspace = true } -http = { workspace = true } ipc-channel = { workspace = true } keyboard-types = { workspace = true } malloc_size_of = { workspace = true } diff --git a/components/shared/script_layout/Cargo.toml b/components/shared/script_layout/Cargo.toml index 06690192f73..167606f7247 100644 --- a/components/shared/script_layout/Cargo.toml +++ b/components/shared/script_layout/Cargo.toml @@ -15,7 +15,6 @@ path = "lib.rs" base = { workspace = true } app_units = { workspace = true } atomic_refcell = { workspace = true } -canvas_traits = { workspace = true } compositing_traits = { workspace = true } constellation_traits = { workspace = true } embedder_traits = { workspace = true } @@ -29,7 +28,6 @@ ipc-channel = { workspace = true } libc = { workspace = true } malloc_size_of = { workspace = true } malloc_size_of_derive = { workspace = true } -metrics = { path = "../../metrics" } net_traits = { workspace = true } pixels = { path = "../../pixels" } profile_traits = { workspace = true } @@ -40,5 +38,4 @@ serde = { workspace = true } servo_arc = { workspace = true } servo_url = { path = "../../url" } stylo = { workspace = true } -stylo_traits = { workspace = true } webrender_api = { workspace = true } diff --git a/components/shared/script_layout/lib.rs b/components/shared/script_layout/lib.rs index 1f526b64240..96670e60084 100644 --- a/components/shared/script_layout/lib.rs +++ b/components/shared/script_layout/lib.rs @@ -507,21 +507,116 @@ pub fn node_id_from_scroll_id(id: usize) -> Option<usize> { #[derive(Clone, Debug, MallocSizeOf)] pub struct ImageAnimationState { #[ignore_malloc_size_of = "Arc is hard"] - image: Arc<Image>, - active_frame: usize, + pub image: Arc<Image>, + pub active_frame: usize, last_update_time: f64, } impl ImageAnimationState { - pub fn new(image: Arc<Image>) -> Self { + pub fn new(image: Arc<Image>, last_update_time: f64) -> Self { Self { image, active_frame: 0, - last_update_time: 0., + last_update_time, } } pub fn image_key(&self) -> Option<ImageKey> { self.image.id } + + pub fn time_to_next_frame(&self, now: f64) -> f64 { + let frame_delay = self + .image + .frames + .get(self.active_frame) + .expect("Image frame should always be valid") + .delay + .map_or(0., |delay| delay.as_secs_f64()); + (frame_delay - now + self.last_update_time).max(0.0) + } + + /// check whether image active frame need to be updated given current time, + /// return true if there are image that need to be updated. + /// false otherwise. + pub fn update_frame_for_animation_timeline_value(&mut self, now: f64) -> bool { + if self.image.frames.len() <= 1 { + return false; + } + let image = &self.image; + let time_interval_since_last_update = now - self.last_update_time; + let mut remain_time_interval = time_interval_since_last_update - + image + .frames + .get(self.active_frame) + .unwrap() + .delay + .unwrap() + .as_secs_f64(); + let mut next_active_frame_id = self.active_frame; + while remain_time_interval > 0.0 { + next_active_frame_id = (next_active_frame_id + 1) % image.frames.len(); + remain_time_interval -= image + .frames + .get(next_active_frame_id) + .unwrap() + .delay + .unwrap() + .as_secs_f64(); + } + if self.active_frame == next_active_frame_id { + return false; + } + self.active_frame = next_active_frame_id; + self.last_update_time = now; + true + } +} + +#[cfg(test)] +mod test { + use std::sync::Arc; + use std::time::Duration; + + use ipc_channel::ipc::IpcSharedMemory; + use pixels::{CorsStatus, Image, ImageFrame, PixelFormat}; + + use crate::ImageAnimationState; + + #[test] + fn test() { + let image_frames: Vec<ImageFrame> = std::iter::repeat_with(|| ImageFrame { + delay: Some(Duration::from_millis(100)), + byte_range: 0..1, + width: 100, + height: 100, + }) + .take(10) + .collect(); + let image = Image { + width: 100, + height: 100, + format: PixelFormat::BGRA8, + id: None, + bytes: IpcSharedMemory::from_byte(1, 1), + frames: image_frames, + cors_status: CorsStatus::Unsafe, + }; + let mut image_animation_state = ImageAnimationState::new(Arc::new(image), 0.0); + + assert_eq!(image_animation_state.active_frame, 0); + assert_eq!(image_animation_state.last_update_time, 0.0); + assert_eq!( + image_animation_state.update_frame_for_animation_timeline_value(0.101), + true + ); + assert_eq!(image_animation_state.active_frame, 1); + assert_eq!(image_animation_state.last_update_time, 0.101); + assert_eq!( + image_animation_state.update_frame_for_animation_timeline_value(0.116), + false + ); + assert_eq!(image_animation_state.active_frame, 1); + assert_eq!(image_animation_state.last_update_time, 0.101); + } } |