Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
flutter::TestMetalContext Class Reference

#include <test_metal_context.h>

Classes

struct  TextureInfo
 

Public Member Functions

 TestMetalContext ()
 
 ~TestMetalContext ()
 
void * GetMetalDevice () const
 
void * GetMetalCommandQueue () const
 
sk_sp< GrDirectContextGetSkiaContext () const
 
TextureInfo CreateMetalTexture (const SkISize &size)
 Returns texture_id = -1 when texture creation fails.
 
bool Present (int64_t texture_id)
 
TextureInfo GetTextureInfo (int64_t texture_id)
 

Detailed Description

Definition at line 16 of file test_metal_context.h.

Constructor & Destructor Documentation

◆ TestMetalContext()

flutter::TestMetalContext::TestMetalContext ( )

Definition at line 19 of file test_metal_context.mm.

19 {
20 auto device = fml::scoped_nsprotocol{MTLCreateSystemDefaultDevice()};
21 if (!device) {
22 FML_LOG(ERROR) << "Could not acquire Metal device.";
23 return;
24 }
25
26 auto command_queue = fml::scoped_nsobject{[device.get() newCommandQueue]};
27 if (!command_queue) {
28 FML_LOG(ERROR) << "Could not create the default command queue.";
29 return;
30 }
31
32 [command_queue.get() setLabel:@"Flutter Test Queue"];
33
34 GrMtlBackendContext backendContext = {};
35 // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
36 // when the GrDirectContext is collected.
37 backendContext.fDevice.reset([device.get() retain]);
38 backendContext.fQueue.reset([command_queue.get() retain]);
39 skia_context_ = GrDirectContexts::MakeMetal(backendContext);
40 if (!skia_context_) {
41 FML_LOG(ERROR) << "Could not create the GrDirectContext from the Metal Device "
42 "and command queue.";
43 }
44
45 device_ = [device.get() retain];
46 command_queue_ = [command_queue.get() retain];
47}
VkDevice device
Definition main.cc:53
#define FML_LOG(severity)
Definition logging.h:82
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue
#define ERROR(message)

◆ ~TestMetalContext()

flutter::TestMetalContext::~TestMetalContext ( )

Definition at line 49 of file test_metal_context.mm.

49 {
50 std::scoped_lock lock(textures_mutex_);
51 textures_.clear();
52 if (device_) {
53 [(__bridge id)device_ release];
54 }
55 if (command_queue_) {
56 [(__bridge id)command_queue_ release];
57 }
58}
const uintptr_t id

Member Function Documentation

◆ CreateMetalTexture()

TestMetalContext::TextureInfo flutter::TestMetalContext::CreateMetalTexture ( const SkISize size)

Returns texture_id = -1 when texture creation fails.

Definition at line 72 of file test_metal_context.mm.

72 {
73 std::scoped_lock lock(textures_mutex_);
74 auto texture_descriptor = fml::scoped_nsobject{
75 [[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
76 width:size.width()
77 height:size.height()
78 mipmapped:NO] retain]};
79
80 // The most pessimistic option and disables all optimizations but allows tests
81 // the most flexible access to the surface. They may read and write to the
82 // surface from shaders or use as a pixel view.
83 texture_descriptor.get().usage = MTLTextureUsageUnknown;
84
85 if (!texture_descriptor) {
86 FML_CHECK(false) << "Invalid texture descriptor.";
87 return {.texture_id = -1, .texture = nullptr};
88 }
89
90 id<MTLDevice> device = (__bridge id<MTLDevice>)GetMetalDevice();
91 sk_cfp<void*> texture = sk_cfp<void*>{[device newTextureWithDescriptor:texture_descriptor.get()]};
92
93 if (!texture) {
94 FML_CHECK(false) << "Could not create texture from texture descriptor.";
95 return {.texture_id = -1, .texture = nullptr};
96 }
97
98 const int64_t texture_id = texture_id_ctr_++;
99 textures_[texture_id] = texture;
100
101 return {
102 .texture_id = texture_id,
103 .texture = texture.get(),
104 };
105}
T get() const __attribute((ns_returns_not_retained))
#define FML_CHECK(condition)
Definition logging.h:85
FlTexture * texture
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
int32_t height
int32_t width
int64_t texture_id

◆ GetMetalCommandQueue()

void * flutter::TestMetalContext::GetMetalCommandQueue ( ) const

Definition at line 64 of file test_metal_context.mm.

64 {
65 return command_queue_;
66}

◆ GetMetalDevice()

void * flutter::TestMetalContext::GetMetalDevice ( ) const

Definition at line 60 of file test_metal_context.mm.

60 {
61 return device_;
62}

◆ GetSkiaContext()

sk_sp< GrDirectContext > flutter::TestMetalContext::GetSkiaContext ( ) const

Definition at line 68 of file test_metal_context.mm.

68 {
69 return skia_context_;
70}

◆ GetTextureInfo()

TestMetalContext::TextureInfo flutter::TestMetalContext::GetTextureInfo ( int64_t  texture_id)

Definition at line 117 of file test_metal_context.mm.

117 {
118 std::scoped_lock lock(textures_mutex_);
119 if (textures_.find(texture_id) == textures_.end()) {
120 FML_CHECK(false) << "Invalid texture id: " << texture_id;
121 return {.texture_id = -1, .texture = nullptr};
122 } else {
123 return {
124 .texture_id = texture_id,
125 .texture = textures_[texture_id].get(),
126 };
127 }
128}

◆ Present()

bool flutter::TestMetalContext::Present ( int64_t  texture_id)

Definition at line 108 of file test_metal_context.mm.

108 {
109 std::scoped_lock lock(textures_mutex_);
110 if (textures_.find(texture_id) == textures_.end()) {
111 return false;
112 } else {
113 return true;
114 }
115}

The documentation for this class was generated from the following files: