[impeller] ensure full glyphs respect alpha (flutter/engine#39377)

This commit is contained in:
Jonah Williams
2023-02-07 11:46:51 -08:00
committed by GitHub
parent 93dd24de00
commit a479b5c310
2 changed files with 17 additions and 3 deletions

View File

@@ -1120,7 +1120,8 @@ bool RenderTextInCanvas(const std::shared_ptr<Context>& context,
Canvas& canvas,
const std::string& text,
const std::string& font_fixture,
Scalar font_size = 50.0) {
Scalar font_size = 50.0,
Scalar alpha = 1.0) {
Scalar baseline = 200.0;
Point text_position = {100, baseline};
@@ -1147,7 +1148,7 @@ bool RenderTextInCanvas(const std::shared_ptr<Context>& context,
auto frame = TextFrameFromTextBlob(blob);
Paint text_paint;
text_paint.color = Color::Yellow();
text_paint.color = Color::Yellow().WithAlpha(alpha);
canvas.DrawTextFrame(frame, text_position, text_paint);
return true;
}
@@ -1180,6 +1181,18 @@ TEST_P(AiksTest, CanRenderEmojiTextFrame) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, CanRenderEmojiTextFrameWithAlpha) {
Canvas canvas;
ASSERT_TRUE(RenderTextInCanvas(GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
#if FML_OS_MACOSX
"Apple Color Emoji.ttc", 50, 0.5));
#else
"NotoColorEmoji.ttf", 50, 0.5));
#endif
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, CanRenderTextInSaveLayer) {
Canvas canvas;
canvas.DrawPaint({.color = Color::White()});

View File

@@ -24,7 +24,8 @@ void main() {
vec2 uv_position = v_source_position / frag_info.atlas_size;
if (v_has_color == 1.0) {
frag_color =
texture(glyph_atlas_sampler, v_unit_position * uv_size + uv_position);
texture(glyph_atlas_sampler, v_unit_position * uv_size + uv_position) *
frag_info.text_color.a;
} else {
frag_color =
texture(glyph_atlas_sampler, v_unit_position * uv_size + uv_position)