From 4422323e7da7ca219483b1157ae8a8b71e67d112 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 9 May 2023 18:29:22 -0700 Subject: [PATCH] [Impeller] Increase minimum size of alpha glyph atlas. (flutter/engine#41880) Fixes https://github.com/flutter/flutter/issues/122839 Fixes https://github.com/flutter/flutter/issues/126103 Unlike Skia which starts with 2048x2048, I decreased the size of 1024x1024. Now that we'll never switch this to a color bitmap, the memory impact is dramatically lessened. --- .../backends/skia/text_render_context_skia.cc | 10 +++++++--- .../impeller/typographer/typographer_unittests.cc | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) 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 886674ea45..15334b4237 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 @@ -135,13 +135,17 @@ namespace { ISize OptimumAtlasSizeForFontGlyphPairs( const FontGlyphPair::Set& pairs, std::vector& glyph_positions, - const std::shared_ptr& atlas_context) { + const std::shared_ptr& atlas_context, + GlyphAtlas::Type type) { static constexpr auto kMinAtlasSize = 8u; + static constexpr auto kMinAlphaBitmapSize = 1024u; static constexpr auto kMaxAtlasSize = 4096u; TRACE_EVENT0("impeller", __FUNCTION__); - ISize current_size(kMinAtlasSize, kMinAtlasSize); + ISize current_size = type == GlyphAtlas::Type::kAlphaBitmap + ? ISize(kMinAlphaBitmapSize, kMinAlphaBitmapSize) + : ISize(kMinAtlasSize, kMinAtlasSize); size_t total_pairs = pairs.size() + 1; do { auto rect_packer = std::shared_ptr( @@ -403,7 +407,7 @@ std::shared_ptr TextRenderContextSkia::CreateGlyphAtlas( // --------------------------------------------------------------------------- auto glyph_atlas = std::make_shared(type); auto atlas_size = OptimumAtlasSizeForFontGlyphPairs( - font_glyph_pairs, glyph_positions, atlas_context); + font_glyph_pairs, glyph_positions, atlas_context, type); atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size); if (atlas_size.IsEmpty()) { diff --git a/engine/src/flutter/impeller/typographer/typographer_unittests.cc b/engine/src/flutter/impeller/typographer/typographer_unittests.cc index 31c649fab0..a425612ea8 100644 --- a/engine/src/flutter/impeller/typographer/typographer_unittests.cc +++ b/engine/src/flutter/impeller/typographer/typographer_unittests.cc @@ -189,9 +189,7 @@ TEST_P(TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize) { atlas->GetTexture()->GetSize().height); } -// TODO(jonahwilliams): Re-enable -// https://github.com/flutter/flutter/issues/122839 -TEST_P(TypographerTest, DISABLED_GlyphAtlasTextureIsRecycledIfUnchanged) { +TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) { auto context = TextRenderContext::Create(GetContext()); auto atlas_context = std::make_shared(); ASSERT_TRUE(context && context->IsValid());