| Flutter Impeller |

texture_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_TEXTURE_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXTURE_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/geometry/path.h"
16
17 namespace impeller {
18
19 class Texture;
20
21 class TextureContents final : public Contents {
22 public:
23 TextureContents();
24
25 ~TextureContents() override;
26
27 /// @brief A common case factory that marks the texture contents as having a
28 /// destination rectangle. In this situation, a subpass can be avoided
29 /// when image filters are applied.
30 static std::shared_ptr<TextureContents> MakeRect(Rect destination);
31
32 void SetLabel(std::string label);
33
34 void SetDestinationRect(Rect rect);
35
36 void SetTexture(std::shared_ptr<Texture> texture);
37
38 std::shared_ptr<Texture> GetTexture() const;
39
40 void SetSamplerDescriptor(SamplerDescriptor desc);
41
42 const SamplerDescriptor& GetSamplerDescriptor() const;
43
44 void SetSourceRect(const Rect& source_rect);
45
46 const Rect& GetSourceRect() const;
47
48 void SetOpacity(Scalar opacity);
49
50 Scalar GetOpacity() const;
51
52 void SetStencilEnabled(bool enabled);
53
54 // |Contents|
55 std::optional<Rect> GetCoverage(const Entity& entity) const override;
56
57 // |Contents|
58 std::optional<Snapshot> RenderToSnapshot(
59 const ContentContext& renderer,
60 const Entity& entity,
61 std::optional<Rect> coverage_limit = std::nullopt,
62 const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
63 bool msaa_enabled = true,
64 const std::string& label = "Texture Snapshot") const override;
65
66 // |Contents|
67 bool Render(const ContentContext& renderer,
68 const Entity& entity,
69 RenderPass& pass) const override;
70
71 // |Contents|
72 bool CanInheritOpacity(const Entity& entity) const override;
73
74 // |Contents|
75 void SetInheritedOpacity(Scalar opacity) override;
76
77 void SetDeferApplyingOpacity(bool defer_applying_opacity);
78
79 private:
80 std::string label_;
81
82 Rect destination_rect_;
83 bool stencil_enabled_ = true;
84
85 std::shared_ptr<Texture> texture_;
86 SamplerDescriptor sampler_descriptor_ = {};
87 Rect source_rect_;
88 Scalar opacity_ = 1.0f;
89 Scalar inherited_opacity_ = 1.0f;
90 bool defer_applying_opacity_ = false;
91
92 TextureContents(const TextureContents&) = delete;
93
94 TextureContents& operator=(const TextureContents&) = delete;
95 };
96
97 } // namespace impeller
98
99 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXTURE_CONTENTS_H_
path.h
impeller::TextureContents::SetSamplerDescriptor
void SetSamplerDescriptor(SamplerDescriptor desc)
Definition: texture_contents.cc:199
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TextureContents::SetOpacity
void SetOpacity(Scalar opacity)
Definition: texture_contents.cc:49
impeller::TextureContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: texture_contents.cc:61
impeller::TextureContents::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: texture_contents.cc:69
impeller::TextureContents::SetSourceRect
void SetSourceRect(const Rect &source_rect)
Definition: texture_contents.cc:191
impeller::TextureContents::SetStencilEnabled
void SetStencilEnabled(bool enabled)
Definition: texture_contents.cc:53
impeller::TextureContents::GetOpacity
Scalar GetOpacity() const
Definition: texture_contents.cc:65
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::Entity
Definition: entity.h:21
impeller::TextureContents::~TextureContents
~TextureContents() override
impeller::TextureContents::GetSourceRect
const Rect & GetSourceRect() const
Definition: texture_contents.cc:195
impeller::TextureContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: texture_contents.cc:57
impeller::TextureContents::SetLabel
void SetLabel(std::string label)
Definition: texture_contents.cc:33
impeller::TextureContents::GetTexture
std::shared_ptr< Texture > GetTexture() const
Definition: texture_contents.cc:45
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
sampler_descriptor.h
impeller::TextureContents::SetDeferApplyingOpacity
void SetDeferApplyingOpacity(bool defer_applying_opacity)
Definition: texture_contents.cc:207
impeller::TextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: texture_contents.cc:107
impeller::TextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: texture_contents.cc:41
impeller::TextureContents::TextureContents
TextureContents()
impeller::Contents
Definition: contents.h:34
impeller::TextureContents::SetDestinationRect
void SetDestinationRect(Rect rect)
Definition: texture_contents.cc:37
impeller::TextureContents::MakeRect
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
Definition: texture_contents.cc:27
impeller::TextureContents::GetSamplerDescriptor
const SamplerDescriptor & GetSamplerDescriptor() const
Definition: texture_contents.cc:203
impeller::TextureContents::RenderToSnapshot
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, const std::string &label="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
Definition: texture_contents.cc:76
impeller
Definition: aiks_context.cc:10
impeller::TextureContents
Definition: texture_contents.h:21
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >