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

92 lines
3.2 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-05 13:41:05 -07:00
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/graphics/IOGraphicsLib.h>
2022-09-05 17:42:42 +02:00
void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
{
2022-09-05 13:41:05 -07:00
FF_UNUSED(instance);
2022-09-09 05:40:27 -07:00
const FFCPUResult* cpu = ffDetectCPU();
if(ffStrbufStartsWithIgnCaseS(&cpu->name, "Apple M"))
{
FFGPUResult* gpu = ffListAdd(gpus);
ffStrbufInit(&gpu->vendor);
ffStrbufAppendS(&gpu->vendor, "Apple");
ffStrbufInit(&gpu->name);
ffStrbufAppendS(&gpu->name, cpu->name.chars + 6); //Cut "Apple "
ffStrbufInitA(&gpu->driver, 0);
gpu->temperature = FF_GPU_TEMP_UNSET;
}
2022-09-06 15:42:37 +02:00
void* iokit = dlopen(FASTFETCH_TARGET_DIR_ROOT"/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
2022-09-05 13:41:05 -07:00
if(iokit == NULL)
return;
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceMatching, )
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceGetMatchingServices, )
FF_LIBRARY_LOAD_SYMBOL(iokit, IOIteratorNext, )
2022-09-06 02:28:32 -07:00
FF_LIBRARY_LOAD_SYMBOL(iokit, IORegistryEntryCreateCFProperties, )
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorDefault, )
2022-09-07 06:37:35 -07:00
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorNull, )
2022-09-06 02:28:32 -07:00
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDictionaryGetValue, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFGetTypeID, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringCreateWithCStringNoCopy, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetLength, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetCString, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFRelease, )
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDataGetTypeID, )
2022-09-05 13:41:05 -07:00
FF_LIBRARY_LOAD_SYMBOL(iokit, IOObjectRelease, )
2022-09-08 17:33:29 +02:00
CFMutableDictionaryRef matchDict = ffIOServiceMatching("IOPCIDevice");
2022-09-05 13:41:05 -07:00
io_iterator_t iterator;
2022-09-07 06:37:35 -07:00
if(ffIOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
2022-09-05 13:41:05 -07:00
{
dlclose(iokit);
return;
}
io_registry_entry_t registryEntry;
while((registryEntry = ffIOIteratorNext(iterator)) != 0)
{
2022-09-06 02:28:32 -07:00
CFMutableDictionaryRef properties;
if(ffIORegistryEntryCreateCFProperties(registryEntry, &properties, *ffkCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
{
ffIOObjectRelease(registryEntry);
continue;
}
2022-09-05 13:41:05 -07:00
2022-09-11 02:44:19 -07:00
CFStringRef key = ffCFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, *ffkCFAllocatorNull);
2022-09-06 02:28:32 -07:00
CFStringRef model = ffCFDictionaryGetValue(properties, key);
if(model == NULL || ffCFGetTypeID(model) != ffCFDataGetTypeID())
{
ffCFRelease(properties);
ffIOObjectRelease(registryEntry);
2022-09-05 13:41:05 -07:00
continue;
2022-09-06 02:28:32 -07:00
}
2022-09-05 13:41:05 -07:00
FFGPUResult* gpu = ffListAdd(gpus);
2022-09-07 06:37:35 -07:00
uint32_t modelLength = (uint32_t) ffCFStringGetLength(model);
ffStrbufInitA(&gpu->name, modelLength + 1);
2022-09-11 02:44:19 -07:00
ffCFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
2022-09-07 06:40:47 -07:00
gpu->name.length = modelLength;
gpu->name.chars[gpu->name.length] = '\0';
2022-09-05 13:41:05 -07:00
ffStrbufInitA(&gpu->vendor, 0);
ffStrbufInitA(&gpu->driver, 0);
gpu->temperature = FF_GPU_TEMP_UNSET;
2022-09-06 02:28:32 -07:00
ffCFRelease(properties);
ffIOObjectRelease(registryEntry);
2022-09-05 13:41:05 -07:00
}
ffIOObjectRelease(iterator);
dlclose(iokit);
2022-09-05 17:42:42 +02:00
}