Skip to content

Commit

Permalink
Fix graphics card query (thanks to http://is.gd/D2rSCR)
Browse files Browse the repository at this point in the history
  • Loading branch information
balr0g committed Aug 8, 2012
1 parent de88228 commit d06e588
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
4C1BE0FA159A5FCF00DB3341 /* TPISystemProfiler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C1BE0F8159A5FCF00DB3341 /* TPISystemProfiler.xib */; };
4C57A681131D378900252759 /* TPI_SP_SysInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C57A67E131D378900252759 /* TPI_SP_SysInfo.m */; };
4C57A682131D378900252759 /* TPISystemProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C57A680131D378900252759 /* TPISystemProfiler.m */; };
4C57A695131D37F000252759 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C57A694131D37F000252759 /* OpenGL.framework */; };
4C8884B0158EB9CE00747ABB /* PLWeakCompatibilityStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8884AE158EB9CE00747ABB /* PLWeakCompatibilityStubs.m */; };
4CD69D82131E2BD200F4618E /* MacintoshModels.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4CD69D81131E2BD200F4618E /* MacintoshModels.plist */; };
4CEE0DD112E09A1900C5096E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CEE0DD012E09A1900C5096E /* Cocoa.framework */; };
63EF581515D2D5FE001071C8 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63EF581215D2D57F001071C8 /* IOKit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -24,10 +24,10 @@
4C57A67E131D378900252759 /* TPI_SP_SysInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPI_SP_SysInfo.m; sourceTree = "<group>"; };
4C57A67F131D378900252759 /* TPISystemProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPISystemProfiler.h; sourceTree = "<group>"; };
4C57A680131D378900252759 /* TPISystemProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPISystemProfiler.m; sourceTree = "<group>"; };
4C57A694131D37F000252759 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
4C8884AE158EB9CE00747ABB /* PLWeakCompatibilityStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLWeakCompatibilityStubs.m; sourceTree = "<group>"; };
4CD69D81131E2BD200F4618E /* MacintoshModels.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = MacintoshModels.plist; sourceTree = "<group>"; };
4CEE0DD012E09A1900C5096E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
63EF581215D2D57F001071C8 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
8D576316048677EA00EA77CD /* SystemProfiler.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SystemProfiler.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
8D576317048677EA00EA77CD /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -38,7 +38,7 @@
buildActionMask = 2147483647;
files = (
4CEE0DD112E09A1900C5096E /* Cocoa.framework in Frameworks */,
4C57A695131D37F000252759 /* OpenGL.framework in Frameworks */,
63EF581515D2D5FE001071C8 /* IOKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -59,9 +59,9 @@
089C1671FE841209C02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (
63EF581215D2D57F001071C8 /* IOKit.framework */,
4CEE0DD012E09A1900C5096E /* Cocoa.framework */,
0AA1909FFE8422F4C02AAC07 /* CoreFoundation.framework */,
4C57A694131D37F000252759 /* OpenGL.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down
3 changes: 1 addition & 2 deletions Resources/Plugins/System Profiler/SystemProfiler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <IOKit/IOKitLib.h>

#import "TextualApplication.h"

Expand Down
68 changes: 41 additions & 27 deletions Resources/Plugins/System Profiler/TPI_SP_SysInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -482,34 +482,48 @@ + (NSString *)applicationMemoryUsage

+ (NSString *)graphicsCardInfo
{
CGDirectDisplayID displayID = CGMainDisplayID();
CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);

GLint numPixelFormats = 0;

CGLContextObj cglContext = 0;
CGLPixelFormatObj pixelFormat = NULL;
CGLContextObj curr_ctx = CGLGetCurrentContext();

#pragma unused(curr_ctx)

CGLPixelFormatAttribute attribs[] = {kCGLPFADisplayMask, displayMask, 0};
CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats);

if (pixelFormat) {
CGLCreateContext(pixelFormat, NULL, &cglContext);

CGLDestroyPixelFormat(pixelFormat);
CGLSetCurrentContext(cglContext);

if (cglContext) {
NSString *model = @((const char *)glGetString(GL_RENDERER));
CFMutableDictionaryRef pciDevices = IOServiceMatching("IOPCIDevice");
io_iterator_t entry_iterator;
if(IOServiceGetMatchingServices(kIOMasterPortDefault,
pciDevices,
&entry_iterator) == kIOReturnSuccess)
{
NSMutableArray *gpuList = [[NSMutableArray alloc] init];
io_iterator_t serviceObject;
while ((serviceObject = IOIteratorNext(entry_iterator))) {
CFMutableDictionaryRef serviceDictionary;
if (IORegistryEntryCreateCFProperties(serviceObject,
&serviceDictionary,
kCFAllocatorDefault,
kNilOptions) != kIOReturnSuccess)
{
IOObjectRelease(serviceObject);
continue;
}

return [model stringByReplacingOccurrencesOfString:@" OpenGL Engine" withString:NSStringEmptyPlaceholder];
}
}

return nil;
const void *model = CFDictionaryGetValue(serviceDictionary, @"model");
if (model != nil) {
if (CFGetTypeID(model) == CFDataGetTypeID()) {
NSString *s = [[NSString alloc] initWithData:(__bridge NSData *)model
encoding:NSASCIIStringEncoding];
[gpuList addObject:s];
}
}

CFRelease(serviceDictionary);
}
NSString *res = [[NSString alloc] init];
for(int i=0; i < [gpuList count]; i++)
{
res = [res stringByAppendingString:[gpuList objectAtIndex:i]];
if(i + 1 < [gpuList count])
{
res = [res stringByAppendingString:@", "];
}
}
return res;
}
return nil;
}

+ (NSString *)diskInfo
Expand Down

0 comments on commit d06e588

Please sign in to comment.