| Flutter Impeller |

Functions
impeller::skia_conversions Namespace Reference

## Functions
static bool | SkScalarsNearlyEqual (SkScalar a, SkScalar b, SkScalar c, SkScalar d)
bool | IsNearlySimpleRRect (const SkRRect &rr)
| Like SkRRect.isSimple, but allows the corners to differ by kEhCloseEnough. More...
Rect | ToRect (const SkRect &rect)
std::optional< Rect > | ToRect (const SkRect *rect)
std::optional< const Rect > | ToRect (const flutter::DlRect *rect)
std::vector< Rect > | ToRects (const SkRect tex[], int count)
std::vector< Rect > | ToRects (const flutter::DlRect tex[], int count)
std::vector< Point > | ToPoints (const SkPoint points[], int count)
std::vector< Point > | ToPoints (const flutter::DlPoint points[], int count)
PathBuilder::RoundingRadii | ToRoundingRadii (const SkRRect &rrect)
Path | ToPath (const SkRRect &rrect)
Point | ToPoint (const SkPoint &point)
Size | ToSize (const SkPoint &point)
Color | ToColor (const flutter::DlColor &color)
Matrix | ToRSXForm (const SkRSXform &form)
std::optional< impeller::PixelFormat > | ToPixelFormat (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. More...
impeller::SamplerDescriptor | ToSamplerDescriptor (const flutter::DlImageSampling options)
Matrix | ToMatrix (const SkMatrix &m)
BlendMode | ToBlendMode (flutter::DlBlendMode mode)

## 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 144 of file skia_conversions.cc.

146 {
147 FML_DCHECK(gradient->stop_count() >= 2)
148 << "stop_count:" << gradient->stop_count();
149
150 auto* dl_colors = gradient->colors();
151 auto* dl_stops = gradient->stops();
152 if (dl_stops[0] != 0.0) {
153 colors.emplace_back(skia_conversions::ToColor(dl_colors[0]));
154 stops.emplace_back(0);
155 }
156 for (auto i = 0; i < gradient->stop_count(); i++) {
157 colors.emplace_back(skia_conversions::ToColor(dl_colors[i]));
158 stops.emplace_back(std::clamp(dl_stops[i], 0.0f, 1.0f));
159 }
160 if (dl_stops[gradient->stop_count() - 1] != 1.0) {
161 colors.emplace_back(colors.back());
162 stops.emplace_back(1.0);
163 }
164 for (auto i = 1; i < gradient->stop_count(); i++) {
165 stops[i] = std::clamp(stops[i], stops[i - 1], stops[i]);
166 }
167 }

References ToColor().

Referenced by impeller::Paint::CreateContents(), and impeller::testing::TEST().

## ◆ IsNearlySimpleRRect()

bool impeller::skia_conversions::IsNearlySimpleRRect | ( | const SkRRect & | rr | ) |

Like SkRRect.isSimple, but allows the corners to differ by kEhCloseEnough.

An RRect is simple if all corner radii are approximately equal.

Definition at line 21 of file skia_conversions.cc.

21 {
22 auto [xa, ya] = rr.radii(SkRRect::kUpperLeft_Corner);
23 auto [xb, yb] = rr.radii(SkRRect::kLowerLeft_Corner);
24 auto [xc, yc] = rr.radii(SkRRect::kUpperRight_Corner);
25 auto [xd, yd] = rr.radii(SkRRect::kLowerRight_Corner);
26 return SkScalarsNearlyEqual(xa, xb, xc, xd) &&
27 SkScalarsNearlyEqual(ya, yb, yc, yd);
28 }

References SkScalarsNearlyEqual().

Referenced by impeller::DlDispatcherBase::drawRRect(), and impeller::testing::TEST().

## ◆ SkScalarsNearlyEqual()

static bool impeller::skia_conversions::SkScalarsNearlyEqual | ( | SkScalar | a,
|  | SkScalar | b,
|  | SkScalar | c,
|  | SkScalar | d
| ) |  |
| inline static

Definition at line 12 of file skia_conversions.cc.

15 {
16 return SkScalarNearlyEqual(a, b, kEhCloseEnough) &&
17 SkScalarNearlyEqual(a, c, kEhCloseEnough) &&
18 SkScalarNearlyEqual(a, d, kEhCloseEnough);
19 }

References impeller::saturated::b, and impeller::kEhCloseEnough.

Referenced by IsNearlySimpleRRect().

## ◆ ToBlendMode()

BlendMode impeller::skia_conversions::ToBlendMode | ( | flutter::DlBlendMode | mode | ) |

Definition at line 204 of file skia_conversions.cc.

204 {
205 switch (mode) {
206 case flutter::DlBlendMode::kClear:
207 return BlendMode::kClear;
208 case flutter::DlBlendMode::kSrc:
209 return BlendMode::kSource;
210 case flutter::DlBlendMode::kDst:
211 return BlendMode::kDestination;
212 case flutter::DlBlendMode::kSrcOver:
213 return BlendMode::kSourceOver;
214 case flutter::DlBlendMode::kDstOver:
215 return BlendMode::kDestinationOver;
216 case flutter::DlBlendMode::kSrcIn:
217 return BlendMode::kSourceIn;
218 case flutter::DlBlendMode::kDstIn:
219 return BlendMode::kDestinationIn;
220 case flutter::DlBlendMode::kSrcOut:
221 return BlendMode::kSourceOut;
222 case flutter::DlBlendMode::kDstOut:
223 return BlendMode::kDestinationOut;
224 case flutter::DlBlendMode::kSrcATop:
225 return BlendMode::kSourceATop;
226 case flutter::DlBlendMode::kDstATop:
227 return BlendMode::kDestinationATop;
228 case flutter::DlBlendMode::kXor:
229 return BlendMode::kXor;
230 case flutter::DlBlendMode::kPlus:
231 return BlendMode::kPlus;
232 case flutter::DlBlendMode::kModulate:
233 return BlendMode::kModulate;
234 case flutter::DlBlendMode::kScreen:
235 return BlendMode::kScreen;
236 case flutter::DlBlendMode::kOverlay:
237 return BlendMode::kOverlay;
238 case flutter::DlBlendMode::kDarken:
239 return BlendMode::kDarken;
240 case flutter::DlBlendMode::kLighten:
241 return BlendMode::kLighten;
242 case flutter::DlBlendMode::kColorDodge:
243 return BlendMode::kColorDodge;
244 case flutter::DlBlendMode::kColorBurn:
245 return BlendMode::kColorBurn;
246 case flutter::DlBlendMode::kHardLight:
247 return BlendMode::kHardLight;
248 case flutter::DlBlendMode::kSoftLight:
249 return BlendMode::kSoftLight;
250 case flutter::DlBlendMode::kDifference:
251 return BlendMode::kDifference;
252 case flutter::DlBlendMode::kExclusion:
253 return BlendMode::kExclusion;
254 case flutter::DlBlendMode::kMultiply:
255 return BlendMode::kMultiply;
256 case flutter::DlBlendMode::kHue:
257 return BlendMode::kHue;
258 case flutter::DlBlendMode::kSaturation:
259 return BlendMode::kSaturation;
260 case flutter::DlBlendMode::kColor:
261 return BlendMode::kColor;
262 case flutter::DlBlendMode::kLuminosity:
263 return BlendMode::kLuminosity;
264 }
265 FML_UNREACHABLE();
266 }

References impeller::kClear, impeller::kColor, impeller::kColorBurn, impeller::kColorDodge, impeller::kDarken, impeller::kDestination, impeller::kDestinationATop, impeller::kDestinationIn, impeller::kDestinationOut, impeller::kDestinationOver, impeller::kDifference, impeller::kExclusion, impeller::kHardLight, impeller::kHue, impeller::kLighten, impeller::kLuminosity, impeller::kModulate, impeller::kMultiply, impeller::kOverlay, impeller::kPlus, impeller::kSaturation, impeller::kScreen, impeller::kSoftLight, impeller::kSource, impeller::kSourceATop, impeller::kSourceIn, impeller::kSourceOut, impeller::kSourceOver, and impeller::kXor.

Referenced by impeller::DlDispatcherBase::drawAtlas(), impeller::DlDispatcherBase::drawColor(), impeller::CanvasDlDispatcher::drawVertices(), impeller::RequiresReadbackForBlends(), impeller::DlDispatcherBase::setBlendMode(), and impeller::testing::TEST().

## ◆ ToColor()

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

Definition at line 106 of file skia_conversions.cc.

106 {
107 FML_DCHECK(color.getColorSpace() == flutter::DlColorSpace::kExtendedSRGB ||
108 color.getColorSpace() == flutter::DlColorSpace::kSRGB);
109 return {
110 static_cast<Scalar>(color.getRedF()), //
111 static_cast<Scalar>(color.getGreenF()), //
112 static_cast<Scalar>(color.getBlueF()), //
113 static_cast<Scalar>(color.getAlphaF()) //
114 };
115 }

References color.

Referenced by ConvertStops(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlDispatcherBase::drawColor(), impeller::DlDispatcherBase::drawShadow(), impeller::GetCPUColorFilterProc(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::DlDispatcherBase::setColor(), impeller::TextFrameDispatcher::setColor(), impeller::testing::TEST(), and impeller::WrapWithGPUColorFilter().

## ◆ ToMatrix()

Matrix impeller::skia_conversions::ToMatrix | ( | const SkMatrix & | m | ) |

Definition at line 193 of file skia_conversions.cc.

193 {
194 return Matrix{
195 // clang-format off
196 m[0], m[3], 0, m[6],
197 m[1], m[4], 0, m[7],
198 0, 0, 1, 0,
199 m[2], m[5], 0, m[8],
200 // clang-format on
201 };
202 }

Referenced by impeller::Paint::CreateContents(), impeller::Canvas::DrawVertices(), impeller::testing::TEST(), impeller::testing::TEST_P(), and impeller::WrapInput().

## ◆ ToPath()

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

Definition at line 90 of file skia_conversions.cc.

90 {
91 return PathBuilder{}
92 .AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
93 .SetConvexity(Convexity::kConvex)
94 .SetBounds(ToRect(rrect.getBounds()))
95 .TakePath();
96 }

References impeller::PathBuilder::AddRoundedRect(), impeller::kConvex, impeller::PathBuilder::SetBounds(), impeller::PathBuilder::SetConvexity(), impeller::PathBuilder::TakePath(), ToRect(), and ToRoundingRadii().

Referenced by impeller::DlDispatcherBase::clipRRect(), impeller::DlDispatcherBase::drawDRRect(), and impeller::DlDispatcherBase::drawRRect().

## ◆ ToPixelFormat()

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

Definition at line 128 of file skia_conversions.cc.

128 {
129 switch (type) {
130 case kRGBA_8888_SkColorType:
131 return impeller::PixelFormat::kR8G8B8A8UNormInt;
132 case kBGRA_8888_SkColorType:
133 return impeller::PixelFormat::kB8G8R8A8UNormInt;
134 case kRGBA_F16_SkColorType:
135 return impeller::PixelFormat::kR16G16B16A16Float;
136 case kBGR_101010x_XR_SkColorType:
137 return impeller::PixelFormat::kB10G10R10XR;
138 default:
139 return std::nullopt;
140 }
141 return std::nullopt;
142 }

References impeller::kB10G10R10XR, impeller::kB8G8R8A8UNormInt, impeller::kR16G16B16A16Float, impeller::kR8G8B8A8UNormInt, and type.

## ◆ ToPoint()

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

Definition at line 98 of file skia_conversions.cc.

98 {
99 return Point::MakeXY(point.fX, point.fY);
100 }

References impeller::TPoint< Scalar >::MakeXY().

Referenced by impeller::Paint::CreateContents(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::testing::TEST(), ToPoints(), and ToRoundingRadii().

## ◆ ToPoints() [1/2]

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

Definition at line 72 of file skia_conversions.cc.

72 {
73 std::vector<Point> result(count);
74 for (auto i = 0; i < count; i++) {
75 result[i] = points[i];
76 }
77 return result;
78 }

## ◆ ToPoints() [2/2]

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

Definition at line 64 of file skia_conversions.cc.

64 {
65 std::vector<Point> result(count);
66 for (auto i = 0; i < count; i++) {
67 result[i] = ToPoint(points[i]);
68 }
69 return result;
70 }

References ToPoint().

Referenced by impeller::DlDispatcherBase::drawPoints().

## ◆ ToRect() [1/3]

std::optional< const Rect > impeller::skia_conversions::ToRect | ( | const flutter::DlRect * | rect | ) |

Definition at line 41 of file skia_conversions.cc.

41 {
42 if (rect == nullptr) {
43 return std::nullopt;
44 }
45 return *rect;
46 }

## ◆ ToRect() [2/3]

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

Definition at line 30 of file skia_conversions.cc.

30 {
31 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
32 }

References impeller::TRect< Scalar >::MakeLTRB().

Referenced by impeller::DlDispatcherBase::clipPath(), impeller::DlDispatcherBase::clipRRect(), impeller::DlVerticesGeometry::DlVerticesGeometry(), impeller::DlDispatcherBase::drawAtlas(), impeller::DlDispatcherBase::drawDisplayList(), impeller::DlDispatcherBase::drawRRect(), impeller::DlDispatcherBase::SimplifyOrDrawPath(), ToPath(), and ToRects().

## ◆ ToRect() [3/3]

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

Definition at line 34 of file skia_conversions.cc.

34 {
35 if (rect == nullptr) {
36 return std::nullopt;
37 }
38 return Rect::MakeLTRB(rect->fLeft, rect->fTop, rect->fRight, rect->fBottom);
39 }

References impeller::TRect< Scalar >::MakeLTRB().

## ◆ ToRects() [1/2]

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

Definition at line 56 of file skia_conversions.cc.

56 {
57 auto result = std::vector<Rect>();
58 for (int i = 0; i < count; i++) {
59 result.push_back(tex[i]);
60 }
61 return result;
62 }

## ◆ ToRects() [2/2]

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

Definition at line 48 of file skia_conversions.cc.

48 {
49 auto result = std::vector<Rect>();
50 for (int i = 0; i < count; i++) {
51 result.push_back(ToRect(tex[i]));
52 }
53 return result;
54 }

References ToRect().

## ◆ ToRoundingRadii()

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

Definition at line 80 of file skia_conversions.cc.

80 {
81 using Corner = SkRRect::Corner;
82 PathBuilder::RoundingRadii radii;
83 radii.bottom_left = ToPoint(rrect.radii(Corner::kLowerLeft_Corner));
84 radii.bottom_right = ToPoint(rrect.radii(Corner::kLowerRight_Corner));
85 radii.top_left = ToPoint(rrect.radii(Corner::kUpperLeft_Corner));
86 radii.top_right = ToPoint(rrect.radii(Corner::kUpperRight_Corner));
87 return radii;
88 }

References impeller::PathBuilder::RoundingRadii::bottom_left, impeller::PathBuilder::RoundingRadii::bottom_right, impeller::PathBuilder::RoundingRadii::top_left, impeller::PathBuilder::RoundingRadii::top_right, and ToPoint().

Referenced by ToPath().

## ◆ ToRSXForm()

Matrix impeller::skia_conversions::ToRSXForm | ( | const SkRSXform & | form | ) |

Definition at line 117 of file skia_conversions.cc.

117 {
118 // clang-format off
119 return Matrix{
120 form.fSCos, form.fSSin, 0, 0,
121 -form.fSSin, form.fSCos, 0, 0,
122 0, 0, 1, 0,
123 form.fTx, form.fTy, 0, 1
124 };
125 // clang-format on
126 }

Referenced by impeller::DlAtlasGeometry::ComputeBoundingBox(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), and impeller::DlAtlasGeometry::CreateSimpleVertexBuffer().

## ◆ ToSamplerDescriptor()

impeller::SamplerDescriptor impeller::skia_conversions::ToSamplerDescriptor | ( | const flutter::DlImageSampling | options | ) |

Definition at line 169 of file skia_conversions.cc.

170 {
171 impeller::SamplerDescriptor desc;
172 switch (options) {
173 case flutter::DlImageSampling::kNearestNeighbor:
174 desc.min_filter = desc.mag_filter = impeller::MinMagFilter::kNearest;
175 desc.mip_filter = impeller::MipFilter::kBase;
176 desc.label = "Nearest Sampler";
177 break;
178 case flutter::DlImageSampling::kLinear:
179 desc.min_filter = desc.mag_filter = impeller::MinMagFilter::kLinear;
180 desc.mip_filter = impeller::MipFilter::kBase;
181 desc.label = "Linear Sampler";
182 break;
183 case flutter::DlImageSampling::kCubic:
184 case flutter::DlImageSampling::kMipmapLinear:
185 desc.min_filter = desc.mag_filter = impeller::MinMagFilter::kLinear;
186 desc.mip_filter = impeller::MipFilter::kLinear;
187 desc.label = "Mipmap Linear Sampler";
188 break;
189 }
190 return desc;
191 }

References impeller::kBase, impeller::kLinear, impeller::kNearest, impeller::SamplerDescriptor::label, impeller::SamplerDescriptor::mag_filter, impeller::SamplerDescriptor::min_filter, and impeller::SamplerDescriptor::mip_filter.

Referenced by impeller::Paint::CreateContents(), impeller::DlDispatcherBase::drawAtlas(), impeller::DlDispatcherBase::drawImageRect(), impeller::Canvas::DrawVertices(), impeller::testing::TEST(), and impeller::WrapInput().

## ◆ ToSize()

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

Definition at line 102 of file skia_conversions.cc.

102 {
103 return Size(point.fX, point.fY);
104 }

Referenced by impeller::DlDispatcherBase::clipPath(), impeller::DlDispatcherBase::clipRRect(), impeller::DlDispatcherBase::drawRRect(), impeller::DlDispatcherBase::SimplifyOrDrawPath(), and impeller::testing::TEST().

impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::kEhCloseEnough
constexpr float kEhCloseEnough
Definition: constants.h:56
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::skia_conversions::ToRect
std::optional< const Rect > ToRect(const flutter::DlRect *rect)
Definition: skia_conversions.cc:41
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:106
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
impeller::MinMagFilter::kNearest
@ kNearest
Select nearest to the sample point. Most widely supported.
impeller::SamplerDescriptor::mag_filter
MinMagFilter mag_filter
Definition: sampler_descriptor.h:17
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::skia_conversions::SkScalarsNearlyEqual
static bool SkScalarsNearlyEqual(SkScalar a, SkScalar b, SkScalar c, SkScalar d)
Definition: skia_conversions.cc:12
impeller::skia_conversions::ToRoundingRadii
PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect &rrect)
Definition: skia_conversions.cc:80
impeller::SamplerDescriptor::min_filter
MinMagFilter min_filter
Definition: sampler_descriptor.h:16
impeller::MinMagFilter::kLinear
@ kLinear
impeller::PixelFormat::kB10G10R10XR
@ kB10G10R10XR
type
GLenum type
Definition: blit_command_gles.cc:127
impeller::PixelFormat::kR16G16B16A16Float
@ kR16G16B16A16Float
impeller::skia_conversions::ToPoint
Point ToPoint(const SkPoint &point)
Definition: skia_conversions.cc:98
impeller::SamplerDescriptor::mip_filter
MipFilter mip_filter
Definition: sampler_descriptor.h:18
impeller::MipFilter::kBase
@ kBase
The texture is sampled as if it only had a single mipmap level.
impeller::saturated::b
SI b
Definition: saturated_math.h:87
impeller::MipFilter::kLinear
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
impeller::SamplerDescriptor::label
std::string label
Definition: sampler_descriptor.h:24
color
DlColor color
Definition: dl_golden_blur_unittests.cc:24
impeller::PixelFormat::kB8G8R8A8UNormInt
@ kB8G8R8A8UNormInt