mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Respect the composition op when drawing images
This commit is contained in:
parent
315c4f5ed7
commit
1d02239804
14 changed files with 14 additions and 72 deletions
|
@ -381,11 +381,13 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
|
|
||||||
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
|
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
|
||||||
write_image(&new_draw_target, image_data, source_rect.size, dest_rect,
|
write_image(&new_draw_target, image_data, source_rect.size, dest_rect,
|
||||||
smoothing_enabled, self.state.draw_options.alpha);
|
smoothing_enabled, self.state.draw_options.composition,
|
||||||
|
self.state.draw_options.alpha);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
write_image(&self.drawtarget, image_data, source_rect.size, dest_rect,
|
write_image(&self.drawtarget, image_data, source_rect.size, dest_rect,
|
||||||
smoothing_enabled, self.state.draw_options.alpha);
|
smoothing_enabled, self.state.draw_options.composition,
|
||||||
|
self.state.draw_options.alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,12 +404,14 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
|
|
||||||
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
|
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
|
||||||
write_image(&new_draw_target, image_data, source_rect.size, dest_rect,
|
write_image(&new_draw_target, image_data, source_rect.size, dest_rect,
|
||||||
smoothing_enabled, self.state.draw_options.alpha);
|
smoothing_enabled, self.state.draw_options.composition,
|
||||||
|
self.state.draw_options.alpha);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Writes on target canvas
|
// Writes on target canvas
|
||||||
write_image(&self.drawtarget, image_data, image_size, dest_rect,
|
write_image(&self.drawtarget, image_data, image_size, dest_rect,
|
||||||
smoothing_enabled, self.state.draw_options.alpha);
|
smoothing_enabled, self.state.draw_options.composition,
|
||||||
|
self.state.draw_options.alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,7 +635,7 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
Size2D::new(source_rect.size.width, source_rect.size.height));
|
Size2D::new(source_rect.size.width, source_rect.size.height));
|
||||||
|
|
||||||
write_pixels(&self.drawtarget, &imagedata, image_data_rect.size, source_rect,
|
write_pixels(&self.drawtarget, &imagedata, image_data_rect.size, source_rect,
|
||||||
dest_rect, true, self.state.draw_options.alpha)
|
dest_rect, true, self.state.draw_options.composition, self.state.draw_options.alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_shadow_offset_x(&mut self, value: f64) {
|
fn set_shadow_offset_x(&mut self, value: f64) {
|
||||||
|
@ -728,6 +732,7 @@ fn write_image(draw_target: &DrawTarget,
|
||||||
image_size: Size2D<f64>,
|
image_size: Size2D<f64>,
|
||||||
dest_rect: Rect<f64>,
|
dest_rect: Rect<f64>,
|
||||||
smoothing_enabled: bool,
|
smoothing_enabled: bool,
|
||||||
|
composition_op: CompositionOp,
|
||||||
global_alpha: f32) {
|
global_alpha: f32) {
|
||||||
if image_data.len() == 0 {
|
if image_data.len() == 0 {
|
||||||
return
|
return
|
||||||
|
@ -735,7 +740,8 @@ fn write_image(draw_target: &DrawTarget,
|
||||||
let image_rect = Rect::new(Point2D::zero(), image_size);
|
let image_rect = Rect::new(Point2D::zero(), image_size);
|
||||||
// rgba -> bgra
|
// rgba -> bgra
|
||||||
byte_swap(&mut image_data);
|
byte_swap(&mut image_data);
|
||||||
write_pixels(&draw_target, &image_data, image_size, image_rect, dest_rect, smoothing_enabled, global_alpha);
|
write_pixels(&draw_target, &image_data, image_size, image_rect,
|
||||||
|
dest_rect, smoothing_enabled, composition_op, global_alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// It writes image data to the target
|
/// It writes image data to the target
|
||||||
|
@ -749,6 +755,7 @@ fn write_pixels(draw_target: &DrawTarget,
|
||||||
source_rect: Rect<f64>,
|
source_rect: Rect<f64>,
|
||||||
dest_rect: Rect<f64>,
|
dest_rect: Rect<f64>,
|
||||||
smoothing_enabled: bool,
|
smoothing_enabled: bool,
|
||||||
|
composition_op: CompositionOp,
|
||||||
global_alpha: f32) {
|
global_alpha: f32) {
|
||||||
// From spec https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
// From spec https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
||||||
// When scaling up, if the imageSmoothingEnabled attribute is set to true, the user agent should attempt
|
// When scaling up, if the imageSmoothingEnabled attribute is set to true, the user agent should attempt
|
||||||
|
@ -767,7 +774,7 @@ fn write_pixels(draw_target: &DrawTarget,
|
||||||
image_size, image_size.width * 4, SurfaceFormat::B8G8R8A8);
|
image_size, image_size.width * 4, SurfaceFormat::B8G8R8A8);
|
||||||
|
|
||||||
let draw_surface_options = DrawSurfaceOptions::new(filter, true);
|
let draw_surface_options = DrawSurfaceOptions::new(filter, true);
|
||||||
let draw_options = DrawOptions::new(global_alpha, CompositionOp::Over, AntialiasMode::None);
|
let draw_options = DrawOptions::new(global_alpha, composition_op, AntialiasMode::None);
|
||||||
|
|
||||||
draw_target.draw_surface(source_surface,
|
draw_target.draw_surface(source_surface,
|
||||||
dest_rect.to_azfloat(),
|
dest_rect.to_azfloat(),
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.canvas.lighter.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.composite.canvas.lighter]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.image.lighter.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.composite.image.lighter]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.image.copy.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() draws pixels not covered by the source object as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.image.destination-atop.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() draws pixels not covered by the source object as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.image.destination-in.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() draws pixels not covered by the source object as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.image.source-in.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() draws pixels not covered by the source object as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.image.source-out.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() draws pixels not covered by the source object as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.nocontext.copy.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() of a canvas with no context draws pixels as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.nocontext.destination-atop.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() of a canvas with no context draws pixels as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.nocontext.destination-in.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() of a canvas with no context draws pixels as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.nocontext.source-in.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() of a canvas with no context draws pixels as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.uncovered.nocontext.source-out.html]
|
|
||||||
type: testharness
|
|
||||||
[drawImage() of a canvas with no context draws pixels as (0,0,0,0), and does not leave the pixels unchanged.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.drawImage.composite.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.drawImage.composite]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue