diff --git a/components/canvas/azure_backend.rs b/components/canvas/azure_backend.rs index a99429e7769..037809b5a05 100644 --- a/components/canvas/azure_backend.rs +++ b/components/canvas/azure_backend.rs @@ -3,16 +3,18 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::canvas_data::{ - Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, - GenericPathBuilder, Path, Pattern, StrokeOptions, + Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, ExtendMode, Filter, + GenericDrawTarget, GenericPathBuilder, GradientStop, GradientStops, Path, Pattern, + SourceSurface, StrokeOptions, SurfaceFormat, }; use crate::canvas_paint_thread::AntialiasMode; -use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint}; +use azure::azure::{AzFloat, AzGradientStop, AzPoint}; use azure::azure_hl; use azure::azure_hl::SurfacePattern; -use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle}; use azure::azure_hl::{BackendType, ColorPattern, DrawTarget}; +use azure::azure_hl::{CapStyle, JoinStyle}; use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; +use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; @@ -24,7 +26,7 @@ impl Backend for AzureBackend { } fn need_to_draw_shadow(&self, color: &Color) -> bool { - self.state.shadow_color.as_azure().a != 0.0f32 + color.as_azure().a != 0.0f32 } fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option> { @@ -93,7 +95,7 @@ impl Backend for AzureBackend { fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { CanvasPaintState::new(AntialiasMode::from_azure( - self.state.draw_options.as_azure().antialias, + state.draw_options.as_azure().antialias, )) } } @@ -251,15 +253,15 @@ impl GenericDrawTarget for azure_hl::DrawTarget { let surf_options = azure_hl::DrawSurfaceOptions::new(filter.as_azure(), true); let draw_options = azure_hl::DrawOptions::new( draw_options.as_azure().alpha, - draw_options.as_azure().composition.into_azure(), + draw_options.as_azure().composition, azure_hl::AntialiasMode::None, ); self.draw_surface( surface.into_azure(), - dest as Rect, - source as Rect, - surf_options.into_azure(), - options.into_azure(), + dest.to_azure_style(), + source.to_azure_style(), + surf_options, + draw_options, ); } fn draw_surface_with_shadow( @@ -356,7 +358,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { start, end, pattern.as_azure().to_pattern_ref(), - stroke_options.as_azure(), + &stroke_opts, draw_options.as_azure(), ); } @@ -375,8 +377,14 @@ impl GenericDrawTarget for azure_hl::DrawTarget { ); } - fn snapshot_data(&self) -> &[u8] { - unsafe { self.snapshot().get_data_surface().data() } + #[allow(unsafe_code)] + fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec) -> Vec { + unsafe { f(self.snapshot().get_data_surface().data()) } + } + + #[allow(unsafe_code)] + fn snapshot_data_owned(&self) -> Vec { + unsafe { self.snapshot().get_data_surface().data().into() } } } @@ -388,10 +396,11 @@ impl AntialiasMode { } } - fn from_azure(val: azure_hl::AntialiasMode) { + fn from_azure(val: azure_hl::AntialiasMode) -> AntialiasMode { match val { azure_hl::AntialiasMode::Default => AntialiasMode::Default, azure_hl::AntialiasMode::None => AntialiasMode::None, + v => unimplemented!("{:?} is unsupported", v), } } } @@ -452,14 +461,6 @@ impl SourceSurface { } } -impl IntSize { - fn into_azure(self) -> AzIntSize { - match self { - IntSize::Azure(s) => s, - } - } -} - impl Path { fn as_azure(&self) -> &azure_hl::Path { match self { @@ -476,14 +477,6 @@ impl Pattern { } } -impl DrawSurfaceOptions { - fn into_azure(self) -> azure_hl::DrawSurfaceOptions { - match self { - DrawSurfaceOptions::Azure(options) => options, - } - } -} - impl DrawOptions { fn as_azure(&self) -> &azure_hl::DrawOptions { match self { @@ -495,11 +488,6 @@ impl DrawOptions { DrawOptions::Azure(options) => options, } } - fn into_azure(self) -> azure_hl::DrawOptions { - match self { - DrawOptions::Azure(options) => options, - } - } pub fn set_alpha(&mut self, val: f32) { match self { DrawOptions::Azure(options) => options.alpha = val as AzFloat, @@ -738,7 +726,7 @@ impl ToAzureStyle for RGBA { impl Pattern { pub fn is_zero_size_gradient(&self) -> bool { match *self { - Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => { + Pattern::Azure(azure_hl::Pattern::LinearGradient(ref gradient)) => { gradient.is_zero_size() }, _ => false, @@ -768,6 +756,6 @@ impl Path { } pub fn copy_to_builder(&self) -> Box { - self.as_azure().copy_to_builder() + Box::new(self.as_azure().copy_to_builder()) } } diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 7792e9ed902..6b65f75117a 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -8,6 +8,7 @@ use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; use num_traits::ToPrimitive; +#[allow(unused_imports)] use std::marker::PhantomData; use std::mem; use std::sync::Arc; @@ -274,27 +275,28 @@ pub trait GenericDrawTarget { stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); - fn snapshot_data(&self) -> Vec; + fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec) -> Vec; + fn snapshot_data_owned(&self) -> Vec; } #[derive(Clone)] pub enum ExtendMode { #[cfg(feature = "azure_backend")] - Azure(azure_hl::ExtendMode), + Azure(azure::azure_hl::ExtendMode), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum GradientStop { #[cfg(feature = "azure_backend")] - Azure(AzGradientStop), + Azure(azure::AzGradientStop), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum GradientStops { #[cfg(feature = "azure_backend")] - Azure(azure_hl::GradientStops), + Azure(azure::azure_hl::GradientStops), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -302,7 +304,7 @@ pub enum GradientStops { #[derive(Clone)] pub enum Color { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Color), + Azure(azure::azure_hl::Color), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -310,14 +312,14 @@ pub enum Color { #[derive(Clone)] pub enum CompositionOp { #[cfg(feature = "azure_backend")] - Azure(azure_hl::CompositionOp), + Azure(azure::azure_hl::CompositionOp), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum SurfaceFormat { #[cfg(feature = "azure_backend")] - Azure(azure_hl::SurfaceFormat), + Azure(azure::azure_hl::SurfaceFormat), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -325,14 +327,14 @@ pub enum SurfaceFormat { #[derive(Clone)] pub enum SourceSurface { #[cfg(feature = "azure_backend")] - Azure(azure_hl::SourceSurface), + Azure(azure::azure_hl::SourceSurface), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum Path { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Path), + Azure(azure::azure_hl::Path), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -340,14 +342,14 @@ pub enum Path { #[derive(Clone)] pub enum Pattern { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Pattern), + Azure(azure::azure_hl::Pattern), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum DrawSurfaceOptions { #[cfg(feature = "azure_backend")] - Azure(azure_hl::DrawSurfaceOptions), + Azure(azure::azure_hl::DrawSurfaceOptions), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -355,7 +357,7 @@ pub enum DrawSurfaceOptions { #[derive(Clone)] pub enum DrawOptions { #[cfg(feature = "azure_backend")] - Azure(azure_hl::DrawOptions), + Azure(azure::azure_hl::DrawOptions), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -363,7 +365,7 @@ pub enum DrawOptions { #[derive(Clone)] pub enum StrokeOptions<'a> { #[cfg(feature = "azure_backend")] - Azure(azure_hl::StrokeOptions<'a>), + Azure(azure::azure_hl::StrokeOptions<'a>), #[cfg(feature = "raqote_backend")] Raqote(PhantomData<&'a ()>), } @@ -927,13 +929,14 @@ impl<'a> CanvasData<'a> { } } - #[allow(unsafe_code)] pub fn send_pixels(&mut self, chan: IpcSender) { - let data = IpcSharedMemory::from_bytes(&self.drawtarget.snapshot_data()); - chan.send(data).unwrap(); + self.drawtarget.snapshot_data(&|bytes| { + let data = IpcSharedMemory::from_bytes(bytes); + chan.send(data).unwrap(); + vec![] + }); } - #[allow(unsafe_code)] pub fn send_data(&mut self, chan: IpcSender) { let size = self.drawtarget.get_size(); @@ -945,7 +948,8 @@ impl<'a> CanvasData<'a> { is_opaque: false, allow_mipmaps: false, }; - let data = webrender_api::ImageData::Raw(Arc::new(self.drawtarget.snapshot_data().into())); + let data = self.drawtarget.snapshot_data_owned(); + let data = webrender_api::ImageData::Raw(Arc::new(data)); let mut txn = webrender_api::Transaction::new(); @@ -1070,12 +1074,9 @@ impl<'a> CanvasData<'a> { return vec![]; } - pixels::rgba8_get_rect( - &self.drawtarget.snapshot_data(), - canvas_size.to_u32(), - read_rect.to_u32(), - ) - .into_owned() + self.drawtarget.snapshot_data(&|bytes| { + pixels::rgba8_get_rect(bytes, canvas_size.to_u32(), read_rect.to_u32()).into_owned() + }) } } diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 79a09ac29da..6e49026606e 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -59,7 +59,10 @@ impl Backend for RaqoteBackend { } fn create_drawtarget(&self, size: Size2D) -> Box { - Box::new(raqote::DrawTarget::new(size.width as i32, size.height as i32)) + Box::new(raqote::DrawTarget::new( + size.width as i32, + size.height as i32, + )) } fn recreate_paint_state<'a>(&self, _state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { @@ -136,7 +139,12 @@ impl GenericDrawTarget for raqote::DrawTarget { unimplemented!() } - fn copy_surface(&self, _surface: SourceSurface, _source: Rect, _destination: Point2D) { + fn copy_surface( + &self, + _surface: SourceSurface, + _source: Rect, + _destination: Point2D, + ) { unimplemented!() } @@ -244,7 +252,11 @@ impl GenericDrawTarget for raqote::DrawTarget { unimplemented!() } - fn snapshot_data(&self) -> Vec { + fn snapshot_data(&self, _f: &Fn(&[u8]) -> Vec) -> Vec { + unimplemented!() + } + + fn snapshot_data_owned(&self) -> Vec { unimplemented!() } }