405 TRACE_EVENT0(
"impeller", __FUNCTION__);
410 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
412 if (font_glyph_map.empty()) {
420 std::vector<FontGlyphPair> new_glyphs;
421 std::vector<Rect> new_sizes;
422 for (
const auto& font_value : font_glyph_map) {
423 const ScaledFont& scaled_font = font_value.first;
424 const FontGlyphAtlas* font_glyph_atlas =
425 last_atlas->GetFontGlyphAtlas(scaled_font.font, scaled_font.scale);
426 if (font_glyph_atlas) {
427 for (
const SubpixelGlyph& glyph : font_value.second) {
428 if (!font_glyph_atlas->FindGlyphBounds(glyph)) {
429 new_glyphs.emplace_back(scaled_font, glyph);
434 for (
const SubpixelGlyph& glyph : font_value.second) {
435 new_glyphs.emplace_back(scaled_font, glyph);
441 if (last_atlas->GetType() ==
type && new_glyphs.size() == 0) {
445 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
446 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
448 fml::ScopedCleanupClosure closure([&cmd_buffer, &context]() {
449 context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
457 std::vector<Rect> glyph_positions;
458 if (last_atlas->GetType() ==
type &&
460 atlas_context->GetAtlasSize(),
461 atlas_context->GetRectPacker())) {
469 for (
size_t i = 0, count = glyph_positions.size(); i < count; i++) {
470 last_atlas->AddTypefaceGlyphPositionAndBounds(
471 new_glyphs[i], glyph_positions[i], new_sizes[i]);
478 auto bitmap = atlas_context_stb.GetBitmap();
487 blit_pass, last_atlas->GetTexture())) {
497 std::vector<FontGlyphPair> font_glyph_pairs;
498 font_glyph_pairs.reserve(std::accumulate(
499 font_glyph_map.begin(), font_glyph_map.end(), 0,
500 [](
const int a,
const auto&
b) { return a + b.second.size(); }));
501 for (
const auto& font_value : font_glyph_map) {
502 const ScaledFont& scaled_font = font_value.first;
503 for (
const SubpixelGlyph& glyph : font_value.second) {
504 font_glyph_pairs.push_back({scaled_font, glyph});
507 auto glyph_atlas = std::make_shared<GlyphAtlas>(
type);
513 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
516 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size, 0);
517 if (atlas_size.IsEmpty()) {
527 if (glyph_positions.size() != font_glyph_pairs.size()) {
536 for (
auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
538 glyph_atlas->AddTypefaceGlyphPositionAndBounds(*it, glyph_positions[i],
550 atlas_context_stb.UpdateBitmap(bitmap);
558 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
562 ? context.GetCapabilities()->GetDefaultGlyphAtlasFormat()
567 blit_pass, bitmap, atlas_size, format);
575 glyph_atlas->SetTexture(std::move(texture));