forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_target.h
More file actions
163 lines (122 loc) · 5.12 KB
/
render_target.h
File metadata and controls
163 lines (122 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_
#define FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_
#include <functional>
#include <map>
#include <optional>
#include "flutter/fml/macros.h"
#include "impeller/core/allocator.h"
#include "impeller/core/formats.h"
#include "impeller/geometry/size.h"
namespace impeller {
class Context;
/// @brief a wrapper around the impeller [Allocator] instance that can be used
/// to provide caching of allocated render target textures.
class RenderTargetAllocator {
public:
explicit RenderTargetAllocator(std::shared_ptr<Allocator> allocator);
virtual ~RenderTargetAllocator() = default;
/// @brief Create a new render target texture, or recycle a previously
/// allocated render
/// target texture.
virtual std::shared_ptr<Texture> CreateTexture(const TextureDescriptor& desc);
/// @brief Mark the beginning of a frame workload.
///
/// This may be used to reset any tracking state on whether or not a
/// particular texture instance is still in use.
virtual void Start();
/// @brief Mark the end of a frame workload.
///
/// This may be used to deallocate any unused textures.
virtual void End();
private:
std::shared_ptr<Allocator> allocator_;
};
class RenderTarget final {
public:
struct AttachmentConfig {
StorageMode storage_mode;
LoadAction load_action;
StoreAction store_action;
Color clear_color;
};
struct AttachmentConfigMSAA {
StorageMode storage_mode;
StorageMode resolve_storage_mode;
LoadAction load_action;
StoreAction store_action;
Color clear_color;
};
static constexpr AttachmentConfig kDefaultColorAttachmentConfig = {
.storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kStore,
.clear_color = Color::BlackTransparent()};
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA = {
.storage_mode = StorageMode::kDeviceTransient,
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kMultisampleResolve,
.clear_color = Color::BlackTransparent()};
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig = {
.storage_mode = StorageMode::kDeviceTransient,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kDontCare,
.clear_color = Color::BlackTransparent()};
static RenderTarget CreateOffscreen(
const Context& context,
RenderTargetAllocator& allocator,
ISize size,
int mip_count,
const std::string& label = "Offscreen",
AttachmentConfig color_attachment_config = kDefaultColorAttachmentConfig,
std::optional<AttachmentConfig> stencil_attachment_config =
kDefaultStencilAttachmentConfig);
static RenderTarget CreateOffscreenMSAA(
const Context& context,
RenderTargetAllocator& allocator,
ISize size,
int mip_count,
const std::string& label = "Offscreen MSAA",
AttachmentConfigMSAA color_attachment_config =
kDefaultColorAttachmentConfigMSAA,
std::optional<AttachmentConfig> stencil_attachment_config =
kDefaultStencilAttachmentConfig);
RenderTarget();
~RenderTarget();
bool IsValid() const;
void SetupDepthStencilAttachments(const Context& context,
RenderTargetAllocator& allocator,
ISize size,
bool msaa,
const std::string& label = "Offscreen",
AttachmentConfig stencil_attachment_config =
kDefaultStencilAttachmentConfig);
SampleCount GetSampleCount() const;
bool HasColorAttachment(size_t index) const;
ISize GetRenderTargetSize() const;
std::shared_ptr<Texture> GetRenderTargetTexture() const;
PixelFormat GetRenderTargetPixelFormat() const;
std::optional<ISize> GetColorAttachmentSize(size_t index) const;
RenderTarget& SetColorAttachment(const ColorAttachment& attachment,
size_t index);
RenderTarget& SetDepthAttachment(std::optional<DepthAttachment> attachment);
RenderTarget& SetStencilAttachment(
std::optional<StencilAttachment> attachment);
size_t GetMaxColorAttacmentBindIndex() const;
const std::map<size_t, ColorAttachment>& GetColorAttachments() const;
const std::optional<DepthAttachment>& GetDepthAttachment() const;
const std::optional<StencilAttachment>& GetStencilAttachment() const;
size_t GetTotalAttachmentCount() const;
void IterateAllAttachments(
const std::function<bool(const Attachment& attachment)>& iterator) const;
std::string ToString() const;
private:
std::map<size_t, ColorAttachment> colors_;
std::optional<DepthAttachment> depth_;
std::optional<StencilAttachment> stencil_;
};
} // namespace impeller
#endif // FLUTTER_IMPELLER_RENDERER_RENDER_TARGET_H_