src/video/quartz/SDL_QuartzVideo.h
changeset 47 45b1c4303f87
child 58 bd6b0a910a65
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Thu Jun 07 14:28:11 2001 +0000
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +/*	
    1.27 +    @file   SDL_QuartzVideo.h
    1.28 +    @author Darrell Walisser
    1.29 +    
    1.30 +    @abstract SDL video driver for MacOS X.
    1.31 +    
    1.32 +    @discussion
    1.33 +    
    1.34 +    TODO
    1.35 +        - Hardware Cursor support with NSCursor instead of Carbon
    1.36 +        - Keyboard repeat/mouse speed adjust (if needed)
    1.37 +        - Multiple monitor support (currently only main display)
    1.38 +        - Accelerated blitting support
    1.39 +        - Set the window icon (dock icon when API is available)
    1.40 +        - Avoid erasing window on minimize, or disable minimize
    1.41 +    Problems:
    1.42 +        - OGL not working in full screen with software renderer
    1.43 +        - SetColors sets palette correctly but clears framebuffer
    1.44 +        - Crash in CG after several mode switches
    1.45 +        - Retained windows don't draw their title bar quite right (OS Bug)
    1.46 +        - Should I do depth switching for windowed modes?
    1.47 +        - Launch times are slow, maybe prebinding will help
    1.48 +        - Direct framebuffer access has some artifacts, maybe a driver issue
    1.49 +        - Cursor in 8 bit modes is screwy
    1.50 +        - Modifier + mouse-down maps alternate mouse button, but if modifier is released
    1.51 +           before mouse button, corresponding mouse-up event is not generated.
    1.52 +        - Clicking in content activates app, but doesn't generate the activate event,
    1.53 +          and subsequent switches generate no activate/deactivate events! (OS Bug I hope)
    1.54 +*/
    1.55 +
    1.56 +#include <ApplicationServices/ApplicationServices.h>
    1.57 +#include <OpenGL/OpenGL.h>
    1.58 +#include <Cocoa/Cocoa.h>
    1.59 +#include <Carbon/Carbon.h>
    1.60 +
    1.61 +#include "SDL_video.h"
    1.62 +#include "SDL_error.h"
    1.63 +#include "SDL_syswm.h"
    1.64 +#include "SDL_sysvideo.h"
    1.65 +#include "SDL_pixels_c.h"
    1.66 +#include "SDL_events_c.h"
    1.67 +
    1.68 +/* This is a workaround to directly access NSOpenGLContext's CGL context */
    1.69 +/* We need to do this in order to check for errors */
    1.70 +@interface NSOpenGLContext (CGLContextAccess)
    1.71 +- (CGLContextObj) cglContext;
    1.72 +@end
    1.73 +
    1.74 +@implementation NSOpenGLContext (CGLContextAccess)
    1.75 +- (CGLContextObj) cglContext;
    1.76 +{
    1.77 +    return _contextAuxiliary;
    1.78 +}
    1.79 +@end
    1.80 +
    1.81 +typedef struct SDL_PrivateVideoData {
    1.82 +
    1.83 +    CGDirectDisplayID  display; /* 0 == main display */
    1.84 +    CFDictionaryRef    mode;
    1.85 +    CFDictionaryRef    save_mode;
    1.86 +    CFArrayRef         mode_list;
    1.87 +    CGDirectPaletteRef palette;
    1.88 +    NSOpenGLContext    *gl_context;
    1.89 +    int                width, height, bpp;
    1.90 +    Uint32             flags;
    1.91 +    
    1.92 +    /* Window-only fields */
    1.93 +    NSWindow        *window;
    1.94 +    NSQuickDrawView *view;
    1.95 +    NSString        *title;
    1.96 +    
    1.97 +} SDL_PrivateVideoData ;
    1.98 +
    1.99 +#define _THIS	SDL_VideoDevice *this
   1.100 +#define display_id (this->hidden->display)
   1.101 +#define mode (this->hidden->mode)
   1.102 +#define save_mode (this->hidden->save_mode)
   1.103 +#define mode_list (this->hidden->mode_list)
   1.104 +#define palette (this->hidden->palette)
   1.105 +#define glcontext (this->hidden->glcontext)
   1.106 +#define objc_video (this->hidden->objc_video)
   1.107 +#define gl_context (this->hidden->gl_context)
   1.108 +#define device_width (this->hidden->width)
   1.109 +#define device_height (this->hidden->height)
   1.110 +#define device_bpp (this->hidden->bpp)
   1.111 +#define mode_flags (this->hidden->flags)
   1.112 +#define window (this->hidden->window)
   1.113 +#define windowView (this->hidden->view)
   1.114 +#define windowTitle (this->hidden->title)
   1.115 +
   1.116 +/* Interface for hardware fill not (yet) in the public API */
   1.117 +int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
   1.118 +                      unsigned int w, unsigned int h, unsigned int color);
   1.119 +int CGSDisplayCanHWFill (CGDirectDisplayID id);
   1.120 +
   1.121 +/* Bootstrap functions */
   1.122 +static int              QZ_Available ();
   1.123 +static SDL_VideoDevice* QZ_CreateDevice (int device_index);
   1.124 +static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   1.125 +
   1.126 +/* Initialization, Query, Setup, and Redrawing functions */
   1.127 +static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   1.128 +
   1.129 +static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
   1.130 +					 Uint32 flags);
   1.131 +static void         QZ_UnsetVideoMode   (_THIS);
   1.132 +
   1.133 +static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
   1.134 +					 int width, int height, int bpp, 
   1.135 +					 Uint32 flags);
   1.136 +static int          QZ_ToggleFullScreen (_THIS, int on);
   1.137 +static int          QZ_SetColors        (_THIS, int first_color, 
   1.138 +					 int num_colors, SDL_Color *colors);
   1.139 +static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   1.140 +static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   1.141 +static void         QZ_VideoQuit        (_THIS);
   1.142 +
   1.143 +/* Hardware surface functions (for fullscreen mode only) */
   1.144 +static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
   1.145 +static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
   1.146 +static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
   1.147 +static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
   1.148 +/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
   1.149 +
   1.150 +/* Gamma Functions */
   1.151 +static int QZ_SetGamma     (_THIS, float red, float green, float blue);
   1.152 +static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
   1.153 +static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
   1.154 +static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
   1.155 +
   1.156 +/* OpenGL functions */
   1.157 +static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
   1.158 +static void   QZ_TearDownOpenGL (_THIS);
   1.159 +static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   1.160 +static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   1.161 +static int    QZ_GL_MakeCurrent    (_THIS);
   1.162 +static void   QZ_GL_SwapBuffers    (_THIS);
   1.163 +static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
   1.164 +
   1.165 +/* Private function to warp the cursor (used internally) */
   1.166 +static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
   1.167 +
   1.168 +/* Cursor and Mouse functions */
   1.169 +static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   1.170 +static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   1.171 +                                          int w, int h, int hot_x, int hot_y);
   1.172 +static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   1.173 +static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   1.174 +static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   1.175 +static void         QZ_CheckMouseMode   (_THIS);
   1.176 +
   1.177 +/* Event functions */
   1.178 +static void         QZ_InitOSKeymap     (_THIS);
   1.179 +static void         QZ_PumpEvents       (_THIS);
   1.180 +
   1.181 +/* Window Manager functions */
   1.182 +static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
   1.183 +static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   1.184 +static int  QZ_IconifyWindow (_THIS);
   1.185 +static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   1.186 +/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/