mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Remove azure(canvas) dependency from canvas_traits
This commit is contained in:
parent
61d8f4d688
commit
912d5f3547
6 changed files with 163 additions and 145 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -257,6 +257,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"azure 0.9.2 (git+https://github.com/servo/rust-azure)",
|
||||
"canvas_traits 0.0.1",
|
||||
"cssparser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gleam 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -272,7 +273,6 @@ dependencies = [
|
|||
name = "canvas_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"azure 0.9.2 (git+https://github.com/servo/rust-azure)",
|
||||
"cssparser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -12,6 +12,7 @@ path = "lib.rs"
|
|||
[dependencies]
|
||||
azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
|
||||
canvas_traits = {path = "../canvas_traits"}
|
||||
cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]}
|
||||
euclid = "0.10.1"
|
||||
gleam = "0.2.8"
|
||||
ipc-channel = "0.5"
|
||||
|
|
|
@ -6,7 +6,10 @@ use azure::azure::AzFloat;
|
|||
use azure::azure_hl::{AntialiasMode, CapStyle, CompositionOp, JoinStyle};
|
||||
use azure::azure_hl::{BackendType, DrawOptions, DrawTarget, Pattern, StrokeOptions, SurfaceFormat};
|
||||
use azure::azure_hl::{Color, ColorPattern, DrawSurfaceOptions, Filter, PathBuilder};
|
||||
use azure::azure_hl::{ExtendMode, GradientStop, LinearGradientPattern, RadialGradientPattern};
|
||||
use azure::azure_hl::SurfacePattern;
|
||||
use canvas_traits::*;
|
||||
use cssparser::RGBA;
|
||||
use euclid::matrix2d::Matrix2D;
|
||||
use euclid::point::Point2D;
|
||||
use euclid::rect::Rect;
|
||||
|
@ -185,7 +188,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
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),
|
||||
Canvas2dMsg::SetShadowColor(ref color) => painter.set_shadow_color(color.to_azcolor()),
|
||||
Canvas2dMsg::SetShadowColor(ref color) => painter.set_shadow_color(color.to_azure_style()),
|
||||
}
|
||||
},
|
||||
CanvasMsg::Common(message) => {
|
||||
|
@ -794,8 +797,8 @@ fn write_image(draw_target: &DrawTarget,
|
|||
let draw_options = DrawOptions::new(global_alpha, composition_op, AntialiasMode::None);
|
||||
|
||||
draw_target.draw_surface(source_surface,
|
||||
dest_rect.to_azfloat(),
|
||||
image_rect.to_azfloat(),
|
||||
dest_rect.to_azure_style(),
|
||||
image_rect.to_azure_style(),
|
||||
draw_surface_options,
|
||||
draw_options);
|
||||
}
|
||||
|
@ -854,13 +857,163 @@ impl RectToi32 for Rect<f64> {
|
|||
|
||||
}
|
||||
|
||||
pub trait ToAzFloat {
|
||||
fn to_azfloat(&self) -> Rect<AzFloat>;
|
||||
pub trait ToAzureStyle {
|
||||
type Target;
|
||||
fn to_azure_style(self) -> Self::Target;
|
||||
}
|
||||
|
||||
impl ToAzFloat for Rect<f64> {
|
||||
fn to_azfloat(&self) -> Rect<AzFloat> {
|
||||
impl ToAzureStyle for Rect<f64> {
|
||||
type Target = Rect<AzFloat>;
|
||||
|
||||
fn to_azure_style(self) -> Rect<AzFloat> {
|
||||
Rect::new(Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat),
|
||||
Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ToAzureStyle for LineCapStyle {
|
||||
type Target = CapStyle;
|
||||
|
||||
fn to_azure_style(self) -> CapStyle {
|
||||
match self {
|
||||
LineCapStyle::Butt => CapStyle::Butt,
|
||||
LineCapStyle::Round => CapStyle::Round,
|
||||
LineCapStyle::Square => CapStyle::Square,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAzureStyle for LineJoinStyle {
|
||||
type Target = JoinStyle;
|
||||
|
||||
fn to_azure_style(self) -> JoinStyle {
|
||||
match self {
|
||||
LineJoinStyle::Round => JoinStyle::Round,
|
||||
LineJoinStyle::Bevel => JoinStyle::Bevel,
|
||||
LineJoinStyle::Miter => JoinStyle::Miter,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAzureStyle for CompositionStyle {
|
||||
type Target = CompositionOp;
|
||||
|
||||
fn to_azure_style(self) -> CompositionOp {
|
||||
match self {
|
||||
CompositionStyle::SrcIn => CompositionOp::In,
|
||||
CompositionStyle::SrcOut => CompositionOp::Out,
|
||||
CompositionStyle::SrcOver => CompositionOp::Over,
|
||||
CompositionStyle::SrcAtop => CompositionOp::Atop,
|
||||
CompositionStyle::DestIn => CompositionOp::DestIn,
|
||||
CompositionStyle::DestOut => CompositionOp::DestOut,
|
||||
CompositionStyle::DestOver => CompositionOp::DestOver,
|
||||
CompositionStyle::DestAtop => CompositionOp::DestAtop,
|
||||
CompositionStyle::Copy => CompositionOp::Source,
|
||||
CompositionStyle::Lighter => CompositionOp::Add,
|
||||
CompositionStyle::Xor => CompositionOp::Xor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAzureStyle for BlendingStyle {
|
||||
type Target = CompositionOp;
|
||||
|
||||
fn to_azure_style(self) -> CompositionOp {
|
||||
match self {
|
||||
BlendingStyle::Multiply => CompositionOp::Multiply,
|
||||
BlendingStyle::Screen => CompositionOp::Screen,
|
||||
BlendingStyle::Overlay => CompositionOp::Overlay,
|
||||
BlendingStyle::Darken => CompositionOp::Darken,
|
||||
BlendingStyle::Lighten => CompositionOp::Lighten,
|
||||
BlendingStyle::ColorDodge => CompositionOp::ColorDodge,
|
||||
BlendingStyle::ColorBurn => CompositionOp::ColorBurn,
|
||||
BlendingStyle::HardLight => CompositionOp::HardLight,
|
||||
BlendingStyle::SoftLight => CompositionOp::SoftLight,
|
||||
BlendingStyle::Difference => CompositionOp::Difference,
|
||||
BlendingStyle::Exclusion => CompositionOp::Exclusion,
|
||||
BlendingStyle::Hue => CompositionOp::Hue,
|
||||
BlendingStyle::Saturation => CompositionOp::Saturation,
|
||||
BlendingStyle::Color => CompositionOp::Color,
|
||||
BlendingStyle::Luminosity => CompositionOp::Luminosity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAzureStyle for CompositionOrBlending {
|
||||
type Target = CompositionOp;
|
||||
|
||||
fn to_azure_style(self) -> CompositionOp {
|
||||
match self {
|
||||
CompositionOrBlending::Composition(op) => op.to_azure_style(),
|
||||
CompositionOrBlending::Blending(op) => op.to_azure_style(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToAzurePattern {
|
||||
fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option<Pattern>;
|
||||
}
|
||||
|
||||
impl ToAzurePattern for FillOrStrokeStyle {
|
||||
fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option<Pattern> {
|
||||
match *self {
|
||||
FillOrStrokeStyle::Color(ref color) => {
|
||||
Some(Pattern::Color(ColorPattern::new(color.to_azure_style())))
|
||||
},
|
||||
FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azure_style()
|
||||
}
|
||||
}).collect();
|
||||
|
||||
Some(Pattern::LinearGradient(LinearGradientPattern::new(
|
||||
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Matrix2D::identity())))
|
||||
},
|
||||
FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azure_style()
|
||||
}
|
||||
}).collect();
|
||||
|
||||
Some(Pattern::RadialGradient(RadialGradientPattern::new(
|
||||
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
|
||||
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Matrix2D::identity())))
|
||||
},
|
||||
FillOrStrokeStyle::Surface(ref surface_style) => {
|
||||
drawtarget.create_source_surface_from_data(&surface_style.surface_data,
|
||||
surface_style.surface_size,
|
||||
surface_style.surface_size.width * 4,
|
||||
SurfaceFormat::B8G8R8A8)
|
||||
.map(|source_surface| {
|
||||
Pattern::Surface(SurfacePattern::new(
|
||||
source_surface.azure_source_surface,
|
||||
surface_style.repeat_x,
|
||||
surface_style.repeat_y,
|
||||
&Matrix2D::identity()))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAzureStyle for RGBA {
|
||||
type Target = Color;
|
||||
|
||||
fn to_azure_style(self) -> Color {
|
||||
Color::rgba(self.red as AzFloat,
|
||||
self.green as AzFloat,
|
||||
self.blue as AzFloat,
|
||||
self.alpha as AzFloat)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
extern crate azure;
|
||||
extern crate canvas_traits;
|
||||
extern crate core;
|
||||
extern crate cssparser;
|
||||
extern crate euclid;
|
||||
extern crate gleam;
|
||||
extern crate ipc_channel;
|
||||
|
|
|
@ -10,7 +10,6 @@ name = "canvas_traits"
|
|||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
|
||||
cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]}
|
||||
euclid = "0.10.1"
|
||||
heapsize = "0.3.0"
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#![deny(unsafe_code)]
|
||||
|
||||
extern crate azure;
|
||||
extern crate core;
|
||||
extern crate cssparser;
|
||||
extern crate euclid;
|
||||
|
@ -21,11 +20,6 @@ extern crate serde;
|
|||
#[macro_use] extern crate serde_derive;
|
||||
extern crate webrender_traits;
|
||||
|
||||
use azure::azure::AzFloat;
|
||||
use azure::azure_hl::{CapStyle, CompositionOp, JoinStyle};
|
||||
use azure::azure_hl::{Color, ColorPattern, DrawTarget, Pattern};
|
||||
use azure::azure_hl::{ExtendMode, GradientStop, LinearGradientPattern, RadialGradientPattern};
|
||||
use azure::azure_hl::{SurfaceFormat, SurfacePattern};
|
||||
use cssparser::RGBA;
|
||||
use euclid::matrix2d::Matrix2D;
|
||||
use euclid::point::Point2D;
|
||||
|
@ -202,58 +196,6 @@ pub enum FillOrStrokeStyle {
|
|||
Surface(SurfaceStyle),
|
||||
}
|
||||
|
||||
impl FillOrStrokeStyle {
|
||||
pub fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option<Pattern> {
|
||||
match *self {
|
||||
FillOrStrokeStyle::Color(ref color) => {
|
||||
Some(Pattern::Color(ColorPattern::new(color.to_azcolor())))
|
||||
},
|
||||
FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azcolor()
|
||||
}
|
||||
}).collect();
|
||||
|
||||
Some(Pattern::LinearGradient(LinearGradientPattern::new(
|
||||
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Matrix2D::identity())))
|
||||
},
|
||||
FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azcolor()
|
||||
}
|
||||
}).collect();
|
||||
|
||||
Some(Pattern::RadialGradient(RadialGradientPattern::new(
|
||||
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
|
||||
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Matrix2D::identity())))
|
||||
},
|
||||
FillOrStrokeStyle::Surface(ref surface_style) => {
|
||||
drawtarget.create_source_surface_from_data(&surface_style.surface_data,
|
||||
surface_style.surface_size,
|
||||
surface_style.surface_size.width * 4,
|
||||
SurfaceFormat::B8G8R8A8)
|
||||
.map(|source_surface| {
|
||||
Pattern::Surface(SurfacePattern::new(
|
||||
source_surface.azure_source_surface,
|
||||
surface_style.repeat_x,
|
||||
surface_style.repeat_y,
|
||||
&Matrix2D::identity()))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Deserialize, Serialize, HeapSizeOf)]
|
||||
pub enum LineCapStyle {
|
||||
Butt = 0,
|
||||
|
@ -274,16 +216,6 @@ impl FromStr for LineCapStyle {
|
|||
}
|
||||
}
|
||||
|
||||
impl LineCapStyle {
|
||||
pub fn to_azure_style(&self) -> CapStyle {
|
||||
match *self {
|
||||
LineCapStyle::Butt => CapStyle::Butt,
|
||||
LineCapStyle::Round => CapStyle::Round,
|
||||
LineCapStyle::Square => CapStyle::Square,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Deserialize, Serialize, HeapSizeOf)]
|
||||
pub enum LineJoinStyle {
|
||||
Round = 0,
|
||||
|
@ -304,16 +236,6 @@ impl FromStr for LineJoinStyle {
|
|||
}
|
||||
}
|
||||
|
||||
impl LineJoinStyle {
|
||||
pub fn to_azure_style(&self) -> JoinStyle {
|
||||
match *self {
|
||||
LineJoinStyle::Round => JoinStyle::Round,
|
||||
LineJoinStyle::Bevel => JoinStyle::Bevel,
|
||||
LineJoinStyle::Miter => JoinStyle::Miter,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub enum RepetitionStyle {
|
||||
Repeat,
|
||||
|
@ -373,22 +295,6 @@ impl FromStr for CompositionStyle {
|
|||
}
|
||||
|
||||
impl CompositionStyle {
|
||||
pub fn to_azure_style(&self) -> CompositionOp {
|
||||
match *self {
|
||||
CompositionStyle::SrcIn => CompositionOp::In,
|
||||
CompositionStyle::SrcOut => CompositionOp::Out,
|
||||
CompositionStyle::SrcOver => CompositionOp::Over,
|
||||
CompositionStyle::SrcAtop => CompositionOp::Atop,
|
||||
CompositionStyle::DestIn => CompositionOp::DestIn,
|
||||
CompositionStyle::DestOut => CompositionOp::DestOut,
|
||||
CompositionStyle::DestOver => CompositionOp::DestOver,
|
||||
CompositionStyle::DestAtop => CompositionOp::DestAtop,
|
||||
CompositionStyle::Copy => CompositionOp::Source,
|
||||
CompositionStyle::Lighter => CompositionOp::Add,
|
||||
CompositionStyle::Xor => CompositionOp::Xor,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_str(&self) -> &str {
|
||||
match *self {
|
||||
CompositionStyle::SrcIn => "source-in",
|
||||
|
@ -451,26 +357,6 @@ impl FromStr for BlendingStyle {
|
|||
}
|
||||
|
||||
impl BlendingStyle {
|
||||
pub fn to_azure_style(&self) -> CompositionOp {
|
||||
match *self {
|
||||
BlendingStyle::Multiply => CompositionOp::Multiply,
|
||||
BlendingStyle::Screen => CompositionOp::Screen,
|
||||
BlendingStyle::Overlay => CompositionOp::Overlay,
|
||||
BlendingStyle::Darken => CompositionOp::Darken,
|
||||
BlendingStyle::Lighten => CompositionOp::Lighten,
|
||||
BlendingStyle::ColorDodge => CompositionOp::ColorDodge,
|
||||
BlendingStyle::ColorBurn => CompositionOp::ColorBurn,
|
||||
BlendingStyle::HardLight => CompositionOp::HardLight,
|
||||
BlendingStyle::SoftLight => CompositionOp::SoftLight,
|
||||
BlendingStyle::Difference => CompositionOp::Difference,
|
||||
BlendingStyle::Exclusion => CompositionOp::Exclusion,
|
||||
BlendingStyle::Hue => CompositionOp::Hue,
|
||||
BlendingStyle::Saturation => CompositionOp::Saturation,
|
||||
BlendingStyle::Color => CompositionOp::Color,
|
||||
BlendingStyle::Luminosity => CompositionOp::Luminosity,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_str(&self) -> &str {
|
||||
match *self {
|
||||
BlendingStyle::Multiply => "multiply",
|
||||
|
@ -520,28 +406,6 @@ impl FromStr for CompositionOrBlending {
|
|||
}
|
||||
}
|
||||
|
||||
impl CompositionOrBlending {
|
||||
pub fn to_azure_style(&self) -> CompositionOp {
|
||||
match *self {
|
||||
CompositionOrBlending::Composition(op) => op.to_azure_style(),
|
||||
CompositionOrBlending::Blending(op) => op.to_azure_style(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToAzColor {
|
||||
fn to_azcolor(&self) -> Color;
|
||||
}
|
||||
|
||||
impl ToAzColor for RGBA {
|
||||
fn to_azcolor(&self) -> Color {
|
||||
Color::rgba(self.red as AzFloat,
|
||||
self.green as AzFloat,
|
||||
self.blue as AzFloat,
|
||||
self.alpha as AzFloat)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
||||
pub fn byte_swap(data: &mut [u8]) {
|
||||
let length = data.len();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue