Flutter Engine
The Flutter Engine
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
12
13namespace impeller {
14
15class HostBuffer;
16class 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///
26class 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 Record a command to copy the contents of one texture to
44 /// another texture. The blit area is limited by the intersection
45 /// of the texture coverage with respect the source region and
46 /// destination origin.
47 ///
48 /// @param[in] source The texture to read for copying.
49 /// @param[in] destination The texture to overwrite using the source
50 /// contents.
51 /// @param[in] source_region The optional region of the source texture
52 /// to use for copying. If not specified, the
53 /// full size of the source texture is used.
54 /// @param[in] destination_origin The origin to start writing to in the
55 /// destination texture.
56 /// @param[in] label The optional debug label to give the
57 /// command.
58 ///
59 /// @return If the command was valid for subsequent commitment.
60 ///
61 bool AddCopy(std::shared_ptr<Texture> source,
62 std::shared_ptr<Texture> destination,
63 std::optional<IRect> source_region = std::nullopt,
64 IPoint destination_origin = {},
65 std::string label = "");
66
67 //----------------------------------------------------------------------------
68 /// @brief Record a command to copy the contents of the buffer to
69 /// the texture.
70 ///
71 /// @param[in] source The texture to read for copying.
72 /// @param[in] destination The buffer to overwrite using the source
73 /// contents.
74 /// @param[in] source_region The optional region of the source texture
75 /// to use for copying. If not specified, the
76 /// full size of the source texture is used.
77 /// @param[in] destination_origin The origin to start writing to in the
78 /// destination texture.
79 /// @param[in] label The optional debug label to give the
80 /// command.
81 ///
82 /// @return If the command was valid for subsequent commitment.
83 ///
84 bool AddCopy(std::shared_ptr<Texture> source,
85 std::shared_ptr<DeviceBuffer> destination,
86 std::optional<IRect> source_region = std::nullopt,
87 size_t destination_offset = 0,
88 std::string label = "");
89
90 //----------------------------------------------------------------------------
91 /// @brief Record a command to copy the contents of the buffer to
92 /// the texture.
93 ///
94 /// @param[in] source The buffer view to read for copying.
95 /// @param[in] destination The texture to overwrite using the source
96 /// contents.
97 /// @param[in] destination_region The offset to start writing to in the
98 /// destination texture. If not provided, this
99 /// defaults to the entire texture.
100 /// @param[in] label The optional debug label to give the
101 /// command.
102 /// @param[in] slice For cubemap textures, the slice to write
103 /// data to.
104 /// @param[in] convert_to_read Whether to convert the texture to a shader
105 /// read state. Defaults to true.
106 ///
107 /// @return If the command was valid for subsequent commitment.
108 ///
109 /// If a region smaller than the texture size is provided, the
110 /// contents are treated as containing tightly packed pixel data of
111 /// that region. Only the portion of the texture in this region is
112 /// replaced and existing data is preserved.
113 ///
114 /// For example, to replace the top left 10 x 10 region of a larger
115 /// 100 x 100 texture, the region is {0, 0, 10, 10} and the expected
116 /// buffer size in bytes is 100 x bpp.
118 std::shared_ptr<Texture> destination,
119 std::optional<IRect> destination_region = std::nullopt,
120 std::string label = "",
121 uint32_t slice = 0,
122 bool convert_to_read = true);
123
124 //----------------------------------------------------------------------------
125 /// @brief Record a command to generate all mip levels for a texture.
126 ///
127 /// @param[in] texture The texture to generate mipmaps for.
128 /// @param[in] label The optional debug label to give the command.
129 ///
130 /// @return If the command was valid for subsequent commitment.
131 ///
132 bool GenerateMipmap(std::shared_ptr<Texture> texture, std::string label = "");
133
134 //----------------------------------------------------------------------------
135 /// @brief Encode the recorded commands to the underlying command buffer.
136 ///
137 /// @param transients_allocator The transients allocator.
138 ///
139 /// @return If the commands were encoded to the underlying command
140 /// buffer.
141 ///
142 virtual bool EncodeCommands(
143 const std::shared_ptr<Allocator>& transients_allocator) const = 0;
144
145 protected:
146 explicit BlitPass();
147
148 virtual void OnSetLabel(std::string label) = 0;
149
151 std::shared_ptr<Texture> source,
152 std::shared_ptr<Texture> destination,
153 IRect source_region,
154 IPoint destination_origin,
155 std::string label) = 0;
156
158 std::shared_ptr<Texture> source,
159 std::shared_ptr<DeviceBuffer> destination,
160 IRect source_region,
161 size_t destination_offset,
162 std::string label) = 0;
163
166 std::shared_ptr<Texture> destination,
167 IRect destination_region,
168 std::string label,
169 uint32_t slice,
170 bool convert_to_read) = 0;
171
172 virtual bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
173 std::string label) = 0;
174
175 private:
176 BlitPass(const BlitPass&) = delete;
177
178 BlitPass& operator=(const BlitPass&) = delete;
179};
180
181} // namespace impeller
182
183#endif // FLUTTER_IMPELLER_RENDERER_BLIT_PASS_H_
Blit passes encode blit into the underlying command buffer.
Definition: blit_pass.h:26
virtual bool EncodeCommands(const std::shared_ptr< Allocator > &transients_allocator) const =0
Encode the recorded commands to the underlying command buffer.
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
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
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
void SetLabel(std::string label)
Definition: blit_pass.cc:19
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IRect destination_region, std::string label, uint32_t slice, bool convert_to_read)=0
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
virtual void OnSetLabel(std::string label)=0
virtual bool IsValid() const =0
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string label)=0
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
SkBitmap source
Definition: examples.cpp:28
FlTexture * texture