| Flutter Impeller |

Public Member Functions | Protected Member Functions | Protected Attributes | 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:

## Public Member Functions
virtual | ~BlitPass ()
virtual bool | IsValid () const =0
void | SetLabel (std::string label)
HostBuffer & | GetTransientsBuffer ()
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. More...
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. More...
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. More...
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. More...
virtual bool | EncodeCommands (const std::shared_ptr< Allocator > &transients_allocator) const =0
| Encode the recorded commands to the underlying command buffer. More...

## 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

## Protected Attributes
std::shared_ptr< HostBuffer > | transients_buffer_

## 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 27 of file blit_pass.h.

## Constructor & Destructor Documentation

## ◆ ~BlitPass()

impeller::BlitPass::~BlitPass | ( |  | ) |
| virtual default

## ◆ BlitPass()

impeller::BlitPass::BlitPass | ( |  | ) |
| explicit protected

Definition at line 16 of file blit_pass.cc.

16 : transients_buffer_(HostBuffer::Create()) {}

## 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] | source | The buffer view to read for copying.
  [in] | destination | The texture to overwrite using the source contents.
  [in] | destination_offset | The offset to start writing to in the destination buffer.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 119 of file blit_pass.cc.

122 {
123 if (!destination) {
124 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
125 return false;
126 }
127
128 auto bytes_per_pixel =
129 BytesPerPixelForPixelFormat(destination->GetTextureDescriptor().format);
130 auto bytes_per_image =
131 destination->GetTextureDescriptor().size.Area() * bytes_per_pixel;
132
133 if (source.range.length != bytes_per_image) {
134 VALIDATION_LOG
135 << "Attempted to add a texture blit with out of bounds access.";
136 return false;
137 }
138
139 return OnCopyBufferToTextureCommand(std::move(source), std::move(destination),
140 destination_origin, std::move(label));
141 }

References impeller::BytesPerPixelForPixelFormat(), impeller::Range::length, OnCopyBufferToTextureCommand(), impeller::BufferView::range, and VALIDATION_LOG.

## ◆ 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] | source | The texture to read for copying.
  [in] | destination | The buffer to overwrite using the source contents.
  [in] | source_region | The optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
  [in] | destination_origin | The origin to start writing to in the destination texture.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 79 of file blit_pass.cc.

83 {
84 if (!source) {
85 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
86 return false;
87 }
88 if (!destination) {
89 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
90 return false;
91 }
92
93 if (!source_region.has_value()) {
94 source_region = IRect::MakeSize(source->GetSize());
95 }
96
97 auto bytes_per_pixel =
98 BytesPerPixelForPixelFormat(source->GetTextureDescriptor().format);
99 auto bytes_per_image = source_region->size.Area() * bytes_per_pixel;
100 if (destination_offset + bytes_per_image >
101 destination->GetDeviceBufferDescriptor().size) {
102 VALIDATION_LOG
103 << "Attempted to add a texture blit with out of bounds access.";
104 return false;
105 }
106
107 // Clip the source image.
108 source_region =
109 source_region->Intersection(IRect::MakeSize(source->GetSize()));
110 if (!source_region.has_value()) {
111 return true; // Nothing to blit.
112 }
113
114 return OnCopyTextureToBufferCommand(std::move(source), std::move(destination),
115 source_region.value(), destination_offset,
116 std::move(label));
117 }

References impeller::BytesPerPixelForPixelFormat(), impeller::TRect< int64_t >::MakeSize(), OnCopyTextureToBufferCommand(), and VALIDATION_LOG.

## ◆ 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] | source | The texture to read for copying.
  [in] | destination | The texture to overwrite using the source contents.
  [in] | source_region | The optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
  [in] | destination_origin | The origin to start writing to in the destination texture.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 32 of file blit_pass.cc.

36 {
37 if (!source) {
38 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
39 return false;
40 }
41 if (!destination) {
42 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
43 return false;
44 }
45
46 if (source->GetTextureDescriptor().sample_count !=
47 destination->GetTextureDescriptor().sample_count) {
48 VALIDATION_LOG << SPrintF(
49 "The source sample count (%d) must match the destination sample count "
50 "(%d) for blits.",
51 static_cast<int>(source->GetTextureDescriptor().sample_count),
52 static_cast<int>(destination->GetTextureDescriptor().sample_count));
53 return false;
54 }
55
56 if (!source_region.has_value()) {
57 source_region = IRect::MakeSize(source->GetSize());
58 }
59
60 // Clip the source image.
61 source_region =
62 source_region->Intersection(IRect::MakeSize(source->GetSize()));
63 if (!source_region.has_value()) {
64 return true; // Nothing to blit.
65 }
66
67 // Clip the destination image.
68 source_region = source_region->Intersection(
69 IRect(-destination_origin, destination->GetSize()));
70 if (!source_region.has_value()) {
71 return true; // Nothing to blit.
72 }
73
74 return OnCopyTextureToTextureCommand(
75 std::move(source), std::move(destination), source_region.value(),
76 destination_origin, std::move(label));
77 }

References impeller::TRect< int64_t >::MakeSize(), OnCopyTextureToTextureCommand(), impeller::SPrintF(), and VALIDATION_LOG.

## ◆ 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_allocator | The transients allocator.

Returns
  If the commands were encoded to the underlying command buffer.

## ◆ 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] | texture | The texture to generate mipmaps for.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 143 of file blit_pass.cc.

144 {
145 if (!texture) {
146 VALIDATION_LOG << "Attempted to add an invalid mipmap generation command "
147 "with no texture.";
148 return false;
149 }
150
151 return OnGenerateMipmapCommand(std::move(texture), std::move(label));
152 }

References OnGenerateMipmapCommand(), and VALIDATION_LOG.

## ◆ GetTransientsBuffer()

HostBuffer & impeller::BlitPass::GetTransientsBuffer | ( |  | ) |

Definition at line 20 of file blit_pass.cc.

20 {
21 return *transients_buffer_;
22 }

References transients_buffer_.

## ◆ 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
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ 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
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ 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
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ OnGenerateMipmapCommand()

virtual bool impeller::BlitPass::OnGenerateMipmapCommand | ( | std::shared_ptr< Texture > | texture,
|  | std::string | label
| ) |  |
| protected pure virtual

Referenced by GenerateMipmap().

## ◆ OnSetLabel()

virtual void impeller::BlitPass::OnSetLabel | ( | std::string | label | ) |
| protected pure virtual

Referenced by SetLabel().

## ◆ SetLabel()

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

Definition at line 24 of file blit_pass.cc.

24 {
25 if (label.empty()) {
26 return;
27 }
28 transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
29 OnSetLabel(std::move(label));
30 }

References OnSetLabel(), impeller::SPrintF(), and transients_buffer_.

## Member Data Documentation

## ◆ transients_buffer_

std::shared_ptr<HostBuffer> impeller::BlitPass::transients_buffer_
| protected

Definition at line 130 of file blit_pass.h.

Referenced by GetTransientsBuffer(), and SetLabel().

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

- impeller/renderer/blit_pass.h
- impeller/renderer/blit_pass.cc

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
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::OnCopyBufferToTextureCommand
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label)=0
impeller::HostBuffer::Create
static std::shared_ptr< HostBuffer > Create()
Definition: host_buffer.cc:18
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:399
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
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::IRect
TRect< int64_t > IRect
Definition: rect.h:307
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::BlitPass::transients_buffer_
std::shared_ptr< HostBuffer > transients_buffer_
Definition: blit_pass.h:130
impeller::TRect< int64_t >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:52