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