Files
fastfetch/src/detection/gpu/gpu_apple.c
T

49 lines
1.4 KiB
C
Raw Normal View History

2022-09-05 17:42:42 +02:00
#include "gpu.h"
2022-09-05 13:41:05 -07:00
#include "common/library.h"
2022-09-09 05:40:27 -07:00
#include "detection/cpu/cpu.h"
2022-09-16 18:11:39 +08:00
#include "util/apple/cfdict_helpers.h"
2022-09-05 13:41:05 -07:00
#include <IOKit/graphics/IOGraphicsLib.h>
2022-09-05 17:42:42 +02:00
2022-09-16 18:11:39 +08:00
const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
2022-09-05 17:42:42 +02:00
{
2022-09-05 13:41:05 -07:00
FF_UNUSED(instance);
2022-09-16 18:11:39 +08:00
CFMutableDictionaryRef matchDict = IOServiceMatching(kIOAcceleratorClassName);
2022-09-05 13:41:05 -07:00
io_iterator_t iterator;
2022-09-14 14:55:28 +02:00
if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
2022-09-16 18:11:39 +08:00
return "IOServiceGetMatchingServices() failed";
2022-09-05 13:41:05 -07:00
io_registry_entry_t registryEntry;
2022-09-14 14:55:28 +02:00
while((registryEntry = IOIteratorNext(iterator)) != 0)
2022-09-05 13:41:05 -07:00
{
2022-09-06 02:28:32 -07:00
CFMutableDictionaryRef properties;
2022-09-14 14:55:28 +02:00
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
2022-09-06 02:28:32 -07:00
{
2022-09-14 14:55:28 +02:00
IOObjectRelease(registryEntry);
2022-09-06 02:28:32 -07:00
continue;
}
2022-09-05 13:41:05 -07:00
FFGPUResult* gpu = ffListAdd(gpus);
2022-09-16 18:11:39 +08:00
ffStrbufInit(&gpu->name);
ffCfDictGetString(properties, "model", &gpu->name);
if (!ffCfDictGetInt(properties, "gpu-core-count", &gpu->coreCount))
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
2022-09-05 13:41:05 -07:00
ffStrbufInitA(&gpu->vendor, 0);
2022-09-16 18:11:39 +08:00
ffStrbufInit(&gpu->driver);
ffCfDictGetString(properties, "CFBundleIdentifier", &gpu->driver);
2022-09-05 13:41:05 -07:00
gpu->temperature = FF_GPU_TEMP_UNSET;
2022-09-06 02:28:32 -07:00
2022-09-14 14:55:28 +02:00
CFRelease(properties);
IOObjectRelease(registryEntry);
2022-09-05 13:41:05 -07:00
}
2022-09-14 14:55:28 +02:00
IOObjectRelease(iterator);
2022-09-16 18:11:39 +08:00
return NULL;
2022-09-05 17:42:42 +02:00
}