Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
lazy_glyph_atlas.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "fml/logging.h"
11
12#include <memory>
13#include <utility>
14
15namespace impeller {
16
17static const std::shared_ptr<GlyphAtlas> kNullGlyphAtlas = nullptr;
18
20 std::shared_ptr<TypographerContext> typographer_context)
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) {}
28
30
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}
39
41 alpha_glyph_map_.clear();
42 color_glyph_map_.clear();
43 alpha_atlas_.reset();
44 color_atlas_.reset();
45}
46
47const std::shared_ptr<GlyphAtlas>& LazyGlyphAtlas::CreateOrGetGlyphAtlas(
48 Context& context,
49 GlyphAtlas::Type type) const {
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 }
81 alpha_atlas_ = std::move(atlas);
82 return alpha_atlas_;
83 }
85 color_atlas_ = std::move(atlas);
86 return color_atlas_;
87 }
89}
90
91} // namespace impeller
To do anything rendering related with Impeller, you need a context.
Definition context.h:46
Type
Describes how the glyphs are represented in the texture.
Definition glyph_atlas.h:32
LazyGlyphAtlas(std::shared_ptr< TypographerContext > typographer_context)
void AddTextFrame(const TextFrame &frame, Scalar scale)
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas(Context &context, GlyphAtlas::Type type) const
Represents a collection of shaped text runs.
Definition text_frame.h:20
double frame
Definition examples.cpp:31
#define FML_UNREACHABLE()
Definition logging.h:109
#define FML_DCHECK(condition)
Definition logging.h:103
static const std::shared_ptr< GlyphAtlas > kNullGlyphAtlas
float Scalar
Definition scalar.h:18
Definition ref_ptr.h:256
const Scalar scale
#define VALIDATION_LOG
Definition validation.h:73