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