mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] dont append to existing atlas if type changed (flutter/engine#39913)
[Impeller] dont append to existing atlas if type changed
This commit is contained in:
parent
ad789d08f8
commit
dc786470e6
@ -473,10 +473,12 @@ std::shared_ptr<GlyphAtlas> 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<Rect> 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
|
||||
|
||||
@ -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<GlyphAtlasContext>();
|
||||
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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user