Flutter Engine
flutter::IOSContextMetal Class Referencefinal

#include <ios_context_metal.h>

Inheritance diagram for flutter::IOSContextMetal:
flutter::IOSContext

Public Member Functions

 IOSContextMetal ()
 
 ~IOSContextMetal ()
 
fml::scoped_nsprotocol< id< MTLDevice > > GetDevice () const
 
fml::scoped_nsprotocol< id< MTLCommandQueue > > GetMainCommandQueue () const
 
fml::scoped_nsprotocol< id< MTLCommandQueue > > GetResourceCommandQueue () const
 
sk_sp< GrDirectContext > GetMainContext () const
 
sk_sp< GrDirectContext > GetResourceContext () const
 
- Public Member Functions inherited from flutter::IOSContext
virtual ~IOSContext ()
 Collects the context object. This must happen on the thread on which this object was created. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::IOSContext
static std::unique_ptr< IOSContextCreate (IOSRenderingAPI rendering_api)
 Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by Skia. More...
 
- Protected Member Functions inherited from flutter::IOSContext
 IOSContext ()
 

Detailed Description

Definition at line 18 of file ios_context_metal.h.

Constructor & Destructor Documentation

◆ IOSContextMetal()

flutter::IOSContextMetal::IOSContextMetal ( )

Definition at line 24 of file ios_context_metal.mm.

References flutter::CreateMetalGrContextOptions(), FML_DLOG, fml::scoped_nsprotocol< NST >::get(), fml::CFRef< T >::Reset(), fml::scoped_nsprotocol< NST >::reset(), and ~IOSContextMetal().

24  {
25  device_.reset([MTLCreateSystemDefaultDevice() retain]);
26  if (!device_) {
27  FML_DLOG(ERROR) << "Could not acquire Metal device.";
28  return;
29  }
30 
31  main_queue_.reset([device_ newCommandQueue]);
32 
33  if (!main_queue_) {
34  FML_DLOG(ERROR) << "Could not create Metal command queue.";
35  return;
36  }
37 
38  [main_queue_ setLabel:@"Flutter Main Queue"];
39 
40  const auto& context_options = CreateMetalGrContextOptions();
41 
42  // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
43  // when the GrDirectContext is collected.
44  main_context_ =
45  GrDirectContext::MakeMetal([device_ retain], [main_queue_ retain], context_options);
46  resource_context_ =
47  GrDirectContext::MakeMetal([device_ retain], [main_queue_ retain], context_options);
48 
49  if (!main_context_ || !resource_context_) {
50  FML_DLOG(ERROR) << "Could not create Skia Metal contexts.";
51  return;
52  }
53 
54  resource_context_->setResourceCacheLimits(0u, 0u);
55 
56  CVMetalTextureCacheRef texture_cache_raw = NULL;
57  auto cv_return = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator
58  NULL, // cache attributes (NULL default)
59  device_.get(), // metal device
60  NULL, // texture attributes (NULL default)
61  &texture_cache_raw // [out] cache
62  );
63  if (cv_return != kCVReturnSuccess) {
64  FML_DLOG(ERROR) << "Could not create Metal texture cache.";
65  return;
66  }
67  texture_cache_.Reset(texture_cache_raw);
68 }
void reset(NST object=nil)
void Reset(T instance=nullptr)
Definition: cf_utils.h:43
#define FML_DLOG(severity)
Definition: logging.h:85
static GrContextOptions CreateMetalGrContextOptions()

◆ ~IOSContextMetal()

flutter::IOSContextMetal::~IOSContextMetal ( )
default

Referenced by IOSContextMetal().

Member Function Documentation

◆ GetDevice()

fml::scoped_nsprotocol< id< MTLDevice > > flutter::IOSContextMetal::GetDevice ( ) const

Definition at line 72 of file ios_context_metal.mm.

72  {
73  return device_;
74 }

◆ GetMainCommandQueue()

fml::scoped_nsprotocol< id< MTLCommandQueue > > flutter::IOSContextMetal::GetMainCommandQueue ( ) const

Definition at line 76 of file ios_context_metal.mm.

76  {
77  return main_queue_;
78 }

◆ GetMainContext()

sk_sp< GrDirectContext > flutter::IOSContextMetal::GetMainContext ( ) const

Definition at line 85 of file ios_context_metal.mm.

85  {
86  return main_context_;
87 }

◆ GetResourceCommandQueue()

fml::scoped_nsprotocol< id< MTLCommandQueue > > flutter::IOSContextMetal::GetResourceCommandQueue ( ) const

Definition at line 80 of file ios_context_metal.mm.

80  {
81  // TODO(52150): Create a dedicated resource queue once multiple queues are supported in Skia.
82  return main_queue_;
83 }

◆ GetResourceContext()

sk_sp< GrDirectContext > flutter::IOSContextMetal::GetResourceContext ( ) const

Definition at line 89 of file ios_context_metal.mm.

89  {
90  return resource_context_;
91 }

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