Flutter Engine
The 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
10#include "flutter/fml/macros.h"
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 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_
static sk_sp< Effect > Create()
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
id< MTLTexture > GetMTLTexture() const
~TextureMTL() override
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice) override
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
void SetLabel(std::string_view label) override
bool IsWrapped() const
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
ISize GetSize() const override
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
size_t length
FlTexture * texture
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...