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 ()
 
bool GenerateMipmap ()
 
bool SetAsFramebufferAttachment (GLenum target, AttachmentType attachment_type)
 
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)
 Indicates that a specific texture slice has been initialized.
 
bool IsSliceInitialized (size_t slice) const
 
void MarkSliceMipLevelInitialized (size_t slice, size_t mip_level)
 Indicates that storage for mip_level of slice has been allocated by a glTexImage2D call (or equivalent).
 
bool IsSliceMipLevelInitialized (size_t slice, size_t mip_level) 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 19 of file texture_gles.h.

Member Enumeration Documentation

◆ AttachmentType

Enumerator
kColor0 
kDepth 
kStencil 

Definition at line 95 of file texture_gles.h.

◆ Type

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

Definition at line 22 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 116 of file texture_gles.cc.

119 : TextureGLES(std::move(reactor), //
120 desc, //
121 threadsafe, //
122 std::nullopt, //
123 std::nullopt //
124 ) {}
TextureGLES(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, bool threadsafe=false)

◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES ( )
override

Definition at line 161 of file texture_gles.cc.

161 {
162 reactor_->CollectHandle(handle_);
163 if (!cached_fbo_.IsDead()) {
164 reactor_->CollectHandle(cached_fbo_);
165 }
166}
constexpr bool IsDead() const
Determines if the handle is dead.
Definition handle_gles.h:58

References impeller::HandleGLES::IsDead().

Member Function Documentation

◆ Bind()

bool impeller::TextureGLES::Bind ( )

Definition at line 490 of file texture_gles.cc.

490 {
491 auto handle = GetGLHandle();
492 if (!handle.has_value()) {
493 return false;
494 }
495 const auto& gl = reactor_->GetProcTable();
496
497 if (fence_.has_value()) {
498 std::optional<GLsync> fence = reactor_->GetGLFence(fence_.value());
499 if (fence.has_value()) {
500 gl.WaitSync(fence.value(), 0, GL_TIMEOUT_IGNORED);
501 }
502 reactor_->CollectHandle(fence_.value());
503 fence_ = std::nullopt;
504 }
505
506 switch (type_) {
507 case Type::kTexture:
510 if (!target.has_value()) {
511 VALIDATION_LOG << "Could not bind texture of this type.";
512 return false;
513 }
514 gl.BindTexture(target.value(), handle.value());
515 } break;
518 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
519 break;
520 }
521 InitializeContentsIfNecessary();
522 return true;
523}
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
uint32_t * target
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
impeller::ShaderType 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 346 of file texture_gles.cc.

346 {
347 // When binding to a GL_READ_FRAMEBUFFER, any multisampled
348 // textures must be bound as single sampled.
349 if (target == GL_READ_FRAMEBUFFER && type_ == Type::kTextureMultisampled) {
350 return Type::kTexture;
351 }
352 return type_;
353}

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

112 {
113 return TextureGLES::WrapFBO(std::move(reactor), desc, 0u);
114}
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 556 of file texture_gles.cc.

556 {
557 if (!IsValid()) {
558 return false;
559 }
560
562 switch (type) {
564 break;
566 VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
567 "supported in the GLES backend.";
568 return false;
570 break;
572 break;
573 }
574
575 if (!Bind()) {
576 return false;
577 }
578
579 auto handle = GetGLHandle();
580 if (!handle.has_value()) {
581 return false;
582 }
583
584 const auto& gl = reactor_->GetProcTable();
585 gl.GenerateMipmap(ToTextureType(type));
586 mipmap_generated_ = true;
587 return true;
588}
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 683 of file texture_gles.cc.

683 {
684 return cached_fbo_;
685}

Referenced by impeller::EncodeCommandsInReactor().

◆ GetFBO()

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

Definition at line 665 of file texture_gles.cc.

665 {
666 return wrapped_fbo_;
667}

Referenced by impeller::EncodeCommandsInReactor().

◆ GetGLHandle()

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

Definition at line 483 of file texture_gles.cc.

483 {
484 if (!IsValid()) {
485 return std::nullopt;
486 }
487 return reactor_->GetGLHandle(handle_);
488}

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

675 {
676 return fence_;
677}

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

◆ GetType()

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

Definition at line 590 of file texture_gles.cc.

590 {
591 return type_;
592}

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

◆ IsSliceInitialized()

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

Definition at line 535 of file texture_gles.cc.

535 {
536 return IsSliceMipLevelInitialized(slice, 0);
537}
bool IsSliceMipLevelInitialized(size_t slice, size_t mip_level) const

References IsSliceMipLevelInitialized().

◆ IsSliceMipLevelInitialized()

bool impeller::TextureGLES::IsSliceMipLevelInitialized ( size_t  slice,
size_t  mip_level 
) const

Definition at line 547 of file texture_gles.cc.

548 {
549 if (slice >= slice_mip_initialized_.size() ||
550 mip_level >= kMaxTrackedMipLevels) {
551 return false;
552 }
553 return slice_mip_initialized_[slice].test(mip_level);
554}

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode(), and IsSliceInitialized().

◆ IsValid()

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

Implements impeller::Texture.

Definition at line 173 of file texture_gles.cc.

173 {
174 return is_valid_;
175}

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

◆ IsWrapped()

bool impeller::TextureGLES::IsWrapped ( ) const

Definition at line 661 of file texture_gles.cc.

661 {
662 return is_wrapped_;
663}

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

168 {
169 handle_ = HandleGLES::DeadHandle();
170}
static HandleGLES DeadHandle()
Creates a dead handle.
Definition handle_gles.h:49

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

525 {
526 for (auto& slice_mips : slice_mip_initialized_) {
527 slice_mips.set();
528 }
529}

◆ MarkSliceInitialized()

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

Indicates that a specific texture slice has been initialized.

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

Definition at line 531 of file texture_gles.cc.

531 {
533}
void MarkSliceMipLevelInitialized(size_t slice, size_t mip_level)
Indicates that storage for mip_level of slice has been allocated by a glTexImage2D call (or equivalen...

References MarkSliceMipLevelInitialized().

◆ MarkSliceMipLevelInitialized()

void impeller::TextureGLES::MarkSliceMipLevelInitialized ( size_t  slice,
size_t  mip_level 
)

Indicates that storage for mip_level of slice has been allocated by a glTexImage2D call (or equivalent).

GLES raises GL_INVALID_OPERATION when glTexSubImage2D targets a level that has not been previously defined, so every per-level upload must check this first and allocate on demand.

Parameters
[in]sliceThe slice (cubemap face for cubemaps, otherwise always 0).
[in]mip_levelThe mip level whose storage was allocated.

Definition at line 539 of file texture_gles.cc.

539 {
540 if (slice >= slice_mip_initialized_.size() ||
541 mip_level >= kMaxTrackedMipLevels) {
542 return;
543 }
544 slice_mip_initialized_[slice].set(mip_level);
545}

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode(), and MarkSliceInitialized().

◆ SetAsFramebufferAttachment()

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

Definition at line 605 of file texture_gles.cc.

606 {
607 if (!IsValid()) {
608 return false;
609 }
610 InitializeContentsIfNecessary();
611 auto handle = GetGLHandle();
612 if (!handle.has_value()) {
613 return false;
614 }
615 const auto& gl = reactor_->GetProcTable();
616
617 switch (ComputeTypeForBinding(target)) {
618 case Type::kTexture:
619 gl.FramebufferTexture2D(target, // target
620 ToAttachmentType(attachment_type), // attachment
621 GL_TEXTURE_2D, // textarget
622 handle.value(), // texture
623 0 // level
624 );
625 break;
627 gl.FramebufferTexture2DMultisampleEXT(
628 target, // target
629 ToAttachmentType(attachment_type), // attachment
630 GL_TEXTURE_2D, // textarget
631 handle.value(), // texture
632 0, // level
633 4 // samples
634 );
635 break;
638 gl.FramebufferRenderbuffer(
639 target, // target
640 ToAttachmentType(attachment_type), // attachment
641 GL_RENDERBUFFER, // render-buffer target
642 handle.value() // render-buffer
643 );
644 break;
645 }
646
647 return true;
648}
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 679 of file texture_gles.cc.

679 {
680 cached_fbo_ = fbo;
681}

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

669 {
670 FML_DCHECK(!fence_.has_value());
671 fence_ = fence;
672}
#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 78 of file texture_gles.cc.

81 {
82 auto texture = std::shared_ptr<TextureGLES>(
83 new TextureGLES(std::move(reactor), desc, false, fbo, std::nullopt));
84 if (!texture->IsValid()) {
85 return nullptr;
86 }
87 return texture;
88}
FlTexture * texture

References texture.

Referenced by CreatePlaceholder(), MakeRenderTargetFromBackingStoreImpeller(), impeller::testing::TEST_P(), 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 90 of file texture_gles.cc.

93 {
94 if (external_handle.IsDead()) {
95 VALIDATION_LOG << "Cannot wrap a dead handle.";
96 return nullptr;
97 }
98 if (external_handle.GetType() != HandleType::kTexture) {
99 VALIDATION_LOG << "Cannot wrap a non-texture handle.";
100 return nullptr;
101 }
102 auto texture = std::shared_ptr<TextureGLES>(new TextureGLES(
103 std::move(reactor), desc, false, std::nullopt, external_handle));
104 if (!texture->IsValid()) {
105 return nullptr;
106 }
107 return texture;
108}

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

Referenced by Skwasm::DlWimpImageFromTexture::GetImpellerTexture(), impeller::interop::ImpellerTextureCreateWithOpenGLTextureHandleNew(), and impeller::testing::TEST_P().


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