Flutter Engine
 
Loading...
Searching...
No Matches
formats.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_TOOLKIT_INTEROP_FORMATS_H_
6#define FLUTTER_IMPELLER_TOOLKIT_INTEROP_FORMATS_H_
7
8#include <vector>
9
23
24#include "flutter/third_party/skia/include/core/SkM44.h"
25#include "flutter/third_party/skia/include/core/SkPath.h"
26#include "flutter/third_party/skia/include/core/SkRRect.h"
27
28namespace impeller::interop {
29
30constexpr std::optional<SkRect> ToSkiaType(const ImpellerRect* rect) {
31 if (!rect) {
32 return std::nullopt;
33 }
34 return SkRect::MakeXYWH(rect->x, rect->y, rect->width, rect->height);
35}
36
37constexpr SkPoint ToSkiaType(const Point& point) {
38 return SkPoint::Make(point.x, point.y);
39}
40
41constexpr SkColor ToSkiaType(const ImpellerColor& color) {
42 return SkColorSetARGB(color.alpha * 255, //
43 color.red * 255, //
44 color.green * 255, //
45 color.blue * 255 //
46 );
47}
48
49constexpr SkVector ToSkiaVector(const Size& point) {
50 return SkVector::Make(point.width, point.height);
51}
52
53constexpr SkRect ToSkiaType(const Rect& rect) {
54 return SkRect::MakeXYWH(rect.GetX(), //
55 rect.GetY(), //
56 rect.GetWidth(), //
57 rect.GetHeight() //
58 );
59}
60
61constexpr SkPathFillType ToSkiaType(FillType type) {
62 switch (type) {
64 return SkPathFillType::kWinding;
65 case FillType::kOdd:
66 return SkPathFillType::kEvenOdd;
67 }
68 return SkPathFillType::kWinding;
69}
70
71constexpr SkIRect ToSkiaType(IRect rect) {
72 return SkIRect::MakeXYWH(rect.GetX(), //
73 rect.GetY(), //
74 rect.GetWidth(), //
75 rect.GetHeight() //
76 );
77}
78
79template <class SkiaType, class OtherType>
80std::vector<SkiaType> ToSkiaType(const std::vector<OtherType>& other_vec) {
81 std::vector<SkiaType> skia_vec;
82 skia_vec.reserve(other_vec.size());
83 for (const auto& other : other_vec) {
84 skia_vec.emplace_back(ToSkiaType(other));
85 }
86 return skia_vec;
87}
88
90 return flutter::DlColor::RGBA(color.red, //
91 color.green, //
92 color.blue, //
93 color.alpha //
94 );
95}
96
97inline SkMatrix ToSkMatrix(const Matrix& matrix) {
98 return SkM44::ColMajor(matrix.m).asM33();
99}
100
101template <class DlType, class OtherType>
102std::vector<DlType> ToDisplayListType(const std::vector<OtherType>& other_vec) {
103 std::vector<DlType> dl_vec;
104 dl_vec.reserve(other_vec.size());
105 for (const auto& other : other_vec) {
106 dl_vec.emplace_back(ToDisplayListType(other));
107 }
108 return dl_vec;
109}
110
121
135
137 using Mode = flutter::DlBlendMode;
138 switch (mode) {
140 return Mode::kClear;
141 case BlendMode::kSrc:
142 return Mode::kSrc;
143 case BlendMode::kDst:
144 return Mode::kDst;
146 return Mode::kSrcOver;
148 return Mode::kDstOver;
150 return Mode::kSrcIn;
152 return Mode::kDstIn;
154 return Mode::kSrcOut;
156 return Mode::kDstOut;
158 return Mode::kSrcATop;
160 return Mode::kDstATop;
161 case BlendMode::kXor:
162 return Mode::kXor;
163 case BlendMode::kPlus:
164 return Mode::kPlus;
166 return Mode::kModulate;
168 return Mode::kScreen;
170 return Mode::kOverlay;
172 return Mode::kDarken;
174 return Mode::kLighten;
176 return Mode::kColorDodge;
178 return Mode::kColorBurn;
180 return Mode::kHardLight;
182 return Mode::kSoftLight;
184 return Mode::kDifference;
186 return Mode::kExclusion;
188 return Mode::kMultiply;
189 case BlendMode::kHue:
190 return Mode::kHue;
192 return Mode::kSaturation;
194 return Mode::kColor;
196 return Mode::kLuminosity;
197 }
198 return Mode::kSrcOver;
199}
200
201inline SkRRect ToSkiaType(const Rect& rect, const RoundingRadii& radii) {
202 using Corner = SkRRect::Corner;
203 SkVector sk_radii[4];
204 sk_radii[Corner::kUpperLeft_Corner] = ToSkiaVector(radii.top_left);
205 sk_radii[Corner::kUpperRight_Corner] = ToSkiaVector(radii.top_right);
206 sk_radii[Corner::kLowerRight_Corner] = ToSkiaVector(radii.bottom_right);
207 sk_radii[Corner::kLowerLeft_Corner] = ToSkiaVector(radii.bottom_left);
208 SkRRect result;
209 result.setRectRadii(ToSkiaType(rect), sk_radii);
210 return result;
211}
212
214 return Matrix(m.m[0], m.m[1], m.m[2], m.m[3], //
215 m.m[4], m.m[5], m.m[6], m.m[7], //
216 m.m[8], m.m[9], m.m[10], m.m[11], //
217 m.m[12], m.m[13], m.m[14], m.m[15] //
218 );
219}
220
221constexpr void FromImpellerType(const Matrix& from, ImpellerMatrix& to) {
222 to.m[0] = from.m[0];
223 to.m[1] = from.m[1];
224 to.m[2] = from.m[2];
225 to.m[3] = from.m[3];
226 to.m[4] = from.m[4];
227 to.m[5] = from.m[5];
228 to.m[6] = from.m[6];
229 to.m[7] = from.m[7];
230 to.m[8] = from.m[8];
231 to.m[9] = from.m[9];
232 to.m[10] = from.m[10];
233 to.m[11] = from.m[11];
234 to.m[12] = from.m[12];
235 to.m[13] = from.m[13];
236 to.m[14] = from.m[14];
237 to.m[15] = from.m[15];
238}
239
240constexpr Size ToImpellerType(const ImpellerSize& size) {
241 return Size{size.width, size.height};
242}
243
244constexpr Point ToImpellerType(const ImpellerPoint& point) {
245 return Point{point.x, point.y};
246}
247
248constexpr Size ToImpellerSize(const ImpellerPoint& point) {
249 return Size{point.x, point.y};
250}
251
252constexpr Rect ToImpellerType(const ImpellerRect& rect) {
253 return Rect::MakeXYWH(rect.x, rect.y, rect.width, rect.height);
254}
255
269
271 auto result = RoundingRadii{};
272 result.top_left = ToImpellerSize(radii.top_left);
273 result.bottom_left = ToImpellerSize(radii.bottom_left);
274 result.top_right = ToImpellerSize(radii.top_right);
275 result.bottom_right = ToImpellerSize(radii.bottom_right);
276 return result;
277}
278
280 switch (type) {
282 return FillType::kNonZero;
284 return FillType::kOdd;
285 }
286 return FillType::kNonZero;
287}
288
298
299constexpr Color ToImpellerType(const ImpellerColor& color) {
300 Color result;
301 result.red = color.red;
302 result.green = color.green;
303 result.blue = color.blue;
304 result.alpha = color.alpha;
305 return result;
306}
307
309 switch (mode) {
311 return BlendMode::kClear;
313 return BlendMode::kSrc;
315 return BlendMode::kDst;
317 return BlendMode::kSrcOver;
319 return BlendMode::kDstOver;
321 return BlendMode::kSrcIn;
323 return BlendMode::kDstIn;
325 return BlendMode::kSrcOut;
327 return BlendMode::kDstOut;
329 return BlendMode::kSrcATop;
331 return BlendMode::kDstATop;
333 return BlendMode::kXor;
335 return BlendMode::kPlus;
339 return BlendMode::kScreen;
341 return BlendMode::kOverlay;
343 return BlendMode::kDarken;
345 return BlendMode::kLighten;
361 return BlendMode::kHue;
365 return BlendMode::kColor;
368 }
369 return BlendMode::kSrcOver;
370}
371
383
395
407
415
416constexpr ISize ToImpellerType(const ImpellerISize& size) {
417 return ISize::MakeWH(size.width, size.height);
418}
419
432
434 return flutter::DlColor(color.alpha, //
435 color.red, //
436 color.green, //
437 color.blue, //
439 );
440}
441
458
459constexpr int ToTxtType(ImpellerFontWeight weight) {
460 switch (weight) {
462 return 100;
464 return 200;
466 return 300;
468 return 400;
470 return 500;
472 return 600;
474 return 700;
476 return 800;
478 return 900;
479 }
481}
482
484 switch (style) {
489 }
491}
492
510
512 switch (direction) {
517 }
519}
520
521} // namespace impeller::interop
522
523#endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_FORMATS_H_
GLenum type
uint32_t uint32_t * format
ImpellerFillType
Definition impeller.h:364
@ kImpellerFillTypeOdd
Definition impeller.h:366
@ kImpellerFillTypeNonZero
Definition impeller.h:365
ImpellerTextDirection
Definition impeller.h:479
@ kImpellerTextDirectionLTR
Definition impeller.h:481
@ kImpellerTextDirectionRTL
Definition impeller.h:480
ImpellerTextureSampling
Definition impeller.h:428
@ kImpellerTextureSamplingNearestNeighbor
Definition impeller.h:429
@ kImpellerTextureSamplingLinear
Definition impeller.h:430
ImpellerTextDecorationStyle
Definition impeller.h:491
@ kImpellerTextDecorationStyleSolid
Definition impeller.h:492
@ kImpellerTextDecorationStyleWavy
Definition impeller.h:496
@ kImpellerTextDecorationStyleDouble
Definition impeller.h:493
@ kImpellerTextDecorationStyleDotted
Definition impeller.h:494
@ kImpellerTextDecorationStyleDashed
Definition impeller.h:495
ImpellerStrokeJoin
Definition impeller.h:418
@ kImpellerStrokeJoinRound
Definition impeller.h:420
@ kImpellerStrokeJoinBevel
Definition impeller.h:421
@ kImpellerStrokeJoinMiter
Definition impeller.h:419
ImpellerBlendMode
Definition impeller.h:374
@ kImpellerBlendModeSaturation
Definition impeller.h:401
@ kImpellerBlendModeSoftLight
Definition impeller.h:396
@ kImpellerBlendModeHardLight
Definition impeller.h:395
@ kImpellerBlendModeLuminosity
Definition impeller.h:403
@ kImpellerBlendModeLighten
Definition impeller.h:392
@ kImpellerBlendModeModulate
Definition impeller.h:388
@ kImpellerBlendModeSourceIn
Definition impeller.h:380
@ kImpellerBlendModeDifference
Definition impeller.h:397
@ kImpellerBlendModeClear
Definition impeller.h:375
@ kImpellerBlendModeColor
Definition impeller.h:402
@ kImpellerBlendModeMultiply
Definition impeller.h:399
@ kImpellerBlendModeSourceATop
Definition impeller.h:384
@ kImpellerBlendModeDestinationOut
Definition impeller.h:383
@ kImpellerBlendModeScreen
Definition impeller.h:389
@ kImpellerBlendModeExclusion
Definition impeller.h:398
@ kImpellerBlendModeColorBurn
Definition impeller.h:394
@ kImpellerBlendModeDarken
Definition impeller.h:391
@ kImpellerBlendModePlus
Definition impeller.h:387
@ kImpellerBlendModeOverlay
Definition impeller.h:390
@ kImpellerBlendModeDestinationIn
Definition impeller.h:381
@ kImpellerBlendModeDestinationATop
Definition impeller.h:385
@ kImpellerBlendModeDestination
Definition impeller.h:377
@ kImpellerBlendModeSourceOver
Definition impeller.h:378
@ kImpellerBlendModeXor
Definition impeller.h:386
@ kImpellerBlendModeColorDodge
Definition impeller.h:393
@ kImpellerBlendModeDestinationOver
Definition impeller.h:379
@ kImpellerBlendModeSource
Definition impeller.h:376
@ kImpellerBlendModeSourceOut
Definition impeller.h:382
@ kImpellerBlendModeHue
Definition impeller.h:400
ImpellerFontWeight
Definition impeller.h:453
@ kImpellerFontWeight400
Definition impeller.h:457
@ kImpellerFontWeight500
Definition impeller.h:458
@ kImpellerFontWeight700
Definition impeller.h:460
@ kImpellerFontWeight200
Definition impeller.h:455
@ kImpellerFontWeight300
Definition impeller.h:456
@ kImpellerFontWeight900
Definition impeller.h:462
@ kImpellerFontWeight800
Definition impeller.h:461
@ kImpellerFontWeight600
Definition impeller.h:459
@ kImpellerFontWeight100
Definition impeller.h:454
ImpellerStrokeCap
Definition impeller.h:412
@ kImpellerStrokeCapButt
Definition impeller.h:413
@ kImpellerStrokeCapRound
Definition impeller.h:414
@ kImpellerStrokeCapSquare
Definition impeller.h:415
ImpellerDrawStyle
Definition impeller.h:406
@ kImpellerDrawStyleStroke
Definition impeller.h:408
@ kImpellerDrawStyleFill
Definition impeller.h:407
@ kImpellerDrawStyleStrokeAndFill
Definition impeller.h:409
ImpellerColorSpace
Definition impeller.h:447
@ kImpellerColorSpaceExtendedSRGB
Definition impeller.h:449
@ kImpellerColorSpaceSRGB
Definition impeller.h:448
@ kImpellerColorSpaceDisplayP3
Definition impeller.h:450
ImpellerTileMode
Definition impeller.h:433
@ kImpellerTileModeMirror
Definition impeller.h:436
@ kImpellerTileModeClamp
Definition impeller.h:434
@ kImpellerTileModeRepeat
Definition impeller.h:435
@ kImpellerTileModeDecal
Definition impeller.h:437
ImpellerTextAlignment
Definition impeller.h:470
@ kImpellerTextAlignmentJustify
Definition impeller.h:474
@ kImpellerTextAlignmentLeft
Definition impeller.h:471
@ kImpellerTextAlignmentCenter
Definition impeller.h:473
@ kImpellerTextAlignmentRight
Definition impeller.h:472
@ kImpellerTextAlignmentStart
Definition impeller.h:475
@ kImpellerTextAlignmentEnd
Definition impeller.h:476
ImpellerFontStyle
Definition impeller.h:465
@ kImpellerFontStyleItalic
Definition impeller.h:467
@ kImpellerFontStyleNormal
Definition impeller.h:466
ImpellerClipOperation
Definition impeller.h:369
@ kImpellerClipOperationIntersect
Definition impeller.h:371
@ kImpellerClipOperationDifference
Definition impeller.h:370
ImpellerBlurStyle
Definition impeller.h:440
@ kImpellerBlurStyleNormal
Definition impeller.h:441
@ kImpellerBlurStyleOuter
Definition impeller.h:443
@ kImpellerBlurStyleInner
Definition impeller.h:444
@ kImpellerBlurStyleSolid
Definition impeller.h:442
ImpellerPixelFormat
Definition impeller.h:424
@ kImpellerPixelFormatRGBA8888
Definition impeller.h:425
DlStrokeJoin
Definition dl_paint.h:37
@ kMiter
extends to miter limit
@ kBevel
connects outside edges
DlStrokeCap
Definition dl_paint.h:28
@ kRound
adds circle
@ kButt
no stroke extension
@ kSquare
adds square
DlDrawStyle
Definition dl_paint.h:19
@ kStrokeAndFill
both strokes and fills shapes
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes
DlColorSpace
Definition dl_color.h:13
@ kNormal
fuzzy inside and outside
@ kOuter
nothing inside, fuzzy outside
@ kInner
fuzzy inside, nothing outside
@ kSolid
solid inside, fuzzy outside
impeller::BlendMode DlBlendMode
constexpr SkVector ToSkiaVector(const Size &point)
Definition formats.h:49
constexpr txt::TextDecorationStyle ToTxtType(ImpellerTextDecorationStyle style)
Definition formats.h:442
SkMatrix ToSkMatrix(const Matrix &matrix)
Definition formats.h:97
constexpr Matrix ToImpellerType(const ImpellerMatrix &m)
Definition formats.h:213
constexpr Size ToImpellerSize(const ImpellerPoint &point)
Definition formats.h:248
constexpr std::optional< SkRect > ToSkiaType(const ImpellerRect *rect)
Definition formats.h:30
constexpr void FromImpellerType(const Matrix &from, ImpellerMatrix &to)
Definition formats.h:221
constexpr flutter::DlColor ToDisplayListType(Color color)
Definition formats.h:89
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
BlendMode
Definition color.h:58
FontStyle
Definition font_style.h:10
TextDecorationStyle
@ normal
Definition font_weight.h:12
ImpellerColorSpace color_space
Definition impeller.h:617
float m[16]
Definition impeller.h:540
float width
Definition impeller.h:505
float height
Definition impeller.h:506
ImpellerPoint top_left
Definition impeller.h:606
ImpellerPoint top_right
Definition impeller.h:608
ImpellerPoint bottom_left
Definition impeller.h:607
ImpellerPoint bottom_right
Definition impeller.h:609
static constexpr DlColor RGBA(DlScalar r, DlScalar g, DlScalar b, DlScalar a)
Construct a 32 bit color from floating point R, G, B, and A color channels.
Definition dl_color.h:48
Scalar blue
Definition color.h:138
Scalar alpha
Definition color.h:143
Scalar red
Definition color.h:128
Scalar green
Definition color.h:133
A 4x4 matrix using column-major storage.
Definition matrix.h:37
Scalar m[16]
Definition matrix.h:39
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition rect.h:337
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:347
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition rect.h:333
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:341
Type height
Definition size.h:29
Type width
Definition size.h:28
static constexpr TSize MakeWH(Type width, Type height)
Definition size.h:43