Flutter Engine
 
Loading...
Searching...
No Matches
dl_path_builder.cc
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
6
10#include "flutter/third_party/skia/include/core/SkArc.h"
11
12namespace {
13
14inline constexpr SkPathFillType ToSkFillType(flutter::DlPathFillType dl_type) {
15 switch (dl_type) {
17 return SkPathFillType::kEvenOdd;
19 return SkPathFillType::kWinding;
20 }
21}
22
23class BuilderReceiver : public impeller::PathReceiver {
24 private:
25 using Point = impeller::Point;
27
28 public:
29 explicit BuilderReceiver(flutter::DlPathBuilder& builder)
30 : builder_(builder) {}
31
32 void MoveTo(const Point& p2, bool will_be_closed) { builder_.MoveTo(p2); }
33 void LineTo(const Point& p2) { builder_.LineTo(p2); }
34 void QuadTo(const Point& cp, const Point& p2) {
35 builder_.QuadraticCurveTo(cp, p2);
36 }
37 bool ConicTo(const Point& cp, const Point& p2, Scalar weight) {
38 builder_.ConicCurveTo(cp, p2, weight);
39 return true;
40 }
41 void CubicTo(const Point& cp1, const Point& cp2, const Point& p2) {
42 builder_.CubicCurveTo(cp1, cp2, p2);
43 }
44 void Close() { builder_.Close(); }
45
46 private:
47 flutter::DlPathBuilder& builder_;
48};
49
50} // namespace
51
52namespace flutter {
53
55 path_.setFillType(ToSkFillType(fill_type));
56 return *this;
57}
58
60 path_.moveTo(p2.x, p2.y);
61 return *this;
62}
63
65 path_.lineTo(p2.x, p2.y);
66 return *this;
67}
68
70 path_.quadTo(cp.x, cp.y, p2.x, p2.y);
71 return *this;
72}
73
75 DlPoint p2,
76 DlScalar weight) {
77 path_.conicTo(cp.x, cp.y, p2.x, p2.y, weight);
78 return *this;
79}
80
82 DlPoint cp2,
83 DlPoint p2) {
84 path_.cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, p2.x, p2.y);
85 return *this;
86}
87
89 path_.close();
90 return *this;
91}
92
94 path_.addRect(ToSkRect(rect));
95 return *this;
96}
97
99 path_.addOval(ToSkRect(bounds));
100 return *this;
101}
102
104 path_.addCircle(center.x, center.y, radius);
105 return *this;
106}
107
109 path_.addRRect(ToSkRRect(round_rect));
110 return *this;
111}
112
114 const DlRoundSuperellipse& rse) {
115 BuilderReceiver receiver(*this);
117 rse.GetRadii())
118 .Dispatch(receiver);
119 return *this;
120}
121
123 DlDegrees start,
124 DlDegrees sweep,
125 bool use_center) {
126 if (use_center) {
127 path_.moveTo(ToSkPoint(bounds.GetCenter()));
128 }
129 path_.arcTo(ToSkRect(bounds), start.degrees, sweep.degrees, !use_center);
130 if (use_center) {
131 path_.close();
132 }
133 return *this;
134}
135
137 path_.addPath(path.GetSkPath());
138 return *this;
139}
140
142 return DlPath(path_);
143}
144
146 DlPath path = DlPath(path_);
147 path_.reset();
148 return path;
149}
150
151} // namespace flutter
DlPathBuilder & AddRoundSuperellipse(const DlRoundSuperellipse &rse)
Append a closed rounded super-ellipse contour to the path.
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
DlPathBuilder & AddPath(const DlPath &path)
Append the provided path to this path as if the commands used to construct it were repeated on this p...
DlPathBuilder & MoveTo(DlPoint p2)
Start a new contour that will originate at the indicated point p2.
const DlPath CopyPath()
Returns the path constructed by this path builder so far and retains all current geometry to continue...
DlPathBuilder & SetFillType(DlPathFillType fill_type)
Set the fill type that should be used to determine the interior of this path to the indicated |fill_t...
const DlPath TakePath()
Returns the path constructed by this path builder and resets its internal state to the default state ...
DlPathBuilder & ConicCurveTo(DlPoint cp, DlPoint p2, DlScalar weight)
Draw a conic curve (a rational quadratic bezier curve) from the current point to the indicated point ...
DlPathBuilder & AddCircle(DlPoint center, DlScalar radius)
Append a closed circular contour to the path centered on the provided point at the provided radius.
DlPathBuilder & AddRect(const DlRect &rect)
Append a closed rectangular contour to the path.
DlPathBuilder & AddRoundRect(const DlRoundRect &round_rect)
Append a closed rounded rect contour to the path.
DlPathBuilder & QuadraticCurveTo(DlPoint cp, DlPoint p2)
Draw a quadratic bezier curve from the current point to the indicated point p2, using the indicated p...
DlPathBuilder & Close()
The path is closed back to the location of the most recent MoveTo call. Contours that are filled are ...
DlPathBuilder & AddArc(const DlRect &bounds, DlDegrees start, DlDegrees sweep, bool use_center=false)
Append an arc contour to the path which:
DlPathBuilder & AddOval(const DlRect &bounds)
Append a closed elliptical contour to the path inscribed in the provided bounds.
DlPathBuilder & CubicCurveTo(DlPoint cp1, DlPoint cp2, DlPoint p2)
Draw a cubic bezier curve from the current point to the indicated point p2, using the indicated point...
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition path_source.h:42
virtual void CubicTo(const Point &cp1, const Point &cp2, const Point &p2)=0
virtual void LineTo(const Point &p2)=0
virtual void QuadTo(const Point &cp, const Point &p2)=0
virtual void Close()=0
virtual void MoveTo(const Point &p2, bool will_be_closed)=0
virtual bool ConicTo(const Point &cp, const Point &p2, Scalar weight)
Definition path_source.h:48
impeller::Scalar DlScalar
const SkPoint & ToSkPoint(const DlPoint &point)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
const SkRRect ToSkRRect(const DlRoundRect &round_rect)
const SkRect & ToSkRect(const DlRect &rect)
float Scalar
Definition scalar.h:19
TPoint< Scalar > Point
Definition point.h:327
Scalar degrees
Definition scalar.h:67
constexpr const Rect & GetBounds() const
constexpr const RoundingRadii & GetRadii() const
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
void Dispatch(PathReceiver &receiver) const
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition rect.h:382
const size_t start