Skip to content

Commit 96fe3e2

Browse files
authored
Change Flutter APIs to use spans (flutter#177272)
Some old APIs are currently guarded by `SK_SUPPORT_UNSPANNED_APIS` and Skia plans to delete them (for example in this [CL](https://skia-review.googlesource.com/c/skia/+/1073616)). This updates Flutter calls to use the new APIs (by wrapping the pointers and counts together) and removes the define to avoid backsliding. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent efc4d23 commit 96fe3e2

File tree

14 files changed

+68
-51
lines changed

14 files changed

+68
-51
lines changed

engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ class SkMatrixAdapter : public SkiaAdapterBase {
213213
TestPoint out[],
214214
int n) const override {
215215
static_assert(sizeof(TestPoint) == sizeof(SkPoint));
216-
transform.sk_matrix.mapPoints(reinterpret_cast<SkPoint*>(out),
217-
reinterpret_cast<const SkPoint*>(in), n);
216+
transform.sk_matrix.mapPoints({reinterpret_cast<SkPoint*>(out), n},
217+
{reinterpret_cast<const SkPoint*>(in), n});
218218
}
219219

220220
void TransformRectFast(const TestTransform& transform,
@@ -234,7 +234,7 @@ class SkMatrixAdapter : public SkiaAdapterBase {
234234
SkPoint3 homogenous[4];
235235
SkPoint corners[4];
236236
rect.sk_rect.toQuad(corners);
237-
transform.sk_matrix.mapHomogeneousPoints(homogenous, corners, 4);
237+
transform.sk_matrix.mapPointsToHomogeneous({homogenous, 4}, {corners, 4});
238238
int count = 0;
239239
for (SkPoint3 hpt : homogenous) {
240240
if (hpt.fZ <= 0) {
@@ -299,8 +299,9 @@ class SkM44Adapter : public SkiaAdapterBase {
299299
TestPoint out[],
300300
int n) const override {
301301
static_assert(sizeof(TestPoint) == sizeof(SkPoint));
302-
transform.sk_m44.asM33().mapPoints(reinterpret_cast<SkPoint*>(out),
303-
reinterpret_cast<const SkPoint*>(in), n);
302+
transform.sk_m44.asM33().mapPoints(
303+
{reinterpret_cast<SkPoint*>(out), n},
304+
{reinterpret_cast<const SkPoint*>(in), n});
304305
}
305306

306307
void TransformRectFast(const TestTransform& transform,
@@ -328,7 +329,8 @@ class SkM44Adapter : public SkiaAdapterBase {
328329
SkPoint3 homogenous[4];
329330
SkPoint corners[4];
330331
rect.sk_rect.toQuad(corners);
331-
transform.sk_m44.asM33().mapHomogeneousPoints(homogenous, corners, 4);
332+
transform.sk_m44.asM33().mapPointsToHomogeneous({homogenous, 4},
333+
{corners, 4});
332334
int count = 0;
333335
for (SkPoint3 hpt : homogenous) {
334336
if (hpt.fZ <= 0) {

engine/src/flutter/display_list/geometry/dl_path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ DlPath DlPath::MakePoly(const DlPoint pts[],
9494
int count,
9595
bool close,
9696
DlPathFillType fill_type) {
97-
return DlPath(
98-
SkPath::Polygon(ToSkPoints(pts), count, close, ToSkFillType(fill_type)));
97+
return DlPath(SkPath::Polygon({ToSkPoints(pts), count}, close,
98+
ToSkFillType(fill_type)));
9999
}
100100

101101
DlPath DlPath::MakeArc(const DlRect& bounds,

engine/src/flutter/display_list/skia/dl_sk_canvas.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void DlSkCanvasAdapter::DrawDashedLine(const DlPoint& p0,
214214
const DlPaint& paint) {
215215
SkPaint dashed_paint = ToStrokedSk(paint);
216216
SkScalar intervals[2] = {on_length, off_length};
217-
dashed_paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f));
217+
dashed_paint.setPathEffect(SkDashPathEffect::Make({intervals, 2}, 0.0f));
218218
delegate_->drawLine(ToSkPoint(p0), ToSkPoint(p1), dashed_paint);
219219
}
220220

@@ -266,7 +266,8 @@ void DlSkCanvasAdapter::DrawPoints(DlPointMode mode,
266266
uint32_t count,
267267
const DlPoint pts[],
268268
const DlPaint& paint) {
269-
delegate_->drawPoints(ToSk(mode), count, ToSkPoints(pts), ToStrokedSk(paint));
269+
delegate_->drawPoints(ToSk(mode), {ToSkPoints(pts), count},
270+
ToStrokedSk(paint));
270271
}
271272

272273
void DlSkCanvasAdapter::DrawVertices(
@@ -325,9 +326,10 @@ void DlSkCanvasAdapter::DrawAtlas(const sk_sp<DlImage>& atlas,
325326
for (int i = 0; i < count; ++i) {
326327
sk_colors.push_back(colors[i].argb());
327328
}
328-
delegate_->drawAtlas(sk_image.get(), ToSk(xform), ToSkRects(tex),
329-
sk_colors.data(), count, ToSk(mode), ToSk(sampling),
330-
ToSkRect(cullRect), sk_paint());
329+
delegate_->drawAtlas(sk_image.get(), {ToSk(xform), count},
330+
{ToSkRects(tex), count}, {sk_colors.data(), count},
331+
ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
332+
sk_paint());
331333
}
332334

333335
void DlSkCanvasAdapter::DrawDisplayList(const sk_sp<DisplayList> display_list,

engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void DlSkCanvasDispatcher::drawDashedLine(const DlPoint& p0,
181181
DlScalar off_length) {
182182
SkPaint dash_paint = paint();
183183
SkScalar intervals[] = {on_length, off_length};
184-
dash_paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f));
184+
dash_paint.setPathEffect(SkDashPathEffect::Make({intervals, 2}, 0.0f));
185185
canvas_->drawLine(ToSkPoint(p0), ToSkPoint(p1), dash_paint);
186186
}
187187
void DlSkCanvasDispatcher::drawRect(const DlRect& rect) {
@@ -218,7 +218,7 @@ void DlSkCanvasDispatcher::drawArc(const DlRect& bounds,
218218
void DlSkCanvasDispatcher::drawPoints(DlPointMode mode,
219219
uint32_t count,
220220
const DlPoint pts[]) {
221-
canvas_->drawPoints(ToSk(mode), count, ToSkPoints(pts), paint());
221+
canvas_->drawPoints(ToSk(mode), {ToSkPoints(pts), count}, paint());
222222
}
223223
void DlSkCanvasDispatcher::drawVertices(
224224
const std::shared_ptr<DlVertices>& vertices,
@@ -280,9 +280,15 @@ void DlSkCanvasDispatcher::drawAtlas(const sk_sp<DlImage> atlas,
280280
sk_colors.push_back(colors[i].argb());
281281
}
282282
}
283-
canvas_->drawAtlas(skia_atlas.get(), ToSk(xform), ToSkRects(tex),
284-
sk_colors.empty() ? nullptr : sk_colors.data(), count,
285-
ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
283+
SkSpan<const SkColor> colorSpan;
284+
if (!colors) {
285+
colorSpan = {nullptr, 0};
286+
} else {
287+
colorSpan = {sk_colors.data(), count};
288+
}
289+
canvas_->drawAtlas(skia_atlas.get(), {ToSk(xform), count},
290+
{ToSkRects(tex), count}, colorSpan, ToSk(mode),
291+
ToSk(sampling), ToSkRect(cullRect),
286292
safe_paint(render_with_attributes));
287293
}
288294
void DlSkCanvasDispatcher::drawDisplayList(

engine/src/flutter/display_list/testing/dl_rendering_unittests.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,7 +3087,7 @@ TEST_F(DisplayListRendering, DrawDiagonalDashedLines) {
30873087
SkPaint p = ctx.paint;
30883088
p.setStyle(SkPaint::kStroke_Style);
30893089
DlScalar intervals[2] = {25.0f, 5.0f};
3090-
p.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f));
3090+
p.setPathEffect(SkDashPathEffect::Make({intervals, 2}, 0.0f));
30913091
ctx.canvas->drawLine(ToSkPoint(p1), ToSkPoint(p2), p);
30923092
ctx.canvas->drawLine(ToSkPoint(p3), ToSkPoint(p4), p);
30933093
ctx.canvas->drawLine(ToSkPoint(p5), ToSkPoint(p6), p);
@@ -3299,7 +3299,7 @@ TEST_F(DisplayListRendering, DrawPointsAsPoints) {
32993299
SkPaint p = ctx.paint;
33003300
p.setStyle(SkPaint::kStroke_Style);
33013301
auto mode = SkCanvas::kPoints_PointMode;
3302-
ctx.canvas->drawPoints(mode, count, ToSkPoints(points), p);
3302+
ctx.canvas->drawPoints(mode, {ToSkPoints(points), count}, p);
33033303
},
33043304
[=](const DlRenderContext& ctx) {
33053305
auto mode = DlPointMode::kPoints;
@@ -3351,7 +3351,7 @@ TEST_F(DisplayListRendering, DrawPointsAsLines) {
33513351
SkPaint p = ctx.paint;
33523352
p.setStyle(SkPaint::kStroke_Style);
33533353
auto mode = SkCanvas::kLines_PointMode;
3354-
ctx.canvas->drawPoints(mode, count, ToSkPoints(points), p);
3354+
ctx.canvas->drawPoints(mode, {ToSkPoints(points), count}, p);
33553355
},
33563356
[=](const DlRenderContext& ctx) {
33573357
auto mode = DlPointMode::kLines;
@@ -3386,7 +3386,7 @@ TEST_F(DisplayListRendering, DrawPointsAsPolygon) {
33863386
SkPaint p = ctx.paint;
33873387
p.setStyle(SkPaint::kStroke_Style);
33883388
auto mode = SkCanvas::kPolygon_PointMode;
3389-
ctx.canvas->drawPoints(mode, count1, ToSkPoints(points1), p);
3389+
ctx.canvas->drawPoints(mode, {ToSkPoints(points1), count1}, p);
33903390
},
33913391
[=](const DlRenderContext& ctx) {
33923392
auto mode = DlPointMode::kPolygon;
@@ -3695,9 +3695,10 @@ TEST_F(DisplayListRendering, DrawAtlasNearest) {
36953695
CanvasCompareTester::RenderAll( //
36963696
TestParameters(
36973697
[=](const SkRenderContext& ctx) {
3698-
ctx.canvas->drawAtlas(ctx.image.get(), sk_xform, ToSkRects(tex),
3699-
sk_colors, 4, SkBlendMode::kSrcOver,
3700-
sk_sampling, nullptr, &ctx.paint);
3698+
ctx.canvas->drawAtlas(ctx.image.get(), {sk_xform, 4},
3699+
{ToSkRects(tex), 4}, {sk_colors, 4},
3700+
SkBlendMode::kSrcOver, sk_sampling, nullptr,
3701+
&ctx.paint);
37013702
},
37023703
[=](const DlRenderContext& ctx) {
37033704
ctx.canvas->DrawAtlas(ctx.image, dl_xform, tex, dl_colors, 4,
@@ -3754,9 +3755,10 @@ TEST_F(DisplayListRendering, DrawAtlasNearestNoPaint) {
37543755
CanvasCompareTester::RenderAll( //
37553756
TestParameters(
37563757
[=](const SkRenderContext& ctx) {
3757-
ctx.canvas->drawAtlas(ctx.image.get(), sk_xform, ToSkRects(tex),
3758-
sk_colors, 4, SkBlendMode::kSrcOver,
3759-
sk_sampling, nullptr, nullptr);
3758+
ctx.canvas->drawAtlas(ctx.image.get(), {sk_xform, 4},
3759+
{ToSkRects(tex), 4}, {sk_colors, 4},
3760+
SkBlendMode::kSrcOver, sk_sampling, nullptr,
3761+
nullptr);
37603762
},
37613763
[=](const DlRenderContext& ctx) {
37623764
ctx.canvas->DrawAtlas(ctx.image, dl_xform, tex, dl_colors, 4,
@@ -3813,9 +3815,10 @@ TEST_F(DisplayListRendering, DrawAtlasLinear) {
38133815
CanvasCompareTester::RenderAll( //
38143816
TestParameters(
38153817
[=](const SkRenderContext& ctx) {
3816-
ctx.canvas->drawAtlas(ctx.image.get(), sk_xform, ToSkRects(tex),
3817-
sk_colors, 2, SkBlendMode::kSrcOver,
3818-
sk_sampling, nullptr, &ctx.paint);
3818+
ctx.canvas->drawAtlas(ctx.image.get(), {sk_xform, 2},
3819+
{ToSkRects(tex), 2}, {sk_colors, 2},
3820+
SkBlendMode::kSrcOver, sk_sampling, nullptr,
3821+
&ctx.paint);
38193822
},
38203823
[=](const DlRenderContext& ctx) {
38213824
ctx.canvas->DrawAtlas(ctx.image, dl_xform, tex, dl_colors, 2,

engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ static void DrawGlyph(SkCanvas* canvas,
248248
canvas->save();
249249
Point subpixel_offset = SubpixelPositionToPoint(glyph.subpixel_offset);
250250
canvas->translate(subpixel_offset.x, subpixel_offset.y);
251-
canvas->drawGlyphs(1u, // count
252-
&glyph_id, // glyphs
253-
&position, // positions
251+
// Draw a single glyph in the bounds
252+
canvas->drawGlyphs({&glyph_id, 1u}, // glyphs
253+
{&position, 1u}, // positions
254254
SkPoint::Make(-scaled_bounds.GetLeft(),
255255
-scaled_bounds.GetTop()), // origin
256256
sk_font, // font
@@ -406,7 +406,8 @@ static Rect ComputeGlyphSize(const SkFont& font,
406406
glyph_paint.setStrokeJoin(ToSkiaJoin(glyph.properties->stroke->join));
407407
glyph_paint.setStrokeMiter(glyph.properties->stroke->miter_limit);
408408
}
409-
font.getBounds(&glyph.glyph.index, 1, &scaled_bounds, &glyph_paint);
409+
// Get bounds for a single glyph
410+
font.getBounds({&glyph.glyph.index, 1}, {&scaled_bounds, 1}, &glyph_paint);
410411

411412
// Expand the bounds of glyphs at subpixel offsets by 2 in the x direction.
412413
Scalar adjustment = 0.0;

engine/src/flutter/impeller/typographer/typographer_unittests.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,10 @@ TEST_P(TypographerTest, GlyphAtlasTextureWillGrowTilMaxTextureSize) {
478478
auto add_char = [&](const SkFont& sk_font, char c) {
479479
int count = sk_font.countText(&c, 1, SkTextEncoding::kUTF8);
480480
auto buffer = builder.allocRunPos(sk_font, count);
481-
sk_font.textToGlyphs(&c, 1, SkTextEncoding::kUTF8, buffer.glyphs, count);
482-
sk_font.getPos(buffer.glyphs, count, buffer.points(), {0, 0});
481+
sk_font.textToGlyphs(&c, 1, SkTextEncoding::kUTF8,
482+
{buffer.glyphs, count});
483+
sk_font.getPos({buffer.glyphs, count}, {buffer.points(), count},
484+
{0, 0} /*=origin*/);
483485
};
484486

485487
SkFont sk_font = flutter::testing::CreateTestFontOfSize(50 + i);

engine/src/flutter/lib/ui/painting/path.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ void CanvasPath::addArc(double left,
194194
}
195195

196196
void CanvasPath::addPolygon(const tonic::Float32List& points, bool close) {
197-
sk_path_.addPoly(reinterpret_cast<const SkPoint*>(points.data()),
198-
points.num_elements() / 2, close);
197+
SkSpan<const SkPoint> ptsSpan = {
198+
reinterpret_cast<const SkPoint*>(points.data()),
199+
points.num_elements() / 2};
200+
sk_path_.addPoly(ptsSpan, close);
199201
resetVolatility();
200202
}
201203

engine/src/flutter/lib/web_ui/skwasm/fonts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ SKWASM_EXPORT int typefaces_filterCoveredCodePoints(SkTypeface** typefaces,
6161
int remainingCodePointCount = codePointCount;
6262
for (int typefaceIndex = 0; typefaceIndex < typefaceCount; typefaceIndex++) {
6363
typefaces[typefaceIndex]->unicharsToGlyphs(
64-
codePoints, remainingCodePointCount, glyphPointer);
64+
{codePoints, remainingCodePointCount},
65+
{glyphPointer, remainingCodePointCount});
6566
int outputIndex = 0;
6667
for (int inputIndex = 0; inputIndex < remainingCodePointCount;
6768
inputIndex++) {

engine/src/flutter/lib/web_ui/skwasm/path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ SKWASM_EXPORT void path_addPolygon(SkPath* path,
154154
const SkPoint* points,
155155
int count,
156156
bool close) {
157-
path->addPoly(points, count, close);
157+
path->addPoly({points, count}, close);
158158
}
159159

160160
SKWASM_EXPORT void path_addRRect(SkPath* path, const SkScalar* rrectValues) {

0 commit comments

Comments
 (0)