404 {
407 return nullptr;
408 }
410 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
411
412 if (font_glyph_map.empty()) {
413 return last_atlas;
414 }
415
416 std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
417 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
418
420 context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
421 });
422
423
424
425
426
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);
438 }
439 }
440 } else {
441 for (const SubpixelGlyph& glyph : font_value.second) {
442 new_glyphs.emplace_back(scaled_font, glyph);
444 }
445 }
446 }
447 if (last_atlas->GetType() ==
type && new_glyphs.size() == 0) {
448 return last_atlas;
449 }
450
451
452
453
454
455
456 std::vector<Rect> glyph_positions;
457 if (last_atlas->GetType() ==
type &&
459 atlas_context->GetAtlasSize(),
460 atlas_context->GetRectPacker())) {
461
462
463
464
465
466
467
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]);
471 }
472
473
474
475
476
477 auto bitmap = atlas_context_stb.GetBitmap();
479 return nullptr;
480 }
481
482
483
484
486 blit_pass, last_atlas->GetTexture())) {
487 return nullptr;
488 }
489 return last_atlas;
490 }
491
492
493
494
495
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});
504 }
505 }
506 auto glyph_atlas = std::make_shared<GlyphAtlas>(
type);
508 font_glyph_pairs,
509 glyph_positions,
510 atlas_context,
512 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
513 );
514
515 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size, 0);
516 if (atlas_size.IsEmpty()) {
517 return nullptr;
518 }
519
520
521
522
523
524
525
526 if (glyph_positions.size() != font_glyph_pairs.size()) {
527 return nullptr;
528 }
529
530
531
532
533 {
535 for (auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
537 glyph_atlas->AddTypefaceGlyphPositionAndBounds(*it, glyph_positions[
i],
539 }
540 }
541
542
543
544
547 return nullptr;
548 }
549 atlas_context_stb.UpdateBitmap(
bitmap);
550
551
552
553
557 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
558 break;
561 ? context.GetCapabilities()->GetDefaultGlyphAtlasFormat()
563 break;
564 }
568 return nullptr;
569 }
570
571
572
573
574 glyph_atlas->SetTexture(std::move(
texture));
575
576 return glyph_atlas;
577}
Wraps a closure that is invoked in the destructor unless released by the caller.
static GlyphAtlasContextSTB & Cast(GlyphAtlasContext &base)
virtual bool IsValid() const
uint32_t uint32_t * format
std::function< void()> closure
static Rect ComputeGlyphSize(const SkFont &font, const SubpixelGlyph &glyph, Scalar scale)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
static std::shared_ptr< BitmapSTB > CreateAtlasBitmap(const GlyphAtlas &atlas, const ISize &atlas_size)
static ISize OptimumAtlasSizeForFontGlyphPairs(const std::vector< FontGlyphPair > &pairs, std::vector< Rect > &glyph_positions, const std::shared_ptr< GlyphAtlasContext > &atlas_context, GlyphAtlas::Type type, const ISize &max_texture_size)
static bool UpdateGlyphTextureAtlas(std::shared_ptr< BitmapSTB > &bitmap, const std::shared_ptr< Allocator > &allocator, std::shared_ptr< BlitPass > &blit_pass, const std::shared_ptr< Texture > &texture)
static std::shared_ptr< Texture > UploadGlyphTextureAtlas(const std::shared_ptr< Allocator > &allocator, std::shared_ptr< BlitPass > &blit_pass, std::shared_ptr< BitmapSTB > &bitmap, const ISize &atlas_size, PixelFormat format)
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)
static bool CanAppendToExistingAtlas(const std::shared_ptr< GlyphAtlas > &atlas, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, ISize atlas_size, const std::shared_ptr< RectanglePacker > &rect_packer)
#define TRACE_EVENT0(category_group, name)
#define DISABLE_COLOR_FONT_SUPPORT