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);
60 auto verb = SkPath::Verb::kDone_Verb;
62 verb = iterator.next(data.points);
64 case SkPath::kMove_Verb:
67 case SkPath::kLine_Verb:
70 case SkPath::kQuad_Verb:
74 case SkPath::kConic_Verb: {
75 constexpr
auto kPow2 = 1;
76 constexpr
auto kQuadCount = 1 + (2 * (1 << kPow2));
77 SkPoint points[kQuadCount];
78 const auto curve_count =
79 SkPath::ConvertConicToQuads(data.points[0],
82 iterator.conicWeight(),
87 for (
int curve_index = 0, point_index = 0;
88 curve_index < curve_count;
89 curve_index++, point_index += 2
92 ToPoint(points[point_index + 2]));
95 case SkPath::kCubic_Verb:
99 case SkPath::kClose_Verb:
102 case SkPath::kDone_Verb:
105 }
while (verb != SkPath::Verb::kDone_Verb);
108 switch (path.getFillType()) {
109 case SkPathFillType::kWinding:
112 case SkPathFillType::kEvenOdd:
115 case SkPathFillType::kInverseWinding:
116 case SkPathFillType::kInverseEvenOdd:
124 builder.
Shift(shift);
125 auto sk_bounds = path.getBounds().makeOutset(shift.
x, shift.
y);
144 static_cast<Scalar>(color.getRedF()),
145 static_cast<Scalar>(color.getGreenF()),
146 static_cast<Scalar>(color.getBlueF()),
147 static_cast<Scalar>(color.getAlphaF())
151 std::vector<Matrix>
ToRSXForms(
const SkRSXform xform[],
int count) {
152 auto result = std::vector<Matrix>();
153 for (
int i = 0; i < count; i++) {
154 auto form = xform[i];
157 form.fSCos, form.fSSin, 0, 0,
158 -form.fSSin, form.fSCos, 0, 0,
160 form.fTx, form.fTy, 0, 1
163 result.push_back(matrix);
173 return ToPath(skia::textlayout::Paragraph::GetPath(blob.get()), shift);
178 case kRGBA_8888_SkColorType:
180 case kBGRA_8888_SkColorType:
182 case kRGBA_F16_SkColorType:
184 case kBGR_101010x_XR_SkColorType:
193 std::vector<Color>& colors,
194 std::vector<float>& stops) {
195 FML_DCHECK(gradient->stop_count() >= 2);
197 auto* dl_colors = gradient->colors();
198 auto* dl_stops = gradient->stops();
199 if (dl_stops[0] != 0.0) {
201 stops.emplace_back(0);
203 for (
auto i = 0; i < gradient->stop_count(); i++) {
205 stops.emplace_back(std::clamp(dl_stops[i], 0.0f, 1.0f));
207 if (dl_stops[gradient->stop_count() - 1] != 1.0) {
208 colors.emplace_back(colors.back());
209 stops.emplace_back(1.0);
211 for (
auto i = 1; i < gradient->stop_count(); i++) {
212 stops[i] = std::clamp(stops[i], stops[i - 1], stops[i]);