| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::TextureGLES Class Referencefinal

`#include <texture_gles.h>`

Inheritance diagram for impeller::TextureGLES:

## Public Types
enum class | Type { kTexture , kTextureMultisampled , kRenderBuffer , kRenderBufferMultisampled }
enum class | AttachmentType { kColor0 , kDepth , kStencil }

## Public Member Functions
| TextureGLES (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, bool threadsafe=false)
| ~TextureGLES () override
bool | IsValid () const override
std::optional< GLuint > | GetGLHandle () const
bool | Bind () const
bool | GenerateMipmap ()
bool | SetAsFramebufferAttachment (GLenum target, AttachmentType attachment_type) const
Type | GetType () const
bool | IsWrapped () const
void | Leak ()
| Reset the internal texture state so that the reactor will not free the associated handle. More...
std::optional< GLuint > | GetFBO () const
void | MarkContentsInitialized ()
| Indicates that all texture storage has already been allocated and contents initialized. More...
void | MarkSliceInitialized (size_t slice) const
| Indicates that a specific texture slice has been initialized. More...
bool | IsSliceInitialized (size_t slice) const
void | SetFence (HandleGLES fence)
| Attach a sync fence to this texture that will be waited on before encoding a rendering operation that references it. More...
void | SetCachedFBO (HandleGLES fbo)
const HandleGLES & | GetCachedFBO () const
| Retrieve the cached FBO object, or a dead handle if there is no object. More...
std::optional< HandleGLES > | GetSyncFence () const
Type | ComputeTypeForBinding (GLenum target) const
Public Member Functions inherited from impeller::Texture
virtual | ~Texture ()
bool | SetContents (const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
bool | SetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice=0, bool is_opaque=false)
bool | IsOpaque () const
size_t | GetMipCount () const
const TextureDescriptor & | GetTextureDescriptor () const
void | SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
TextureCoordinateSystem | GetCoordinateSystem () const
bool | NeedsMipmapGeneration () const

## Static Public Member Functions
static std::shared_ptr< TextureGLES > | WrapFBO (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
| Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller. More...
static std::shared_ptr< TextureGLES > | WrapTexture (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
| Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is assumed by the reactor. More...
static std::shared_ptr< TextureGLES > | CreatePlaceholder (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
| Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way. It only exists to setup a render pass description. More...
Static Public Member Functions inherited from impeller::BackendCast< TextureGLES, Texture >
static TextureGLES & | Cast (Texture &base)
static const TextureGLES & | Cast (const Texture &base)
static TextureGLES * | Cast (Texture *base)
static const TextureGLES * | Cast (const Texture *base)

## Additional Inherited Members
Protected Member Functions inherited from impeller::Texture
| Texture (TextureDescriptor desc)
Protected Attributes inherited from impeller::Texture
bool | mipmap_generated_ = false

## Detailed Description

Definition at line 18 of file texture_gles.h.

## Member Enumeration Documentation

## ◆ AttachmentType

enum impeller::TextureGLES::AttachmentType
| strong

Enumerator
kColor0 |
kDepth |
kStencil |

Definition at line 94 of file texture_gles.h.

94 {
95 kColor0,
96 kDepth,
97 kStencil,
98 };

## ◆ Type

enum impeller::TextureGLES::Type
| strong

Enumerator
kTexture |
kTextureMultisampled |
kRenderBuffer |
kRenderBufferMultisampled |

Definition at line 21 of file texture_gles.h.

21 {
22 kTexture,
23 kTextureMultisampled,
24 kRenderBuffer,
25 kRenderBufferMultisampled,
26 };
impeller::HandleType::kTexture
@ kTexture
impeller::HandleType::kRenderBuffer
@ kRenderBuffer

## Constructor & Destructor Documentation

## ◆ TextureGLES()

impeller::TextureGLES::TextureGLES | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc,
|  | bool | threadsafe = `false`
| ) |  |

Definition at line 185 of file texture_gles.cc.

188 : TextureGLES(std::move(reactor), //
189 desc, //
190 threadsafe, //
191 std::nullopt, //
192 std::nullopt //
193 ) {}
impeller::TextureGLES::TextureGLES
TextureGLES(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, bool threadsafe=false)
Definition: texture_gles.cc:185

Referenced by WrapFBO(), and WrapTexture().

## ◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES | ( |  | ) |
| override

Definition at line 231 of file texture_gles.cc.

231 {
232 reactor_->CollectHandle(handle_);
233 if (!cached_fbo_.IsDead()) {
234 reactor_->CollectHandle(cached_fbo_);
235 }
236 }
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Determines if the handle is dead.
Definition: handle_gles.h:53

References impeller::HandleGLES::IsDead().

## Member Function Documentation

## ◆ Bind()

bool impeller::TextureGLES::Bind | ( |  | ) | const

Definition at line 516 of file texture_gles.cc.

516 {
517 auto handle = GetGLHandle();
518 if (!handle.has_value()) {
519 return false;
520 }
521 const auto& gl = reactor_->GetProcTable();
522
523 if (fence_.has_value()) {
524 std::optional<GLsync> fence = reactor_->GetGLFence(fence_.value());
525 if (fence.has_value()) {
526 gl.WaitSync(fence.value(), 0, GL_TIMEOUT_IGNORED);
527 }
528 reactor_->CollectHandle(fence_.value());
529 fence_ = std::nullopt;
530 }
531
532 switch (type_) {
533 case Type::kTexture:
534 case Type::kTextureMultisampled: {
535 const auto target = ToTextureTarget(GetTextureDescriptor().type);
536 if (!target.has_value()) {
537 VALIDATION_LOG << "Could not bind texture of this type.";
538 return false;
539 }
540 gl.BindTexture(target.value(), handle.value());
541 } break;
542 case Type::kRenderBuffer:
543 case Type::kRenderBufferMultisampled:
544 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
545 break;
546 }
547 InitializeContentsIfNecessary();
548 return true;
549 }
impeller::TextureGLES::Type::kTexture
@ kTexture
impeller::TextureGLES::Type::kRenderBuffer
@ kRenderBuffer
impeller::TextureGLES::Type::kTextureMultisampled
@ kTextureMultisampled
impeller::TextureGLES::Type::kRenderBufferMultisampled
@ kRenderBufferMultisampled
impeller::TextureGLES::GetGLHandle
std::optional< GLuint > GetGLHandle() const
Definition: texture_gles.cc:509
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:185
type
GLenum type
Definition: texture_gles.cc:67
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References GetGLHandle(), impeller::Texture::GetTextureDescriptor(), kRenderBuffer, kRenderBufferMultisampled, kTexture, kTextureMultisampled, impeller::ToTextureTarget(), type, and VALIDATION_LOG.

Referenced by GenerateMipmap().

## ◆ ComputeTypeForBinding()

TextureGLES::Type impeller::TextureGLES::ComputeTypeForBinding | ( | GLenum | target | ) | const

Definition at line 410 of file texture_gles.cc.

410 {
411 // When binding to a GL_READ_FRAMEBUFFER, any multisampled
412 // textures must be bound as single sampled.
413 if (target == GL_READ_FRAMEBUFFER && type_ == Type::kTextureMultisampled) {
414 return Type::kTexture;
415 }
416 return type_;
417 }

References kTexture, and kTextureMultisampled.

Referenced by SetAsFramebufferAttachment().

## ◆ CreatePlaceholder()

std::shared_ptr< TextureGLES > impeller::TextureGLES::CreatePlaceholder | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc
| ) |  |
| static

Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way. It only exists to setup a render pass description.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description

Returns
  If a texture placeholder could be created.

Definition at line 179 of file texture_gles.cc.

181 {
182 return TextureGLES::WrapFBO(std::move(reactor), desc, 0u);
183 }
impeller::TextureGLES::WrapFBO
static std::shared_ptr< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
Definition: texture_gles.cc:147

References WrapFBO().

Referenced by impeller::SurfaceGLES::WrapFBO().

## ◆ GenerateMipmap()

bool impeller::TextureGLES::GenerateMipmap | ( |  | ) |

Definition at line 565 of file texture_gles.cc.

565 {
566 if (!IsValid()) {
567 return false;
568 }
569
570 auto type = GetTextureDescriptor().type;
571 switch (type) {
572 case TextureType::kTexture2D:
573 break;
574 case TextureType::kTexture2DMultisample:
575 VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
576 "supported in the GLES backend.";
577 return false;
578 case TextureType::kTextureCube:
579 break;
580 case TextureType::kTextureExternalOES:
581 break;
582 }
583
584 if (!Bind()) {
585 return false;
586 }
587
588 auto handle = GetGLHandle();
589 if (!handle.has_value()) {
590 return false;
591 }
592
593 const auto& gl = reactor_->GetProcTable();
594 gl.GenerateMipmap(ToTextureType(type));
595 mipmap_generated_ = true;
596 return true;
597 }
impeller::TextureGLES::Bind
bool Bind() const
Definition: texture_gles.cc:516
impeller::TextureGLES::IsValid
bool IsValid() const override
Definition: texture_gles.cc:243
impeller::Texture::mipmap_generated_
bool mipmap_generated_
Definition: texture.h:79
impeller::ToTextureType
constexpr GLenum ToTextureType(TextureType type)
Definition: formats_gles.h:171
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:40

References Bind(), GetGLHandle(), impeller::Texture::GetTextureDescriptor(), IsValid(), impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::Texture::mipmap_generated_, impeller::ToTextureType(), impeller::TextureDescriptor::type, type, and VALIDATION_LOG.

## ◆ GetCachedFBO()

const HandleGLES & impeller::TextureGLES::GetCachedFBO | ( |  | ) | const

Retrieve the cached FBO object, or a dead handle if there is no object.

Definition at line 693 of file texture_gles.cc.

693 {
694 return cached_fbo_;
695 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ GetFBO()

std::optional< GLuint > impeller::TextureGLES::GetFBO | ( |  | ) | const

Definition at line 675 of file texture_gles.cc.

675 {
676 return wrapped_fbo_;
677 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ GetGLHandle()

std::optional< GLuint > impeller::TextureGLES::GetGLHandle | ( |  | ) | const

Definition at line 509 of file texture_gles.cc.

509 {
510 if (!IsValid()) {
511 return std::nullopt;
512 }
513 return reactor_->GetGLHandle(handle_);
514 }

References IsValid().

Referenced by Bind(), impeller::ConfigureFBO(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), GenerateMipmap(), impeller::interop::ImpellerTextureGetOpenGLHandle(), and SetAsFramebufferAttachment().

## ◆ GetSyncFence()

std::optional< HandleGLES > impeller::TextureGLES::GetSyncFence | ( |  | ) | const

Definition at line 685 of file texture_gles.cc.

685 {
686 return fence_;
687 }

## ◆ GetType()

TextureGLES::Type impeller::TextureGLES::GetType | ( |  | ) | const

Definition at line 599 of file texture_gles.cc.

599 {
600 return type_;
601 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ IsSliceInitialized()

bool impeller::TextureGLES::IsSliceInitialized | ( | size_t | slice | ) | const

Definition at line 561 of file texture_gles.cc.

561 {
562 return slices_initialized_[slice];
563 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ IsValid()

bool impeller::TextureGLES::IsValid | ( |  | ) | const
| overridevirtual

Implements impeller::Texture.

Definition at line 243 of file texture_gles.cc.

243 {
244 return is_valid_;
245 }

Referenced by GenerateMipmap(), GetGLHandle(), and SetAsFramebufferAttachment().

## ◆ IsWrapped()

bool impeller::TextureGLES::IsWrapped | ( |  | ) | const

Definition at line 671 of file texture_gles.cc.

671 {
672 return is_wrapped_;
673 }

Referenced by impeller::ConfigureFBO(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), and impeller::EncodeCommandsInReactor().

## ◆ Leak()

void impeller::TextureGLES::Leak | ( |  | ) |

Reset the internal texture state so that the reactor will not free the associated handle.

Definition at line 238 of file texture_gles.cc.

238 {
239 handle_ = HandleGLES::DeadHandle();
240 }
impeller::HandleGLES::DeadHandle
static HandleGLES DeadHandle()
Creates a dead handle.
Definition: handle_gles.h:44

References impeller::HandleGLES::DeadHandle().

## ◆ MarkContentsInitialized()

void impeller::TextureGLES::MarkContentsInitialized | ( |  | ) |

Indicates that all texture storage has already been allocated and contents initialized.

This is similar to calling `MarkSliceInitialized` with all slices.

See also
  MarkSliceInitialized.

Definition at line 551 of file texture_gles.cc.

551 {
552 for (size_t i = 0; i < slices_initialized_.size(); i++) {
553 slices_initialized_[i] = true;
554 }
555 }

## ◆ MarkSliceInitialized()

void impeller::TextureGLES::MarkSliceInitialized | ( | size_t | slice | ) | const

Indicates that a specific texture slice has been initialized.

Parameters

  [in] | slice | The slice to mark as being initialized.

Definition at line 557 of file texture_gles.cc.

557 {
558 slices_initialized_[slice] = true;
559 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ SetAsFramebufferAttachment()

bool impeller::TextureGLES::SetAsFramebufferAttachment | ( | GLenum | target,
|  | AttachmentType | attachment_type
| ) |  | const

Definition at line 614 of file texture_gles.cc.

616 {
617 if (!IsValid()) {
618 return false;
619 }
620 InitializeContentsIfNecessary();
621 auto handle = GetGLHandle();
622 if (!handle.has_value()) {
623 return false;
624 }
625 const auto& gl = reactor_->GetProcTable();
626
627 switch (ComputeTypeForBinding(target)) {
628 case Type::kTexture:
629 gl.FramebufferTexture2D(target, // target
630 ToAttachmentType(attachment_type), // attachment
631 GL_TEXTURE_2D, // textarget
632 handle.value(), // texture
633 0 // level
634 );
635 break;
636 case Type::kTextureMultisampled:
637 gl.FramebufferTexture2DMultisampleEXT(
638 target, // target
639 ToAttachmentType(attachment_type), // attachment
640 GL_TEXTURE_2D, // textarget
641 handle.value(), // texture
642 0, // level
643 4 // samples
644 );
645 break;
646 case Type::kRenderBuffer:
647 case Type::kRenderBufferMultisampled:
648 gl.FramebufferRenderbuffer(
649 target, // target
650 ToAttachmentType(attachment_type), // attachment
651 GL_RENDERBUFFER, // render-buffer target
652 handle.value() // render-buffer
653 );
654 break;
655 }
656
657 return true;
658 }
impeller::TextureGLES::ComputeTypeForBinding
Type ComputeTypeForBinding(GLenum target) const
Definition: texture_gles.cc:410
impeller::ToAttachmentType
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)
Definition: texture_gles.cc:603

References ComputeTypeForBinding(), GetGLHandle(), IsValid(), kRenderBuffer, kRenderBufferMultisampled, kTexture, kTextureMultisampled, and impeller::ToAttachmentType().

Referenced by impeller::ConfigureFBO(), and impeller::EncodeCommandsInReactor().

## ◆ SetCachedFBO()

void impeller::TextureGLES::SetCachedFBO | ( | HandleGLES | fbo | ) |

Store the FBO object for recycling in the 2D renderer.

The color0 texture used by the 2D renderer will use this texture object to store the associated FBO the first time it is used.

Definition at line 689 of file texture_gles.cc.

689 {
690 cached_fbo_ = fbo;
691 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ SetFence()

void impeller::TextureGLES::SetFence | ( | HandleGLES | fence | ) |

Attach a sync fence to this texture that will be waited on before encoding a rendering operation that references it.

Parameters

  [in] | fence | A handle to a sync fence.

Definition at line 679 of file texture_gles.cc.

679 {
680 FML_DCHECK(!fence_.has_value());
681 fence_ = fence;
682 }

## ◆ WrapFBO()

std::shared_ptr< TextureGLES > impeller::TextureGLES::WrapFBO | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc,
|  | GLuint | fbo
| ) |  |
| static

Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.

This is useful for creating a render target for the default window managed framebuffer.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description
  [in] | fbo | The fbo

Returns
  If a texture representation of the framebuffer could be created.

Definition at line 147 of file texture_gles.cc.

150 {
151 auto texture = std::shared_ptr<TextureGLES>(
152 new TextureGLES(std::move(reactor), desc, false, fbo, std::nullopt));
153 if (!texture->IsValid()) {
154 return nullptr;
155 }
156 return texture;
157 }

References TextureGLES().

Referenced by CreatePlaceholder(), and impeller::SurfaceGLES::WrapFBO().

## ◆ WrapTexture()

std::shared_ptr< TextureGLES > impeller::TextureGLES::WrapTexture | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc,
|  | HandleGLES | external_handle
| ) |  |
| static

Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is assumed by the reactor.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description
  [in] | external_handle | The external handle

Returns
  If a texture representation of the framebuffer could be created.

Definition at line 159 of file texture_gles.cc.

162 {
163 if (external_handle.IsDead()) {
164 VALIDATION_LOG << "Cannot wrap a dead handle.";
165 return nullptr;
166 }
167 if (external_handle.GetType() != HandleType::kTexture) {
168 VALIDATION_LOG << "Cannot wrap a non-texture handle.";
169 return nullptr;
170 }
171 auto texture = std::shared_ptr<TextureGLES>(new TextureGLES(
172 std::move(reactor), desc, false, std::nullopt, external_handle));
173 if (!texture->IsValid()) {
174 return nullptr;
175 }
176 return texture;
177 }

References impeller::HandleGLES::GetType(), impeller::HandleGLES::IsDead(), impeller::kTexture, TextureGLES(), and VALIDATION_LOG.

Referenced by impeller::interop::ImpellerTextureCreateWithOpenGLTextureHandleNew().

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

- impeller/renderer/backend/gles/texture_gles.h
- impeller/renderer/backend/gles/texture_gles.cc