Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
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)
 

Private Member Functions

void SetLabel (std::string_view label) override
 
bool OnSetContents (const uint8_t *contents, size_t length, size_t slice) override
 
bool OnSetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice) override
 
ISize GetSize () const override
 

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 20 of file texture_mtl.mm.

24 : Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
25 const auto& desc = GetTextureDescriptor();
26
27 if (!desc.IsValid() || !aquire_proc) {
28 return;
29 }
30
31 if (desc.size != GetSize()) {
32 VALIDATION_LOG << "The texture and its descriptor disagree about its size.";
33 return;
34 }
35
36 is_wrapped_ = wrapped;
37 is_valid_ = true;
38}
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
ISize GetSize() const override
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
Texture(TextureDescriptor desc)
Definition texture.cc:11
#define VALIDATION_LOG
Definition validation.h:73

◆ ~TextureMTL()

impeller::TextureMTL::~TextureMTL ( )
overridedefault

Member Function Documentation

◆ Create()

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

Definition at line 57 of file texture_mtl.mm.

58 {
59 return std::make_shared<TextureMTL>(desc, [texture]() { return texture; });
60}
FlTexture * texture

◆ GenerateMipmap()

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

Definition at line 132 of file texture_mtl.mm.

132 {
133 if (is_drawable_) {
134 return false;
135 }
136
137 auto texture = aquire_proc_();
138 if (!texture) {
139 return false;
140 }
141
142 [encoder generateMipmapsForTexture:texture];
143 mipmap_generated_ = true;
144
145 return true;
146}
bool mipmap_generated_
Definition texture.h:64

◆ GetMTLTexture()

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

Definition at line 116 of file texture_mtl.mm.

116 {
117 return aquire_proc_();
118}

◆ GetSize()

ISize impeller::TextureMTL::GetSize ( ) const
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 107 of file texture_mtl.mm.

107 {
108 if (is_drawable_) {
109 return GetTextureDescriptor().size;
110 }
111 const auto& texture = aquire_proc_();
112 return {static_cast<ISize::Type>(texture.width),
113 static_cast<ISize::Type>(texture.height)};
114}

◆ IsDrawable()

bool impeller::TextureMTL::IsDrawable ( ) const

Whether or not this texture is wrapping a Metal drawable.

Definition at line 128 of file texture_mtl.mm.

128 {
129 return is_drawable_;
130}

◆ IsValid()

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

Implements impeller::Texture.

Definition at line 120 of file texture_mtl.mm.

120 {
121 return is_valid_;
122}

◆ IsWrapped()

bool impeller::TextureMTL::IsWrapped ( ) const

Definition at line 124 of file texture_mtl.mm.

124 {
125 return is_wrapped_;
126}

◆ OnSetContents() [1/2]

bool impeller::TextureMTL::OnSetContents ( const uint8_t *  contents,
size_t  length,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 80 of file texture_mtl.mm.

82 {
83 if (!IsValid() || !contents || is_wrapped_ || is_drawable_) {
84 return false;
85 }
86
87 const auto& desc = GetTextureDescriptor();
88
89 // Out of bounds access.
90 if (length != desc.GetByteSizeOfBaseMipLevel()) {
91 return false;
92 }
93
94 const auto region =
95 MTLRegionMake2D(0u, 0u, desc.size.width, desc.size.height);
96 [aquire_proc_() replaceRegion:region //
97 mipmapLevel:0u //
98 slice:slice //
99 withBytes:contents //
100 bytesPerRow:desc.GetBytesPerRow() //
101 bytesPerImage:desc.GetByteSizeOfBaseMipLevel() //
102 ];
103
104 return true;
105}
bool IsValid() const override
size_t length
ClipOpAndAA opAA SkRegion region
Definition SkRecords.h:238

◆ OnSetContents() [2/2]

bool impeller::TextureMTL::OnSetContents ( std::shared_ptr< const fml::Mapping mapping,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 72 of file texture_mtl.mm.

73 {
74 // Metal has no threading restrictions. So we can pass this data along to the
75 // client rendering API immediately.
76 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
77}
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice) override

◆ SetLabel()

void impeller::TextureMTL::SetLabel ( std::string_view  label)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 64 of file texture_mtl.mm.

64 {
65 if (is_drawable_) {
66 return;
67 }
68 [aquire_proc_() setLabel:@(label.data())];
69}

◆ Wrapper()

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

Definition at line 40 of file texture_mtl.mm.

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

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