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