mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
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:
parent
213b532712
commit
d410236c87
2 changed files with 10 additions and 29 deletions
|
@ -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,
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg};
|
||||
use canvas_traits::canvas::{Canvas2dMsg, CanvasId};
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::default::Size2D;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::ipc;
|
||||
use pixels::Snapshot;
|
||||
use script_bindings::inheritance::Castable;
|
||||
use servo_url::ServoUrl;
|
||||
|
@ -37,29 +37,12 @@ use crate::dom::path2d::Path2D;
|
|||
use crate::dom::textmetrics::TextMetrics;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
struct DroppableCanvasRenderingContext2D {
|
||||
#[no_trace]
|
||||
ipc_sender: IpcSender<CanvasMsg>,
|
||||
#[no_trace]
|
||||
canvas_id: CanvasId,
|
||||
}
|
||||
|
||||
impl Drop for DroppableCanvasRenderingContext2D {
|
||||
fn drop(&mut self) {
|
||||
if let Err(err) = self.ipc_sender.send(CanvasMsg::Close(self.canvas_id)) {
|
||||
warn!("Could not close canvas: {}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d
|
||||
#[dom_struct]
|
||||
pub(crate) struct CanvasRenderingContext2D {
|
||||
reflector_: Reflector,
|
||||
canvas: HTMLCanvasElementOrOffscreenCanvas,
|
||||
canvas_state: CanvasState,
|
||||
droppable: DroppableCanvasRenderingContext2D,
|
||||
}
|
||||
|
||||
impl CanvasRenderingContext2D {
|
||||
|
@ -71,16 +54,10 @@ impl CanvasRenderingContext2D {
|
|||
) -> Option<CanvasRenderingContext2D> {
|
||||
let canvas_state =
|
||||
CanvasState::new(global, Size2D::new(size.width as u64, size.height as u64))?;
|
||||
let ipc_sender = canvas_state.get_ipc_renderer().clone();
|
||||
let canvas_id = canvas_state.get_canvas_id();
|
||||
Some(CanvasRenderingContext2D {
|
||||
reflector_: Reflector::new(),
|
||||
canvas,
|
||||
canvas_state,
|
||||
droppable: DroppableCanvasRenderingContext2D {
|
||||
ipc_sender,
|
||||
canvas_id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue