src/video/quartz/SDL_QuartzVideo.h
author Sam Lantinga
Mon, 11 Jun 2001 06:44:43 +0000
changeset 58 bd6b0a910a65
parent 47 45b1c4303f87
child 155 2d162219f433
permissions -rw-r--r--
* Removed fullscreen menu option from the "Window" menu
* Updated the BUGS file
* Fixed command line parameters when launched from Finder
* Implemented setting the icon window caption
* Implemented frameless style windows
* Added note about SDL_RESIZABLE implementation to SDL_QuartzVideo.m
* Window close requests now go through the event filtering system
     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? - 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         - 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     
    93 } SDL_PrivateVideoData ;
    94 
    95 #define _THIS	SDL_VideoDevice *this
    96 #define display_id (this->hidden->display)
    97 #define mode (this->hidden->mode)
    98 #define save_mode (this->hidden->save_mode)
    99 #define mode_list (this->hidden->mode_list)
   100 #define palette (this->hidden->palette)
   101 #define glcontext (this->hidden->glcontext)
   102 #define objc_video (this->hidden->objc_video)
   103 #define gl_context (this->hidden->gl_context)
   104 #define device_width (this->hidden->width)
   105 #define device_height (this->hidden->height)
   106 #define device_bpp (this->hidden->bpp)
   107 #define mode_flags (this->hidden->flags)
   108 #define window (this->hidden->window)
   109 #define windowView (this->hidden->view)
   110 
   111 /* Interface for hardware fill not (yet) in the public API */
   112 int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
   113                       unsigned int w, unsigned int h, unsigned int color);
   114 int CGSDisplayCanHWFill (CGDirectDisplayID id);
   115 
   116 /* Bootstrap functions */
   117 static int              QZ_Available ();
   118 static SDL_VideoDevice* QZ_CreateDevice (int device_index);
   119 static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   120 
   121 /* Initialization, Query, Setup, and Redrawing functions */
   122 static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   123 
   124 static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
   125 					 Uint32 flags);
   126 static void         QZ_UnsetVideoMode   (_THIS);
   127 
   128 static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
   129 					 int width, int height, int bpp, 
   130 					 Uint32 flags);
   131 static int          QZ_ToggleFullScreen (_THIS, int on);
   132 static int          QZ_SetColors        (_THIS, int first_color, 
   133 					 int num_colors, SDL_Color *colors);
   134 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   135 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   136 static void         QZ_VideoQuit        (_THIS);
   137 
   138 /* Hardware surface functions (for fullscreen mode only) */
   139 static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
   140 static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
   141 static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
   142 static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
   143 /* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
   144 
   145 /* Gamma Functions */
   146 static int QZ_SetGamma     (_THIS, float red, float green, float blue);
   147 static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
   148 static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
   149 static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
   150 
   151 /* OpenGL functions */
   152 static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
   153 static void   QZ_TearDownOpenGL (_THIS);
   154 static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   155 static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   156 static int    QZ_GL_MakeCurrent    (_THIS);
   157 static void   QZ_GL_SwapBuffers    (_THIS);
   158 static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
   159 
   160 /* Private function to warp the cursor (used internally) */
   161 static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
   162 
   163 /* Cursor and Mouse functions */
   164 static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   165 static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   166                                           int w, int h, int hot_x, int hot_y);
   167 static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   168 static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   169 static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   170 static void         QZ_CheckMouseMode   (_THIS);
   171 
   172 /* Event functions */
   173 static void         QZ_InitOSKeymap     (_THIS);
   174 static void         QZ_PumpEvents       (_THIS);
   175 
   176 /* Window Manager functions */
   177 static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
   178 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   179 static int  QZ_IconifyWindow (_THIS);
   180 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   181 /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/