mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #24464 - rasviitanen:offscreen-canvas, r=jdm
fix getimagedata returns empty pixels <!-- Please describe your changes on the following line: --> GetImageData for OffscreenCanvas without an associated canvas element returned blank pixels. To solve this, we now pass a `Size2D` instead of a canvas to relevant functions. I don't quite know if it's ok that `OffscreenCanvasRenderingContext2D` now have a `width` and `height`, but I found no other reasonable solution to this. There are some tests that previously were marked as `PASS` that are now failing. It seems that they were passing for the wrong reason. These are: > tests/wpt/metadata/offscreen-canvas/pixel-manipulation/2d.imageData.put.unchanged.html.ini > tests/wpt/metadata/offscreen-canvas/pixel-manipulatio/2d.imageData.put.unchanged.worker.js.ini > tests/wpt/metadata/offscreen-canvas/the-offscreen-canvas/initial.reset.path.html.ini > tests/wpt/metadata/offscreen-canvas/the-offscreen-canvas/initial.reset.path.worker.js.ini --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #24271 (GitHub issue number if applicable) <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
83fb2b06d0
57 changed files with 44 additions and 239 deletions
|
@ -298,12 +298,9 @@ impl CanvasState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_rect(&self, canvas: Option<&HTMLCanvasElement>, rect: Rect<u32>) -> Vec<u8> {
|
||||
pub fn get_rect(&self, canvas_size: Size2D<u32>, rect: Rect<u32>) -> Vec<u8> {
|
||||
assert!(self.origin_is_clean());
|
||||
|
||||
// FIXME(nox): This is probably wrong when this is a context for an
|
||||
// offscreen canvas.
|
||||
let canvas_size = canvas.as_ref().map_or(Size2D::zero(), |c| c.get_size());
|
||||
assert!(Rect::from_size(canvas_size).contains_rect(&rect));
|
||||
|
||||
let (sender, receiver) = ipc::bytes_channel().unwrap();
|
||||
|
@ -1020,7 +1017,7 @@ impl CanvasState {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||
pub fn GetImageData(
|
||||
&self,
|
||||
canvas: Option<&HTMLCanvasElement>,
|
||||
canvas_size: Size2D<u32>,
|
||||
global: &GlobalScope,
|
||||
sx: i32,
|
||||
sy: i32,
|
||||
|
@ -1039,9 +1036,6 @@ impl CanvasState {
|
|||
}
|
||||
|
||||
let (origin, size) = adjust_size_sign(Point2D::new(sx, sy), Size2D::new(sw, sh));
|
||||
// FIXME(nox): This is probably wrong when this is a context for an
|
||||
// offscreen canvas.
|
||||
let canvas_size = canvas.as_ref().map_or(Size2D::zero(), |c| c.get_size());
|
||||
let read_rect = match pixels::clip(origin, size, canvas_size) {
|
||||
Some(rect) => rect,
|
||||
None => {
|
||||
|
@ -1054,20 +1048,14 @@ impl CanvasState {
|
|||
global,
|
||||
size.width,
|
||||
size.height,
|
||||
Some(self.get_rect(canvas, read_rect)),
|
||||
Some(self.get_rect(canvas_size, read_rect)),
|
||||
)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
pub fn PutImageData(
|
||||
&self,
|
||||
canvas: Option<&HTMLCanvasElement>,
|
||||
imagedata: &ImageData,
|
||||
dx: i32,
|
||||
dy: i32,
|
||||
) {
|
||||
pub fn PutImageData(&self, canvas_size: Size2D<u32>, imagedata: &ImageData, dx: i32, dy: i32) {
|
||||
self.PutImageData_(
|
||||
canvas,
|
||||
canvas_size,
|
||||
imagedata,
|
||||
dx,
|
||||
dy,
|
||||
|
@ -1082,7 +1070,7 @@ impl CanvasState {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn PutImageData_(
|
||||
&self,
|
||||
canvas: Option<&HTMLCanvasElement>,
|
||||
canvas_size: Size2D<u32>,
|
||||
imagedata: &ImageData,
|
||||
dx: i32,
|
||||
dy: i32,
|
||||
|
@ -1105,10 +1093,6 @@ impl CanvasState {
|
|||
// Step 2.
|
||||
// TODO: throw InvalidState if buffer is detached.
|
||||
|
||||
// FIXME(nox): This is probably wrong when this is a context for an
|
||||
// offscreen canvas.
|
||||
let canvas_size = canvas.as_ref().map_or(Size2D::zero(), |c| c.get_size());
|
||||
|
||||
// Steps 3-6.
|
||||
let (src_origin, src_size) = adjust_size_sign(
|
||||
Point2D::new(dirty_x, dirty_y),
|
||||
|
@ -1553,9 +1537,12 @@ impl CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
pub fn get_rect(&self, rect: Rect<u32>) -> Vec<u8> {
|
||||
self.canvas_state
|
||||
.borrow()
|
||||
.get_rect(self.canvas.as_ref().map(|c| &**c), rect)
|
||||
self.canvas_state.borrow().get_rect(
|
||||
self.canvas
|
||||
.as_ref()
|
||||
.map_or(Size2D::zero(), |c| c.get_size()),
|
||||
rect,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1886,7 +1873,9 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
// 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.borrow().GetImageData(
|
||||
self.canvas.as_ref().map(|c| &**c),
|
||||
self.canvas
|
||||
.as_ref()
|
||||
.map_or(Size2D::zero(), |c| c.get_size()),
|
||||
&self.global(),
|
||||
sx,
|
||||
sy,
|
||||
|
@ -1898,7 +1887,9 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
|
||||
self.canvas_state.borrow().PutImageData(
|
||||
self.canvas.as_ref().map(|c| &**c),
|
||||
self.canvas
|
||||
.as_ref()
|
||||
.map_or(Size2D::zero(), |c| c.get_size()),
|
||||
imagedata,
|
||||
dx,
|
||||
dy,
|
||||
|
@ -1918,7 +1909,9 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
dirty_height: i32,
|
||||
) {
|
||||
self.canvas_state.borrow().PutImageData_(
|
||||
self.canvas.as_ref().map(|c| &**c),
|
||||
self.canvas
|
||||
.as_ref()
|
||||
.map_or(Size2D::zero(), |c| c.get_size()),
|
||||
imagedata,
|
||||
dx,
|
||||
dy,
|
||||
|
|
|
@ -33,6 +33,8 @@ pub struct OffscreenCanvasRenderingContext2D {
|
|||
canvas: Option<Dom<OffscreenCanvas>>,
|
||||
canvas_state: DomRefCell<CanvasState>,
|
||||
htmlcanvas: Option<Dom<HTMLCanvasElement>>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
}
|
||||
|
||||
impl OffscreenCanvasRenderingContext2D {
|
||||
|
@ -50,6 +52,8 @@ impl OffscreenCanvasRenderingContext2D {
|
|||
global,
|
||||
Size2D::new(size.width as u64, size.height as u64),
|
||||
)),
|
||||
width: size.width as u32,
|
||||
height: size.height as u32,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,7 +311,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
|||
// 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.borrow().GetImageData(
|
||||
self.htmlcanvas.as_ref().map(|c| &**c),
|
||||
Size2D::new(self.width, self.height),
|
||||
&self.global(),
|
||||
sx,
|
||||
sy,
|
||||
|
@ -319,7 +323,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
|||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
|
||||
self.canvas_state.borrow().PutImageData(
|
||||
self.htmlcanvas.as_ref().map(|c| &**c),
|
||||
Size2D::new(self.width, self.height),
|
||||
imagedata,
|
||||
dx,
|
||||
dy,
|
||||
|
@ -339,7 +343,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
|||
dirty_height: i32,
|
||||
) {
|
||||
self.canvas_state.borrow().PutImageData_(
|
||||
self.htmlcanvas.as_ref().map(|c| &**c),
|
||||
Size2D::new(self.width, self.height),
|
||||
imagedata,
|
||||
dx,
|
||||
dy,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue