452 TRACE_EVENT0(
"impeller", __FUNCTION__);
456 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
457 FML_DCHECK(last_atlas->GetType() ==
type);
459 if (font_glyph_map.empty()) {
468 std::vector<FontGlyphPair> new_glyphs;
469 std::vector<Rect> glyph_sizes;
471 if (new_glyphs.size() == 0) {
479 std::vector<Rect> glyph_positions;
480 glyph_positions.reserve(new_glyphs.size());
481 size_t first_missing_index = 0;
483 if (last_atlas->GetTexture()) {
486 last_atlas, new_glyphs, glyph_positions, glyph_sizes,
487 atlas_context->GetAtlasSize(), atlas_context->GetHeightAdjustment(),
488 atlas_context->GetRectPacker());
494 for (
size_t i = 0; i < first_missing_index; i++) {
495 last_atlas->AddTypefaceGlyphPositionAndBounds(
496 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
499 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
500 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
502 fml::ScopedCleanupClosure closure([&]() {
503 blit_pass->EncodeCommands(context.GetResourceAllocator());
504 context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
512 last_atlas->GetTexture(), new_glyphs, 0,
513 first_missing_index)) {
518 if (first_missing_index == new_glyphs.size()) {
523 int64_t height_adjustment = atlas_context->GetAtlasSize().height;
524 const int64_t max_texture_height =
525 context.GetResourceAllocator()->GetMaxTextureSizeSupported().height;
532 bool blit_old_atlas =
true;
533 std::shared_ptr<GlyphAtlas> new_atlas = last_atlas;
534 if (atlas_context->GetAtlasSize().height >= max_texture_height ||
536 blit_old_atlas =
false;
537 new_atlas = std::make_shared<GlyphAtlas>(
type);
542 glyph_positions.clear();
543 glyph_positions.reserve(new_glyphs.size());
544 first_missing_index = 0;
546 height_adjustment = 0;
547 atlas_context->UpdateRectPacker(
nullptr);
548 atlas_context->UpdateGlyphAtlas(new_atlas, {0, 0}, 0);
560 atlas_context->UpdateGlyphAtlas(new_atlas, atlas_size, height_adjustment);
561 if (atlas_size.IsEmpty()) {
564 FML_DCHECK(new_glyphs.size() == glyph_positions.size());
566 TextureDescriptor descriptor;
570 context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
576 descriptor.size = atlas_size;
579 std::shared_ptr<Texture> new_texture =
580 context.GetResourceAllocator()->CreateTexture(descriptor);
585 new_texture->SetLabel(
"GlyphAtlas");
587 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
588 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
590 fml::ScopedCleanupClosure closure([&]() {
591 blit_pass->EncodeCommands(context.GetResourceAllocator());
592 context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
596 auto old_texture = new_atlas->GetTexture();
597 new_atlas->SetTexture(std::move(new_texture));
603 for (
size_t i = first_missing_index; i < glyph_positions.size(); i++) {
604 new_atlas->AddTypefaceGlyphPositionAndBounds(
605 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
613 new_atlas->GetTexture(), new_glyphs,
614 first_missing_index, new_glyphs.size())) {
619 if (blit_old_atlas && old_texture) {
620 blit_pass->AddCopy(old_texture, new_atlas->GetTexture(),