15 const void* mtl_texture,
16 std::function<
void()> deletion_proc) {
18 std::move(deletion_proc));
25 :
Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
28 if (!desc.
IsValid() || !aquire_proc) {
32 if (desc.
size != GetSize()) {
33 VALIDATION_LOG <<
"The texture and its descriptor disagree about its size.";
37 is_wrapped_ = wrapped;
43 id<MTLTexture> texture,
44 std::function<
void()> deletion_proc) {
46 return std::shared_ptr<TextureMTL>(
48 desc, [texture]() {
return texture; },
true),
49 [deletion_proc = std::move(deletion_proc)](
TextureMTL* t) {
54 return std::shared_ptr<TextureMTL>(
55 new TextureMTL(desc, [texture]() {
return texture; },
true));
59 id<MTLTexture> texture) {
60 return std::make_shared<TextureMTL>(desc, [texture]() {
return texture; });
65 if (debug_allocator_) {
72 #endif // IMPELLER_DEBUG
75 void TextureMTL::SetLabel(std::string_view label) {
79 [aquire_proc_() setLabel:@(label.
data())];
83 bool TextureMTL::OnSetContents(
std::shared_ptr<const fml::Mapping> mapping,
87 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
91 void TextureMTL::SetDebugAllocator(
92 const std::shared_ptr<DebugAllocatorStats>& debug_allocator) {
93 debug_allocator_ = debug_allocator;
95 #endif // IMPELLER_DEBUG
98 bool TextureMTL::OnSetContents(
const uint8_t* contents,
101 if (!
IsValid() || !contents || is_wrapped_ || is_drawable_) {
114 [aquire_proc_() replaceRegion:region
118 bytesPerRow:desc.GetBytesPerRow()
119 bytesPerImage:desc.GetByteSizeOfBaseMipLevel()
129 const auto& texture = aquire_proc_();
135 return aquire_proc_();
155 auto texture = aquire_proc_();
160 [encoder generateMipmapsForTexture:texture];