508 TRACE_EVENT0(
"impeller", __FUNCTION__);
512 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
513 FML_DCHECK(last_atlas->GetType() ==
type);
515 if (text_frames.empty()) {
524 auto [new_glyphs, glyph_sizes] = CollectNewGlyphs(last_atlas, text_frames);
525 if (new_glyphs.size() == 0) {
533 std::vector<Rect> glyph_positions;
534 glyph_positions.reserve(new_glyphs.size());
535 size_t first_missing_index = 0;
537 if (last_atlas->GetTexture()) {
540 last_atlas, new_glyphs, glyph_positions, glyph_sizes,
541 atlas_context->GetAtlasSize(), atlas_context->GetHeightAdjustment(),
542 atlas_context->GetRectPacker());
548 for (
size_t i = 0; i < first_missing_index; i++) {
549 last_atlas->AddTypefaceGlyphPositionAndBounds(
550 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
553 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
554 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
556 fml::ScopedCleanupClosure closure([&]() {
557 blit_pass->EncodeCommands();
558 if (!context.EnqueueCommandBuffer(std::move(cmd_buffer))) {
559 VALIDATION_LOG <<
"Failed to submit glyph atlas command buffer";
568 last_atlas->GetTexture(), new_glyphs, 0,
569 first_missing_index)) {
574 if (first_missing_index == new_glyphs.size()) {
579 int64_t height_adjustment = atlas_context->GetAtlasSize().height;
580 const int64_t max_texture_height =
581 context.GetResourceAllocator()->GetMaxTextureSizeSupported().height;
588 bool blit_old_atlas =
true;
589 std::shared_ptr<GlyphAtlas> new_atlas = last_atlas;
590 if (atlas_context->GetAtlasSize().height >= max_texture_height ||
592 blit_old_atlas =
false;
593 new_atlas = std::make_shared<GlyphAtlas>(
594 type, last_atlas->GetAtlasGeneration() + 1);
596 auto [update_glyphs, update_sizes] =
597 CollectNewGlyphs(new_atlas, text_frames);
598 new_glyphs = std::move(update_glyphs);
599 glyph_sizes = std::move(update_sizes);
601 glyph_positions.clear();
602 glyph_positions.reserve(new_glyphs.size());
603 first_missing_index = 0;
605 height_adjustment = 0;
606 atlas_context->UpdateRectPacker(
nullptr);
607 atlas_context->UpdateGlyphAtlas(new_atlas, {0, 0}, 0);
619 atlas_context->UpdateGlyphAtlas(new_atlas, atlas_size, height_adjustment);
620 if (atlas_size.IsEmpty()) {
623 FML_DCHECK(new_glyphs.size() == glyph_positions.size());
625 TextureDescriptor descriptor;
629 context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
635 descriptor.size = atlas_size;
638 std::shared_ptr<Texture> new_texture =
639 context.GetResourceAllocator()->CreateTexture(descriptor);
644 new_texture->SetLabel(
"GlyphAtlas");
646 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
647 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
649 fml::ScopedCleanupClosure closure([&]() {
650 blit_pass->EncodeCommands();
651 if (!context.EnqueueCommandBuffer(std::move(cmd_buffer))) {
652 VALIDATION_LOG <<
"Failed to submit glyph atlas command buffer";
657 auto old_texture = new_atlas->GetTexture();
658 new_atlas->SetTexture(std::move(new_texture));
664 for (
size_t i = first_missing_index; i < glyph_positions.size(); i++) {
665 new_atlas->AddTypefaceGlyphPositionAndBounds(
666 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
674 new_atlas->GetTexture(), new_glyphs,
675 first_missing_index, new_glyphs.size())) {
680 if (blit_old_atlas && old_texture) {
681 blit_pass->AddCopy(old_texture, new_atlas->GetTexture(),
virtual bool IsValid() const
static bool BulkUpdateAtlasBitmap(const GlyphAtlas &atlas, std::shared_ptr< BlitPass > &blit_pass, HostBuffer &host_buffer, const std::shared_ptr< Texture > &texture, const std::vector< FontGlyphPair > &new_pairs, size_t start_index, size_t end_index)
Batch render to a single surface.
static size_t AppendToExistingAtlas(const std::shared_ptr< GlyphAtlas > &atlas, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, const std::vector< Rect > &glyph_sizes, ISize atlas_size, int64_t height_adjustment, const std::shared_ptr< RectanglePacker > &rect_packer)
static ISize ComputeNextAtlasSize(const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, const std::vector< Rect > &glyph_sizes, size_t glyph_index_start, int64_t max_texture_height)
static bool UpdateAtlasBitmap(const GlyphAtlas &atlas, std::shared_ptr< BlitPass > &blit_pass, HostBuffer &host_buffer, const std::shared_ptr< Texture > &texture, const std::vector< FontGlyphPair > &new_pairs, size_t start_index, size_t end_index)
constexpr static TRect MakeSize(const TSize< U > &size)