mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
CanGc fixes starting from imagedata.rs (#33808)
* CanGc fixes starting from imagedata.rs Signed-off-by: L Ashwin B <lashwinib@gmail.com> * Update components/script/dom/imagedata.rs Co-authored-by: Josh Matthews <josh@joshmatthews.net> Signed-off-by: chickenleaf <lashwinib@gmail.com> --------- Signed-off-by: L Ashwin B <lashwinib@gmail.com> Signed-off-by: chickenleaf <lashwinib@gmail.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
27b25e869b
commit
20a15619f0
5 changed files with 65 additions and 24 deletions
|
@ -57,6 +57,7 @@ use crate::dom::node::{window_from_node, Node, NodeDamage};
|
|||
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
|
||||
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||
use crate::dom::textmetrics::TextMetrics;
|
||||
use crate::script_runtime::CanGc;
|
||||
use crate::unpremultiplytable::UNPREMULTIPLY_TABLE;
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
|
@ -1232,11 +1233,12 @@ impl CanvasState {
|
|||
global: &GlobalScope,
|
||||
sw: i32,
|
||||
sh: i32,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
if sw == 0 || sh == 0 {
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
ImageData::new(global, sw.unsigned_abs(), sh.unsigned_abs(), None)
|
||||
ImageData::new(global, sw.unsigned_abs(), sh.unsigned_abs(), None, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
|
@ -1244,8 +1246,9 @@ impl CanvasState {
|
|||
&self,
|
||||
global: &GlobalScope,
|
||||
imagedata: &ImageData,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
ImageData::new(global, imagedata.Width(), imagedata.Height(), None)
|
||||
ImageData::new(global, imagedata.Width(), imagedata.Height(), None, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||
|
@ -1257,6 +1260,7 @@ impl CanvasState {
|
|||
sy: i32,
|
||||
sw: i32,
|
||||
sh: i32,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
// FIXME(nox): There are many arithmetic operations here that can
|
||||
// overflow or underflow, this should probably be audited.
|
||||
|
@ -1274,7 +1278,7 @@ impl CanvasState {
|
|||
Some(rect) => rect,
|
||||
None => {
|
||||
// All the pixels are outside the canvas surface.
|
||||
return ImageData::new(global, size.width, size.height, None);
|
||||
return ImageData::new(global, size.width, size.height, None, can_gc);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1283,6 +1287,7 @@ impl CanvasState {
|
|||
size.width,
|
||||
size.height,
|
||||
Some(self.get_rect(canvas_size, read_rect)),
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,10 @@ DOMInterfaces = {
|
|||
'inRealms': ['WhenDefined'],
|
||||
},
|
||||
|
||||
'CanvasRenderingContext2D': {
|
||||
'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'],
|
||||
},
|
||||
|
||||
'DOMImplementation': {
|
||||
'canGc': ['CreateDocument', 'CreateHTMLDocument'],
|
||||
},
|
||||
|
@ -145,6 +149,10 @@ DOMInterfaces = {
|
|||
'inRealms': ['StartRendering'],
|
||||
},
|
||||
|
||||
'OffscreenCanvasRenderingContext2D': {
|
||||
'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'],
|
||||
},
|
||||
|
||||
'Promise': {
|
||||
'spiderMonkeyInterface': True,
|
||||
},
|
||||
|
|
|
@ -26,6 +26,7 @@ use crate::dom::globalscope::GlobalScope;
|
|||
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
||||
use crate::dom::imagedata::ImageData;
|
||||
use crate::dom::textmetrics::TextMetrics;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d
|
||||
#[dom_struct]
|
||||
|
@ -467,18 +468,30 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state.create_image_data(&self.global(), sw, sh)
|
||||
fn CreateImageData(&self, sw: i32, sh: i32, can_gc: CanGc) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state
|
||||
.create_image_data(&self.global(), sw, sh, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
||||
fn CreateImageData_(
|
||||
&self,
|
||||
imagedata: &ImageData,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state
|
||||
.create_image_data_(&self.global(), imagedata)
|
||||
.create_image_data_(&self.global(), imagedata, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||
fn GetImageData(
|
||||
&self,
|
||||
sx: i32,
|
||||
sy: i32,
|
||||
sw: i32,
|
||||
sh: i32,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state.get_image_data(
|
||||
self.canvas
|
||||
.as_ref()
|
||||
|
@ -488,6 +501,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
sy,
|
||||
sw,
|
||||
sh,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ impl ImageData {
|
|||
width: u32,
|
||||
height: u32,
|
||||
mut data: Option<Vec<u8>>,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
let len = width * height * 4;
|
||||
unsafe {
|
||||
|
@ -48,16 +49,9 @@ impl ImageData {
|
|||
d.resize(len as usize, 0);
|
||||
let data = CreateWith::Slice(&d[..]);
|
||||
Uint8ClampedArray::create(*cx, data, js_object.handle_mut()).unwrap();
|
||||
Self::new_with_jsobject(
|
||||
global,
|
||||
None,
|
||||
width,
|
||||
Some(height),
|
||||
js_object.get(),
|
||||
CanGc::note(),
|
||||
)
|
||||
Self::new_with_jsobject(global, None, width, Some(height), js_object.get(), can_gc)
|
||||
} else {
|
||||
Self::new_without_jsobject(global, None, width, height, CanGc::note())
|
||||
Self::new_without_jsobject(global, None, width, height, can_gc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
|||
use crate::dom::imagedata::ImageData;
|
||||
use crate::dom::offscreencanvas::OffscreenCanvas;
|
||||
use crate::dom::textmetrics::TextMetrics;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OffscreenCanvasRenderingContext2D {
|
||||
|
@ -342,20 +343,39 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state.create_image_data(&self.global(), sw, sh)
|
||||
fn CreateImageData(&self, sw: i32, sh: i32, can_gc: CanGc) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state
|
||||
.create_image_data(&self.global(), sw, sh, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
||||
fn CreateImageData_(
|
||||
&self,
|
||||
imagedata: &ImageData,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state
|
||||
.create_image_data_(&self.global(), imagedata)
|
||||
.create_image_data_(&self.global(), imagedata, can_gc)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state
|
||||
.get_image_data(self.canvas.get_size(), &self.global(), sx, sy, sw, sh)
|
||||
fn GetImageData(
|
||||
&self,
|
||||
sx: i32,
|
||||
sy: i32,
|
||||
sw: i32,
|
||||
sh: i32,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
self.canvas_state.get_image_data(
|
||||
self.canvas.get_size(),
|
||||
&self.global(),
|
||||
sx,
|
||||
sy,
|
||||
sw,
|
||||
sh,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue