Flutter Engine
The Flutter Engine
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 GlyphAtlas::Type::kAlphaBitmap)
25 : nullptr),
26 color_context_(typographer_context_
27 ? typographer_context_->CreateGlyphAtlasContext(
28 GlyphAtlas::Type::kColorBitmap)
29 : nullptr) {}
30
32
36 const GlyphProperties& properties) {
37 FML_DCHECK(alpha_atlas_ == nullptr && color_atlas_ == nullptr);
38 if (frame.GetAtlasType() == GlyphAtlas::Type::kAlphaBitmap) {
39 frame.CollectUniqueFontGlyphPairs(alpha_glyph_map_, scale, offset,
40 properties);
41 } else {
42 frame.CollectUniqueFontGlyphPairs(color_glyph_map_, scale, offset,
43 properties);
44 }
45}
46
48 alpha_glyph_map_.clear();
49 color_glyph_map_.clear();
50 alpha_atlas_.reset();
51 color_atlas_.reset();
52}
53
54const std::shared_ptr<GlyphAtlas>& LazyGlyphAtlas::CreateOrGetGlyphAtlas(
55 Context& context,
56 HostBuffer& host_buffer,
57 GlyphAtlas::Type type) const {
58 {
59 if (type == GlyphAtlas::Type::kAlphaBitmap && alpha_atlas_) {
60 return alpha_atlas_;
61 }
62 if (type == GlyphAtlas::Type::kColorBitmap && color_atlas_) {
63 return color_atlas_;
64 }
65 }
66
67 if (!typographer_context_) {
68 VALIDATION_LOG << "Unable to render text because a TypographerContext has "
69 "not been set.";
70 return kNullGlyphAtlas;
71 }
72 if (!typographer_context_->IsValid()) {
74 << "Unable to render text because the TypographerContext is invalid.";
75 return kNullGlyphAtlas;
76 }
77
78 auto& glyph_map = type == GlyphAtlas::Type::kAlphaBitmap ? alpha_glyph_map_
79 : color_glyph_map_;
80 const std::shared_ptr<GlyphAtlasContext>& atlas_context =
81 type == GlyphAtlas::Type::kAlphaBitmap ? alpha_context_ : color_context_;
82 std::shared_ptr<GlyphAtlas> atlas = typographer_context_->CreateGlyphAtlas(
83 context, type, host_buffer, atlas_context, glyph_map);
84 if (!atlas || !atlas->IsValid()) {
85 VALIDATION_LOG << "Could not create valid atlas.";
86 return kNullGlyphAtlas;
87 }
89 alpha_atlas_ = std::move(atlas);
90 return alpha_atlas_;
91 }
93 color_atlas_ = std::move(atlas);
94 return color_atlas_;
95 }
97}
98
99} // namespace impeller
GLenum type
To do anything rendering related with Impeller, you need a context.
Definition: context.h:45
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
Definition: glyph_atlas.h:27
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:31
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas(Context &context, HostBuffer &host_buffer, GlyphAtlas::Type type) const
void AddTextFrame(const TextFrame &frame, Scalar scale, Point offset, const GlyphProperties &properties)
LazyGlyphAtlas(std::shared_ptr< TypographerContext > typographer_context)
Represents a collection of shaped text runs.
Definition: text_frame.h:19
double frame
Definition: examples.cpp:31
#define FML_UNREACHABLE()
Definition: logging.h:109
#define FML_DCHECK(condition)
Definition: logging.h:103
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
static const std::shared_ptr< GlyphAtlas > kNullGlyphAtlas
float Scalar
Definition: scalar.h:18
Definition: ref_ptr.h:256
const Scalar scale
SeparatedVector2 offset
#define VALIDATION_LOG
Definition: validation.h:73