mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Align ctx.createImageData and ctx.getImageData with the spec
This commit is contained in:
parent
f13e35b2c5
commit
241dba064d
10 changed files with 54 additions and 81 deletions
|
@ -11,7 +11,7 @@ use azure::azure_hl::SurfacePattern;
|
|||
use canvas_traits::canvas::*;
|
||||
use cssparser::RGBA;
|
||||
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
||||
use ipc_channel::ipc::{IpcBytesSender, IpcSender};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use num_traits::ToPrimitive;
|
||||
use pixels;
|
||||
use serde_bytes::ByteBuf;
|
||||
|
@ -440,15 +440,6 @@ impl<'a> CanvasData<'a> {
|
|||
chan.send(data).unwrap();
|
||||
}
|
||||
|
||||
pub fn image_data(
|
||||
&self,
|
||||
dest_rect: Rect<i32>,
|
||||
canvas_size: Size2D<f64>,
|
||||
sender: IpcBytesSender,
|
||||
) {
|
||||
sender.send(&self.read_pixels(dest_rect, canvas_size)).unwrap();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
pub fn put_image_data(
|
||||
&mut self,
|
||||
|
@ -526,9 +517,8 @@ impl<'a> CanvasData<'a> {
|
|||
/// canvas_size: The size of the canvas we're reading from
|
||||
/// read_rect: The area of the canvas we want to read from
|
||||
#[allow(unsafe_code)]
|
||||
pub fn read_pixels(&self, read_rect: Rect<i32>, canvas_size: Size2D<f64>) -> Vec<u8> {
|
||||
let canvas_size = canvas_size.to_i32();
|
||||
let canvas_rect = Rect::new(Point2D::new(0i32, 0i32), canvas_size);
|
||||
pub fn read_pixels(&self, read_rect: Rect<i32>, canvas_size: Size2D<i32>) -> Vec<u8> {
|
||||
let canvas_rect = Rect::from_size(canvas_size);
|
||||
let src_read_rect = canvas_rect.intersection(&read_rect).unwrap_or(Rect::zero());
|
||||
|
||||
if src_read_rect.is_empty() || canvas_size.width <= 0 && canvas_size.height <= 0 {
|
||||
|
|
|
@ -163,7 +163,7 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
) => {
|
||||
let image_data = self.canvas(canvas_id).read_pixels(
|
||||
source_rect.to_i32(),
|
||||
image_size,
|
||||
image_size.to_i32(),
|
||||
);
|
||||
self.canvas(other_canvas_id).draw_image(
|
||||
image_data.into(),
|
||||
|
@ -238,8 +238,9 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
Canvas2dMsg::SetGlobalComposition(op) => {
|
||||
self.canvas(canvas_id).set_global_composition(op)
|
||||
},
|
||||
Canvas2dMsg::GetImageData(dest_rect, canvas_size, chan) => {
|
||||
self.canvas(canvas_id).image_data(dest_rect, canvas_size, chan)
|
||||
Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender) => {
|
||||
let pixels = self.canvas(canvas_id).read_pixels(dest_rect, canvas_size);
|
||||
sender.send(&pixels).unwrap();
|
||||
},
|
||||
Canvas2dMsg::PutImageData(receiver, offset, imagedata_size) => {
|
||||
self.canvas(canvas_id).put_image_data(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue