Flutter Impeller
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< RectToRect (const SkRect *rect)
 
std::optional< const RectToRect (const flutter::DlRect *rect)
 
std::vector< RectToRects (const SkRect tex[], int count)
 
std::vector< RectToRects (const flutter::DlRect tex[], int count)
 
std::vector< PointToPoints (const SkPoint points[], int count)
 
std::vector< PointToPoints (const flutter::DlPoint points[], int count)
 
Point ToPoint (const SkPoint &point)
 
Size ToSize (const SkPoint &point)
 
Color ToColor (const flutter::DlColor &color)
 
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. 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 116 of file skia_conversions.cc.

118  {
119  FML_DCHECK(gradient->stop_count() >= 2)
120  << "stop_count:" << gradient->stop_count();
121 
122  auto* dl_colors = gradient->colors();
123  auto* dl_stops = gradient->stops();
124  if (dl_stops[0] != 0.0) {
125  colors.emplace_back(skia_conversions::ToColor(dl_colors[0]));
126  stops.emplace_back(0);
127  }
128  for (auto i = 0; i < gradient->stop_count(); i++) {
129  colors.emplace_back(skia_conversions::ToColor(dl_colors[i]));
130  stops.emplace_back(std::clamp(dl_stops[i], 0.0f, 1.0f));
131  }
132  if (dl_stops[gradient->stop_count() - 1] != 1.0) {
133  colors.emplace_back(colors.back());
134  stops.emplace_back(1.0);
135  }
136  for (auto i = 1; i < gradient->stop_count(); i++) {
137  stops[i] = std::clamp(stops[i], stops[i - 1], stops[i]);
138  }
139 }
Color ToColor(const flutter::DlColor &color)

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

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

References SkScalarsNearlyEqual().

Referenced by impeller::testing::TEST().

◆ SkScalarsNearlyEqual()

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

Definition at line 13 of file skia_conversions.cc.

16  {
17  return SkScalarNearlyEqual(a, b, kEhCloseEnough) &&
18  SkScalarNearlyEqual(a, c, kEhCloseEnough) &&
19  SkScalarNearlyEqual(a, d, kEhCloseEnough);
20 }
constexpr float kEhCloseEnough
Definition: constants.h:56

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

Referenced by IsNearlySimpleRRect().

◆ ToBlendMode()

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

Definition at line 176 of file skia_conversions.cc.

176  {
177  switch (mode) {
178  case flutter::DlBlendMode::kClear:
179  return BlendMode::kClear;
180  case flutter::DlBlendMode::kSrc:
181  return BlendMode::kSource;
182  case flutter::DlBlendMode::kDst:
183  return BlendMode::kDestination;
184  case flutter::DlBlendMode::kSrcOver:
185  return BlendMode::kSourceOver;
186  case flutter::DlBlendMode::kDstOver:
187  return BlendMode::kDestinationOver;
188  case flutter::DlBlendMode::kSrcIn:
189  return BlendMode::kSourceIn;
190  case flutter::DlBlendMode::kDstIn:
191  return BlendMode::kDestinationIn;
192  case flutter::DlBlendMode::kSrcOut:
193  return BlendMode::kSourceOut;
194  case flutter::DlBlendMode::kDstOut:
195  return BlendMode::kDestinationOut;
196  case flutter::DlBlendMode::kSrcATop:
197  return BlendMode::kSourceATop;
198  case flutter::DlBlendMode::kDstATop:
199  return BlendMode::kDestinationATop;
200  case flutter::DlBlendMode::kXor:
201  return BlendMode::kXor;
202  case flutter::DlBlendMode::kPlus:
203  return BlendMode::kPlus;
204  case flutter::DlBlendMode::kModulate:
205  return BlendMode::kModulate;
206  case flutter::DlBlendMode::kScreen:
207  return BlendMode::kScreen;
208  case flutter::DlBlendMode::kOverlay:
209  return BlendMode::kOverlay;
210  case flutter::DlBlendMode::kDarken:
211  return BlendMode::kDarken;
212  case flutter::DlBlendMode::kLighten:
213  return BlendMode::kLighten;
214  case flutter::DlBlendMode::kColorDodge:
215  return BlendMode::kColorDodge;
216  case flutter::DlBlendMode::kColorBurn:
217  return BlendMode::kColorBurn;
218  case flutter::DlBlendMode::kHardLight:
219  return BlendMode::kHardLight;
220  case flutter::DlBlendMode::kSoftLight:
221  return BlendMode::kSoftLight;
222  case flutter::DlBlendMode::kDifference:
223  return BlendMode::kDifference;
224  case flutter::DlBlendMode::kExclusion:
225  return BlendMode::kExclusion;
226  case flutter::DlBlendMode::kMultiply:
227  return BlendMode::kMultiply;
228  case flutter::DlBlendMode::kHue:
229  return BlendMode::kHue;
230  case flutter::DlBlendMode::kSaturation:
231  return BlendMode::kSaturation;
232  case flutter::DlBlendMode::kColor:
233  return BlendMode::kColor;
234  case flutter::DlBlendMode::kLuminosity:
235  return BlendMode::kLuminosity;
236  }
237  FML_UNREACHABLE();
238 }

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

89  {
90  FML_DCHECK(color.getColorSpace() == flutter::DlColorSpace::kExtendedSRGB ||
91  color.getColorSpace() == flutter::DlColorSpace::kSRGB);
92  return {
93  static_cast<Scalar>(color.getRedF()), //
94  static_cast<Scalar>(color.getGreenF()), //
95  static_cast<Scalar>(color.getBlueF()), //
96  static_cast<Scalar>(color.getAlphaF()) //
97  };
98 }
float Scalar
Definition: scalar.h:18

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

◆ ToMatrix()

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

Definition at line 165 of file skia_conversions.cc.

165  {
166  return Matrix{
167  // clang-format off
168  m[0], m[3], 0, m[6],
169  m[1], m[4], 0, m[7],
170  0, 0, 1, 0,
171  m[2], m[5], 0, m[8],
172  // clang-format on
173  };
174 }

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

◆ ToPixelFormat()

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

Definition at line 100 of file skia_conversions.cc.

100  {
101  switch (type) {
102  case kRGBA_8888_SkColorType:
104  case kBGRA_8888_SkColorType:
106  case kRGBA_F16_SkColorType:
108  case kBGR_101010x_XR_SkColorType:
110  default:
111  return std::nullopt;
112  }
113  return std::nullopt;
114 }
GLenum type

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

◆ ToPoint()

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

Definition at line 81 of file skia_conversions.cc.

81  {
82  return Point::MakeXY(point.fX, point.fY);
83 }

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

Referenced by impeller::testing::TEST(), and ToPoints().

◆ ToPoints() [1/2]

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

Definition at line 73 of file skia_conversions.cc.

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

◆ ToPoints() [2/2]

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

Definition at line 65 of file skia_conversions.cc.

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

References ToPoint().

◆ ToRect() [1/3]

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

Definition at line 42 of file skia_conversions.cc.

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

◆ ToRect() [2/3]

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

Definition at line 31 of file skia_conversions.cc.

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

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

Referenced by impeller::DlDispatcherBase::clipPath(), impeller::DlDispatcherBase::drawAtlas(), impeller::DlDispatcherBase::drawDisplayList(), and ToRects().

◆ ToRect() [3/3]

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

Definition at line 35 of file skia_conversions.cc.

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

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

◆ ToRects() [1/2]

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

Definition at line 57 of file skia_conversions.cc.

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

◆ ToRects() [2/2]

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

Definition at line 49 of file skia_conversions.cc.

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

References ToRect().

◆ ToSamplerDescriptor()

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

Definition at line 141 of file skia_conversions.cc.

142  {
144  switch (options) {
145  case flutter::DlImageSampling::kNearestNeighbor:
148  desc.label = "Nearest Sampler";
149  break;
150  case flutter::DlImageSampling::kLinear:
153  desc.label = "Linear Sampler";
154  break;
155  case flutter::DlImageSampling::kCubic:
156  case flutter::DlImageSampling::kMipmapLinear:
159  desc.label = "Mipmap Linear Sampler";
160  break;
161  }
162  return desc;
163 }
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
@ kBase
The texture is sampled as if it only had a single mipmap level.
@ kNearest
Select nearest to the sample point. Most widely supported.

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

85  {
86  return Size(point.fX, point.fY);
87 }
TSize< Scalar > Size
Definition: size.h:171

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