src/video/quartz/SDL_QuartzVideo.h
changeset 47 45b1c4303f87
child 58 bd6b0a910a65
equal deleted inserted replaced
46:3dcf26fa9d15 47:45b1c4303f87
       
     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@devolution.com
       
    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?
       
    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         - Modifier + mouse-down maps alternate mouse button, but if modifier is released
       
    48            before mouse button, corresponding mouse-up event is not generated.
       
    49         - Clicking in content activates app, but doesn't generate the activate event,
       
    50           and subsequent switches generate no activate/deactivate events! (OS Bug I hope)
       
    51 */
       
    52 
       
    53 #include <ApplicationServices/ApplicationServices.h>
       
    54 #include <OpenGL/OpenGL.h>
       
    55 #include <Cocoa/Cocoa.h>
       
    56 #include <Carbon/Carbon.h>
       
    57 
       
    58 #include "SDL_video.h"
       
    59 #include "SDL_error.h"
       
    60 #include "SDL_syswm.h"
       
    61 #include "SDL_sysvideo.h"
       
    62 #include "SDL_pixels_c.h"
       
    63 #include "SDL_events_c.h"
       
    64 
       
    65 /* This is a workaround to directly access NSOpenGLContext's CGL context */
       
    66 /* We need to do this in order to check for errors */
       
    67 @interface NSOpenGLContext (CGLContextAccess)
       
    68 - (CGLContextObj) cglContext;
       
    69 @end
       
    70 
       
    71 @implementation NSOpenGLContext (CGLContextAccess)
       
    72 - (CGLContextObj) cglContext;
       
    73 {
       
    74     return _contextAuxiliary;
       
    75 }
       
    76 @end
       
    77 
       
    78 typedef struct SDL_PrivateVideoData {
       
    79 
       
    80     CGDirectDisplayID  display; /* 0 == main display */
       
    81     CFDictionaryRef    mode;
       
    82     CFDictionaryRef    save_mode;
       
    83     CFArrayRef         mode_list;
       
    84     CGDirectPaletteRef palette;
       
    85     NSOpenGLContext    *gl_context;
       
    86     int                width, height, bpp;
       
    87     Uint32             flags;
       
    88     
       
    89     /* Window-only fields */
       
    90     NSWindow        *window;
       
    91     NSQuickDrawView *view;
       
    92     NSString        *title;
       
    93     
       
    94 } SDL_PrivateVideoData ;
       
    95 
       
    96 #define _THIS	SDL_VideoDevice *this
       
    97 #define display_id (this->hidden->display)
       
    98 #define mode (this->hidden->mode)
       
    99 #define save_mode (this->hidden->save_mode)
       
   100 #define mode_list (this->hidden->mode_list)
       
   101 #define palette (this->hidden->palette)
       
   102 #define glcontext (this->hidden->glcontext)
       
   103 #define objc_video (this->hidden->objc_video)
       
   104 #define gl_context (this->hidden->gl_context)
       
   105 #define device_width (this->hidden->width)
       
   106 #define device_height (this->hidden->height)
       
   107 #define device_bpp (this->hidden->bpp)
       
   108 #define mode_flags (this->hidden->flags)
       
   109 #define window (this->hidden->window)
       
   110 #define windowView (this->hidden->view)
       
   111 #define windowTitle (this->hidden->title)
       
   112 
       
   113 /* Interface for hardware fill not (yet) in the public API */
       
   114 int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
       
   115                       unsigned int w, unsigned int h, unsigned int color);
       
   116 int CGSDisplayCanHWFill (CGDirectDisplayID id);
       
   117 
       
   118 /* Bootstrap functions */
       
   119 static int              QZ_Available ();
       
   120 static SDL_VideoDevice* QZ_CreateDevice (int device_index);
       
   121 static void             QZ_DeleteDevice (SDL_VideoDevice *device);
       
   122 
       
   123 /* Initialization, Query, Setup, and Redrawing functions */
       
   124 static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
       
   125 
       
   126 static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
       
   127 					 Uint32 flags);
       
   128 static void         QZ_UnsetVideoMode   (_THIS);
       
   129 
       
   130 static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
       
   131 					 int width, int height, int bpp, 
       
   132 					 Uint32 flags);
       
   133 static int          QZ_ToggleFullScreen (_THIS, int on);
       
   134 static int          QZ_SetColors        (_THIS, int first_color, 
       
   135 					 int num_colors, SDL_Color *colors);
       
   136 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
       
   137 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
       
   138 static void         QZ_VideoQuit        (_THIS);
       
   139 
       
   140 /* Hardware surface functions (for fullscreen mode only) */
       
   141 static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
       
   142 static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
       
   143 static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
       
   144 static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
       
   145 /* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
       
   146 
       
   147 /* Gamma Functions */
       
   148 static int QZ_SetGamma     (_THIS, float red, float green, float blue);
       
   149 static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
       
   150 static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
       
   151 static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
       
   152 
       
   153 /* OpenGL functions */
       
   154 static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
       
   155 static void   QZ_TearDownOpenGL (_THIS);
       
   156 static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
       
   157 static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
       
   158 static int    QZ_GL_MakeCurrent    (_THIS);
       
   159 static void   QZ_GL_SwapBuffers    (_THIS);
       
   160 static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
       
   161 
       
   162 /* Private function to warp the cursor (used internally) */
       
   163 static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
       
   164 
       
   165 /* Cursor and Mouse functions */
       
   166 static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
       
   167 static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
       
   168                                           int w, int h, int hot_x, int hot_y);
       
   169 static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
       
   170 static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
       
   171 static void         QZ_MoveWMCursor     (_THIS, int x, int y);
       
   172 static void         QZ_CheckMouseMode   (_THIS);
       
   173 
       
   174 /* Event functions */
       
   175 static void         QZ_InitOSKeymap     (_THIS);
       
   176 static void         QZ_PumpEvents       (_THIS);
       
   177 
       
   178 /* Window Manager functions */
       
   179 static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
       
   180 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
       
   181 static int  QZ_IconifyWindow (_THIS);
       
   182 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
       
   183 /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/