/src/mozilla-central/gfx/2d/PathCairo.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_PATH_CAIRO_H_ |
8 | | #define MOZILLA_GFX_PATH_CAIRO_H_ |
9 | | |
10 | | #include "2D.h" |
11 | | #include "cairo.h" |
12 | | #include <vector> |
13 | | |
14 | | namespace mozilla { |
15 | | namespace gfx { |
16 | | |
17 | | class PathCairo; |
18 | | |
19 | | class PathBuilderCairo : public PathBuilder |
20 | | { |
21 | | public: |
22 | | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo, override) |
23 | | |
24 | | explicit PathBuilderCairo(FillRule aFillRule); |
25 | | |
26 | | virtual void MoveTo(const Point &aPoint) override; |
27 | | virtual void LineTo(const Point &aPoint) override; |
28 | | virtual void BezierTo(const Point &aCP1, |
29 | | const Point &aCP2, |
30 | | const Point &aCP3) override; |
31 | | virtual void QuadraticBezierTo(const Point &aCP1, |
32 | | const Point &aCP2) override; |
33 | | virtual void Close() override; |
34 | | virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle, |
35 | | float aEndAngle, bool aAntiClockwise = false) override; |
36 | | virtual Point CurrentPoint() const override; |
37 | | virtual already_AddRefed<Path> Finish() override; |
38 | | |
39 | 0 | virtual BackendType GetBackendType() const override { return BackendType::CAIRO; } |
40 | | |
41 | | private: // data |
42 | | friend class PathCairo; |
43 | | |
44 | | FillRule mFillRule; |
45 | | std::vector<cairo_path_data_t> mPathData; |
46 | | // It's easiest to track this here, parsing the path data to find the current |
47 | | // point is a little tricky. |
48 | | Point mCurrentPoint; |
49 | | Point mBeginPoint; |
50 | | }; |
51 | | |
52 | | class PathCairo : public Path |
53 | | { |
54 | | public: |
55 | | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo, override) |
56 | | |
57 | | PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint); |
58 | | explicit PathCairo(cairo_t *aContext); |
59 | | ~PathCairo(); |
60 | | |
61 | 0 | virtual BackendType GetBackendType() const override { return BackendType::CAIRO; } |
62 | | |
63 | | virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const override; |
64 | | virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform, |
65 | | FillRule aFillRule) const override; |
66 | | |
67 | | virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const override; |
68 | | |
69 | | virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, |
70 | | const Point &aPoint, |
71 | | const Matrix &aTransform) const override; |
72 | | |
73 | | virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const override; |
74 | | |
75 | | virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, |
76 | | const Matrix &aTransform = Matrix()) const override; |
77 | | |
78 | | virtual void StreamToSink(PathSink *aSink) const override; |
79 | | |
80 | 0 | virtual FillRule GetFillRule() const override { return mFillRule; } |
81 | | |
82 | | void SetPathOnContext(cairo_t *aContext) const; |
83 | | |
84 | | void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const; |
85 | | private: |
86 | | void EnsureContainingContext(const Matrix &aTransform) const; |
87 | | |
88 | | FillRule mFillRule; |
89 | | std::vector<cairo_path_data_t> mPathData; |
90 | | mutable cairo_t *mContainingContext; |
91 | | mutable Matrix mContainingTransform; |
92 | | Point mCurrentPoint; |
93 | | }; |
94 | | |
95 | | } // namespace gfx |
96 | | } // namespace mozilla |
97 | | |
98 | | #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */ |