| 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 "flutter/fml/macros.h"
11 #include "impeller/base/backend_cast.h"
12 #include "impeller/core/texture.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 private:
52 AcquireTextureProc aquire_proc_ = {};
53 bool is_valid_ = false;
54 bool is_wrapped_ = false;
55 bool is_drawable_ = false;
56
57 // |Texture|
58 void SetLabel(std::string_view label) override;
59
60 // |Texture|
61 bool OnSetContents(const uint8_t* contents,
62 size_t length,
63 size_t slice) override;
64
65 // |Texture|
66 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
67 size_t slice) override;
68 // |Texture|
69 ISize GetSize() const override;
70
71 TextureMTL(const TextureMTL&) = delete;
72
73 TextureMTL& operator=(const TextureMTL&) = delete;
74 };
75
76 } // namespace impeller
77
78 #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:128
impeller::TextureMTL::GenerateMipmap
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
Definition: texture_mtl.mm:132
impeller::TextureMTL::GetMTLTexture
id< MTLTexture > GetMTLTexture() const
Definition: texture_mtl.mm:116
impeller::TextureMTL::TextureMTL
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
Definition: texture_mtl.mm:20
impeller::TextureMTL
Definition: texture_mtl.h:16
impeller::Texture
Definition: texture.h:17
impeller::TSize< int64_t >
impeller::TextureMTL::IsValid
bool IsValid() const override
Definition: texture_mtl.mm:120
backend_cast.h
impeller::TextureMTL::Create
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
Definition: texture_mtl.mm:57
impeller::TextureMTL::Wrapper
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
Definition: texture_mtl.mm:40
impeller::TextureMTL::~TextureMTL
~TextureMTL() override
impeller::BackendCast
Definition: backend_cast.h:11
impeller::TextureMTL::IsWrapped
bool IsWrapped() const
Definition: texture_mtl.mm:124
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:37
impeller
Definition: aiks_blur_unittests.cc:20