For MAINT-2404 Fixes detection of VRAM on OSX removed along with other AGL code. Code Review: callum

master
Graham Madarasz (Graham Linden) 2013-02-27 06:46:53 -08:00
parent 9a85a9d6bf
commit f5516e0fc0
5 changed files with 35 additions and 0 deletions

View File

@ -7,6 +7,9 @@
//
#import <Cocoa/Cocoa.h>
#import <IOKit/IOKitLib.h>
#import <CoreFoundation/CFBase.h>
#import <CoreFoundation/CFNumber.h>
#include "llwindowmacosx-objc.h"
// Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities.
@ -33,6 +36,8 @@
- (CGLContextObj) getCGLContextObj;
- (CGLPixelFormatObj*)getCGLPixelFormatObj;
- (unsigned long) getVramSize;
@end
@interface LLNSWindow : NSWindow {

View File

@ -39,6 +39,28 @@
@implementation LLOpenGLView
- (unsigned long)getVramSize
{
unsigned long vram_bytes = 0;
io_service_t display_port = CGDisplayIOServicePort(kCGDirectMainDisplay);
const void* type_code = IORegistryEntryCreateCFProperty(display_port, CFSTR(kIOFBMemorySizeKey), kCFAllocatorDefault, kNilOptions);
// Ensure we have valid data from IOKit
if(type_code && CFGetTypeID(type_code) == CFNumberGetTypeID())
{
long val;
// Retrieve actual number...is Apple ever embarrassed by this nonsense?
//
CFNumberGetValue((const __CFNumber*)type_code, kCFNumberSInt32Type, &val);
vram_bytes = (unsigned long)val;
CFRelease(type_code);
}
return vram_bytes;
}
- (void)viewDidMoveToWindow
{
[[NSNotificationCenter defaultCenter] addObserver:self

View File

@ -62,6 +62,7 @@ NSWindowRef createNSWindow(int x, int y, int width, int height);
GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync);
void glSwapBuffers(void* context);
CGLContextObj getCGLContextObj(GLViewRef view);
unsigned long getVramSize(GLViewRef view);
void getContentViewBounds(NSWindowRef window, float* bounds);
void getWindowSize(NSWindowRef window, float* size);
void setWindowSize(NSWindowRef window, int width, int height);

View File

@ -237,6 +237,11 @@ CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window)
return [glview getCGLPixelFormatObj];
}
unsigned long getVramSize(GLViewRef view)
{
return [(LLOpenGLView *)view getVramSize];
}
void getContentViewBounds(NSWindowRef window, float* bounds)
{
bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x;

View File

@ -408,6 +408,8 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
mContext = getCGLContextObj(mGLView);
// Since we just created the context, it needs to be set up.
glNeedsInit = TRUE;
gGLManager.mVRAM = getVramSize(mGLView);
}
// Hook up the context to a drawable