[Impeller] Fix STB backend to account for max texture sizes. (flutter/engine#46010)

Gets rid of the hardcoded 2048 px size.

Followup from review comment left unaddressed in https://github.com/flutter/engine/pull/45992.

Missing this will be less easy after https://github.com/flutter/flutter/issues/133029.
This commit is contained in:
Chinmay Garde 2023-09-18 20:26:36 -07:00 committed by GitHub
parent 2b4d2616aa
commit 88f8bb7e25

View File

@ -160,10 +160,10 @@ static ISize OptimumAtlasSizeForFontGlyphPairs(
const std::vector<FontGlyphPair>& pairs,
std::vector<Rect>& glyph_positions,
const std::shared_ptr<GlyphAtlasContext>& atlas_context,
GlyphAtlas::Type type) {
GlyphAtlas::Type type,
const ISize& max_texture_size) {
static constexpr auto kMinAtlasSize = 8u;
static constexpr auto kMinAlphaBitmapSize = 1024u;
static constexpr auto kMaxAtlasSize = 2048u; // QNX required 2048 or less.
TRACE_EVENT0("impeller", __FUNCTION__);
@ -190,8 +190,8 @@ static ISize OptimumAtlasSizeForFontGlyphPairs(
Allocation::NextPowerOfTwoSize(current_size.width + 1),
Allocation::NextPowerOfTwoSize(current_size.height + 1));
}
} while (current_size.width <= kMaxAtlasSize &&
current_size.height <= kMaxAtlasSize);
} while (current_size.width <= max_texture_size.width &&
current_size.height <= max_texture_size.height);
return ISize{0, 0};
}
@ -469,7 +469,12 @@ std::shared_ptr<GlyphAtlas> TypographerContextSTB::CreateGlyphAtlas(
}
auto glyph_atlas = std::make_shared<GlyphAtlas>(type);
auto atlas_size = OptimumAtlasSizeForFontGlyphPairs(
font_glyph_pairs, glyph_positions, atlas_context, type);
font_glyph_pairs, //
glyph_positions, //
atlas_context, //
type, //
context.GetResourceAllocator()->GetMaxTextureSizeSupported() //
);
atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size);
if (atlas_size.IsEmpty()) {