Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
GrContext single ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Feb 5, 2021
1 parent 6fe1c8e commit 4c86f57
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)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.";
Expand All @@ -77,6 +72,16 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
return self;
}

- (sk_sp<GrDirectContext>)createGrContext {
auto contextOptions = CreateMetalGrContextOptions();
id<MTLDevice> device = _device;
id<MTLCommandQueue> 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);
Expand Down

0 comments on commit 4c86f57

Please sign in to comment.