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

Commit c0744c3

Browse files
author
Jonah Williams
authored
[Impeller] dont append to existing atlas if type changed (#39913)
[Impeller] dont append to existing atlas if type changed
1 parent 44e00c3 commit c0744c3

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

impeller/typographer/backends/skia/text_render_context_skia.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,12 @@ std::shared_ptr<GlyphAtlas> TextRenderContextSkia::CreateGlyphAtlas(
473473

474474
// ---------------------------------------------------------------------------
475475
// Step 3: Determine if the additional missing glyphs can be appended to the
476-
// existing bitmap without recreating the atlas.
476+
// existing bitmap without recreating the atlas. This requires that
477+
// the type is identical.
477478
// ---------------------------------------------------------------------------
478479
std::vector<Rect> glyph_positions;
479-
if (CanAppendToExistingAtlas(last_atlas, new_glyphs, glyph_positions,
480+
if (last_atlas->GetType() == type &&
481+
CanAppendToExistingAtlas(last_atlas, new_glyphs, glyph_positions,
480482
atlas_context->GetAtlasSize(),
481483
atlas_context->GetRectPacker())) {
482484
// The old bitmap will be reused and only the additional glyphs will be

impeller/typographer/typographer_unittests.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,40 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) {
201201
ASSERT_EQ(old_packer, new_packer);
202202
}
203203

204+
TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) {
205+
auto context = TextRenderContext::Create(GetContext());
206+
auto atlas_context = std::make_shared<GlyphAtlasContext>();
207+
ASSERT_TRUE(context && context->IsValid());
208+
SkFont sk_font;
209+
auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font);
210+
ASSERT_TRUE(blob);
211+
auto atlas =
212+
context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, atlas_context,
213+
TextFrameFromTextBlob(blob));
214+
auto old_packer = atlas_context->GetRectPacker();
215+
216+
ASSERT_NE(atlas, nullptr);
217+
ASSERT_NE(atlas->GetTexture(), nullptr);
218+
ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
219+
220+
auto* first_texture = atlas->GetTexture().get();
221+
222+
// now create a new glyph atlas with an identical blob,
223+
// but change the type.
224+
225+
auto blob2 = SkTextBlob::MakeFromString("spooky 1", sk_font);
226+
auto next_atlas =
227+
context->CreateGlyphAtlas(GlyphAtlas::Type::kColorBitmap, atlas_context,
228+
TextFrameFromTextBlob(blob2));
229+
ASSERT_NE(atlas, next_atlas);
230+
auto* second_texture = next_atlas->GetTexture().get();
231+
232+
auto new_packer = atlas_context->GetRectPacker();
233+
234+
ASSERT_NE(second_texture, first_texture);
235+
ASSERT_NE(old_packer, new_packer);
236+
}
237+
204238
TEST_P(TypographerTest, FontGlyphPairTypeChangesHashAndEquals) {
205239
Font font = Font(nullptr, {});
206240
FontGlyphPair pair_1 = {

0 commit comments

Comments
 (0)