Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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"
12
13#include <memory>
14#include <utility>
15
16namespace impeller {
17
18static const std::shared_ptr<GlyphAtlas> kNullGlyphAtlas = nullptr;
19
21 std::shared_ptr<TypographerContext> typographer_context)
22 : typographer_context_(std::move(typographer_context)),
23 alpha_data_(typographer_context_
24 ? typographer_context_->CreateGlyphAtlasContext(
25 GlyphAtlas::Type::kAlphaBitmap)
26 : nullptr),
27 color_data_(typographer_context_
28 ? typographer_context_->CreateGlyphAtlasContext(
29 GlyphAtlas::Type::kColorBitmap)
30 : nullptr) {}
31
33
34void LazyGlyphAtlas::AddTextFrame(const std::shared_ptr<TextFrame>& frame,
35 Point position,
36 const Matrix& transform,
37 const GlyphProperties& properties) {
38 FML_DCHECK(alpha_data_.atlas == nullptr && color_data_.atlas == nullptr);
39 AtlasData& data = GetData(frame->GetAtlasType());
40 data.renderable_frames.emplace_back(
41 frame, transform * Matrix::MakeTranslation(position), properties);
42}
43
45 alpha_data_.reset();
46 color_data_.reset();
47}
48
49const std::shared_ptr<GlyphAtlas>& LazyGlyphAtlas::CreateOrGetGlyphAtlas(
50 Context& context,
51 HostBuffer& data_host_buffer,
53 AtlasData& data = GetData(type);
54 if (data.atlas) {
55 return data.atlas;
56 }
57
58 if (!typographer_context_) {
59 VALIDATION_LOG << "Unable to render text because a TypographerContext has "
60 "not been set.";
61 return kNullGlyphAtlas;
62 }
63 if (!typographer_context_->IsValid()) {
65 << "Unable to render text because the TypographerContext is invalid.";
66 return kNullGlyphAtlas;
67 }
68
69 data.atlas = typographer_context_->CreateGlyphAtlas(
70 context, type, data_host_buffer, data.context, data.renderable_frames);
71 if (!data.atlas || !data.atlas->IsValid()) {
72 VALIDATION_LOG << "Could not create valid atlas.";
73 return kNullGlyphAtlas;
74 }
75 return data.atlas;
76}
77
78LazyGlyphAtlas::AtlasData::AtlasData(std::shared_ptr<GlyphAtlasContext> context)
79 : context(std::move(context)) {}
80
81LazyGlyphAtlas::AtlasData::~AtlasData() = default;
82
83void LazyGlyphAtlas::AtlasData::reset() {
84 renderable_frames.clear();
85 atlas.reset();
86}
87
88LazyGlyphAtlas::AtlasData& LazyGlyphAtlas::GetData(GlyphAtlas::Type type) {
89 switch (type) {
91 return alpha_data_;
93 return color_data_;
94 }
96}
97
98} // namespace impeller
To do anything rendering related with Impeller, you need a context.
Definition context.h:69
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
Definition glyph_atlas.h:37
Type
Describes how the glyphs are represented in the texture.
Definition glyph_atlas.h:41
void AddTextFrame(const std::shared_ptr< TextFrame > &frame, Point position, const Matrix &transform, const GlyphProperties &properties)
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas(Context &context, HostBuffer &host_buffer, GlyphAtlas::Type type)
LazyGlyphAtlas(std::shared_ptr< TypographerContext > typographer_context)
#define FML_UNREACHABLE()
Definition logging.h:128
#define FML_DCHECK(condition)
Definition logging.h:122
static const std::shared_ptr< GlyphAtlas > kNullGlyphAtlas
Definition ref_ptr.h:261
impeller::ShaderType type
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
#define VALIDATION_LOG
Definition validation.h:91