Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::TextureGLES Class Referencefinal

#include <texture_gles.h>

Inheritance diagram for impeller::TextureGLES:
impeller::Texture impeller::BackendCast< TextureGLES, Texture >

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.
 
std::optional< GLuint > GetFBO () const
 
void MarkContentsInitialized ()
 Indicates that all texture storage has already been allocated and contents initialized.
 
void MarkSliceInitialized (size_t slice) const
 Indicates that a specific texture slice has been initialized.
 
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.
 
void SetCachedFBO (HandleGLES fbo)
 
const HandleGLESGetCachedFBO () const
 Retrieve the cached FBO object, or a dead handle if there is no object.
 
std::optional< HandleGLESGetSyncFence () 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 TextureDescriptorGetTextureDescriptor () const
 
void SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
 
TextureCoordinateSystem GetCoordinateSystem () const
 
bool NeedsMipmapGeneration () const
 

Static Public Member Functions

static std::shared_ptr< TextureGLESWrapFBO (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.
 
static std::shared_ptr< TextureGLESWrapTexture (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.
 
static std::shared_ptr< TextureGLESCreatePlaceholder (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.
 
- Static Public Member Functions inherited from impeller::BackendCast< TextureGLES, Texture >
static TextureGLESCast (Texture &base)
 
static const TextureGLESCast (const Texture &base)
 
static TextureGLESCast (Texture *base)
 
static const TextureGLESCast (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

Enumerator
kColor0 
kDepth 
kStencil 

Definition at line 94 of file texture_gles.h.

◆ Type

enum class impeller::TextureGLES::Type
strong
Enumerator
kTexture 
kTextureMultisampled 
kRenderBuffer 
kRenderBufferMultisampled 

Definition at line 21 of file texture_gles.h.

Constructor & Destructor Documentation

◆ TextureGLES()

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

Definition at line 191 of file texture_gles.cc.

194 : TextureGLES(std::move(reactor), //
195 desc, //
196 threadsafe, //
197 std::nullopt, //
198 std::nullopt //
199 ) {}
TextureGLES(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, bool threadsafe=false)

◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES ( )
override

Definition at line 237 of file texture_gles.cc.

237 {
238 reactor_->CollectHandle(handle_);
239 if (!cached_fbo_.IsDead()) {
240 reactor_->CollectHandle(cached_fbo_);
241 }
242}
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 522 of file texture_gles.cc.

522 {
523 auto handle = GetGLHandle();
524 if (!handle.has_value()) {
525 return false;
526 }
527 const auto& gl = reactor_->GetProcTable();
528
529 if (fence_.has_value()) {
530 std::optional<GLsync> fence = reactor_->GetGLFence(fence_.value());
531 if (fence.has_value()) {
532 gl.WaitSync(fence.value(), 0, GL_TIMEOUT_IGNORED);
533 }
534 reactor_->CollectHandle(fence_.value());
535 fence_ = std::nullopt;
536 }
537
538 switch (type_) {
539 case Type::kTexture:
542 if (!target.has_value()) {
543 VALIDATION_LOG << "Could not bind texture of this type.";
544 return false;
545 }
546 gl.BindTexture(target.value(), handle.value());
547 } break;
550 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
551 break;
552 }
553 InitializeContentsIfNecessary();
554 return true;
555}
GLenum type
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
uint32_t * target
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
#define VALIDATION_LOG
Definition validation.h:91

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

Referenced by GenerateMipmap().

◆ ComputeTypeForBinding()

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

Definition at line 416 of file texture_gles.cc.

416 {
417 // When binding to a GL_READ_FRAMEBUFFER, any multisampled
418 // textures must be bound as single sampled.
419 if (target == GL_READ_FRAMEBUFFER && type_ == Type::kTextureMultisampled) {
420 return Type::kTexture;
421 }
422 return type_;
423}

References kTexture, kTextureMultisampled, and target.

Referenced by SetAsFramebufferAttachment(), and impeller::testing::TEST_P().

◆ 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]reactorThe reactor
[in]descThe description
Returns
If a texture placeholder could be created.

Definition at line 185 of file texture_gles.cc.

187 {
188 return TextureGLES::WrapFBO(std::move(reactor), desc, 0u);
189}
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.

References WrapFBO().

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

◆ GenerateMipmap()

bool impeller::TextureGLES::GenerateMipmap ( )

Definition at line 571 of file texture_gles.cc.

571 {
572 if (!IsValid()) {
573 return false;
574 }
575
577 switch (type) {
579 break;
581 VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
582 "supported in the GLES backend.";
583 return false;
585 break;
587 break;
588 }
589
590 if (!Bind()) {
591 return false;
592 }
593
594 auto handle = GetGLHandle();
595 if (!handle.has_value()) {
596 return false;
597 }
598
599 const auto& gl = reactor_->GetProcTable();
600 gl.GenerateMipmap(ToTextureType(type));
601 mipmap_generated_ = true;
602 return true;
603}
bool IsValid() const override
bool mipmap_generated_
Definition texture.h:79
constexpr GLenum ToTextureType(TextureType type)

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 699 of file texture_gles.cc.

699 {
700 return cached_fbo_;
701}

Referenced by impeller::EncodeCommandsInReactor().

◆ GetFBO()

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

Definition at line 681 of file texture_gles.cc.

681 {
682 return wrapped_fbo_;
683}

Referenced by impeller::EncodeCommandsInReactor().

◆ GetGLHandle()

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

Definition at line 515 of file texture_gles.cc.

515 {
516 if (!IsValid()) {
517 return std::nullopt;
518 }
519 return reactor_->GetGLHandle(handle_);
520}

References IsValid().

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

◆ GetSyncFence()

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

Definition at line 691 of file texture_gles.cc.

691 {
692 return fence_;
693}

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

◆ GetType()

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

Definition at line 605 of file texture_gles.cc.

605 {
606 return type_;
607}

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

◆ IsSliceInitialized()

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

Definition at line 567 of file texture_gles.cc.

567 {
568 return slices_initialized_[slice];
569}

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

◆ IsValid()

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

Implements impeller::Texture.

Definition at line 249 of file texture_gles.cc.

249 {
250 return is_valid_;
251}

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

◆ IsWrapped()

bool impeller::TextureGLES::IsWrapped ( ) const

Definition at line 677 of file texture_gles.cc.

677 {
678 return is_wrapped_;
679}

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 244 of file texture_gles.cc.

244 {
245 handle_ = HandleGLES::DeadHandle();
246}
static HandleGLES DeadHandle()
Creates a dead handle.
Definition handle_gles.h:44

References impeller::HandleGLES::DeadHandle().

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

◆ 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 557 of file texture_gles.cc.

557 {
558 for (size_t i = 0; i < slices_initialized_.size(); i++) {
559 slices_initialized_[i] = true;
560 }
561}

References i.

◆ MarkSliceInitialized()

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

Indicates that a specific texture slice has been initialized.

Parameters
[in]sliceThe slice to mark as being initialized.

Definition at line 563 of file texture_gles.cc.

563 {
564 slices_initialized_[slice] = true;
565}

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

◆ SetAsFramebufferAttachment()

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

Definition at line 620 of file texture_gles.cc.

622 {
623 if (!IsValid()) {
624 return false;
625 }
626 InitializeContentsIfNecessary();
627 auto handle = GetGLHandle();
628 if (!handle.has_value()) {
629 return false;
630 }
631 const auto& gl = reactor_->GetProcTable();
632
633 switch (ComputeTypeForBinding(target)) {
634 case Type::kTexture:
635 gl.FramebufferTexture2D(target, // target
636 ToAttachmentType(attachment_type), // attachment
637 GL_TEXTURE_2D, // textarget
638 handle.value(), // texture
639 0 // level
640 );
641 break;
643 gl.FramebufferTexture2DMultisampleEXT(
644 target, // target
645 ToAttachmentType(attachment_type), // attachment
646 GL_TEXTURE_2D, // textarget
647 handle.value(), // texture
648 0, // level
649 4 // samples
650 );
651 break;
654 gl.FramebufferRenderbuffer(
655 target, // target
656 ToAttachmentType(attachment_type), // attachment
657 GL_RENDERBUFFER, // render-buffer target
658 handle.value() // render-buffer
659 );
660 break;
661 }
662
663 return true;
664}
Type ComputeTypeForBinding(GLenum target) const
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)

References ComputeTypeForBinding(), GetGLHandle(), IsValid(), kRenderBuffer, kRenderBufferMultisampled, kTexture, kTextureMultisampled, target, 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 695 of file texture_gles.cc.

695 {
696 cached_fbo_ = fbo;
697}

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]fenceA handle to a sync fence.

Definition at line 685 of file texture_gles.cc.

685 {
686 FML_DCHECK(!fence_.has_value());
687 fence_ = fence;
688}
#define FML_DCHECK(condition)
Definition logging.h:122

References FML_DCHECK.

◆ 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]reactorThe reactor
[in]descThe description
[in]fboThe fbo
Returns
If a texture representation of the framebuffer could be created.

Definition at line 153 of file texture_gles.cc.

156 {
157 auto texture = std::shared_ptr<TextureGLES>(
158 new TextureGLES(std::move(reactor), desc, false, fbo, std::nullopt));
159 if (!texture->IsValid()) {
160 return nullptr;
161 }
162 return texture;
163}
FlTexture * texture

References texture.

Referenced by CreatePlaceholder(), MakeRenderTargetFromBackingStoreImpeller(), impeller::testing::TEST_P(), 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]reactorThe reactor
[in]descThe description
[in]external_handleThe external handle
Returns
If a texture representation of the framebuffer could be created.

Definition at line 165 of file texture_gles.cc.

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

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

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


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