| Flutter Impeller |

blit_pass.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_BLIT_PASS_H_
6 #define FLUTTER_IMPELLER_RENDERER_BLIT_PASS_H_
7
8 #include <string>
9
10 #include "impeller/core/device_buffer.h"
11 #include "impeller/core/texture.h"
12
13 namespace impeller {
14
15 class HostBuffer;
16 class Allocator;
17
18 //------------------------------------------------------------------------------
19 /// @brief Blit passes encode blit into the underlying command buffer.
20 ///
21 /// Blit passes can be obtained from the command buffer in which
22 /// the pass is meant to encode commands into.
23 ///
24 /// @see `CommandBuffer`
25 ///
26 class BlitPass {
27 public:
28 virtual ~BlitPass();
29
30 virtual bool IsValid() const = 0;
31
32 void SetLabel(std::string label);
33
34 //----------------------------------------------------------------------------
35 /// @brief If the texture is not already in a shader read internal
36 /// state, then convert it to that state.
37 ///
38 /// This API is only used by Vulkan.
39 virtual bool ConvertTextureToShaderRead(
40 const std::shared_ptr<Texture>& texture);
41
42 //----------------------------------------------------------------------------
43 /// @brief Resize the [source] texture into the [destination] texture.
44 ///
45 /// On Metal platforms, [destination] is required to be non-lossy
46 /// and have the Shader read capability.
47 virtual bool ResizeTexture(const std::shared_ptr<Texture>& source,
48 const std::shared_ptr<Texture>& destination) = 0;
49
50 //----------------------------------------------------------------------------
51 /// @brief Record a command to copy the contents of one texture to
52 /// another texture. The blit area is limited by the intersection
53 /// of the texture coverage with respect the source region and
54 /// destination origin.
55 ///
56 /// @param[in] source The texture to read for copying.
57 /// @param[in] destination The texture to overwrite using the source
58 /// contents.
59 /// @param[in] source_region The optional region of the source texture
60 /// to use for copying. If not specified, the
61 /// full size of the source texture is used.
62 /// @param[in] destination_origin The origin to start writing to in the
63 /// destination texture.
64 /// @param[in] label The optional debug label to give the
65 /// command.
66 ///
67 /// @return If the command was valid for subsequent commitment.
68 ///
69 bool AddCopy(std::shared_ptr<Texture> source,
70 std::shared_ptr<Texture> destination,
71 std::optional<IRect> source_region = std::nullopt,
72 IPoint destination_origin = {},
73 std::string label = "");
74
75 //----------------------------------------------------------------------------
76 /// @brief Record a command to copy the contents of the buffer to
77 /// the texture.
78 ///
79 /// @param[in] source The texture to read for copying.
80 /// @param[in] destination The buffer to overwrite using the source
81 /// contents.
82 /// @param[in] source_region The optional region of the source texture
83 /// to use for copying. If not specified, the
84 /// full size of the source texture is used.
85 /// @param[in] destination_origin The origin to start writing to in the
86 /// destination texture.
87 /// @param[in] label The optional debug label to give the
88 /// command.
89 ///
90 /// @return If the command was valid for subsequent commitment.
91 ///
92 bool AddCopy(std::shared_ptr<Texture> source,
93 std::shared_ptr<DeviceBuffer> destination,
94 std::optional<IRect> source_region = std::nullopt,
95 size_t destination_offset = 0,
96 std::string label = "");
97
98 //----------------------------------------------------------------------------
99 /// @brief Record a command to copy the contents of the buffer to
100 /// the texture.
101 ///
102 /// @param[in] source The buffer view to read for copying.
103 /// @param[in] destination The texture to overwrite using the source
104 /// contents.
105 /// @param[in] destination_region The offset to start writing to in the
106 /// destination texture. If not provided, this
107 /// defaults to the entire texture.
108 /// @param[in] label The optional debug label to give the
109 /// command.
110 /// @param[in] slice For cubemap textures, the slice to write
111 /// data to.
112 /// @param[in] convert_to_read Whether to convert the texture to a shader
113 /// read state. Defaults to true.
114 ///
115 /// @return If the command was valid for subsequent commitment.
116 ///
117 /// If a region smaller than the texture size is provided, the
118 /// contents are treated as containing tightly packed pixel data of
119 /// that region. Only the portion of the texture in this region is
120 /// replaced and existing data is preserved.
121 ///
122 /// For example, to replace the top left 10 x 10 region of a larger
123 /// 100 x 100 texture, the region is {0, 0, 10, 10} and the expected
124 /// buffer size in bytes is 100 x bpp.
125 bool AddCopy(BufferView source,
126 std::shared_ptr<Texture> destination,
127 std::optional<IRect> destination_region = std::nullopt,
128 std::string label = "",
129 uint32_t slice = 0,
130 bool convert_to_read = true);
131
132 //----------------------------------------------------------------------------
133 /// @brief Record a command to generate all mip levels for a texture.
134 ///
135 /// @param[in] texture The texture to generate mipmaps for.
136 /// @param[in] label The optional debug label to give the command.
137 ///
138 /// @return If the command was valid for subsequent commitment.
139 ///
140 bool GenerateMipmap(std::shared_ptr<Texture> texture, std::string label = "");
141
142 //----------------------------------------------------------------------------
143 /// @brief Encode the recorded commands to the underlying command buffer.
144 ///
145 /// @param transients_allocator The transients allocator.
146 ///
147 /// @return If the commands were encoded to the underlying command
148 /// buffer.
149 ///
150 virtual bool EncodeCommands(
151 const std::shared_ptr<Allocator>& transients_allocator) const = 0;
152
153 protected:
154 explicit BlitPass();
155
156 virtual void OnSetLabel(std::string label) = 0;
157
158 virtual bool OnCopyTextureToTextureCommand(
159 std::shared_ptr<Texture> source,
160 std::shared_ptr<Texture> destination,
161 IRect source_region,
162 IPoint destination_origin,
163 std::string label) = 0;
164
165 virtual bool OnCopyTextureToBufferCommand(
166 std::shared_ptr<Texture> source,
167 std::shared_ptr<DeviceBuffer> destination,
168 IRect source_region,
169 size_t destination_offset,
170 std::string label) = 0;
171
172 virtual bool OnCopyBufferToTextureCommand(
173 BufferView source,
174 std::shared_ptr<Texture> destination,
175 IRect destination_region,
176 std::string label,
177 uint32_t slice,
178 bool convert_to_read) = 0;
179
180 virtual bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
181 std::string label) = 0;
182
183 private:
184 BlitPass(const BlitPass&) = delete;
185
186 BlitPass& operator=(const BlitPass&) = delete;
187 };
188
189 } // namespace impeller
190
191 #endif // FLUTTER_IMPELLER_RENDERER_BLIT_PASS_H_
impeller::BlitPass::OnCopyTextureToBufferCommand
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
device_buffer.h
impeller::BlitPass::~BlitPass
virtual ~BlitPass()
impeller::BlitPass::AddCopy
bool AddCopy(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, std::optional< IRect > source_region=std::nullopt, IPoint destination_origin={}, std::string label="")
Record a command to copy the contents of one texture to another texture. The blit area is limited by ...
Definition: blit_pass.cc:26
impeller::BlitPass::ConvertTextureToShaderRead
virtual bool ConvertTextureToShaderRead(const std::shared_ptr< Texture > &texture)
If the texture is not already in a shader read internal state, then convert it to that state.
Definition: blit_pass.cc:163
impeller::BlitPass::BlitPass
BlitPass()
Definition: blit_pass.cc:15
impeller::BlitPass::GenerateMipmap
bool GenerateMipmap(std::shared_ptr< Texture > texture, std::string label="")
Record a command to generate all mip levels for a texture.
Definition: blit_pass.cc:168
impeller::BlitPass::OnCopyTextureToTextureCommand
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
impeller::BlitPass
Blit passes encode blit into the underlying command buffer.
Definition: blit_pass.h:26
impeller::BlitPass::ResizeTexture
virtual bool ResizeTexture(const std::shared_ptr< Texture > &source, const std::shared_ptr< Texture > &destination)=0
Resize the [source] texture into the [destination] texture.
impeller::BlitPass::OnCopyBufferToTextureCommand
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IRect destination_region, std::string label, uint32_t slice, bool convert_to_read)=0
impeller::BlitPass::OnGenerateMipmapCommand
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string label)=0
impeller::BlitPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
impeller::BlitPass::SetLabel
void SetLabel(std::string label)
Definition: blit_pass.cc:19
impeller::BufferView
Definition: buffer_view.h:15
impeller::BlitPass::EncodeCommands
virtual bool EncodeCommands(const std::shared_ptr< Allocator > &transients_allocator) const =0
Encode the recorded commands to the underlying command buffer.
impeller::TPoint< int64_t >
texture.h
impeller
Definition: allocation.cc:12
impeller::TRect
Definition: rect.h:122
impeller::BlitPass::IsValid
virtual bool IsValid() const =0