mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Switch PutImageData to using CopySurface
This commit is contained in:
parent
9a88348978
commit
51938d579f
9 changed files with 61 additions and 46 deletions
|
@ -172,8 +172,8 @@ impl<'a> CanvasPaintTask<'a> {
|
|||
Canvas2dMsg::SetGlobalComposition(op) => painter.set_global_composition(op),
|
||||
Canvas2dMsg::GetImageData(dest_rect, canvas_size, chan)
|
||||
=> painter.get_image_data(dest_rect, canvas_size, chan),
|
||||
Canvas2dMsg::PutImageData(imagedata, image_data_rect, dirty_rect)
|
||||
=> painter.put_image_data(imagedata, image_data_rect, dirty_rect),
|
||||
Canvas2dMsg::PutImageData(imagedata, offset, image_data_size, dirty_rect)
|
||||
=> painter.put_image_data(imagedata, offset, image_data_size, dirty_rect),
|
||||
Canvas2dMsg::SetShadowOffsetX(value) => painter.set_shadow_offset_x(value),
|
||||
Canvas2dMsg::SetShadowOffsetY(value) => painter.set_shadow_offset_y(value),
|
||||
Canvas2dMsg::SetShadowBlur(value) => painter.set_shadow_blur(value),
|
||||
|
@ -543,20 +543,17 @@ impl<'a> CanvasPaintTask<'a> {
|
|||
chan.send(dest_data).unwrap();
|
||||
}
|
||||
|
||||
fn put_image_data(&mut self, mut imagedata: Vec<u8>,
|
||||
image_data_rect: Rect<f64>,
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||
fn put_image_data(&mut self, imagedata: Vec<u8>,
|
||||
offset: Point2D<f64>,
|
||||
image_data_size: Size2D<f64>,
|
||||
mut dirty_rect: Rect<f64>) {
|
||||
|
||||
|
||||
if image_data_rect.size.width <= 0.0 || image_data_rect.size.height <= 0.0 {
|
||||
if image_data_size.width <= 0.0 || image_data_size.height <= 0.0 {
|
||||
return
|
||||
}
|
||||
|
||||
assert!(image_data_rect.size.width * image_data_rect.size.height * 4.0 == imagedata.len() as f64);
|
||||
// rgba -> bgra
|
||||
byte_swap(&mut imagedata);
|
||||
|
||||
let image_data_size = image_data_rect.size;
|
||||
assert!(image_data_size.width * image_data_size.height * 4.0 == imagedata.len() as f64);
|
||||
|
||||
// Step 1. TODO (neutered data)
|
||||
|
||||
|
@ -597,19 +594,40 @@ impl<'a> CanvasPaintTask<'a> {
|
|||
return
|
||||
}
|
||||
|
||||
// 6) For all integer values of x and y where dirtyX ≤ x < dirty
|
||||
// X+dirtyWidth and dirtyY ≤ y < dirtyY+dirtyHeight, copy the
|
||||
// four channels of the pixel with coordinate (x, y) in the imagedata
|
||||
// data structure's Canvas Pixel ArrayBuffer to the pixel with coordinate
|
||||
// (dx+x, dy+y) in the rendering context's scratch bitmap.
|
||||
// It also clips the destination rectangle to the canvas area
|
||||
let dest_rect = Rect::new(
|
||||
Point2D::new(image_data_rect.origin.x + dirty_rect.origin.x,
|
||||
image_data_rect.origin.y + dirty_rect.origin.y),
|
||||
Size2D::new(dirty_rect.size.width, dirty_rect.size.height));
|
||||
// Step 6.
|
||||
let dest_rect = dirty_rect.translate(&offset).to_i32();
|
||||
|
||||
write_pixels(&self.drawtarget, &imagedata, image_data_rect.size, dirty_rect,
|
||||
dest_rect, true, self.state.draw_options.composition, self.state.draw_options.alpha)
|
||||
// azure_hl operates with integers. We need to cast the image size
|
||||
let image_size = image_data_size.to_i32();
|
||||
|
||||
let first_pixel = dest_rect.origin - offset.to_i32();
|
||||
let mut src_line = (first_pixel.y * (image_size.width * 4) + first_pixel.x * 4) as usize;
|
||||
|
||||
let mut dest =
|
||||
Vec::with_capacity((dest_rect.size.width * dest_rect.size.height * 4) as usize);
|
||||
|
||||
for _ in 0 .. dest_rect.size.height {
|
||||
let mut src_offset = src_line;
|
||||
for _ in 0 .. dest_rect.size.width {
|
||||
// Premultiply alpha and swap RGBA -> BGRA.
|
||||
// TODO: may want a precomputed premultiply table to make this fast. (#6969)
|
||||
let alpha = imagedata[src_offset + 3] as f32 / 255.;
|
||||
dest.push((imagedata[src_offset + 2] as f32 * alpha) as u8);
|
||||
dest.push((imagedata[src_offset + 1] as f32 * alpha) as u8);
|
||||
dest.push((imagedata[src_offset + 0] as f32 * alpha) as u8);
|
||||
dest.push(imagedata[src_offset + 3]);
|
||||
src_offset += 4;
|
||||
}
|
||||
src_line += (image_size.width * 4) as usize;
|
||||
}
|
||||
|
||||
let source_surface = self.drawtarget.create_source_surface_from_data(
|
||||
&dest,
|
||||
dest_rect.size, dest_rect.size.width * 4, SurfaceFormat::B8G8R8A8);
|
||||
|
||||
self.drawtarget.copy_surface(source_surface,
|
||||
Rect::new(Point2D::new(0, 0), dest_rect.size),
|
||||
dest_rect.origin);
|
||||
}
|
||||
|
||||
fn set_shadow_offset_x(&mut self, value: f64) {
|
||||
|
@ -766,6 +784,17 @@ fn is_zero_size_gradient(pattern: &Pattern) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
pub trait PointToi32 {
|
||||
fn to_i32(&self) -> Point2D<i32>;
|
||||
}
|
||||
|
||||
impl PointToi32 for Point2D<f64> {
|
||||
fn to_i32(&self) -> Point2D<i32> {
|
||||
Point2D::new(self.x.to_i32().unwrap(),
|
||||
self.y.to_i32().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SizeToi32 {
|
||||
fn to_i32(&self) -> Size2D<i32>;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ pub enum Canvas2dMsg {
|
|||
GetImageData(Rect<f64>, Size2D<f64>, IpcSender<Vec<u8>>),
|
||||
LineTo(Point2D<f32>),
|
||||
MoveTo(Point2D<f32>),
|
||||
PutImageData(Vec<u8>, Rect<f64>, Rect<f64>),
|
||||
PutImageData(Vec<u8>, Point2D<f64>, Size2D<f64>, Rect<f64>),
|
||||
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
||||
Rect(Rect<f32>),
|
||||
RestoreContext,
|
||||
|
|
|
@ -926,12 +926,13 @@ impl<'a> CanvasRenderingContext2DMethods for &'a CanvasRenderingContext2D {
|
|||
fn PutImageData_(self, imagedata: &ImageData, dx: Finite<f64>, dy: Finite<f64>,
|
||||
dirtyX: Finite<f64>, dirtyY: Finite<f64>, dirtyWidth: Finite<f64>, dirtyHeight: Finite<f64>) {
|
||||
let data = imagedata.get_data_array(&self.global.root().r());
|
||||
let image_data_rect = Rect::new(Point2D::new(*dx, *dy),
|
||||
Size2D::new(imagedata.Width() as f64,
|
||||
imagedata.Height() as f64));
|
||||
let offset = Point2D::new(*dx, *dy);
|
||||
let image_data_size = Size2D::new(imagedata.Width() as f64,
|
||||
imagedata.Height() as f64);
|
||||
|
||||
let dirty_rect = Rect::new(Point2D::new(*dirtyX, *dirtyY),
|
||||
Size2D::new(*dirtyWidth, *dirtyHeight));
|
||||
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect));
|
||||
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, offset, image_data_size, dirty_rect));
|
||||
self.ipc_renderer.send(msg).unwrap();
|
||||
self.mark_as_dirty();
|
||||
}
|
||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -64,7 +64,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
[[package]]
|
||||
name = "azure"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-azure#a6d3af35eafe9a02af3fa58b1f1d30eb9cb57ccd"
|
||||
source = "git+https://github.com/servo/rust-azure#53e7b7d07bd43199b136d869b1605016ed882cbc"
|
||||
dependencies = [
|
||||
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -63,7 +63,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
[[package]]
|
||||
name = "azure"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-azure#a6d3af35eafe9a02af3fa58b1f1d30eb9cb57ccd"
|
||||
source = "git+https://github.com/servo/rust-azure#53e7b7d07bd43199b136d869b1605016ed882cbc"
|
||||
dependencies = [
|
||||
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
2
ports/gonk/Cargo.lock
generated
2
ports/gonk/Cargo.lock
generated
|
@ -50,7 +50,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
[[package]]
|
||||
name = "azure"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-azure#a6d3af35eafe9a02af3fa58b1f1d30eb9cb57ccd"
|
||||
source = "git+https://github.com/servo/rust-azure#53e7b7d07bd43199b136d869b1605016ed882cbc"
|
||||
dependencies = [
|
||||
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[2d.imageData.get.unaffected.html]
|
||||
type: testharness
|
||||
[getImageData() is not affected by context state]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[2d.imageData.put.clip.html]
|
||||
type: testharness
|
||||
[putImageData() is not affected by clipping regions]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[2d.imageData.put.unaffected.html]
|
||||
type: testharness
|
||||
[putImageData() is not affected by context state]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue