Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a338661

Browse files
author
Jonah Williams
authored
[display_list] allow applying opacity peephole to single glyph. (#53160)
A single glyph can be opacity peepholed, this is common in the case of Icons.
1 parent a6aa5d8 commit a338661

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

display_list/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ if (enable_unittests) {
131131
":display_list",
132132
":display_list_fixtures",
133133
"//flutter/display_list/testing:display_list_testing",
134+
"//flutter/impeller/typographer/backends/skia:typographer_skia_backend",
134135
"//flutter/testing",
135136
"//flutter/testing:skia",
136137
]

display_list/display_list_unittests.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "flutter/testing/display_list_testing.h"
2323
#include "flutter/testing/testing.h"
2424

25+
#include "impeller/typographer/backends/skia/text_frame_skia.h"
2526
#include "third_party/skia/include/core/SkBBHFactory.h"
2627
#include "third_party/skia/include/core/SkColorFilter.h"
2728
#include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -4331,5 +4332,30 @@ TEST_F(DisplayListTest, DrawDisplayListForwardsBackdropFlag) {
43314332
EXPECT_TRUE(parent_dl->root_has_backdrop_filter());
43324333
}
43334334

4335+
TEST_F(DisplayListTest, TextFrameOpacityPeephole) {
4336+
// Single character can have opacity peephole applied.
4337+
{
4338+
std::string message = "A";
4339+
sk_sp<SkTextBlob> blob = CreateTextBlob(message);
4340+
auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob);
4341+
DisplayListBuilder builder;
4342+
builder.DrawTextFrame(frame, 0, 0, {});
4343+
auto dl = builder.Build();
4344+
EXPECT_TRUE(dl->can_apply_group_opacity());
4345+
}
4346+
4347+
// Multiple characters cannot have opacity peephole applied.
4348+
{
4349+
std::string message = "ABC";
4350+
sk_sp<SkTextBlob> blob = CreateTextBlob(message);
4351+
4352+
auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob);
4353+
DisplayListBuilder builder;
4354+
builder.DrawTextFrame(frame, 0, 0, {});
4355+
auto dl = builder.Build();
4356+
EXPECT_FALSE(dl->can_apply_group_opacity());
4357+
}
4358+
}
4359+
43344360
} // namespace testing
43354361
} // namespace flutter

display_list/dl_builder.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,11 @@ void DisplayListBuilder::drawTextFrame(
16981698
// they will protect overlapping glyphs from the effects of overdraw
16991699
// so we must make the conservative assessment that this DL layer is
17001700
// not compatible with group opacity inheritance.
1701-
UpdateLayerOpacityCompatibility(false);
1701+
// A single glyph can still have the opacity peephole applied (this is
1702+
// likely a glyph used as an Icon)
1703+
const bool is_single_glyph = text_frame->GetRunCount() == 1u &&
1704+
text_frame->GetRuns()[0].GetGlyphCount() == 1u;
1705+
UpdateLayerOpacityCompatibility(is_single_glyph);
17021706
UpdateLayerResult(result);
17031707
}
17041708
}

display_list/testing/dl_test_snippets.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,5 +980,12 @@ sk_sp<SkTextBlob> GetTestTextBlob(int index) {
980980
return blob;
981981
}
982982

983+
sk_sp<SkTextBlob> CreateTextBlob(std::string& message) {
984+
sk_sp<SkTextBlob> blob =
985+
SkTextBlob::MakeFromText(message.c_str(), message.size(),
986+
CreateTestFontOfSize(20), SkTextEncoding::kUTF8);
987+
return blob;
988+
}
989+
983990
} // namespace testing
984991
} // namespace flutter

display_list/testing/dl_test_snippets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ SkFont CreateTestFontOfSize(SkScalar scalar);
227227

228228
sk_sp<SkTextBlob> GetTestTextBlob(int index);
229229

230+
sk_sp<SkTextBlob> CreateTextBlob(std::string& message);
231+
230232
struct DisplayListInvocation {
231233
// ----------------------------------
232234
// Required fields for initialization

0 commit comments

Comments
 (0)