aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas
diff options
context:
space:
mode:
Diffstat (limited to 'components/canvas')
-rw-r--r--components/canvas/canvas_data.rs13
-rw-r--r--components/canvas/canvas_paint_thread.rs24
2 files changed, 26 insertions, 11 deletions
diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs
index 778851524ba..38d84f2d00c 100644
--- a/components/canvas/canvas_data.rs
+++ b/components/canvas/canvas_data.rs
@@ -446,11 +446,12 @@ impl<'a> CanvasData<'a> {
pub fn draw_image(
&mut self,
- image_data: Vec<u8>,
+ image_data: &[u8],
image_size: Size2D<f64>,
dest_rect: Rect<f64>,
source_rect: Rect<f64>,
smoothing_enabled: bool,
+ premultiply: bool,
) {
// We round up the floating pixel values to draw the pixels
let source_rect = source_rect.ceil();
@@ -469,6 +470,7 @@ impl<'a> CanvasData<'a> {
source_rect.size,
dest_rect,
smoothing_enabled,
+ premultiply,
&draw_options,
);
};
@@ -1306,17 +1308,24 @@ pub struct CanvasPaintState<'a> {
/// image_size: The size of the image to be written
/// dest_rect: Area of the destination target where the pixels will be copied
/// smoothing_enabled: It determines if smoothing is applied to the image result
+/// premultiply: Determines whenever the image data should be premultiplied or not
fn write_image(
draw_target: &mut dyn GenericDrawTarget,
- image_data: Vec<u8>,
+ mut image_data: Vec<u8>,
image_size: Size2D<f64>,
dest_rect: Rect<f64>,
smoothing_enabled: bool,
+ premultiply: bool,
draw_options: &DrawOptions,
) {
if image_data.is_empty() {
return;
}
+
+ if premultiply {
+ pixels::rgba8_premultiply_inplace(&mut image_data);
+ }
+
let image_rect = Rect::new(Point2D::zero(), image_size);
// From spec https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs
index 7234aaed4ab..808714b14e8 100644
--- a/components/canvas/canvas_paint_thread.rs
+++ b/components/canvas/canvas_paint_thread.rs
@@ -175,22 +175,27 @@ impl<'a> CanvasPaintThread<'a> {
.canvas(canvas_id)
.is_point_in_path(x, y, fill_rule, chan),
Canvas2dMsg::DrawImage(
- imagedata,
+ ref image_data,
image_size,
dest_rect,
source_rect,
smoothing_enabled,
- ) => {
- let data = imagedata.map_or_else(
- || vec![0; image_size.width as usize * image_size.height as usize * 4],
- |bytes| bytes.into_vec(),
- );
+ ) => self.canvas(canvas_id).draw_image(
+ &*image_data,
+ image_size,
+ dest_rect,
+ source_rect,
+ smoothing_enabled,
+ true,
+ ),
+ Canvas2dMsg::DrawEmptyImage(image_size, dest_rect, source_rect) => {
self.canvas(canvas_id).draw_image(
- data,
+ &vec![0; image_size.area() as usize * 4],
image_size,
dest_rect,
source_rect,
- smoothing_enabled,
+ false,
+ false,
)
},
Canvas2dMsg::DrawImageInOther(
@@ -204,11 +209,12 @@ impl<'a> CanvasPaintThread<'a> {
.canvas(canvas_id)
.read_pixels(source_rect.to_u64(), image_size.to_u64());
self.canvas(other_canvas_id).draw_image(
- image_data.into(),
+ &image_data,
source_rect.size,
dest_rect,
source_rect,
smoothing,
+ false,
);
},
Canvas2dMsg::MoveTo(ref point) => self.canvas(canvas_id).move_to(point),