Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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/hash_combine.h"
16
17namespace impeller {
18
19class Context;
20
22 ISize size = ISize{0, 0};
23 size_t mip_count = 0;
24 bool has_msaa = false;
25 bool has_depth_stencil = false;
26
27 constexpr bool operator==(const RenderTargetConfig& o) const {
28 return size == o.size && mip_count == o.mip_count &&
30 }
31
32 constexpr size_t Hash() const {
35 }
36};
37
38class RenderTarget final {
39 public:
46
54
60
67
73
75
77
78 bool IsValid() const;
79
81 const Context& context,
82 Allocator& allocator,
83 ISize size,
84 bool msaa,
85 const std::string& label = "Offscreen",
86 RenderTarget::AttachmentConfig stencil_attachment_config =
88 const std::shared_ptr<Texture>& depth_stencil_texture = nullptr);
89
91
92 bool HasColorAttachment(size_t index) const;
93
95
96 std::shared_ptr<Texture> GetRenderTargetTexture() const;
97
99
100 std::optional<ISize> GetColorAttachmentSize(size_t index) const;
101
103 size_t index);
104
105 RenderTarget& SetDepthAttachment(std::optional<DepthAttachment> attachment);
106
108 std::optional<StencilAttachment> attachment);
109
110 size_t GetMaxColorAttacmentBindIndex() const;
111
112 const std::map<size_t, ColorAttachment>& GetColorAttachments() const;
113
114 const std::optional<DepthAttachment>& GetDepthAttachment() const;
115
116 const std::optional<StencilAttachment>& GetStencilAttachment() const;
117
118 size_t GetTotalAttachmentCount() const;
119
121 const std::function<bool(const Attachment& attachment)>& iterator) const;
122
123 std::string ToString() const;
124
126 auto& color_attachment = GetColorAttachments().find(0)->second;
127 return RenderTargetConfig{
128 .size = color_attachment.texture->GetSize(),
129 .mip_count = color_attachment.texture->GetMipCount(),
130 .has_msaa = color_attachment.resolve_texture != nullptr,
131 .has_depth_stencil = depth_.has_value() && stencil_.has_value()};
132 }
133
134 private:
135 std::map<size_t, ColorAttachment> colors_;
136 std::optional<DepthAttachment> depth_;
137 std::optional<StencilAttachment> stencil_;
138};
139
140/// @brief a wrapper around the impeller [Allocator] instance that can be used
141/// to provide caching of allocated render target textures.
143 public:
144 explicit RenderTargetAllocator(std::shared_ptr<Allocator> allocator);
145
146 virtual ~RenderTargetAllocator() = default;
147
149 const Context& context,
150 ISize size,
151 int mip_count,
152 const std::string& label = "Offscreen",
153 RenderTarget::AttachmentConfig color_attachment_config =
155 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
157 const std::shared_ptr<Texture>& existing_color_texture = nullptr,
158 const std::shared_ptr<Texture>& existing_depth_stencil_texture = nullptr);
159
161 const Context& context,
162 ISize size,
163 int mip_count,
164 const std::string& label = "Offscreen MSAA",
165 RenderTarget::AttachmentConfigMSAA color_attachment_config =
167 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
169 const std::shared_ptr<Texture>& existing_color_msaa_texture = nullptr,
170 const std::shared_ptr<Texture>& existing_color_resolve_texture = nullptr,
171 const std::shared_ptr<Texture>& existing_depth_stencil_texture = nullptr);
172
173 /// @brief Mark the beginning of a frame workload.
174 ///
175 /// This may be used to reset any tracking state on whether or not a
176 /// particular texture instance is still in use.
177 virtual void Start();
178
179 /// @brief Mark the end of a frame workload.
180 ///
181 /// This may be used to deallocate any unused textures.
182 virtual void End();
183
184 private:
185 std::shared_ptr<Allocator> allocator_;
186};
187
188} // namespace impeller
189
190#endif // FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_
An object that allocates device memory.
Definition allocator.h:22
To do anything rendering related with Impeller, you need a context.
Definition context.h:46
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual ~RenderTargetAllocator()=default
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, const std::string &label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual void Start()
Mark the beginning of a frame workload.
virtual RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, const std::string &label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual void End()
Mark the end of a frame workload.
std::shared_ptr< Texture > GetRenderTargetTexture() const
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
SampleCount GetSampleCount() const
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
void IterateAllAttachments(const std::function< bool(const Attachment &attachment)> &iterator) const
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
void SetupDepthStencilAttachments(const Context &context, Allocator &allocator, ISize size, bool msaa, const std::string &label="Offscreen", RenderTarget::AttachmentConfig stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &depth_stencil_texture=nullptr)
bool HasColorAttachment(size_t index) const
size_t GetMaxColorAttacmentBindIndex() const
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
std::string ToString() const
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
PixelFormat GetRenderTargetPixelFormat() const
size_t GetTotalAttachmentCount() const
ISize GetRenderTargetSize() const
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
std::optional< ISize > GetColorAttachmentSize(size_t index) const
const std::optional< DepthAttachment > & GetDepthAttachment() const
const std::optional< StencilAttachment > & GetStencilAttachment() const
RenderTargetConfig ToConfig() const
constexpr std::size_t HashCombine()
StorageMode
Specified where the allocation resides and how it is used.
Definition formats.h:33
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
static constexpr Color BlackTransparent()
Definition color.h:262
constexpr size_t Hash() const
constexpr bool operator==(const RenderTargetConfig &o) const
Type height
Definition size.h:23
Type width
Definition size.h:22