| Flutter Impeller |

texture_mtl.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_TEXTURE_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_TEXTURE_MTL_H_
7
8 #include <Metal/Metal.h>
9
10 #include "impeller/base/backend_cast.h"
11 #include "impeller/core/texture.h"
12 #include "impeller/renderer/backend/metal/allocator_mtl.h"
13
14 namespace impeller {
15
16 class TextureMTL final : public Texture,
17 public BackendCast<TextureMTL, Texture> {
18 public:
19 /// @brief This callback needs to always return the same texture when called
20 /// multiple times.
21 using AcquireTextureProc = std::function<id<MTLTexture>()>;
22
23 TextureMTL(TextureDescriptor desc,
24 const AcquireTextureProc& aquire_proc,
25 bool wrapped = false,
26 bool drawable = false);
27
28 static std::shared_ptr<TextureMTL> Wrapper(
29 TextureDescriptor desc,
30 id<MTLTexture> texture,
31 std::function<void()> deletion_proc = nullptr);
32
33 static std::shared_ptr<TextureMTL> Create(TextureDescriptor desc,
34 id<MTLTexture> texture);
35
36 // |Texture|
37 ~TextureMTL() override;
38
39 id<MTLTexture> GetMTLTexture() const;
40
41 bool IsWrapped() const;
42
43 /// @brief Whether or not this texture is wrapping a Metal drawable.
44 bool IsDrawable() const;
45
46 // |Texture|
47 bool IsValid() const override;
48
49 bool GenerateMipmap(id<MTLBlitCommandEncoder> encoder);
50
51 #ifdef IMPELLER_DEBUG
52 void SetDebugAllocator(
53 const std::shared_ptr<DebugAllocatorStats>& debug_allocator);
54 #endif // IMPELLER_DEBUG
55
56 private:
57 #ifdef IMPELLER_DEBUG
58 std::shared_ptr<DebugAllocatorStats> debug_allocator_ = nullptr;
59 #endif // IMPELLER_DEBUG
60
61 AcquireTextureProc aquire_proc_ = {};
62 bool is_valid_ = false;
63 bool is_wrapped_ = false;
64 bool is_drawable_ = false;
65
66 // |Texture|
67 void SetLabel(std::string_view label) override;
68
69 // |Texture|
70 void SetLabel(std::string_view label, std::string_view trailing) override;
71
72 // |Texture|
73 bool OnSetContents(const uint8_t* contents,
74 size_t length,
75 size_t slice) override;
76
77 // |Texture|
78 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
79 size_t slice) override;
80 // |Texture|
81 ISize GetSize() const override;
82
83 TextureMTL(const TextureMTL&) = delete;
84
85 TextureMTL& operator=(const TextureMTL&) = delete;
86 };
87
88 } // namespace impeller
89
90 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_TEXTURE_MTL_H_
allocator_mtl.h
backend_cast.h
impeller::BackendCast
Definition: backend_cast.h:11
impeller::Texture
Definition: texture.h:17
impeller::TextureMTL
Definition: texture_mtl.h:17
impeller::TextureMTL::GetMTLTexture
id< MTLTexture > GetMTLTexture() const
Definition: texture_mtl.mm:149
impeller::TextureMTL::~TextureMTL
~TextureMTL() override
Definition: texture_mtl.mm:66
impeller::TextureMTL::TextureMTL
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
Definition: texture_mtl.mm:24
impeller::TextureMTL::IsDrawable
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
Definition: texture_mtl.mm:161
impeller::TextureMTL::IsValid
bool IsValid() const override
Definition: texture_mtl.mm:153
impeller::TextureMTL::AcquireTextureProc
std::function< id< MTLTexture >()> AcquireTextureProc
This callback needs to always return the same texture when called multiple times.
Definition: texture_mtl.h:21
impeller::TextureMTL::IsWrapped
bool IsWrapped() const
Definition: texture_mtl.mm:157
impeller::TextureMTL::GenerateMipmap
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
Definition: texture_mtl.mm:165
impeller::TextureMTL::Wrapper
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
Definition: texture_mtl.mm:44
impeller::TextureMTL::Create
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
Definition: texture_mtl.mm:61
texture.h
impeller
Definition: allocation.cc:12
impeller::TSize
Definition: size.h:25
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38