| Flutter Impeller |

text_contents.h
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
5 #pragma once
6
7 #include <functional>
8 #include <memory>
9 #include <variant>
10 #include <vector>
11
12 #include "flutter/fml/macros.h"
13 #include "impeller/entity/contents/contents.h"
14 #include "impeller/geometry/color.h"
15 #include "impeller/typographer/glyph_atlas.h"
16 #include "impeller/typographer/text_frame.h"
17
18 namespace impeller {
19
20 class LazyGlyphAtlas;
21 class Context;
22
23 class TextContents final : public Contents {
24 public:
25 TextContents();
26
27 ~TextContents();
28
29 void SetTextFrame(const std::shared_ptr<TextFrame>& frame);
30
31 void SetColor(Color color);
32
33 Color GetColor() const;
34
35 // |Contents|
36 bool CanInheritOpacity(const Entity& entity) const override;
37
38 // |Contents|
39 void SetInheritedOpacity(Scalar opacity) override;
40
41 void SetOffset(Vector2 offset);
42
43 std::optional<Rect> GetTextFrameBounds() const;
44
45 // |Contents|
46 std::optional<Rect> GetCoverage(const Entity& entity) const override;
47
48 // |Contents|
49 void PopulateGlyphAtlas(
50 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
51 Scalar scale) override;
52
53 // |Contents|
54 bool Render(const ContentContext& renderer,
55 const Entity& entity,
56 RenderPass& pass) const override;
57
58 private:
59 std::shared_ptr<TextFrame> frame_;
60 Scalar scale_ = 1.0;
61 Color color_;
62 Scalar inherited_opacity_ = 1.0;
63 Vector2 offset_;
64
65 std::shared_ptr<GlyphAtlas> ResolveAtlas(
66 Context& context,
67 GlyphAtlas::Type type,
68 const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas) const;
69
70 FML_DISALLOW_COPY_AND_ASSIGN(TextContents);
71 };
72
73 } // namespace impeller
impeller::TextContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: text_contents.cc:51
contents.h
impeller::TextContents
Definition: text_contents.h:23
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::TextContents::GetTextFrameBounds
std::optional< Rect > GetTextFrameBounds() const
impeller::Color
Definition: color.h:122
impeller::TextContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
Definition: text_contents.cc:63
impeller::TextContents::SetColor
void SetColor(Color color)
Definition: text_contents.cc:43
impeller::Entity
Definition: entity.h:21
impeller::TextContents::PopulateGlyphAtlas
void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale) override
Add any text data to the specified lazy atlas. The scale parameter must be used again later when draw...
Definition: text_contents.cc:67
impeller::GlyphAtlas::Type
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:32
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
Definition: text_contents.cc:59
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::TextContents::TextContents
TextContents()
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::TextContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: text_contents.cc:55
impeller::TPoint< Scalar >
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:74
impeller::TextContents::GetColor
Color GetColor() const
Definition: text_contents.cc:47
color.h
impeller::TextContents::SetTextFrame
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
Definition: text_contents.cc:27
glyph_atlas.h
text_frame.h
impeller::Contents
Definition: contents.h:33
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:344