Deal with fallout from mutable trait method change.

This commit is contained in:
Josh Matthews 2019-07-03 21:24:48 -04:00 committed by Bastien Orivel
parent b43c5c30e3
commit 4e51caeb7e
2 changed files with 85 additions and 76 deletions

View file

@ -343,11 +343,12 @@ pub enum SourceSurface {
Raqote(()),
}
#[derive(Clone)]
pub enum Path {
#[cfg(feature = "canvas2d-azure")]
Azure(azure::azure_hl::Path),
#[cfg(feature = "canvas2d-raqote")]
Raqote(()),
Raqote(raqote::Path),
}
#[derive(Clone)]
@ -437,7 +438,7 @@ impl<'a> CanvasData<'a> {
}
pub fn draw_image(
&self,
&mut self,
image_data: Vec<u8>,
image_size: Size2D<f64>,
dest_rect: Rect<f64>,
@ -453,14 +454,15 @@ impl<'a> CanvasData<'a> {
image_data.into()
};
let writer = |draw_target: &dyn GenericDrawTarget| {
let draw_options = self.state.draw_options.clone();
let writer = |draw_target: &mut dyn GenericDrawTarget| {
write_image(
draw_target,
image_data,
source_rect.size,
dest_rect,
smoothing_enabled,
&self.state.draw_options,
&draw_options,
);
};
@ -473,7 +475,7 @@ impl<'a> CanvasData<'a> {
// TODO(pylbrecht) pass another closure for raqote
self.draw_with_shadow(&rect, writer);
} else {
writer(&*self.drawtarget);
writer(&mut *self.drawtarget);
}
}
@ -496,7 +498,7 @@ impl<'a> CanvasData<'a> {
);
}
pub fn fill_rect(&self, rect: &Rect<f32>) {
pub fn fill_rect(&mut self, rect: &Rect<f32>) {
if self.state.fill_style.is_zero_size_gradient() {
return; // Paint nothing if gradient size is zero.
}
@ -509,7 +511,7 @@ impl<'a> CanvasData<'a> {
);
if self.need_to_draw_shadow() {
self.draw_with_shadow(&draw_rect, |new_draw_target: &dyn GenericDrawTarget| {
self.draw_with_shadow(&draw_rect, |new_draw_target: &mut dyn GenericDrawTarget| {
new_draw_target.fill_rect(
&draw_rect,
self.state.fill_style.clone(),
@ -529,13 +531,13 @@ impl<'a> CanvasData<'a> {
self.drawtarget.clear_rect(rect);
}
pub fn stroke_rect(&self, rect: &Rect<f32>) {
pub fn stroke_rect(&mut self, rect: &Rect<f32>) {
if self.state.stroke_style.is_zero_size_gradient() {
return; // Paint nothing if gradient size is zero.
}
if self.need_to_draw_shadow() {
self.draw_with_shadow(&rect, |new_draw_target: &dyn GenericDrawTarget| {
self.draw_with_shadow(&rect, |new_draw_target: &mut dyn GenericDrawTarget| {
new_draw_target.stroke_rect(
rect,
self.state.stroke_style.clone(),
@ -642,7 +644,7 @@ impl<'a> CanvasData<'a> {
self.ensure_path();
self.drawtarget.fill(
&self.path(),
&self.path().clone(),
self.state.fill_style.clone(),
&self.state.draw_options,
);
@ -655,7 +657,7 @@ impl<'a> CanvasData<'a> {
self.ensure_path();
self.drawtarget.stroke(
&self.path(),
&self.path().clone(),
self.state.stroke_style.clone(),
&self.state.stroke_opts,
&self.state.draw_options,
@ -664,7 +666,7 @@ impl<'a> CanvasData<'a> {
pub fn clip(&mut self) {
self.ensure_path();
let path = self.path();
let path = self.path().clone();
self.drawtarget.push_clip(&path);
}
@ -1037,7 +1039,7 @@ impl<'a> CanvasData<'a> {
}
fn create_draw_target_for_shadow(&self, source_rect: &Rect<f32>) -> Box<dyn GenericDrawTarget> {
let draw_target = self.drawtarget.create_similar_draw_target(
let mut draw_target = self.drawtarget.create_similar_draw_target(
&Size2D::new(
source_rect.size.width as i32,
source_rect.size.height as i32,
@ -1053,11 +1055,11 @@ impl<'a> CanvasData<'a> {
fn draw_with_shadow<F>(&self, rect: &Rect<f32>, draw_shadow_source: F)
where
F: FnOnce(&dyn GenericDrawTarget),
F: FnOnce(&mut dyn GenericDrawTarget),
{
let shadow_src_rect = self.state.transform.transform_rect(rect);
let new_draw_target = self.create_draw_target_for_shadow(&shadow_src_rect);
draw_shadow_source(&*new_draw_target);
let mut new_draw_target = self.create_draw_target_for_shadow(&shadow_src_rect);
draw_shadow_source(&mut *new_draw_target);
self.drawtarget.draw_surface_with_shadow(
new_draw_target.snapshot(),
&Point2D::new(

View file

@ -143,72 +143,71 @@ impl Path {
}
impl GenericDrawTarget for raqote::DrawTarget {
fn clear_rect(&self, rect: &Rect<f32>) {
fn clear_rect(&self, _rect: &Rect<f32>) {
unimplemented!();
}
fn copy_surface(
&mut self,
surface: SourceSurface,
source: Rect<i32>,
destination: Point2D<i32>,
_surface: SourceSurface,
_source: Rect<i32>,
_destination: Point2D<i32>,
) {
unimplemented!();
}
fn create_gradient_stops(
&self,
gradient_stops: Vec<GradientStop>,
extend_mode: ExtendMode,
_gradient_stops: Vec<GradientStop>,
_extend_mode: ExtendMode,
) -> GradientStops {
unimplemented!();
}
fn create_path_builder(&self) -> Box<dyn GenericPathBuilder> {
unimplemented!();
Box::new(PathBuilder::new())
}
fn create_similar_draw_target(
&self,
size: &Size2D<i32>,
format: SurfaceFormat,
_size: &Size2D<i32>,
_format: SurfaceFormat,
) -> Box<dyn GenericDrawTarget> {
unimplemented!();
}
fn create_source_surface_from_data(
&self,
data: &[u8],
size: Size2D<i32>,
stride: i32,
_data: &[u8],
_size: Size2D<i32>,
_stride: i32,
) -> Option<SourceSurface> {
unimplemented!();
}
fn draw_surface(
&self,
surface: SourceSurface,
dest: Rect<f64>,
source: Rect<f64>,
filter: Filter,
draw_options: &DrawOptions,
_surface: SourceSurface,
_dest: Rect<f64>,
_source: Rect<f64>,
_filter: Filter,
_draw_options: &DrawOptions,
) {
unimplemented!();
}
fn draw_surface_with_shadow(
&self,
surface: SourceSurface,
dest: &Point2D<f32>,
color: &Color,
offset: &Vector2D<f32>,
sigma: f32,
operator: CompositionOp,
_surface: SourceSurface,
_dest: &Point2D<f32>,
_color: &Color,
_offset: &Vector2D<f32>,
_sigma: f32,
_operator: CompositionOp,
) {
unimplemented!();
}
fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) {
fn fill(&mut self, _path: &Path, _pattern: Pattern, _draw_options: &DrawOptions) {
unimplemented!();
}
fn fill_rect(
&mut self,
rect: &Rect<f32>,
pattern: Pattern,
draw_options: Option<&DrawOptions>,
_rect: &Rect<f32>,
_pattern: Pattern,
_draw_options: Option<&DrawOptions>,
) {
unimplemented!();
}
@ -224,10 +223,10 @@ impl GenericDrawTarget for raqote::DrawTarget {
fn pop_clip(&mut self) {
unimplemented!();
}
fn push_clip(&mut self, path: &Path) {
fn push_clip(&mut self, _path: &Path) {
unimplemented!();
}
fn set_transform(&mut self, matrix: &Transform2D<f32>) {
fn set_transform(&mut self, _matrix: &Transform2D<f32>) {
unimplemented!();
}
fn snapshot(&self) -> SourceSurface {
@ -235,33 +234,33 @@ impl GenericDrawTarget for raqote::DrawTarget {
}
fn stroke(
&mut self,
path: &Path,
pattern: Pattern,
stroke_options: &StrokeOptions,
draw_options: &DrawOptions,
_path: &Path,
_pattern: Pattern,
_stroke_options: &StrokeOptions,
_draw_options: &DrawOptions,
) {
unimplemented!();
}
fn stroke_line(
&mut self,
start: Point2D<f32>,
end: Point2D<f32>,
pattern: Pattern,
stroke_options: &StrokeOptions,
draw_options: &DrawOptions,
_start: Point2D<f32>,
_end: Point2D<f32>,
_pattern: Pattern,
_stroke_options: &StrokeOptions,
_draw_options: &DrawOptions,
) {
unimplemented!();
}
fn stroke_rect(
&mut self,
rect: &Rect<f32>,
pattern: Pattern,
stroke_options: &StrokeOptions,
draw_options: &DrawOptions,
_rect: &Rect<f32>,
_pattern: Pattern,
_stroke_options: &StrokeOptions,
_draw_options: &DrawOptions,
) {
unimplemented!();
}
fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec<u8>) -> Vec<u8> {
fn snapshot_data(&self, _f: &dyn Fn(&[u8]) -> Vec<u8>) -> Vec<u8> {
unimplemented!();
}
fn snapshot_data_owned(&self) -> Vec<u8> {
@ -269,16 +268,24 @@ impl GenericDrawTarget for raqote::DrawTarget {
}
}
impl GenericPathBuilder for raqote::PathBuilder {
struct PathBuilder(Option<raqote::PathBuilder>);
impl PathBuilder {
fn new() -> PathBuilder {
PathBuilder(Some(raqote::PathBuilder::new()))
}
}
impl GenericPathBuilder for PathBuilder {
fn arc(
&mut self,
origin: Point2D<f32>,
radius: f32,
start_angle: f32,
end_angle: f32,
anticlockwise: bool,
_anticlockwise: bool,
) {
self.arc(origin.x, origin.y, radius, start_angle, end_angle);
self.0.as_mut().unwrap().arc(origin.x, origin.y, radius, start_angle, end_angle);
}
fn bezier_curve_to(
&mut self,
@ -286,7 +293,7 @@ impl GenericPathBuilder for raqote::PathBuilder {
control_point2: &Point2D<f32>,
control_point3: &Point2D<f32>,
) {
self.cubic_to(
self.0.as_mut().unwrap().cubic_to(
control_point1.x,
control_point1.y,
control_point2.x,
@ -296,17 +303,17 @@ impl GenericPathBuilder for raqote::PathBuilder {
);
}
fn close(&mut self) {
self.close();
self.0.as_mut().unwrap().close();
}
fn ellipse(
&mut self,
origin: Point2D<f32>,
radius_x: f32,
radius_y: f32,
rotation_angle: f32,
start_angle: f32,
end_angle: f32,
anticlockwise: bool,
_origin: Point2D<f32>,
_radius_x: f32,
_radius_y: f32,
_rotation_angle: f32,
_start_angle: f32,
_end_angle: f32,
_anticlockwise: bool,
) {
unimplemented!();
}
@ -314,16 +321,16 @@ impl GenericPathBuilder for raqote::PathBuilder {
unimplemented!();
}
fn line_to(&mut self, point: Point2D<f32>) {
self.line_to(point.x, point.y);
self.0.as_mut().unwrap().line_to(point.x, point.y);
}
fn move_to(&mut self, point: Point2D<f32>) {
self.move_to(point.x, point.y);
self.0.as_mut().unwrap().move_to(point.x, point.y);
}
fn quadratic_curve_to(&mut self, control_point: &Point2D<f32>, end_point: &Point2D<f32>) {
self.quad_to(control_point.x, control_point.y, end_point.x, end_point.y);
self.0.as_mut().unwrap().quad_to(control_point.x, control_point.y, end_point.x, end_point.y);
}
fn finish(&mut self) -> Path {
self.finish()
Path::Raqote(self.0.take().unwrap().finish())
}
}