| Flutter Impeller |

stroke_path_geometry.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_ENTITY_GEOMETRY_STROKE_PATH_GEOMETRY_H_
6 #define FLUTTER_IMPELLER_ENTITY_GEOMETRY_STROKE_PATH_GEOMETRY_H_
7
8 #include "impeller/entity/geometry/geometry.h"
9 #include "impeller/geometry/dashed_line_path_source.h"
10 #include "impeller/geometry/matrix.h"
11 #include "impeller/geometry/path_source.h"
12 #include "impeller/geometry/stroke_parameters.h"
13 #include "impeller/tessellator/path_tessellator.h"
14
15 namespace impeller {
16
17 /// @brief A |SegmentReceiver| that also accepts Arc segments for optimal
18 /// handling. A path or |PathSource| will typically represent such
19 /// curves using Conic segments which are harder to iterate.
20 class PathAndArcSegmentReceiver : public PathTessellator::SegmentReceiver {
21 public:
22 virtual void RecordArc(const Arc& arc,
23 const Point center,
24 const Size radii) = 0;
25 };
26
27 /// @brief An abstract Geometry base class that produces fillable vertices
28 /// representing the stroked outline of the segments provided by
29 /// the subclass in the virtual |Dispatch| method.
30 ///
31 /// Most subclasses will be based on an instance of |PathSource| and use the
32 /// |StrokePathSourceGeometry| subclass to feed the segments from that path
33 /// source object, but some subclasses may be able to operate more optimally
34 /// by talking directly to the |StrokePathSegmentReceiver| (mainly arcs).
35 class StrokeSegmentsGeometry : public Geometry {
36 public:
37 ~StrokeSegmentsGeometry() override;
38
39 Scalar GetStrokeWidth() const;
40
41 Scalar GetMiterLimit() const;
42
43 Cap GetStrokeCap() const;
44
45 Join GetStrokeJoin() const;
46
47 Scalar ComputeAlphaCoverage(const Matrix& transform) const override;
48
49 protected:
50 explicit StrokeSegmentsGeometry(const StrokeParameters& parameters);
51
52 /// Dispatch the path segments to the StrokePathSegmentReceiver for
53 /// the provided transform scale.
54 virtual void Dispatch(PathAndArcSegmentReceiver& receiver,
55 Tessellator& tessellator,
56 Scalar scale) const = 0;
57
58 /// Provide the stroke-padded bounds for the provided bounds of the
59 /// segments themselves.
60 std::optional<Rect> GetStrokeCoverage(const Matrix& transform,
61 const Rect& segment_bounds) const;
62
63 private:
64 // |Geometry|
65 GeometryResult GetPositionBuffer(const ContentContext& renderer,
66 const Entity& entity,
67 RenderPass& pass) const override;
68
69 // |Geometry|
70 GeometryResult::Mode GetResultMode() const override;
71
72 // Private for benchmarking and debugging
73 static std::vector<Point> GenerateSolidStrokeVertices(
74 Tessellator& tessellator,
75 const PathSource& source,
76 const StrokeParameters& stroke,
77 Scalar scale);
78
79 friend class ImpellerBenchmarkAccessor;
80 friend class ImpellerEntityUnitTestAccessor;
81
82 bool SkipRendering() const;
83
84 const StrokeParameters stroke_;
85
86 StrokeSegmentsGeometry(const StrokeSegmentsGeometry&) = delete;
87
88 StrokeSegmentsGeometry& operator=(const StrokeSegmentsGeometry&) = delete;
89 };
90
91 /// @brief An abstract Geometry base class that produces fillable vertices
92 /// representing the stroked outline from any |PathSource| provided
93 /// by the subclass.
94 class StrokePathSourceGeometry : public StrokeSegmentsGeometry {
95 protected:
96 explicit StrokePathSourceGeometry(const StrokeParameters& parameters);
97
98 /// The PathSource object that will be iterated to produce the raw
99 /// vertices to be stroked.
100 virtual const PathSource& GetSource() const = 0;
101
102 // |Geometry|
103 std::optional<Rect> GetCoverage(const Matrix& transform) const override;
104
105 // |StrokeSegmentsGeometry|
106 void Dispatch(PathAndArcSegmentReceiver& receiver,
107 Tessellator& tessellator,
108 Scalar scale) const override;
109 };
110
111 /// @brief A Geometry that produces fillable vertices representing the
112 /// stroked outline of a |DlPath| object using the
113 /// |StrokePathSourceGeometry| base class and a |DlPath| object
114 /// to perform path iteration.
115 class StrokePathGeometry final : public StrokePathSourceGeometry {
116 public:
117 StrokePathGeometry(const flutter::DlPath& path,
118 const StrokeParameters& parameters);
119
120 protected:
121 // |StrokePathSourceGeometry|
122 const PathSource& GetSource() const override;
123
124 private:
125 const flutter::DlPath path_;
126 };
127
128 /// @brief A Geometry that produces fillable vertices representing the
129 /// stroked outline of an |Arc| object using the base class
130 /// |StrokeSegmentsGeometry| and utilizing the special |RecordArc|
131 /// extension method provided by the |PathAndArcSegmentReceiver|.
132 class ArcStrokeGeometry final : public StrokeSegmentsGeometry {
133 public:
134 ArcStrokeGeometry(const Arc& arc, const StrokeParameters& parameters);
135
136 protected:
137 // |Geometry|
138 std::optional<Rect> GetCoverage(const Matrix& transform) const override;
139
140 // |StrokeSegmentsGeometry|
141 void Dispatch(PathAndArcSegmentReceiver& receiver,
142 Tessellator& tessellator,
143 Scalar scale) const override;
144
145 private:
146 const Arc arc_;
147 };
148
149 /// @brief A Geometry that produces fillable vertices representing the
150 /// stroked outline of a pair of nested |RoundRect| objects using
151 /// the |StrokePathSourceGeometry| base class.
152 class StrokeDiffRoundRectGeometry final : public StrokePathSourceGeometry {
153 public:
154 explicit StrokeDiffRoundRectGeometry(const RoundRect& outer,
155 const RoundRect& inner,
156 const StrokeParameters& parameters);
157
158 protected:
159 // |StrokePathSourceGeometry|
160 const PathSource& GetSource() const override;
161
162 private:
163 const DiffRoundRectPathSource source_;
164 };
165
166 /// @brief A Geometry that produces fillable vertices representing the
167 /// stroked outline of a |DlPath| object using the
168 /// |StrokePathSourceGeometry| base class and a |DlPath| object
169 /// to perform path iteration.
170 class StrokeDashedLineGeometry final : public StrokePathSourceGeometry {
171 public:
172 StrokeDashedLineGeometry(Point p0,
173 Point p1,
174 Scalar on_length,
175 Scalar off_length,
176 const StrokeParameters& parameters);
177
178 protected:
179 const PathSource& GetSource() const override;
180
181 private:
182 const DashedLinePathSource source_;
183 };
184
185 } // namespace impeller
186
187 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_STROKE_PATH_GEOMETRY_H_
impeller::ArcStrokeGeometry
A Geometry that produces fillable vertices representing the stroked outline of an |Arc| object using ...
Definition: stroke_path_geometry.h:132
impeller::ArcStrokeGeometry::Dispatch
void Dispatch(PathAndArcSegmentReceiver &receiver, Tessellator &tessellator, Scalar scale) const override
Definition: stroke_path_geometry.cc:871
impeller::ArcStrokeGeometry::ArcStrokeGeometry
ArcStrokeGeometry(const Arc &arc, const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:862
impeller::ArcStrokeGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: stroke_path_geometry.cc:866
impeller::ContentContext
Definition: content_context.h:138
impeller::DashedLinePathSource
A PathSource that generates the various segments of a dashed line.
Definition: dashed_line_path_source.h:15
impeller::DiffRoundRectPathSource
Definition: round_rect.h:173
impeller::Entity
Definition: entity.h:26
impeller::Geometry
Definition: geometry.h:50
impeller::ImpellerBenchmarkAccessor
Definition: geometry_benchmarks.cc:14
impeller::ImpellerEntityUnitTestAccessor
Definition: geometry_unittests.cc:57
impeller::PathAndArcSegmentReceiver
A |SegmentReceiver| that also accepts Arc segments for optimal handling. A path or |PathSource| will ...
Definition: stroke_path_geometry.h:20
impeller::PathAndArcSegmentReceiver::RecordArc
virtual void RecordArc(const Arc &arc, const Point center, const Size radii)=0
impeller::PathSource
Definition: path_source.h:55
impeller::PathTessellator::SegmentReceiver
An interface for receiving pruned path segments.
Definition: path_tessellator.h:28
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::StrokeDashedLineGeometry
A Geometry that produces fillable vertices representing the stroked outline of a |DlPath| object usin...
Definition: stroke_path_geometry.h:170
impeller::StrokeDashedLineGeometry::GetSource
const PathSource & GetSource() const override
Definition: stroke_path_geometry.cc:913
impeller::StrokeDashedLineGeometry::StrokeDashedLineGeometry
StrokeDashedLineGeometry(Point p0, Point p1, Scalar on_length, Scalar off_length, const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:904
impeller::StrokeDiffRoundRectGeometry
A Geometry that produces fillable vertices representing the stroked outline of a pair of nested |Roun...
Definition: stroke_path_geometry.h:152
impeller::StrokeDiffRoundRectGeometry::StrokeDiffRoundRectGeometry
StrokeDiffRoundRectGeometry(const RoundRect &outer, const RoundRect &inner, const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:894
impeller::StrokeDiffRoundRectGeometry::GetSource
const PathSource & GetSource() const override
Definition: stroke_path_geometry.cc:900
impeller::StrokePathGeometry
A Geometry that produces fillable vertices representing the stroked outline of a |DlPath| object usin...
Definition: stroke_path_geometry.h:115
impeller::StrokePathGeometry::StrokePathGeometry
StrokePathGeometry(const flutter::DlPath &path, const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:854
impeller::StrokePathGeometry::GetSource
const PathSource & GetSource() const override
Definition: stroke_path_geometry.cc:858
impeller::StrokePathSourceGeometry
An abstract Geometry base class that produces fillable vertices representing the stroked outline from...
Definition: stroke_path_geometry.h:94
impeller::StrokePathSourceGeometry::GetSource
virtual const PathSource & GetSource() const =0
impeller::StrokePathSourceGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: stroke_path_geometry.cc:843
impeller::StrokePathSourceGeometry::StrokePathSourceGeometry
StrokePathSourceGeometry(const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:839
impeller::StrokePathSourceGeometry::Dispatch
void Dispatch(PathAndArcSegmentReceiver &receiver, Tessellator &tessellator, Scalar scale) const override
Definition: stroke_path_geometry.cc:848
impeller::StrokeSegmentsGeometry
An abstract Geometry base class that produces fillable vertices representing the stroked outline of t...
Definition: stroke_path_geometry.h:35
impeller::StrokeSegmentsGeometry::Dispatch
virtual void Dispatch(PathAndArcSegmentReceiver &receiver, Tessellator &tessellator, Scalar scale) const =0
impeller::StrokeSegmentsGeometry::GetStrokeJoin
Join GetStrokeJoin() const
Definition: stroke_path_geometry.cc:731
impeller::StrokeSegmentsGeometry::GetStrokeWidth
Scalar GetStrokeWidth() const
Definition: stroke_path_geometry.cc:719
impeller::StrokeSegmentsGeometry::GetMiterLimit
Scalar GetMiterLimit() const
Definition: stroke_path_geometry.cc:723
impeller::StrokeSegmentsGeometry::ComputeAlphaCoverage
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Definition: stroke_path_geometry.cc:735
impeller::StrokeSegmentsGeometry::GetStrokeCap
Cap GetStrokeCap() const
Definition: stroke_path_geometry.cc:727
impeller::StrokeSegmentsGeometry::GetStrokeCoverage
std::optional< Rect > GetStrokeCoverage(const Matrix &transform, const Rect &segment_bounds) const
Definition: stroke_path_geometry.cc:815
impeller::StrokeSegmentsGeometry::StrokeSegmentsGeometry
StrokeSegmentsGeometry(const StrokeParameters &parameters)
Definition: stroke_path_geometry.cc:714
impeller::StrokeSegmentsGeometry::~StrokeSegmentsGeometry
~StrokeSegmentsGeometry() override
impeller::Tessellator
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
Definition: tessellator.h:37
dashed_line_path_source.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
geometry.h
matrix.h
impeller
Definition: allocation.cc:12
impeller::Join
Join
An enum that describes ways to join two segments of a path.
Definition: stroke_parameters.h:20
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::Cap
Cap
An enum that describes ways to decorate the end of a path contour.
Definition: stroke_parameters.h:13
impeller::DlPath
flutter::DlPath DlPath
Definition: dl_dispatcher.h:29
path_source.h
path_tessellator.h
stroke_parameters.h
impeller::Arc
Definition: arc.h:13
impeller::GeometryResult
Definition: geometry.h:21
impeller::GeometryResult::Mode
Mode
Definition: geometry.h:22
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::RoundRect
Definition: round_rect.h:16
impeller::StrokeParameters
A structure to store all of the parameters related to stroking a path or basic geometry object.
Definition: stroke_parameters.h:28
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller::TSize< Scalar >