16 const void* mtl_texture,
17 std::function<
void()> deletion_proc) {
19 std::move(deletion_proc));
26 :
Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
29 if (!desc.
IsValid() || !aquire_proc) {
33 if (desc.
size != GetSize()) {
34 VALIDATION_LOG <<
"The texture and its descriptor disagree about its size.";
38 is_wrapped_ = wrapped;
44 id<MTLTexture> texture,
45 std::function<
void()> deletion_proc) {
47 return std::shared_ptr<TextureMTL>(
49 desc, [texture]() {
return texture; },
true),
50 [deletion_proc = std::move(deletion_proc)](
TextureMTL* t) {
55 return std::shared_ptr<TextureMTL>(
56 new TextureMTL(desc, [texture]() {
return texture; },
true));
60 id<MTLTexture> texture) {
61 return std::make_shared<TextureMTL>(desc, [texture]() {
return texture; });
66 if (debug_allocator_) {
76 void TextureMTL::SetLabel(std::string_view label) {
81 [aquire_proc_() setLabel:@(label.
data())];
85 void TextureMTL::SetLabel(std::string_view label, std::string_view trailing) {
90 std::string combined =
SPrintF(
"%s %s", label.data(), trailing.data());
91 [aquire_proc_() setLabel:@(combined.
data())];
96 bool TextureMTL::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
100 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
103 #ifdef IMPELLER_DEBUG
104 void TextureMTL::SetDebugAllocator(
105 const std::shared_ptr<DebugAllocatorStats>& debug_allocator) {
106 debug_allocator_ = debug_allocator;
111 bool TextureMTL::OnSetContents(
const uint8_t* contents,
114 if (!
IsValid() || !contents || is_wrapped_ || is_drawable_) {
127 [aquire_proc_() replaceRegion:region
131 bytesPerRow:desc.GetBytesPerRow()
132 bytesPerImage:desc.GetByteSizeOfBaseMipLevel()
142 const auto& texture = aquire_proc_();
148 return aquire_proc_();
168 auto texture = aquire_proc_();
173 [encoder generateMipmapsForTexture:texture];
const TextureDescriptor & GetTextureDescriptor() const
id< MTLTexture > GetMTLTexture() const
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
bool IsValid() const override
std::function< id< MTLTexture >()> AcquireTextureProc
This callback needs to always return the same texture when called multiple times.
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
std::string SPrintF(const char *format,...)
std::shared_ptr< Texture > WrapperMTL(TextureDescriptor desc, const void *mtl_texture, std::function< void()> deletion_proc)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
constexpr size_t GetByteSizeOfBaseMipLevel() const
constexpr bool IsValid() const
std::shared_ptr< const fml::Mapping > data