Flutter Impeller
impeller::LazyGlyphAtlas Class Reference

#include <lazy_glyph_atlas.h>

Public Member Functions

 LazyGlyphAtlas (std::shared_ptr< TypographerContext > typographer_context)
 
 ~LazyGlyphAtlas ()
 
void AddTextFrame (const TextFrame &frame, Scalar scale)
 
void ResetTextFrames ()
 
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas (Context &context, GlyphAtlas::Type type) const
 

Detailed Description

Definition at line 18 of file lazy_glyph_atlas.h.

Constructor & Destructor Documentation

◆ LazyGlyphAtlas()

impeller::LazyGlyphAtlas::LazyGlyphAtlas ( std::shared_ptr< TypographerContext typographer_context)
explicit

Definition at line 19 of file lazy_glyph_atlas.cc.

21  : typographer_context_(std::move(typographer_context)),
22  alpha_context_(typographer_context_
23  ? typographer_context_->CreateGlyphAtlasContext()
24  : nullptr),
25  color_context_(typographer_context_
26  ? typographer_context_->CreateGlyphAtlasContext()
27  : nullptr) {}

◆ ~LazyGlyphAtlas()

impeller::LazyGlyphAtlas::~LazyGlyphAtlas ( )
default

Member Function Documentation

◆ AddTextFrame()

void impeller::LazyGlyphAtlas::AddTextFrame ( const TextFrame frame,
Scalar  scale 
)

Definition at line 31 of file lazy_glyph_atlas.cc.

31  {
32  FML_DCHECK(alpha_atlas_ == nullptr && color_atlas_ == nullptr);
33  if (frame.GetAtlasType() == GlyphAtlas::Type::kAlphaBitmap) {
34  frame.CollectUniqueFontGlyphPairs(alpha_glyph_map_, scale);
35  } else {
36  frame.CollectUniqueFontGlyphPairs(color_glyph_map_, scale);
37  }
38 }

References impeller::TextFrame::CollectUniqueFontGlyphPairs(), impeller::TextFrame::GetAtlasType(), impeller::GlyphAtlas::kAlphaBitmap, and scale.

Referenced by impeller::testing::TEST_P().

◆ CreateOrGetGlyphAtlas()

const std::shared_ptr< GlyphAtlas > & impeller::LazyGlyphAtlas::CreateOrGetGlyphAtlas ( Context context,
GlyphAtlas::Type  type 
) const

Definition at line 47 of file lazy_glyph_atlas.cc.

49  {
50  {
51  if (type == GlyphAtlas::Type::kAlphaBitmap && alpha_atlas_) {
52  return alpha_atlas_;
53  }
54  if (type == GlyphAtlas::Type::kColorBitmap && color_atlas_) {
55  return color_atlas_;
56  }
57  }
58 
59  if (!typographer_context_) {
60  VALIDATION_LOG << "Unable to render text because a TypographerContext has "
61  "not been set.";
62  return kNullGlyphAtlas;
63  }
64  if (!typographer_context_->IsValid()) {
66  << "Unable to render text because the TypographerContext is invalid.";
67  return kNullGlyphAtlas;
68  }
69 
70  auto& glyph_map = type == GlyphAtlas::Type::kAlphaBitmap ? alpha_glyph_map_
71  : color_glyph_map_;
72  const std::shared_ptr<GlyphAtlasContext>& atlas_context =
73  type == GlyphAtlas::Type::kAlphaBitmap ? alpha_context_ : color_context_;
74  std::shared_ptr<GlyphAtlas> atlas = typographer_context_->CreateGlyphAtlas(
75  context, type, atlas_context, glyph_map);
76  if (!atlas || !atlas->IsValid()) {
77  VALIDATION_LOG << "Could not create valid atlas.";
78  return kNullGlyphAtlas;
79  }
80  if (type == GlyphAtlas::Type::kAlphaBitmap) {
81  alpha_atlas_ = std::move(atlas);
82  return alpha_atlas_;
83  }
84  if (type == GlyphAtlas::Type::kColorBitmap) {
85  color_atlas_ = std::move(atlas);
86  return color_atlas_;
87  }
88  FML_UNREACHABLE();
89 }

References impeller::GlyphAtlas::kAlphaBitmap, impeller::GlyphAtlas::kColorBitmap, impeller::kNullGlyphAtlas, and VALIDATION_LOG.

Referenced by impeller::testing::TEST_P().

◆ ResetTextFrames()

void impeller::LazyGlyphAtlas::ResetTextFrames ( )

Definition at line 40 of file lazy_glyph_atlas.cc.

40  {
41  alpha_glyph_map_.clear();
42  color_glyph_map_.clear();
43  alpha_atlas_.reset();
44  color_atlas_.reset();
45 }

The documentation for this class was generated from the following files:
impeller::GlyphAtlas::Type::kColorBitmap
@ kColorBitmap
impeller::GlyphAtlas::Type::kAlphaBitmap
@ kAlphaBitmap
impeller::kNullGlyphAtlas
static const std::shared_ptr< GlyphAtlas > kNullGlyphAtlas
Definition: lazy_glyph_atlas.cc:17
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
scale
const Scalar scale
Definition: stroke_path_geometry.cc:297