diff --git a/engine/src/flutter/impeller/typographer/backends/skia/text_render_context_skia.cc b/engine/src/flutter/impeller/typographer/backends/skia/text_render_context_skia.cc index cb301e97d0b..1338c0c13c5 100644 --- a/engine/src/flutter/impeller/typographer/backends/skia/text_render_context_skia.cc +++ b/engine/src/flutter/impeller/typographer/backends/skia/text_render_context_skia.cc @@ -473,10 +473,12 @@ std::shared_ptr TextRenderContextSkia::CreateGlyphAtlas( // --------------------------------------------------------------------------- // Step 3: Determine if the additional missing glyphs can be appended to the - // existing bitmap without recreating the atlas. + // existing bitmap without recreating the atlas. This requires that + // the type is identical. // --------------------------------------------------------------------------- std::vector glyph_positions; - if (CanAppendToExistingAtlas(last_atlas, new_glyphs, glyph_positions, + if (last_atlas->GetType() == type && + CanAppendToExistingAtlas(last_atlas, new_glyphs, glyph_positions, atlas_context->GetAtlasSize(), atlas_context->GetRectPacker())) { // The old bitmap will be reused and only the additional glyphs will be diff --git a/engine/src/flutter/impeller/typographer/typographer_unittests.cc b/engine/src/flutter/impeller/typographer/typographer_unittests.cc index a4d174100a7..70718e2be20 100644 --- a/engine/src/flutter/impeller/typographer/typographer_unittests.cc +++ b/engine/src/flutter/impeller/typographer/typographer_unittests.cc @@ -201,6 +201,40 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) { ASSERT_EQ(old_packer, new_packer); } +TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) { + auto context = TextRenderContext::Create(GetContext()); + auto atlas_context = std::make_shared(); + ASSERT_TRUE(context && context->IsValid()); + SkFont sk_font; + auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font); + ASSERT_TRUE(blob); + auto atlas = + context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, atlas_context, + TextFrameFromTextBlob(blob)); + auto old_packer = atlas_context->GetRectPacker(); + + ASSERT_NE(atlas, nullptr); + ASSERT_NE(atlas->GetTexture(), nullptr); + ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas()); + + auto* first_texture = atlas->GetTexture().get(); + + // now create a new glyph atlas with an identical blob, + // but change the type. + + auto blob2 = SkTextBlob::MakeFromString("spooky 1", sk_font); + auto next_atlas = + context->CreateGlyphAtlas(GlyphAtlas::Type::kColorBitmap, atlas_context, + TextFrameFromTextBlob(blob2)); + ASSERT_NE(atlas, next_atlas); + auto* second_texture = next_atlas->GetTexture().get(); + + auto new_packer = atlas_context->GetRectPacker(); + + ASSERT_NE(second_texture, first_texture); + ASSERT_NE(old_packer, new_packer); +} + TEST_P(TypographerTest, FontGlyphPairTypeChangesHashAndEquals) { Font font = Font(nullptr, {}); FontGlyphPair pair_1 = {