mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement HTMLCanvasElement.transferControlToOffscreen (#34959)
This follows the spec by introducing a new "Placeholder" canvas context mode. The underlying offscreen canvas is kept accessible from the DOM element to allow for the drawImage() implementation to work with canvases that have transfered their control. Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
90c5685d61
commit
c936dd6c4e
8 changed files with 139 additions and 42 deletions
|
@ -57,7 +57,7 @@ impl OffscreenCanvas {
|
|||
}
|
||||
}
|
||||
|
||||
fn new(
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
width: u64,
|
||||
|
@ -115,8 +115,9 @@ impl OffscreenCanvas {
|
|||
Some((data, size.to_u32()))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_or_init_2d_context(&self) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
|
||||
pub(crate) fn get_or_init_2d_context(
|
||||
&self,
|
||||
) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
|
||||
if let Some(ctx) = self.context() {
|
||||
return match *ctx {
|
||||
OffscreenCanvasContext::OffscreenContext2d(ref ctx) => Some(DomRoot::from_ref(ctx)),
|
||||
|
@ -190,6 +191,10 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(canvas) = &self.placeholder {
|
||||
canvas.set_natural_width(value as _);
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-height
|
||||
|
@ -208,5 +213,9 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(canvas) = &self.placeholder {
|
||||
canvas.set_natural_height(value as _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue