servo: Merge #18242 - Implement Ellipse Canvas 2D API (from joone:ellipse); r=jdm
authorJoone Hur <joone.hur@intel.com>
Fri, 01 Sep 2017 20:25:57 -0500
changeset 378367 51f851ac3b808416b7ab7df38473cbd3c9410054
parent 378366 3e029b5ea02f00fd54b996b6833424d1944a5ec0
child 378368 2047237ce098815c66e3c59f39b1a9af6221da1d
push id32428
push userarchaeopteryx@coole-files.de
push dateSat, 02 Sep 2017 08:52:28 +0000
treeherdermozilla-central@b01a7e57425b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #18242 - Implement Ellipse Canvas 2D API (from joone:ellipse); r=jdm This patch needs to update rust-azure to 0.21.0. - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #17598 <!-- Either: --> - [] There are tests for these changes OR - [] These changes do not require tests because _____ Source-Repo: https://github.com/servo/servo Source-Revision: 3a4b98ad38214495ac0f1f1aa1052f0c583ffe5c
servo/Cargo.lock
servo/components/canvas/canvas_paint_thread.rs
servo/components/canvas_traits/canvas.rs
servo/components/script/dom/canvasrenderingcontext2d.rs
servo/components/script/dom/paintrenderingcontext2d.rs
servo/components/script/dom/webidls/CanvasRenderingContext2D.webidl
--- a/servo/Cargo.lock
+++ b/servo/Cargo.lock
@@ -104,18 +104,18 @@ source = "registry+https://github.com/ru
 dependencies = [
  "mp3-metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "mp4parse 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ogg_metadata 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[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)",
  "core-graphics 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "freetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -319,17 +319,17 @@ source = "registry+https://github.com/ru
 name = "bytes"
 version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 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.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3720,17 +3720,17 @@ dependencies = [
 "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
 "checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5"
 "checksum app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ff4f3fe57393a150b39b026b6f6f4b9a6c4f49b52d0a4e2d61d08d926358438"
 "checksum arraydeque 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "96e774cadb24c2245225280c6799793f9802b918a58a79615e9490607489a717"
 "checksum arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "699e63a93b79d717e8c3b5eb1b28b7780d0d6d9e59a72eb769291c83b0c8dc67"
 "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"
 "checksum binary-space-partition 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88ceb0d16c4fd0e42876e298d7d3ce3780dd9ebdcbe4199816a32c77e08597ff"
 "checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e"
 "checksum bindgen 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c338079dafc81bef7d581f494b906603d12359c4306979eae6ca081925a4984"
 "checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c"
 "checksum bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5b97c2c8e8bbb4251754f559df8af22fb264853c7d009084a576cdf12565089d"
--- a/servo/components/canvas/canvas_paint_thread.rs
+++ b/servo/components/canvas/canvas_paint_thread.rs
@@ -168,16 +168,19 @@ impl<'a> CanvasPaintThread<'a> {
                                 painter.bezier_curve_to(cp1, cp2, pt)
                             }
                             Canvas2dMsg::Arc(ref center, radius, start, end, ccw) => {
                                 painter.arc(center, radius, start, end, ccw)
                             }
                             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),
                             Canvas2dMsg::SetStrokeStyle(style) => painter.set_stroke_style(style),
                             Canvas2dMsg::SetLineWidth(width) => painter.set_line_width(width),
                             Canvas2dMsg::SetLineCap(cap) => painter.set_line_cap(cap),
                             Canvas2dMsg::SetLineJoin(join) => painter.set_line_join(join),
                             Canvas2dMsg::SetMiterLimit(limit) => painter.set_miter_limit(limit),
@@ -496,16 +499,27 @@ impl<'a> CanvasPaintThread<'a> {
 
         self.line_to(&tp1);
         if [cx, cy, angle_start, angle_end].iter().all(|x| x.is_finite()) {
             self.arc(&Point2D::new(cx, cy), radius,
                      angle_start, angle_end, anticlockwise);
         }
     }
 
+    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
         }
     }
 
     fn set_stroke_style(&mut self, style: FillOrStrokeStyle) {
         if let Some(pattern) = style.to_azure_pattern(&self.drawtarget) {
--- a/servo/components/canvas_traits/canvas.rs
+++ b/servo/components/canvas_traits/canvas.rs
@@ -37,16 +37,17 @@ pub enum Canvas2dMsg {
     DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
     DrawImageInOther(
         IpcSender<CanvasMsg>, Size2D<f64>, Rect<f64>, Rect<f64>, bool, IpcSender<()>),
     BeginPath,
     BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
     ClearRect(Rect<f32>),
     Clip,
     ClosePath,
+    Ellipse(Point2D<f32>, f32, f32, f32, f32, f32, bool),
     Fill,
     FillText(String, f64, f64, Option<f64>),
     FillRect(Rect<f32>),
     GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
     IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
     LineTo(Point2D<f32>),
     MoveTo(Point2D<f32>),
     PutImageData(Vec<u8>, Vector2D<f64>, Size2D<f64>, Rect<f64>),
--- a/servo/components/script/dom/canvasrenderingcontext2d.rs
+++ b/servo/components/script/dom/canvasrenderingcontext2d.rs
@@ -952,16 +952,36 @@ impl CanvasRenderingContext2DMethods for
 
         let msg = CanvasMsg::Canvas2d(Canvas2dMsg::ArcTo(Point2D::new(cp1x as f32, cp1y as f32),
                                                          Point2D::new(cp2x as f32, cp2y as f32),
                                                          r as f32));
         self.ipc_renderer.send(msg).unwrap();
         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();
         state.image_smoothing_enabled
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
     fn SetImageSmoothingEnabled(&self, value: bool) {
--- a/servo/components/script/dom/paintrenderingcontext2d.rs
+++ b/servo/components/script/dom/paintrenderingcontext2d.rs
@@ -258,16 +258,21 @@ impl PaintRenderingContext2DMethods for 
         self.context.Arc(x, y, r, start, end, ccw)
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto
     fn ArcTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult {
         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()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
     fn SetImageSmoothingEnabled(&self, value: bool) {
         self.context.SetImageSmoothingEnabled(value)
--- a/servo/components/script/dom/webidls/CanvasRenderingContext2D.webidl
+++ b/servo/components/script/dom/webidls/CanvasRenderingContext2D.webidl
@@ -259,9 +259,14 @@ interface CanvasPath {
   void rect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
 
   [Throws]
   void arc(unrestricted double x, unrestricted double y, unrestricted double radius,
            unrestricted double startAngle, unrestricted double endAngle, optional boolean anticlockwise = false);
   // [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);
 };