Skip to content

Commit

Permalink
Auto merge of #24470 - pylbrecht:raqote, r=<try>
Browse files Browse the repository at this point in the history
Enable raqote as 2D canvas rendering backend by default

<!-- Please describe your changes on the following line: -->
This will enable raqote by default and make all WPT tests pass.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #23431

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
  • Loading branch information
bors-servo committed Nov 15, 2019
2 parents b9cdf9e + f3d6b9d commit bba90e9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/canvas/azure_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ impl GenericPathBuilder for azure_hl::PathBuilder {
anticlockwise,
);
}
fn get_current_point(&mut self) -> Point2D<f32> {
fn get_current_point(&mut self) -> Option<Point2D<f32>> {
let AzPoint { x, y } = azure_hl::PathBuilder::get_current_point(self);
Point2D::new(x as f32, y as f32)
Some(Point2D::new(x as f32, y as f32))
}
fn line_to(&mut self, point: Point2D<f32>) {
azure_hl::PathBuilder::line_to(self, point as Point2D<AzFloat>);
Expand Down
8 changes: 5 additions & 3 deletions components/canvas/canvas_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub trait GenericPathBuilder {
end_angle: f32,
anticlockwise: bool,
);
fn get_current_point(&mut self) -> Point2D<f32>;
fn get_current_point(&mut self) -> Option<Point2D<f32>>;
fn line_to(&mut self, point: Point2D<f32>);
fn move_to(&mut self, point: Point2D<f32>);
fn quadratic_curve_to(&mut self, control_point: &Point2D<f32>, end_point: &Point2D<f32>);
Expand Down Expand Up @@ -205,8 +205,10 @@ impl<'a> PathBuilderRef<'a> {
Some(i) => i,
None => return None,
};
let current_point = self.builder.get_current_point();
Some(inverse.transform_point(Point2D::new(current_point.x, current_point.y)))
match self.builder.get_current_point() {
Some(point) => Some(inverse.transform_point(Point2D::new(point.x, point.y))),
None => None,
}
}
}

Expand Down
90 changes: 45 additions & 45 deletions components/canvas/raqote_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl Backend for RaqoteBackend {

impl<'a> CanvasPaintState<'a> {
pub fn new(_antialias: AntialiasMode) -> CanvasPaintState<'a> {
let solid_src = raqote::SolidSource {
r: 0,
g: 0,
b: 0,
a: 255,
};
let solid_src = raqote::SolidSource::from_unpremultiplied_argb(
255,
0,
0,
0,
);
CanvasPaintState {
draw_options: DrawOptions::Raqote(raqote::DrawOptions::new()),
fill_style: Pattern::Raqote(raqote::Source::Solid(solid_src)),
Expand All @@ -99,12 +99,12 @@ impl<'a> CanvasPaintState<'a> {
shadow_offset_x: 0.0,
shadow_offset_y: 0.0,
shadow_blur: 0.0,
shadow_color: Color::Raqote(raqote::SolidSource {
r: 0,
g: 0,
b: 0,
a: 0,
}),
shadow_color: Color::Raqote(raqote::SolidSource::from_unpremultiplied_argb(
0,
0,
0,
0,
)),
}
}
}
Expand Down Expand Up @@ -187,8 +187,11 @@ impl Path {
))))
}

pub fn contains_point(&self, x: f64, y: f64, _path_transform: &Transform2D<f32>) -> bool {
self.as_raqote().contains_point(0.1, x as f32, y as f32)
pub fn contains_point(&self, x: f64, y: f64, path_transform: &Transform2D<f32>) -> bool {
self.as_raqote()
.clone()
.transform(path_transform)
.contains_point(0.1, x as f32, y as f32)
}

pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> {
Expand Down Expand Up @@ -218,12 +221,12 @@ impl GenericDrawTarget for raqote::DrawTarget {
raqote::DrawTarget::fill(
self,
&pb.finish(),
&raqote::Source::Solid(raqote::SolidSource {
r: 0,
g: 0,
b: 0,
a: 0,
}),
&raqote::Source::Solid(raqote::SolidSource::from_unpremultiplied_argb(
0,
0,
0,
0,
)),
&options,
);
}
Expand Down Expand Up @@ -285,7 +288,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
data: unsafe {
std::slice::from_raw_parts(
v.as_ptr() as *const u32,
v.len() * std::mem::size_of::<u8>(),
v.len() / std::mem::size_of::<u32>(),
)
},
};
Expand Down Expand Up @@ -561,21 +564,18 @@ impl GenericPathBuilder for PathBuilder {
}
}

fn get_current_point(&mut self) -> Point2D<f32> {
fn get_current_point(&mut self) -> Option<Point2D<f32>> {
let path = self.finish();
self.0 = Some(path.as_raqote().clone().into());

for op in path.as_raqote().ops.iter().rev() {
match op {
PathOp::MoveTo(point) | PathOp::LineTo(point) => {
return Point2D::new(point.x, point.y)
},
PathOp::CubicTo(_, _, point) => return Point2D::new(point.x, point.y),
PathOp::QuadTo(_, point) => return Point2D::new(point.x, point.y),
PathOp::Close => {},
};
}
panic!("dead end");
path.as_raqote().ops.iter().last().and_then(|op| match op {
PathOp::MoveTo(point) | PathOp::LineTo(point) => Some(Point2D::new(point.x, point.y)),
PathOp::CubicTo(_, _, point) => Some(Point2D::new(point.x, point.y)),
PathOp::QuadTo(_, point) => Some(Point2D::new(point.x, point.y)),
PathOp::Close => None,
})
}

fn line_to(&mut self, point: Point2D<f32>) {
self.0.as_mut().unwrap().line_to(point.x, point.y);
}
Expand Down Expand Up @@ -652,12 +652,12 @@ impl<'a> ToRaqoteSource<'a> for FillOrStrokeStyle {
use canvas_traits::canvas::FillOrStrokeStyle::*;

match self {
Color(rgba) => Some(raqote::Source::Solid(raqote::SolidSource {
r: rgba.red,
g: rgba.green,
b: rgba.blue,
a: rgba.alpha,
})),
Color(rgba) => Some(raqote::Source::Solid(raqote::SolidSource::from_unpremultiplied_argb(
rgba.alpha,
rgba.red,
rgba.green,
rgba.blue,
))),
LinearGradient(style) => {
let stops = style.stops.into_iter().map(|s| s.to_raqote()).collect();
let gradient = raqote::Gradient { stops };
Expand Down Expand Up @@ -715,12 +715,12 @@ impl ToRaqoteStyle for RGBA {
type Target = raqote::SolidSource;

fn to_raqote_style(self) -> Self::Target {
raqote::SolidSource {
r: self.red,
g: self.green,
b: self.blue,
a: self.alpha,
}
raqote::SolidSource::from_unpremultiplied_argb(
self.alpha,
self.red,
self.green,
self.blue,
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ def run_cargo_build_like_command(
features.append("egl")
if with_raqote and "canvas2d-azure" not in features:
features.append("canvas2d-raqote")
elif "canvas2d-raqote" not in features:
features.append("canvas2d-azure")
elif "canvas2d-azure" not in features:
features.append("canvas2d-raqote")
if with_layout_2020 and "layout-2013" not in features:
features.append("layout-2020")
elif "layout-2020" not in features:
Expand Down

0 comments on commit bba90e9

Please sign in to comment.