diff --git a/Cargo.lock b/Cargo.lock index 04e53d5dd00..c88f40d40cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,7 +805,6 @@ dependencies = [ "range", "raqote", "servo_arc", - "snapshot", "stylo", "unicode-script", "webrender_api", @@ -826,7 +825,6 @@ dependencies = [ "serde_bytes", "servo_config", "servo_malloc_size_of", - "snapshot", "stylo", "webrender_api", "webxr-api", @@ -1215,11 +1213,11 @@ dependencies = [ "log", "malloc_size_of_derive", "net_traits", + "pixels", "profile_traits", "serde", "servo_malloc_size_of", "servo_url", - "snapshot", "strum", "strum_macros", "uuid", @@ -6650,7 +6648,6 @@ dependencies = [ "servo_rand", "servo_url", "smallvec", - "snapshot", "strum", "strum_macros", "stylo", @@ -7426,18 +7423,6 @@ dependencies = [ "serde", ] -[[package]] -name = "snapshot" -version = "0.0.1" -dependencies = [ - "euclid", - "ipc-channel", - "malloc_size_of_derive", - "pixels", - "serde", - "servo_malloc_size_of", -] - [[package]] name = "socket2" version = "0.5.10" @@ -8987,7 +8972,6 @@ dependencies = [ "itertools 0.14.0", "log", "pixels", - "snapshot", "surfman", "webrender", "webrender_api", @@ -9005,9 +8989,9 @@ dependencies = [ "euclid", "ipc-channel", "log", + "pixels", "serde", "servo_config", - "snapshot", "webgpu_traits", "webrender", "webrender_api", @@ -9022,9 +9006,9 @@ dependencies = [ "arrayvec", "base", "ipc-channel", + "pixels", "serde", "servo_malloc_size_of", - "snapshot", "webrender_api", "wgpu-core", "wgpu-types", diff --git a/Cargo.toml b/Cargo.toml index edfce3d48be..f74964ed07b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,7 +131,6 @@ servo-tracing = { path = "components/servo_tracing" } servo_arc = { git = "https://github.com/servo/stylo", branch = "2025-06-03" } smallbitvec = "2.6.0" smallvec = "1.15" -snapshot = { path = "./components/shared/snapshot" } static_assertions = "1.1" string_cache = "0.8" string_cache_codegen = "0.5" diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index 7aadc8a9bb5..9284c2f89bc 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -28,7 +28,6 @@ pixels = { path = "../pixels" } range = { path = "../range" } raqote = "0.8.5" servo_arc = { workspace = true } -snapshot = { workspace = true } stylo = { workspace = true } unicode-script = { workspace = true } webrender_api = { workspace = true } diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 449e7ef5802..3d833facc1c 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -17,9 +17,9 @@ use fonts::{ }; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; use log::warn; +use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use range::Range; use servo_arc::Arc as ServoArc; -use snapshot::Snapshot; use style::color::AbsoluteColor; use style::properties::style_structs::Font as FontStyleStruct; use unicode_script::Script; @@ -1336,8 +1336,8 @@ impl<'a, B: Backend> CanvasData<'a, B> { Snapshot::from_vec( canvas_size, - snapshot::PixelFormat::BGRA, - snapshot::AlphaMode::Transparent { + SnapshotPixelFormat::BGRA, + SnapshotAlphaMode::Transparent { premultiplied: true, }, data, diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index 93aff081c35..ab270eec835 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -17,6 +17,7 @@ use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use log::warn; use net_traits::ResourceThreads; +use pixels::Snapshot; use style::color::AbsoluteColor; use style::properties::style_structs::Font as FontStyleStruct; use webrender_api::ImageKey; @@ -420,7 +421,7 @@ impl Canvas<'_> { &mut self, read_rect: Option>, canvas_size: Option>, - ) -> snapshot::Snapshot { + ) -> Snapshot { match self { Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size), } diff --git a/components/pixels/lib.rs b/components/pixels/lib.rs index c6f85348df1..3f7b3ec6bfc 100644 --- a/components/pixels/lib.rs +++ b/components/pixels/lib.rs @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +mod snapshot; + use std::borrow::Cow; use std::io::Cursor; use std::ops::Range; @@ -16,6 +18,7 @@ use ipc_channel::ipc::IpcSharedMemory; use log::debug; use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; +pub use snapshot::*; use webrender_api::ImageKey; #[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)] diff --git a/components/shared/snapshot/lib.rs b/components/pixels/snapshot.rs similarity index 72% rename from components/shared/snapshot/lib.rs rename to components/pixels/snapshot.rs index 47def64a8f5..9a14b0935c3 100644 --- a/components/shared/snapshot/lib.rs +++ b/components/pixels/snapshot.rs @@ -7,18 +7,19 @@ use std::ops::{Deref, DerefMut}; use euclid::default::Size2D; use ipc_channel::ipc::IpcSharedMemory; use malloc_size_of_derive::MallocSizeOf; -use pixels::Multiply; use serde::{Deserialize, Serialize}; +use crate::{Multiply, transform_inplace}; + #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)] -pub enum PixelFormat { +pub enum SnapshotPixelFormat { #[default] RGBA, BGRA, } #[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)] -pub enum AlphaMode { +pub enum SnapshotAlphaMode { /// Internal data is opaque (alpha is cleared to 1) Opaque, /// Internal data should be threated as opaque (does not mean it actually is) @@ -27,7 +28,7 @@ pub enum AlphaMode { Transparent { premultiplied: bool }, } -impl Default for AlphaMode { +impl Default for SnapshotAlphaMode { fn default() -> Self { Self::Transparent { premultiplied: true, @@ -35,43 +36,46 @@ impl Default for AlphaMode { } } -impl AlphaMode { +impl SnapshotAlphaMode { pub const fn is_premultiplied(&self) -> bool { match self { - AlphaMode::Opaque => true, - AlphaMode::AsOpaque { premultiplied } => *premultiplied, - AlphaMode::Transparent { premultiplied } => *premultiplied, + SnapshotAlphaMode::Opaque => true, + SnapshotAlphaMode::AsOpaque { premultiplied } => *premultiplied, + SnapshotAlphaMode::Transparent { premultiplied } => *premultiplied, } } pub const fn is_opaque(&self) -> bool { - matches!(self, AlphaMode::Opaque | AlphaMode::AsOpaque { .. }) + matches!( + self, + SnapshotAlphaMode::Opaque | SnapshotAlphaMode::AsOpaque { .. } + ) } } #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] -pub enum Data { +pub enum SnapshotData { // TODO: https://github.com/servo/servo/issues/36594 //IPC(IpcSharedMemory), Owned(Vec), } -impl Deref for Data { +impl Deref for SnapshotData { type Target = [u8]; fn deref(&self) -> &Self::Target { match &self { //Data::IPC(ipc_shared_memory) => ipc_shared_memory, - Data::Owned(items) => items, + SnapshotData::Owned(items) => items, } } } -impl DerefMut for Data { +impl DerefMut for SnapshotData { fn deref_mut(&mut self) -> &mut Self::Target { match self { //Data::IPC(ipc_shared_memory) => unsafe { ipc_shared_memory.deref_mut() }, - Data::Owned(items) => items, + SnapshotData::Owned(items) => items, } } } @@ -86,14 +90,14 @@ pub type IpcSnapshot = Snapshot; /// Inspired by snapshot for concept in WebGPU spec: /// #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] -pub struct Snapshot { +pub struct Snapshot { size: Size2D, /// internal data (can be any format it will be converted on use if needed) data: T, /// RGBA/BGRA (reflect internal data) - format: PixelFormat, + format: SnapshotPixelFormat, /// How to treat alpha channel - alpha_mode: AlphaMode, + alpha_mode: SnapshotAlphaMode, } impl Snapshot { @@ -101,11 +105,11 @@ impl Snapshot { self.size } - pub const fn format(&self) -> PixelFormat { + pub const fn format(&self) -> SnapshotPixelFormat { self.format } - pub const fn alpha_mode(&self) -> AlphaMode { + pub const fn alpha_mode(&self) -> SnapshotAlphaMode { self.alpha_mode } @@ -118,13 +122,13 @@ impl Snapshot { } } -impl Snapshot { +impl Snapshot { pub fn empty() -> Self { Self { size: Size2D::zero(), - data: Data::Owned(vec![]), - format: PixelFormat::RGBA, - alpha_mode: AlphaMode::Transparent { + data: SnapshotData::Owned(vec![]), + format: SnapshotPixelFormat::RGBA, + alpha_mode: SnapshotAlphaMode::Transparent { premultiplied: true, }, } @@ -134,9 +138,9 @@ impl Snapshot { pub fn cleared(size: Size2D) -> Self { Self { size, - data: Data::Owned(vec![0; size.area() as usize * 4]), - format: PixelFormat::RGBA, - alpha_mode: AlphaMode::Transparent { + data: SnapshotData::Owned(vec![0; size.area() as usize * 4]), + format: SnapshotPixelFormat::RGBA, + alpha_mode: SnapshotAlphaMode::Transparent { premultiplied: true, }, } @@ -144,13 +148,13 @@ impl Snapshot { pub fn from_vec( size: Size2D, - format: PixelFormat, - alpha_mode: AlphaMode, + format: SnapshotPixelFormat, + alpha_mode: SnapshotAlphaMode, data: Vec, ) -> Self { Self { size, - data: Data::Owned(data), + data: SnapshotData::Owned(data), format, alpha_mode, } @@ -187,11 +191,15 @@ impl Snapshot { /// Convert inner data of snapshot to target format and alpha mode. /// If data is already in target format and alpha mode no work will be done. - pub fn transform(&mut self, target_alpha_mode: AlphaMode, target_format: PixelFormat) { + pub fn transform( + &mut self, + target_alpha_mode: SnapshotAlphaMode, + target_format: SnapshotPixelFormat, + ) { let swap_rb = target_format != self.format; let multiply = match (self.alpha_mode, target_alpha_mode) { - (AlphaMode::Opaque, _) => Multiply::None, - (alpha_mode, AlphaMode::Opaque) => { + (SnapshotAlphaMode::Opaque, _) => Multiply::None, + (alpha_mode, SnapshotAlphaMode::Opaque) => { if alpha_mode.is_premultiplied() { Multiply::UnMultiply } else { @@ -199,11 +207,12 @@ impl Snapshot { } }, ( - AlphaMode::Transparent { premultiplied } | AlphaMode::AsOpaque { premultiplied }, - AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied } | + SnapshotAlphaMode::AsOpaque { premultiplied }, + SnapshotAlphaMode::Transparent { premultiplied: target_premultiplied, } | - AlphaMode::AsOpaque { + SnapshotAlphaMode::AsOpaque { premultiplied: target_premultiplied, }, ) => { @@ -216,9 +225,9 @@ impl Snapshot { } }, }; - let clear_alpha = !matches!(self.alpha_mode, AlphaMode::Opaque) && - matches!(target_alpha_mode, AlphaMode::Opaque); - pixels::transform_inplace(self.data.deref_mut(), multiply, swap_rb, clear_alpha); + let clear_alpha = !matches!(self.alpha_mode, SnapshotAlphaMode::Opaque) && + matches!(target_alpha_mode, SnapshotAlphaMode::Opaque); + transform_inplace(self.data.deref_mut(), multiply, swap_rb, clear_alpha); self.alpha_mode = target_alpha_mode; self.format = target_format; } @@ -232,7 +241,7 @@ impl Snapshot { } = self; let data = match data { //Data::IPC(ipc_shared_memory) => ipc_shared_memory, - Data::Owned(items) => IpcSharedMemory::from_bytes(&items), + SnapshotData::Owned(items) => IpcSharedMemory::from_bytes(&items), }; Snapshot { size, @@ -244,7 +253,7 @@ impl Snapshot { pub fn to_vec(self) -> Vec { match self.data { - Data::Owned(data) => data, + SnapshotData::Owned(data) => data, } } } @@ -271,7 +280,7 @@ impl Snapshot { } } */ - pub fn to_owned(self) -> Snapshot { + pub fn to_owned(self) -> Snapshot { let Snapshot { size, data, @@ -280,7 +289,7 @@ impl Snapshot { } = self; Snapshot { size, - data: Data::Owned(data.to_vec()), + data: SnapshotData::Owned(data.to_vec()), format, alpha_mode, } diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 09dab3471df..1cbf7c47e01 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -113,7 +113,6 @@ servo_config = { path = "../config" } servo_geometry = { path = "../geometry" } servo_rand = { path = "../rand" } servo_url = { path = "../url" } -snapshot = { workspace = true } smallvec = { workspace = true, features = ["union"] } strum = { workspace = true } strum_macros = { workspace = true } diff --git a/components/script/canvas_context.rs b/components/script/canvas_context.rs index 31e893729d1..a4db133673e 100644 --- a/components/script/canvas_context.rs +++ b/components/script/canvas_context.rs @@ -5,9 +5,9 @@ //! Common interfaces for Canvas Contexts use euclid::default::Size2D; +use pixels::Snapshot; use script_bindings::root::Dom; use script_layout_interface::HTMLCanvasData; -use snapshot::Snapshot; use webrender_api::ImageKey; use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas; diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index c37d8e81c35..323fb97d2e3 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -20,7 +20,7 @@ use euclid::vec2; use ipc_channel::ipc::{self, IpcSender}; use net_traits::image_cache::{ImageCache, ImageResponse}; use net_traits::request::CorsSettings; -use pixels::PixelFormat; +use pixels::{PixelFormat, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use profile_traits::ipc as profiled_ipc; use servo_url::{ImmutableOrigin, ServoUrl}; use style::color::{AbsoluteColor, ColorFlags, ColorSpace}; @@ -330,7 +330,7 @@ impl CanvasState { &self, url: ServoUrl, cors_setting: Option, - ) -> Option { + ) -> Option { let img = match self.request_image_from_cache(url, cors_setting) { ImageResponse::Loaded(image, _) => { if let Some(image) = image.as_raster_image() { @@ -350,15 +350,15 @@ impl CanvasState { let size = Size2D::new(img.metadata.width, img.metadata.height); let format = match img.format { - PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA, - PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA, + PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA, + PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA, pixel_format => unimplemented!("unsupported pixel format ({:?})", pixel_format), }; - let alpha_mode = snapshot::AlphaMode::Transparent { + let alpha_mode = SnapshotAlphaMode::Transparent { premultiplied: false, }; - Some(snapshot::Snapshot::from_vec( + Some(Snapshot::from_vec( size.cast(), format, alpha_mode, @@ -393,10 +393,10 @@ impl CanvasState { self.send_canvas_2d_msg(Canvas2dMsg::GetImageData(rect, canvas_size, sender)); let mut snapshot = receiver.recv().unwrap().to_owned(); snapshot.transform( - snapshot::AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied: false, }, - snapshot::PixelFormat::RGBA, + SnapshotPixelFormat::RGBA, ); snapshot.to_vec() } diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 859454a3064..3e7cf1f0bda 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -6,10 +6,10 @@ use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg, FromScriptMsg}; use dom_struct::dom_struct; use euclid::default::Size2D; use ipc_channel::ipc::IpcSender; +use pixels::Snapshot; use profile_traits::ipc; use script_bindings::inheritance::Castable; use servo_url::ServoUrl; -use snapshot::Snapshot; use webrender_api::ImageKey; use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers}; diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 492cccb66c1..ceb4064c905 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -60,11 +60,10 @@ use net_traits::{ CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend, ReferrerPolicy, ResourceThreads, fetch_async, }; -use pixels::{CorsStatus, PixelFormat}; +use pixels::{CorsStatus, PixelFormat, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time}; use script_bindings::interfaces::GlobalScopeHelpers; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; -use snapshot::Snapshot; use timers::{TimerEventRequest, TimerId}; use url::Origin; use uuid::Uuid; @@ -3084,13 +3083,13 @@ impl GlobalScope { let size = Size2D::new(img.metadata.width, img.metadata.height); let format = match img.format { - PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA, - PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA, + PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA, + PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA, pixel_format => { unimplemented!("unsupported pixel format ({:?})", pixel_format) }, }; - let alpha_mode = snapshot::AlphaMode::Transparent { + let alpha_mode = SnapshotAlphaMode::Transparent { premultiplied: false, }; @@ -3278,13 +3277,13 @@ impl GlobalScope { let size = Size2D::new(img.metadata.width, img.metadata.height); let format = match img.format { - PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA, - PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA, + PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA, + PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA, pixel_format => { unimplemented!("unsupported pixel format ({:?})", pixel_format) }, }; - let alpha_mode = snapshot::AlphaMode::Transparent { + let alpha_mode = SnapshotAlphaMode::Transparent { premultiplied: false, }; @@ -3319,13 +3318,13 @@ impl GlobalScope { return p; } - let alpha_mode = snapshot::AlphaMode::Transparent { + let alpha_mode = SnapshotAlphaMode::Transparent { premultiplied: false, }; let snapshot = Snapshot::from_vec( image_data.get_size().cast(), - snapshot::PixelFormat::RGBA, + SnapshotPixelFormat::RGBA, alpha_mode, image_data.to_vec(), ); diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 2ac9e92f40c..a783a8794e4 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -21,10 +21,10 @@ use image::{ColorType, ImageEncoder, ImageError}; use ipc_channel::ipc::{self as ipcchan}; use js::error::throw_type_error; use js::rust::{HandleObject, HandleValue}; +use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use script_layout_interface::HTMLCanvasData; use servo_media::streams::MediaStreamType; use servo_media::streams::registry::MediaStreamId; -use snapshot::Snapshot; use style::attr::AttrValue; use super::node::NodeDamage; @@ -543,15 +543,15 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement { let image_type = EncodedImageType::from(mime_type); snapshot.transform( if image_type == EncodedImageType::Jpeg { - snapshot::AlphaMode::AsOpaque { + SnapshotAlphaMode::AsOpaque { premultiplied: true, } } else { - snapshot::AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied: false, } }, - snapshot::PixelFormat::RGBA, + SnapshotPixelFormat::RGBA, ); let mut url = format!("data:{};base64,", image_type.as_mime_type()); @@ -627,8 +627,8 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement { }; snapshot.transform( - snapshot::AlphaMode::Transparent{ premultiplied: false }, - snapshot::PixelFormat::RGBA + SnapshotAlphaMode::Transparent { premultiplied: false }, + SnapshotPixelFormat::RGBA ); // Step 4.1: If result is non-null, then set result to a serialization of diff --git a/components/script/dom/htmlvideoelement.rs b/components/script/dom/htmlvideoelement.rs index f767fb657b0..5ab58fab15b 100644 --- a/components/script/dom/htmlvideoelement.rs +++ b/components/script/dom/htmlvideoelement.rs @@ -19,10 +19,10 @@ use net_traits::{ FetchMetadata, FetchResponseListener, FetchResponseMsg, NetworkError, ResourceFetchTiming, ResourceTimingType, }; +use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use script_layout_interface::{HTMLMediaData, MediaMetadata}; use servo_media::player::video::VideoFrame; use servo_url::ServoUrl; -use snapshot::Snapshot; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use crate::document_loader::{LoadBlocker, LoadType}; @@ -146,13 +146,13 @@ impl HTMLVideoElement { Some(frame) => { let size = Size2D::new(frame.get_width() as u32, frame.get_height() as u32); if !frame.is_gl_texture() { - let alpha_mode = snapshot::AlphaMode::Transparent { + let alpha_mode = SnapshotAlphaMode::Transparent { premultiplied: false, }; Some(Snapshot::from_vec( size.cast(), - snapshot::PixelFormat::BGRA, + SnapshotPixelFormat::BGRA, alpha_mode, frame.get_data().to_vec(), )) diff --git a/components/script/dom/imagebitmap.rs b/components/script/dom/imagebitmap.rs index 992b07fc501..76e111cb99f 100644 --- a/components/script/dom/imagebitmap.rs +++ b/components/script/dom/imagebitmap.rs @@ -9,7 +9,7 @@ use base::id::{ImageBitmapId, ImageBitmapIndex}; use constellation_traits::SerializableImageBitmap; use dom_struct::dom_struct; use euclid::default::{Point2D, Rect, Size2D}; -use snapshot::Snapshot; +use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{ @@ -246,18 +246,18 @@ impl ImageBitmap { match options.premultiplyAlpha { PremultiplyAlpha::Default | PremultiplyAlpha::Premultiply => { output.transform( - snapshot::AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied: true, }, - snapshot::PixelFormat::BGRA, + SnapshotPixelFormat::BGRA, ); }, PremultiplyAlpha::None => { output.transform( - snapshot::AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied: false, }, - snapshot::PixelFormat::BGRA, + SnapshotPixelFormat::BGRA, ); }, } diff --git a/components/script/dom/offscreencanvas.rs b/components/script/dom/offscreencanvas.rs index 391c83f3a84..b890f872f8f 100644 --- a/components/script/dom/offscreencanvas.rs +++ b/components/script/dom/offscreencanvas.rs @@ -7,7 +7,7 @@ use std::cell::Cell; use dom_struct::dom_struct; use euclid::default::Size2D; use js::rust::{HandleObject, HandleValue}; -use snapshot::Snapshot; +use pixels::Snapshot; use crate::canvas_context::{CanvasContext, OffscreenRenderingContext}; use crate::dom::bindings::cell::{DomRefCell, Ref}; diff --git a/components/script/dom/offscreencanvasrenderingcontext2d.rs b/components/script/dom/offscreencanvasrenderingcontext2d.rs index f5ed2ca28e7..702cd609214 100644 --- a/components/script/dom/offscreencanvasrenderingcontext2d.rs +++ b/components/script/dom/offscreencanvasrenderingcontext2d.rs @@ -7,7 +7,7 @@ use crate::canvas_context::CanvasContext; use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas; use canvas_traits::canvas::Canvas2dMsg; use dom_struct::dom_struct; -use snapshot::Snapshot; +use pixels::Snapshot; use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{ CanvasDirection, CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin, diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index b237304ad44..43075fe502d 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -21,9 +21,9 @@ use js::jsapi::{JSObject, Type}; use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, UInt32Value}; use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue}; use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array}; +use pixels::Snapshot; use script_bindings::interfaces::WebGL2RenderingContextHelpers; use servo_config::pref; -use snapshot::Snapshot; use url::Host; use webrender_api::ImageKey; diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 1cd246e39d1..d6d4ce3bff6 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -30,10 +30,9 @@ use js::typedarray::{ TypedArrayElementCreator, Uint32Array, }; use net_traits::image_cache::ImageResponse; -use pixels::{self, PixelFormat}; +use pixels::{self, PixelFormat, Snapshot, SnapshotPixelFormat}; use serde::{Deserialize, Serialize}; use servo_config::pref; -use snapshot::Snapshot; use webrender_api::ImageKey; use crate::canvas_context::CanvasContext; @@ -586,8 +585,8 @@ impl WebGLRenderingContext { let snapshot = snapshot.as_ipc(); let size = snapshot.size().cast(); let format = match snapshot.format() { - snapshot::PixelFormat::RGBA => PixelFormat::RGBA8, - snapshot::PixelFormat::BGRA => PixelFormat::BGRA8, + SnapshotPixelFormat::RGBA => PixelFormat::RGBA8, + SnapshotPixelFormat::BGRA => PixelFormat::BGRA8, }; let premultiply = snapshot.alpha_mode().is_premultiplied(); TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply) @@ -666,8 +665,8 @@ impl WebGLRenderingContext { let snapshot = snapshot.as_ipc(); let size = snapshot.size().cast(); let format = match snapshot.format() { - snapshot::PixelFormat::RGBA => PixelFormat::RGBA8, - snapshot::PixelFormat::BGRA => PixelFormat::BGRA8, + SnapshotPixelFormat::RGBA => PixelFormat::RGBA8, + SnapshotPixelFormat::BGRA => PixelFormat::BGRA8, }; let premultiply = snapshot.alpha_mode().is_premultiplied(); TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply) @@ -687,8 +686,8 @@ impl WebGLRenderingContext { let snapshot = snapshot.as_ipc(); let size = snapshot.size().cast(); let format: PixelFormat = match snapshot.format() { - snapshot::PixelFormat::RGBA => PixelFormat::RGBA8, - snapshot::PixelFormat::BGRA => PixelFormat::BGRA8, + SnapshotPixelFormat::RGBA => PixelFormat::RGBA8, + SnapshotPixelFormat::BGRA => PixelFormat::BGRA8, }; let premultiply = snapshot.alpha_mode().is_premultiplied(); TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply) @@ -1996,7 +1995,7 @@ impl CanvasContext for WebGLRenderingContext { let (data, alpha_mode) = receiver.recv().unwrap(); Some(Snapshot::from_vec( size.cast(), - snapshot::PixelFormat::RGBA, + SnapshotPixelFormat::RGBA, alpha_mode, data.to_vec(), )) diff --git a/components/script/dom/webgpu/gpucanvascontext.rs b/components/script/dom/webgpu/gpucanvascontext.rs index b4b83da1e6d..3722f19bc24 100644 --- a/components/script/dom/webgpu/gpucanvascontext.rs +++ b/components/script/dom/webgpu/gpucanvascontext.rs @@ -8,7 +8,7 @@ use std::cell::RefCell; use arrayvec::ArrayVec; use dom_struct::dom_struct; use ipc_channel::ipc::{self}; -use snapshot::Snapshot; +use pixels::Snapshot; use webgpu_traits::{ ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest, WebGPUTexture, diff --git a/components/shared/canvas/Cargo.toml b/components/shared/canvas/Cargo.toml index c77399ef847..d6e96711e1d 100644 --- a/components/shared/canvas/Cargo.toml +++ b/components/shared/canvas/Cargo.toml @@ -26,7 +26,6 @@ pixels = { path = "../../pixels" } serde = { workspace = true } serde_bytes = { workspace = true } servo_config = { path = "../../config" } -snapshot = { workspace = true } stylo = { workspace = true } webrender_api = { workspace = true } webxr-api = { workspace = true, features = ["ipc"] } diff --git a/components/shared/canvas/canvas.rs b/components/shared/canvas/canvas.rs index 283be0d458e..f33bb2b0732 100644 --- a/components/shared/canvas/canvas.rs +++ b/components/shared/canvas/canvas.rs @@ -8,9 +8,9 @@ use std::str::FromStr; use euclid::default::{Point2D, Rect, Size2D, Transform2D}; use ipc_channel::ipc::{IpcBytesReceiver, IpcSender}; use malloc_size_of_derive::MallocSizeOf; +use pixels::IpcSnapshot; use serde::{Deserialize, Serialize}; use serde_bytes::ByteBuf; -use snapshot::IpcSnapshot; use style::color::AbsoluteColor; use style::properties::style_structs::Font as FontStyleStruct; diff --git a/components/shared/canvas/webgl.rs b/components/shared/canvas/webgl.rs index 7ffae5d5fc5..89d064ed6ee 100644 --- a/components/shared/canvas/webgl.rs +++ b/components/shared/canvas/webgl.rs @@ -20,7 +20,7 @@ use glow::{ }; use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory}; use malloc_size_of_derive::MallocSizeOf; -use pixels::PixelFormat; +use pixels::{PixelFormat, SnapshotAlphaMode}; use serde::{Deserialize, Serialize}; use webrender_api::ImageKey; use webxr_api::{ @@ -302,7 +302,7 @@ pub enum WebGLCommand { Rect, u32, u32, - IpcSender<(IpcSharedMemory, snapshot::AlphaMode)>, + IpcSender<(IpcSharedMemory, SnapshotAlphaMode)>, ), ReadPixelsPP(Rect, u32, u32, usize), SampleCoverage(f32, bool), diff --git a/components/shared/constellation/Cargo.toml b/components/shared/constellation/Cargo.toml index 15a9c53bb83..eff0732f60b 100644 --- a/components/shared/constellation/Cargo.toml +++ b/components/shared/constellation/Cargo.toml @@ -28,10 +28,10 @@ log = { workspace = true } malloc_size_of = { workspace = true } malloc_size_of_derive = { workspace = true } net_traits = { workspace = true } +pixels = { path = "../../pixels" } profile_traits = { workspace = true } serde = { workspace = true } servo_url = { path = "../../url" } -snapshot = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } uuid = { workspace = true } diff --git a/components/shared/constellation/structured_data/serializable.rs b/components/shared/constellation/structured_data/serializable.rs index e72d3593bb3..f0f07f65e98 100644 --- a/components/shared/constellation/structured_data/serializable.rs +++ b/components/shared/constellation/structured_data/serializable.rs @@ -14,9 +14,9 @@ use std::path::PathBuf; use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId}; use malloc_size_of_derive::MallocSizeOf; use net_traits::filemanager_thread::RelativePos; +use pixels::Snapshot; use serde::{Deserialize, Serialize}; use servo_url::ImmutableOrigin; -use snapshot::Snapshot; use strum::EnumIter; use uuid::Uuid; diff --git a/components/shared/snapshot/Cargo.toml b/components/shared/snapshot/Cargo.toml deleted file mode 100644 index 81b2125a3c8..00000000000 --- a/components/shared/snapshot/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "snapshot" -version.workspace = true -authors.workspace = true -license.workspace = true -edition.workspace = true -publish.workspace = true -rust-version.workspace = true - -[lib] -name = "snapshot" -path = "lib.rs" - - -[dependencies] -euclid = { workspace = true } -ipc-channel = { workspace = true } -malloc_size_of = { workspace = true } -malloc_size_of_derive = { workspace = true } -serde = { workspace = true } -pixels = { path = "../../pixels" } diff --git a/components/shared/webgpu/Cargo.toml b/components/shared/webgpu/Cargo.toml index 04efea0cb9c..5fb042dfb78 100644 --- a/components/shared/webgpu/Cargo.toml +++ b/components/shared/webgpu/Cargo.toml @@ -16,8 +16,8 @@ arrayvec = { workspace = true } base = { workspace = true } ipc-channel = { workspace = true } malloc_size_of = { workspace = true } +pixels = { path = "../../pixels" } serde = { workspace = true } webrender_api = { workspace = true } wgpu-core = { workspace = true, features = ["serde", "wgsl"] } wgpu-types = { workspace = true } -snapshot = { workspace = true } diff --git a/components/shared/webgpu/messages/recv.rs b/components/shared/webgpu/messages/recv.rs index 4a30177cf0a..8c58bdfa346 100644 --- a/components/shared/webgpu/messages/recv.rs +++ b/components/shared/webgpu/messages/recv.rs @@ -8,8 +8,8 @@ use arrayvec::ArrayVec; use base::id::PipelineId; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; +use pixels::IpcSnapshot; use serde::{Deserialize, Serialize}; -use snapshot::IpcSnapshot; use webrender_api::ImageKey; use webrender_api::units::DeviceIntSize; use wgpu_core::Label; diff --git a/components/webgl/Cargo.toml b/components/webgl/Cargo.toml index 542a3cb4fae..46fe7381959 100644 --- a/components/webgl/Cargo.toml +++ b/components/webgl/Cargo.toml @@ -29,7 +29,6 @@ ipc-channel = { workspace = true } itertools = { workspace = true } log = { workspace = true } pixels = { path = "../pixels" } -snapshot = { workspace = true } surfman = { workspace = true } webrender = { workspace = true } webrender_api = { workspace = true } diff --git a/components/webgl/webgl_thread.rs b/components/webgl/webgl_thread.rs index 9562c4cb4e0..b1803f615fe 100644 --- a/components/webgl/webgl_thread.rs +++ b/components/webgl/webgl_thread.rs @@ -34,7 +34,7 @@ use half::f16; use ipc_channel::ipc::IpcSharedMemory; use itertools::Itertools; use log::{debug, error, trace, warn}; -use pixels::{self, PixelFormat, unmultiply_inplace}; +use pixels::{self, PixelFormat, SnapshotAlphaMode, unmultiply_inplace}; use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI}; use surfman::{ self, Adapter, Connection, Context, ContextAttributeFlags, ContextAttributes, Device, @@ -1215,8 +1215,8 @@ impl WebGLImpl { ) }; let alpha_mode = match (attributes.alpha, attributes.premultiplied_alpha) { - (true, premultiplied) => snapshot::AlphaMode::Transparent { premultiplied }, - (false, _) => snapshot::AlphaMode::Opaque, + (true, premultiplied) => SnapshotAlphaMode::Transparent { premultiplied }, + (false, _) => SnapshotAlphaMode::Opaque, }; sender .send((IpcSharedMemory::from_bytes(&pixels), alpha_mode)) diff --git a/components/webgpu/Cargo.toml b/components/webgpu/Cargo.toml index 39b2e952679..e1a2c6191cd 100644 --- a/components/webgpu/Cargo.toml +++ b/components/webgpu/Cargo.toml @@ -18,10 +18,10 @@ compositing_traits = { workspace = true } euclid = { workspace = true } ipc-channel = { workspace = true } log = { workspace = true } +pixels = { path = "../pixels" } serde = { workspace = true, features = ["serde_derive"] } servo_config = { path = "../config" } webgpu_traits = { workspace = true } -snapshot = { workspace = true } webrender = { workspace = true } webrender_api = { workspace = true } wgpu-core = { workspace = true, features = ["serde", "wgsl"] } diff --git a/components/webgpu/swapchain.rs b/components/webgpu/swapchain.rs index a3ca15b638d..29ed59ccae6 100644 --- a/components/webgpu/swapchain.rs +++ b/components/webgpu/swapchain.rs @@ -12,8 +12,8 @@ use compositing_traits::{WebrenderExternalImageApi, WebrenderImageSource}; use euclid::default::Size2D; use ipc_channel::ipc::IpcSender; use log::{error, warn}; +use pixels::{IpcSnapshot, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat}; use serde::{Deserialize, Serialize}; -use snapshot::{IpcSnapshot, Snapshot}; use webgpu_traits::{ ContextConfiguration, Error, PRESENTATION_BUFFER_COUNT, WebGPUContextId, WebGPUMsg, }; @@ -375,16 +375,16 @@ impl crate::WGPU { .and_then(|swap_chain| swap_chain.data.as_ref()) { let format = match context_data.image_desc.0.format { - ImageFormat::RGBA8 => snapshot::PixelFormat::RGBA, - ImageFormat::BGRA8 => snapshot::PixelFormat::BGRA, + ImageFormat::RGBA8 => SnapshotPixelFormat::RGBA, + ImageFormat::BGRA8 => SnapshotPixelFormat::BGRA, _ => unimplemented!(), }; let alpha_mode = if context_data.image_desc.0.is_opaque() { - snapshot::AlphaMode::AsOpaque { + SnapshotAlphaMode::AsOpaque { premultiplied: false, } } else { - snapshot::AlphaMode::Transparent { + SnapshotAlphaMode::Transparent { premultiplied: true, } };