aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-09-02 12:32:23 -0400
committerGitHub <noreply@github.com>2019-09-02 12:32:23 -0400
commit18f59fc16f431b16407bf5fcfb2e89d9a5adfd5b (patch)
tree58b6ff793da925c625374aae88dbf1db158765ec /components
parent026dc7485f27f6f444965693f3746e0b75988cdd (diff)
parentd24568218b2046560be29f35daa67cbf405e9281 (diff)
downloadservo-18f59fc16f431b16407bf5fcfb2e89d9a5adfd5b.tar.gz
servo-18f59fc16f431b16407bf5fcfb2e89d9a5adfd5b.zip
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 -->
Diffstat (limited to 'components')
-rw-r--r--components/canvas/canvas_data.rs4
-rw-r--r--components/canvas/raqote_backend.rs36
2 files changed, 33 insertions, 7 deletions
diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs
index f2df5bf179d..78c32b4d813 100644
--- a/components/canvas/canvas_data.rs
+++ b/components/canvas/canvas_data.rs
@@ -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)]
diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs
index 279402fa77a..bd25b5fb9de 100644
--- a/components/canvas/raqote_backend.rs
+++ b/components/canvas/raqote_backend.rs
@@ -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,
+ }
+ }
+}