6 #include "display_list/dl_color.h"
7 #include "third_party/skia/modules/skparagraph/include/Paragraph.h"
10 namespace skia_conversions {
13 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
16 std::optional<Rect>
ToRect(
const SkRect* rect) {
17 if (rect ==
nullptr) {
20 return Rect::MakeLTRB(rect->fLeft, rect->fTop, rect->fRight, rect->fBottom);
23 std::vector<Rect>
ToRects(
const SkRect tex[],
int count) {
24 auto result = std::vector<Rect>();
25 for (
int i = 0; i < count; i++) {
26 result.push_back(
ToRect(tex[i]));
31 std::vector<Point>
ToPoints(
const SkPoint points[],
int count) {
32 std::vector<Point> result(count);
33 for (
auto i = 0; i < count; i++) {
40 using Corner = SkRRect::Corner;
50 auto iterator = SkPath::Iter(path,
false);
61 builder.
Reserve(path.countPoints() + 8, path.countVerbs() + 8);
62 auto verb = SkPath::Verb::kDone_Verb;
64 verb = iterator.next(data.points);
66 case SkPath::kMove_Verb:
69 case SkPath::kLine_Verb:
72 case SkPath::kQuad_Verb:
76 case SkPath::kConic_Verb: {
77 constexpr
auto kPow2 = 1;
78 constexpr
auto kQuadCount = 1 + (2 * (1 << kPow2));
79 SkPoint points[kQuadCount];
80 const auto curve_count =
81 SkPath::ConvertConicToQuads(data.points[0],
84 iterator.conicWeight(),
89 for (
int curve_index = 0, point_index = 0;
90 curve_index < curve_count;
91 curve_index++, point_index += 2
94 ToPoint(points[point_index + 2]));
97 case SkPath::kCubic_Verb:
101 case SkPath::kClose_Verb:
104 case SkPath::kDone_Verb:
107 }
while (verb != SkPath::Verb::kDone_Verb);
110 switch (path.getFillType()) {
111 case SkPathFillType::kWinding:
114 case SkPathFillType::kEvenOdd:
117 case SkPathFillType::kInverseWinding:
118 case SkPathFillType::kInverseEvenOdd:
126 builder.
Shift(shift);
127 auto sk_bounds = path.getBounds().makeOutset(shift.
x, shift.
y);
145 return Size(point.fX, point.fY);
150 static_cast<Scalar>(color.getRedF()),
151 static_cast<Scalar>(color.getGreenF()),
152 static_cast<Scalar>(color.getBlueF()),
153 static_cast<Scalar>(color.getAlphaF())
157 std::vector<Matrix>
ToRSXForms(
const SkRSXform xform[],
int count) {
158 auto result = std::vector<Matrix>();
159 for (
int i = 0; i < count; i++) {
160 auto form = xform[i];
163 form.fSCos, form.fSSin, 0, 0,
164 -form.fSSin, form.fSCos, 0, 0,
166 form.fTx, form.fTy, 0, 1
169 result.push_back(matrix);
179 return ToPath(skia::textlayout::Paragraph::GetPath(blob.get()), shift);
184 case kRGBA_8888_SkColorType:
186 case kBGRA_8888_SkColorType:
188 case kRGBA_F16_SkColorType:
190 case kBGR_101010x_XR_SkColorType:
199 std::vector<Color>& colors,
200 std::vector<float>& stops) {
201 FML_DCHECK(gradient->stop_count() >= 2);
203 auto* dl_colors = gradient->colors();
204 auto* dl_stops = gradient->stops();
205 if (dl_stops[0] != 0.0) {
207 stops.emplace_back(0);
209 for (
auto i = 0; i < gradient->stop_count(); i++) {
211 stops.emplace_back(std::clamp(dl_stops[i], 0.0f, 1.0f));
213 if (dl_stops[gradient->stop_count() - 1] != 1.0) {
214 colors.emplace_back(colors.back());
215 stops.emplace_back(1.0);
217 for (
auto i = 1; i < gradient->stop_count(); i++) {
218 stops[i] = std::clamp(stops[i], stops[i - 1], stops[i]);