mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Make CanvasPaintState generic
This commit is contained in:
parent
3182eba73b
commit
7ace517770
1 changed files with 55 additions and 24 deletions
|
@ -467,6 +467,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum ExtendMode {
|
enum ExtendMode {
|
||||||
Azure(azure_hl::ExtendMode),
|
Azure(azure_hl::ExtendMode),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -488,6 +489,7 @@ impl ExtendMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum GradientStop {
|
enum GradientStop {
|
||||||
Azure(AzGradientStop),
|
Azure(AzGradientStop),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -509,6 +511,7 @@ impl GradientStop {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum GradientStops {
|
enum GradientStops {
|
||||||
Azure(azure_hl::GradientStops),
|
Azure(azure_hl::GradientStops),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -530,6 +533,7 @@ impl GradientStops {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum Color {
|
enum Color {
|
||||||
Azure(azure_hl::Color),
|
Azure(azure_hl::Color),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -544,6 +548,7 @@ impl Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum CompositionOp {
|
enum CompositionOp {
|
||||||
Azure(azure_hl::CompositionOp),
|
Azure(azure_hl::CompositionOp),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -558,6 +563,7 @@ impl CompositionOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum SurfaceFormat {
|
enum SurfaceFormat {
|
||||||
Azure(azure_hl::SurfaceFormat),
|
Azure(azure_hl::SurfaceFormat),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -572,6 +578,7 @@ impl SurfaceFormat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum SourceSurface {
|
enum SourceSurface {
|
||||||
Azure(azure_hl::SourceSurface),
|
Azure(azure_hl::SourceSurface),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -586,6 +593,7 @@ impl SourceSurface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum IntSize {
|
enum IntSize {
|
||||||
Azure(AzIntSize),
|
Azure(AzIntSize),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -600,6 +608,7 @@ impl IntSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum Path {
|
enum Path {
|
||||||
Azure(azure_hl::Path),
|
Azure(azure_hl::Path),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -614,11 +623,13 @@ impl Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum Pattern {
|
enum Pattern {
|
||||||
Azure(azure_hl::Pattern),
|
Azure(azure_hl::Pattern),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum PatternRef<'a> {
|
enum PatternRef<'a> {
|
||||||
Azure(azure_hl::PatternRef<'a>),
|
Azure(azure_hl::PatternRef<'a>),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -649,6 +660,7 @@ impl Pattern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum DrawOptions {
|
enum DrawOptions {
|
||||||
Azure(azure_hl::DrawOptions),
|
Azure(azure_hl::DrawOptions),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -663,6 +675,7 @@ impl DrawOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum StrokeOptions<'a> {
|
enum StrokeOptions<'a> {
|
||||||
Azure(azure_hl::StrokeOptions<'a>),
|
Azure(azure_hl::StrokeOptions<'a>),
|
||||||
Raqote(()),
|
Raqote(()),
|
||||||
|
@ -703,7 +716,7 @@ impl<'a> CanvasData<'a> {
|
||||||
CanvasData {
|
CanvasData {
|
||||||
drawtarget: draw_target,
|
drawtarget: draw_target,
|
||||||
path_state: None,
|
path_state: None,
|
||||||
state: CanvasPaintState::new(antialias),
|
state: CanvasPaintState::new(antialias, CanvasBackend::Azure),
|
||||||
saved_states: vec![],
|
saved_states: vec![],
|
||||||
webrender_api: webrender_api,
|
webrender_api: webrender_api,
|
||||||
image_key: None,
|
image_key: None,
|
||||||
|
@ -1236,7 +1249,7 @@ impl<'a> CanvasData<'a> {
|
||||||
|
|
||||||
pub fn recreate(&mut self, size: Size2D<u32>) {
|
pub fn recreate(&mut self, size: Size2D<u32>) {
|
||||||
self.drawtarget = CanvasData::create(Size2D::new(size.width as u64, size.height as u64));
|
self.drawtarget = CanvasData::create(Size2D::new(size.width as u64, size.height as u64));
|
||||||
self.state = CanvasPaintState::new(self.state.draw_options.antialias);
|
self.state = CanvasPaintState::new(self.state.draw_options.antialias, CanvasBackend::Azure);
|
||||||
self.saved_states.clear();
|
self.saved_states.clear();
|
||||||
// Webrender doesn't let images change size, so we clear the webrender image key.
|
// Webrender doesn't let images change size, so we clear the webrender image key.
|
||||||
// TODO: there is an annying race condition here: the display list builder
|
// TODO: there is an annying race condition here: the display list builder
|
||||||
|
@ -1423,38 +1436,56 @@ impl<'a> Drop for CanvasData<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CanvasBackend {
|
||||||
|
Azure,
|
||||||
|
Raqote,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct CanvasPaintState<'a> {
|
struct CanvasPaintState<'a> {
|
||||||
draw_options: azure_hl::DrawOptions,
|
draw_options: DrawOptions,
|
||||||
fill_style: azure_hl::Pattern,
|
fill_style: Pattern,
|
||||||
stroke_style: azure_hl::Pattern,
|
stroke_style: Pattern,
|
||||||
stroke_opts: azure_hl::StrokeOptions<'a>,
|
stroke_opts: StrokeOptions<'a>,
|
||||||
/// The current 2D transform matrix.
|
/// The current 2D transform matrix.
|
||||||
transform: Transform2D<f32>,
|
transform: Transform2D<f32>,
|
||||||
shadow_offset_x: f64,
|
shadow_offset_x: f64,
|
||||||
shadow_offset_y: f64,
|
shadow_offset_y: f64,
|
||||||
shadow_blur: f64,
|
shadow_blur: f64,
|
||||||
shadow_color: azure_hl::Color,
|
shadow_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CanvasPaintState<'a> {
|
impl<'a> CanvasPaintState<'a> {
|
||||||
fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> {
|
fn new(antialias: AntialiasMode, backend: CanvasBackend) -> CanvasPaintState<'a> {
|
||||||
CanvasPaintState {
|
match backend {
|
||||||
draw_options: azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias),
|
CanvasBackend::Azure => CanvasPaintState {
|
||||||
fill_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())),
|
draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias)),
|
||||||
stroke_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())),
|
fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))),
|
||||||
stroke_opts: azure_hl::StrokeOptions::new(
|
stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))),
|
||||||
1.0,
|
stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new(
|
||||||
JoinStyle::MiterOrBevel,
|
1.0,
|
||||||
CapStyle::Butt,
|
JoinStyle::MiterOrBevel,
|
||||||
10.0,
|
CapStyle::Butt,
|
||||||
&[],
|
10.0,
|
||||||
),
|
&[],
|
||||||
transform: Transform2D::identity(),
|
)),
|
||||||
shadow_offset_x: 0.0,
|
transform: Transform2D::identity(),
|
||||||
shadow_offset_y: 0.0,
|
shadow_offset_x: 0.0,
|
||||||
shadow_blur: 0.0,
|
shadow_offset_y: 0.0,
|
||||||
shadow_color: azure_hl::Color::transparent(),
|
shadow_blur: 0.0,
|
||||||
|
shadow_color: Color::Azure(azure_hl::Color::transparent()),
|
||||||
|
},
|
||||||
|
CanvasBackend::Raqote => CanvasPaintState {
|
||||||
|
draw_options: DrawOptions::Raqote(()),
|
||||||
|
fill_style: Pattern::Raqote(()),
|
||||||
|
stroke_style: Pattern::Raqote(()),
|
||||||
|
stroke_opts: StrokeOptions::Raqote(()),
|
||||||
|
transform: Transform2D::identity(),
|
||||||
|
shadow_offset_x: 0.0,
|
||||||
|
shadow_offset_y: 0.0,
|
||||||
|
shadow_blur: 0.0,
|
||||||
|
shadow_color: Color::Raqote(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue