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,10 @@ use wgpu_core::id;
|
|||
|
||||
use super::gpuconvert::convert_texture_descriptor;
|
||||
use super::gputexture::GPUTexture;
|
||||
use crate::canvas_context::{CanvasContext, CanvasHelpers};
|
||||
use crate::canvas_context::{
|
||||
CanvasContext, CanvasHelpers, HTMLCanvasElementOrOffscreenCanvas,
|
||||
LayoutCanvasRenderingContextHelpers,
|
||||
};
|
||||
use crate::conversions::Convert;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUTexture_Binding::GPUTextureMethods;
|
||||
|
@ -29,15 +32,15 @@ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
|||
GPUObjectDescriptorBase, GPUTextureDescriptor, GPUTextureDimension, GPUTextureFormat,
|
||||
GPUTextureUsageConstants,
|
||||
};
|
||||
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::reflector::{DomGlobal, Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::bindings::weakref::WeakRef;
|
||||
use crate::dom::document::WebGPUContextsMap;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::html::htmlcanvaselement::{HTMLCanvasElement, LayoutCanvasRenderingContextHelpers};
|
||||
use crate::dom::html::htmlcanvaselement::HTMLCanvasElement;
|
||||
use crate::dom::node::NodeTraits;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
|
@ -91,6 +94,7 @@ pub(crate) struct GPUCanvasContext {
|
|||
}
|
||||
|
||||
impl GPUCanvasContext {
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
fn new_inherited(
|
||||
global: &GlobalScope,
|
||||
canvas: HTMLCanvasElementOrOffscreenCanvas,
|
||||
|
@ -139,7 +143,7 @@ impl GPUCanvasContext {
|
|||
let this = reflect_dom_object(
|
||||
Box::new(GPUCanvasContext::new_inherited(
|
||||
global,
|
||||
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(DomRoot::from_ref(canvas)),
|
||||
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(Dom::from_ref(canvas)),
|
||||
channel,
|
||||
document.webgpu_contexts(),
|
||||
)),
|
||||
|
@ -328,8 +332,8 @@ impl CanvasContext for GPUCanvasContext {
|
|||
})
|
||||
}
|
||||
|
||||
fn canvas(&self) -> Option<HTMLCanvasElementOrOffscreenCanvas> {
|
||||
Some(self.canvas.clone())
|
||||
fn canvas(&self) -> Option<RootedHTMLCanvasElementOrOffscreenCanvas> {
|
||||
Some(RootedHTMLCanvasElementOrOffscreenCanvas::from(&self.canvas))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,8 +345,8 @@ impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
|
|||
|
||||
impl GPUCanvasContextMethods<crate::DomTypeHolder> for GPUCanvasContext {
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-canvas>
|
||||
fn Canvas(&self) -> HTMLCanvasElementOrOffscreenCanvas {
|
||||
self.canvas.clone()
|
||||
fn Canvas(&self) -> RootedHTMLCanvasElementOrOffscreenCanvas {
|
||||
RootedHTMLCanvasElementOrOffscreenCanvas::from(&self.canvas)
|
||||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-configure>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue