405 TRACE_EVENT0(
"impeller", __FUNCTION__);
410 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
412 if (font_glyph_map.empty()) {
416 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
417 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
419 fml::ScopedCleanupClosure closure([&cmd_buffer, &context]() {
420 context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
427 std::vector<FontGlyphPair> new_glyphs;
428 std::vector<Rect> new_sizes;
429 for (
const auto& font_value : font_glyph_map) {
430 const ScaledFont& scaled_font = font_value.first;
431 const FontGlyphAtlas* font_glyph_atlas =
432 last_atlas->GetFontGlyphAtlas(scaled_font.font, scaled_font.scale);
433 if (font_glyph_atlas) {
434 for (
const SubpixelGlyph& glyph : font_value.second) {
435 if (!font_glyph_atlas->FindGlyphBounds(glyph)) {
436 new_glyphs.emplace_back(scaled_font, glyph);
441 for (
const SubpixelGlyph& glyph : font_value.second) {
442 new_glyphs.emplace_back(scaled_font, glyph);
447 if (last_atlas->GetType() ==
type && new_glyphs.size() == 0) {
456 std::vector<Rect> glyph_positions;
457 if (last_atlas->GetType() ==
type &&
459 atlas_context->GetAtlasSize(),
460 atlas_context->GetRectPacker())) {
468 for (
size_t i = 0, count = glyph_positions.size(); i < count; i++) {
469 last_atlas->AddTypefaceGlyphPositionAndBounds(
470 new_glyphs[i], glyph_positions[i], new_sizes[i]);
477 auto bitmap = atlas_context_stb.GetBitmap();
486 blit_pass, last_atlas->GetTexture())) {
496 std::vector<FontGlyphPair> font_glyph_pairs;
497 font_glyph_pairs.reserve(std::accumulate(
498 font_glyph_map.begin(), font_glyph_map.end(), 0,
499 [](
const int a,
const auto&
b) { return a + b.second.size(); }));
500 for (
const auto& font_value : font_glyph_map) {
501 const ScaledFont& scaled_font = font_value.first;
502 for (
const SubpixelGlyph& glyph : font_value.second) {
503 font_glyph_pairs.push_back({scaled_font, glyph});
506 auto glyph_atlas = std::make_shared<GlyphAtlas>(
type);
512 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
515 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size, 0);
516 if (atlas_size.IsEmpty()) {
526 if (glyph_positions.size() != font_glyph_pairs.size()) {
535 for (
auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
537 glyph_atlas->AddTypefaceGlyphPositionAndBounds(*it, glyph_positions[i],
549 atlas_context_stb.UpdateBitmap(bitmap);
557 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
561 ? context.GetCapabilities()->GetDefaultGlyphAtlasFormat()
566 blit_pass, bitmap, atlas_size, format);
574 glyph_atlas->SetTexture(std::move(texture));