canvas: Use snapshot in canvas backends (#37863)

This removes assumption about pixel format from backend abstraction to
actual backend implementation. This is important for vello.

Testing: WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-07-04 22:22:20 +02:00 committed by GitHub
parent 8df5e1e74d
commit e1a891ea96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 174 additions and 292 deletions

View file

@ -1186,14 +1186,7 @@ impl CanvasState {
let size = snapshot.size();
Ok(Some(CanvasPattern::new(
global,
snapshot
.to_vec(
Some(SnapshotAlphaMode::Transparent {
premultiplied: true,
}),
Some(SnapshotPixelFormat::BGRA),
)
.0, // TODO: send snapshot
snapshot,
size.cast(),
rep,
self.is_origin_clean(image),
@ -1703,10 +1696,8 @@ impl CanvasState {
};
// Step 7.
let (sender, receiver) = ipc::bytes_channel().unwrap();
let pixels = unsafe { &imagedata.get_rect(Rect::new(src_rect.origin, dst_rect.size)) };
self.send_canvas_2d_msg(Canvas2dMsg::PutImageData(dst_rect, receiver));
sender.send(pixels).unwrap();
let snapshot = imagedata.get_snapshot_rect(Rect::new(src_rect.origin, dst_rect.size));
self.send_canvas_2d_msg(Canvas2dMsg::PutImageData(dst_rect, snapshot.as_ipc()));
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage