1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/Attributes.h"
9 #include "mozilla/RefPtr.h"
10 #include "nsWrapperCache.h"
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/dom/BindingDeclarations.h"
19 enum class CanvasWindingRule
: uint8_t;
20 struct DOMMatrix2DInit
;
22 class CanvasPath final
: public nsWrapperCache
{
24 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasPath
)
25 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasPath
)
27 nsCOMPtr
<nsISupports
> GetParentObject() { return mParent
; }
29 JSObject
* WrapObject(JSContext
* aCx
,
30 JS::Handle
<JSObject
*> aGivenProto
) override
;
32 static already_AddRefed
<CanvasPath
> Constructor(const GlobalObject
& aGlobal
);
33 static already_AddRefed
<CanvasPath
> Constructor(const GlobalObject
& aGlobal
,
34 CanvasPath
& aCanvasPath
);
35 static already_AddRefed
<CanvasPath
> Constructor(const GlobalObject
& aGlobal
,
36 const nsAString
& aPathString
);
39 void MoveTo(double x
, double y
);
40 void LineTo(double x
, double y
);
41 void QuadraticCurveTo(double cpx
, double cpy
, double x
, double y
);
42 void BezierCurveTo(double cp1x
, double cp1y
, double cp2x
, double cp2y
,
44 void ArcTo(double x1
, double y1
, double x2
, double y2
, double radius
,
46 void Rect(double x
, double y
, double w
, double h
);
47 void Arc(double x
, double y
, double radius
, double startAngle
,
48 double endAngle
, bool anticlockwise
, ErrorResult
& error
);
49 void Ellipse(double x
, double y
, double radiusX
, double radiusY
,
50 double rotation
, double startAngle
, double endAngle
,
51 bool anticlockwise
, ErrorResult
& error
);
53 void LineTo(const gfx::Point
& aPoint
);
54 void BezierTo(const gfx::Point
& aCP1
, const gfx::Point
& aCP2
,
55 const gfx::Point
& aCP3
);
57 already_AddRefed
<gfx::Path
> GetPath(const CanvasWindingRule
& aWinding
,
58 const gfx::DrawTarget
* aTarget
) const;
60 explicit CanvasPath(nsISupports
* aParent
);
61 // already_AddRefed arg because the return value from Path::CopyToBuilder()
62 // is passed directly and we can't drop the only ref to have a raw pointer.
63 CanvasPath(nsISupports
* aParent
,
64 already_AddRefed
<gfx::PathBuilder
> aPathBuilder
);
66 void AddPath(CanvasPath
& aCanvasPath
, const DOMMatrix2DInit
& aInit
,
70 virtual ~CanvasPath() = default;
72 nsCOMPtr
<nsISupports
> mParent
;
73 static gfx::Float
ToFloat(double aValue
) { return gfx::Float(aValue
); }
75 mutable RefPtr
<gfx::Path
> mPath
;
76 mutable RefPtr
<gfx::PathBuilder
> mPathBuilder
;
78 void EnsurePathBuilder() const;
82 } // namespace mozilla
84 #endif /* CanvasPath_h */