Flutter Engine
The Flutter Engine
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
12
13namespace impeller {
14
15class TextureMTL final : public Texture,
16 public BackendCast<TextureMTL, Texture> {
17 public:
18 /// @brief This callback needs to always return the same texture when called
19 /// multiple times.
20 using AcquireTextureProc = std::function<id<MTLTexture>()>;
21
23 const AcquireTextureProc& aquire_proc,
24 bool wrapped = false,
25 bool drawable = false);
26
27 static std::shared_ptr<TextureMTL> Wrapper(
29 id<MTLTexture> texture,
30 std::function<void()> deletion_proc = nullptr);
31
32 static std::shared_ptr<TextureMTL> Create(TextureDescriptor desc,
33 id<MTLTexture> texture);
34
35 // |Texture|
36 ~TextureMTL() override;
37
38 id<MTLTexture> GetMTLTexture() const;
39
40 bool IsWrapped() const;
41
42 /// @brief Whether or not this texture is wrapping a Metal drawable.
43 bool IsDrawable() const;
44
45 // |Texture|
46 bool IsValid() const override;
47
48 bool GenerateMipmap(id<MTLBlitCommandEncoder> encoder);
49
50 private:
51 AcquireTextureProc aquire_proc_ = {};
52 bool is_valid_ = false;
53 bool is_wrapped_ = false;
54 bool is_drawable_ = false;
55
56 // |Texture|
57 void SetLabel(std::string_view label) override;
58
59 // |Texture|
60 bool OnSetContents(const uint8_t* contents,
61 size_t length,
62 size_t slice) override;
63
64 // |Texture|
65 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
66 size_t slice) override;
67 // |Texture|
68 ISize GetSize() const override;
69
70 TextureMTL(const TextureMTL&) = delete;
71
72 TextureMTL& operator=(const TextureMTL&) = delete;
73};
74
75} // namespace impeller
76
77#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_TEXTURE_MTL_H_
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
id< MTLTexture > GetMTLTexture() const
Definition: texture_mtl.mm:116
~TextureMTL() override
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
Definition: texture_mtl.mm:20
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
Definition: texture_mtl.mm:128
bool IsValid() const override
Definition: texture_mtl.mm:120
std::function< id< MTLTexture >()> AcquireTextureProc
This callback needs to always return the same texture when called multiple times.
Definition: texture_mtl.h:20
bool IsWrapped() const
Definition: texture_mtl.mm:124
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
Definition: texture_mtl.mm:132
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
Definition: texture_mtl.mm:40
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
Definition: texture_mtl.mm:57
Dart_NativeFunction function
Definition: fuchsia.cc:51
size_t length
FlTexture * texture
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...