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

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