Flutter Engine
 
Loading...
Searching...
No Matches
flutter::testing::TestMetalContext Class Reference

#include <test_metal_context.h>

Classes

struct  TextureInfo
 

Public Member Functions

 TestMetalContext ()
 
 ~TestMetalContext ()
 
id< MTLDevice > GetMetalDevice () const
 
id< MTLCommandQueue > GetMetalCommandQueue () const
 
sk_sp< GrDirectContext > GetSkiaContext () const
 
TextureInfo CreateMetalTexture (const DlISize &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 22 of file test_metal_context.h.

Constructor & Destructor Documentation

◆ TestMetalContext()

flutter::testing::TestMetalContext::TestMetalContext ( )

Definition at line 19 of file test_metal_context.mm.

19 {
20 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
21 if (!device) {
22 FML_LOG(ERROR) << "Could not acquire Metal device.";
23 return;
24 }
25
26 id<MTLCommandQueue> command_queue = [device newCommandQueue];
27 if (!command_queue) {
28 FML_LOG(ERROR) << "Could not create the default command queue.";
29 return;
30 }
31
32 [command_queue 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.retain((__bridge GrMTLHandle)device);
38 backendContext.fQueue.retain((__bridge GrMTLHandle)command_queue);
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 device_ = device;
45 command_queue_ = command_queue;
46}
VkDevice device
Definition main.cc:69
#define FML_LOG(severity)
Definition logging.h:101

References device, and FML_LOG.

◆ ~TestMetalContext()

flutter::testing::TestMetalContext::~TestMetalContext ( )

Definition at line 48 of file test_metal_context.mm.

48 {
49 std::scoped_lock lock(textures_mutex_);
50 textures_.clear();
51}

Member Function Documentation

◆ CreateMetalTexture()

TestMetalContext::TextureInfo flutter::testing::TestMetalContext::CreateMetalTexture ( const DlISize size)

Returns texture_id = -1 when texture creation fails.

Definition at line 65 of file test_metal_context.mm.

65 {
66 std::scoped_lock lock(textures_mutex_);
67 MTLTextureDescriptor* texture_descriptor =
68 [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
69 width:size.width
70 height:size.height
71 mipmapped:NO];
72
73 // The most pessimistic option and disables all optimizations but allows tests
74 // the most flexible access to the surface. They may read and write to the
75 // surface from shaders or use as a pixel view.
76 texture_descriptor.usage = MTLTextureUsageUnknown;
77
78 if (!texture_descriptor) {
79 FML_CHECK(false) << "Invalid texture descriptor.";
80 return {.texture_id = -1, .texture = nullptr};
81 }
82
83 if (!device_) {
84 FML_CHECK(false) << "Invalid Metal device.";
85 return {.texture_id = -1, .texture = nullptr};
86 }
87
88 id<MTLTexture> texture = [device_ newTextureWithDescriptor:texture_descriptor];
89 if (!texture) {
90 FML_CHECK(false) << "Could not create texture from texture descriptor.";
91 return {.texture_id = -1, .texture = nullptr};
92 }
93
94 const int64_t texture_id = texture_id_ctr_++;
95 sk_cfp<void*> texture_ptr;
96 texture_ptr.retain((__bridge void*)texture);
97 textures_[texture_id] = texture_ptr;
98
99 return {
100 .texture_id = texture_id,
101 .texture = (__bridge void*)texture,
102 };
103}
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
int32_t height
int32_t width
int64_t texture_id

References FML_CHECK, height, flutter::size, texture, texture_id, and width.

Referenced by flutter::testing::TEST_F(), and flutter::testing::TEST_F().

◆ GetMetalCommandQueue()

id< MTLCommandQueue > flutter::testing::TestMetalContext::GetMetalCommandQueue ( ) const

Definition at line 57 of file test_metal_context.mm.

57 {
58 return command_queue_;
59}

◆ GetMetalDevice()

id< MTLDevice > flutter::testing::TestMetalContext::GetMetalDevice ( ) const

Definition at line 53 of file test_metal_context.mm.

53 {
54 return device_;
55}

◆ GetSkiaContext()

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

Definition at line 61 of file test_metal_context.mm.

61 {
62 return skia_context_;
63}

Referenced by flutter::testing::TEST_F().

◆ GetTextureInfo()

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

Definition at line 115 of file test_metal_context.mm.

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

References FML_CHECK, and texture_id.

◆ Present()

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

Definition at line 106 of file test_metal_context.mm.

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

References texture_id.


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