[macos] prefer integrated GPU. (#164569)

Attempted fix for https://github.com/flutter/flutter/issues/163218

There are very few macOS devices with multiple GPUs and they were only
brielfy sold. We seem to have a problem o the specific devices when
choosing the dedicated GPU. INstead, lets try forcing the integrated GPU
when its available.
This commit is contained in:
Jonah Williams 2025-03-04 19:24:27 -08:00 committed by GitHub
parent b771b39813
commit ccf99229c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,10 +38,26 @@ static bool OnAcquireExternalTexture(void* user_data,
FlutterDarwinContextMetalSkia* _darwinMetalContext;
}
namespace {
// Attempts to find the integrated GPU backed metal device.
//
// See also: https://developer.apple.com/documentation/metal/multi-gpu-systems?language=objc
id<MTLDevice> SelectMetalDevice() {
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
for (id<MTLDevice> device in devices) {
if (device.hasUnifiedMemory) {
return device;
}
}
return MTLCreateSystemDefaultDevice();
}
} // namespace
- (instancetype)initWithFlutterEngine:(nonnull FlutterEngine*)flutterEngine {
self = [super initWithDelegate:self engine:flutterEngine];
if (self) {
_device = MTLCreateSystemDefaultDevice();
_device = SelectMetalDevice();
if (!_device) {
NSLog(@"Could not acquire Metal device.");
return nil;