1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_PATH_CAIRO_H_
8 #define MOZILLA_GFX_PATH_CAIRO_H_
19 class PathBuilderCairo
: public PathBuilder
{
21 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo
, override
)
23 explicit PathBuilderCairo(FillRule aFillRule
);
25 void MoveTo(const Point
& aPoint
) override
;
26 void LineTo(const Point
& aPoint
) override
;
27 void BezierTo(const Point
& aCP1
, const Point
& aCP2
,
28 const Point
& aCP3
) override
;
29 void QuadraticBezierTo(const Point
& aCP1
, const Point
& aCP2
) override
;
30 void Close() override
;
31 void Arc(const Point
& aOrigin
, float aRadius
, float aStartAngle
,
32 float aEndAngle
, bool aAntiClockwise
= false) override
;
33 already_AddRefed
<Path
> Finish() override
;
35 BackendType
GetBackendType() const override
{ return BackendType::CAIRO
; }
37 bool IsActive() const override
{ return !mPathData
.empty(); }
39 static already_AddRefed
<PathBuilder
> Create(FillRule aFillRule
);
42 friend class PathCairo
;
45 std::vector
<cairo_path_data_t
> mPathData
;
48 class PathCairo
: public Path
{
50 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo
, override
)
52 PathCairo(FillRule aFillRule
, std::vector
<cairo_path_data_t
>& aPathData
,
53 const Point
& aCurrentPoint
, const Point
& aBeginPoint
);
54 explicit PathCairo(cairo_t
* aContext
);
57 BackendType
GetBackendType() const override
{ return BackendType::CAIRO
; }
59 already_AddRefed
<PathBuilder
> CopyToBuilder(
60 FillRule aFillRule
) const override
;
61 already_AddRefed
<PathBuilder
> TransformedCopyToBuilder(
62 const Matrix
& aTransform
, FillRule aFillRule
) const override
;
64 bool ContainsPoint(const Point
& aPoint
,
65 const Matrix
& aTransform
) const override
;
67 bool StrokeContainsPoint(const StrokeOptions
& aStrokeOptions
,
69 const Matrix
& aTransform
) const override
;
71 Rect
GetBounds(const Matrix
& aTransform
= Matrix()) const override
;
73 Rect
GetStrokedBounds(const StrokeOptions
& aStrokeOptions
,
74 const Matrix
& aTransform
= Matrix()) const override
;
76 void StreamToSink(PathSink
* aSink
) const override
;
78 FillRule
GetFillRule() const override
{ return mFillRule
; }
80 void SetPathOnContext(cairo_t
* aContext
) const;
82 void AppendPathToBuilder(PathBuilderCairo
* aBuilder
,
83 const Matrix
* aTransform
= nullptr) const;
85 bool IsEmpty() const override
;
88 void EnsureContainingContext(const Matrix
& aTransform
) const;
91 std::vector
<cairo_path_data_t
> mPathData
;
92 mutable cairo_t
* mContainingContext
;
93 mutable Matrix mContainingTransform
;
99 } // namespace mozilla
101 #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */