mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
canvas: Use non rooted variant of HTMLCanvasElementOrOffscreenCanvas type (#38970)
Any RenderingContext/OffscreenRenderingContext type has readonly "canvas" attribute and associated native-code DOM context objects have reference to target DOM canvas objects. https://html.spec.whatwg.org/multipage/canvas.html#renderingcontext https://html.spec.whatwg.org/multipage/canvas.html#offscreenrenderingcontext And currently the reference to DOM canvas object is the rooting pointer on the stack, which leads to the circular reference problem. The SpiderMonkey's (SM) garbage collector will not be able to free the DOM canvas and context objects (unreacheble from JS) because of the rooting pointer on stack (see STACK_ROOTS). And these objects will be stored until the associated script runtime/thread will be terminated. SM -> JS Roots -> DOM Canvas* (on heap) -> DOM Context (on heap) SM -> Rust Roots -> Dom Canvas* (on stack) <- as "canvas" member field Let's replace the rooting pointer to the traceble pointer (DomRoot -> Dom) in the "canvas" member field of DOM context object, which allows to broke circular referencing problem. Testing: No changes in existed tests Signed-off-by: Andrei Volykhin <volykhin.andrei@huawei.com> Co-authored-by: Andrei Volykhin <volykhin.andrei@huawei.com>
This commit is contained in:
parent
2c7866eb24
commit
8a62984c2f
11 changed files with 191 additions and 116 deletions
|
@ -20,7 +20,7 @@ use crate::dom::bindings::codegen::Bindings::OffscreenCanvasBinding::{
|
|||
ImageEncodeOptions, OffscreenCanvasMethods,
|
||||
OffscreenRenderingContext as RootedOffscreenRenderingContext,
|
||||
};
|
||||
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
||||
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas as RootedHTMLCanvasElementOrOffscreenCanvas;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
|
||||
|
@ -135,7 +135,8 @@ impl OffscreenCanvas {
|
|||
_ => None,
|
||||
};
|
||||
}
|
||||
let context = OffscreenCanvasRenderingContext2D::new(&self.global(), self, can_gc)?;
|
||||
let context =
|
||||
OffscreenCanvasRenderingContext2D::new(&self.global(), self, self.get_size(), can_gc)?;
|
||||
*self.context.borrow_mut() = Some(OffscreenRenderingContext::Context2d(Dom::from_ref(
|
||||
&*context,
|
||||
)));
|
||||
|
@ -159,11 +160,10 @@ impl OffscreenCanvas {
|
|||
// Step 1. Let context be the result of running the
|
||||
// ImageBitmapRenderingContext creation algorithm given this and
|
||||
// options.
|
||||
let context = ImageBitmapRenderingContext::new(
|
||||
&self.global(),
|
||||
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(DomRoot::from_ref(self)),
|
||||
can_gc,
|
||||
);
|
||||
let canvas =
|
||||
RootedHTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(DomRoot::from_ref(self));
|
||||
|
||||
let context = ImageBitmapRenderingContext::new(&self.global(), &canvas, can_gc);
|
||||
|
||||
// Step 2. Set this's context mode to bitmaprenderer.
|
||||
*self.context.borrow_mut() = Some(OffscreenRenderingContext::BitmapRenderer(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue