diff --git a/dom/canvas/CanvasPath.h b/dom/canvas/CanvasPath.h index e31b375cc3..0aa74d49ff 100644 --- a/dom/canvas/CanvasPath.h +++ b/dom/canvas/CanvasPath.h @@ -16,7 +16,7 @@ namespace mozilla { namespace dom { enum class CanvasWindingRule : uint32_t; -class SVGMatrix; +struct DOMMatrix2DInit; class CanvasPath final : public nsWrapperCache @@ -69,8 +69,8 @@ public: CanvasPath(nsISupports* aParent, already_AddRefed aPathBuilder); - void AddPath(CanvasPath& aCanvasPath, - const Optional>& aMatrix); + void AddPath(CanvasPath& aCanvasPath, const DOMMatrix2DInit& aInit, + ErrorResult& aError); private: virtual ~CanvasPath() {} diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index d8c3c4e135..f63338567d 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -80,6 +80,7 @@ #include "mozilla/CheckedInt.h" #include "mozilla/DebugOnly.h" #include "mozilla/dom/ContentParent.h" +#include "mozilla/dom/DOMMatrix.h" #include "mozilla/dom/ImageBitmap.h" #include "mozilla/dom/ImageData.h" #include "mozilla/dom/PBrowserParent.h" @@ -6579,19 +6580,28 @@ CanvasPath::BezierTo(const gfx::Point& aCP1, } void -CanvasPath::AddPath(CanvasPath& aCanvasPath, const Optional>& aMatrix) +CanvasPath::AddPath(CanvasPath& aCanvasPath, const DOMMatrix2DInit& aInit, + ErrorResult& aError) + { RefPtr tempPath = aCanvasPath.GetPath(CanvasWindingRule::Nonzero, gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()); - if (aMatrix.WasPassed()) { - const SVGMatrix& m = aMatrix.Value(); - Matrix transform(m.A(), m.B(), m.C(), m.D(), m.E(), m.F()); + RefPtr matrix = + DOMMatrixReadOnly::FromMatrix(GetParentObject(), aInit, aError); + if (aError.Failed()) { + return; + } - if (!transform.IsIdentity()) { - RefPtr tempBuilder = tempPath->TransformedCopyToBuilder(transform, FillRule::FILL_WINDING); - tempPath = tempBuilder->Finish(); - } + Matrix transform(*(matrix->GetInternal2D())); + + if (!transform.IsFinite()) { + return; + } + + if (!transform.IsIdentity()) { + RefPtr tempBuilder = tempPath->TransformedCopyToBuilder(transform, FillRule::FILL_WINDING); + tempPath = tempBuilder->Finish(); } EnsurePathBuilder(); // in case a path is added to itself diff --git a/dom/webidl/CanvasRenderingContext2D.webidl b/dom/webidl/CanvasRenderingContext2D.webidl index 1c55642152..fe48385d7a 100644 --- a/dom/webidl/CanvasRenderingContext2D.webidl +++ b/dom/webidl/CanvasRenderingContext2D.webidl @@ -335,6 +335,6 @@ interface TextMetrics { Constructor(DOMString pathString)] interface Path2D { - void addPath(Path2D path, optional SVGMatrix transformation); + [Throws] void addPath(Path2D path, optional DOMMatrix2DInit transformation); }; Path2D implements CanvasPathMethods;