Flutter Engine
 
Loading...
Searching...
No Matches
impeller::TextureMTL Class Referencefinal

#include <texture_mtl.h>

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

Public Types

using AcquireTextureProc = std::function< id< MTLTexture >()>
 This callback needs to always return the same texture when called multiple times.
 

Public Member Functions

 TextureMTL (TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
 
 ~TextureMTL () override
 
id< MTLTexture > GetMTLTexture () const
 
bool IsWrapped () const
 
bool IsDrawable () const
 Whether or not this texture is wrapping a Metal drawable.
 
bool IsValid () const override
 
bool GenerateMipmap (id< MTLBlitCommandEncoder > encoder)
 
- 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
 
virtual Scalar GetYCoordScale () const
 
bool NeedsMipmapGeneration () const
 

Static Public Member Functions

static std::shared_ptr< TextureMTLWrapper (TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
 
static std::shared_ptr< TextureMTLCreate (TextureDescriptor desc, id< MTLTexture > texture)
 
- Static Public Member Functions inherited from impeller::BackendCast< TextureMTL, Texture >
static TextureMTLCast (Texture &base)
 
static const TextureMTLCast (const Texture &base)
 
static TextureMTLCast (Texture *base)
 
static const TextureMTLCast (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 16 of file texture_mtl.h.

Member Typedef Documentation

◆ AcquireTextureProc

using impeller::TextureMTL::AcquireTextureProc = std::function<id<MTLTexture>()>

This callback needs to always return the same texture when called multiple times.

Definition at line 21 of file texture_mtl.h.

Constructor & Destructor Documentation

◆ TextureMTL()

impeller::TextureMTL::TextureMTL ( TextureDescriptor  desc,
const AcquireTextureProc aquire_proc,
bool  wrapped = false,
bool  drawable = false 
)

Definition at line 24 of file texture_mtl.mm.

28 : Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
29 const auto& desc = GetTextureDescriptor();
30
31 if (!desc.IsValid() || !aquire_proc) {
32 return;
33 }
34
35 if (desc.size != GetSize()) {
36 VALIDATION_LOG << "The texture and its descriptor disagree about its size.";
37 return;
38 }
39
40 is_wrapped_ = wrapped;
41 is_valid_ = true;
42}
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
Texture(TextureDescriptor desc)
Definition texture.cc:11
#define VALIDATION_LOG
Definition validation.h:91

References impeller::Texture::GetTextureDescriptor(), impeller::TextureDescriptor::IsValid(), impeller::TextureDescriptor::size, and VALIDATION_LOG.

◆ ~TextureMTL()

impeller::TextureMTL::~TextureMTL ( )
override

Definition at line 66 of file texture_mtl.mm.

66 {
67#ifdef IMPELLER_DEBUG
68 if (debug_allocator_) {
69 auto desc = GetTextureDescriptor();
70 if (desc.storage_mode == StorageMode::kDeviceTransient) {
71 return;
72 }
73 debug_allocator_->Decrement(desc.GetByteSizeOfBaseMipLevel());
74 }
75#endif // IMPELLER_DEBUG
76}

References impeller::TextureDescriptor::GetByteSizeOfBaseMipLevel(), impeller::Texture::GetTextureDescriptor(), impeller::kDeviceTransient, and impeller::TextureDescriptor::storage_mode.

Member Function Documentation

◆ Create()

std::shared_ptr< TextureMTL > impeller::TextureMTL::Create ( TextureDescriptor  desc,
id< MTLTexture >  texture 
)
static

Definition at line 61 of file texture_mtl.mm.

62 {
63 return std::make_shared<TextureMTL>(desc, [texture]() { return texture; });
64}
FlTexture * texture

References texture.

Referenced by impeller::WrapTextureWithRenderTarget().

◆ GenerateMipmap()

bool impeller::TextureMTL::GenerateMipmap ( id< MTLBlitCommandEncoder >  encoder)

Definition at line 165 of file texture_mtl.mm.

165 {
166 if (is_drawable_) {
167 return false;
168 }
169
170 auto texture = aquire_proc_();
171 if (!texture) {
172 return false;
173 }
174
175 [encoder generateMipmapsForTexture:texture];
176 mipmap_generated_ = true;
177
178 return true;
179}
bool mipmap_generated_
Definition texture.h:79

References impeller::Texture::mipmap_generated_, and texture.

◆ GetMTLTexture()

id< MTLTexture > impeller::TextureMTL::GetMTLTexture ( ) const

Definition at line 149 of file texture_mtl.mm.

149 {
150 return aquire_proc_();
151}

Referenced by impeller::ConfigureAttachment(), and impeller::ConfigureResolveTextureAttachment().

◆ IsDrawable()

bool impeller::TextureMTL::IsDrawable ( ) const

Whether or not this texture is wrapping a Metal drawable.

Definition at line 161 of file texture_mtl.mm.

161 {
162 return is_drawable_;
163}

◆ IsValid()

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

Implements impeller::Texture.

Definition at line 153 of file texture_mtl.mm.

153 {
154 return is_valid_;
155}

◆ IsWrapped()

bool impeller::TextureMTL::IsWrapped ( ) const

Definition at line 157 of file texture_mtl.mm.

157 {
158 return is_wrapped_;
159}

◆ Wrapper()

std::shared_ptr< TextureMTL > impeller::TextureMTL::Wrapper ( TextureDescriptor  desc,
id< MTLTexture >  texture,
std::function< void()>  deletion_proc = nullptr 
)
static

Definition at line 44 of file texture_mtl.mm.

47 {
48 if (deletion_proc) {
49 return std::shared_ptr<TextureMTL>(
50 new TextureMTL(
51 desc, [texture]() { return texture; }, true),
52 [deletion_proc = std::move(deletion_proc)](TextureMTL* t) {
53 deletion_proc();
54 delete t;
55 });
56 }
57 return std::shared_ptr<TextureMTL>(
58 new TextureMTL(desc, [texture]() { return texture; }, true));
59}
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)

References texture.

Referenced by impeller::SurfaceMTL::MakeFromTexture(), impeller::WrapperMTL(), and impeller::WrapTextureMTL().


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