Auto merge of #24048 - pylbrecht:raqote, r=jrmuizel

Implement raqote backend for canvas 2D rendering

<!-- Please describe your changes on the following line: -->
This is a follow-up of #23936.

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

<!-- Either: -->

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24048)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-09-02 12:32:23 -04:00 committed by GitHub
commit 18f59fc16f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 8 deletions

2
Cargo.lock generated
View file

@ -3702,7 +3702,7 @@ dependencies = [
[[package]]
name = "raqote"
version = "0.6.2-alpha.0"
source = "git+https://github.com/jrmuizel/raqote#b3675e6cc1ac1d854605918f6613b64636d5e47b"
source = "git+https://github.com/jrmuizel/raqote#b1437ce88d27d376520485a1f8d60c5a480be5c1"
dependencies = [
"euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"font-kit 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -302,14 +302,14 @@ pub enum GradientStop {
#[cfg(feature = "canvas2d-azure")]
Azure(azure::AzGradientStop),
#[cfg(feature = "canvas2d-raqote")]
Raqote(()),
Raqote(raqote::GradientStop),
}
pub enum GradientStops {
#[cfg(feature = "canvas2d-azure")]
Azure(azure::azure_hl::GradientStops),
#[cfg(feature = "canvas2d-raqote")]
Raqote(()),
Raqote(Vec<raqote::GradientStop>),
}
#[derive(Clone)]

View file

@ -11,6 +11,7 @@ use crate::canvas_paint_thread::AntialiasMode;
use canvas_traits::canvas::*;
use cssparser::RGBA;
use euclid::default::{Point2D, Rect, Size2D, Transform2D, Vector2D};
use raqote::PathOp;
use std::marker::PhantomData;
pub struct RaqoteBackend;
@ -183,8 +184,9 @@ impl Path {
unimplemented!()
}
pub fn contains_point(&self, _x: f64, _y: f64, _path_transform: &Transform2D<f32>) -> bool {
unimplemented!()
pub fn contains_point(&self, x: f64, y: f64, _path_transform: &Transform2D<f32>) -> bool {
let path = self.as_raqote();
path.contains_point(0.1, path.winding, x as f32, y as f32)
}
pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> {
@ -238,10 +240,14 @@ impl GenericDrawTarget for raqote::DrawTarget {
}
fn create_gradient_stops(
&self,
_gradient_stops: Vec<GradientStop>,
gradient_stops: Vec<GradientStop>,
_extend_mode: ExtendMode,
) -> GradientStops {
unimplemented!();
let stops = gradient_stops
.into_iter()
.map(|item| item.as_raqote().clone())
.collect();
GradientStops::Raqote(stops)
}
fn create_path_builder(&self) -> Box<dyn GenericPathBuilder> {
Box::new(PathBuilder::new())
@ -488,7 +494,19 @@ impl GenericPathBuilder for PathBuilder {
unimplemented!();
}
fn get_current_point(&mut self) -> Point2D<f32> {
unimplemented!();
let path = self.finish();
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");
}
fn line_to(&mut self, point: Point2D<f32>) {
self.0.as_mut().unwrap().line_to(point.x, point.y);
@ -659,3 +677,11 @@ impl SourceSurface {
}
}
}
impl GradientStop {
fn as_raqote(&self) -> &raqote::GradientStop {
match self {
GradientStop::Raqote(s) => s,
}
}
}