imagebitmap: Use snapshot::Snapshot as bitmap data (#37131)

Replace the holder of actual pixel data of the ImageBitmap interface
([[BitmapData]] slot) from Vec<u8> to snapshot::Snapshot (image bitmap
with metadata).
https://html.spec.whatwg.org/multipage/#the-imagebitmap-interface

It will allow to have all required information (e.g. size, pixel format,
alpha mode)
for further drawing processing to/from canvas2D output bitmap.

Testing: No required tests
Fixes: https://github.com/servo/servo/issues/34112

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-05-27 09:41:25 +03:00 committed by GitHub
parent d76b4a14df
commit 86b3b16b4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 47 deletions

View file

@ -31,6 +31,7 @@ net_traits = { workspace = true }
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

@ -16,6 +16,7 @@ use malloc_size_of_derive::MallocSizeOf;
use net_traits::filemanager_thread::RelativePos;
use serde::{Deserialize, Serialize};
use servo_url::ImmutableOrigin;
use snapshot::Snapshot;
use strum::EnumIter;
use uuid::Uuid;
@ -321,9 +322,7 @@ impl BroadcastClone for DomException {
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
/// A serializable version of the ImageBitmap interface.
pub struct SerializableImageBitmap {
pub width: u32,
pub height: u32,
pub bitmap_data: Vec<u8>,
pub bitmap_data: Snapshot,
}
impl BroadcastClone for SerializableImageBitmap {

View file

@ -15,5 +15,7 @@ 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

@ -6,17 +6,18 @@ 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};
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub enum PixelFormat {
#[default]
RGBA,
BGRA,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub enum AlphaMode {
/// Internal data is opaque (alpha is cleared to 1)
Opaque,
@ -48,7 +49,7 @@ impl AlphaMode {
}
}
#[derive(Debug)]
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub enum Data {
// TODO: https://github.com/servo/servo/issues/36594
//IPC(IpcSharedMemory),
@ -84,7 +85,7 @@ 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(Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct Snapshot<T = Data> {
size: Size2D<u64>,
/// internal data (can be any format it will be converted on use if needed)