mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Make Azure backend build again.
This commit is contained in:
parent
3539c029f1
commit
ce18636aef
3 changed files with 66 additions and 65 deletions
|
@ -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<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> {
|
||||
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<AzFloat>,
|
||||
source as Rect<AzFloat>,
|
||||
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<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 {
|
||||
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<GenericPathBuilder> {
|
||||
self.as_azure().copy_to_builder()
|
||||
Box::new(self.as_azure().copy_to_builder())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<u8>;
|
||||
fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec<u8>) -> Vec<u8>;
|
||||
fn snapshot_data_owned(&self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
#[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<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();
|
||||
vec![]
|
||||
});
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn send_data(&mut self, chan: IpcSender<CanvasImageData>) {
|
||||
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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,10 @@ impl Backend for RaqoteBackend {
|
|||
}
|
||||
|
||||
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> {
|
||||
|
@ -136,7 +139,12 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
|||
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!()
|
||||
}
|
||||
|
||||
|
@ -244,7 +252,11 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
|||
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!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue