Skip to content

Commit

Permalink
Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u …
Browse files Browse the repository at this point in the history
…SDK.

sigh.
  • Loading branch information
icculus committed Sep 16, 2011
1 parent 75c93a1 commit 9fbe67b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.h
Expand Up @@ -86,6 +86,7 @@ CGLContextObj QZ_GetCGLContextObj(NSOpenGLContext *nsctx);

/* Main driver structure to store required state information */
typedef struct SDL_PrivateVideoData {
BOOL use_new_mode_apis; /* 1 == >= 10.6 APIs available */
BOOL allow_screensaver; /* 0 == disable screensaver */
CGDirectDisplayID display; /* 0 == main display (only support single display) */
const void *mode; /* current mode of the display */
Expand Down Expand Up @@ -127,6 +128,7 @@ typedef struct SDL_PrivateVideoData {
#define display_id (this->hidden->display)
#define mode (this->hidden->mode)
#define save_mode (this->hidden->save_mode)
#define use_new_mode_apis (this->hidden->use_new_mode_apis)
#define allow_screensaver (this->hidden->allow_screensaver)
#define palette (this->hidden->palette)
#define gl_context (this->hidden->gl_context)
Expand Down
30 changes: 18 additions & 12 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -127,7 +127,7 @@ static void QZ_ReleaseDisplayMode(_THIS, const void *moderef)
{
/* we only own these references in the 10.6+ API. */
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
CGDisplayModeRelease((CGDisplayModeRef) moderef);
}
#endif
Expand All @@ -137,7 +137,7 @@ static void QZ_ReleaseDisplayModeList(_THIS, CFArrayRef mode_list)
{
/* we only own these references in the 10.6+ API. */
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
CFRelease(mode_list);
}
#endif
Expand Down Expand Up @@ -239,7 +239,7 @@ static void QZ_GetModeInfo(_THIS, const void *_mode, Uint32 *w, Uint32 *h, Uint3
}

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
CGDisplayModeRef vidmode = (CGDisplayModeRef) _mode;
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);

Expand All @@ -257,7 +257,7 @@ static void QZ_GetModeInfo(_THIS, const void *_mode, Uint32 *w, Uint32 *h, Uint3
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
if (!use_new_mode_apis) {
CFDictionaryRef vidmode = (CFDictionaryRef) _mode;
CFNumberGetValue (
CFDictionaryGetValue (vidmode, kCGDisplayBitsPerPixel),
Expand Down Expand Up @@ -287,6 +287,12 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
system_version = 0;

use_new_mode_apis = NO;

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
use_new_mode_apis = IS_SNOW_LEOPARD_OR_LATER(this);
#endif

/* Initialize the video settings; this data persists between mode switches */
display_id = kCGDirectMainDisplay;

Expand All @@ -304,13 +310,13 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
#endif

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
save_mode = CGDisplayCopyDisplayMode(display_id);
}
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
if (!use_new_mode_apis) {
save_mode = CGDisplayCurrentMode(display_id);
}
#endif
Expand Down Expand Up @@ -394,13 +400,13 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
}

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
}
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
if (!use_new_mode_apis) {
mode_list = CGDisplayAvailableModes(display_id);
}
#endif
Expand Down Expand Up @@ -498,13 +504,13 @@ static SDL_bool QZ_WindowPosition(_THIS, int *x, int *y)
static CGError QZ_SetDisplayMode(_THIS, const void *vidmode)
{
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
return CGDisplaySetDisplayMode(display_id, (CGDisplayModeRef) vidmode, NULL);
}
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
if (!use_new_mode_apis) {
return CGDisplaySwitchToMode(display_id, (CFDictionaryRef) vidmode);
}
#endif
Expand Down Expand Up @@ -606,7 +612,7 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
}

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
if (IS_SNOW_LEOPARD_OR_LATER(this)) {
if (use_new_mode_apis) {
/* apparently, we have to roll our own now. :/ */
CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
if (mode_list != NULL) {
Expand All @@ -630,7 +636,7 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
if (!use_new_mode_apis) {
boolean_t exact = 0;
best = CGDisplayBestModeForParameters(display_id, bpp, w, h, &exact);
if (!exact) {
Expand Down

0 comments on commit 9fbe67b

Please sign in to comment.