mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
imagebitmap: Make ImageBitmap serializable and transferable (#37101)
According to specification ImageBitmap objects are serializable objects and transferable objects. https://html.spec.whatwg.org/multipage/#the-imagebitmap-interface:imagebitmap-11 Testing: - html/canvas/element/manual/imagebitmap/* - html/infrastructure/safe-passing-of-structured-data/* - html/webappapis/structured-clone/* - workers/semantics/structured-clone/* Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
parent
cd36c35cf2
commit
1f5087d773
19 changed files with 215 additions and 103 deletions
|
@ -10,7 +10,7 @@ mod transferable;
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{BlobId, DomExceptionId, DomPointId, MessagePortId};
|
||||
use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId, MessagePortId};
|
||||
use log::warn;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -34,6 +34,10 @@ pub struct StructuredSerializedData {
|
|||
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
||||
/// Transform streams transferred objects.
|
||||
pub transform_streams: Option<HashMap<MessagePortId, TransformStreamData>>,
|
||||
/// Serialized image bitmap objects.
|
||||
pub image_bitmaps: Option<HashMap<ImageBitmapId, SerializableImageBitmap>>,
|
||||
/// Transferred image bitmap objects.
|
||||
pub transferred_image_bitmaps: Option<HashMap<ImageBitmapId, SerializableImageBitmap>>,
|
||||
}
|
||||
|
||||
impl StructuredSerializedData {
|
||||
|
@ -42,6 +46,7 @@ impl StructuredSerializedData {
|
|||
field.as_ref().is_some_and(|h| h.is_empty())
|
||||
}
|
||||
match val {
|
||||
Transferrable::ImageBitmap => is_field_empty(&self.transferred_image_bitmaps),
|
||||
Transferrable::MessagePort => is_field_empty(&self.ports),
|
||||
Transferrable::ReadableStream => is_field_empty(&self.ports),
|
||||
Transferrable::WritableStream => is_field_empty(&self.ports),
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use base::id::{BlobId, DomExceptionId, DomPointId};
|
||||
use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId};
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use net_traits::filemanager_thread::RelativePos;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -47,6 +47,8 @@ pub enum Serializable {
|
|||
DomPointReadOnly,
|
||||
/// The `DOMException` interface.
|
||||
DomException,
|
||||
/// The `ImageBitmap` interface.
|
||||
ImageBitmap,
|
||||
}
|
||||
|
||||
impl Serializable {
|
||||
|
@ -62,6 +64,9 @@ impl Serializable {
|
|||
Serializable::DomException => {
|
||||
StructuredSerializedData::clone_all_of_type::<DomException>
|
||||
},
|
||||
Serializable::ImageBitmap => {
|
||||
StructuredSerializedData::clone_all_of_type::<SerializableImageBitmap>
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,3 +317,31 @@ impl BroadcastClone for DomException {
|
|||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
/// A serializable version of the ImageBitmap interface.
|
||||
pub struct SerializableImageBitmap {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub bitmap_data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl BroadcastClone for SerializableImageBitmap {
|
||||
type Id = ImageBitmapId;
|
||||
|
||||
fn source(
|
||||
data: &StructuredSerializedData,
|
||||
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&data.image_bitmaps
|
||||
}
|
||||
|
||||
fn destination(
|
||||
data: &mut StructuredSerializedData,
|
||||
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&mut data.image_bitmaps
|
||||
}
|
||||
|
||||
fn clone_for_broadcast(&self) -> Option<Self> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ pub struct TransformStreamData {
|
|||
/// All the DOM interfaces that can be transferred.
|
||||
#[derive(Clone, Copy, Debug, EnumIter)]
|
||||
pub enum Transferrable {
|
||||
/// The `ImageBitmap` interface.
|
||||
ImageBitmap,
|
||||
/// The `MessagePort` interface.
|
||||
MessagePort,
|
||||
/// The `ReadableStream` interface.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue