Skip to content

Commit 3a6417f

Browse files
authored
Make DisplayLists' use of DlPaint, SkPaint, and impeller::Paint agree on the default isAntiAlias (flutter#193939)
The existing code has a mismatch with the default `isAntiAlias` value of various initial `Paint` properties used throughout the code. - `DisplayListBuilder` uses a default `DlPaint`, which has a default `isAntiAlias=false`. - Skia's `DlSkPaintDispatchHelper` use a default `SkPaint`, which has a default `isAntiAlias=false`. - Impeller's `DlOpReceiver`s use a default `impeller::Paint`, which has a default `isAntiAlias=true`. The mismatch of `impeller::Paint` and `DisplayListBuilder`'s `DlPaint` causes issues. `DisplayListBuilder`'s `setAntiAlias` no-op exits if setting the same value as its internal `DlPaint` state: https://github.com/flutter/flutter/blob/d454b1b841d223f28bb725bb2928e2ac337b5611/engine/src/flutter/display_list/dl_builder.h#L277-L281 That works correctly if all its downstream `DlOpReceiver`s have matching initial values for their `Paint` state. But this is not the case for `impeller::Paint`. If we get a `Paint` with `setAntiAlias(false)`, `DisplayListBuilder` won't pass this setting to its downstream `DlOpReceiver`s, instead incorrectly assuming that the downstream receivers already have a default `false` value. All of these defaults need to agree. We can either change them all to `true` or all to `false`. This changes them all to `true`, which matches the default `isAntiAlias=true` used for the `dart:ui` `Paint`. - Adds a new `kDefaultAntiAlias = true` const to `DlPaint`, which it uses when initializing itself. Its default value is now `true` instead of `false`. - Skia's `DlSkPaintDispatchHelper` explicitly sets its `SkPaint` using `DlPaint::kDefaultAntiAlias`. Its default value is now `true` instead of `false`. - Impeller's `impeller::Paint` sets its default with `DlPaint::kDefaultAntiAlias`. This is the same as its existing `true` default, but setting it this way is more consistent and explicit about matching `DlPaint`. - Updates tests which relied on `DlPaint` being non-anti-aliased. Adds new tests to ensure the default paint in `DlSkPaintDispatchHelper` and the default `impeller::Paint` match `DlPaint`. Fixes flutter#193388 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [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]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [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]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **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 [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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 [flutter/website]: https://github.com/flutter/website [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 4249ccb commit 3a6417f

17 files changed

Lines changed: 91 additions & 19 deletions

‎engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ TEST(DisplayListComplexity, NestedDisplayList) {
7777

7878
TEST(DisplayListComplexity, AntiAliasing) {
7979
DisplayListBuilder builder_no_aa;
80-
builder_no_aa.DrawLine(DlPoint(0, 0), DlPoint(100, 100), DlPaint());
80+
builder_no_aa.DrawLine(DlPoint(0, 0), DlPoint(100, 100),
81+
DlPaint().setAntiAlias(false));
8182
auto display_list_no_aa = builder_no_aa.Build();
8283

8384
DisplayListBuilder builder_aa;
@@ -95,12 +96,12 @@ TEST(DisplayListComplexity, AntiAliasing) {
9596
TEST(DisplayListComplexity, StrokeWidth) {
9697
DisplayListBuilder builder_stroke_0;
9798
builder_stroke_0.DrawLine(DlPoint(0, 0), DlPoint(100, 100),
98-
DlPaint().setStrokeWidth(0.0f));
99+
DlPaint().setAntiAlias(false).setStrokeWidth(0.0f));
99100
auto display_list_stroke_0 = builder_stroke_0.Build();
100101

101102
DisplayListBuilder builder_stroke_1;
102103
builder_stroke_1.DrawLine(DlPoint(0, 0), DlPoint(100, 100),
103-
DlPaint().setStrokeWidth(1.0f));
104+
DlPaint().setAntiAlias(false).setStrokeWidth(1.0f));
104105
auto display_list_stroke_1 = builder_stroke_1.Build();
105106

106107
auto calculators = AccumulatorCalculators();

‎engine/src/flutter/display_list/display_list_unittests.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ TEST_F(DisplayListTest, BuildRestoresAttributes) {
477477
DisplayListBuilder builder(cull_rect);
478478
DlOpReceiver& receiver = ToReceiver(builder);
479479

480-
receiver.setAntiAlias(true);
480+
receiver.setAntiAlias(!DlPaint::kDefaultAntiAlias);
481481
builder.Build();
482482
check_defaults(builder, cull_rect);
483483

@@ -1886,7 +1886,7 @@ TEST_F(DisplayListTest, FlutterSvgIssue661BoundsWereEmpty) {
18861886
EXPECT_EQ(DlIRect::RoundOut(display_list->GetBounds()),
18871887
DlIRect::MakeWH(100, 100));
18881888
EXPECT_EQ(display_list->op_count(), 19u);
1889-
EXPECT_EQ(display_list->bytes(), sizeof(DisplayList) + 408u);
1889+
EXPECT_EQ(display_list->bytes(), sizeof(DisplayList) + 400u);
18901890
EXPECT_EQ(display_list->total_depth(), 3u);
18911891
}
18921892

‎engine/src/flutter/display_list/dl_op_receiver.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class DlOpReceiver {
9797
// attribute for the rest of the display list or until it is reset by
9898
// another method that changes the same attribute. The current set of
9999
// attributes is not affected by |save| and |restore|.
100+
//
101+
// The |DisplayListBuilder| only records an attribute when its value differs
102+
// from |DlPaint::kDefault|, so a receiver must begin every DisplayList with
103+
// its attribute state equal to |DlPaint::kDefault|.
100104
virtual void setAntiAlias(bool aa) = 0;
101105
virtual void setDrawStyle(DlDrawStyle style) = 0;
102106
virtual void setColor(DlColor color) = 0;

‎engine/src/flutter/display_list/dl_paint.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ DlPaint::DlPaint(DlColor color)
1313
draw_style_(static_cast<unsigned>(DlDrawStyle::kDefaultStyle)),
1414
stroke_cap_(static_cast<unsigned>(DlStrokeCap::kDefaultCap)),
1515
stroke_join_(static_cast<unsigned>(DlStrokeJoin::kDefaultJoin)),
16+
is_anti_alias_(kDefaultAntiAlias),
1617
color_(color),
1718
stroke_width_(kDefaultWidth),
1819
stroke_miter_(kDefaultMiter) {}

‎engine/src/flutter/display_list/dl_paint.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class DlPaint {
4848
static constexpr DlColor kDefaultColor = DlColor::kBlack();
4949
static constexpr float kDefaultWidth = 0.0;
5050
static constexpr float kDefaultMiter = 4.0;
51+
// Matches the default of dart:ui Paint.isAntiAlias.
52+
static constexpr bool kDefaultAntiAlias = true;
5153

5254
static const DlPaint kDefault;
5355

‎engine/src/flutter/display_list/dl_paint_unittests.cc‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace testing {
1414

1515
TEST(DisplayListPaint, ConstructorDefaults) {
1616
DlPaint paint;
17-
EXPECT_FALSE(paint.isAntiAlias());
17+
EXPECT_TRUE(paint.isAntiAlias());
1818
EXPECT_FALSE(paint.isInvertColors());
1919
EXPECT_EQ(paint.getColor(), DlPaint::kDefaultColor);
2020
EXPECT_EQ(paint.getAlpha(), 0xFF);
@@ -39,12 +39,13 @@ TEST(DisplayListPaint, ConstructorDefaults) {
3939
EXPECT_EQ(DlPaint::kDefaultColor, DlColor::kBlack());
4040
EXPECT_EQ(DlPaint::kDefaultWidth, 0.0);
4141
EXPECT_EQ(DlPaint::kDefaultMiter, 4.0);
42+
EXPECT_TRUE(DlPaint::kDefaultAntiAlias);
4243

4344
EXPECT_EQ(paint, DlPaint());
4445
EXPECT_EQ(paint, DlPaint(DlColor::kBlack()));
4546
EXPECT_EQ(paint, DlPaint(DlColor(0xFF000000)));
4647

47-
EXPECT_NE(paint, DlPaint().setAntiAlias(true));
48+
EXPECT_NE(paint, DlPaint().setAntiAlias(false));
4849
EXPECT_NE(paint, DlPaint().setInvertColors(true));
4950
EXPECT_NE(paint, DlPaint().setColor(DlColor::kGreen()));
5051
EXPECT_NE(paint, DlPaint(DlColor::kGreen()));
@@ -115,7 +116,7 @@ TEST(DisplayListPaint, ChainingConstructor) {
115116
};
116117
DlPaint paint =
117118
DlPaint() //
118-
.setAntiAlias(true) //
119+
.setAntiAlias(false) //
119120
.setInvertColors(true) //
120121
.setColor(DlColor::kGreen()) //
121122
.setAlpha(0x7F) //
@@ -131,7 +132,7 @@ TEST(DisplayListPaint, ChainingConstructor) {
131132
DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kDstIn))
132133
.setImageFilter(DlImageFilter::MakeBlur(1.3, 4.7, DlTileMode::kClamp))
133134
.setMaskFilter(DlBlurMaskFilter(DlBlurStyle::kInner, 3.14).shared());
134-
EXPECT_TRUE(paint.isAntiAlias());
135+
EXPECT_FALSE(paint.isAntiAlias());
135136
EXPECT_TRUE(paint.isInvertColors());
136137
EXPECT_EQ(paint.getColor(), DlColor::kGreen().withAlpha(0x7F));
137138
EXPECT_EQ(paint.getAlpha(), 0x7F);

‎engine/src/flutter/display_list/skia/dl_sk_paint_dispatcher.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class DlSkPaintDispatchHelper : public virtual DlOpReceiver {
1717
public:
1818
explicit DlSkPaintDispatchHelper(SkScalar opacity = SK_Scalar1)
1919
: current_color_(DlColor::kBlack()), opacity_(opacity) {
20+
// SkPaint defaults to non-anti-aliased. Explicitly set it to match
21+
// DlPaint's default.
22+
paint_.setAntiAlias(DlPaint::kDefaultAntiAlias);
2023
if (opacity < SK_Scalar1) {
2124
paint_.setAlphaf(opacity);
2225
}

‎engine/src/flutter/display_list/skia/dl_sk_paint_dispatcher_unittests.cc‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ TEST(DisplayListUtils, OverRestore) {
4646
helper.restore();
4747
}
4848

49+
// Initial paint must match DlPaint::kDefault (see DlOpReceiver).
50+
// https://github.com/flutter/flutter/issues/193388.
51+
TEST(DisplayListUtils, InitialPaintMatchesDlPaintDefaults) {
52+
MockDispatchHelper helper;
53+
const SkPaint& sk_paint = helper.paint();
54+
const DlPaint& defaults = DlPaint::kDefault;
55+
56+
EXPECT_EQ(sk_paint.isAntiAlias(), defaults.isAntiAlias());
57+
EXPECT_EQ(sk_paint.getColor4f().toSkColor(), defaults.getColor().argb());
58+
EXPECT_EQ(sk_paint.getStrokeWidth(), defaults.getStrokeWidth());
59+
EXPECT_EQ(sk_paint.getStrokeMiter(), defaults.getStrokeMiter());
60+
EXPECT_EQ(sk_paint.getStyle(), SkPaint::kFill_Style);
61+
EXPECT_EQ(sk_paint.getStrokeCap(), SkPaint::kButt_Cap);
62+
EXPECT_EQ(sk_paint.getStrokeJoin(), SkPaint::kMiter_Join);
63+
EXPECT_EQ(sk_paint.asBlendMode(), SkBlendMode::kSrcOver);
64+
EXPECT_EQ(sk_paint.getShader(), nullptr);
65+
EXPECT_EQ(sk_paint.getColorFilter(), nullptr);
66+
EXPECT_EQ(sk_paint.getImageFilter(), nullptr);
67+
EXPECT_EQ(sk_paint.getMaskFilter(), nullptr);
68+
}
69+
4970
// https://github.com/flutter/flutter/issues/132860.
5071
TEST(DisplayListUtils, SetColorSourceDithersIfGradient) {
5172
MockDispatchHelper helper;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ struct DlJobRenderer : public MatrixClipJobRenderer {
405405
DlCanvas* canvas,
406406
const RenderJobInfo& info) override {
407407
FML_DCHECK(info.opacity == 1.0f);
408-
DlPaint paint;
408+
// Some tests assume non-anti-aliased rendering. Anti-aliasing is tested
409+
// explicitly in RenderWithAttributes.
410+
DlPaint paint = DlPaint().setAntiAlias(false);
409411
dl_setup_({env, canvas, paint});
410412
setup_paint_ = paint;
411413
setup_matrix_ = canvas->GetMatrix();

‎engine/src/flutter/display_list/testing/dl_test_snippets.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ std::vector<DisplayListInvocationGroup> CreateAllAttributesOps() {
9090
return {
9191
{"SetAntiAlias",
9292
{
93-
{0, 8, 0, [](DlOpReceiver& r) { r.setAntiAlias(true); }},
93+
{0, 8, 0, [](DlOpReceiver& r) { r.setAntiAlias(false); }},
9494

9595
// Reset attribute to default as last entry
96-
{0, 0, 0, [](DlOpReceiver& r) { r.setAntiAlias(false); }},
96+
{0, 0, 0, [](DlOpReceiver& r) { r.setAntiAlias(true); }},
9797
}},
9898
{"SetInvertColors",
9999
{

0 commit comments

Comments
 (0)