Flutter Engine
 
Loading...
Searching...
No Matches
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
13
14namespace impeller {
15
16class 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
24 const AcquireTextureProc& aquire_proc,
25 bool wrapped = false,
26 bool drawable = false);
27
28 static std::shared_ptr<TextureMTL> Wrapper(
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_
id< MTLTexture > GetMTLTexture() const
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
bool IsValid() const override
std::function< id< MTLTexture >()> AcquireTextureProc
This callback needs to always return the same texture when called multiple times.
Definition texture_mtl.h:21
bool IsWrapped() const
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
size_t length
FlTexture * texture
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...