canvas: Send CanvasClose to canvas thread from canvas state (#38315)

Currently we only closed `CanvasRenderingContext2D` (and
`OffscreenCanvasRenderingContext2D` because it wraps
`CanvasRenderingContext2D`), but we didn't close last consumer of
`CanvasState` which is `PaintRenderingContext`. To prevent any future
leaks, let's just send `CanvasClose` in `CanvasState` drop.

Testing: Existing WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-07-28 22:09:47 +02:00 committed by GitHub
parent 213b532712
commit d410236c87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 29 deletions

View file

@ -259,10 +259,6 @@ impl CanvasState {
})
}
pub(crate) fn get_ipc_renderer(&self) -> &IpcSender<CanvasMsg> {
&self.ipc_renderer
}
pub(crate) fn image_key(&self) -> ImageKey {
self.image_key
}
@ -2197,6 +2193,14 @@ impl CanvasState {
}
}
impl Drop for CanvasState {
fn drop(&mut self) {
if let Err(err) = self.ipc_renderer.send(CanvasMsg::Close(self.canvas_id)) {
warn!("Could not close canvas: {}", err)
}
}
}
pub(crate) fn parse_color(
canvas: Option<&HTMLCanvasElement>,
string: &str,