Adds some OS X availability macros to support 10.5 SDK. Not foolproof but good enough for now.
This was SVN commit r11757.
This commit is contained in:
parent
7fcc350df9
commit
ffc89ee1af
@ -28,8 +28,10 @@
|
||||
#include "lib/sysdep/gfx.h"
|
||||
#include "osx_bundle.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <mach-o/dyld.h> // _NSGetExecutablePath
|
||||
|
||||
|
||||
// "copy" text into the clipboard. replaces previous contents.
|
||||
@ -63,9 +65,11 @@ namespace gfx {
|
||||
|
||||
Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
|
||||
{
|
||||
// TODO: This breaks 10.5 compatibility, as CGDisplayCopyDisplayMode
|
||||
// and CGDisplayModeCopyPixelEncoding were not available
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
|
||||
#else
|
||||
CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
|
||||
#endif
|
||||
|
||||
if(xres)
|
||||
*xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay);
|
||||
@ -75,6 +79,7 @@ Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
|
||||
|
||||
if(bpp)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// CGDisplayBitsPerPixel was deprecated in OS X 10.6
|
||||
CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode);
|
||||
if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
||||
@ -88,13 +93,26 @@ Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
|
||||
|
||||
// We're responsible for this
|
||||
CFRelease(pixelEncoding);
|
||||
#else
|
||||
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel);
|
||||
CFNumberGetValue(num, kCFNumberIntType, bpp);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(freq)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
*freq = (int)CGDisplayModeGetRefreshRate(currentMode);
|
||||
#else
|
||||
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate);
|
||||
CFNumberGetValue(num, kCFNumberIntType, freq);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// We're responsible for this
|
||||
CGDisplayModeRelease(currentMode);
|
||||
#endif
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <string>
|
||||
|
||||
@ -57,10 +58,14 @@ std::string osx_GetBundlePath()
|
||||
NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
|
||||
if (bundle != nil)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// Retrieve NSURL and convert to POSIX path, then get C-string
|
||||
// encoded as UTF-8, and use it to construct std::string
|
||||
// NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
|
||||
NSString *pathStr = [[bundle bundleURL] path];
|
||||
#else
|
||||
NSString *pathStr = [bundle bundlePath];
|
||||
#endif
|
||||
if (pathStr != nil)
|
||||
{
|
||||
path = std::string([pathStr UTF8String]);
|
||||
@ -79,10 +84,14 @@ std::string osx_GetBundleResourcesPath()
|
||||
NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
|
||||
if (bundle != nil)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// Retrieve NSURL and convert to POSIX path, then get C-string
|
||||
// encoded as UTF-8, and use it to construct std::string
|
||||
// NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
|
||||
NSString *pathStr = [[bundle resourceURL] path];
|
||||
#else
|
||||
NSString *pathStr = [bundle resourcePath];
|
||||
#endif
|
||||
if (pathStr != nil)
|
||||
{
|
||||
path = std::string([pathStr UTF8String]);
|
||||
@ -101,10 +110,14 @@ std::string osx_GetBundleFrameworksPath()
|
||||
NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
|
||||
if (bundle != nil)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// Retrieve NSURL and convert to POSIX path, then get C-string
|
||||
// encoded as UTF-8, and use it to construct std::string
|
||||
// NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
|
||||
NSString *pathStr = [[bundle privateFrameworksURL] path];
|
||||
#else
|
||||
NSString *pathStr = [bundle privateFrameworksPath];
|
||||
#endif
|
||||
if (pathStr != nil)
|
||||
{
|
||||
path = std::string([pathStr UTF8String]);
|
||||
|
@ -20,6 +20,7 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <string>
|
||||
|
||||
@ -31,14 +32,22 @@ static std::string getUserDirectoryPath(NSSearchPathDirectory directory)
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
std::string result;
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// Returns array of NSURL objects which are preferred for file paths
|
||||
NSArray* paths = [[NSFileManager defaultManager] URLsForDirectory:directory inDomains:NSUserDomainMask];
|
||||
#else
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, true);
|
||||
#endif
|
||||
if ([paths count] > 0)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
// Retrieve first NSURL and convert to POSIX path, then get C-string
|
||||
// encoded as UTF-8, and use it to construct std::string
|
||||
// NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
|
||||
NSString* pathStr = [[paths objectAtIndex:0] path];
|
||||
#else
|
||||
NSString* pathStr = [paths objectAtIndex:0];
|
||||
#endif
|
||||
if (pathStr != nil)
|
||||
result = std::string([pathStr UTF8String]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user