comparison src/video/quartz/SDL_QuartzVideo.h @ 501:74262d2647ca

Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Oct 2002 05:07:57 +0000
parents 4b8ff8ac2c07
children 2536446a92de
comparison
equal deleted inserted replaced
500:c335456c421d 501:74262d2647ca
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 /* 23 /*
24 @file SDL_QuartzVideo.h 24 @file SDL_QuartzVideo.h
25 @author Darrell Walisser 25 @author Darrell Walisser, Max Horn, et al.
26 26
27 @abstract SDL video driver for MacOS X. 27 @abstract SDL video driver for Mac OS X.
28 28
29 @discussion 29 @discussion
30 30
31 TODO 31 TODO
32 - Hardware Cursor support with NSCursor instead of Carbon 32 - Hardware Cursor support with NSCursor instead of Carbon
33 - Keyboard repeat/mouse speed adjust (if needed) 33 - Keyboard repeat/mouse speed adjust (if needed)
34 - Multiple monitor support (currently only main display) 34 - Multiple monitor support (currently only main display)
35 - Accelerated blitting support 35 - Accelerated blitting support
36 - Fix white OpenGL window on minimize (fixed) 36 - Fix white OpenGL window on minimize (fixed) (update: broken again on 10.2)
37 - Find out what events should be sent/ignored if window is mimimized 37 - Find out what events should be sent/ignored if window is minimized
38 - Find a way to deal with external resolution/depth switch while app is running 38 - Find a way to deal with external resolution/depth switch while app is running
39 - Resizeable windows 39 - Resizeable windows (done)
40 - Check accuracy of QZ_SetGamma() 40 - Check accuracy of QZ_SetGamma()
41 Problems: 41 Problems:
42 - OGL not working in full screen with software renderer 42 - OGL not working in full screen with software renderer
43 - SetColors sets palette correctly but clears framebuffer 43 - SetColors sets palette correctly but clears framebuffer
44 - Crash in CG after several mode switches (I think this has been fixed) 44 - Crash in CG after several mode switches (I think this has been fixed)
45 - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows) 45 - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
46 - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) 46 - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
47 - Warping cursor delays mouse events for a fraction of a second, 47 - Warping cursor delays mouse events for a fraction of a second,
48 there is a hack around this that helps a bit 48 there is a hack around this that helps a bit
49 */ 49 */
50 50
51 #include <Cocoa/Cocoa.h> 51 #include <Cocoa/Cocoa.h>
60 #include "SDL_sysvideo.h" 60 #include "SDL_sysvideo.h"
61 #include "SDL_pixels_c.h" 61 #include "SDL_pixels_c.h"
62 #include "SDL_events_c.h" 62 #include "SDL_events_c.h"
63 63
64 /* 64 /*
65 Add methods to get at private members of NSScreen. 65 Add methods to get at private members of NSScreen.
66 Since there is a bug in Apple's screen switching code 66 Since there is a bug in Apple's screen switching code
67 that does not update this variable when switching 67 that does not update this variable when switching
68 to fullscreen, we'll set it manually (but only for the 68 to fullscreen, we'll set it manually (but only for the
69 main screen). 69 main screen).
70 */ 70 */
71 @interface NSScreen (NSScreenAccess) 71 @interface NSScreen (NSScreenAccess)
72 - (void) setFrame:(NSRect)frame; 72 - (void) setFrame:(NSRect)frame;
73 @end 73 @end
74 74
77 { 77 {
78 _frame = frame; 78 _frame = frame;
79 } 79 }
80 @end 80 @end
81 81
82 /* This is a workaround to directly access NSOpenGLContext's CGL context */ 82 /*
83 /* We need to do this in order to check for errors */ 83 This is a workaround to directly access NSOpenGLContext's CGL context
84 We need this to check for errors NSOpenGLContext doesn't support
85 */
84 @interface NSOpenGLContext (CGLContextAccess) 86 @interface NSOpenGLContext (CGLContextAccess)
85 - (CGLContextObj) cglContext; 87 - (CGLContextObj) cglContext;
86 @end 88 @end
87 89
88 @implementation NSOpenGLContext (CGLContextAccess) 90 @implementation NSOpenGLContext (CGLContextAccess)
90 { 92 {
91 return _contextAuxiliary; 93 return _contextAuxiliary;
92 } 94 }
93 @end 95 @end
94 96
95 /* Structure for rez switch gamma fades */ 97 /*
96 /* We can hide the monitor flicker by setting the gamma tables to 0 */ 98 Structure for rez switch gamma fades
99 We can hide the monitor flicker by setting the gamma tables to 0
100 */
97 #define QZ_GAMMA_TABLE_SIZE 256 101 #define QZ_GAMMA_TABLE_SIZE 256
98 102
99 typedef struct { 103 typedef struct {
100 104
101 CGGammaValue red[QZ_GAMMA_TABLE_SIZE]; 105 CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
110 CGDirectDisplayID display; /* 0 == main display (only support single display) */ 114 CGDirectDisplayID display; /* 0 == main display (only support single display) */
111 CFDictionaryRef mode; /* current mode of the display */ 115 CFDictionaryRef mode; /* current mode of the display */
112 CFDictionaryRef save_mode; /* original mode of the display */ 116 CFDictionaryRef save_mode; /* original mode of the display */
113 CFArrayRef mode_list; /* list of available fullscreen modes */ 117 CFArrayRef mode_list; /* list of available fullscreen modes */
114 CGDirectPaletteRef palette; /* palette of an 8-bit display */ 118 CGDirectPaletteRef palette; /* palette of an 8-bit display */
115 NSOpenGLContext *gl_context; /* object that represents an OpenGL rendering context */ 119 NSOpenGLContext *gl_context; /* OpenGL rendering context */
116 Uint32 width, height, bpp; /* frequently used data about the display */ 120 Uint32 width, height, bpp; /* frequently used data about the display */
117 Uint32 flags; /* flags for mode, for teardown purposes */ 121 Uint32 flags; /* flags for current mode, for teardown purposes */
118 Uint32 video_set; /* boolean; indicates if video was set correctly */ 122 Uint32 video_set; /* boolean; indicates if video was set correctly */
119 Uint32 warp_flag; /* boolean; notify to event loop that a warp just occured */ 123 Uint32 warp_flag; /* boolean; notify to event loop that a warp just occured */
120 Uint32 warp_ticks; /* timestamp when the warp occured */ 124 Uint32 warp_ticks; /* timestamp when the warp occured */
121 NSWindow *window; /* Cocoa window to implement the SDL window */ 125 NSWindow *window; /* Cocoa window to implement the SDL window */
122 NSQuickDrawView *view; /* the window's view; draw 2D into this view */ 126 NSQuickDrawView *view; /* the window's view; draw 2D and OpenGL into this view */
127 SDL_Surface *resize_icon; /* icon for the resize badge, we have to draw it by hand */
128 SDL_GrabMode current_grab_mode; /* default value is SDL_GRAB_OFF */
129 BOOL in_foreground; /* boolean; indicate if app is in foreground or not */
130 SDL_Rect **client_mode_list; /* resolution list to pass back to client */
131 SDLKey keymap[256]; /* Mac OS X to SDL key mapping */
132 Uint32 current_mods; /* current keyboard modifiers, to track modifier state */
133 Uint32 last_virtual_button;/* last virtual mouse button pressed */
134
123 ImageDescriptionHandle yuv_idh; 135 ImageDescriptionHandle yuv_idh;
124 MatrixRecordPtr yuv_matrix; 136 MatrixRecordPtr yuv_matrix;
125 DecompressorComponent yuv_codec; 137 DecompressorComponent yuv_codec;
126 ImageSequence yuv_seq; 138 ImageSequence yuv_seq;
127 PlanarPixmapInfoYUV420 *yuv_pixmap; 139 PlanarPixmapInfoYUV420 *yuv_pixmap;
144 #define qz_window (this->hidden->window) 156 #define qz_window (this->hidden->window)
145 #define window_view (this->hidden->view) 157 #define window_view (this->hidden->view)
146 #define video_set (this->hidden->video_set) 158 #define video_set (this->hidden->video_set)
147 #define warp_ticks (this->hidden->warp_ticks) 159 #define warp_ticks (this->hidden->warp_ticks)
148 #define warp_flag (this->hidden->warp_flag) 160 #define warp_flag (this->hidden->warp_flag)
161 #define resize_icon (this->hidden->resize_icon)
162 #define current_grab_mode (this->hidden->current_grab_mode)
163 #define in_foreground (this->hidden->in_foreground)
164 #define client_mode_list (this->hidden->client_mode_list)
165 #define keymap (this->hidden->keymap)
166 #define current_mods (this->hidden->current_mods)
167 #define last_virtual_button (this->hidden->last_virtual_button)
168
149 #define yuv_idh (this->hidden->yuv_idh) 169 #define yuv_idh (this->hidden->yuv_idh)
150 #define yuv_matrix (this->hidden->yuv_matrix) 170 #define yuv_matrix (this->hidden->yuv_matrix)
151 #define yuv_codec (this->hidden->yuv_codec) 171 #define yuv_codec (this->hidden->yuv_codec)
152 #define yuv_seq (this->hidden->yuv_seq) 172 #define yuv_seq (this->hidden->yuv_seq)
153 #define yuv_pixmap (this->hidden->yuv_pixmap) 173 #define yuv_pixmap (this->hidden->yuv_pixmap)
154 #define yuv_data (this->hidden->yuv_data) 174 #define yuv_data (this->hidden->yuv_data)
155 #define yuv_width (this->hidden->yuv_width) 175 #define yuv_width (this->hidden->yuv_width)
156 #define yuv_height (this->hidden->yuv_height) 176 #define yuv_height (this->hidden->yuv_height)
157 #define yuv_port (this->hidden->yuv_port) 177 #define yuv_port (this->hidden->yuv_port)
158 178
159 /* Obscuring code: maximum number of windows above ours (inclusive) */ 179 /*
180 Obscuring code: maximum number of windows above ours (inclusive)
181
182 Note: this doesn't work too well in practice and should be
183 phased out when we add OpenGL 2D acceleration. It was never
184 enabled in the first place, so this shouldn't be a problem ;-)
185 */
160 #define kMaxWindows 256 186 #define kMaxWindows 256
161 187
162 /* Some of the Core Graphics Server API for obscuring code */ 188 /* Some of the Core Graphics Server API for obscuring code */
163 #define kCGSWindowLevelTop 2147483632 189 #define kCGSWindowLevelTop 2147483632
164 #define kCGSWindowLevelDockIconDrag 500 190 #define kCGSWindowLevelDockIconDrag 500
169 #define kCGSWindowLevelDockIcon 11 195 #define kCGSWindowLevelDockIcon 11
170 #define kCGSWindowLevelDock 10 196 #define kCGSWindowLevelDock 10
171 #define kCGSWindowLevelUtility 3 197 #define kCGSWindowLevelUtility 3
172 #define kCGSWindowLevelNormal 0 198 #define kCGSWindowLevelNormal 0
173 199
174 /* For completeness; We never use these window levels, they are always below us 200 /*
175 #define kCGSWindowLevelMBarShadow -20 201 For completeness; We never use these window levels, they are always below us
176 #define kCGSWindowLevelDesktopPicture -2147483647 202 #define kCGSWindowLevelMBarShadow -20
177 #define kCGSWindowLevelDesktop -2147483648 203 #define kCGSWindowLevelDesktopPicture -2147483647
204 #define kCGSWindowLevelDesktop -2147483648
178 */ 205 */
179 206
180 typedef CGError CGSError; 207 typedef CGError CGSError;
181 typedef long CGSWindowCount; 208 typedef long CGSWindowCount;
182 typedef void * CGSConnectionID; 209 typedef void * CGSConnectionID;
225 Uint32 flags); 252 Uint32 flags);
226 static int QZ_ToggleFullScreen (_THIS, int on); 253 static int QZ_ToggleFullScreen (_THIS, int on);
227 static int QZ_SetColors (_THIS, int first_color, 254 static int QZ_SetColors (_THIS, int first_color,
228 int num_colors, SDL_Color *colors); 255 int num_colors, SDL_Color *colors);
229 static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects); 256 static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects);
230 static int QZ_LockWindow (_THIS, SDL_Surface *surface); 257 static int QZ_LockWindow (_THIS, SDL_Surface *surface);
231 static void QZ_UnlockWindow (_THIS, SDL_Surface *surface); 258 static void QZ_UnlockWindow (_THIS, SDL_Surface *surface);
232 static void QZ_UpdateRects (_THIS, int num_rects, SDL_Rect *rects); 259 static void QZ_UpdateRects (_THIS, int num_rects, SDL_Rect *rects);
233 static void QZ_VideoQuit (_THIS); 260 static void QZ_VideoQuit (_THIS);
234 261
235 /* Hardware surface functions (for fullscreen mode only) */ 262 /* Hardware surface functions (for fullscreen mode only) */
244 static int QZ_GetGamma (_THIS, float *red, float *green, float *blue); 271 static int QZ_GetGamma (_THIS, float *red, float *green, float *blue);
245 static int QZ_SetGammaRamp (_THIS, Uint16 *ramp); 272 static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
246 static int QZ_GetGammaRamp (_THIS, Uint16 *ramp); 273 static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
247 274
248 /* OpenGL functions */ 275 /* OpenGL functions */
249 static int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags); 276 static int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
250 static void QZ_TearDownOpenGL (_THIS); 277 static void QZ_TearDownOpenGL (_THIS);
251 static void* QZ_GL_GetProcAddress (_THIS, const char *proc); 278 static void* QZ_GL_GetProcAddress (_THIS, const char *proc);
252 static int QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int* value); 279 static int QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int* value);
253 static int QZ_GL_MakeCurrent (_THIS); 280 static int QZ_GL_MakeCurrent (_THIS);
254 static void QZ_GL_SwapBuffers (_THIS); 281 static void QZ_GL_SwapBuffers (_THIS);
255 static int QZ_GL_LoadLibrary (_THIS, const char *location); 282 static int QZ_GL_LoadLibrary (_THIS, const char *location);
269 /* Event functions */ 296 /* Event functions */
270 static void QZ_InitOSKeymap (_THIS); 297 static void QZ_InitOSKeymap (_THIS);
271 static void QZ_PumpEvents (_THIS); 298 static void QZ_PumpEvents (_THIS);
272 299
273 /* Window Manager functions */ 300 /* Window Manager functions */
274 static void QZ_SetCaption (_THIS, const char *title, const char *icon); 301 static void QZ_SetCaption (_THIS, const char *title, const char *icon);
275 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask); 302 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask);
276 static int QZ_IconifyWindow (_THIS); 303 static int QZ_IconifyWindow (_THIS);
277 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode); 304 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
278 /*static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/ 305 /*static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/
279 306
280 /* YUV functions */ 307 /* YUV functions */
281 static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height, 308 static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
282 Uint32 format, SDL_Surface *display); 309 Uint32 format, SDL_Surface *display);
283