| 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 #include <variant>
10
11 #include "impeller/core/device_buffer.h"
12 #include "impeller/core/texture.h"
13 #include "impeller/renderer/blit_command.h"
14
15 namespace impeller {
16
17 class HostBuffer;
18 class Allocator;
19
20 //------------------------------------------------------------------------------
21 /// @brief Blit passes encode blit into the underlying command buffer.
22 ///
23 /// Blit passes can be obtained from the command buffer in which
24 /// the pass is meant to encode commands into.
25 ///
26 /// @see `CommandBuffer`
27 ///
28 class BlitPass {
29 public:
30 virtual ~BlitPass();
31
32 virtual bool IsValid() const = 0;
33
34 void SetLabel(std::string label);
35
36 HostBuffer& GetTransientsBuffer();
37
38 //----------------------------------------------------------------------------
39 /// @brief Record a command to copy the contents of one texture to
40 /// another texture. The blit area is limited by the intersection
41 /// of the texture coverage with respect the source region and
42 /// destination origin.
43 /// No work is encoded into the command buffer at this time.
44 ///
45 /// @param[in] source The texture to read for copying.
46 /// @param[in] destination The texture to overwrite using the source
47 /// contents.
48 /// @param[in] source_region The optional region of the source texture
49 /// to use for copying. If not specified, the
50 /// full size of the source texture is used.
51 /// @param[in] destination_origin The origin to start writing to in the
52 /// destination texture.
53 /// @param[in] label The optional debug label to give the
54 /// command.
55 ///
56 /// @return If the command was valid for subsequent commitment.
57 ///
58 bool AddCopy(std::shared_ptr<Texture> source,
59 std::shared_ptr<Texture> destination,
60 std::optional<IRect> source_region = std::nullopt,
61 IPoint destination_origin = {},
62 std::string label = "");
63
64 //----------------------------------------------------------------------------
65 /// @brief Record a command to copy the contents of the buffer to
66 /// the texture.
67 /// No work is encoded into the command buffer at this time.
68 ///
69 /// @param[in] source The texture to read for copying.
70 /// @param[in] destination The buffer to overwrite using the source
71 /// contents.
72 /// @param[in] source_region The optional region of the source texture
73 /// to use for copying. If not specified, the
74 /// full size of the source texture is used.
75 /// @param[in] destination_origin The origin to start writing to in the
76 /// destination texture.
77 /// @param[in] label The optional debug label to give the
78 /// command.
79 ///
80 /// @return If the command was valid for subsequent commitment.
81 ///
82 bool AddCopy(std::shared_ptr<Texture> source,
83 std::shared_ptr<DeviceBuffer> destination,
84 std::optional<IRect> source_region = std::nullopt,
85 size_t destination_offset = 0,
86 std::string label = "");
87
88 //----------------------------------------------------------------------------
89 /// @brief Record a command to copy the contents of the buffer to
90 /// the texture.
91 /// No work is encoded into the command buffer at this time.
92 ///
93 /// @param[in] source The buffer view to read for copying.
94 /// @param[in] destination The texture to overwrite using the source
95 /// contents.
96 /// @param[in] destination_offset The offset to start writing to in the
97 /// destination buffer.
98 /// @param[in] label The optional debug label to give the
99 /// command.
100 ///
101 /// @return If the command was valid for subsequent commitment.
102 ///
103 bool AddCopy(BufferView source,
104 std::shared_ptr<Texture> destination,
105 IPoint destination_origin = {},
106 std::string label = "");
107
108 //----------------------------------------------------------------------------
109 /// @brief Record a command to generate all mip levels for a texture.
110 /// No work is encoded into the command buffer at this time.
111 ///
112 /// @param[in] texture The texture to generate mipmaps for.
113 /// @param[in] label The optional debug label to give the command.
114 ///
115 /// @return If the command was valid for subsequent commitment.
116 ///
117 bool GenerateMipmap(std::shared_ptr<Texture> texture, std::string label = "");
118
119 //----------------------------------------------------------------------------
120 /// @brief Encode the recorded commands to the underlying command buffer.
121 ///
122 /// @param transients_allocator The transients allocator.
123 ///
124 /// @return If the commands were encoded to the underlying command
125 /// buffer.
126 ///
127 virtual bool EncodeCommands(
128 const std::shared_ptr<Allocator>& transients_allocator) const = 0;
129
130 protected:
131 std::shared_ptr<HostBuffer> transients_buffer_;
132
133 explicit BlitPass();
134
135 virtual void OnSetLabel(std::string label) = 0;
136
137 virtual bool OnCopyTextureToTextureCommand(
138 std::shared_ptr<Texture> source,
139 std::shared_ptr<Texture> destination,
140 IRect source_region,
141 IPoint destination_origin,
142 std::string label) = 0;
143
144 virtual bool OnCopyTextureToBufferCommand(
145 std::shared_ptr<Texture> source,
146 std::shared_ptr<DeviceBuffer> destination,
147 IRect source_region,
148 size_t destination_offset,
149 std::string label) = 0;
150
151 virtual bool OnCopyBufferToTextureCommand(
152 BufferView source,
153 std::shared_ptr<Texture> destination,
154 IPoint destination_origin,
155 std::string label) = 0;
156
157 virtual bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
158 std::string label) = 0;
159
160 private:
161 BlitPass(const BlitPass&) = delete;
162
163 BlitPass& operator=(const BlitPass&) = delete;
164 };
165
166 } // namespace impeller
167
168 #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::HostBuffer
Definition: host_buffer.h:20
blit_command.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:33
impeller::BlitPass::BlitPass
BlitPass()
Definition: blit_pass.cc:17
impeller::BlitPass::GenerateMipmap
bool GenerateMipmap(std::shared_ptr< Texture > texture, std::string label="")
Record a command to generate all mip levels for a texture. No work is encoded into the command buffer...
Definition: blit_pass.cc:154
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:28
impeller::BlitPass::OnCopyBufferToTextureCommand
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label)=0
impeller::BlitPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: blit_pass.cc:21
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:25
impeller::BufferView
Definition: buffer_view.h:13
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::BlitPass::transients_buffer_
std::shared_ptr< HostBuffer > transients_buffer_
Definition: blit_pass.h:131
impeller::TPoint< int64_t >
texture.h
impeller
Definition: aiks_context.cc:10
impeller::TRect< int64_t >
impeller::BlitPass::IsValid
virtual bool IsValid() const =0