src/video/quartz/SDL_QuartzVideo.m
author Sam Lantinga <slouken@libsdl.org>
Sat, 07 Jan 2012 13:52:10 -0500
branchSDL-1.2
changeset 6173 5619adf4736d
parent 6158 6f3a2bb301d6
child 6228 adbb020cb5a2
permissions -rw-r--r--
Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7 amaranth72@gmail.com 2012-01-07 01:28:40 PST Using the latest Hg tip of SDL 1.2, SDL_SetVideoMode will fail with the SDL_OPENGL and SDL_FULLSCREEN flags set if the computer is running Lion and the build deployment target version is lower than 10.7. The issue seems to be at line 840 of SDL_QuartzVideo.m, where it checks if the minimum required version is less than 10.7. If that condition is true, then it uses the pre-Lion fullscreen method, even though the condition doesn't seem to say anything about whether the computer is currently running Lion or not. I tried doing this inside the #if conditional check (pseudocode): if (isLion) { do new Lion stuff } else { do old stuff } , and that seemed to work fine. An "invalid fullscreen drawable" warning was still around even though fullscreen worked with the new addition, but I think that's because Lion wants SDL to add a new Spaces thing when it goes fullscreen.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
6137
4720145f848b Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6134
diff changeset
     3
    Copyright (C) 1997-2012  Sam Lantinga
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    13
    Library General Public License for more details.
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 197
diff changeset
    20
    slouken@libsdl.org
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
1403
376665398b25 Catch the C++ and Objective C sources too...
Sam Lantinga <slouken@libsdl.org>
parents: 1340
diff changeset
    22
#include "SDL_config.h"
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#include "SDL_QuartzVideo.h"
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    25
#include "SDL_QuartzWindow.h"
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
6049
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    27
/* These APIs aren't just deprecated; they're gone from the headers in the
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    28
   10.7 SDK. If we're using a >= 10.7 SDK, but targeting < 10.7, then we
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    29
   force these function declarations. */
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    30
#if ((MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070))
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    31
CG_EXTERN void *CGDisplayBaseAddress(CGDirectDisplayID display)
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    32
  CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_6,
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    33
    __IPHONE_NA, __IPHONE_NA);
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    34
CG_EXTERN size_t CGDisplayBytesPerRow(CGDirectDisplayID display)
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    35
  CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_6,
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    36
    __IPHONE_NA, __IPHONE_NA);
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    37
#endif
4b79fd1fd9a3 Fix compiler warning on Mac OS X, when targeting old OS with new SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 6048
diff changeset
    38
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    39
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    40
static inline BOOL IS_LION_OR_LATER(_THIS)
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    41
{
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    42
    return (system_version >= 0x1070);
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    43
}
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    44
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    45
static inline BOOL IS_SNOW_LEOPARD_OR_LATER(_THIS)
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    46
{
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    47
    return (system_version >= 0x1060);
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    48
}
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    49
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    50
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) && !defined(__LP64__)  /* Fixed in Snow Leopard */
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    51
/*
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    52
    Add methods to get at private members of NSScreen. 
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    53
    Since there is a bug in Apple's screen switching code
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    54
    that does not update this variable when switching
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    55
    to fullscreen, we'll set it manually (but only for the
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    56
    main screen).
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    57
*/
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    58
@interface NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    59
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    60
@end
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    61
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    62
@implementation NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    63
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    64
{
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    65
    _frame = frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    66
}
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    67
@end
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    68
static inline void QZ_SetFrame(_THIS, NSScreen *nsscreen, NSRect frame)
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    69
{
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    70
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    71
        [nsscreen setFrame:frame];
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    72
    }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    73
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    74
#else
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
    75
static inline void QZ_SetFrame(_THIS, NSScreen *nsscreen, NSRect frame)
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    76
{
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    77
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    78
#endif
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    79
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    80
@interface SDLTranslatorResponder : NSTextView
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    81
{
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    82
}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    83
- (void) doCommandBySelector:(SEL)myselector;
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    84
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    85
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    86
@implementation SDLTranslatorResponder
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    87
- (void) doCommandBySelector:(SEL) myselector {}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    88
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    89
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    90
/* absent in 10.3.9.  */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    91
CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    92
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    93
/* Bootstrap functions */
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    94
static int              QZ_Available ();
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    95
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    96
static void             QZ_DeleteDevice (SDL_VideoDevice *device);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    97
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    98
/* Initialization, Query, Setup, and Redrawing functions */
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    99
static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   100
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   101
static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   102
                                         Uint32 flags);
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   103
static void         QZ_UnsetVideoMode   (_THIS, BOOL to_desktop, BOOL save_gl);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   104
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   105
static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   106
                                         int width, int height, int bpp,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   107
                                         Uint32 flags);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   108
static int          QZ_ToggleFullScreen (_THIS, int on);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   109
static int          QZ_SetColors        (_THIS, int first_color,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   110
                                         int num_colors, SDL_Color *colors);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   111
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   112
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   113
static int          QZ_LockDoubleBuffer   (_THIS, SDL_Surface *surface);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   114
static void         QZ_UnlockDoubleBuffer (_THIS, SDL_Surface *surface);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   115
static int          QZ_ThreadFlip         (_THIS);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   116
static int          QZ_FlipDoubleBuffer   (_THIS, SDL_Surface *surface);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   117
static void         QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   118
static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   119
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   120
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   121
static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   122
static void         QZ_VideoQuit        (_THIS);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   123
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   124
static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   125
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
1120
8e1fde455471 Patch by me to fix crash described below.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   126
static int QZ_AllocHWSurface(_THIS, SDL_Surface *surface);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   127
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   128
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   129
/* Bootstrap binding, enables entry point into the driver */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   130
VideoBootStrap QZ_bootstrap = {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   131
    "Quartz", "Mac OS X CoreGraphics", QZ_Available, QZ_CreateDevice
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
};
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   133
5909
f99f59413a14 Attempt to quiet unavoidable compiler warnings on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 5908
diff changeset
   134
/* Disable compiler warnings we can't avoid. */
f99f59413a14 Attempt to quiet unavoidable compiler warnings on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 5908
diff changeset
   135
#if (defined(__GNUC__) && (__GNUC__ >= 4))
5910
87fa93acf216 Mac OS X deprecation cleanup: maybe this SDK test is better...?
Ryan C. Gordon <icculus@icculus.org>
parents: 5909
diff changeset
   136
#  if (MAC_OS_X_VERSION_MAX_ALLOWED <= 1070)
87fa93acf216 Mac OS X deprecation cleanup: maybe this SDK test is better...?
Ryan C. Gordon <icculus@icculus.org>
parents: 5909
diff changeset
   137
#    pragma GCC diagnostic ignored "-Wdeprecated-declarations"
5909
f99f59413a14 Attempt to quiet unavoidable compiler warnings on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 5908
diff changeset
   138
#  endif
f99f59413a14 Attempt to quiet unavoidable compiler warnings on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 5908
diff changeset
   139
#endif
f99f59413a14 Attempt to quiet unavoidable compiler warnings on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 5908
diff changeset
   140
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   141
static void QZ_ReleaseDisplayMode(_THIS, const void *moderef)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   142
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   143
    /* we only own these references in the 10.6+ API. */
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   144
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   145
    if (use_new_mode_apis) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   146
        CGDisplayModeRelease((CGDisplayModeRef) moderef);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   147
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   148
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   149
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   150
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   151
static void QZ_ReleaseDisplayModeList(_THIS, CFArrayRef mode_list)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   152
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   153
    /* we only own these references in the 10.6+ API. */
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   154
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   155
    if (use_new_mode_apis) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   156
        CFRelease(mode_list);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   157
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   158
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   159
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   160
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   161
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
/* Bootstrap functions */
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   163
static int QZ_Available ()
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   164
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
    return 1;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   168
static SDL_VideoDevice* QZ_CreateDevice (int device_index)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   169
{
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   170
#pragma unused (device_index)
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
    SDL_VideoDevice *device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
    SDL_PrivateVideoData *hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   175
    device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   176
    hidden = (SDL_PrivateVideoData*) SDL_malloc (sizeof (*hidden) );
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
    if (device == NULL || hidden == NULL)
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
        SDL_OutOfMemory ();
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   181
    SDL_memset (device, 0, sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   182
    SDL_memset (hidden, 0, sizeof (*hidden) );
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   183
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
    device->hidden = hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
    device->VideoInit        = QZ_VideoInit;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
    device->ListModes        = QZ_ListModes;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
    device->SetVideoMode     = QZ_SetVideoMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
    device->ToggleFullScreen = QZ_ToggleFullScreen;
1212
7663bb0f52c7 To: sdl@libsdl.org
Ryan C. Gordon <icculus@icculus.org>
parents: 1189
diff changeset
   190
    device->UpdateMouse      = QZ_UpdateMouse;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
    device->SetColors        = QZ_SetColors;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   192
    /* device->UpdateRects      = QZ_UpdateRects; this is determined by SetVideoMode() */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
    device->VideoQuit        = QZ_VideoQuit;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   194
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
    device->LockHWSurface   = QZ_LockHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
    device->UnlockHWSurface = QZ_UnlockHWSurface;
1120
8e1fde455471 Patch by me to fix crash described below.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   197
    device->AllocHWSurface   = QZ_AllocHWSurface;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
    device->FreeHWSurface   = QZ_FreeHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
    device->SetGamma     = QZ_SetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
    device->GetGamma     = QZ_GetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
    device->SetGammaRamp = QZ_SetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
    device->GetGammaRamp = QZ_GetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   204
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
    device->GL_GetProcAddress = QZ_GL_GetProcAddress;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   206
    device->GL_GetAttribute   = QZ_GL_GetAttribute;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   207
    device->GL_MakeCurrent    = QZ_GL_MakeCurrent;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
    device->GL_SwapBuffers    = QZ_GL_SwapBuffers;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   209
    device->GL_LoadLibrary    = QZ_GL_LoadLibrary;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   210
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   211
    device->FreeWMCursor   = QZ_FreeWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   212
    device->CreateWMCursor = QZ_CreateWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   213
    device->ShowWMCursor   = QZ_ShowWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   214
    device->WarpWMCursor   = QZ_WarpWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
    device->MoveWMCursor   = QZ_MoveWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
    device->CheckMouseMode = QZ_CheckMouseMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   217
    device->InitOSKeymap   = QZ_InitOSKeymap;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   218
    device->PumpEvents     = QZ_PumpEvents;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   219
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   220
    device->SetCaption    = QZ_SetCaption;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   221
    device->SetIcon       = QZ_SetIcon;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   222
    device->IconifyWindow = QZ_IconifyWindow;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   223
    /*device->GetWMInfo     = QZ_GetWMInfo;*/
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   224
    device->GrabInput     = QZ_GrabInput;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   225
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   226
    /*
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   227
     * This is a big hassle, needing QuickDraw and QuickTime on older
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   228
     *  systems, and god knows what on 10.6, so we immediately fail here,
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   229
     *  which causes SDL to make an RGB surface and manage the YUV overlay
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   230
     *  in software. Sorry. Use SDL 1.3 if you want YUV rendering in a pixel
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   231
     *  shader.  :)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   232
     */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   233
    /*device->CreateYUVOverlay = QZ_CreateYUVOverlay;*/
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   234
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   235
    device->free             = QZ_DeleteDevice;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   236
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   237
    return device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   239
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   240
static void QZ_DeleteDevice (SDL_VideoDevice *device)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   241
{
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   242
    _THIS = device;
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   243
    QZ_ReleaseDisplayMode(this, save_mode);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   244
    QZ_ReleaseDisplayMode(this, mode);
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   245
    SDL_free (device->hidden);
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   246
    SDL_free (device);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   247
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   248
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   249
static void QZ_GetModeInfo(_THIS, const void *_mode, Uint32 *w, Uint32 *h, Uint32 *bpp)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   250
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   251
    *w = *h = *bpp = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   252
    if (_mode == NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   253
        return;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   254
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   255
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   256
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   257
    if (use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   258
        CGDisplayModeRef vidmode = (CGDisplayModeRef) _mode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   259
        CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   260
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   261
        *w = (Uint32) CGDisplayModeGetWidth(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   262
        *h = (Uint32) CGDisplayModeGetHeight(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   263
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   264
        /* we only care about the 32-bit modes... */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   265
        if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   266
                            kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   267
            *bpp = 32;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   268
        }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   269
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   270
        CFRelease(fmt);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   271
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   272
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   273
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   274
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   275
    if (!use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   276
        CFDictionaryRef vidmode = (CFDictionaryRef) _mode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   277
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   278
            CFDictionaryGetValue (vidmode, kCGDisplayBitsPerPixel),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   279
            kCFNumberSInt32Type, bpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   280
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   281
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   282
            CFDictionaryGetValue (vidmode, kCGDisplayWidth),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   283
            kCFNumberSInt32Type, w);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   284
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   285
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   286
            CFDictionaryGetValue (vidmode, kCGDisplayHeight),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   287
            kCFNumberSInt32Type, h);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   288
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   289
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   290
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   291
    /* we only care about the 32-bit modes... */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   292
    if (*bpp != 32) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   293
        *bpp = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   294
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   295
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   296
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   297
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   298
{
4049
60f677630282 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 3936
diff changeset
   299
    NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   300
    const char *env = NULL;
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   301
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   302
    if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   303
        system_version = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   304
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   305
    use_new_mode_apis = NO;
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   306
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   307
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   308
    use_new_mode_apis = IS_SNOW_LEOPARD_OR_LATER(this);
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   309
#endif
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   310
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   311
    /* Initialize the video settings; this data persists between mode switches */
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   312
    display_id = kCGDirectMainDisplay;
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   313
4319
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   314
#if 0 /* The mouse event code needs to take this into account... */
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   315
    env = getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   316
    if ( env ) {
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   317
        int monitor = SDL_atoi(env);
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   318
    	CGDirectDisplayID activeDspys [3];
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   319
    	CGDisplayCount dspyCnt;
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   320
    	CGGetActiveDisplayList (3, activeDspys, &dspyCnt);
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   321
        if ( monitor >= 0 && monitor < dspyCnt ) {
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   322
    	    display_id = activeDspys[monitor];
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   323
        }
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   324
    }
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   325
#endif
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   326
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   327
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   328
    if (use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   329
        save_mode = CGDisplayCopyDisplayMode(display_id);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   330
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   331
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   332
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   333
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   334
    if (!use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   335
        save_mode = CGDisplayCurrentMode(display_id);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   336
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   337
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   338
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   339
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   340
    if (!IS_LION_OR_LATER(this)) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   341
        palette = CGPaletteCreateDefaultColorPalette();
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   342
    }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   343
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   344
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   345
    if (save_mode == NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   346
        SDL_SetError("Couldn't figure out current display mode.");
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   347
        return -1;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   348
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   349
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   350
    /* Allow environment override of screensaver disable. */
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   351
    env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   352
    if ( env ) {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   353
        allow_screensaver = SDL_atoi(env);
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   354
    } else {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   355
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   356
        allow_screensaver = 0;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   357
#else
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   358
        allow_screensaver = 1;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   359
#endif
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   360
    }
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   361
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   362
    /* Gather some information that is useful to know about the display */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   363
    QZ_GetModeInfo(this, save_mode, &device_width, &device_height, &device_bpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   364
    if (device_bpp == 0) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   365
        QZ_ReleaseDisplayMode(this, save_mode);
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   366
        save_mode = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   367
        SDL_SetError("Unsupported display mode");
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   368
        return -1;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   369
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   370
1545
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   371
    /* Determine the current screen size */
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   372
    this->info.current_w = device_width;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   373
    this->info.current_h = device_height;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   374
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   375
    /* Determine the default screen depth */
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   376
    video_format->BitsPerPixel = device_bpp;
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   377
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   378
    /* Set misc globals */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   379
    current_grab_mode = SDL_GRAB_OFF;
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   380
    cursor_should_be_visible    = YES;
779
68c8da837fc0 Date: Tue, 6 Jan 2004 21:54:02 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 768
diff changeset
   381
    cursor_visible              = YES;
823
d67e76f25874 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 816
diff changeset
   382
    current_mods = 0;
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
   383
    field_edit =  [[SDLTranslatorResponder alloc] initWithFrame:r];
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   384
555
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   385
    /* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   386
    QZ_RegisterForSleepNotifications (this);
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   387
    
1271
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   388
    /* Fill in some window manager capabilities */
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   389
    this->info.wm_available = 1;
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   390
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   391
    return 0;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   394
static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   395
{
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   396
    CFArrayRef mode_list = NULL;          /* list of available fullscreen modes */
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   397
    CFIndex num_modes;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   398
    CFIndex i;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   399
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   400
    int list_size = 0;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   401
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   402
    /* Any windowed mode is acceptable */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   403
    if ( (flags & SDL_FULLSCREEN) == 0 )
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   404
        return (SDL_Rect**)-1;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   405
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   406
    /* Free memory from previous call, if any */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   407
    if ( client_mode_list != NULL ) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   408
        int i;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   409
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   410
        for (i = 0; client_mode_list[i] != NULL; i++)
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   411
            SDL_free (client_mode_list[i]);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   412
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   413
        SDL_free (client_mode_list);
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   414
        client_mode_list = NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   415
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   416
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   417
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   418
    if (use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   419
        mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   420
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   421
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   422
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   423
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   424
    if (!use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   425
        mode_list = CGDisplayAvailableModes(display_id);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   426
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   427
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   428
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   429
    num_modes = CFArrayGetCount (mode_list);
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   430
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   431
    /* Build list of modes with the requested bpp */
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   432
    for (i = 0; i < num_modes; i++) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   433
        Uint32 width, height, bpp;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   434
        const void *onemode = CFArrayGetValueAtIndex(mode_list, i);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   435
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   436
        QZ_GetModeInfo(this, onemode, &width, &height, &bpp);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   437
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   438
        if (bpp && (bpp == format->BitsPerPixel)) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   439
            int hasMode = SDL_FALSE;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   440
            int i;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   441
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   442
            /* Check if mode is already in the list */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   443
            for (i = 0; i < list_size; i++) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   444
                if (client_mode_list[i]->w == width &&
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   445
                    client_mode_list[i]->h == height) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   446
                        hasMode = SDL_TRUE;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   447
                        break;
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   448
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   449
            }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   450
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   451
            /* Grow the list and add mode to the list */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   452
            if ( ! hasMode ) {
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   453
                SDL_Rect *rect;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   454
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   455
                list_size++;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   456
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   457
                if (client_mode_list == NULL)
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   458
                    client_mode_list = (SDL_Rect**) 
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   459
                        SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   460
                else {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   461
                    /* !!! FIXME: this leaks memory if SDL_realloc() fails! */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   462
                    client_mode_list = (SDL_Rect**)
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   463
                        SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   464
                }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   465
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   466
                rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   467
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   468
                if (client_mode_list == NULL || rect == NULL) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   469
                    QZ_ReleaseDisplayModeList(this, mode_list);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   470
                    SDL_OutOfMemory ();
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   471
                    return NULL;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   472
                }
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   473
1218
057d313e36a2 Quartz target: set x and y field of mode list to 0 in SDL_ListMode call.
Ryan C. Gordon <icculus@icculus.org>
parents: 1212
diff changeset
   474
                rect->x = rect->y = 0;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   475
                rect->w = width;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   476
                rect->h = height;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   477
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   478
                client_mode_list[list_size-1] = rect;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   479
                client_mode_list[list_size]   = NULL;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   480
            }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   481
        }
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   482
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   483
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   484
    QZ_ReleaseDisplayModeList(this, mode_list);
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   485
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   486
    /* Sort list largest to smallest (by area) */
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   487
    {
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   488
        int i, j;
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   489
        for (i = 0; i < list_size; i++) {
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   490
            for (j = 0; j < list_size-1; j++) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   491
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   492
                int area1, area2;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   493
                area1 = client_mode_list[j]->w * client_mode_list[j]->h;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   494
                area2 = client_mode_list[j+1]->w * client_mode_list[j+1]->h;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   495
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   496
                if (area1 < area2) {
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   497
                    SDL_Rect *tmp = client_mode_list[j];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   498
                    client_mode_list[j] = client_mode_list[j+1];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   499
                    client_mode_list[j+1] = tmp;
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   500
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   501
            }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   502
        }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   503
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   504
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   505
    return client_mode_list;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   506
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   507
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   508
static SDL_bool QZ_WindowPosition(_THIS, int *x, int *y)
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   509
{
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   510
    const char *window = getenv("SDL_VIDEO_WINDOW_POS");
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   511
    if ( window ) {
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   512
        if ( sscanf(window, "%d,%d", x, y) == 2 ) {
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   513
            return SDL_TRUE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   514
        }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   515
    }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   516
    return SDL_FALSE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   517
}
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   518
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   519
static CGError QZ_SetDisplayMode(_THIS, const void *vidmode)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   520
{
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   521
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   522
    if (use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   523
        return CGDisplaySetDisplayMode(display_id, (CGDisplayModeRef) vidmode, NULL);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   524
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   525
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   526
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   527
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   528
    if (!use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   529
        return CGDisplaySwitchToMode(display_id, (CFDictionaryRef) vidmode);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   530
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   531
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   532
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   533
    return kCGErrorFailure;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   534
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   535
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   536
static inline CGError QZ_RestoreDisplayMode(_THIS)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   537
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   538
    return QZ_SetDisplayMode(this, save_mode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   539
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   540
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   541
static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop, BOOL save_gl)
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   542
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   543
    /* Reset values that may change between switches */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   544
    this->info.blit_fill  = 0;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   545
    this->FillHWRect      = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   546
    this->UpdateRects     = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   547
    this->LockHWSurface   = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   548
    this->UnlockHWSurface = NULL;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   549
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   550
    if (cg_context) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   551
        CGContextFlush (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   552
        CGContextRelease (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   553
        cg_context = nil;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   554
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   555
    
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   556
    /* Release fullscreen resources */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   557
    if ( mode_flags & SDL_FULLSCREEN ) {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   558
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   559
        NSRect screen_rect;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   560
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   561
        /*  Release double buffer stuff */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   562
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   563
        if ( !IS_LION_OR_LATER(this) && (mode_flags & SDL_DOUBLEBUF) ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   564
            quit_thread = YES;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   565
            SDL_SemPost (sem1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   566
            SDL_WaitThread (thread, NULL);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   567
            SDL_DestroySemaphore (sem1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   568
            SDL_DestroySemaphore (sem2);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   569
            SDL_free (sw_buffers[0]);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   570
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   571
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   572
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   573
        /* If we still have a valid window, close it. */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   574
        if ( qz_window ) {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   575
            NSCAssert([ qz_window delegate ] == nil, @"full screen window shouldn't have a delegate"); /* if that should ever change, we'd have to release it here */
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   576
            [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   577
            qz_window = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   578
            window_view = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   579
        }
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   580
        /* 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   581
            Release the OpenGL context
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   582
            Do this first to avoid trash on the display before fade
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   583
        */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   584
        if ( mode_flags & SDL_OPENGL ) {
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   585
            if (!save_gl) {
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   586
                QZ_TearDownOpenGL (this);
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   587
            }
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   588
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   589
            #ifdef __powerpc__  /* we only use this for pre-10.3 compatibility. */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   590
            CGLSetFullScreen (NULL);
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   591
            #endif
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   592
        }
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   593
        if (to_desktop) {
5986
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   594
            /* !!! FIXME: keep an eye on this.
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   595
             * This API is officially unavailable for 64-bit binaries.
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   596
             *  It happens to work, as of 10.7, but we're going to see if
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   597
             *  we can just simply do without it on newer OSes...
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   598
             */
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   599
            #if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   600
            if ( !IS_LION_OR_LATER(this) ) {
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   601
                ShowMenuBar ();
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   602
            }
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   603
            #endif
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   604
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   605
            /* Restore original screen resolution/bpp */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   606
            QZ_RestoreDisplayMode (this);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   607
            CGReleaseAllDisplays ();
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   608
            /* 
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   609
                Reset the main screen's rectangle
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   610
                See comment in QZ_SetVideoFullscreen for why we do this
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   611
            */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   612
            screen_rect = NSMakeRect(0,0,device_width,device_height);
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
   613
            QZ_SetFrame(this, [ NSScreen mainScreen ], screen_rect);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   614
        }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   615
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   616
    /* Release window mode resources */
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   617
    else {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   618
        id delegate = [ qz_window delegate ];
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   619
        [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   620
        if (delegate != nil) [ delegate release ];
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   621
        qz_window = nil;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   622
        window_view = nil;
1160
72c6c3e5bb85 Closed a memory leak caused when quitting video subsystem on Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 1144
diff changeset
   623
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   624
        /* Release the OpenGL context */
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   625
        if ( mode_flags & SDL_OPENGL ) {
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   626
            if (!save_gl) {
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   627
                QZ_TearDownOpenGL (this);
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   628
            }
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   629
        }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   630
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   631
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   632
    /* Signal successful teardown */
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   633
    video_set = SDL_FALSE;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   634
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   635
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   636
static const void *QZ_BestMode(_THIS, const int bpp, const int w, const int h)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   637
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   638
    const void *best = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   639
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   640
    if (bpp == 0) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   641
        return NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   642
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   643
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   644
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   645
    if (use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   646
        /* apparently, we have to roll our own now. :/ */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   647
        CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   648
        if (mode_list != NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   649
            const CFIndex num_modes = CFArrayGetCount(mode_list);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   650
            CFIndex i;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   651
            for (i = 0; i < num_modes; i++) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   652
                const void *vidmode = CFArrayGetValueAtIndex(mode_list, i);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   653
                Uint32 thisw, thish, thisbpp;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   654
                QZ_GetModeInfo(this, vidmode, &thisw, &thish, &thisbpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   655
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   656
                /* We only care about exact matches, apparently. */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   657
                if ((thisbpp == bpp) && (thisw == w) && (thish == h)) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   658
                    best = vidmode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   659
                    break;  /* got it! */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   660
                }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   661
            }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   662
            CGDisplayModeRetain((CGDisplayModeRef) best);  /* NULL is ok */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   663
            CFRelease(mode_list);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   664
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   665
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   666
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   667
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   668
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5945
3868f2e09b12 Make SDL-1.2 Quartz target to work on Lion when built with the 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5913
diff changeset
   669
    if (!use_new_mode_apis) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   670
        boolean_t exact = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   671
        best = CGDisplayBestModeForParameters(display_id, bpp, w, h, &exact);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   672
        if (!exact) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   673
            best = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   674
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   675
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   676
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   677
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   678
    return best;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   679
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   680
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   681
static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   682
                                           int height, int bpp, Uint32 flags,
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   683
                                           const BOOL save_gl)
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   684
{
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   685
    const BOOL isLion = IS_LION_OR_LATER(this);
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   686
    NSRect screen_rect;
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   687
    CGError error;
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   688
    NSRect contentRect;
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   689
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   690
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   691
    current->flags = SDL_FULLSCREEN;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   692
    current->w = width;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   693
    current->h = height;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   694
4442
31b0f2e06e3c SDL-1.2: Quartz fullscreen video contentRect was used uninitialized.
Ryan C. Gordon <icculus@icculus.org>
parents: 4389
diff changeset
   695
    contentRect = NSMakeRect (0, 0, width, height);
31b0f2e06e3c SDL-1.2: Quartz fullscreen video contentRect was used uninitialized.
Ryan C. Gordon <icculus@icculus.org>
parents: 4389
diff changeset
   696
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   697
    /* Fade to black to hide resolution-switching flicker (and garbage
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   698
       that is displayed by a destroyed OpenGL context, if applicable) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   699
    if ( CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   700
        CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   701
    }
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   702
    
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   703
    /* Destroy any previous mode */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   704
    if (video_set == SDL_TRUE)
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   705
        QZ_UnsetVideoMode (this, FALSE, save_gl);
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   706
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   707
    /* Sorry, QuickDraw was ripped out. */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   708
    if (getenv("SDL_NSWindowPointer") || getenv("SDL_NSQuickDrawViewPointer")) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   709
        SDL_SetError ("Embedded QuickDraw windows are no longer supported");
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   710
        goto ERR_NO_MATCH;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   711
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   712
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   713
    QZ_ReleaseDisplayMode(this, mode);  /* NULL is okay. */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   714
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   715
    /* See if requested mode exists */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   716
    mode = QZ_BestMode(this, bpp, width, height);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   717
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   718
    /* Require an exact match to the requested mode */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   719
    if ( mode == NULL ) {
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   720
        SDL_SetError ("Failed to find display resolution: %dx%dx%d", width, height, bpp);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
        goto ERR_NO_MATCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
    }
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   723
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   724
    /* Put up the blanking window (a window above all other windows) */
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   725
    if (getenv ("SDL_SINGLEDISPLAY"))
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   726
        error = CGDisplayCapture (display_id);
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   727
    else
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   728
        error = CGCaptureAllDisplays ();
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   729
        
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   730
    if ( CGDisplayNoErr != error ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   731
        SDL_SetError ("Failed capturing display");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   732
        goto ERR_NO_CAPTURE;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   733
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   734
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
    /* Do the physical switch */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   736
    if ( CGDisplayNoErr != QZ_SetDisplayMode(this, mode) ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   737
        SDL_SetError ("Failed switching display resolution");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   738
        goto ERR_NO_SWITCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   739
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   740
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   741
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   742
    if ( !isLion ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   743
        current->pixels = (Uint32*) CGDisplayBaseAddress (display_id);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   744
        current->pitch  = CGDisplayBytesPerRow (display_id);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   745
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   746
        current->flags |= SDL_HWSURFACE;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   747
        current->flags |= SDL_PREALLOC;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   748
        /* current->hwdata = (void *) CGDisplayGetDrawingContext (display_id); */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   749
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   750
        this->UpdateRects     = QZ_DirectUpdate;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   751
        this->LockHWSurface   = QZ_LockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   752
        this->UnlockHWSurface = QZ_UnlockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   753
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   754
        /* Setup double-buffer emulation */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   755
        if ( flags & SDL_DOUBLEBUF ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   756
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   757
            /*
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   758
            Setup a software backing store for reasonable results when
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   759
            double buffering is requested (since a single-buffered hardware
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   760
            surface looks hideous).
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   761
            
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   762
            The actual screen blit occurs in a separate thread to allow 
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   763
            other blitting while waiting on the VBL (and hence results in higher framerates).
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   764
            */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   765
            this->LockHWSurface = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   766
            this->UnlockHWSurface = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   767
            this->UpdateRects = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   768
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   769
            current->flags |= (SDL_HWSURFACE|SDL_DOUBLEBUF);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   770
            this->UpdateRects = QZ_DoubleBufferUpdate;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   771
            this->LockHWSurface = QZ_LockDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   772
            this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   773
            this->FlipHWSurface = QZ_FlipDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   774
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   775
            current->pixels = SDL_malloc (current->pitch * current->h * 2);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   776
            if (current->pixels == NULL) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   777
                SDL_OutOfMemory ();
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   778
                goto ERR_DOUBLEBUF;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   779
            }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   780
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   781
            sw_buffers[0] = current->pixels;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   782
            sw_buffers[1] = (Uint8*)current->pixels + current->pitch * current->h;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   783
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   784
            quit_thread = NO;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   785
            sem1 = SDL_CreateSemaphore (0);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   786
            sem2 = SDL_CreateSemaphore (1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   787
            thread = SDL_CreateThread ((int (*)(void *))QZ_ThreadFlip, this);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   788
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   789
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   790
        if ( CGDisplayCanSetPalette (display_id) )
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   791
            current->flags |= SDL_HWPALETTE;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   792
    }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   793
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   794
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   795
    /* Check if we should recreate the window */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   796
    if (qz_window == nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   797
        /* Manually create a window, avoids having a nib file resource */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   798
        qz_window = [ [ SDL_QuartzWindow alloc ] 
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   799
            initWithContentRect:contentRect
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   800
                styleMask:(isLion ? NSBorderlessWindowMask : 0)
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   801
                    backing:NSBackingStoreBuffered
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   802
                        defer:NO ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   803
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   804
        if (qz_window != nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   805
            [ qz_window setAcceptsMouseMovedEvents:YES ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   806
            [ qz_window setViewsNeedDisplay:NO ];
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   807
            if (isLion) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   808
                [ qz_window setContentView: [ [ [ SDL_QuartzView alloc ] init ] autorelease ] ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   809
            }
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   810
        }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   811
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   812
    /* We already have a window, just change its size */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   813
    else {
4267
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   814
        [ qz_window setContentSize:contentRect.size ];
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   815
        current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   816
        [ window_view setFrameSize:contentRect.size ];
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   817
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   818
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   819
    /* Setup OpenGL for a fullscreen context */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   820
    if (flags & SDL_OPENGL) {
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   821
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   822
        if ( ! save_gl ) {
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   823
            if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   824
                goto ERR_NO_GL;
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   825
            }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   826
        }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   827
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   828
        /* Initialize the NSView and add it to our window.  The presence of a valid window and
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   829
           view allow the cursor to be changed whilst in fullscreen.*/
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   830
        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   831
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   832
        if ( isLion ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   833
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   834
        }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   835
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   836
        [ [ qz_window contentView ] addSubview:window_view ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   837
5946
19520acd1501 Fixed fullscreen OpenGL on Lion when built with the Mac OS X 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5945
diff changeset
   838
        /* Apparently Lion checks some version flag set by the linker
19520acd1501 Fixed fullscreen OpenGL on Lion when built with the Mac OS X 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5945
diff changeset
   839
           and changes API behavior. Annoying. */
6173
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   840
        if ( isLion ) {
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   841
		[ qz_window setLevel:CGShieldingWindowLevel() ];
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   842
		[ gl_context setView: window_view ];
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   843
		[ gl_context setFullScreen ];
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   844
		[ gl_context update ];
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   845
	} else {
6048
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   846
            CGLError err;
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   847
            CGLContextObj ctx;
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   848
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   849
            [ qz_window setLevel:NSNormalWindowLevel ];
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   850
            ctx = QZ_GetCGLContextObj (gl_context);
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   851
            err = CGLSetFullScreen (ctx);
5946
19520acd1501 Fixed fullscreen OpenGL on Lion when built with the Mac OS X 10.4u SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5945
diff changeset
   852
    
6048
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   853
            if (err) {
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   854
                SDL_SetError ("Error setting OpenGL fullscreen: %s", CGLErrorString(err));
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   855
                goto ERR_NO_GL;
a0538c8c39b5 Fixed a compiler warning when building with Mac OS X target < 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5986
diff changeset
   856
            }
6173
5619adf4736d Fixed bug 1364 - Fullscreen OpenGL fails in OS 10.7 if deployment target is less than 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 6158
diff changeset
   857
	}
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   858
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   859
        [ window_view release ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
        [ gl_context makeCurrentContext];
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   861
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   862
        glClear (GL_COLOR_BUFFER_BIT);
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   863
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   864
        [ gl_context flushBuffer ];
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   865
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   866
        current->flags |= SDL_OPENGL;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   867
    } else if (isLion) {  /* For 2D, we build a CGBitmapContext */
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   868
        CGColorSpaceRef cgColorspace;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   869
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   870
        /* Only recreate the view if it doesn't already exist */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   871
        if (window_view == nil) {
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   872
            window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   873
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   874
            [ [ qz_window contentView ] addSubview:window_view ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   875
            [ window_view release ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   876
        }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   877
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   878
        cgColorspace = CGColorSpaceCreateDeviceRGB();
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   879
        current->pitch = 4 * current->w;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   880
        current->pixels = SDL_malloc (current->h * current->pitch);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   881
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   882
        cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h,
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   883
                        8, current->pitch, cgColorspace,
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   884
                        kCGImageAlphaNoneSkipFirst);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   885
        CGColorSpaceRelease (cgColorspace);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   886
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   887
        current->flags |= SDL_SWSURFACE;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   888
        current->flags |= SDL_ASYNCBLIT;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   889
        current->hwdata = (void *) cg_context;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   890
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   891
        /* Force this window to draw above _everything_. */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   892
        [ qz_window setLevel:CGShieldingWindowLevel() ];
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   893
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   894
        this->UpdateRects     = QZ_UpdateRects;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   895
        this->LockHWSurface   = QZ_LockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   896
        this->UnlockHWSurface = QZ_UnlockHWSurface;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   897
    }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   898
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   899
    if (isLion) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   900
        [ qz_window setHasShadow:NO];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   901
        [ qz_window setOpaque:YES];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   902
        [ qz_window makeKeyAndOrderFront:nil ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   903
    }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   904
5986
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   905
    /* !!! FIXME: keep an eye on this.
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   906
     * This API is officially unavailable for 64-bit binaries.
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   907
     *  It happens to work, as of 10.7, but we're going to see if
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   908
     *  we can just simply do without it on newer OSes...
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   909
     */
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   910
    #if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   911
    if ( !IS_LION_OR_LATER(this) ) {
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   912
        /* If we don't hide menu bar, it will get events and interrupt the program */
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   913
        HideMenuBar ();
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   914
    }
4854219a91e9 Quartz: Only use ShowMenuBar()/HideMenuBar() for legacy OS releases.
Ryan C. Gordon <icculus@icculus.org>
parents: 5946
diff changeset
   915
    #endif
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   916
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   917
    /* Fade in again (asynchronously) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   918
    if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   919
        CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   920
        CGReleaseDisplayFadeReservation(fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   921
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   922
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   923
    /* 
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   924
        There is a bug in Cocoa where NSScreen doesn't synchronize
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   925
        with CGDirectDisplay, so the main screen's frame is wrong.
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   926
        As a result, coordinate translation produces incorrect results.
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   927
        We can hack around this bug by setting the screen rect
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   928
        ourselves. This hack should be removed if/when the bug is fixed.
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   929
    */
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   930
    screen_rect = NSMakeRect(0,0,width,height);
6158
6f3a2bb301d6 Fixed bug 1363 - SDL 1.2 hg does not compile against the 10.5 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 6157
diff changeset
   931
    QZ_SetFrame(this, [ NSScreen mainScreen ], screen_rect);
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   932
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
    /* Save the flags to ensure correct tear-down */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   934
    mode_flags = current->flags;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   935
1629
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   936
    /* Set app state, hide cursor if necessary, ... */
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   937
    QZ_DoActivate(this);
1119
430d8d701f69 SDL_GetAppState() correction when toggling fullscreen on OSX.
Ryan C. Gordon <icculus@icculus.org>
parents: 967
diff changeset
   938
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   939
    return current;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   940
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   941
    /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
6055
90167a588fd4 Stop a compiler warning on newer Mac OS X SDKs.
Ryan C. Gordon <icculus@icculus.org>
parents: 6050
diff changeset
   942
ERR_NO_GL:      goto ERR_DOUBLEBUF;  /* this goto is to stop a compiler warning on newer SDKs. */
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   943
ERR_DOUBLEBUF:  QZ_RestoreDisplayMode(this);
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   944
ERR_NO_SWITCH:  CGReleaseAllDisplays ();
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   945
ERR_NO_CAPTURE:
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   946
ERR_NO_MATCH:   if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   947
                    CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   948
                    CGReleaseDisplayFadeReservation (fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   949
                }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   950
                return NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   951
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   952
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   953
static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   954
                                         int height, int *bpp, Uint32 flags,
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   955
                                         const BOOL save_gl)
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   956
{
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   957
    unsigned int style;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   958
    NSRect contentRect;
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   959
    int center_window = 1;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   960
    int origin_x, origin_y;
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   961
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   962
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   963
    current->flags = 0;
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   964
    current->w = width;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   965
    current->h = height;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   966
    
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   967
    contentRect = NSMakeRect (0, 0, width, height);
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   968
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   969
    /*
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   970
        Check if we should completely destroy the previous mode 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   971
        - If it is fullscreen
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   972
        - If it has different noframe or resizable attribute
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   973
        - If it is OpenGL (since gl attributes could be different)
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   974
        - If new mode is OpenGL, but previous mode wasn't
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   975
    */
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   976
    if (video_set == SDL_TRUE) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   977
        if (mode_flags & SDL_FULLSCREEN) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   978
            /* Fade to black to hide resolution-switching flicker (and garbage
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   979
               that is displayed by a destroyed OpenGL context, if applicable) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   980
            if (CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   981
                CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   982
            }
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   983
            QZ_UnsetVideoMode (this, TRUE, save_gl);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   984
        }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   985
        else if ( ((mode_flags ^ flags) & (SDL_NOFRAME|SDL_RESIZABLE)) ||
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   986
                  (mode_flags & SDL_OPENGL) || 
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   987
                  (flags & SDL_OPENGL) ) {
6058
6144843db128 Mac OS X: Try to save the GL context between fullscreen/windowed toggles.
Ryan C. Gordon <icculus@icculus.org>
parents: 6056
diff changeset
   988
            QZ_UnsetVideoMode (this, TRUE, save_gl);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   989
        }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   990
    }
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   991
    
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   992
    /* Sorry, QuickDraw was ripped out. */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   993
    if (getenv("SDL_NSWindowPointer") || getenv("SDL_NSQuickDrawViewPointer")) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   994
        SDL_SetError ("Embedded QuickDraw windows are no longer supported");
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   995
        if (fade_token != kCGDisplayFadeReservationInvalidToken) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   996
            CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   997
            CGReleaseDisplayFadeReservation (fade_token);
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   998
        }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   999
        return NULL;
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
  1000
    }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
  1001
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
  1002
    /* Check if we should recreate the window */