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
This commit is contained in:
Ennui Langeweile 2023-10-18 10:39:58 -03:00 committed by GitHub
parent 66258bfbbd
commit 2d7dfb06c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 25 deletions

View file

@ -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