| Flutter Impeller |

atlas_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 #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_ATLAS_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_ATLAS_CONTENTS_H_
7
8 #include <functional>
9 #include <memory>
10 #include <vector>
11
12 #include "flutter/fml/macros.h"
13 #include "impeller/core/sampler_descriptor.h"
14 #include "impeller/entity/contents/contents.h"
15 #include "impeller/entity/entity.h"
16
17 namespace impeller {
18
19 struct SubAtlasResult {
20 // Sub atlas values.
21 std::vector<Rect> sub_texture_coords;
22 std::vector<Color> sub_colors;
23 std::vector<Matrix> sub_transforms;
24
25 // Result atlas values.
26 std::vector<Rect> result_texture_coords;
27 std::vector<Matrix> result_transforms;
28
29 // Size of the sub-atlass.
30 ISize size;
31 };
32
33 class AtlasContents final : public Contents {
34 public:
35 explicit AtlasContents();
36
37 ~AtlasContents() override;
38
39 void SetTexture(std::shared_ptr<Texture> texture);
40
41 std::shared_ptr<Texture> GetTexture() const;
42
43 void SetTransforms(std::vector<Matrix> transforms);
44
45 void SetBlendMode(BlendMode blend_mode);
46
47 void SetTextureCoordinates(std::vector<Rect> texture_coords);
48
49 void SetColors(std::vector<Color> colors);
50
51 void SetCullRect(std::optional<Rect> cull_rect);
52
53 void SetSamplerDescriptor(SamplerDescriptor desc);
54
55 void SetAlpha(Scalar alpha);
56
57 const SamplerDescriptor& GetSamplerDescriptor() const;
58
59 const std::vector<Matrix>& GetTransforms() const;
60
61 const std::vector<Rect>& GetTextureCoordinates() const;
62
63 const std::vector<Color>& GetColors() const;
64
65 /// @brief Compress a drawAtlas call with blending into a smaller sized atlas.
66 /// This atlas has no overlapping to ensure
67 /// blending behaves as if it were done in the fragment shader.
68 std::shared_ptr<SubAtlasResult> GenerateSubAtlas() const;
69
70 // |Contents|
71 std::optional<Rect> GetCoverage(const Entity& entity) const override;
72
73 // |Contents|
74 bool Render(const ContentContext& renderer,
75 const Entity& entity,
76 RenderPass& pass) const override;
77
78 private:
79 Rect ComputeBoundingBox() const;
80
81 std::shared_ptr<Texture> texture_;
82 std::vector<Rect> texture_coords_;
83 std::vector<Color> colors_;
84 std::vector<Matrix> transforms_;
85 BlendMode blend_mode_;
86 std::optional<Rect> cull_rect_;
87 Scalar alpha_ = 1.0;
88 SamplerDescriptor sampler_descriptor_ = {};
89 mutable std::optional<Rect> bounding_box_cache_;
90
91 AtlasContents(const AtlasContents&) = delete;
92
93 AtlasContents& operator=(const AtlasContents&) = delete;
94 };
95
96 class AtlasTextureContents final : public Contents {
97 public:
98 explicit AtlasTextureContents(const AtlasContents& parent);
99
100 ~AtlasTextureContents() override;
101
102 // |Contents|
103 std::optional<Rect> GetCoverage(const Entity& entity) const override;
104
105 // |Contents|
106 bool Render(const ContentContext& renderer,
107 const Entity& entity,
108 RenderPass& pass) const override;
109
110 void SetAlpha(Scalar alpha);
111
112 void SetCoverage(Rect coverage);
113
114 void SetTexture(std::shared_ptr<Texture> texture);
115
116 void SetUseDestination(bool value);
117
118 void SetSubAtlas(const std::shared_ptr<SubAtlasResult>& subatlas);
119
120 private:
121 const AtlasContents& parent_;
122 Scalar alpha_ = 1.0;
123 Rect coverage_;
124 std::shared_ptr<Texture> texture_;
125 bool use_destination_ = false;
126 std::shared_ptr<SubAtlasResult> subatlas_;
127
128 AtlasTextureContents(const AtlasTextureContents&) = delete;
129
130 AtlasTextureContents& operator=(const AtlasTextureContents&) = delete;
131 };
132
133 class AtlasColorContents final : public Contents {
134 public:
135 explicit AtlasColorContents(const AtlasContents& parent);
136
137 ~AtlasColorContents() override;
138
139 // |Contents|
140 std::optional<Rect> GetCoverage(const Entity& entity) const override;
141
142 // |Contents|
143 bool Render(const ContentContext& renderer,
144 const Entity& entity,
145 RenderPass& pass) const override;
146
147 void SetAlpha(Scalar alpha);
148
149 void SetCoverage(Rect coverage);
150
151 void SetSubAtlas(const std::shared_ptr<SubAtlasResult>& subatlas);
152
153 private:
154 const AtlasContents& parent_;
155 Scalar alpha_ = 1.0;
156 Rect coverage_;
157 std::shared_ptr<SubAtlasResult> subatlas_;
158
159 AtlasColorContents(const AtlasColorContents&) = delete;
160
161 AtlasColorContents& operator=(const AtlasColorContents&) = delete;
162 };
163
164 } // namespace impeller
165
166 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_ATLAS_CONTENTS_H_
impeller::AtlasContents::SetTextureCoordinates
void SetTextureCoordinates(std::vector< Rect > texture_coords)
Definition: atlas_contents.cc:41
impeller::AtlasColorContents::SetAlpha
void SetAlpha(Scalar alpha)
Definition: atlas_contents.cc:435
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
entity.h
impeller::AtlasContents::SetSamplerDescriptor
void SetSamplerDescriptor(SamplerDescriptor desc)
Definition: atlas_contents.cc:165
impeller::AtlasColorContents
Definition: atlas_contents.h:133
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::SubAtlasResult::result_transforms
std::vector< Matrix > result_transforms
Definition: atlas_contents.h:27
impeller::AtlasTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: atlas_contents.cc:356
impeller::AtlasColorContents::AtlasColorContents
AtlasColorContents(const AtlasContents &parent)
Definition: atlas_contents.cc:425
impeller::AtlasColorContents::SetCoverage
void SetCoverage(Rect coverage)
Definition: atlas_contents.cc:439
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::AtlasTextureContents::SetAlpha
void SetAlpha(Scalar alpha)
Definition: atlas_contents.cc:335
impeller::Entity
Definition: entity.h:21
impeller::AtlasContents::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: atlas_contents.cc:54
impeller::TSize< int64_t >
impeller::AtlasContents::GenerateSubAtlas
std::shared_ptr< SubAtlasResult > GenerateSubAtlas() const
Compress a drawAtlas call with blending into a smaller sized atlas. This atlas has no overlapping to ...
Definition: atlas_contents.cc:83
impeller::AtlasContents::~AtlasContents
~AtlasContents() override
impeller::AtlasContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: atlas_contents.cc:185
impeller::AtlasContents::GetTransforms
const std::vector< Matrix > & GetTransforms() const
Definition: atlas_contents.cc:173
impeller::AtlasContents::GetTextureCoordinates
const std::vector< Rect > & GetTextureCoordinates() const
Definition: atlas_contents.cc:177
impeller::AtlasColorContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: atlas_contents.cc:448
impeller::AtlasColorContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: atlas_contents.cc:430
impeller::AtlasContents::GetTexture
std::shared_ptr< Texture > GetTexture() const
Definition: atlas_contents.cc:32
impeller::SubAtlasResult
Definition: atlas_contents.h:19
impeller::SubAtlasResult::sub_transforms
std::vector< Matrix > sub_transforms
Definition: atlas_contents.h:23
impeller::AtlasContents
Definition: atlas_contents.h:33
impeller::SubAtlasResult::sub_colors
std::vector< Color > sub_colors
Definition: atlas_contents.h:22
impeller::AtlasTextureContents::SetSubAtlas
void SetSubAtlas(const std::shared_ptr< SubAtlasResult > &subatlas)
Definition: atlas_contents.cc:347
impeller::AtlasContents::AtlasContents
AtlasContents()
impeller::AtlasContents::SetColors
void SetColors(std::vector< Color > colors)
Definition: atlas_contents.cc:46
impeller::AtlasColorContents::~AtlasColorContents
~AtlasColorContents() override
Definition: atlas_contents.cc:428
impeller::AtlasTextureContents
Definition: atlas_contents.h:96
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::AtlasContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: atlas_contents.cc:143
sampler_descriptor.h
impeller::AtlasTextureContents::SetUseDestination
void SetUseDestination(bool value)
Definition: atlas_contents.cc:343
impeller::AtlasTextureContents::~AtlasTextureContents
~AtlasTextureContents() override
Definition: atlas_contents.cc:328
impeller::AtlasContents::SetAlpha
void SetAlpha(Scalar alpha)
Definition: atlas_contents.cc:50
impeller::AtlasTextureContents::AtlasTextureContents
AtlasTextureContents(const AtlasContents &parent)
Definition: atlas_contents.cc:325
impeller::AtlasContents::SetCullRect
void SetCullRect(std::optional< Rect > cull_rect)
Definition: atlas_contents.cc:58
impeller::SubAtlasResult::size
ISize size
Definition: atlas_contents.h:30
impeller::AtlasContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: atlas_contents.cc:28
impeller::SubAtlasResult::sub_texture_coords
std::vector< Rect > sub_texture_coords
Definition: atlas_contents.h:21
impeller::Contents
Definition: contents.h:34
impeller::AtlasContents::SetTransforms
void SetTransforms(std::vector< Matrix > transforms)
Definition: atlas_contents.cc:36
impeller::AtlasTextureContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: atlas_contents.cc:330
impeller
Definition: aiks_blur_unittests.cc:20
impeller::AtlasContents::GetSamplerDescriptor
const SamplerDescriptor & GetSamplerDescriptor() const
Definition: atlas_contents.cc:169
impeller::ContentContext
Definition: content_context.h:392
impeller::AtlasTextureContents::SetCoverage
void SetCoverage(Rect coverage)
Definition: atlas_contents.cc:339
impeller::TRect< Scalar >
impeller::AtlasTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: atlas_contents.cc:352
impeller::SubAtlasResult::result_texture_coords
std::vector< Rect > result_texture_coords
Definition: atlas_contents.h:26
impeller::AtlasContents::GetColors
const std::vector< Color > & GetColors() const
Definition: atlas_contents.cc:181
impeller::AtlasColorContents::SetSubAtlas
void SetSubAtlas(const std::shared_ptr< SubAtlasResult > &subatlas)
Definition: atlas_contents.cc:443