Flutter Impeller
impeller::BlitCopyTextureToBufferCommandGLES Struct Reference

#include <blit_command_gles.h>

Inheritance diagram for impeller::BlitCopyTextureToBufferCommandGLES:
impeller::BlitEncodeGLES impeller::BlitCopyTextureToBufferCommand impeller::BackendCast< BlitEncodeGLES, BlitCommand > impeller::BlitCommand

Public Member Functions

 ~BlitCopyTextureToBufferCommandGLES () override
 
std::string GetLabel () const override
 
bool Encode (const ReactorGLES &reactor) const override
 
- Public Member Functions inherited from impeller::BlitEncodeGLES
virtual ~BlitEncodeGLES ()
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< BlitEncodeGLES, BlitCommand >
static BlitEncodeGLESCast (BlitCommand &base)
 
static const BlitEncodeGLESCast (const BlitCommand &base)
 
static BlitEncodeGLESCast (BlitCommand *base)
 
static const BlitEncodeGLESCast (const BlitCommand *base)
 
- Public Attributes inherited from impeller::BlitCopyTextureToBufferCommand
std::shared_ptr< Texturesource
 
std::shared_ptr< DeviceBufferdestination
 
IRect source_region
 
size_t destination_offset
 
- Public Attributes inherited from impeller::BlitCommand
std::string label
 

Detailed Description

Definition at line 43 of file blit_command_gles.h.

Constructor & Destructor Documentation

◆ ~BlitCopyTextureToBufferCommandGLES()

impeller::BlitCopyTextureToBufferCommandGLES::~BlitCopyTextureToBufferCommandGLES ( )
overridedefault

Member Function Documentation

◆ Encode()

bool impeller::BlitCopyTextureToBufferCommandGLES::Encode ( const ReactorGLES reactor) const
overridevirtual

Implements impeller::BlitEncodeGLES.

Definition at line 265 of file blit_command_gles.cc.

266  {
267  const auto& gl = reactor.GetProcTable();
268 
269  PixelFormat source_format = source->GetTextureDescriptor().format;
270  std::optional<PixelFormatGLES> gles_format =
271  ToPixelFormatGLES(source_format,
272  /*supports_bgra=*/
273  reactor.GetProcTable().GetDescription()->HasExtension(
274  "GL_EXT_texture_format_BGRA8888"));
275 
276  if (!gles_format.has_value()) {
277  VALIDATION_LOG << "Texture has unsupported pixel format.";
278  return false;
279  }
280 
281  TextureCoordinateSystem coord_system = source->GetCoordinateSystem();
282 
283  GLuint read_fbo = GL_NONE;
284  fml::ScopedCleanupClosure delete_fbos(
285  [&gl, &read_fbo]() { DeleteFBO(gl, read_fbo, GL_FRAMEBUFFER); });
286 
287  {
288  auto read = ConfigureFBO(gl, source, GL_FRAMEBUFFER);
289  if (!read.has_value()) {
290  return false;
291  }
292  read_fbo = read.value();
293  }
294 
297  [&gl, //
298  this, //
299  format = gles_format->external_format, //
300  type = gles_format->type, //
301  coord_system, //
302  bytes_per_pixel = BytesPerPixelForPixelFormat(source_format) //
303  ](uint8_t* data, size_t length) {
304  gl.ReadPixels(source_region.GetX(), source_region.GetY(),
306  format, type, data + destination_offset);
307  switch (coord_system) {
309  break;
311  // The texture is upside down, and must be inverted when copying
312  // byte data out.
313  FlipImage(data + destination_offset, source_region.GetWidth(),
314  source_region.GetHeight(), bytes_per_pixel);
315  }
316  });
317 
318  return true;
319 };
static DeviceBufferGLES & Cast(DeviceBuffer &base)
Definition: backend_cast.h:13
void UpdateBufferData(const std::function< void(uint8_t *, size_t length)> &update_buffer_data)
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:469
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
Definition: formats_gles.cc:26
static std::optional< GLuint > ConfigureFBO(const ProcTableGLES &gl, const std::shared_ptr< Texture > &texture, GLenum fbo_type)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
static void DeleteFBO(const ProcTableGLES &gl, GLuint fbo, GLenum type)
TextureCoordinateSystem
Definition: formats.h:330
std::shared_ptr< DeviceBuffer > destination
Definition: blit_command.h:33
std::shared_ptr< Texture > source
Definition: blit_command.h:32
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition: rect.h:337
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:347
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition: rect.h:333
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:341
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BytesPerPixelForPixelFormat(), impeller::BackendCast< DeviceBufferGLES, DeviceBuffer >::Cast(), impeller::ConfigureFBO(), impeller::DeleteFBO(), impeller::BlitCopyTextureToBufferCommand::destination, impeller::BlitCopyTextureToBufferCommand::destination_offset, impeller::ProcTableGLES::GetDescription(), impeller::TRect< T >::GetHeight(), impeller::ReactorGLES::GetProcTable(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::DescriptionGLES::HasExtension(), impeller::kRenderToTexture, impeller::kUploadFromHost, impeller::BlitCopyTextureToBufferCommand::source, impeller::BlitCopyTextureToBufferCommand::source_region, impeller::ToPixelFormatGLES(), impeller::DeviceBufferGLES::UpdateBufferData(), and VALIDATION_LOG.

Referenced by impeller::testing::TEST().

◆ GetLabel()

std::string impeller::BlitCopyTextureToBufferCommandGLES::GetLabel ( ) const
overridevirtual

Implements impeller::BlitEncodeGLES.

Definition at line 261 of file blit_command_gles.cc.

261  {
262  return label;
263 }

References impeller::BlitCommand::label.


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