mirror of
https://github.com/servo/servo.git
synced 2025-06-28 19:13:41 +01:00
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:
parent
80a7de8c9c
commit
309485d2db
32 changed files with 123 additions and 154 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -805,7 +805,6 @@ dependencies = [
|
||||||
"range",
|
"range",
|
||||||
"raqote",
|
"raqote",
|
||||||
"servo_arc",
|
"servo_arc",
|
||||||
"snapshot",
|
|
||||||
"stylo",
|
"stylo",
|
||||||
"unicode-script",
|
"unicode-script",
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
|
@ -826,7 +825,6 @@ dependencies = [
|
||||||
"serde_bytes",
|
"serde_bytes",
|
||||||
"servo_config",
|
"servo_config",
|
||||||
"servo_malloc_size_of",
|
"servo_malloc_size_of",
|
||||||
"snapshot",
|
|
||||||
"stylo",
|
"stylo",
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
"webxr-api",
|
"webxr-api",
|
||||||
|
@ -1215,11 +1213,11 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"malloc_size_of_derive",
|
"malloc_size_of_derive",
|
||||||
"net_traits",
|
"net_traits",
|
||||||
|
"pixels",
|
||||||
"profile_traits",
|
"profile_traits",
|
||||||
"serde",
|
"serde",
|
||||||
"servo_malloc_size_of",
|
"servo_malloc_size_of",
|
||||||
"servo_url",
|
"servo_url",
|
||||||
"snapshot",
|
|
||||||
"strum",
|
"strum",
|
||||||
"strum_macros",
|
"strum_macros",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
@ -6650,7 +6648,6 @@ dependencies = [
|
||||||
"servo_rand",
|
"servo_rand",
|
||||||
"servo_url",
|
"servo_url",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"snapshot",
|
|
||||||
"strum",
|
"strum",
|
||||||
"strum_macros",
|
"strum_macros",
|
||||||
"stylo",
|
"stylo",
|
||||||
|
@ -7426,18 +7423,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "snapshot"
|
|
||||||
version = "0.0.1"
|
|
||||||
dependencies = [
|
|
||||||
"euclid",
|
|
||||||
"ipc-channel",
|
|
||||||
"malloc_size_of_derive",
|
|
||||||
"pixels",
|
|
||||||
"serde",
|
|
||||||
"servo_malloc_size_of",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.5.10"
|
version = "0.5.10"
|
||||||
|
@ -8987,7 +8972,6 @@ dependencies = [
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"log",
|
"log",
|
||||||
"pixels",
|
"pixels",
|
||||||
"snapshot",
|
|
||||||
"surfman",
|
"surfman",
|
||||||
"webrender",
|
"webrender",
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
|
@ -9005,9 +8989,9 @@ dependencies = [
|
||||||
"euclid",
|
"euclid",
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
"log",
|
"log",
|
||||||
|
"pixels",
|
||||||
"serde",
|
"serde",
|
||||||
"servo_config",
|
"servo_config",
|
||||||
"snapshot",
|
|
||||||
"webgpu_traits",
|
"webgpu_traits",
|
||||||
"webrender",
|
"webrender",
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
|
@ -9022,9 +9006,9 @@ dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"base",
|
"base",
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
|
"pixels",
|
||||||
"serde",
|
"serde",
|
||||||
"servo_malloc_size_of",
|
"servo_malloc_size_of",
|
||||||
"snapshot",
|
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
"wgpu-core",
|
"wgpu-core",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
|
|
|
@ -131,7 +131,6 @@ servo-tracing = { path = "components/servo_tracing" }
|
||||||
servo_arc = { git = "https://github.com/servo/stylo", branch = "2025-06-03" }
|
servo_arc = { git = "https://github.com/servo/stylo", branch = "2025-06-03" }
|
||||||
smallbitvec = "2.6.0"
|
smallbitvec = "2.6.0"
|
||||||
smallvec = "1.15"
|
smallvec = "1.15"
|
||||||
snapshot = { path = "./components/shared/snapshot" }
|
|
||||||
static_assertions = "1.1"
|
static_assertions = "1.1"
|
||||||
string_cache = "0.8"
|
string_cache = "0.8"
|
||||||
string_cache_codegen = "0.5"
|
string_cache_codegen = "0.5"
|
||||||
|
|
|
@ -28,7 +28,6 @@ pixels = { path = "../pixels" }
|
||||||
range = { path = "../range" }
|
range = { path = "../range" }
|
||||||
raqote = "0.8.5"
|
raqote = "0.8.5"
|
||||||
servo_arc = { workspace = true }
|
servo_arc = { workspace = true }
|
||||||
snapshot = { workspace = true }
|
|
||||||
stylo = { workspace = true }
|
stylo = { workspace = true }
|
||||||
unicode-script = { workspace = true }
|
unicode-script = { workspace = true }
|
||||||
webrender_api = { workspace = true }
|
webrender_api = { workspace = true }
|
||||||
|
|
|
@ -17,9 +17,9 @@ use fonts::{
|
||||||
};
|
};
|
||||||
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
|
use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
use range::Range;
|
use range::Range;
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use style::color::AbsoluteColor;
|
use style::color::AbsoluteColor;
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
use unicode_script::Script;
|
use unicode_script::Script;
|
||||||
|
@ -1336,8 +1336,8 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
|
|
||||||
Snapshot::from_vec(
|
Snapshot::from_vec(
|
||||||
canvas_size,
|
canvas_size,
|
||||||
snapshot::PixelFormat::BGRA,
|
SnapshotPixelFormat::BGRA,
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -17,6 +17,7 @@ use ipc_channel::ipc::{self, IpcSender};
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use net_traits::ResourceThreads;
|
use net_traits::ResourceThreads;
|
||||||
|
use pixels::Snapshot;
|
||||||
use style::color::AbsoluteColor;
|
use style::color::AbsoluteColor;
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
@ -420,7 +421,7 @@ impl Canvas<'_> {
|
||||||
&mut self,
|
&mut self,
|
||||||
read_rect: Option<Rect<u32>>,
|
read_rect: Option<Rect<u32>>,
|
||||||
canvas_size: Option<Size2D<u32>>,
|
canvas_size: Option<Size2D<u32>>,
|
||||||
) -> snapshot::Snapshot {
|
) -> Snapshot {
|
||||||
match self {
|
match self {
|
||||||
Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size),
|
Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
mod snapshot;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
@ -16,6 +18,7 @@ use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
pub use snapshot::*;
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||||
|
|
|
@ -7,18 +7,19 @@ use std::ops::{Deref, DerefMut};
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use ipc_channel::ipc::IpcSharedMemory;
|
use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
use pixels::Multiply;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{Multiply, transform_inplace};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||||
pub enum PixelFormat {
|
pub enum SnapshotPixelFormat {
|
||||||
#[default]
|
#[default]
|
||||||
RGBA,
|
RGBA,
|
||||||
BGRA,
|
BGRA,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||||
pub enum AlphaMode {
|
pub enum SnapshotAlphaMode {
|
||||||
/// Internal data is opaque (alpha is cleared to 1)
|
/// Internal data is opaque (alpha is cleared to 1)
|
||||||
Opaque,
|
Opaque,
|
||||||
/// Internal data should be threated as opaque (does not mean it actually is)
|
/// Internal data should be threated as opaque (does not mean it actually is)
|
||||||
|
@ -27,7 +28,7 @@ pub enum AlphaMode {
|
||||||
Transparent { premultiplied: bool },
|
Transparent { premultiplied: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AlphaMode {
|
impl Default for SnapshotAlphaMode {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Transparent {
|
Self::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
|
@ -35,43 +36,46 @@ impl Default for AlphaMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AlphaMode {
|
impl SnapshotAlphaMode {
|
||||||
pub const fn is_premultiplied(&self) -> bool {
|
pub const fn is_premultiplied(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
AlphaMode::Opaque => true,
|
SnapshotAlphaMode::Opaque => true,
|
||||||
AlphaMode::AsOpaque { premultiplied } => *premultiplied,
|
SnapshotAlphaMode::AsOpaque { premultiplied } => *premultiplied,
|
||||||
AlphaMode::Transparent { premultiplied } => *premultiplied,
|
SnapshotAlphaMode::Transparent { premultiplied } => *premultiplied,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn is_opaque(&self) -> bool {
|
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)]
|
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
pub enum Data {
|
pub enum SnapshotData {
|
||||||
// TODO: https://github.com/servo/servo/issues/36594
|
// TODO: https://github.com/servo/servo/issues/36594
|
||||||
//IPC(IpcSharedMemory),
|
//IPC(IpcSharedMemory),
|
||||||
Owned(Vec<u8>),
|
Owned(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Data {
|
impl Deref for SnapshotData {
|
||||||
type Target = [u8];
|
type Target = [u8];
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match &self {
|
match &self {
|
||||||
//Data::IPC(ipc_shared_memory) => ipc_shared_memory,
|
//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 {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
match self {
|
match self {
|
||||||
//Data::IPC(ipc_shared_memory) => unsafe { ipc_shared_memory.deref_mut() },
|
//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:
|
/// 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>
|
/// <https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context>
|
||||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
pub struct Snapshot<T = Data> {
|
pub struct Snapshot<T = SnapshotData> {
|
||||||
size: Size2D<u32>,
|
size: Size2D<u32>,
|
||||||
/// internal data (can be any format it will be converted on use if needed)
|
/// internal data (can be any format it will be converted on use if needed)
|
||||||
data: T,
|
data: T,
|
||||||
/// RGBA/BGRA (reflect internal data)
|
/// RGBA/BGRA (reflect internal data)
|
||||||
format: PixelFormat,
|
format: SnapshotPixelFormat,
|
||||||
/// How to treat alpha channel
|
/// How to treat alpha channel
|
||||||
alpha_mode: AlphaMode,
|
alpha_mode: SnapshotAlphaMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Snapshot<T> {
|
impl<T> Snapshot<T> {
|
||||||
|
@ -101,11 +105,11 @@ impl<T> Snapshot<T> {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn format(&self) -> PixelFormat {
|
pub const fn format(&self) -> SnapshotPixelFormat {
|
||||||
self.format
|
self.format
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn alpha_mode(&self) -> AlphaMode {
|
pub const fn alpha_mode(&self) -> SnapshotAlphaMode {
|
||||||
self.alpha_mode
|
self.alpha_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +122,13 @@ impl<T> Snapshot<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Snapshot<Data> {
|
impl Snapshot<SnapshotData> {
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: Size2D::zero(),
|
size: Size2D::zero(),
|
||||||
data: Data::Owned(vec![]),
|
data: SnapshotData::Owned(vec![]),
|
||||||
format: PixelFormat::RGBA,
|
format: SnapshotPixelFormat::RGBA,
|
||||||
alpha_mode: AlphaMode::Transparent {
|
alpha_mode: SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -134,9 +138,9 @@ impl Snapshot<Data> {
|
||||||
pub fn cleared(size: Size2D<u32>) -> Self {
|
pub fn cleared(size: Size2D<u32>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
size,
|
size,
|
||||||
data: Data::Owned(vec![0; size.area() as usize * 4]),
|
data: SnapshotData::Owned(vec![0; size.area() as usize * 4]),
|
||||||
format: PixelFormat::RGBA,
|
format: SnapshotPixelFormat::RGBA,
|
||||||
alpha_mode: AlphaMode::Transparent {
|
alpha_mode: SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -144,13 +148,13 @@ impl Snapshot<Data> {
|
||||||
|
|
||||||
pub fn from_vec(
|
pub fn from_vec(
|
||||||
size: Size2D<u32>,
|
size: Size2D<u32>,
|
||||||
format: PixelFormat,
|
format: SnapshotPixelFormat,
|
||||||
alpha_mode: AlphaMode,
|
alpha_mode: SnapshotAlphaMode,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
size,
|
size,
|
||||||
data: Data::Owned(data),
|
data: SnapshotData::Owned(data),
|
||||||
format,
|
format,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
}
|
}
|
||||||
|
@ -187,11 +191,15 @@ impl Snapshot<Data> {
|
||||||
|
|
||||||
/// Convert inner data of snapshot to target format and alpha mode.
|
/// 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.
|
/// 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 swap_rb = target_format != self.format;
|
||||||
let multiply = match (self.alpha_mode, target_alpha_mode) {
|
let multiply = match (self.alpha_mode, target_alpha_mode) {
|
||||||
(AlphaMode::Opaque, _) => Multiply::None,
|
(SnapshotAlphaMode::Opaque, _) => Multiply::None,
|
||||||
(alpha_mode, AlphaMode::Opaque) => {
|
(alpha_mode, SnapshotAlphaMode::Opaque) => {
|
||||||
if alpha_mode.is_premultiplied() {
|
if alpha_mode.is_premultiplied() {
|
||||||
Multiply::UnMultiply
|
Multiply::UnMultiply
|
||||||
} else {
|
} else {
|
||||||
|
@ -199,11 +207,12 @@ impl Snapshot<Data> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
AlphaMode::Transparent { premultiplied } | AlphaMode::AsOpaque { premultiplied },
|
SnapshotAlphaMode::Transparent { premultiplied } |
|
||||||
AlphaMode::Transparent {
|
SnapshotAlphaMode::AsOpaque { premultiplied },
|
||||||
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: target_premultiplied,
|
premultiplied: target_premultiplied,
|
||||||
} |
|
} |
|
||||||
AlphaMode::AsOpaque {
|
SnapshotAlphaMode::AsOpaque {
|
||||||
premultiplied: target_premultiplied,
|
premultiplied: target_premultiplied,
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
|
@ -216,9 +225,9 @@ impl Snapshot<Data> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let clear_alpha = !matches!(self.alpha_mode, AlphaMode::Opaque) &&
|
let clear_alpha = !matches!(self.alpha_mode, SnapshotAlphaMode::Opaque) &&
|
||||||
matches!(target_alpha_mode, AlphaMode::Opaque);
|
matches!(target_alpha_mode, SnapshotAlphaMode::Opaque);
|
||||||
pixels::transform_inplace(self.data.deref_mut(), multiply, swap_rb, clear_alpha);
|
transform_inplace(self.data.deref_mut(), multiply, swap_rb, clear_alpha);
|
||||||
self.alpha_mode = target_alpha_mode;
|
self.alpha_mode = target_alpha_mode;
|
||||||
self.format = target_format;
|
self.format = target_format;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +241,7 @@ impl Snapshot<Data> {
|
||||||
} = self;
|
} = self;
|
||||||
let data = match data {
|
let data = match data {
|
||||||
//Data::IPC(ipc_shared_memory) => ipc_shared_memory,
|
//Data::IPC(ipc_shared_memory) => ipc_shared_memory,
|
||||||
Data::Owned(items) => IpcSharedMemory::from_bytes(&items),
|
SnapshotData::Owned(items) => IpcSharedMemory::from_bytes(&items),
|
||||||
};
|
};
|
||||||
Snapshot {
|
Snapshot {
|
||||||
size,
|
size,
|
||||||
|
@ -244,7 +253,7 @@ impl Snapshot<Data> {
|
||||||
|
|
||||||
pub fn to_vec(self) -> Vec<u8> {
|
pub fn to_vec(self) -> Vec<u8> {
|
||||||
match self.data {
|
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 {
|
let Snapshot {
|
||||||
size,
|
size,
|
||||||
data,
|
data,
|
||||||
|
@ -280,7 +289,7 @@ impl Snapshot<IpcSharedMemory> {
|
||||||
} = self;
|
} = self;
|
||||||
Snapshot {
|
Snapshot {
|
||||||
size,
|
size,
|
||||||
data: Data::Owned(data.to_vec()),
|
data: SnapshotData::Owned(data.to_vec()),
|
||||||
format,
|
format,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
}
|
}
|
|
@ -113,7 +113,6 @@ servo_config = { path = "../config" }
|
||||||
servo_geometry = { path = "../geometry" }
|
servo_geometry = { path = "../geometry" }
|
||||||
servo_rand = { path = "../rand" }
|
servo_rand = { path = "../rand" }
|
||||||
servo_url = { path = "../url" }
|
servo_url = { path = "../url" }
|
||||||
snapshot = { workspace = true }
|
|
||||||
smallvec = { workspace = true, features = ["union"] }
|
smallvec = { workspace = true, features = ["union"] }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
strum_macros = { workspace = true }
|
strum_macros = { workspace = true }
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
//! Common interfaces for Canvas Contexts
|
//! Common interfaces for Canvas Contexts
|
||||||
|
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
|
use pixels::Snapshot;
|
||||||
use script_bindings::root::Dom;
|
use script_bindings::root::Dom;
|
||||||
use script_layout_interface::HTMLCanvasData;
|
use script_layout_interface::HTMLCanvasData;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
||||||
|
|
|
@ -20,7 +20,7 @@ use euclid::vec2;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use net_traits::image_cache::{ImageCache, ImageResponse};
|
use net_traits::image_cache::{ImageCache, ImageResponse};
|
||||||
use net_traits::request::CorsSettings;
|
use net_traits::request::CorsSettings;
|
||||||
use pixels::PixelFormat;
|
use pixels::{PixelFormat, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
use profile_traits::ipc as profiled_ipc;
|
use profile_traits::ipc as profiled_ipc;
|
||||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use style::color::{AbsoluteColor, ColorFlags, ColorSpace};
|
use style::color::{AbsoluteColor, ColorFlags, ColorSpace};
|
||||||
|
@ -330,7 +330,7 @@ impl CanvasState {
|
||||||
&self,
|
&self,
|
||||||
url: ServoUrl,
|
url: ServoUrl,
|
||||||
cors_setting: Option<CorsSettings>,
|
cors_setting: Option<CorsSettings>,
|
||||||
) -> Option<snapshot::Snapshot> {
|
) -> Option<Snapshot> {
|
||||||
let img = match self.request_image_from_cache(url, cors_setting) {
|
let img = match self.request_image_from_cache(url, cors_setting) {
|
||||||
ImageResponse::Loaded(image, _) => {
|
ImageResponse::Loaded(image, _) => {
|
||||||
if let Some(image) = image.as_raster_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 size = Size2D::new(img.metadata.width, img.metadata.height);
|
||||||
let format = match img.format {
|
let format = match img.format {
|
||||||
PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA,
|
PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA,
|
||||||
PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA,
|
PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA,
|
||||||
pixel_format => unimplemented!("unsupported pixel format ({:?})", pixel_format),
|
pixel_format => unimplemented!("unsupported pixel format ({:?})", pixel_format),
|
||||||
};
|
};
|
||||||
let alpha_mode = snapshot::AlphaMode::Transparent {
|
let alpha_mode = SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(snapshot::Snapshot::from_vec(
|
Some(Snapshot::from_vec(
|
||||||
size.cast(),
|
size.cast(),
|
||||||
format,
|
format,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
|
@ -393,10 +393,10 @@ impl CanvasState {
|
||||||
self.send_canvas_2d_msg(Canvas2dMsg::GetImageData(rect, canvas_size, sender));
|
self.send_canvas_2d_msg(Canvas2dMsg::GetImageData(rect, canvas_size, sender));
|
||||||
let mut snapshot = receiver.recv().unwrap().to_owned();
|
let mut snapshot = receiver.recv().unwrap().to_owned();
|
||||||
snapshot.transform(
|
snapshot.transform(
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
},
|
},
|
||||||
snapshot::PixelFormat::RGBA,
|
SnapshotPixelFormat::RGBA,
|
||||||
);
|
);
|
||||||
snapshot.to_vec()
|
snapshot.to_vec()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg, FromScriptMsg};
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
use pixels::Snapshot;
|
||||||
use profile_traits::ipc;
|
use profile_traits::ipc;
|
||||||
use script_bindings::inheritance::Castable;
|
use script_bindings::inheritance::Castable;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers};
|
use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers};
|
||||||
|
|
|
@ -60,11 +60,10 @@ use net_traits::{
|
||||||
CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend, ReferrerPolicy,
|
CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend, ReferrerPolicy,
|
||||||
ResourceThreads, fetch_async,
|
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 profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
|
||||||
use script_bindings::interfaces::GlobalScopeHelpers;
|
use script_bindings::interfaces::GlobalScopeHelpers;
|
||||||
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
||||||
use snapshot::Snapshot;
|
|
||||||
use timers::{TimerEventRequest, TimerId};
|
use timers::{TimerEventRequest, TimerId};
|
||||||
use url::Origin;
|
use url::Origin;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -3084,13 +3083,13 @@ impl GlobalScope {
|
||||||
|
|
||||||
let size = Size2D::new(img.metadata.width, img.metadata.height);
|
let size = Size2D::new(img.metadata.width, img.metadata.height);
|
||||||
let format = match img.format {
|
let format = match img.format {
|
||||||
PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA,
|
PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA,
|
||||||
PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA,
|
PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA,
|
||||||
pixel_format => {
|
pixel_format => {
|
||||||
unimplemented!("unsupported pixel format ({:?})", pixel_format)
|
unimplemented!("unsupported pixel format ({:?})", pixel_format)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let alpha_mode = snapshot::AlphaMode::Transparent {
|
let alpha_mode = SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3278,13 +3277,13 @@ impl GlobalScope {
|
||||||
|
|
||||||
let size = Size2D::new(img.metadata.width, img.metadata.height);
|
let size = Size2D::new(img.metadata.width, img.metadata.height);
|
||||||
let format = match img.format {
|
let format = match img.format {
|
||||||
PixelFormat::BGRA8 => snapshot::PixelFormat::BGRA,
|
PixelFormat::BGRA8 => SnapshotPixelFormat::BGRA,
|
||||||
PixelFormat::RGBA8 => snapshot::PixelFormat::RGBA,
|
PixelFormat::RGBA8 => SnapshotPixelFormat::RGBA,
|
||||||
pixel_format => {
|
pixel_format => {
|
||||||
unimplemented!("unsupported pixel format ({:?})", pixel_format)
|
unimplemented!("unsupported pixel format ({:?})", pixel_format)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let alpha_mode = snapshot::AlphaMode::Transparent {
|
let alpha_mode = SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3319,13 +3318,13 @@ impl GlobalScope {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
let alpha_mode = snapshot::AlphaMode::Transparent {
|
let alpha_mode = SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let snapshot = Snapshot::from_vec(
|
let snapshot = Snapshot::from_vec(
|
||||||
image_data.get_size().cast(),
|
image_data.get_size().cast(),
|
||||||
snapshot::PixelFormat::RGBA,
|
SnapshotPixelFormat::RGBA,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
image_data.to_vec(),
|
image_data.to_vec(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,10 +21,10 @@ use image::{ColorType, ImageEncoder, ImageError};
|
||||||
use ipc_channel::ipc::{self as ipcchan};
|
use ipc_channel::ipc::{self as ipcchan};
|
||||||
use js::error::throw_type_error;
|
use js::error::throw_type_error;
|
||||||
use js::rust::{HandleObject, HandleValue};
|
use js::rust::{HandleObject, HandleValue};
|
||||||
|
use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
use script_layout_interface::HTMLCanvasData;
|
use script_layout_interface::HTMLCanvasData;
|
||||||
use servo_media::streams::MediaStreamType;
|
use servo_media::streams::MediaStreamType;
|
||||||
use servo_media::streams::registry::MediaStreamId;
|
use servo_media::streams::registry::MediaStreamId;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use style::attr::AttrValue;
|
use style::attr::AttrValue;
|
||||||
|
|
||||||
use super::node::NodeDamage;
|
use super::node::NodeDamage;
|
||||||
|
@ -543,15 +543,15 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
let image_type = EncodedImageType::from(mime_type);
|
let image_type = EncodedImageType::from(mime_type);
|
||||||
snapshot.transform(
|
snapshot.transform(
|
||||||
if image_type == EncodedImageType::Jpeg {
|
if image_type == EncodedImageType::Jpeg {
|
||||||
snapshot::AlphaMode::AsOpaque {
|
SnapshotAlphaMode::AsOpaque {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
snapshot::PixelFormat::RGBA,
|
SnapshotPixelFormat::RGBA,
|
||||||
);
|
);
|
||||||
let mut url = format!("data:{};base64,", image_type.as_mime_type());
|
let mut url = format!("data:{};base64,", image_type.as_mime_type());
|
||||||
|
|
||||||
|
@ -627,8 +627,8 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
};
|
};
|
||||||
|
|
||||||
snapshot.transform(
|
snapshot.transform(
|
||||||
snapshot::AlphaMode::Transparent{ premultiplied: false },
|
SnapshotAlphaMode::Transparent { premultiplied: false },
|
||||||
snapshot::PixelFormat::RGBA
|
SnapshotPixelFormat::RGBA
|
||||||
);
|
);
|
||||||
|
|
||||||
// Step 4.1: If result is non-null, then set result to a serialization of
|
// Step 4.1: If result is non-null, then set result to a serialization of
|
||||||
|
|
|
@ -19,10 +19,10 @@ use net_traits::{
|
||||||
FetchMetadata, FetchResponseListener, FetchResponseMsg, NetworkError, ResourceFetchTiming,
|
FetchMetadata, FetchResponseListener, FetchResponseMsg, NetworkError, ResourceFetchTiming,
|
||||||
ResourceTimingType,
|
ResourceTimingType,
|
||||||
};
|
};
|
||||||
|
use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
use script_layout_interface::{HTMLMediaData, MediaMetadata};
|
use script_layout_interface::{HTMLMediaData, MediaMetadata};
|
||||||
use servo_media::player::video::VideoFrame;
|
use servo_media::player::video::VideoFrame;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
||||||
|
|
||||||
use crate::document_loader::{LoadBlocker, LoadType};
|
use crate::document_loader::{LoadBlocker, LoadType};
|
||||||
|
@ -146,13 +146,13 @@ impl HTMLVideoElement {
|
||||||
Some(frame) => {
|
Some(frame) => {
|
||||||
let size = Size2D::new(frame.get_width() as u32, frame.get_height() as u32);
|
let size = Size2D::new(frame.get_width() as u32, frame.get_height() as u32);
|
||||||
if !frame.is_gl_texture() {
|
if !frame.is_gl_texture() {
|
||||||
let alpha_mode = snapshot::AlphaMode::Transparent {
|
let alpha_mode = SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Snapshot::from_vec(
|
Some(Snapshot::from_vec(
|
||||||
size.cast(),
|
size.cast(),
|
||||||
snapshot::PixelFormat::BGRA,
|
SnapshotPixelFormat::BGRA,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
frame.get_data().to_vec(),
|
frame.get_data().to_vec(),
|
||||||
))
|
))
|
||||||
|
|
|
@ -9,7 +9,7 @@ use base::id::{ImageBitmapId, ImageBitmapIndex};
|
||||||
use constellation_traits::SerializableImageBitmap;
|
use constellation_traits::SerializableImageBitmap;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::default::{Point2D, Rect, Size2D};
|
use euclid::default::{Point2D, Rect, Size2D};
|
||||||
use snapshot::Snapshot;
|
use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
|
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
|
||||||
|
@ -246,18 +246,18 @@ impl ImageBitmap {
|
||||||
match options.premultiplyAlpha {
|
match options.premultiplyAlpha {
|
||||||
PremultiplyAlpha::Default | PremultiplyAlpha::Premultiply => {
|
PremultiplyAlpha::Default | PremultiplyAlpha::Premultiply => {
|
||||||
output.transform(
|
output.transform(
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
},
|
},
|
||||||
snapshot::PixelFormat::BGRA,
|
SnapshotPixelFormat::BGRA,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
PremultiplyAlpha::None => {
|
PremultiplyAlpha::None => {
|
||||||
output.transform(
|
output.transform(
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
},
|
},
|
||||||
snapshot::PixelFormat::BGRA,
|
SnapshotPixelFormat::BGRA,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::cell::Cell;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use js::rust::{HandleObject, HandleValue};
|
use js::rust::{HandleObject, HandleValue};
|
||||||
use snapshot::Snapshot;
|
use pixels::Snapshot;
|
||||||
|
|
||||||
use crate::canvas_context::{CanvasContext, OffscreenRenderingContext};
|
use crate::canvas_context::{CanvasContext, OffscreenRenderingContext};
|
||||||
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::canvas_context::CanvasContext;
|
||||||
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
||||||
use canvas_traits::canvas::Canvas2dMsg;
|
use canvas_traits::canvas::Canvas2dMsg;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use snapshot::Snapshot;
|
use pixels::Snapshot;
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{
|
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{
|
||||||
CanvasDirection, CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin,
|
CanvasDirection, CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin,
|
||||||
|
|
|
@ -21,9 +21,9 @@ use js::jsapi::{JSObject, Type};
|
||||||
use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, UInt32Value};
|
use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, UInt32Value};
|
||||||
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
|
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
|
||||||
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
|
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
|
||||||
|
use pixels::Snapshot;
|
||||||
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
|
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use url::Host;
|
use url::Host;
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,9 @@ use js::typedarray::{
|
||||||
TypedArrayElementCreator, Uint32Array,
|
TypedArrayElementCreator, Uint32Array,
|
||||||
};
|
};
|
||||||
use net_traits::image_cache::ImageResponse;
|
use net_traits::image_cache::ImageResponse;
|
||||||
use pixels::{self, PixelFormat};
|
use pixels::{self, PixelFormat, Snapshot, SnapshotPixelFormat};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::canvas_context::CanvasContext;
|
use crate::canvas_context::CanvasContext;
|
||||||
|
@ -586,8 +585,8 @@ impl WebGLRenderingContext {
|
||||||
let snapshot = snapshot.as_ipc();
|
let snapshot = snapshot.as_ipc();
|
||||||
let size = snapshot.size().cast();
|
let size = snapshot.size().cast();
|
||||||
let format = match snapshot.format() {
|
let format = match snapshot.format() {
|
||||||
snapshot::PixelFormat::RGBA => PixelFormat::RGBA8,
|
SnapshotPixelFormat::RGBA => PixelFormat::RGBA8,
|
||||||
snapshot::PixelFormat::BGRA => PixelFormat::BGRA8,
|
SnapshotPixelFormat::BGRA => PixelFormat::BGRA8,
|
||||||
};
|
};
|
||||||
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
||||||
TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply)
|
TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply)
|
||||||
|
@ -666,8 +665,8 @@ impl WebGLRenderingContext {
|
||||||
let snapshot = snapshot.as_ipc();
|
let snapshot = snapshot.as_ipc();
|
||||||
let size = snapshot.size().cast();
|
let size = snapshot.size().cast();
|
||||||
let format = match snapshot.format() {
|
let format = match snapshot.format() {
|
||||||
snapshot::PixelFormat::RGBA => PixelFormat::RGBA8,
|
SnapshotPixelFormat::RGBA => PixelFormat::RGBA8,
|
||||||
snapshot::PixelFormat::BGRA => PixelFormat::BGRA8,
|
SnapshotPixelFormat::BGRA => PixelFormat::BGRA8,
|
||||||
};
|
};
|
||||||
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
||||||
TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply)
|
TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply)
|
||||||
|
@ -687,8 +686,8 @@ impl WebGLRenderingContext {
|
||||||
let snapshot = snapshot.as_ipc();
|
let snapshot = snapshot.as_ipc();
|
||||||
let size = snapshot.size().cast();
|
let size = snapshot.size().cast();
|
||||||
let format: PixelFormat = match snapshot.format() {
|
let format: PixelFormat = match snapshot.format() {
|
||||||
snapshot::PixelFormat::RGBA => PixelFormat::RGBA8,
|
SnapshotPixelFormat::RGBA => PixelFormat::RGBA8,
|
||||||
snapshot::PixelFormat::BGRA => PixelFormat::BGRA8,
|
SnapshotPixelFormat::BGRA => PixelFormat::BGRA8,
|
||||||
};
|
};
|
||||||
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
let premultiply = snapshot.alpha_mode().is_premultiplied();
|
||||||
TexPixels::new(snapshot.to_ipc_shared_memory(), size, format, premultiply)
|
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();
|
let (data, alpha_mode) = receiver.recv().unwrap();
|
||||||
Some(Snapshot::from_vec(
|
Some(Snapshot::from_vec(
|
||||||
size.cast(),
|
size.cast(),
|
||||||
snapshot::PixelFormat::RGBA,
|
SnapshotPixelFormat::RGBA,
|
||||||
alpha_mode,
|
alpha_mode,
|
||||||
data.to_vec(),
|
data.to_vec(),
|
||||||
))
|
))
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::cell::RefCell;
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc::{self};
|
use ipc_channel::ipc::{self};
|
||||||
use snapshot::Snapshot;
|
use pixels::Snapshot;
|
||||||
use webgpu_traits::{
|
use webgpu_traits::{
|
||||||
ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest,
|
ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest,
|
||||||
WebGPUTexture,
|
WebGPUTexture,
|
||||||
|
|
|
@ -26,7 +26,6 @@ pixels = { path = "../../pixels" }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_bytes = { workspace = true }
|
serde_bytes = { workspace = true }
|
||||||
servo_config = { path = "../../config" }
|
servo_config = { path = "../../config" }
|
||||||
snapshot = { workspace = true }
|
|
||||||
stylo = { workspace = true }
|
stylo = { workspace = true }
|
||||||
webrender_api = { workspace = true }
|
webrender_api = { workspace = true }
|
||||||
webxr-api = { workspace = true, features = ["ipc"] }
|
webxr-api = { workspace = true, features = ["ipc"] }
|
||||||
|
|
|
@ -8,9 +8,9 @@ use std::str::FromStr;
|
||||||
use euclid::default::{Point2D, Rect, Size2D, Transform2D};
|
use euclid::default::{Point2D, Rect, Size2D, Transform2D};
|
||||||
use ipc_channel::ipc::{IpcBytesReceiver, IpcSender};
|
use ipc_channel::ipc::{IpcBytesReceiver, IpcSender};
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
|
use pixels::IpcSnapshot;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_bytes::ByteBuf;
|
use serde_bytes::ByteBuf;
|
||||||
use snapshot::IpcSnapshot;
|
|
||||||
use style::color::AbsoluteColor;
|
use style::color::AbsoluteColor;
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use glow::{
|
||||||
};
|
};
|
||||||
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
|
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
use pixels::PixelFormat;
|
use pixels::{PixelFormat, SnapshotAlphaMode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
use webxr_api::{
|
use webxr_api::{
|
||||||
|
@ -302,7 +302,7 @@ pub enum WebGLCommand {
|
||||||
Rect<u32>,
|
Rect<u32>,
|
||||||
u32,
|
u32,
|
||||||
u32,
|
u32,
|
||||||
IpcSender<(IpcSharedMemory, snapshot::AlphaMode)>,
|
IpcSender<(IpcSharedMemory, SnapshotAlphaMode)>,
|
||||||
),
|
),
|
||||||
ReadPixelsPP(Rect<i32>, u32, u32, usize),
|
ReadPixelsPP(Rect<i32>, u32, u32, usize),
|
||||||
SampleCoverage(f32, bool),
|
SampleCoverage(f32, bool),
|
||||||
|
|
|
@ -28,10 +28,10 @@ log = { workspace = true }
|
||||||
malloc_size_of = { workspace = true }
|
malloc_size_of = { workspace = true }
|
||||||
malloc_size_of_derive = { workspace = true }
|
malloc_size_of_derive = { workspace = true }
|
||||||
net_traits = { workspace = true }
|
net_traits = { workspace = true }
|
||||||
|
pixels = { path = "../../pixels" }
|
||||||
profile_traits = { workspace = true }
|
profile_traits = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
servo_url = { path = "../../url" }
|
servo_url = { path = "../../url" }
|
||||||
snapshot = { workspace = true }
|
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
strum_macros = { workspace = true }
|
strum_macros = { workspace = true }
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
|
|
|
@ -14,9 +14,9 @@ use std::path::PathBuf;
|
||||||
use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId};
|
use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId};
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
use net_traits::filemanager_thread::RelativePos;
|
use net_traits::filemanager_thread::RelativePos;
|
||||||
|
use pixels::Snapshot;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_url::ImmutableOrigin;
|
use servo_url::ImmutableOrigin;
|
||||||
use snapshot::Snapshot;
|
|
||||||
use strum::EnumIter;
|
use strum::EnumIter;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
|
@ -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" }
|
|
|
@ -16,8 +16,8 @@ arrayvec = { workspace = true }
|
||||||
base = { workspace = true }
|
base = { workspace = true }
|
||||||
ipc-channel = { workspace = true }
|
ipc-channel = { workspace = true }
|
||||||
malloc_size_of = { workspace = true }
|
malloc_size_of = { workspace = true }
|
||||||
|
pixels = { path = "../../pixels" }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
webrender_api = { workspace = true }
|
webrender_api = { workspace = true }
|
||||||
wgpu-core = { workspace = true, features = ["serde", "wgsl"] }
|
wgpu-core = { workspace = true, features = ["serde", "wgsl"] }
|
||||||
wgpu-types = { workspace = true }
|
wgpu-types = { workspace = true }
|
||||||
snapshot = { workspace = true }
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use base::id::PipelineId;
|
use base::id::PipelineId;
|
||||||
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
||||||
|
use pixels::IpcSnapshot;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use snapshot::IpcSnapshot;
|
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::ImageKey;
|
||||||
use webrender_api::units::DeviceIntSize;
|
use webrender_api::units::DeviceIntSize;
|
||||||
use wgpu_core::Label;
|
use wgpu_core::Label;
|
||||||
|
|
|
@ -29,7 +29,6 @@ ipc-channel = { workspace = true }
|
||||||
itertools = { workspace = true }
|
itertools = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
pixels = { path = "../pixels" }
|
pixels = { path = "../pixels" }
|
||||||
snapshot = { workspace = true }
|
|
||||||
surfman = { workspace = true }
|
surfman = { workspace = true }
|
||||||
webrender = { workspace = true }
|
webrender = { workspace = true }
|
||||||
webrender_api = { workspace = true }
|
webrender_api = { workspace = true }
|
||||||
|
|
|
@ -34,7 +34,7 @@ use half::f16;
|
||||||
use ipc_channel::ipc::IpcSharedMemory;
|
use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, trace, warn};
|
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::chains::{PreserveBuffer, SwapChains, SwapChainsAPI};
|
||||||
use surfman::{
|
use surfman::{
|
||||||
self, Adapter, Connection, Context, ContextAttributeFlags, ContextAttributes, Device,
|
self, Adapter, Connection, Context, ContextAttributeFlags, ContextAttributes, Device,
|
||||||
|
@ -1215,8 +1215,8 @@ impl WebGLImpl {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let alpha_mode = match (attributes.alpha, attributes.premultiplied_alpha) {
|
let alpha_mode = match (attributes.alpha, attributes.premultiplied_alpha) {
|
||||||
(true, premultiplied) => snapshot::AlphaMode::Transparent { premultiplied },
|
(true, premultiplied) => SnapshotAlphaMode::Transparent { premultiplied },
|
||||||
(false, _) => snapshot::AlphaMode::Opaque,
|
(false, _) => SnapshotAlphaMode::Opaque,
|
||||||
};
|
};
|
||||||
sender
|
sender
|
||||||
.send((IpcSharedMemory::from_bytes(&pixels), alpha_mode))
|
.send((IpcSharedMemory::from_bytes(&pixels), alpha_mode))
|
||||||
|
|
|
@ -18,10 +18,10 @@ compositing_traits = { workspace = true }
|
||||||
euclid = { workspace = true }
|
euclid = { workspace = true }
|
||||||
ipc-channel = { workspace = true }
|
ipc-channel = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
|
pixels = { path = "../pixels" }
|
||||||
serde = { workspace = true, features = ["serde_derive"] }
|
serde = { workspace = true, features = ["serde_derive"] }
|
||||||
servo_config = { path = "../config" }
|
servo_config = { path = "../config" }
|
||||||
webgpu_traits = { workspace = true }
|
webgpu_traits = { workspace = true }
|
||||||
snapshot = { workspace = true }
|
|
||||||
webrender = { workspace = true }
|
webrender = { workspace = true }
|
||||||
webrender_api = { workspace = true }
|
webrender_api = { workspace = true }
|
||||||
wgpu-core = { workspace = true, features = ["serde", "wgsl"] }
|
wgpu-core = { workspace = true, features = ["serde", "wgsl"] }
|
||||||
|
|
|
@ -12,8 +12,8 @@ use compositing_traits::{WebrenderExternalImageApi, WebrenderImageSource};
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
|
use pixels::{IpcSnapshot, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use snapshot::{IpcSnapshot, Snapshot};
|
|
||||||
use webgpu_traits::{
|
use webgpu_traits::{
|
||||||
ContextConfiguration, Error, PRESENTATION_BUFFER_COUNT, WebGPUContextId, WebGPUMsg,
|
ContextConfiguration, Error, PRESENTATION_BUFFER_COUNT, WebGPUContextId, WebGPUMsg,
|
||||||
};
|
};
|
||||||
|
@ -375,16 +375,16 @@ impl crate::WGPU {
|
||||||
.and_then(|swap_chain| swap_chain.data.as_ref())
|
.and_then(|swap_chain| swap_chain.data.as_ref())
|
||||||
{
|
{
|
||||||
let format = match context_data.image_desc.0.format {
|
let format = match context_data.image_desc.0.format {
|
||||||
ImageFormat::RGBA8 => snapshot::PixelFormat::RGBA,
|
ImageFormat::RGBA8 => SnapshotPixelFormat::RGBA,
|
||||||
ImageFormat::BGRA8 => snapshot::PixelFormat::BGRA,
|
ImageFormat::BGRA8 => SnapshotPixelFormat::BGRA,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
let alpha_mode = if context_data.image_desc.0.is_opaque() {
|
let alpha_mode = if context_data.image_desc.0.is_opaque() {
|
||||||
snapshot::AlphaMode::AsOpaque {
|
SnapshotAlphaMode::AsOpaque {
|
||||||
premultiplied: false,
|
premultiplied: false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snapshot::AlphaMode::Transparent {
|
SnapshotAlphaMode::Transparent {
|
||||||
premultiplied: true,
|
premultiplied: true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue