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