diff options
author | Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> | 2023-10-18 10:39:58 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 13:39:58 +0000 |
commit | 2d7dfb06c0f7228ed311de9ba1eb36c871b10c87 (patch) | |
tree | 89e17f03f33b5cdebcbf67403accc6cb23bc2e15 /components/canvas/canvas_data.rs | |
parent | 66258bfbbd240e0de6cddddf72aa00b3ba85e100 (diff) | |
download | servo-2d7dfb06c0f7228ed311de9ba1eb36c871b10c87.tar.gz servo-2d7dfb06c0f7228ed311de9ba1eb36c871b10c87.zip |
Use `IpcSharedMemory` for `Canvas2dMsg::DrawImage` (#30544)
* Use `IpcSharedMemory` for `Canvas2DMsg::DrawImage`
* Fix `Canvas2dMsg::DrawEmptyImage` crashes
* Do not premultiply canvas image data
* Move `image_data` back to its original position
Diffstat (limited to 'components/canvas/canvas_data.rs')
-rw-r--r-- | components/canvas/canvas_data.rs | 13 |
1 files changed, 11 insertions, 2 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 |