Bug 1318573 - (Part 10) Move CanvasPath to BasicRenderingContext2D. r?mstange draft
authorKevin Chen <kechen@mozilla.com>
Fri, 17 Feb 2017 16:30:39 +0800
changeset 499863 2db0dd1b074cb148ee576f3ffd97b47f06fccbcd
parent 499862 4caf7dd998e12aa359732ea2a5fd582f0c2e6671
child 499864 6ff5325752ff8e1c92559d055385ce2b653e50a5
push id49564
push userbmo:kechen@mozilla.com
push dateThu, 16 Mar 2017 09:50:15 +0000
reviewersmstange
bugs1318573
milestone54.0a1
Bug 1318573 - (Part 10) Move CanvasPath to BasicRenderingContext2D. r?mstange MozReview-Commit-ID: Fwg5DPIpW3g
dom/canvas/BasicRenderingContext2D.cpp
dom/canvas/BasicRenderingContext2D.h
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/CanvasRenderingContext2D.h
--- a/dom/canvas/BasicRenderingContext2D.cpp
+++ b/dom/canvas/BasicRenderingContext2D.cpp
@@ -6,32 +6,35 @@
 #include "AdjustedTarget.h"
 #include "CanvasUtils.h"
 #include "gfxUtils.h"
 #include "mozilla/dom/BasicRenderingContext2D.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/ImageBitmap.h"
+#include "mozilla/gfx/PathHelpers.h"
 #include "nsContentUtils.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "nsPrintfCString.h"
 #include "nsStyleUtil.h"
 
 using mozilla::CanvasUtils::FloatValidate;
 using mozilla::gfx::AntialiasMode;
+using mozilla::gfx::ArcToBezier;
 using mozilla::gfx::CapStyle;
 using mozilla::gfx::Color;
 using mozilla::gfx::DrawOptions;
 using mozilla::gfx::ExtendMode;
 using mozilla::gfx::FillRule;
 using mozilla::gfx::JoinStyle;
 using mozilla::gfx::IntSize;
 using mozilla::gfx::Path;
 using mozilla::gfx::SamplingFilter;
+using mozilla::gfx::Size;
 using mozilla::gfx::SourceSurface;
 using mozilla::gfx::StrokeOptions;
 using mozilla::gfx::ToDeviceColor;
 
 namespace mozilla {
 namespace dom{
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(CanvasGradient, AddRef)
@@ -971,16 +974,145 @@ bool BasicRenderingContext2D::IsPointInS
                               state.dash.Length(),
                               state.dash.Elements(),
                               state.dashOffset);
 
   return tempPath->StrokeContainsPoint(strokeOptions, Point(aX, aY), mTarget->GetTransform());
 }
 
 void
+BasicRenderingContext2D::ArcTo(double aX1, double aY1, double aX2,
+                               double aY2, double aRadius,
+                               ErrorResult& aError)
+{
+  if (aRadius < 0) {
+    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
+  }
+
+  EnsureWritablePath();
+
+  // Current point in user space!
+  Point p0;
+  if (mPathBuilder) {
+    p0 = mPathBuilder->CurrentPoint();
+  } else {
+    Matrix invTransform = mTarget->GetTransform();
+    if (!invTransform.Invert()) {
+      return;
+    }
+
+    p0 = invTransform.TransformPoint(mDSPathBuilder->CurrentPoint());
+  }
+
+  Point p1(aX1, aY1);
+  Point p2(aX2, aY2);
+
+  // Execute these calculations in double precision to avoid cumulative
+  // rounding errors.
+  double dir, a2, b2, c2, cosx, sinx, d, anx, any,
+         bnx, bny, x3, y3, x4, y4, cx, cy, angle0, angle1;
+  bool anticlockwise;
+
+  if (p0 == p1 || p1 == p2 || aRadius == 0) {
+    LineTo(p1.x, p1.y);
+    return;
+  }
+
+  // Check for colinearity
+  dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x);
+  if (dir == 0) {
+    LineTo(p1.x, p1.y);
+    return;
+  }
+
+
+  // XXX - Math for this code was already available from the non-azure code
+  // and would be well tested. Perhaps converting to bezier directly might
+  // be more efficient longer run.
+  a2 = (p0.x-aX1)*(p0.x-aX1) + (p0.y-aY1)*(p0.y-aY1);
+  b2 = (aX1-aX2)*(aX1-aX2) + (aY1-aY2)*(aY1-aY2);
+  c2 = (p0.x-aX2)*(p0.x-aX2) + (p0.y-aY2)*(p0.y-aY2);
+  cosx = (a2+b2-c2)/(2*sqrt(a2*b2));
+
+  sinx = sqrt(1 - cosx*cosx);
+  d = aRadius / ((1 - cosx) / sinx);
+
+  anx = (aX1-p0.x) / sqrt(a2);
+  any = (aY1-p0.y) / sqrt(a2);
+  bnx = (aX1-aX2) / sqrt(b2);
+  bny = (aY1-aY2) / sqrt(b2);
+  x3 = aX1 - anx*d;
+  y3 = aY1 - any*d;
+  x4 = aX1 - bnx*d;
+  y4 = aY1 - bny*d;
+  anticlockwise = (dir < 0);
+  cx = x3 + any*aRadius*(anticlockwise ? 1 : -1);
+  cy = y3 - anx*aRadius*(anticlockwise ? 1 : -1);
+  angle0 = atan2((y3-cy), (x3-cx));
+  angle1 = atan2((y4-cy), (x4-cx));
+
+
+  LineTo(x3, y3);
+
+  Arc(cx, cy, aRadius, angle0, angle1, anticlockwise, aError);
+}
+
+void
+BasicRenderingContext2D::Arc(double aX, double aY, double aR,
+                             double aStartAngle, double aEndAngle,
+                             bool aAnticlockwise, ErrorResult& aError)
+{
+  if (aR < 0.0) {
+    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
+  }
+
+  EnsureWritablePath();
+
+  ArcToBezier(this, Point(aX, aY), Size(aR, aR), aStartAngle, aEndAngle, aAnticlockwise);
+}
+
+void
+BasicRenderingContext2D::Rect(double aX, double aY, double aW, double aH)
+{
+  EnsureWritablePath();
+
+  if (mPathBuilder) {
+    mPathBuilder->MoveTo(Point(aX, aY));
+    mPathBuilder->LineTo(Point(aX + aW, aY));
+    mPathBuilder->LineTo(Point(aX + aW, aY + aH));
+    mPathBuilder->LineTo(Point(aX, aY + aH));
+    mPathBuilder->Close();
+  } else {
+    mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(Point(aX, aY)));
+    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX + aW, aY)));
+    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX + aW, aY + aH)));
+    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX, aY + aH)));
+    mDSPathBuilder->Close();
+  }
+}
+
+void
+BasicRenderingContext2D::Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
+                                 double aRotation, double aStartAngle, double aEndAngle,
+                                 bool aAnticlockwise, ErrorResult& aError)
+{
+  if (aRadiusX < 0.0 || aRadiusY < 0.0) {
+    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
+  }
+
+  EnsureWritablePath();
+
+  ArcToBezier(this, Point(aX, aY), Size(aRadiusX, aRadiusY), aStartAngle, aEndAngle,
+              aAnticlockwise, aRotation);
+}
+
+void
 BasicRenderingContext2D::TransformWillUpdate()
 {
   EnsureTarget();
 
   // Store the matrix that would transform the current path to device
   // space.
   if (mPath || mPathBuilder) {
     if (!mPathTransformWillUpdate) {
@@ -1041,16 +1173,52 @@ BasicRenderingContext2D::EnsureUserSpace
     mPathBuilder = mPath->CopyToBuilder(fillRule);
     mPath = mPathBuilder->Finish();
     mPathBuilder = nullptr;
   }
 
   NS_ASSERTION(mPath, "mPath should exist");
 }
 
+void
+BasicRenderingContext2D::EnsureWritablePath()
+{
+  EnsureTarget();
+
+  if (mDSPathBuilder) {
+    return;
+  }
+
+  FillRule fillRule = CurrentState().fillRule;
+
+  if (mPathBuilder) {
+    if (mPathTransformWillUpdate) {
+      mPath = mPathBuilder->Finish();
+      mDSPathBuilder =
+        mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
+      mPath = nullptr;
+      mPathBuilder = nullptr;
+      mPathTransformWillUpdate = false;
+    }
+    return;
+  }
+
+  if (!mPath) {
+    NS_ASSERTION(!mPathTransformWillUpdate, "mPathTransformWillUpdate should be false, if all paths are null");
+    mPathBuilder = mTarget->CreatePathBuilder(fillRule);
+  } else if (!mPathTransformWillUpdate) {
+    mPathBuilder = mPath->CopyToBuilder(fillRule);
+  } else {
+    mDSPathBuilder =
+      mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
+    mPathTransformWillUpdate = false;
+    mPath = nullptr;
+  }
+}
+
 //
 // line caps/joins
 //
 
 void
 BasicRenderingContext2D::SetLineCap(const nsAString& aLinecapStyle)
 {
   CapStyle cap;
--- a/dom/canvas/BasicRenderingContext2D.h
+++ b/dom/canvas/BasicRenderingContext2D.h
@@ -52,16 +52,39 @@ public:
   // sErrorTarget.
   RefPtr<DrawTarget> mTarget;
 
   // this rect is in mTarget's current user space
   virtual void RedrawUser(const gfxRect& aR) = 0;
 
   virtual nsresult Redraw() = 0;
 
+  void LineTo(const mozilla::gfx::Point& aPoint)
+  {
+    if (mPathBuilder) {
+      mPathBuilder->LineTo(aPoint);
+    } else {
+      mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(aPoint));
+    }
+  }
+
+  void BezierTo(const mozilla::gfx::Point& aCP1,
+                const mozilla::gfx::Point& aCP2,
+                const mozilla::gfx::Point& aCP3)
+  {
+    if (mPathBuilder) {
+      mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
+    } else {
+      mozilla::gfx::Matrix transform = mTarget->GetTransform();
+      mDSPathBuilder->BezierTo(transform.TransformPoint(aCP1),
+                               transform.TransformPoint(aCP2),
+                               transform.TransformPoint(aCP3));
+    }
+  }
+
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_BASICRENDERINGCONTEXT2D_IID)
 protected:
   virtual ~BasicRenderingContext2D() {}
 public:
   explicit BasicRenderingContext2D(layers::LayersBackend aCompositorBackend)
     // these are the default values from the Canvas spec
     : mWidth(0), mHeight(0)
     , mPathTransformWillUpdate(false) {}
@@ -283,52 +306,82 @@ public:
   void GetLineDash(nsTArray<double>& aSegments) const;
 
   void SetLineDashOffset(double aOffset);
   double LineDashOffset() const;
 
   //
   // CanvasPath
   //
-  virtual void ClosePath() = 0;
-  virtual void MoveTo(double aX, double aY) = 0;
-  virtual void LineTo(double aX, double aY) = 0;
-  virtual void QuadraticCurveTo(double aCpx,
-                                double aCpy,
-                                double aX,
-                                double aY) = 0;
-  virtual void BezierCurveTo(double aCp1x,
-                             double aCp1y,
-                             double aCp2x,
-                             double aCp2y,
-                             double aX,
-                             double aY) = 0;
-  virtual void ArcTo(double aX1,
-                     double aY1,
-                     double aX2,
-                     double aY2,
-                     double aRadius,
-                     mozilla::ErrorResult& aError) = 0;
-  virtual void Rect(double aX, double aY, double aW, double aH) = 0;
-  virtual void Arc(double aX,
-                   double aY,
-                   double aRadius,
-                   double aStartAngle,
-                   double aEndAngle,
-                   bool aAnticlockwise,
-                   mozilla::ErrorResult& aError) = 0;
-  virtual void Ellipse(double aX,
-                       double aY,
-                       double aRadiusX,
-                       double aRadiusY,
-                       double aRotation,
-                       double aStartAngle,
-                       double aEndAngle,
-                       bool aAnticlockwise,
-                       ErrorResult& aError) = 0;
+  void ClosePath()
+  {
+    EnsureWritablePath();
+
+    if (mPathBuilder) {
+      mPathBuilder->Close();
+    } else {
+      mDSPathBuilder->Close();
+    }
+  }
+
+  void MoveTo(double aX, double aY)
+  {
+    EnsureWritablePath();
+
+    if (mPathBuilder) {
+      mPathBuilder->MoveTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
+    } else {
+      mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(
+                             mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
+    }
+  }
+
+  void LineTo(double aX, double aY)
+  {
+    EnsureWritablePath();
+
+    LineTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
+  }
+
+  void QuadraticCurveTo(double aCpx, double aCpy, double aX, double aY)
+  {
+    EnsureWritablePath();
+
+    if (mPathBuilder) {
+      mPathBuilder->QuadraticBezierTo(mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy)),
+                                      mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
+    } else {
+      mozilla::gfx::Matrix transform = mTarget->GetTransform();
+      mDSPathBuilder->QuadraticBezierTo(transform.TransformPoint(
+                                          mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy))),
+                                        transform.TransformPoint(
+                                          mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
+    }
+  }
+
+  void BezierCurveTo(double aCp1x, double aCp1y, double aCp2x, double aCp2y,
+                     double aX, double aY)
+  {
+    EnsureWritablePath();
+
+    BezierTo(mozilla::gfx::Point(ToFloat(aCp1x), ToFloat(aCp1y)),
+             mozilla::gfx::Point(ToFloat(aCp2x), ToFloat(aCp2y)),
+             mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
+  }
+
+  void ArcTo(double aX1, double aY1, double aX2, double aY2,
+             double aRadius, mozilla::ErrorResult& aError);
+  void Rect(double aX, double aY, double aW, double aH);
+  void Arc(double aX, double aY, double aRadius, double aStartAngle,
+           double aEndAngle, bool aAnticlockwise,
+           mozilla::ErrorResult& aError);
+  void Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
+               double aRotation, double aStartAngle, double aEndAngle,
+               bool aAnticlockwise, ErrorResult& aError);
+
 protected:
   friend class CanvasGeneralPattern;
   friend class AdjustedTarget;
   friend class AdjustedTargetForShadow;
   friend class AdjustedTargetForFilter;
 
   enum class Style : uint8_t {
     STROKE = 0,
@@ -674,16 +727,23 @@ protected:
 
   bool NeedToCalculateBounds()
   {
     return NeedToDrawShadow() || NeedToApplyFilter();
   }
 
   // Ensures a path in UserSpace is available.
   void EnsureUserSpacePath(const CanvasWindingRule& aWinding = CanvasWindingRule::Nonzero);
+
+  /* This function ensures there is a writable pathbuilder available, this
+   * pathbuilder may be working in user space or in device space or
+   * device space.
+   * After calling this function mPathTransformWillUpdate will be false
+   */
+  void EnsureWritablePath();
 };
 
  NS_DEFINE_STATIC_IID_ACCESSOR(BasicRenderingContext2D,
                                NS_BASICRENDERINGCONTEXT2D_IID)
 
 // This class is named 'GeneralCanvasPattern' instead of just
 // 'GeneralPattern' to keep Windows PGO builds from confusing the
 // GeneralPattern class in gfxContext.cpp with this one.
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2077,181 +2077,16 @@ bool CanvasRenderingContext2D::DrawCusto
         return window->ShouldShowFocusRing();
       }
     }
   }
 
   return false;
 }
 
-void
-CanvasRenderingContext2D::ArcTo(double aX1, double aY1, double aX2,
-                                double aY2, double aRadius,
-                                ErrorResult& aError)
-{
-  if (aRadius < 0) {
-    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    return;
-  }
-
-  EnsureWritablePath();
-
-  // Current point in user space!
-  Point p0;
-  if (mPathBuilder) {
-    p0 = mPathBuilder->CurrentPoint();
-  } else {
-    Matrix invTransform = mTarget->GetTransform();
-    if (!invTransform.Invert()) {
-      return;
-    }
-
-    p0 = invTransform.TransformPoint(mDSPathBuilder->CurrentPoint());
-  }
-
-  Point p1(aX1, aY1);
-  Point p2(aX2, aY2);
-
-  // Execute these calculations in double precision to avoid cumulative
-  // rounding errors.
-  double dir, a2, b2, c2, cosx, sinx, d, anx, any,
-         bnx, bny, x3, y3, x4, y4, cx, cy, angle0, angle1;
-  bool anticlockwise;
-
-  if (p0 == p1 || p1 == p2 || aRadius == 0) {
-    LineTo(p1.x, p1.y);
-    return;
-  }
-
-  // Check for colinearity
-  dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x);
-  if (dir == 0) {
-    LineTo(p1.x, p1.y);
-    return;
-  }
-
-
-  // XXX - Math for this code was already available from the non-azure code
-  // and would be well tested. Perhaps converting to bezier directly might
-  // be more efficient longer run.
-  a2 = (p0.x-aX1)*(p0.x-aX1) + (p0.y-aY1)*(p0.y-aY1);
-  b2 = (aX1-aX2)*(aX1-aX2) + (aY1-aY2)*(aY1-aY2);
-  c2 = (p0.x-aX2)*(p0.x-aX2) + (p0.y-aY2)*(p0.y-aY2);
-  cosx = (a2+b2-c2)/(2*sqrt(a2*b2));
-
-  sinx = sqrt(1 - cosx*cosx);
-  d = aRadius / ((1 - cosx) / sinx);
-
-  anx = (aX1-p0.x) / sqrt(a2);
-  any = (aY1-p0.y) / sqrt(a2);
-  bnx = (aX1-aX2) / sqrt(b2);
-  bny = (aY1-aY2) / sqrt(b2);
-  x3 = aX1 - anx*d;
-  y3 = aY1 - any*d;
-  x4 = aX1 - bnx*d;
-  y4 = aY1 - bny*d;
-  anticlockwise = (dir < 0);
-  cx = x3 + any*aRadius*(anticlockwise ? 1 : -1);
-  cy = y3 - anx*aRadius*(anticlockwise ? 1 : -1);
-  angle0 = atan2((y3-cy), (x3-cx));
-  angle1 = atan2((y4-cy), (x4-cx));
-
-
-  LineTo(x3, y3);
-
-  Arc(cx, cy, aRadius, angle0, angle1, anticlockwise, aError);
-}
-
-void
-CanvasRenderingContext2D::Arc(double aX, double aY, double aR,
-                              double aStartAngle, double aEndAngle,
-                              bool aAnticlockwise, ErrorResult& aError)
-{
-  if (aR < 0.0) {
-    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    return;
-  }
-
-  EnsureWritablePath();
-
-  ArcToBezier(this, Point(aX, aY), Size(aR, aR), aStartAngle, aEndAngle, aAnticlockwise);
-}
-
-void
-CanvasRenderingContext2D::Rect(double aX, double aY, double aW, double aH)
-{
-  EnsureWritablePath();
-
-  if (mPathBuilder) {
-    mPathBuilder->MoveTo(Point(aX, aY));
-    mPathBuilder->LineTo(Point(aX + aW, aY));
-    mPathBuilder->LineTo(Point(aX + aW, aY + aH));
-    mPathBuilder->LineTo(Point(aX, aY + aH));
-    mPathBuilder->Close();
-  } else {
-    mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(Point(aX, aY)));
-    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX + aW, aY)));
-    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX + aW, aY + aH)));
-    mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(Point(aX, aY + aH)));
-    mDSPathBuilder->Close();
-  }
-}
-
-void
-CanvasRenderingContext2D::Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
-                                  double aRotation, double aStartAngle, double aEndAngle,
-                                  bool aAnticlockwise, ErrorResult& aError)
-{
-  if (aRadiusX < 0.0 || aRadiusY < 0.0) {
-    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    return;
-  }
-
-  EnsureWritablePath();
-
-  ArcToBezier(this, Point(aX, aY), Size(aRadiusX, aRadiusY), aStartAngle, aEndAngle,
-              aAnticlockwise, aRotation);
-}
-
-void
-CanvasRenderingContext2D::EnsureWritablePath()
-{
-  EnsureTarget();
-
-  if (mDSPathBuilder) {
-    return;
-  }
-
-  FillRule fillRule = CurrentState().fillRule;
-
-  if (mPathBuilder) {
-    if (mPathTransformWillUpdate) {
-      mPath = mPathBuilder->Finish();
-      mDSPathBuilder =
-        mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
-      mPath = nullptr;
-      mPathBuilder = nullptr;
-      mPathTransformWillUpdate = false;
-    }
-    return;
-  }
-
-  if (!mPath) {
-    NS_ASSERTION(!mPathTransformWillUpdate, "mPathTransformWillUpdate should be false, if all paths are null");
-    mPathBuilder = mTarget->CreatePathBuilder(fillRule);
-  } else if (!mPathTransformWillUpdate) {
-    mPathBuilder = mPath->CopyToBuilder(fillRule);
-  } else {
-    mDSPathBuilder =
-      mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
-    mPathTransformWillUpdate = false;
-    mPath = nullptr;
-  }
-}
-
 //
 // text
 //
 
 void
 CanvasRenderingContext2D::SetFont(const nsAString& aFont,
                                   ErrorResult& aError)
 {
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -139,82 +139,16 @@ public:
   }
 
   void SetFont(const nsAString& aFont, mozilla::ErrorResult& aError);
   void GetTextAlign(nsAString& aTextAlign);
   void SetTextAlign(const nsAString& aTextAlign);
   void GetTextBaseline(nsAString& aTextBaseline);
   void SetTextBaseline(const nsAString& aTextBaseline);
 
-  void ClosePath() override
-  {
-    EnsureWritablePath();
-
-    if (mPathBuilder) {
-      mPathBuilder->Close();
-    } else {
-      mDSPathBuilder->Close();
-    }
-  }
-
-  void MoveTo(double aX, double aY) override
-  {
-    EnsureWritablePath();
-
-    if (mPathBuilder) {
-      mPathBuilder->MoveTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
-    } else {
-      mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(
-                             mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
-    }
-  }
-
-  void LineTo(double aX, double aY) override
-  {
-    EnsureWritablePath();
-
-    LineTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
-  }
-
-  void QuadraticCurveTo(double aCpx, double aCpy, double aX, double aY) override
-  {
-    EnsureWritablePath();
-
-    if (mPathBuilder) {
-      mPathBuilder->QuadraticBezierTo(mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy)),
-                                      mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
-    } else {
-      mozilla::gfx::Matrix transform = mTarget->GetTransform();
-      mDSPathBuilder->QuadraticBezierTo(transform.TransformPoint(
-                                          mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy))),
-                                        transform.TransformPoint(
-                                          mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
-    }
-  }
-
-  void BezierCurveTo(double aCp1x, double aCp1y, double aCp2x, double aCp2y,
-                     double aX, double aY) override
-  {
-    EnsureWritablePath();
-
-    BezierTo(mozilla::gfx::Point(ToFloat(aCp1x), ToFloat(aCp1y)),
-             mozilla::gfx::Point(ToFloat(aCp2x), ToFloat(aCp2y)),
-             mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
-  }
-
-  void ArcTo(double aX1, double aY1, double aX2, double aY2,
-             double aRadius, mozilla::ErrorResult& aError) override;
-  void Rect(double aX, double aY, double aW, double aH) override;
-  void Arc(double aX, double aY, double aRadius, double aStartAngle,
-           double aEndAngle, bool aAnticlockwise,
-           mozilla::ErrorResult& aError) override;
-  void Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
-               double aRotation, double aStartAngle, double aEndAngle,
-               bool aAnticlockwise, ErrorResult& aError) override;
-
   void GetMozCurrentTransform(JSContext* aCx,
                               JS::MutableHandle<JSObject*> aResult,
                               mozilla::ErrorResult& aError);
   void SetMozCurrentTransform(JSContext* aCx,
                               JS::Handle<JSObject*> aCurrentTransform,
                               mozilla::ErrorResult& aError);
   void GetMozCurrentTransformInverse(JSContext* aCx,
                                      JS::MutableHandle<JSObject*> aResult,
@@ -322,39 +256,16 @@ public:
     GRADIENT = 2
   };
 
   nsINode* GetParentObject()
   {
     return mCanvasElement;
   }
 
-  void LineTo(const mozilla::gfx::Point& aPoint)
-  {
-    if (mPathBuilder) {
-      mPathBuilder->LineTo(aPoint);
-    } else {
-      mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(aPoint));
-    }
-  }
-
-  void BezierTo(const mozilla::gfx::Point& aCP1,
-                const mozilla::gfx::Point& aCP2,
-                const mozilla::gfx::Point& aCP3)
-  {
-    if (mPathBuilder) {
-      mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
-    } else {
-      mozilla::gfx::Matrix transform = mTarget->GetTransform();
-      mDSPathBuilder->BezierTo(transform.TransformPoint(aCP1),
-                               transform.TransformPoint(aCP2),
-                               transform.TransformPoint(aCP3));
-    }
-  }
-
   friend class CanvasRenderingContext2DUserData;
 
   virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
 
 
   // Given a point, return hit region ID if it exists
   nsString GetHitRegion(const mozilla::gfx::Point& aPoint) override;
 
@@ -414,23 +325,16 @@ protected:
   bool SetFontInternal(const nsAString& aFont, mozilla::ErrorResult& aError);
 
 
   /**
    * Creates the error target, if it doesn't exist
    */
   static void EnsureErrorTarget();
 
-  /* This function ensures there is a writable pathbuilder available, this
-   * pathbuilder may be working in user space or in device space or
-   * device space.
-   * After calling this function mPathTransformWillUpdate will be false
-   */
-  void EnsureWritablePath();
-
   // Report the fillRule has changed.
   void FillRuleChanged();
 
   /**
    * Create the backing surfacing, if it doesn't exist. If there is an error
    * in creating the target then it will put sErrorTarget in place. If there
    * is in turn an error in creating the sErrorTarget then they would both
    * be null so IsTargetValid() would still return null.