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