aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/constellation/structured_data/serializable.rs
diff options
context:
space:
mode:
authorAndrei Volykhin <andrei.volykhin@gmail.com>2025-05-23 23:40:25 +0300
committerGitHub <noreply@github.com>2025-05-23 20:40:25 +0000
commit1f5087d7734e464ef2cdf7db25c143a5e5720b6a (patch)
tree69287bf8e85c1a7989a67e28b54377d33e29659d /components/shared/constellation/structured_data/serializable.rs
parentcd36c35cf2891076e396155d3e6698fe385cf510 (diff)
downloadservo-1f5087d7734e464ef2cdf7db25c143a5e5720b6a.tar.gz
servo-1f5087d7734e464ef2cdf7db25c143a5e5720b6a.zip
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>
Diffstat (limited to 'components/shared/constellation/structured_data/serializable.rs')
-rw-r--r--components/shared/constellation/structured_data/serializable.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/components/shared/constellation/structured_data/serializable.rs b/components/shared/constellation/structured_data/serializable.rs
index 22370087665..cbb932c52ec 100644
--- a/components/shared/constellation/structured_data/serializable.rs
+++ b/components/shared/constellation/structured_data/serializable.rs
@@ -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())
+ }
+}