Implement Ellipse Canvas 2D API

* Update rust-azure to 0.21.0
* Mark the following test case as fail:
  tests/wpt/mozilla/tests/mozilla/css-paint-api/background-image-tiled.html
* Make the ellipse test case pass.

BUG: https://github.com/servo/servo/issues/17598
This commit is contained in:
Joone Hur 2017-08-17 10:43:19 -07:00
parent ac7cf53692
commit 57e283aaab
8 changed files with 52 additions and 16 deletions

8
Cargo.lock generated
View file

@ -109,8 +109,8 @@ dependencies = [
[[package]]
name = "azure"
version = "0.20.1"
source = "git+https://github.com/servo/rust-azure#ca851788b3bc1f1034d4d899da66faf78e420c5e"
version = "0.21.0"
source = "git+https://github.com/servo/rust-azure#dea0d6ebf4603771740acf2cebceab88f2efcc5e"
dependencies = [
"cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -324,7 +324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.20.1 (git+https://github.com/servo/rust-azure)",
"azure 0.21.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"compositing 0.0.1",
"cssparser 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3724,7 +3724,7 @@ dependencies = [
"checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0"
"checksum atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb2dcb6e6d35f20276943cc04bb98e538b348d525a04ac79c10021561d202f21"
"checksum audio-video-metadata 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3b6ef29ee98ad95a37f34547fd7fb40724772294110ed6ca0445fc2e964c29d1"
"checksum azure 0.20.1 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum azure 0.21.0 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76"
"checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff"
"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557"

View file

@ -173,6 +173,9 @@ impl<'a> CanvasPaintThread<'a> {
Canvas2dMsg::ArcTo(ref cp1, ref cp2, radius) => {
painter.arc_to(cp1, cp2, radius)
}
Canvas2dMsg::Ellipse(ref center, radius_x, radius_y, rotation, start, end, ccw) => {
painter.ellipse(center, radius_x, radius_y, rotation, start, end, ccw)
}
Canvas2dMsg::RestoreContext => painter.restore_context_state(),
Canvas2dMsg::SaveContext => painter.save_context_state(),
Canvas2dMsg::SetFillStyle(style) => painter.set_fill_style(style),
@ -501,6 +504,17 @@ impl<'a> CanvasPaintThread<'a> {
}
}
fn ellipse(&mut self,
center: &Point2D<AzFloat>,
radius_x: AzFloat,
radius_y: AzFloat,
rotation_angle: AzFloat,
start_angle: AzFloat,
end_angle: AzFloat,
ccw: bool) {
self.path_builder.ellipse(*center, radius_x, radius_y, rotation_angle, start_angle, end_angle, ccw);
}
fn set_fill_style(&mut self, style: FillOrStrokeStyle) {
if let Some(pattern) = style.to_azure_pattern(&self.drawtarget) {
self.state.fill_style = pattern

View file

@ -42,6 +42,7 @@ pub enum Canvas2dMsg {
ClearRect(Rect<f32>),
Clip,
ClosePath,
Ellipse(Point2D<f32>, f32, f32, f32, f32, f32, bool),
Fill,
FillText(String, f64, f64, Option<f64>),
FillRect(Rect<f32>),

View file

@ -957,6 +957,26 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
fn Ellipse(&self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
if !([x, y, rx, ry, rotation, start, end].iter().all(|x| x.is_finite())) {
return Ok(());
}
if rx < 0.0 || ry < 0.0 {
return Err(Error::IndexSize);
}
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::Ellipse(Point2D::new(x as f32, y as f32),
rx as f32,
ry as f32,
rotation as f32,
start as f32,
end as f32,
ccw));
self.ipc_renderer.send(msg).unwrap();
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn ImageSmoothingEnabled(&self) -> bool {
let state = self.state.borrow();

View file

@ -263,6 +263,11 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
self.context.ArcTo(cp1x, cp1y, cp2x, cp2y, r)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
fn Ellipse(&self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
self.context.Ellipse(x, y, rx, ry, rotation, start, end, ccw)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn ImageSmoothingEnabled(&self) -> bool {
self.context.ImageSmoothingEnabled()

View file

@ -264,4 +264,9 @@ interface CanvasPath {
// [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY,
// double rotation, double startAngle, double endAngle,
// boolean anticlockwise);
[Throws]
void ellipse(unrestricted double x, unrestricted double y, unrestricted double radius_x,
unrestricted double radius_y, unrestricted double rotation, unrestricted double startAngle,
unrestricted double endAngle, optional boolean anticlockwise = false);
};

View file

@ -3927,9 +3927,6 @@
[CanvasRenderingContext2D interface: attribute direction]
expected: FAIL
[CanvasRenderingContext2D interface: operation ellipse(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,boolean)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "width" with the proper type (1)]
expected: FAIL
@ -4050,12 +4047,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (69)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "ellipse" with the proper type (79)]
expected: FAIL
[CanvasRenderingContext2D interface: calling ellipse(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,boolean) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
expected: FAIL
[CanvasPattern interface: operation setTransform(SVGMatrix)]
expected: FAIL
@ -9591,9 +9582,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (68)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "ellipse" with the proper type (78)]
expected: FAIL
[CanvasPattern interface: operation setTransform(DOMMatrixInit)]
expected: FAIL

View file

@ -0,0 +1,3 @@
[background-image-tiled.html]
type: reftest
expected: FAIL