src/video/quartz/SDL_QuartzVideo.m
author Ryan C. Gordon <icculus@icculus.org>
Tue, 13 Sep 2011 20:30:48 -0400
branchSDL-1.2
changeset 5908 6b62ce1bff72
parent 5645 80e036f88a6e
child 5909 f99f59413a14
permissions -rw-r--r--
Restored the older Quartz video target code. The new code happened to (supposedly) work everywhere, but it is way slower on older Mac OS X releases that could get away with using the now deprecated/removed APIs, so now both implementations are available, and SDL should choose the right path based on compile options and OS version at runtime. Fun stuff.
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
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 4139
diff changeset
     3
    Copyright (C) 1997-2009  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
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
    27
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
    28
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1060  /* 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
    29
/*
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    30
    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
    31
    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
    32
    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
    33
    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
    34
    main screen).
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    35
*/
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    36
@interface NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    37
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    38
@end
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    39
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    40
@implementation NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    41
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    42
{
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    43
    _frame = frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    44
}
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    45
@end
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    46
static inline void QZ_SetFrame(NSScreen *nsscreen, NSRect frame)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    47
{
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    48
    [nsscreen setFrame:frame];
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    49
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    50
#else
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    51
static inline void QZ_SetFrame(NSScreen *nsscreen, NSRect frame)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    52
{
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    53
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    54
#endif
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    55
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    56
@interface SDLTranslatorResponder : NSTextView
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    57
{
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    58
}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    59
- (void) doCommandBySelector:(SEL)myselector;
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    60
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    61
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    62
@implementation SDLTranslatorResponder
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    63
- (void) doCommandBySelector:(SEL) myselector {}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    64
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    65
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    66
/* 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
    67
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
    68
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    69
/* Bootstrap functions */
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    70
static int              QZ_Available ();
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    71
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
    72
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
    73
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    74
/* 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
    75
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
    76
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    77
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
    78
                                         Uint32 flags);
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
    79
static void         QZ_UnsetVideoMode   (_THIS, BOOL to_desktop);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    80
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    81
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
    82
                                         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
    83
                                         Uint32 flags);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    84
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
    85
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
    86
                                         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
    87
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
    88
#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
    89
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
    90
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
    91
static int          QZ_ThreadFlip         (_THIS);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
    92
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
    93
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
    94
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
    95
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
    96
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    97
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
    98
static void         QZ_VideoQuit        (_THIS);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    99
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   100
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
   101
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
   102
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
   103
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
   104
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
/* 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
   106
VideoBootStrap QZ_bootstrap = {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   107
    "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
   108
};
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   110
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   111
/* !!! FIXME: clean out pre-10.6 code when (if!) it makes sense to do so. */
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   112
#define FORCE_OLD_API 0 || (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   113
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   114
#if FORCE_OLD_API
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   115
#undef MAC_OS_X_VERSION_MIN_REQUIRED
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   116
#define MAC_OS_X_VERSION_MIN_REQUIRED 1050
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   117
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   118
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   119
static inline BOOL IS_LION_OR_LATER(_THIS)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   120
{
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   121
#if FORCE_OLD_API
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   122
    return NO;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   123
#else
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   124
    return (system_version >= 0x1070);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   125
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   126
}
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   127
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   128
static inline BOOL IS_SNOW_LEOPARD_OR_LATER(_THIS)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   129
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   130
#if FORCE_OLD_API
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   131
    return NO;
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   132
#else
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   133
    return (system_version >= 0x1060);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   134
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   135
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   136
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   137
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
   138
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   139
    /* 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
   140
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   141
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   142
        CGDisplayModeRelease((CGDisplayModeRef) moderef);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   143
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   144
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   145
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   146
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   147
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
   148
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   149
    /* 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
   150
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   151
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   152
        CFRelease(mode_list);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   153
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   154
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   155
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   156
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   157
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
/* 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
   159
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
   160
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
    return 1;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
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
   164
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
   165
{
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   166
#pragma unused (device_index)
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   168
    SDL_VideoDevice *device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   169
    SDL_PrivateVideoData *hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   170
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   171
    device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   172
    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
   173
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
    if (device == NULL || hidden == NULL)
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
        SDL_OutOfMemory ();
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   177
    SDL_memset (device, 0, sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   178
    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
   179
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
    device->hidden = hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   182
    device->VideoInit        = QZ_VideoInit;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
    device->ListModes        = QZ_ListModes;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
    device->SetVideoMode     = QZ_SetVideoMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
    device->ToggleFullScreen = QZ_ToggleFullScreen;
1212
7663bb0f52c7 To: sdl@libsdl.org
Ryan C. Gordon <icculus@icculus.org>
parents: 1189
diff changeset
   186
    device->UpdateMouse      = QZ_UpdateMouse;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
    device->SetColors        = QZ_SetColors;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   188
    /* 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
   189
    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
   190
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
    device->LockHWSurface   = QZ_LockHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
    device->UnlockHWSurface = QZ_UnlockHWSurface;
1120
8e1fde455471 Patch by me to fix crash described below.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   193
    device->AllocHWSurface   = QZ_AllocHWSurface;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   194
    device->FreeHWSurface   = QZ_FreeHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
    device->SetGamma     = QZ_SetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
    device->GetGamma     = QZ_GetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
    device->SetGammaRamp = QZ_SetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
    device->GetGammaRamp = QZ_GetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
    device->GL_GetProcAddress = QZ_GL_GetProcAddress;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
    device->GL_GetAttribute   = QZ_GL_GetAttribute;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
    device->GL_MakeCurrent    = QZ_GL_MakeCurrent;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   204
    device->GL_SwapBuffers    = QZ_GL_SwapBuffers;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
    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
   206
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   207
    device->FreeWMCursor   = QZ_FreeWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
    device->CreateWMCursor = QZ_CreateWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   209
    device->ShowWMCursor   = QZ_ShowWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   210
    device->WarpWMCursor   = QZ_WarpWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   211
    device->MoveWMCursor   = QZ_MoveWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   212
    device->CheckMouseMode = QZ_CheckMouseMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   213
    device->InitOSKeymap   = QZ_InitOSKeymap;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   214
    device->PumpEvents     = QZ_PumpEvents;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
    device->SetCaption    = QZ_SetCaption;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   217
    device->SetIcon       = QZ_SetIcon;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   218
    device->IconifyWindow = QZ_IconifyWindow;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   219
    /*device->GetWMInfo     = QZ_GetWMInfo;*/
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   220
    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
   221
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   222
    /*
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   223
     * 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
   224
     *  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
   225
     *  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
   226
     *  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
   227
     *  shader.  :)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   228
     */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   229
    /*device->CreateYUVOverlay = QZ_CreateYUVOverlay;*/
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   230
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   231
    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
   232
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   233
    return device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   234
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
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
   236
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
   237
{
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
   238
    _THIS = device;
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   239
    QZ_ReleaseDisplayMode(this, save_mode);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   240
    QZ_ReleaseDisplayMode(this, mode);
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   241
    SDL_free (device->hidden);
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   242
    SDL_free (device);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   243
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   244
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
   245
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
   246
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   247
    *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
   248
    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
   249
        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
   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
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   252
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   253
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   254
        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
   255
        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
   256
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   257
        *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
   258
        *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
   259
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
        /* 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
   261
        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
   262
                            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
   263
            *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
   264
        }
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
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
        CFRelease(fmt);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   267
    }
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
   268
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   269
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   270
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   271
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
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
        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
   273
        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
   274
            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
   275
            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
   276
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, 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
   279
            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
   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, 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
   283
            kCFNumberSInt32Type, h);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   284
    }
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
   285
#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
   286
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
    /* 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
   288
    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
   289
        *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
   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
}
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
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
   293
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
   294
{
4049
60f677630282 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 3936
diff changeset
   295
    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
   296
    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
   297
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   298
    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
   299
        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
   300
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   301
    /* 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
   302
    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
   303
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
   304
#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
   305
    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
   306
    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
   307
        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
   308
    	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
   309
    	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
   310
    	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
   311
        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
   312
    	    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
   313
        }
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
    }
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
#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
   316
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   317
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   318
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   319
        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
   320
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   321
#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
   322
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   323
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   324
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   325
        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
   326
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   327
#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
   328
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   329
#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
   330
    if (!IS_LION_OR_LATER(this)) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   331
        palette = CGPaletteCreateDefaultColorPalette();
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   332
    }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   333
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   334
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
    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
   336
        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
   337
        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
   338
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   339
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   340
    /* 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
   341
    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
   342
    if ( env ) {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   343
        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
   344
    } else {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   345
#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
   346
        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
   347
#else
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   348
        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
   349
#endif
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   350
    }
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
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   352
    /* 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
   353
    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
   354
    if (device_bpp == 0) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   355
        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
   356
        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
   357
        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
   358
        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
   359
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   360
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
   361
    /* 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
   362
    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
   363
    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
   364
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
   365
    /* 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
   366
    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
   367
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   368
    /* 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
   369
    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
   370
    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
   371
    cursor_visible              = YES;
823
d67e76f25874 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 816
diff changeset
   372
    current_mods = 0;
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
   373
    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
   374
555
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   375
    /* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   376
    QZ_RegisterForSleepNotifications (this);
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   377
    
1271
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   378
    /* Fill in some window manager capabilities */
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   379
    this->info.wm_available = 1;
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   380
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   381
    return 0;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   382
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   383
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
   384
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
   385
{
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
   386
    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
   387
    CFIndex num_modes;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   388
    CFIndex i;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   389
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
    int list_size = 0;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   391
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
    /* Any windowed mode is acceptable */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
    if ( (flags & SDL_FULLSCREEN) == 0 )
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   394
        return (SDL_Rect**)-1;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   395
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   396
    /* 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
   397
    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
   398
        int i;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   399
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   400
        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
   401
            SDL_free (client_mode_list[i]);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   402
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   403
        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
   404
        client_mode_list = NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   405
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   406
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   407
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   408
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   409
        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
   410
    }
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
   411
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   412
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   413
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   414
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   415
        mode_list = CGDisplayAvailableModes(display_id);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   416
    }
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
   417
#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
   418
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   419
    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
   420
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   421
    /* 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
   422
    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
   423
        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
   424
        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
   425
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
   426
        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
   427
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
   428
        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
   429
            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
   430
            int i;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   431
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   432
            /* 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
   433
            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
   434
                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
   435
                    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
   436
                        hasMode = SDL_TRUE;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   437
                        break;
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   438
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   439
            }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   440
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   441
            /* 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
   442
            if ( ! hasMode ) {
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   443
                SDL_Rect *rect;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   444
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   445
                list_size++;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   446
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   447
                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
   448
                    client_mode_list = (SDL_Rect**) 
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   449
                        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
   450
                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
   451
                    /* !!! 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
   452
                    client_mode_list = (SDL_Rect**)
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   453
                        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
   454
                }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   455
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   456
                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
   457
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   458
                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
   459
                    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
   460
                    SDL_OutOfMemory ();
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   461
                    return NULL;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   462
                }
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   463
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
   464
                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
   465
                rect->w = width;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   466
                rect->h = height;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
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
                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
   469
                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
   470
            }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   471
        }
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   472
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   473
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   474
    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
   475
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   476
    /* 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
   477
    {
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   478
        int i, j;
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   479
        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
   480
            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
   481
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   482
                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
   483
                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
   484
                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
   485
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   486
                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
   487
                    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
   488
                    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
   489
                    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
   490
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   491
            }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   492
        }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   493
    }
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
   494
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   495
    return client_mode_list;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   496
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   497
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   498
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
   499
{
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   500
    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
   501
    if ( window ) {
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   502
        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
   503
            return SDL_TRUE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   504
        }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   505
    }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   506
    return SDL_FALSE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   507
}
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   508
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
   509
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
   510
{
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   511
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   512
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   513
        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
   514
    }
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
   515
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   516
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   517
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   518
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
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
        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
   520
    }
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
   521
#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
   522
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 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
   524
}
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
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   526
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
   527
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   528
    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
   529
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   530
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
   531
static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
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
   532
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   533
    /* 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
   534
    this->info.blit_fill  = 0;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   535
    this->FillHWRect      = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   536
    this->UpdateRects     = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   537
    this->LockHWSurface   = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   538
    this->UnlockHWSurface = NULL;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   539
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   540
    if (cg_context) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   541
        CGContextFlush (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   542
        CGContextRelease (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   543
        cg_context = nil;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   544
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   545
    
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   546
    /* Release fullscreen resources */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   547
    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
   548
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   549
        NSRect screen_rect;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   550
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   551
        /*  Release double buffer stuff */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   552
#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
   553
        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
   554
            quit_thread = YES;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   555
            SDL_SemPost (sem1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   556
            SDL_WaitThread (thread, NULL);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   557
            SDL_DestroySemaphore (sem1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   558
            SDL_DestroySemaphore (sem2);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   559
            SDL_free (sw_buffers[0]);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   560
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   561
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   562
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   563
        /* If we still have a valid window, close it. */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   564
        if ( qz_window ) {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   565
            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
   566
            [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   567
            qz_window = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   568
            window_view = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   569
        }
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   570
        /* 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   571
            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
   572
            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
   573
        */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   574
        if ( mode_flags & SDL_OPENGL ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   575
        
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   576
            QZ_TearDownOpenGL (this);
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   577
            #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
   578
            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
   579
            #endif
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   580
        }
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
   581
        if (to_desktop) {
3877
81f66f258d77 Fixed bug #281
Sam Lantinga <slouken@libsdl.org>
parents: 1756
diff changeset
   582
            ShowMenuBar ();
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
   583
            /* 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
   584
            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
   585
            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
   586
            /* 
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
   587
                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
   588
                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
   589
            */
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
   590
            screen_rect = NSMakeRect(0,0,device_width,device_height);
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   591
            QZ_SetFrame([ 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
   592
        }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   593
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   594
    /* Release window mode resources */
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   595
    else {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   596
        id delegate = [ qz_window delegate ];
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   597
        [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   598
        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
   599
        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
   600
        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
   601
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   602
        /* Release the OpenGL context */
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   603
        if ( mode_flags & SDL_OPENGL )
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   604
            QZ_TearDownOpenGL (this);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   605
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   606
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   607
    /* Signal successful teardown */
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   608
    video_set = SDL_FALSE;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   609
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   610
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
   611
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
   612
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   613
    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
   614
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   615
    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
   616
        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
   617
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   618
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   619
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   620
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   621
        /* 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
   622
        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
   623
        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
   624
            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
   625
            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
   626
            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
   627
                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
   628
                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
   629
                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
   630
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   631
                /* 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
   632
                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
   633
                    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
   634
                    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
   635
                }
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
            }
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
            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
   638
            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
   639
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   640
    }
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
   641
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   642
5645
80e036f88a6e Remove use of MAC_OS_X_VERSION_10_x macro.
Ryan C. Gordon <icculus@icculus.org>
parents: 5639
diff changeset
   643
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   644
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
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
   645
        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
   646
        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
   647
        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
   648
            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
   649
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   650
    }
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
   651
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   652
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
   653
    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
   654
}
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
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
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
   657
                                           int height, int bpp, 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
   658
{
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   659
    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
   660
    NSRect screen_rect;
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   661
    CGError error;
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   662
    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
   663
    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
   664
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   665
    current->flags = SDL_FULLSCREEN;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   666
    current->w = width;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   667
    current->h = height;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   668
4442
31b0f2e06e3c SDL-1.2: Quartz fullscreen video contentRect was used uninitialized.
Ryan C. Gordon <icculus@icculus.org>
parents: 4389
diff changeset
   669
    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
   670
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
   671
    /* 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
   672
       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
   673
    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
   674
        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
   675
    }
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   676
    
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   677
    /* 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
   678
    if (video_set == SDL_TRUE)
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
   679
        QZ_UnsetVideoMode (this, FALSE);
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   680
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   681
    /* 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
   682
    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
   683
        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
   684
        goto ERR_NO_MATCH;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   685
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   686
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   687
    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
   688
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   689
    /* 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
   690
    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
   691
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   692
    /* 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
   693
    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
   694
        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
   695
        goto ERR_NO_MATCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   696
    }
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   697
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   698
    /* 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
   699
    if (getenv ("SDL_SINGLEDISPLAY"))
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   700
        error = CGDisplayCapture (display_id);
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   701
    else
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   702
        error = CGCaptureAllDisplays ();
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   703
        
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   704
    if ( CGDisplayNoErr != error ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   705
        SDL_SetError ("Failed capturing display");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   706
        goto ERR_NO_CAPTURE;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   707
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   708
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   709
    /* 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
   710
    if ( CGDisplayNoErr != QZ_SetDisplayMode(this, mode) ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   711
        SDL_SetError ("Failed switching display resolution");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   712
        goto ERR_NO_SWITCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   713
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   714
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   715
#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
   716
    if ( !isLion ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   717
        current->pixels = (Uint32*) CGDisplayBaseAddress (display_id);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   718
        current->pitch  = CGDisplayBytesPerRow (display_id);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   719
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   720
        current->flags |= SDL_HWSURFACE;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   721
        current->flags |= SDL_PREALLOC;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   722
        /* current->hwdata = (void *) CGDisplayGetDrawingContext (display_id); */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   723
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   724
        this->UpdateRects     = QZ_DirectUpdate;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   725
        this->LockHWSurface   = QZ_LockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   726
        this->UnlockHWSurface = QZ_UnlockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   727
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   728
        /* Setup double-buffer emulation */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   729
        if ( flags & SDL_DOUBLEBUF ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   730
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   731
            /*
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   732
            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
   733
            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
   734
            surface looks hideous).
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   735
            
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   736
            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
   737
            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
   738
            */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   739
            this->LockHWSurface = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   740
            this->UnlockHWSurface = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   741
            this->UpdateRects = NULL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   742
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   743
            current->flags |= (SDL_HWSURFACE|SDL_DOUBLEBUF);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   744
            this->UpdateRects = QZ_DoubleBufferUpdate;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   745
            this->LockHWSurface = QZ_LockDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   746
            this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   747
            this->FlipHWSurface = QZ_FlipDoubleBuffer;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   748
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   749
            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
   750
            if (current->pixels == NULL) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   751
                SDL_OutOfMemory ();
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   752
                goto ERR_DOUBLEBUF;
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
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   755
            sw_buffers[0] = current->pixels;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   756
            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
   757
        
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   758
            quit_thread = NO;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   759
            sem1 = SDL_CreateSemaphore (0);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   760
            sem2 = SDL_CreateSemaphore (1);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   761
            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
   762
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   763
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   764
        if ( CGDisplayCanSetPalette (display_id) )
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   765
            current->flags |= SDL_HWPALETTE;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   766
    }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   767
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   768
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   769
    /* Check if we should recreate the window */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   770
    if (qz_window == nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   771
        /* Manually create a window, avoids having a nib file resource */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   772
        qz_window = [ [ SDL_QuartzWindow alloc ] 
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   773
            initWithContentRect:contentRect
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   774
                styleMask:(isLion ? NSBorderlessWindowMask : 0)
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   775
                    backing:NSBackingStoreBuffered
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   776
                        defer:NO ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   777
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   778
        if (qz_window != nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   779
            [ qz_window setAcceptsMouseMovedEvents:YES ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   780
            [ qz_window setViewsNeedDisplay:NO ];
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   781
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   782
            if (isLion) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   783
                [ 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
   784
            }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   785
#endif
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   786
        }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   787
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   788
    /* We already have a window, just change its size */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   789
    else {
4267
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   790
        [ qz_window setContentSize:contentRect.size ];
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   791
        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
   792
        [ window_view setFrameSize:contentRect.size ];
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   793
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   794
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   795
    /* Setup OpenGL for a fullscreen context */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   796
    if (flags & SDL_OPENGL) {
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   797
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   798
        CGLError err;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   799
        CGLContextObj ctx;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   800
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   801
        if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   802
            goto ERR_NO_GL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   803
        }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   804
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   805
        /* 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
   806
           view allow the cursor to be changed whilst in fullscreen.*/
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   807
        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   808
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   809
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   810
        if ( isLion ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   811
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   812
        }
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   813
#endif
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   814
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   815
        [ [ qz_window contentView ] addSubview:window_view ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   816
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   817
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   818
        if ( isLion ) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   819
            [ qz_window setLevel:CGShieldingWindowLevel() ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   820
            [ gl_context setView: window_view ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   821
            [ gl_context setFullScreen ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   822
            [ gl_context update ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   823
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   824
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   825
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   826
#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
   827
        if ( !isLion) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   828
            [ qz_window setLevel:NSNormalWindowLevel ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   829
            ctx = QZ_GetCGLContextObj (gl_context);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   830
            err = CGLSetFullScreen (ctx);
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   831
    
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   832
            if (err) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   833
                SDL_SetError ("Error setting OpenGL fullscreen: %s", CGLErrorString(err));
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   834
                goto ERR_NO_GL;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   835
            }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   836
        }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   837
#endif
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   838
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   839
        [ window_view release ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   840
        [ gl_context makeCurrentContext];
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   841
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   842
        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
   843
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   844
        [ gl_context flushBuffer ];
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   845
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   846
        current->flags |= SDL_OPENGL;
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   847
    } else if (isLion) {  /* For 2D, we build a CGBitmapContext */
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   848
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   849
        CGColorSpaceRef cgColorspace;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   850
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   851
        /* 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
   852
        if (window_view == nil) {
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   853
            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
   854
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   855
            [ [ 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
   856
            [ window_view release ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   857
        }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   858
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   859
        cgColorspace = CGColorSpaceCreateDeviceRGB();
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   860
        current->pitch = 4 * current->w;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   861
        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
   862
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   863
        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
   864
                        8, current->pitch, cgColorspace,
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   865
                        kCGImageAlphaNoneSkipFirst);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   866
        CGColorSpaceRelease (cgColorspace);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   867
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   868
        current->flags |= SDL_SWSURFACE;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   869
        current->flags |= SDL_ASYNCBLIT;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   870
        current->hwdata = (void *) cg_context;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   871
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   872
        /* 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
   873
        [ qz_window setLevel:CGShieldingWindowLevel() ];
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   874
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   875
        this->UpdateRects     = QZ_UpdateRects;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   876
        this->LockHWSurface   = QZ_LockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   877
        this->UnlockHWSurface = QZ_UnlockHWSurface;
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   878
#endif
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   879
    }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   880
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   881
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   882
    if (isLion) {
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   883
        [ qz_window setHasShadow:NO];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   884
        [ qz_window setOpaque:YES];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   885
        [ qz_window makeKeyAndOrderFront:nil ];
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   886
    }
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   887
#endif
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
    /* If we don't hide menu bar, it will get events and interrupt the program */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
    HideMenuBar ();
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   891
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
   892
    /* 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
   893
    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
   894
        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
   895
        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
   896
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   897
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   898
    /* 
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   899
        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
   900
        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
   901
        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
   902
        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
   903
        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
   904
    */
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   905
    screen_rect = NSMakeRect(0,0,width,height);
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   906
    QZ_SetFrame([ NSScreen mainScreen ], screen_rect);
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   907
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
    /* 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
   909
    mode_flags = current->flags;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   910
1629
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   911
    /* Set app state, hide cursor if necessary, ... */
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   912
    QZ_DoActivate(this);
1119
430d8d701f69 SDL_GetAppState() correction when toggling fullscreen on OSX.
Ryan C. Gordon <icculus@icculus.org>
parents: 967
diff changeset
   913
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   914
    return current;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   916
    /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
5908
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   917
ERR_NO_GL:
6b62ce1bff72 Restored the older Quartz video target code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5645
diff changeset
   918
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
   919
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
   920
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
   921
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
   922
                    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
   923
                    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
   924
                }
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
   925
                return NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
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
   929
                                         int height, int *bpp, 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
   930
{
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   931
    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
   932
    NSRect contentRect;
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   933
    int center_window = 1;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   934
    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
   935
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   936
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   937
    current->flags = 0;
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   938
    current->w = width;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   939
    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
   940
    
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   941
    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
   942
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   943
    /*
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   944
        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
   945
        - 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
   946
        - 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
   947
        - 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
   948
        - 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
   949
    */
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
   950
    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
   951
        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
   952
            /* 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
   953
               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
   954
            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
   955
                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
   956
            }
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
   957
            QZ_UnsetVideoMode (this, 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
   958
        }
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
   959
        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
   960
                  (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
   961
                  (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
   962
            QZ_UnsetVideoMode (this, 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
   963
        }
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
   964
    }
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   965
    
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   966
    /* 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
   967
    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
   968
        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
   969
        if (fade_token != kCGDisplayFadeReservationInvalidToken) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   970
            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
   971
            CGReleaseDisplayFadeReservation (fade_token);
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   972
        }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   973
        return NULL;
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   974
    }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   975
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   976
    /* Check if we should recreate the window */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   977
    if (qz_window == nil) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   978
    
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   979
        /* Set the window style based on input flags */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   980
        if ( flags & SDL_NOFRAME ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   981
            style = NSBorderlessWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   982
            current->flags |= SDL_NOFRAME;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   983
        } else {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   984
            style = NSTitledWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   985
            style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   986
            if ( flags & SDL_RESIZABLE ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   987
                style |= NSResizableWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   988
                current->flags |= SDL_RESIZABLE;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   989
            }
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   990
        }
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   991
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   992
        /* Manually create a window, avoids having a nib file resource */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   993
        qz_window = [ [ SDL_QuartzWindow alloc ] 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   994
            initWithContentRect:contentRect
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   995
                styleMask:style 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   996
                    backing:NSBackingStoreBuffered
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   997
                        defer:NO ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   998
                          
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   999
        if (qz_window == nil) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
  1000
            SDL_SetError ("Could not create the Cocoa window");
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
  1001
            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
  1002
                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
  1003
                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
  1004
            }
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
  1005
            return NULL;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
  1006
        }
4265