Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
impeller::skia_conversions Namespace Reference

Functions

Rect ToRect (const SkRect &rect)
 
std::optional< RectToRect (const SkRect *rect)
 
std::vector< RectToRects (const SkRect tex[], int count)
 
std::vector< PointToPoints (const SkPoint points[], int count)
 
PathBuilder::RoundingRadii ToRoundingRadii (const SkRRect &rrect)
 
Path ToPath (const SkPath &path, Point shift)
 
Path ToPath (const SkRRect &rrect)
 
Point ToPoint (const SkPoint &point)
 
Size ToSize (const SkPoint &point)
 
Color ToColor (const flutter::DlColor &color)
 
std::vector< MatrixToRSXForms (const SkRSXform xform[], int count)
 
Path PathDataFromTextBlob (const sk_sp< SkTextBlob > &blob, Point shift)
 
std::optional< impeller::PixelFormatToPixelFormat (SkColorType type)
 
void ConvertStops (const flutter::DlGradientColorSourceBase *gradient, std::vector< Color > &colors, std::vector< float > &stops)
 Convert display list colors + stops into impeller colors and stops, taking care to ensure that the stops monotonically increase from 0.0 to 1.0.
 

Function Documentation

◆ ConvertStops()

void impeller::skia_conversions::ConvertStops ( const flutter::DlGradientColorSourceBase gradient,
std::vector< Color > &  colors,
std::vector< float > &  stops 
)

Convert display list colors + stops into impeller colors and stops, taking care to ensure that the stops monotonically increase from 0.0 to 1.0.

The general process is:

  • Ensure that the first gradient stop value is 0.0. If not, insert a new stop with a value of 0.0 and use the first gradient color as this new stops color.
  • Ensure the last gradient stop value is 1.0. If not, insert a new stop with a value of 1.0 and use the last gradient color as this stops color.
  • Clamp all gradient values between the values of 0.0 and 1.0.
  • For all stop values, ensure that the values are monotonically increasing by clamping each value to a minimum of the previous stop value and itself. For example, with stop values of 0.0, 0.5, 0.4, 1.0, we would clamp such that the values were 0.0, 0.5, 0.5, 1.0.

Definition at line 198 of file skia_conversions.cc.

200 {
201 FML_DCHECK(gradient->stop_count() >= 2);
202
203 auto* dl_colors = gradient->colors();
204 auto* dl_stops = gradient->stops();
205 if (dl_stops[0] != 0.0) {
206 colors.emplace_back(skia_conversions::ToColor(dl_colors[0]));
207 stops.emplace_back(0);
208 }
209 for (auto i = 0; i < gradient->stop_count(); i++) {
210 colors.emplace_back(skia_conversions::ToColor(dl_colors[i]));
211 stops.emplace_back(std::clamp(dl_stops[i], 0.0f, 1.0f));
212 }
213 if (dl_stops[gradient->stop_count() - 1] != 1.0) {
214 colors.emplace_back(colors.back());
215 stops.emplace_back(1.0);
216 }
217 for (auto i = 1; i < gradient->stop_count(); i++) {
218 stops[i] = std::clamp(stops[i], stops[i - 1], stops[i]);
219 }
220}
#define FML_DCHECK(condition)
Definition logging.h:103

◆ PathDataFromTextBlob()

Path impeller::skia_conversions::PathDataFromTextBlob ( const sk_sp< SkTextBlob > &  blob,
Point  shift 
)

Definition at line 174 of file skia_conversions.cc.

174 {
175 if (!blob) {
176 return {};
177 }
178
179 return ToPath(skia::textlayout::Paragraph::GetPath(blob.get()), shift);
180}
T * get() const
Definition SkRefCnt.h:303
static SkPath GetPath(SkTextBlob *textBlob)

◆ ToColor()

Color impeller::skia_conversions::ToColor ( const flutter::DlColor color)

Definition at line 148 of file skia_conversions.cc.

148 {
149 return {
150 static_cast<Scalar>(color.getRedF()), //
151 static_cast<Scalar>(color.getGreenF()), //
152 static_cast<Scalar>(color.getBlueF()), //
153 static_cast<Scalar>(color.getAlphaF()) //
154 };
155}
SkColor4f color
float Scalar
Definition scalar.h:18

◆ ToPath() [1/2]

Path impeller::skia_conversions::ToPath ( const SkPath path,
Point  shift 
)

Definition at line 49 of file skia_conversions.cc.

49 {
50 auto iterator = SkPath::Iter(path, false);
51
52 struct PathData {
53 union {
54 SkPoint points[4];
55 };
56 };
57
58 PathBuilder builder;
59 PathData data;
60 // Reserve a path size with some arbitrarily additional padding.
61 builder.Reserve(path.countPoints() + 8, path.countVerbs() + 8);
62 auto verb = SkPath::Verb::kDone_Verb;
63 do {
64 verb = iterator.next(data.points);
65 switch (verb) {
67 builder.MoveTo(ToPoint(data.points[0]));
68 break;
70 builder.LineTo(ToPoint(data.points[1]));
71 break;
73 builder.QuadraticCurveTo(ToPoint(data.points[1]),
74 ToPoint(data.points[2]));
75 break;
77 constexpr auto kPow2 = 1; // Only works for sweeps up to 90 degrees.
78 constexpr auto kQuadCount = 1 + (2 * (1 << kPow2));
79 SkPoint points[kQuadCount];
80 const auto curve_count =
81 SkPath::ConvertConicToQuads(data.points[0], //
82 data.points[1], //
83 data.points[2], //
84 iterator.conicWeight(), //
85 points, //
86 kPow2 //
87 );
88
89 for (int curve_index = 0, point_index = 0; //
90 curve_index < curve_count; //
91 curve_index++, point_index += 2 //
92 ) {
93 builder.QuadraticCurveTo(ToPoint(points[point_index + 1]),
94 ToPoint(points[point_index + 2]));
95 }
96 } break;
98 builder.CubicCurveTo(ToPoint(data.points[1]), ToPoint(data.points[2]),
99 ToPoint(data.points[3]));
100 break;
102 builder.Close();
103 break;
105 break;
106 }
107 } while (verb != SkPath::Verb::kDone_Verb);
108
109 FillType fill_type;
110 switch (path.getFillType()) {
112 fill_type = FillType::kNonZero;
113 break;
115 fill_type = FillType::kOdd;
116 break;
119 // Flutter doesn't expose these path fill types. These are only visible
120 // via the receiver interface. We should never get here.
121 fill_type = FillType::kNonZero;
122 break;
123 }
124 builder.SetConvexity(path.isConvex() ? Convexity::kConvex
126 builder.Shift(shift);
127 auto sk_bounds = path.getBounds().makeOutset(shift.x, shift.y);
128 builder.SetBounds(ToRect(sk_bounds));
129 return builder.TakePath(fill_type);
130}
static const int points[]
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
Definition SkPath.cpp:3174
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
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 switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
Point ToPoint(const SkPoint &point)
Rect ToRect(const SkRect &rect)
FillType
Definition path.h:29
Convexity
Definition path.h:34

◆ ToPath() [2/2]

Path impeller::skia_conversions::ToPath ( const SkRRect rrect)

Definition at line 132 of file skia_conversions.cc.

132 {
133 return PathBuilder{}
134 .AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
135 .SetConvexity(Convexity::kConvex)
136 .SetBounds(ToRect(rrect.getBounds()))
137 .TakePath();
138}
const SkRect & getBounds() const
Definition SkRRect.h:279
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & SetBounds(Rect bounds)
Set the bounding box that will be used by Path.GetBoundingBox in place of performing the computation.
PathBuilder & AddRoundedRect(Rect rect, RoundingRadii radii)
PathBuilder & SetConvexity(Convexity value)

◆ ToPixelFormat()

std::optional< impeller::PixelFormat > impeller::skia_conversions::ToPixelFormat ( SkColorType  type)

Definition at line 182 of file skia_conversions.cc.

182 {
183 switch (type) {
192 default:
193 return std::nullopt;
194 }
195 return std::nullopt;
196}
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition SkColorType.h:31

◆ ToPoint()

Point impeller::skia_conversions::ToPoint ( const SkPoint point)

Definition at line 140 of file skia_conversions.cc.

140 {
141 return Point::MakeXY(point.fX, point.fY);
142}
float fX
x-axis value
float fY
y-axis value

◆ ToPoints()

std::vector< Point > impeller::skia_conversions::ToPoints ( const SkPoint  points[],
int  count 
)

Definition at line 31 of file skia_conversions.cc.

31 {
32 std::vector<Point> result(count);
33 for (auto i = 0; i < count; i++) {
34 result[i] = ToPoint(points[i]);
35 }
36 return result;
37}
int count
GAsyncResult * result

◆ ToRect() [1/2]

Rect impeller::skia_conversions::ToRect ( const SkRect rect)

Definition at line 12 of file skia_conversions.cc.

12 {
13 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
14}

◆ ToRect() [2/2]

std::optional< Rect > impeller::skia_conversions::ToRect ( const SkRect rect)

Definition at line 16 of file skia_conversions.cc.

16 {
17 if (rect == nullptr) {
18 return std::nullopt;
19 }
20 return Rect::MakeLTRB(rect->fLeft, rect->fTop, rect->fRight, rect->fBottom);
21}

◆ ToRects()

std::vector< Rect > impeller::skia_conversions::ToRects ( const SkRect  tex[],
int  count 
)

Definition at line 23 of file skia_conversions.cc.

23 {
24 auto result = std::vector<Rect>();
25 for (int i = 0; i < count; i++) {
26 result.push_back(ToRect(tex[i]));
27 }
28 return result;
29}

◆ ToRoundingRadii()

PathBuilder::RoundingRadii impeller::skia_conversions::ToRoundingRadii ( const SkRRect rrect)

Definition at line 39 of file skia_conversions.cc.

39 {
40 using Corner = SkRRect::Corner;
42 radii.bottom_left = ToPoint(rrect.radii(Corner::kLowerLeft_Corner));
43 radii.bottom_right = ToPoint(rrect.radii(Corner::kLowerRight_Corner));
44 radii.top_left = ToPoint(rrect.radii(Corner::kUpperLeft_Corner));
45 radii.top_right = ToPoint(rrect.radii(Corner::kUpperRight_Corner));
46 return radii;
47}
SkVector radii(Corner corner) const
Definition SkRRect.h:271

◆ ToRSXForms()

std::vector< Matrix > impeller::skia_conversions::ToRSXForms ( const SkRSXform  xform[],
int  count 
)

Definition at line 157 of file skia_conversions.cc.

157 {
158 auto result = std::vector<Matrix>();
159 for (int i = 0; i < count; i++) {
160 auto form = xform[i];
161 // clang-format off
162 auto matrix = Matrix{
163 form.fSCos, form.fSSin, 0, 0,
164 -form.fSSin, form.fSCos, 0, 0,
165 0, 0, 1, 0,
166 form.fTx, form.fTy, 0, 1
167 };
168 // clang-format on
169 result.push_back(matrix);
170 }
171 return result;
172}
A 4x4 matrix using column-major storage.
Definition matrix.h:37

◆ ToSize()

Size impeller::skia_conversions::ToSize ( const SkPoint point)

Definition at line 144 of file skia_conversions.cc.

144 {
145 return Size(point.fX, point.fY);
146}