pixels: Move Snapshot and related data structures to pixels (#37590)

1. The `shared` directory is for the "_traits" crates, which will likely
   be moved out of this directly at some point and renamed "_api". These
   crates expose the API of crates to avoid circular dependencies.
   `Snapshot` isn't really this.
2. `Snapshot` is essentially a specialied kind of `Image` so it makes
   sense that it is grouped with other image-related things in `pixels`.

Testing: This should not change any behavior so is covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-06-20 16:47:06 +02:00 committed by GitHub
parent 80a7de8c9c
commit 309485d2db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 123 additions and 154 deletions

22
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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 }

View file

@ -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,

View file

@ -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<Rect<u32>>,
canvas_size: Option<Size2D<u32>>,
) -> snapshot::Snapshot {
) -> Snapshot {
match self {
Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size),
}

View file

@ -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)]

View file

@ -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<u8>),
}
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<IpcSharedMemory>;
/// Inspired by snapshot for concept in WebGPU spec:
/// <https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context>
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct Snapshot<T = Data> {
pub struct Snapshot<T = SnapshotData> {
size: Size2D<u32>,
/// 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<T> Snapshot<T> {
@ -101,11 +105,11 @@ impl<T> Snapshot<T> {
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<T> Snapshot<T> {
}
}
impl Snapshot<Data> {
impl Snapshot<SnapshotData> {
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<Data> {
pub fn cleared(size: Size2D<u32>) -> 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<Data> {
pub fn from_vec(
size: Size2D<u32>,
format: PixelFormat,
alpha_mode: AlphaMode,
format: SnapshotPixelFormat,
alpha_mode: SnapshotAlphaMode,
data: Vec<u8>,
) -> Self {
Self {
size,
data: Data::Owned(data),
data: SnapshotData::Owned(data),
format,
alpha_mode,
}
@ -187,11 +191,15 @@ impl Snapshot<Data> {
/// 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<Data> {
}
},
(
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<Data> {
}
},
};
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<Data> {
} = 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<Data> {
pub fn to_vec(self) -> Vec<u8> {
match self.data {
Data::Owned(data) => data,
SnapshotData::Owned(data) => data,
}
}
}
@ -271,7 +280,7 @@ impl Snapshot<IpcSharedMemory> {
}
}
*/
pub fn to_owned(self) -> Snapshot<Data> {
pub fn to_owned(self) -> Snapshot<SnapshotData> {
let Snapshot {
size,
data,
@ -280,7 +289,7 @@ impl Snapshot<IpcSharedMemory> {
} = self;
Snapshot {
size,
data: Data::Owned(data.to_vec()),
data: SnapshotData::Owned(data.to_vec()),
format,
alpha_mode,
}

View file

@ -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 }

View file

@ -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;

View file

@ -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<CorsSettings>,
) -> Option<snapshot::Snapshot> {
) -> Option<Snapshot> {
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()
}

View file

@ -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};

View file

@ -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(),
);

View file

@ -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<crate::DomTypeHolder> 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<crate::DomTypeHolder> 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

View file

@ -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(),
))

View file

@ -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,
);
},
}

View file

@ -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};

View file

@ -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,

View file

@ -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;

View file

@ -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(),
))

View file

@ -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,

View file

@ -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"] }

View file

@ -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;

View file

@ -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,
u32,
IpcSender<(IpcSharedMemory, snapshot::AlphaMode)>,
IpcSender<(IpcSharedMemory, SnapshotAlphaMode)>,
),
ReadPixelsPP(Rect<i32>, u32, u32, usize),
SampleCoverage(f32, bool),

View file

@ -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 }

View file

@ -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;

View file

@ -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" }

View file

@ -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 }

View file

@ -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;

View file

@ -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 }

View file

@ -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))

View file

@ -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"] }

View file

@ -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,
}
};