| 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 bool OnSetContents(const uint8_t* contents,
71 size_t length,
72 size_t slice) override;
73
74 // |Texture|
75 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
76 size_t slice) override;
77 // |Texture|
78 ISize GetSize() const override;
79
80 TextureMTL(const TextureMTL&) = delete;
81
82 TextureMTL& operator=(const TextureMTL&) = delete;
83 };
84
85 } // namespace impeller
86
87 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_TEXTURE_MTL_H_
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::IsDrawable
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
Definition: texture_mtl.mm:146
impeller::TextureMTL::GenerateMipmap
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
Definition: texture_mtl.mm:150
allocator_mtl.h
impeller::TextureMTL::GetMTLTexture
id< MTLTexture > GetMTLTexture() const
Definition: texture_mtl.mm:134
impeller::TextureMTL::TextureMTL
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
Definition: texture_mtl.mm:21
impeller::TextureMTL
Definition: texture_mtl.h:16
impeller::Texture
Definition: texture.h:17
impeller::TSize
Definition: size.h:19
impeller::TextureMTL::IsValid
bool IsValid() const override
Definition: texture_mtl.mm:138
backend_cast.h
impeller::TextureMTL::Create
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
Definition: texture_mtl.mm:58
impeller::TextureMTL::Wrapper
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
Definition: texture_mtl.mm:41
impeller::TextureMTL::~TextureMTL
~TextureMTL() override
Definition: texture_mtl.mm:63
impeller::BackendCast
Definition: backend_cast.h:11
impeller::TextureMTL::IsWrapped
bool IsWrapped() const
Definition: texture_mtl.mm:142
texture.h
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
impeller
Definition: allocation.cc:12