src/video/quartz/SDL_QuartzVideo.h
author Sam Lantinga
Wed, 06 Mar 2002 11:23:08 +0000
changeset 297 f6ffac90895c
parent 272 d1447a846d80
child 390 19e73568a75c
permissions -rw-r--r--
Updated copyright information for 2002
slouken@47
     1
/*
slouken@47
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@47
     4
slouken@47
     5
    This library is free software; you can redistribute it and/or
slouken@47
     6
    modify it under the terms of the GNU Library General Public
slouken@47
     7
    License as published by the Free Software Foundation; either
slouken@47
     8
    version 2 of the License, or (at your option) any later version.
slouken@47
     9
slouken@47
    10
    This library is distributed in the hope that it will be useful,
slouken@47
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@47
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@47
    13
    Library General Public License for more details.
slouken@47
    14
slouken@47
    15
    You should have received a copy of the GNU Library General Public
slouken@47
    16
    License along with this library; if not, write to the Free
slouken@47
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@47
    18
slouken@47
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@47
    21
*/
slouken@47
    22
slouken@47
    23
/*	
slouken@47
    24
    @file   SDL_QuartzVideo.h
slouken@47
    25
    @author Darrell Walisser
slouken@47
    26
    
slouken@47
    27
    @abstract SDL video driver for MacOS X.
slouken@47
    28
    
slouken@47
    29
    @discussion
slouken@47
    30
    
slouken@47
    31
    TODO
slouken@47
    32
        - Hardware Cursor support with NSCursor instead of Carbon
slouken@47
    33
        - Keyboard repeat/mouse speed adjust (if needed)
slouken@47
    34
        - Multiple monitor support (currently only main display)
slouken@47
    35
        - Accelerated blitting support
slouken@47
    36
        - Set the window icon (dock icon when API is available)
slouken@272
    37
        - Fix white OpenGL window on minimize
slouken@272
    38
        - Find out what events should be sent/ignored if window is mimimized
slouken@272
    39
        - Find a better way to deal with resolution/depth switch while app is running
slouken@272
    40
        - Resizeable windows
slouken@272
    41
        - Check accuracy of QZ_SetGamma()
slouken@47
    42
    Problems:
slouken@47
    43
        - OGL not working in full screen with software renderer
slouken@47
    44
        - SetColors sets palette correctly but clears framebuffer
slouken@47
    45
        - Crash in CG after several mode switches
slouken@272
    46
        - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
slouken@272
    47
        - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug)
slouken@272
    48
        - Warping cursor delays mouse events for a fraction of a second,
slouken@272
    49
          there is a hack around this that helps a bit
slouken@47
    50
*/
slouken@47
    51
slouken@272
    52
#include <Cocoa/Cocoa.h>
slouken@47
    53
#include <OpenGL/OpenGL.h>
slouken@47
    54
#include <Carbon/Carbon.h>
slouken@47
    55
slouken@47
    56
#include "SDL_video.h"
slouken@47
    57
#include "SDL_error.h"
slouken@272
    58
#include "SDL_timer.h"
slouken@47
    59
#include "SDL_syswm.h"
slouken@47
    60
#include "SDL_sysvideo.h"
slouken@47
    61
#include "SDL_pixels_c.h"
slouken@47
    62
#include "SDL_events_c.h"
slouken@47
    63
slouken@47
    64
/* This is a workaround to directly access NSOpenGLContext's CGL context */
slouken@47
    65
/* We need to do this in order to check for errors */
slouken@47
    66
@interface NSOpenGLContext (CGLContextAccess)
slouken@47
    67
- (CGLContextObj) cglContext;
slouken@47
    68
@end
slouken@47
    69
slouken@47
    70
@implementation NSOpenGLContext (CGLContextAccess)
slouken@47
    71
- (CGLContextObj) cglContext;
slouken@47
    72
{
slouken@47
    73
    return _contextAuxiliary;
slouken@47
    74
}
slouken@47
    75
@end
slouken@47
    76
slouken@272
    77
/* Structure for rez switch gamma fades */
slouken@272
    78
/* We can hide the monitor flicker by setting the gamma tables to 0 */
slouken@272
    79
#define QZ_GAMMA_TABLE_SIZE 256
slouken@272
    80
slouken@272
    81
typedef struct {
slouken@272
    82
slouken@272
    83
    CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
slouken@272
    84
    CGGammaValue green[QZ_GAMMA_TABLE_SIZE];
slouken@272
    85
    CGGammaValue blue[QZ_GAMMA_TABLE_SIZE];
slouken@272
    86
slouken@272
    87
} SDL_QuartzGammaTable;
slouken@272
    88
slouken@272
    89
/* Main driver structure to store required state information */
slouken@47
    90
typedef struct SDL_PrivateVideoData {
slouken@47
    91
slouken@272
    92
    CGDirectDisplayID  display;            /* 0 == main display (only support single display) */
slouken@272
    93
    CFDictionaryRef    mode;               /* current mode of the display */
slouken@272
    94
    CFDictionaryRef    save_mode;          /* original mode of the display */
slouken@272
    95
    CFArrayRef         mode_list;          /* list of available fullscreen modes */
slouken@272
    96
    CGDirectPaletteRef palette;            /* palette of an 8-bit display */
slouken@272
    97
    NSOpenGLContext    *gl_context;        /* object that represents an OpenGL rendering context */
slouken@272
    98
    Uint32             width, height, bpp; /* frequently used data about the display */
slouken@272
    99
    Uint32             flags;              /* flags for mode, for teardown purposes */
slouken@272
   100
    Uint32             video_set;          /* boolean; indicates if video was set correctly */
slouken@272
   101
    Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
slouken@272
   102
    Uint32             warp_ticks;         /* timestamp when the warp occured */
slouken@272
   103
    NSWindow           *window;            /* Cocoa window to implement the SDL window */
slouken@272
   104
    NSQuickDrawView    *view;              /* the window's view; draw 2D into this view */
slouken@47
   105
    
slouken@47
   106
} SDL_PrivateVideoData ;
slouken@47
   107
slouken@47
   108
#define _THIS	SDL_VideoDevice *this
slouken@47
   109
#define display_id (this->hidden->display)
slouken@47
   110
#define mode (this->hidden->mode)
slouken@47
   111
#define save_mode (this->hidden->save_mode)
slouken@47
   112
#define mode_list (this->hidden->mode_list)
slouken@47
   113
#define palette (this->hidden->palette)
slouken@47
   114
#define gl_context (this->hidden->gl_context)
slouken@47
   115
#define device_width (this->hidden->width)
slouken@47
   116
#define device_height (this->hidden->height)
slouken@47
   117
#define device_bpp (this->hidden->bpp)
slouken@47
   118
#define mode_flags (this->hidden->flags)
slouken@158
   119
#define qz_window (this->hidden->window)
slouken@272
   120
#define window_view (this->hidden->view)
slouken@272
   121
#define video_set (this->hidden->video_set)
slouken@272
   122
#define warp_ticks (this->hidden->warp_ticks)
slouken@272
   123
#define warp_flag (this->hidden->warp_flag)
slouken@272
   124
slouken@272
   125
/* Obscuring code: maximum number of windows above ours (inclusive) */
slouken@272
   126
#define kMaxWindows 256
slouken@272
   127
slouken@272
   128
/* Some of the Core Graphics Server API for obscuring code */
slouken@272
   129
#define kCGSWindowLevelTop          2147483632
slouken@272
   130
#define kCGSWindowLevelDockIconDrag 500
slouken@272
   131
#define kCGSWindowLevelDockMenu     101
slouken@272
   132
#define kCGSWindowLevelMenuIgnore    21
slouken@272
   133
#define kCGSWindowLevelMenu          20
slouken@272
   134
#define kCGSWindowLevelDockLabel     12
slouken@272
   135
#define kCGSWindowLevelDockIcon      11
slouken@272
   136
#define kCGSWindowLevelDock          10
slouken@272
   137
#define kCGSWindowLevelUtility        3
slouken@272
   138
#define kCGSWindowLevelNormal         0
slouken@272
   139
slouken@272
   140
/* For completeness; We never use these window levels, they are always below us
slouken@272
   141
#define kCGSWindowLevelMBarShadow -20
slouken@272
   142
#define kCGSWindowLevelDesktopPicture -2147483647
slouken@272
   143
#define kCGSWindowLevelDesktop        -2147483648
slouken@272
   144
*/
slouken@47
   145
slouken@272
   146
typedef CGError       CGSError;
slouken@272
   147
typedef long	      CGSWindowCount;
slouken@272
   148
typedef void *	      CGSConnectionID;
slouken@272
   149
typedef int	      CGSWindowID;
slouken@272
   150
typedef CGSWindowID*  CGSWindowIDList;
slouken@272
   151
typedef CGWindowLevel CGSWindowLevel;
slouken@272
   152
typedef NSRect        CGSRect;
slouken@272
   153
slouken@272
   154
extern CGSConnectionID _CGSDefaultConnection ();
slouken@272
   155
slouken@272
   156
extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid, 
slouken@272
   157
                                          CGSConnectionID owner,
slouken@272
   158
                                          CGSWindowCount listCapacity,
slouken@272
   159
                                          CGSWindowIDList list,
slouken@272
   160
                                          CGSWindowCount *listCount);
slouken@272
   161
slouken@272
   162
extern CGSError CGSGetScreenRectForWindow (CGSConnectionID cid,
slouken@272
   163
                                           CGSWindowID wid,
slouken@272
   164
                                           CGSRect *rect);
slouken@272
   165
slouken@272
   166
extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
slouken@272
   167
                                        CGSWindowID wid,
slouken@272
   168
                                        CGSWindowLevel *level);
slouken@272
   169
                                        
slouken@272
   170
extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
slouken@47
   171
                      unsigned int w, unsigned int h, unsigned int color);
slouken@272
   172
slouken@272
   173
extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
slouken@272
   174
slouken@272
   175
extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
slouken@47
   176
slouken@47
   177
/* Bootstrap functions */
slouken@47
   178
static int              QZ_Available ();
slouken@47
   179
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
slouken@47
   180
static void             QZ_DeleteDevice (SDL_VideoDevice *device);
slouken@47
   181
slouken@47
   182
/* Initialization, Query, Setup, and Redrawing functions */
slouken@47
   183
static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
slouken@47
   184
slouken@47
   185
static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
slouken@47
   186
					 Uint32 flags);
slouken@47
   187
static void         QZ_UnsetVideoMode   (_THIS);
slouken@47
   188
slouken@47
   189
static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
slouken@47
   190
					 int width, int height, int bpp, 
slouken@47
   191
					 Uint32 flags);
slouken@47
   192
static int          QZ_ToggleFullScreen (_THIS, int on);
slouken@47
   193
static int          QZ_SetColors        (_THIS, int first_color, 
slouken@47
   194
					 int num_colors, SDL_Color *colors);
slouken@47
   195
static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   196
static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   197
static void         QZ_VideoQuit        (_THIS);
slouken@47
   198
slouken@47
   199
/* Hardware surface functions (for fullscreen mode only) */
slouken@47
   200
static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
slouken@47
   201
static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   202
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   203
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
slouken@47
   204
/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
slouken@47
   205
slouken@47
   206
/* Gamma Functions */
slouken@47
   207
static int QZ_SetGamma     (_THIS, float red, float green, float blue);
slouken@47
   208
static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
slouken@47
   209
static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   210
static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   211
slouken@47
   212
/* OpenGL functions */
slouken@47
   213
static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
slouken@47
   214
static void   QZ_TearDownOpenGL (_THIS);
slouken@47
   215
static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
slouken@47
   216
static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
slouken@47
   217
static int    QZ_GL_MakeCurrent    (_THIS);
slouken@47
   218
static void   QZ_GL_SwapBuffers    (_THIS);
slouken@47
   219
static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
slouken@47
   220
slouken@47
   221
/* Private function to warp the cursor (used internally) */
slouken@272
   222
static void  QZ_PrivateWarpCursor (_THIS, int x, int y);
slouken@47
   223
slouken@47
   224
/* Cursor and Mouse functions */
slouken@47
   225
static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   226
static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
slouken@47
   227
                                          int w, int h, int hot_x, int hot_y);
slouken@47
   228
static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   229
static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
slouken@47
   230
static void         QZ_MoveWMCursor     (_THIS, int x, int y);
slouken@47
   231
static void         QZ_CheckMouseMode   (_THIS);
slouken@47
   232
slouken@47
   233
/* Event functions */
slouken@47
   234
static void         QZ_InitOSKeymap     (_THIS);
slouken@47
   235
static void         QZ_PumpEvents       (_THIS);
slouken@47
   236
slouken@47
   237
/* Window Manager functions */
slouken@47
   238
static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
slouken@47
   239
static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
slouken@47
   240
static int  QZ_IconifyWindow (_THIS);
slouken@47
   241
static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
slouken@47
   242
/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
slouken@272
   243