Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ if (enable_unittests) {
":display_list",
":display_list_fixtures",
"//flutter/display_list/testing:display_list_testing",
"//flutter/impeller/typographer/backends/skia:typographer_skia_backend",
"//flutter/testing",
"//flutter/testing:skia",
]
Expand Down
26 changes: 26 additions & 0 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "flutter/testing/display_list_testing.h"
#include "flutter/testing/testing.h"

#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "third_party/skia/include/core/SkBBHFactory.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
Expand Down Expand Up @@ -4331,5 +4332,30 @@ TEST_F(DisplayListTest, DrawDisplayListForwardsBackdropFlag) {
EXPECT_TRUE(parent_dl->root_has_backdrop_filter());
}

TEST_F(DisplayListTest, TextFrameOpacityPeephole) {
// Single character can have opacity peephole applied.
{
std::string message = "A";
sk_sp<SkTextBlob> blob = CreateTextBlob(message);
auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob);
DisplayListBuilder builder;
builder.DrawTextFrame(frame, 0, 0, {});
auto dl = builder.Build();
EXPECT_TRUE(dl->can_apply_group_opacity());
}

// Multiple characters cannot have opacity peephole applied.
{
std::string message = "ABC";
sk_sp<SkTextBlob> blob = CreateTextBlob(message);

auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob);
DisplayListBuilder builder;
builder.DrawTextFrame(frame, 0, 0, {});
auto dl = builder.Build();
EXPECT_FALSE(dl->can_apply_group_opacity());
}
}

} // namespace testing
} // namespace flutter
6 changes: 5 additions & 1 deletion display_list/dl_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,11 @@ void DisplayListBuilder::drawTextFrame(
// they will protect overlapping glyphs from the effects of overdraw
// so we must make the conservative assessment that this DL layer is
// not compatible with group opacity inheritance.
UpdateLayerOpacityCompatibility(false);
// A single glyph can still have the opacity peephole applied (this is
// likely a glyph used as an Icon)
const bool is_single_glyph = text_frame->GetRunCount() == 1u &&
text_frame->GetRuns()[0].GetGlyphCount() == 1u;
UpdateLayerOpacityCompatibility(is_single_glyph);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me that this code is mixing and matching attribute incompatibility with overlap incompatibility. Technically this is an overlap condition which is typically reported through the accumulator. But since this mistake is replicated in a few places I think that should be solved as a separate issue...

I filed this as flutter/flutter#149622

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, of note, this doesn't cause a bug, it's just a systemic logic confusion that ends up doing the right thing anyway.

UpdateLayerResult(result);
}
}
Expand Down
7 changes: 7 additions & 0 deletions display_list/testing/dl_test_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,5 +980,12 @@ sk_sp<SkTextBlob> GetTestTextBlob(int index) {
return blob;
}

sk_sp<SkTextBlob> CreateTextBlob(std::string& message) {
sk_sp<SkTextBlob> blob =
SkTextBlob::MakeFromText(message.c_str(), message.size(),
CreateTestFontOfSize(20), SkTextEncoding::kUTF8);
return blob;
}

} // namespace testing
} // namespace flutter
2 changes: 2 additions & 0 deletions display_list/testing/dl_test_snippets.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ SkFont CreateTestFontOfSize(SkScalar scalar);

sk_sp<SkTextBlob> GetTestTextBlob(int index);

sk_sp<SkTextBlob> CreateTextBlob(std::string& message);

struct DisplayListInvocation {
// ----------------------------------
// Required fields for initialization
Expand Down