494 TRACE_EVENT0(
"impeller", __FUNCTION__);
498 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
499 FML_DCHECK(last_atlas->GetType() ==
type);
501 if (text_frames.empty()) {
510 auto [new_glyphs, glyph_sizes] = CollectNewGlyphs(last_atlas, text_frames);
511 if (new_glyphs.size() == 0) {
519 std::vector<Rect> glyph_positions;
520 glyph_positions.reserve(new_glyphs.size());
521 size_t first_missing_index = 0;
523 if (last_atlas->GetTexture()) {
526 last_atlas, new_glyphs, glyph_positions, glyph_sizes,
527 atlas_context->GetAtlasSize(), atlas_context->GetHeightAdjustment(),
528 atlas_context->GetRectPacker());
534 for (
size_t i = 0; i < first_missing_index; i++) {
535 last_atlas->AddTypefaceGlyphPositionAndBounds(
536 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
539 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
540 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
542 fml::ScopedCleanupClosure closure([&]() {
543 blit_pass->EncodeCommands();
544 if (!context.EnqueueCommandBuffer(std::move(cmd_buffer))) {
545 VALIDATION_LOG <<
"Failed to submit glyph atlas command buffer";
554 last_atlas->GetTexture(), new_glyphs, 0,
555 first_missing_index)) {
560 if (first_missing_index == new_glyphs.size()) {
565 int64_t height_adjustment = atlas_context->GetAtlasSize().height;
566 const int64_t max_texture_height =
567 context.GetResourceAllocator()->GetMaxTextureSizeSupported().height;
574 bool blit_old_atlas =
true;
575 std::shared_ptr<GlyphAtlas> new_atlas = last_atlas;
576 if (atlas_context->GetAtlasSize().height >= max_texture_height ||
578 blit_old_atlas =
false;
579 new_atlas = std::make_shared<GlyphAtlas>(
580 type, last_atlas->GetAtlasGeneration() + 1);
582 auto [update_glyphs, update_sizes] =
583 CollectNewGlyphs(new_atlas, text_frames);
584 new_glyphs = std::move(update_glyphs);
585 glyph_sizes = std::move(update_sizes);
587 glyph_positions.clear();
588 glyph_positions.reserve(new_glyphs.size());
589 first_missing_index = 0;
591 height_adjustment = 0;
592 atlas_context->UpdateRectPacker(
nullptr);
593 atlas_context->UpdateGlyphAtlas(new_atlas, {0, 0}, 0);
605 atlas_context->UpdateGlyphAtlas(new_atlas, atlas_size, height_adjustment);
606 if (atlas_size.IsEmpty()) {
609 FML_DCHECK(new_glyphs.size() == glyph_positions.size());
611 TextureDescriptor descriptor;
615 context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
621 descriptor.size = atlas_size;
624 std::shared_ptr<Texture> new_texture =
625 context.GetResourceAllocator()->CreateTexture(descriptor);
630 new_texture->SetLabel(
"GlyphAtlas");
632 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
633 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
635 fml::ScopedCleanupClosure closure([&]() {
636 blit_pass->EncodeCommands();
637 if (!context.EnqueueCommandBuffer(std::move(cmd_buffer))) {
638 VALIDATION_LOG <<
"Failed to submit glyph atlas command buffer";
643 auto old_texture = new_atlas->GetTexture();
644 new_atlas->SetTexture(std::move(new_texture));
650 for (
size_t i = first_missing_index; i < glyph_positions.size(); i++) {
651 new_atlas->AddTypefaceGlyphPositionAndBounds(
652 new_glyphs[i], glyph_positions[i], glyph_sizes[i]);
660 new_atlas->GetTexture(), new_glyphs,
661 first_missing_index, new_glyphs.size())) {
666 if (blit_old_atlas && old_texture) {
667 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)