mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Fix formatting.
This commit is contained in:
parent
97f5dacc29
commit
db362184fd
5 changed files with 116 additions and 90 deletions
|
@ -2,7 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::RGBA;
|
||||
use crate::canvas_data::{
|
||||
Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget,
|
||||
GenericPathBuilder, Path, Pattern, StrokeOptions,
|
||||
|
@ -14,6 +13,7 @@ use azure::azure_hl::SurfacePattern;
|
|||
use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle};
|
||||
use azure::azure_hl::{BackendType, ColorPattern, DrawTarget};
|
||||
use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern};
|
||||
use cssparser::RGBA;
|
||||
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
|
||||
|
||||
pub struct AzureBackend;
|
||||
|
@ -40,8 +40,8 @@ impl Backend for AzureBackend {
|
|||
},
|
||||
};
|
||||
Some(size)
|
||||
}
|
||||
Pattern::Azure(_) => None
|
||||
},
|
||||
Pattern::Azure(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,18 @@ impl Backend for AzureBackend {
|
|||
&mut self,
|
||||
style: FillOrStrokeStyle,
|
||||
state: &mut CanvasPaintState<'a>,
|
||||
drawtarget: &GenericDrawTarget)
|
||||
{
|
||||
drawtarget: &GenericDrawTarget,
|
||||
) {
|
||||
if let Some(pattern) = style.to_azure_pattern(drawtarget) {
|
||||
state.stroke_style = Pattern::Azure(pattern)
|
||||
}
|
||||
}
|
||||
|
||||
fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>) {
|
||||
fn set_global_composition<'a>(
|
||||
&mut self,
|
||||
op: CompositionOrBlending,
|
||||
state: &mut CanvasPaintState<'a>,
|
||||
) {
|
||||
state
|
||||
.draw_options
|
||||
.as_azure_mut()
|
||||
|
@ -89,7 +93,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
|
||||
self.state.draw_options.as_azure().antialias,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -97,9 +101,17 @@ impl Backend for AzureBackend {
|
|||
impl<'a> CanvasPaintState<'a> {
|
||||
pub fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> {
|
||||
CanvasPaintState {
|
||||
draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias.into_azure())),
|
||||
fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))),
|
||||
stroke_style: Pattern::Azure(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.into_azure(),
|
||||
)),
|
||||
fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(
|
||||
azure_hl::Color::black(),
|
||||
))),
|
||||
stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(
|
||||
azure_hl::Color::black(),
|
||||
))),
|
||||
stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new(
|
||||
1.0,
|
||||
JoinStyle::MiterOrBevel,
|
||||
|
@ -112,7 +124,7 @@ impl<'a> CanvasPaintState<'a> {
|
|||
shadow_offset_y: 0.0,
|
||||
shadow_blur: 0.0,
|
||||
shadow_color: Color::Azure(azure_hl::Color::transparent()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +252,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget {
|
|||
let draw_options = azure_hl::DrawOptions::new(
|
||||
draw_options.as_azure().alpha,
|
||||
draw_options.as_azure().composition.into_azure(),
|
||||
azure_hl::AntialiasMode::None
|
||||
azure_hl::AntialiasMode::None,
|
||||
);
|
||||
self.draw_surface(
|
||||
surface.into_azure(),
|
||||
|
@ -364,9 +376,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget {
|
|||
}
|
||||
|
||||
fn snapshot_data(&self) -> &[u8] {
|
||||
unsafe {
|
||||
self.snapshot().get_data_surface().data()
|
||||
}
|
||||
unsafe { self.snapshot().get_data_surface().data() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -634,10 +644,12 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
let gradient_stops: Vec<GradientStop> = linear_gradient_style
|
||||
.stops
|
||||
.iter()
|
||||
.map(|s| GradientStop::Azure(azure_hl::GradientStop {
|
||||
offset: s.offset as f32,
|
||||
color: s.color.to_azure_style(),
|
||||
}))
|
||||
.map(|s| {
|
||||
GradientStop::Azure(azure_hl::GradientStop {
|
||||
offset: s.offset as f32,
|
||||
color: s.color.to_azure_style(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
azure_hl::Pattern::LinearGradient(LinearGradientPattern::new(
|
||||
|
@ -649,7 +661,12 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
linear_gradient_style.x1 as f32,
|
||||
linear_gradient_style.y1 as f32,
|
||||
),
|
||||
drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(),
|
||||
drawtarget
|
||||
.create_gradient_stops(
|
||||
gradient_stops,
|
||||
ExtendMode::Azure(azure_hl::ExtendMode::Clamp),
|
||||
)
|
||||
.into_azure(),
|
||||
&Transform2D::identity(),
|
||||
))
|
||||
},
|
||||
|
@ -657,10 +674,12 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
let gradient_stops: Vec<GradientStop> = radial_gradient_style
|
||||
.stops
|
||||
.iter()
|
||||
.map(|s| GradientStop::Azure(azure_hl::GradientStop {
|
||||
offset: s.offset as f32,
|
||||
color: s.color.to_azure_style(),
|
||||
}))
|
||||
.map(|s| {
|
||||
GradientStop::Azure(azure_hl::GradientStop {
|
||||
offset: s.offset as f32,
|
||||
color: s.color.to_azure_style(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
azure_hl::Pattern::RadialGradient(RadialGradientPattern::new(
|
||||
|
@ -674,17 +693,24 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
),
|
||||
radial_gradient_style.r0 as f32,
|
||||
radial_gradient_style.r1 as f32,
|
||||
drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(),
|
||||
drawtarget
|
||||
.create_gradient_stops(
|
||||
gradient_stops,
|
||||
ExtendMode::Azure(azure_hl::ExtendMode::Clamp),
|
||||
)
|
||||
.into_azure(),
|
||||
&Transform2D::identity(),
|
||||
))
|
||||
},
|
||||
FillOrStrokeStyle::Surface(ref surface_style) => {
|
||||
let source_surface = drawtarget.create_source_surface_from_data(
|
||||
&surface_style.surface_data,
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
surface_style.surface_size.to_i32(),
|
||||
surface_style.surface_size.width as i32 * 4,
|
||||
)?.into_azure();
|
||||
let source_surface = drawtarget
|
||||
.create_source_surface_from_data(
|
||||
&surface_style.surface_data,
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
surface_style.surface_size.to_i32(),
|
||||
surface_style.surface_size.width as i32 * 4,
|
||||
)?
|
||||
.into_azure();
|
||||
azure_hl::Pattern::Surface(SurfacePattern::new(
|
||||
source_surface.azure_source_surface,
|
||||
surface_style.repeat_x,
|
||||
|
@ -711,10 +737,10 @@ impl ToAzureStyle for RGBA {
|
|||
|
||||
impl Pattern {
|
||||
pub fn is_zero_size_gradient(&self) -> bool {
|
||||
match *self {
|
||||
match *self {
|
||||
Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => {
|
||||
gradient.is_zero_size()
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -730,7 +756,10 @@ impl Filter {
|
|||
}
|
||||
|
||||
impl Path {
|
||||
pub fn transformed_copy_to_builder(&self, transform: &Transform2D<f32>) -> Box<GenericPathBuilder> {
|
||||
pub fn transformed_copy_to_builder(
|
||||
&self,
|
||||
transform: &Transform2D<f32>,
|
||||
) -> Box<GenericPathBuilder> {
|
||||
Box::new(self.as_azure().transformed_copy_to_builder(transform))
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,23 @@ pub trait Backend {
|
|||
fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp;
|
||||
fn need_to_draw_shadow(&self, color: &Color) -> bool;
|
||||
fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>);
|
||||
fn set_fill_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget);
|
||||
fn set_stroke_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget);
|
||||
fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>);
|
||||
fn set_fill_style<'a>(
|
||||
&mut self,
|
||||
style: FillOrStrokeStyle,
|
||||
state: &mut CanvasPaintState<'a>,
|
||||
drawtarget: &GenericDrawTarget,
|
||||
);
|
||||
fn set_stroke_style<'a>(
|
||||
&mut self,
|
||||
style: FillOrStrokeStyle,
|
||||
state: &mut CanvasPaintState<'a>,
|
||||
drawtarget: &GenericDrawTarget,
|
||||
);
|
||||
fn set_global_composition<'a>(
|
||||
&mut self,
|
||||
op: CompositionOrBlending,
|
||||
state: &mut CanvasPaintState<'a>,
|
||||
);
|
||||
fn create_drawtarget(&self, size: Size2D<u64>) -> Box<GenericDrawTarget>;
|
||||
fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a>;
|
||||
fn size_from_pattern(&self, rect: &Rect<f32>, pattern: &Pattern) -> Option<Size2D<f32>>;
|
||||
|
@ -143,12 +157,7 @@ impl<'a> PathBuilderRef<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
fn bezier_curve_to(
|
||||
&self,
|
||||
cp1: &Point2D<f32>,
|
||||
cp2: &Point2D<f32>,
|
||||
endpoint: &Point2D<f32>,
|
||||
) {
|
||||
fn bezier_curve_to(&self, cp1: &Point2D<f32>, cp2: &Point2D<f32>, endpoint: &Point2D<f32>) {
|
||||
self.builder.bezier_curve_to(
|
||||
&self.transform.transform_point(cp1),
|
||||
&self.transform.transform_point(cp2),
|
||||
|
@ -156,14 +165,7 @@ impl<'a> PathBuilderRef<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
fn arc(
|
||||
&self,
|
||||
center: &Point2D<f32>,
|
||||
radius: f32,
|
||||
start_angle: f32,
|
||||
end_angle: f32,
|
||||
ccw: bool,
|
||||
) {
|
||||
fn arc(&self, center: &Point2D<f32>, radius: f32, start_angle: f32, end_angle: f32, ccw: bool) {
|
||||
let center = self.transform.transform_point(center);
|
||||
self.builder
|
||||
.arc(center, radius, start_angle, end_angle, ccw);
|
||||
|
@ -305,7 +307,6 @@ pub enum Color {
|
|||
Raqote(()),
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum CompositionOp {
|
||||
#[cfg(feature = "azure_backend")]
|
||||
|
@ -439,7 +440,6 @@ impl<'a> CanvasData<'a> {
|
|||
image_data.into()
|
||||
};
|
||||
|
||||
|
||||
let writer = |draw_target: &GenericDrawTarget| {
|
||||
write_image(
|
||||
draw_target,
|
||||
|
@ -859,11 +859,13 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
pub fn set_fill_style(&mut self, style: FillOrStrokeStyle) {
|
||||
self.backend.set_fill_style(style, &mut self.state, &*self.drawtarget);
|
||||
self.backend
|
||||
.set_fill_style(style, &mut self.state, &*self.drawtarget);
|
||||
}
|
||||
|
||||
pub fn set_stroke_style(&mut self, style: FillOrStrokeStyle) {
|
||||
self.backend.set_stroke_style(style, &mut self.state, &*self.drawtarget);
|
||||
self.backend
|
||||
.set_stroke_style(style, &mut self.state, &*self.drawtarget);
|
||||
}
|
||||
|
||||
pub fn set_line_width(&mut self, width: f32) {
|
||||
|
@ -907,7 +909,9 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
pub fn recreate(&mut self, size: Size2D<u32>) {
|
||||
self.drawtarget = self.backend.create_drawtarget(Size2D::new(size.width as u64, size.height as u64));
|
||||
self.drawtarget = self
|
||||
.backend
|
||||
.create_drawtarget(Size2D::new(size.width as u64, size.height as u64));
|
||||
self.state = self.backend.recreate_paint_state(&self.state);
|
||||
self.saved_states.clear();
|
||||
// Webrender doesn't let images change size, so we clear the webrender image key.
|
||||
|
@ -925,9 +929,7 @@ 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()
|
||||
);
|
||||
let data = IpcSharedMemory::from_bytes(&self.drawtarget.snapshot_data());
|
||||
chan.send(data).unwrap();
|
||||
}
|
||||
|
||||
|
@ -943,9 +945,7 @@ 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 = webrender_api::ImageData::Raw(Arc::new(self.drawtarget.snapshot_data().into()));
|
||||
|
||||
let mut txn = webrender_api::Transaction::new();
|
||||
|
||||
|
@ -1065,17 +1065,17 @@ impl<'a> CanvasData<'a> {
|
|||
let canvas_rect = Rect::from_size(canvas_size);
|
||||
if canvas_rect
|
||||
.intersection(&read_rect)
|
||||
.map_or(true, |rect| rect.is_empty())
|
||||
{
|
||||
return vec![];
|
||||
}
|
||||
.map_or(true, |rect| rect.is_empty())
|
||||
{
|
||||
return vec![];
|
||||
}
|
||||
|
||||
pixels::rgba8_get_rect(
|
||||
&self.drawtarget.snapshot_data(),
|
||||
canvas_size.to_u32(),
|
||||
read_rect.to_u32(),
|
||||
)
|
||||
.into_owned()
|
||||
.into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1139,20 +1139,10 @@ fn write_image(
|
|||
let image_size = image_size.to_i32();
|
||||
|
||||
let source_surface = draw_target
|
||||
.create_source_surface_from_data(
|
||||
&image_data,
|
||||
image_size,
|
||||
image_size.width * 4,
|
||||
)
|
||||
.create_source_surface_from_data(&image_data, image_size, image_size.width * 4)
|
||||
.unwrap();
|
||||
|
||||
draw_target.draw_surface(
|
||||
source_surface,
|
||||
dest_rect,
|
||||
image_rect,
|
||||
filter,
|
||||
draw_options,
|
||||
);
|
||||
|
||||
draw_target.draw_surface(source_surface, dest_rect, image_rect, filter, draw_options);
|
||||
}
|
||||
|
||||
pub trait PointToi32 {
|
||||
|
|
|
@ -199,9 +199,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
self.canvas(canvas_id).set_shadow_offset_y(value)
|
||||
},
|
||||
Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value),
|
||||
Canvas2dMsg::SetShadowColor(color) => self
|
||||
.canvas(canvas_id)
|
||||
.set_shadow_color(color),
|
||||
Canvas2dMsg::SetShadowColor(color) => self.canvas(canvas_id).set_shadow_color(color),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::RGBA;
|
||||
use crate::canvas_data::{
|
||||
Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget,
|
||||
GenericPathBuilder, Path, Pattern, StrokeOptions,
|
||||
};
|
||||
use crate::canvas_paint_thread::AntialiasMode;
|
||||
use canvas_traits::canvas::*;
|
||||
use cssparser::RGBA;
|
||||
use euclid::{Rect, Size2D, Transform2D};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
@ -44,12 +44,16 @@ impl Backend for RaqoteBackend {
|
|||
&mut self,
|
||||
_style: FillOrStrokeStyle,
|
||||
_state: &mut CanvasPaintState<'a>,
|
||||
_drawtarget: &GenericDrawTarget)
|
||||
{
|
||||
_drawtarget: &GenericDrawTarget,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn set_global_composition<'a>(&mut self, _op: CompositionOrBlending, _state: &mut CanvasPaintState<'a>) {
|
||||
fn set_global_composition<'a>(
|
||||
&mut self,
|
||||
_op: CompositionOrBlending,
|
||||
_state: &mut CanvasPaintState<'a>,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
@ -74,13 +78,13 @@ impl<'a> CanvasPaintState<'a> {
|
|||
shadow_offset_y: 0.0,
|
||||
shadow_blur: 0.0,
|
||||
shadow_color: Color::Raqote(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
pub fn is_zero_size_gradient(&self) -> bool {
|
||||
match *self {
|
||||
match *self {
|
||||
Pattern::Raqote(()) => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +114,10 @@ impl DrawOptions {
|
|||
}
|
||||
|
||||
impl Path {
|
||||
pub fn transformed_copy_to_builder(&self, _transform: &Transform2D<f32>) -> Box<GenericPathBuilder> {
|
||||
pub fn transformed_copy_to_builder(
|
||||
&self,
|
||||
_transform: &Transform2D<f32>,
|
||||
) -> Box<GenericPathBuilder> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,11 @@ packages = [
|
|||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
"digest",
|
||||
"dwrote",
|
||||
"generic-array",
|
||||
"gl_generator", # https://github.com/servo/servo/pull/23288#issuecomment-494687746
|
||||
"lock_api",
|
||||
"memmap",
|
||||
"nix", # https://github.com/servo/servo/issues/23189#issuecomment-487512605
|
||||
"parking_lot",
|
||||
"parking_lot_core",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue