Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
impeller::BlitPass Class Referenceabstract

Blit passes encode blit into the underlying command buffer. More...

#include <blit_pass.h>

Inheritance diagram for impeller::BlitPass:
impeller::BlitPassGLES impeller::BlitPassMTL impeller::BlitPassVK impeller::testing::MockBlitPass

Public Member Functions

virtual ~BlitPass ()
 
virtual bool IsValid () const =0
 
void SetLabel (std::string label)
 
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 the intersection of the texture coverage with respect the source region and destination origin. No work is encoded into the command buffer at this time.
 
bool AddCopy (std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, std::optional< IRect > source_region=std::nullopt, size_t destination_offset=0, std::string label="")
 Record a command to copy the contents of the buffer to the texture. No work is encoded into the command buffer at this time.
 
bool AddCopy (BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin={}, std::string label="")
 Record a command to copy the contents of the buffer to the texture. No work is encoded into the command buffer at this time.
 
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 at this time.
 
virtual bool EncodeCommands (const std::shared_ptr< Allocator > &transients_allocator) const =0
 Encode the recorded commands to the underlying command buffer.
 

Protected Member Functions

 BlitPass ()
 
virtual void OnSetLabel (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
 
virtual bool OnCopyTextureToBufferCommand (std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
 
virtual bool OnCopyBufferToTextureCommand (BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label)=0
 
virtual bool OnGenerateMipmapCommand (std::shared_ptr< Texture > texture, std::string label)=0
 

Detailed Description

Blit passes encode blit into the underlying command buffer.

        Blit passes can be obtained from the command buffer in which
        the pass is meant to encode commands into.
See also
CommandBuffer

Definition at line 26 of file blit_pass.h.

Constructor & Destructor Documentation

◆ ~BlitPass()

impeller::BlitPass::~BlitPass ( )
virtualdefault

◆ BlitPass()

impeller::BlitPass::BlitPass ( )
explicitprotected

Definition at line 15 of file blit_pass.cc.

15{}

Member Function Documentation

◆ AddCopy() [1/3]

bool impeller::BlitPass::AddCopy ( BufferView  source,
std::shared_ptr< Texture destination,
IPoint  destination_origin = {},
std::string  label = "" 
)

Record a command to copy the contents of the buffer to the texture. No work is encoded into the command buffer at this time.

Parameters
[in]sourceThe buffer view to read for copying.
[in]destinationThe texture to overwrite using the source contents.
[in]destination_offsetThe offset to start writing to in the destination buffer.
[in]labelThe optional debug label to give the command.
Returns
If the command was valid for subsequent commitment.

Definition at line 123 of file blit_pass.cc.

126 {
127 if (!destination) {
128 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
129 return false;
130 }
131
132 auto bytes_per_pixel =
133 BytesPerPixelForPixelFormat(destination->GetTextureDescriptor().format);
134 auto bytes_per_image =
135 destination->GetTextureDescriptor().size.Area() * bytes_per_pixel;
136
137 if (source.range.length != bytes_per_image) {
139 << "Attempted to add a texture blit with out of bounds access.";
140 return false;
141 }
142
143 return OnCopyBufferToTextureCommand(std::move(source), std::move(destination),
144 destination_origin, std::move(label));
145}
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label)=0
SkBitmap source
Definition examples.cpp:28
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:448
static size_t bytes_per_pixel(skcms_PixelFormat fmt)
Definition skcms.cc:2449
#define VALIDATION_LOG
Definition validation.h:73

◆ AddCopy() [2/3]

bool impeller::BlitPass::AddCopy ( std::shared_ptr< Texture source,
std::shared_ptr< DeviceBuffer destination,
std::optional< IRect source_region = std::nullopt,
size_t  destination_offset = 0,
std::string  label = "" 
)

Record a command to copy the contents of the buffer to the texture. No work is encoded into the command buffer at this time.

Parameters
[in]sourceThe texture to read for copying.
[in]destinationThe buffer to overwrite using the source contents.
[in]source_regionThe optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
[in]destination_originThe origin to start writing to in the destination texture.
[in]labelThe optional debug label to give the command.
Returns
If the command was valid for subsequent commitment.

Definition at line 83 of file blit_pass.cc.

87 {
88 if (!source) {
89 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
90 return false;
91 }
92 if (!destination) {
93 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
94 return false;
95 }
96
97 if (!source_region.has_value()) {
98 source_region = IRect::MakeSize(source->GetSize());
99 }
100
101 auto bytes_per_pixel =
102 BytesPerPixelForPixelFormat(source->GetTextureDescriptor().format);
103 auto bytes_per_image = source_region->Area() * bytes_per_pixel;
104 if (destination_offset + bytes_per_image >
105 destination->GetDeviceBufferDescriptor().size) {
107 << "Attempted to add a texture blit with out of bounds access.";
108 return false;
109 }
110
111 // Clip the source image.
112 source_region =
113 source_region->Intersection(IRect::MakeSize(source->GetSize()));
114 if (!source_region.has_value()) {
115 return true; // Nothing to blit.
116 }
117
118 return OnCopyTextureToBufferCommand(std::move(source), std::move(destination),
119 source_region.value(), destination_offset,
120 std::move(label));
121}
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

◆ AddCopy() [3/3]

bool impeller::BlitPass::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 the intersection of the texture coverage with respect the source region and destination origin. No work is encoded into the command buffer at this time.

Parameters
[in]sourceThe texture to read for copying.
[in]destinationThe texture to overwrite using the source contents.
[in]source_regionThe optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
[in]destination_originThe origin to start writing to in the destination texture.
[in]labelThe optional debug label to give the command.
Returns
If the command was valid for subsequent commitment.

Definition at line 26 of file blit_pass.cc.

30 {
31 if (!source) {
32 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
33 return false;
34 }
35 if (!destination) {
36 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
37 return false;
38 }
39
40 if (source->GetTextureDescriptor().sample_count !=
41 destination->GetTextureDescriptor().sample_count) {
43 "The source sample count (%d) must match the destination sample count "
44 "(%d) for blits.",
45 static_cast<int>(source->GetTextureDescriptor().sample_count),
46 static_cast<int>(destination->GetTextureDescriptor().sample_count));
47 return false;
48 }
49 if (source->GetTextureDescriptor().format !=
50 destination->GetTextureDescriptor().format) {
52 "The source pixel format (%s) must match the destination pixel format "
53 "(%s) "
54 "for blits.",
55 PixelFormatToString(source->GetTextureDescriptor().format),
56 PixelFormatToString(destination->GetTextureDescriptor().format));
57 return false;
58 }
59
60 if (!source_region.has_value()) {
61 source_region = IRect::MakeSize(source->GetSize());
62 }
63
64 // Clip the source image.
65 source_region =
66 source_region->Intersection(IRect::MakeSize(source->GetSize()));
67 if (!source_region.has_value()) {
68 return true; // Nothing to blit.
69 }
70
71 // Clip the destination image.
72 source_region = source_region->Intersection(
73 IRect::MakeOriginSize(-destination_origin, destination->GetSize()));
74 if (!source_region.has_value()) {
75 return true; // Nothing to blit.
76 }
77
79 std::move(source), std::move(destination), source_region.value(),
80 destination_origin, std::move(label));
81}
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
std::string SPrintF(const char *format,...)
Definition strings.cc:12
constexpr const char * PixelFormatToString(PixelFormat format)
Definition formats.h:141
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition rect.h:140

◆ EncodeCommands()

virtual bool impeller::BlitPass::EncodeCommands ( const std::shared_ptr< Allocator > &  transients_allocator) const
pure virtual

Encode the recorded commands to the underlying command buffer.

Parameters
transients_allocatorThe transients allocator.
Returns
If the commands were encoded to the underlying command buffer.

Implemented in impeller::BlitPassGLES, impeller::BlitPassMTL, and impeller::BlitPassVK.

◆ GenerateMipmap()

bool impeller::BlitPass::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 at this time.

Parameters
[in]textureThe texture to generate mipmaps for.
[in]labelThe optional debug label to give the command.
Returns
If the command was valid for subsequent commitment.

Definition at line 147 of file blit_pass.cc.

148 {
149 if (!texture) {
150 VALIDATION_LOG << "Attempted to add an invalid mipmap generation command "
151 "with no texture.";
152 return false;
153 }
154
155 return OnGenerateMipmapCommand(std::move(texture), std::move(label));
156}
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string label)=0
FlTexture * texture

◆ IsValid()

virtual bool impeller::BlitPass::IsValid ( ) const
pure virtual

◆ OnCopyBufferToTextureCommand()

virtual bool impeller::BlitPass::OnCopyBufferToTextureCommand ( BufferView  source,
std::shared_ptr< Texture destination,
IPoint  destination_origin,
std::string  label 
)
protectedpure virtual

◆ OnCopyTextureToBufferCommand()

virtual bool impeller::BlitPass::OnCopyTextureToBufferCommand ( std::shared_ptr< Texture source,
std::shared_ptr< DeviceBuffer destination,
IRect  source_region,
size_t  destination_offset,
std::string  label 
)
protectedpure virtual

◆ OnCopyTextureToTextureCommand()

virtual bool impeller::BlitPass::OnCopyTextureToTextureCommand ( std::shared_ptr< Texture source,
std::shared_ptr< Texture destination,
IRect  source_region,
IPoint  destination_origin,
std::string  label 
)
protectedpure virtual

◆ OnGenerateMipmapCommand()

virtual bool impeller::BlitPass::OnGenerateMipmapCommand ( std::shared_ptr< Texture texture,
std::string  label 
)
protectedpure virtual

◆ OnSetLabel()

virtual void impeller::BlitPass::OnSetLabel ( std::string  label)
protectedpure virtual

◆ SetLabel()

void impeller::BlitPass::SetLabel ( std::string  label)

Definition at line 19 of file blit_pass.cc.

19 {
20 if (label.empty()) {
21 return;
22 }
23 OnSetLabel(std::move(label));
24}
virtual void OnSetLabel(std::string label)=0

The documentation for this class was generated from the following files: