src/video/quartz/SDL_QuartzVideo.h
author Sam Lantinga
Fri, 14 Dec 2001 12:38:15 +0000
changeset 252 e8157fcb3114
parent 158 4382c38dfbee
child 272 d1447a846d80
permissions -rw-r--r--
Updated the source with the correct e-mail address
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /*	
    24     @file   SDL_QuartzVideo.h
    25     @author Darrell Walisser
    26     
    27     @abstract SDL video driver for MacOS X.
    28     
    29     @discussion
    30     
    31     TODO
    32         - Hardware Cursor support with NSCursor instead of Carbon
    33         - Keyboard repeat/mouse speed adjust (if needed)
    34         - Multiple monitor support (currently only main display)
    35         - Accelerated blitting support
    36         - Set the window icon (dock icon when API is available)
    37         - Avoid erasing window on minimize, or disable minimize
    38     Problems:
    39         - OGL not working in full screen with software renderer
    40         - SetColors sets palette correctly but clears framebuffer
    41         - Crash in CG after several mode switches
    42         - Retained windows don't draw their title bar quite right (OS Bug)
    43         - Should I do depth switching for windowed modes? - No, not usually.
    44         - Launch times are slow, maybe prebinding will help
    45         - Direct framebuffer access has some artifacts, maybe a driver issue
    46         - Cursor in 8 bit modes is screwy
    47 */
    48 
    49 #include <ApplicationServices/ApplicationServices.h>
    50 #include <OpenGL/OpenGL.h>
    51 #include <Cocoa/Cocoa.h>
    52 #include <Carbon/Carbon.h>
    53 
    54 #include "SDL_video.h"
    55 #include "SDL_error.h"
    56 #include "SDL_syswm.h"
    57 #include "SDL_sysvideo.h"
    58 #include "SDL_pixels_c.h"
    59 #include "SDL_events_c.h"
    60 
    61 /* This is a workaround to directly access NSOpenGLContext's CGL context */
    62 /* We need to do this in order to check for errors */
    63 @interface NSOpenGLContext (CGLContextAccess)
    64 - (CGLContextObj) cglContext;
    65 @end
    66 
    67 @implementation NSOpenGLContext (CGLContextAccess)
    68 - (CGLContextObj) cglContext;
    69 {
    70     return _contextAuxiliary;
    71 }
    72 @end
    73 
    74 typedef struct SDL_PrivateVideoData {
    75 
    76     CGDirectDisplayID  display; /* 0 == main display */
    77     CFDictionaryRef    mode;
    78     CFDictionaryRef    save_mode;
    79     CFArrayRef         mode_list;
    80     CGDirectPaletteRef palette;
    81     NSOpenGLContext    *gl_context;
    82     Uint32             width, height, bpp;
    83     Uint32             flags;
    84     SDL_bool           video_is_set; /* tell if the video mode was set */
    85     
    86     /* Window-only fields */
    87     NSWindow        *window;
    88     NSQuickDrawView *view;
    89     
    90 } SDL_PrivateVideoData ;
    91 
    92 #define _THIS	SDL_VideoDevice *this
    93 #define display_id (this->hidden->display)
    94 #define mode (this->hidden->mode)
    95 #define save_mode (this->hidden->save_mode)
    96 #define mode_list (this->hidden->mode_list)
    97 #define palette (this->hidden->palette)
    98 #define glcontext (this->hidden->glcontext)
    99 #define objc_video (this->hidden->objc_video)
   100 #define gl_context (this->hidden->gl_context)
   101 #define device_width (this->hidden->width)
   102 #define device_height (this->hidden->height)
   103 #define device_bpp (this->hidden->bpp)
   104 #define mode_flags (this->hidden->flags)
   105 #define video_set (this->hidden->video_is_set)
   106 #define qz_window (this->hidden->window)
   107 #define windowView (this->hidden->view)
   108 
   109 /* Interface for hardware fill not (yet) in the public API */
   110 int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
   111                       unsigned int w, unsigned int h, unsigned int color);
   112 int CGSDisplayCanHWFill (CGDirectDisplayID id);
   113 
   114 /* Bootstrap functions */
   115 static int              QZ_Available ();
   116 static SDL_VideoDevice* QZ_CreateDevice (int device_index);
   117 static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   118 
   119 /* Initialization, Query, Setup, and Redrawing functions */
   120 static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   121 
   122 static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
   123 					 Uint32 flags);
   124 static void         QZ_UnsetVideoMode   (_THIS);
   125 
   126 static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
   127 					 int width, int height, int bpp, 
   128 					 Uint32 flags);
   129 static int          QZ_ToggleFullScreen (_THIS, int on);
   130 static int          QZ_SetColors        (_THIS, int first_color, 
   131 					 int num_colors, SDL_Color *colors);
   132 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   133 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   134 static void         QZ_VideoQuit        (_THIS);
   135 
   136 /* Hardware surface functions (for fullscreen mode only) */
   137 static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
   138 static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
   139 static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
   140 static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
   141 /* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
   142 
   143 /* Gamma Functions */
   144 static int QZ_SetGamma     (_THIS, float red, float green, float blue);
   145 static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
   146 static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
   147 static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
   148 
   149 /* OpenGL functions */
   150 static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
   151 static void   QZ_TearDownOpenGL (_THIS);
   152 static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   153 static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   154 static int    QZ_GL_MakeCurrent    (_THIS);
   155 static void   QZ_GL_SwapBuffers    (_THIS);
   156 static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
   157 
   158 /* Private function to warp the cursor (used internally) */
   159 static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
   160 
   161 /* Cursor and Mouse functions */
   162 static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   163 static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   164                                           int w, int h, int hot_x, int hot_y);
   165 static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   166 static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   167 static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   168 static void         QZ_CheckMouseMode   (_THIS);
   169 
   170 /* Event functions */
   171 static void         QZ_InitOSKeymap     (_THIS);
   172 static void         QZ_PumpEvents       (_THIS);
   173 
   174 /* Window Manager functions */
   175 static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
   176 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   177 static int  QZ_IconifyWindow (_THIS);
   178 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   179 /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/