Make Azure backend build again.

This commit is contained in:
Josh Matthews 2019-05-29 16:24:27 -04:00
parent 3539c029f1
commit ce18636aef
3 changed files with 66 additions and 65 deletions

View file

@ -3,16 +3,18 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::canvas_data::{ use crate::canvas_data::{
Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, ExtendMode, Filter,
GenericPathBuilder, Path, Pattern, StrokeOptions, GenericDrawTarget, GenericPathBuilder, GradientStop, GradientStops, Path, Pattern,
SourceSurface, StrokeOptions, SurfaceFormat,
}; };
use crate::canvas_paint_thread::AntialiasMode; 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;
use azure::azure_hl::SurfacePattern; use azure::azure_hl::SurfacePattern;
use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle};
use azure::azure_hl::{BackendType, ColorPattern, DrawTarget}; use azure::azure_hl::{BackendType, ColorPattern, DrawTarget};
use azure::azure_hl::{CapStyle, JoinStyle};
use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern};
use canvas_traits::canvas::*;
use cssparser::RGBA; use cssparser::RGBA;
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
@ -24,7 +26,7 @@ impl Backend for AzureBackend {
} }
fn need_to_draw_shadow(&self, color: &Color) -> bool { 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<f32>, pattern: &Pattern) -> Option<Size2D<f32>> { fn size_from_pattern(&self, rect: &Rect<f32>, pattern: &Pattern) -> Option<Size2D<f32>> {
@ -93,7 +95,7 @@ impl Backend for AzureBackend {
fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> {
CanvasPaintState::new(AntialiasMode::from_azure( 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 surf_options = azure_hl::DrawSurfaceOptions::new(filter.as_azure(), true);
let draw_options = azure_hl::DrawOptions::new( let draw_options = azure_hl::DrawOptions::new(
draw_options.as_azure().alpha, draw_options.as_azure().alpha,
draw_options.as_azure().composition.into_azure(), draw_options.as_azure().composition,
azure_hl::AntialiasMode::None, azure_hl::AntialiasMode::None,
); );
self.draw_surface( self.draw_surface(
surface.into_azure(), surface.into_azure(),
dest as Rect<AzFloat>, dest.to_azure_style(),
source as Rect<AzFloat>, source.to_azure_style(),
surf_options.into_azure(), surf_options,
options.into_azure(), draw_options,
); );
} }
fn draw_surface_with_shadow( fn draw_surface_with_shadow(
@ -356,7 +358,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget {
start, start,
end, end,
pattern.as_azure().to_pattern_ref(), pattern.as_azure().to_pattern_ref(),
stroke_options.as_azure(), &stroke_opts,
draw_options.as_azure(), draw_options.as_azure(),
); );
} }
@ -375,8 +377,14 @@ impl GenericDrawTarget for azure_hl::DrawTarget {
); );
} }
fn snapshot_data(&self) -> &[u8] { #[allow(unsafe_code)]
unsafe { self.snapshot().get_data_surface().data() } fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec<u8>) -> Vec<u8> {
unsafe { f(self.snapshot().get_data_surface().data()) }
}
#[allow(unsafe_code)]
fn snapshot_data_owned(&self) -> Vec<u8> {
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 { match val {
azure_hl::AntialiasMode::Default => AntialiasMode::Default, azure_hl::AntialiasMode::Default => AntialiasMode::Default,
azure_hl::AntialiasMode::None => AntialiasMode::None, 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 { impl Path {
fn as_azure(&self) -> &azure_hl::Path { fn as_azure(&self) -> &azure_hl::Path {
match self { 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 { impl DrawOptions {
fn as_azure(&self) -> &azure_hl::DrawOptions { fn as_azure(&self) -> &azure_hl::DrawOptions {
match self { match self {
@ -495,11 +488,6 @@ impl DrawOptions {
DrawOptions::Azure(options) => options, 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) { pub fn set_alpha(&mut self, val: f32) {
match self { match self {
DrawOptions::Azure(options) => options.alpha = val as AzFloat, DrawOptions::Azure(options) => options.alpha = val as AzFloat,
@ -738,7 +726,7 @@ impl ToAzureStyle for RGBA {
impl Pattern { impl Pattern {
pub fn is_zero_size_gradient(&self) -> bool { pub fn is_zero_size_gradient(&self) -> bool {
match *self { match *self {
Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => { Pattern::Azure(azure_hl::Pattern::LinearGradient(ref gradient)) => {
gradient.is_zero_size() gradient.is_zero_size()
}, },
_ => false, _ => false,
@ -768,6 +756,6 @@ impl Path {
} }
pub fn copy_to_builder(&self) -> Box<GenericPathBuilder> { pub fn copy_to_builder(&self) -> Box<GenericPathBuilder> {
self.as_azure().copy_to_builder() Box::new(self.as_azure().copy_to_builder())
} }
} }

View file

@ -8,6 +8,7 @@ use cssparser::RGBA;
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
#[allow(unused_imports)]
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
@ -274,27 +275,28 @@ pub trait GenericDrawTarget {
stroke_options: &StrokeOptions, stroke_options: &StrokeOptions,
draw_options: &DrawOptions, draw_options: &DrawOptions,
); );
fn snapshot_data(&self) -> Vec<u8>; fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec<u8>) -> Vec<u8>;
fn snapshot_data_owned(&self) -> Vec<u8>;
} }
#[derive(Clone)] #[derive(Clone)]
pub enum ExtendMode { pub enum ExtendMode {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::ExtendMode), Azure(azure::azure_hl::ExtendMode),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
pub enum GradientStop { pub enum GradientStop {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(AzGradientStop), Azure(azure::AzGradientStop),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
pub enum GradientStops { pub enum GradientStops {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::GradientStops), Azure(azure::azure_hl::GradientStops),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -302,7 +304,7 @@ pub enum GradientStops {
#[derive(Clone)] #[derive(Clone)]
pub enum Color { pub enum Color {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::Color), Azure(azure::azure_hl::Color),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -310,14 +312,14 @@ pub enum Color {
#[derive(Clone)] #[derive(Clone)]
pub enum CompositionOp { pub enum CompositionOp {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::CompositionOp), Azure(azure::azure_hl::CompositionOp),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
pub enum SurfaceFormat { pub enum SurfaceFormat {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::SurfaceFormat), Azure(azure::azure_hl::SurfaceFormat),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -325,14 +327,14 @@ pub enum SurfaceFormat {
#[derive(Clone)] #[derive(Clone)]
pub enum SourceSurface { pub enum SourceSurface {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::SourceSurface), Azure(azure::azure_hl::SourceSurface),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
pub enum Path { pub enum Path {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::Path), Azure(azure::azure_hl::Path),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -340,14 +342,14 @@ pub enum Path {
#[derive(Clone)] #[derive(Clone)]
pub enum Pattern { pub enum Pattern {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::Pattern), Azure(azure::azure_hl::Pattern),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
pub enum DrawSurfaceOptions { pub enum DrawSurfaceOptions {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::DrawSurfaceOptions), Azure(azure::azure_hl::DrawSurfaceOptions),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -355,7 +357,7 @@ pub enum DrawSurfaceOptions {
#[derive(Clone)] #[derive(Clone)]
pub enum DrawOptions { pub enum DrawOptions {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::DrawOptions), Azure(azure::azure_hl::DrawOptions),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(()), Raqote(()),
} }
@ -363,7 +365,7 @@ pub enum DrawOptions {
#[derive(Clone)] #[derive(Clone)]
pub enum StrokeOptions<'a> { pub enum StrokeOptions<'a> {
#[cfg(feature = "azure_backend")] #[cfg(feature = "azure_backend")]
Azure(azure_hl::StrokeOptions<'a>), Azure(azure::azure_hl::StrokeOptions<'a>),
#[cfg(feature = "raqote_backend")] #[cfg(feature = "raqote_backend")]
Raqote(PhantomData<&'a ()>), Raqote(PhantomData<&'a ()>),
} }
@ -927,13 +929,14 @@ impl<'a> CanvasData<'a> {
} }
} }
#[allow(unsafe_code)]
pub fn send_pixels(&mut self, chan: IpcSender<IpcSharedMemory>) { pub fn send_pixels(&mut self, chan: IpcSender<IpcSharedMemory>) {
let data = IpcSharedMemory::from_bytes(&self.drawtarget.snapshot_data()); self.drawtarget.snapshot_data(&|bytes| {
let data = IpcSharedMemory::from_bytes(bytes);
chan.send(data).unwrap(); chan.send(data).unwrap();
vec![]
});
} }
#[allow(unsafe_code)]
pub fn send_data(&mut self, chan: IpcSender<CanvasImageData>) { pub fn send_data(&mut self, chan: IpcSender<CanvasImageData>) {
let size = self.drawtarget.get_size(); let size = self.drawtarget.get_size();
@ -945,7 +948,8 @@ impl<'a> CanvasData<'a> {
is_opaque: false, is_opaque: false,
allow_mipmaps: 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(); let mut txn = webrender_api::Transaction::new();
@ -1070,12 +1074,9 @@ impl<'a> CanvasData<'a> {
return vec![]; return vec![];
} }
pixels::rgba8_get_rect( self.drawtarget.snapshot_data(&|bytes| {
&self.drawtarget.snapshot_data(), pixels::rgba8_get_rect(bytes, canvas_size.to_u32(), read_rect.to_u32()).into_owned()
canvas_size.to_u32(), })
read_rect.to_u32(),
)
.into_owned()
} }
} }

View file

@ -59,7 +59,10 @@ impl Backend for RaqoteBackend {
} }
fn create_drawtarget(&self, size: Size2D<u64>) -> Box<GenericDrawTarget> { fn create_drawtarget(&self, size: Size2D<u64>) -> Box<GenericDrawTarget> {
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> { fn recreate_paint_state<'a>(&self, _state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> {
@ -136,7 +139,12 @@ impl GenericDrawTarget for raqote::DrawTarget {
unimplemented!() unimplemented!()
} }
fn copy_surface(&self, _surface: SourceSurface, _source: Rect<i32>, _destination: Point2D<i32>) { fn copy_surface(
&self,
_surface: SourceSurface,
_source: Rect<i32>,
_destination: Point2D<i32>,
) {
unimplemented!() unimplemented!()
} }
@ -244,7 +252,11 @@ impl GenericDrawTarget for raqote::DrawTarget {
unimplemented!() unimplemented!()
} }
fn snapshot_data(&self) -> Vec<u8> { fn snapshot_data(&self, _f: &Fn(&[u8]) -> Vec<u8>) -> Vec<u8> {
unimplemented!()
}
fn snapshot_data_owned(&self) -> Vec<u8> {
unimplemented!() unimplemented!()
} }
} }