diff --git a/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm b/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm index 75ca69845c1a8..257964fec0981 100644 --- a/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm +++ b/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm @@ -59,13 +59,8 @@ - (instancetype)initWithMTLDevice:(id)device return nil; } - auto contextOptions = CreateMetalGrContextOptions(); - - // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later - // when the GrDirectContext is collected. - _mainContext = GrDirectContext::MakeMetal( - (__bridge_retained void*)_device, (__bridge_retained void*)_commandQueue, contextOptions); - _resourceContext = _mainContext; + _mainContext = [self createGrContext]; + _resourceContext = [self createGrContext]; if (!_mainContext || !_resourceContext) { FML_DLOG(ERROR) << "Could not create Skia Metal contexts."; @@ -77,6 +72,16 @@ - (instancetype)initWithMTLDevice:(id)device return self; } +- (sk_sp)createGrContext { + auto contextOptions = CreateMetalGrContextOptions(); + id device = _device; + id commandQueue = _commandQueue; + // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later + // when the GrDirectContext is collected. + return GrDirectContext::MakeMetal((__bridge_retained void*)device, + (__bridge_retained void*)commandQueue, contextOptions); +} + - (void)dealloc { if (_textureCache) { CFRelease(_textureCache);