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
;
23 UnrestrictedDoubleOrDOMPointInitOrUnrestrictedDoubleOrDOMPointInitSequence
;
25 class CanvasPath final
: public nsWrapperCache
{
27 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasPath
)
28 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CanvasPath
)
30 nsISupports
* GetParentObject() { return mParent
; }
32 JSObject
* WrapObject(JSContext
* aCx
,
33 JS::Handle
<JSObject
*> aGivenProto
) override
;
35 static already_AddRefed
<CanvasPath
> Constructor(const GlobalObject
& aGlobal
);
36 static already_AddRefed
<CanvasPath
> Constructor(const GlobalObject
& aGlobal
,
37 CanvasPath
& aCanvasPath
);
38 static already_AddRefed
<CanvasPath
> Constructor(
39 const GlobalObject
& aGlobal
, const nsACString
& aPathString
);
42 void MoveTo(double x
, double y
);
43 void LineTo(double x
, double y
);
44 void QuadraticCurveTo(double cpx
, double cpy
, double x
, double y
);
45 void BezierCurveTo(double cp1x
, double cp1y
, double cp2x
, double cp2y
,
47 void ArcTo(double x1
, double y1
, double x2
, double y2
, double radius
,
49 void Rect(double x
, double y
, double w
, double h
);
51 double aX
, double aY
, double aW
, double aH
,
52 const UnrestrictedDoubleOrDOMPointInitOrUnrestrictedDoubleOrDOMPointInitSequence
&
55 void Arc(double x
, double y
, double radius
, double startAngle
,
56 double endAngle
, bool anticlockwise
, ErrorResult
& error
);
57 void Ellipse(double x
, double y
, double radiusX
, double radiusY
,
58 double rotation
, double startAngle
, double endAngle
,
59 bool anticlockwise
, ErrorResult
& error
);
61 void LineTo(const gfx::Point
& aPoint
);
62 void BezierTo(const gfx::Point
& aCP1
, const gfx::Point
& aCP2
,
63 const gfx::Point
& aCP3
);
65 already_AddRefed
<gfx::Path
> GetPath(const CanvasWindingRule
& aWinding
,
66 const gfx::DrawTarget
* aTarget
) const;
68 explicit CanvasPath(nsISupports
* aParent
);
69 // already_AddRefed arg because the return value from Path::CopyToBuilder()
70 // is passed directly and we can't drop the only ref to have a raw pointer.
71 CanvasPath(nsISupports
* aParent
,
72 already_AddRefed
<gfx::PathBuilder
> aPathBuilder
);
74 void AddPath(CanvasPath
& aCanvasPath
, const DOMMatrix2DInit
& aInit
,
78 virtual ~CanvasPath() = default;
80 nsCOMPtr
<nsISupports
> mParent
;
81 static gfx::Float
ToFloat(double aValue
) { return gfx::Float(aValue
); }
83 mutable RefPtr
<gfx::Path
> mPath
;
84 mutable RefPtr
<gfx::PathBuilder
> mPathBuilder
;
86 // Whether an internal segment was zero-length.
87 mutable bool mPruned
= false;
89 void EnsurePathBuilder() const;
90 void EnsureCapped() const;
91 void EnsureActive() const;
95 } // namespace mozilla
97 #endif /* CanvasPath_h */