diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2018-03-23 18:41:32 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2018-03-26 20:48:02 +0200 |
commit | ce81420befd0fd0e8335cb676487479e2cc0f985 (patch) | |
tree | 4d883ab322c58496073f43d29c737e35ca23871a /components/canvas/canvas_paint_thread.rs | |
parent | 3ce3f39383c8217a30b15d27f3121f96bbe0014d (diff) | |
download | servo-ce81420befd0fd0e8335cb676487479e2cc0f985.tar.gz servo-ce81420befd0fd0e8335cb676487479e2cc0f985.zip |
Use ByteBuf for the canvas messages
The type Vec<u8> is super unefficient to work with in Serde if all you want
to represent is a simple blob.
Diffstat (limited to 'components/canvas/canvas_paint_thread.rs')
-rw-r--r-- | components/canvas/canvas_paint_thread.rs | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index b3e6093f6f0..d464f6488e5 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -13,6 +13,7 @@ use cssparser::RGBA; use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D}; use ipc_channel::ipc::{self, IpcSender}; use num_traits::ToPrimitive; +use serde_bytes::ByteBuf; use std::borrow::ToOwned; use std::mem; use std::sync::Arc; @@ -145,9 +146,20 @@ impl<'a> CanvasPaintThread<'a> { Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => { painter.is_point_in_path(x, y, fill_rule, chan) }, - Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect, - smoothing_enabled) => { - painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled) + Canvas2dMsg::DrawImage( + imagedata, + image_size, + dest_rect, + source_rect, + smoothing_enabled, + ) => { + painter.draw_image( + imagedata.into(), + image_size, + dest_rect, + source_rect, + smoothing_enabled, + ) } Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled) => { painter.draw_image_self(image_size, dest_rect, source_rect, smoothing_enabled) @@ -189,8 +201,19 @@ impl<'a> CanvasPaintThread<'a> { Canvas2dMsg::SetGlobalComposition(op) => painter.set_global_composition(op), Canvas2dMsg::GetImageData(dest_rect, canvas_size, chan) => painter.image_data(dest_rect, canvas_size, chan), - Canvas2dMsg::PutImageData(imagedata, offset, image_data_size, dirty_rect) - => painter.put_image_data(imagedata, offset, image_data_size, dirty_rect), + Canvas2dMsg::PutImageData( + imagedata, + offset, + image_data_size, + dirty_rect, + ) => { + painter.put_image_data( + imagedata.into(), + 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), @@ -402,7 +425,12 @@ impl<'a> CanvasPaintThread<'a> { byte_swap(&mut image_data); let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage( - image_data, source_rect.size, dest_rect, source_rect, smoothing_enabled)); + image_data.into(), + source_rect.size, + dest_rect, + source_rect, + smoothing_enabled, + )); renderer.send(msg).unwrap(); // We acknowledge to the caller here that the data was sent to the // other canvas so that if JS immediately afterwards try to get the @@ -578,9 +606,9 @@ impl<'a> CanvasPaintThread<'a> { } } - fn send_pixels(&mut self, chan: IpcSender<Option<Vec<u8>>>) { + fn send_pixels(&mut self, chan: IpcSender<Option<ByteBuf>>) { self.drawtarget.snapshot().get_data_surface().with_data(|element| { - chan.send(Some(element.into())).unwrap(); + chan.send(Some(Vec::from(element).into())).unwrap(); }) } @@ -632,12 +660,17 @@ impl<'a> CanvasPaintThread<'a> { }) } - fn image_data(&self, dest_rect: Rect<i32>, canvas_size: Size2D<f64>, chan: IpcSender<Vec<u8>>) { + fn image_data( + &self, + dest_rect: Rect<i32>, + canvas_size: Size2D<f64>, + chan: IpcSender<ByteBuf>, + ) { let mut dest_data = self.read_pixels(dest_rect, canvas_size); // bgra -> rgba byte_swap(&mut dest_data); - chan.send(dest_data).unwrap(); + chan.send(dest_data.into()).unwrap(); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata |