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