Flutter Impeller
render_target.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_RENDERER_RENDER_TARGET_H_
6 #define FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_
7 
8 #include <functional>
9 #include <map>
10 #include <optional>
11 
12 #include "flutter/fml/macros.h"
14 #include "impeller/core/formats.h"
15 #include "impeller/geometry/size.h"
16 
17 namespace impeller {
18 
19 class Context;
20 
21 /// @brief a wrapper around the impeller [Allocator] instance that can be used
22 /// to provide caching of allocated render target textures.
24  public:
25  explicit RenderTargetAllocator(std::shared_ptr<Allocator> allocator);
26 
27  virtual ~RenderTargetAllocator() = default;
28 
29  /// @brief Create a new render target texture, or recycle a previously
30  /// allocated render
31  /// target texture.
32  virtual std::shared_ptr<Texture> CreateTexture(const TextureDescriptor& desc);
33 
34  /// @brief Mark the beginning of a frame workload.
35  ///
36  /// This may be used to reset any tracking state on whether or not a
37  /// particular texture instance is still in use.
38  virtual void Start();
39 
40  /// @brief Mark the end of a frame workload.
41  ///
42  /// This may be used to deallocate any unused textures.
43  virtual void End();
44 
45  private:
46  std::shared_ptr<Allocator> allocator_;
47 };
48 
49 class RenderTarget final {
50  public:
56  };
57 
64  };
65 
68  .load_action = LoadAction::kClear,
69  .store_action = StoreAction::kStore,
70  .clear_color = Color::BlackTransparent()};
71 
74  .resolve_storage_mode = StorageMode::kDevicePrivate,
75  .load_action = LoadAction::kClear,
76  .store_action = StoreAction::kMultisampleResolve,
77  .clear_color = Color::BlackTransparent()};
78 
81  .load_action = LoadAction::kClear,
82  .store_action = StoreAction::kDontCare,
83  .clear_color = Color::BlackTransparent()};
84 
86  const Context& context,
87  RenderTargetAllocator& allocator,
88  ISize size,
89  const std::string& label = "Offscreen",
90  AttachmentConfig color_attachment_config = kDefaultColorAttachmentConfig,
91  std::optional<AttachmentConfig> stencil_attachment_config =
93 
95  const Context& context,
96  RenderTargetAllocator& allocator,
97  ISize size,
98  const std::string& label = "Offscreen MSAA",
99  AttachmentConfigMSAA color_attachment_config =
101  std::optional<AttachmentConfig> stencil_attachment_config =
103 
104  RenderTarget();
105 
106  ~RenderTarget();
107 
108  bool IsValid() const;
109 
110  void SetupStencilAttachment(const Context& context,
111  RenderTargetAllocator& allocator,
112  ISize size,
113  bool msaa,
114  const std::string& label = "Offscreen",
115  AttachmentConfig stencil_attachment_config =
117 
118  SampleCount GetSampleCount() const;
119 
120  bool HasColorAttachment(size_t index) const;
121 
122  ISize GetRenderTargetSize() const;
123 
124  std::shared_ptr<Texture> GetRenderTargetTexture() const;
125 
127 
128  std::optional<ISize> GetColorAttachmentSize(size_t index) const;
129 
131  size_t index);
132 
133  RenderTarget& SetDepthAttachment(std::optional<DepthAttachment> attachment);
134 
136  std::optional<StencilAttachment> attachment);
137 
138  size_t GetMaxColorAttacmentBindIndex() const;
139 
140  const std::map<size_t, ColorAttachment>& GetColorAttachments() const;
141 
142  const std::optional<DepthAttachment>& GetDepthAttachment() const;
143 
144  const std::optional<StencilAttachment>& GetStencilAttachment() const;
145 
146  size_t GetTotalAttachmentCount() const;
147 
149  const std::function<bool(const Attachment& attachment)>& iterator) const;
150 
151  std::string ToString() const;
152 
153  private:
154  std::map<size_t, ColorAttachment> colors_;
155  std::optional<DepthAttachment> depth_;
156  std::optional<StencilAttachment> stencil_;
157 };
158 
159 } // namespace impeller
160 
161 #endif // FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::RenderTarget::SetupStencilAttachment
void SetupStencilAttachment(const Context &context, RenderTargetAllocator &allocator, ISize size, bool msaa, const std::string &label="Offscreen", AttachmentConfig stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:355
impeller::RenderTarget::GetTotalAttachmentCount
size_t GetTotalAttachmentCount() const
Definition: render_target.cc:386
impeller::RenderTarget::AttachmentConfig::store_action
StoreAction store_action
Definition: render_target.h:54
impeller::StoreAction
StoreAction
Definition: formats.h:203
impeller::RenderTarget::AttachmentConfig::load_action
LoadAction load_action
Definition: render_target.h:53
impeller::RenderTarget::kDefaultColorAttachmentConfig
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
Definition: render_target.h:66
impeller::RenderTargetAllocator::Start
virtual void Start()
Mark the beginning of a frame workload.
Definition: render_target.cc:21
impeller::Color
Definition: color.h:124
impeller::ColorAttachment
Definition: formats.h:642
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:180
impeller::RenderTarget::kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
Definition: render_target.h:72
formats.h
impeller::RenderTarget::AttachmentConfigMSAA::store_action
StoreAction store_action
Definition: render_target.h:62
impeller::StoreAction::kDontCare
@ kDontCare
impeller::RenderTarget::GetRenderTargetPixelFormat
PixelFormat GetRenderTargetPixelFormat() const
Definition: render_target.cc:164
impeller::RenderTarget::GetColorAttachmentSize
std::optional< ISize > GetColorAttachmentSize(size_t index) const
Definition: render_target.cc:140
impeller::RenderTargetAllocator::RenderTargetAllocator
RenderTargetAllocator(std::shared_ptr< Allocator > allocator)
Definition: render_target.cc:17
impeller::RenderTarget::GetColorAttachments
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
Definition: render_target.cc:209
impeller::RenderTarget::AttachmentConfigMSAA::load_action
LoadAction load_action
Definition: render_target.h:61
impeller::RenderTarget::AttachmentConfigMSAA::resolve_storage_mode
StorageMode resolve_storage_mode
Definition: render_target.h:60
impeller::RenderTarget::AttachmentConfigMSAA
Definition: render_target.h:58
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::RenderTarget::AttachmentConfig
Definition: render_target.h:51
impeller::TSize< int64_t >
impeller::LoadAction::kClear
@ kClear
impeller::RenderTarget::GetDepthAttachment
const std::optional< DepthAttachment > & GetDepthAttachment() const
Definition: render_target.cc:214
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:27
impeller::RenderTarget::GetRenderTargetTexture
std::shared_ptr< Texture > GetRenderTargetTexture() const
Definition: render_target.cc:155
impeller::RenderTarget::IterateAllAttachments
void IterateAllAttachments(const std::function< bool(const Attachment &attachment)> &iterator) const
Definition: render_target.cc:105
impeller::RenderTarget::~RenderTarget
~RenderTarget()
impeller::LoadAction
LoadAction
Definition: formats.h:197
impeller::RenderTarget::kDefaultStencilAttachmentConfig
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
Definition: render_target.h:79
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::RenderTarget::AttachmentConfig::storage_mode
StorageMode storage_mode
Definition: render_target.h:52
impeller::RenderTargetAllocator::CreateTexture
virtual std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Create a new render target texture, or recycle a previously allocated render target texture.
Definition: render_target.cc:25
impeller::Attachment
Definition: formats.h:633
impeller::RenderTarget
Definition: render_target.h:49
impeller::StoreAction::kStore
@ kStore
impeller::RenderTarget::IsValid
bool IsValid() const
Definition: render_target.cc:34
impeller::RenderTargetAllocator
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
Definition: render_target.h:23
impeller::RenderTarget::AttachmentConfig::clear_color
Color clear_color
Definition: render_target.h:55
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:150
impeller::RenderTarget::CreateOffscreen
static RenderTarget CreateOffscreen(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen", AttachmentConfig color_attachment_config=kDefaultColorAttachmentConfig, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:223
allocator.h
impeller::RenderTarget::AttachmentConfigMSAA::storage_mode
StorageMode storage_mode
Definition: render_target.h:59
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:199
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::RenderTargetAllocator::End
virtual void End()
Mark the end of a frame workload.
Definition: render_target.cc:23
impeller::Color::BlackTransparent
static constexpr Color BlackTransparent()
Definition: color.h:262
impeller::SampleCount
SampleCount
Definition: formats.h:290
impeller::RenderTarget::GetMaxColorAttacmentBindIndex
size_t GetMaxColorAttacmentBindIndex() const
Definition: render_target.cc:172
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
impeller::RenderTarget::GetStencilAttachment
const std::optional< StencilAttachment > & GetStencilAttachment() const
Definition: render_target.cc:218
impeller::RenderTarget::SetDepthAttachment
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
Definition: render_target.cc:189
impeller::RenderTarget::GetSampleCount
SampleCount GetSampleCount() const
Definition: render_target.cc:126
impeller::RenderTarget::HasColorAttachment
bool HasColorAttachment(size_t index) const
Definition: render_target.cc:133
impeller
Definition: aiks_context.cc:10
impeller::RenderTarget::ToString
std::string ToString() const
Definition: render_target.cc:405
impeller::RenderTarget::CreateOffscreenMSAA
static RenderTarget CreateOffscreenMSAA(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen MSAA", AttachmentConfigMSAA color_attachment_config=kDefaultColorAttachmentConfigMSAA, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:265
impeller::RenderTargetAllocator::~RenderTargetAllocator
virtual ~RenderTargetAllocator()=default
size.h
impeller::RenderTarget::AttachmentConfigMSAA::clear_color
Color clear_color
Definition: render_target.h:63
impeller::RenderTarget::RenderTarget
RenderTarget()