Skip to content

Latest commit

 

History

History
360 lines (306 loc) · 15.2 KB

SDL_QuartzVideo.h

File metadata and controls

360 lines (306 loc) · 15.2 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Mar 6, 2002
Mar 6, 2002
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Jun 1, 2002
Jun 1, 2002
23
/*
24
@file SDL_QuartzVideo.h
Oct 5, 2002
Oct 5, 2002
25
@author Darrell Walisser, Max Horn, et al.
Oct 5, 2002
Oct 5, 2002
27
@abstract SDL video driver for Mac OS X.
28
29
30
31
32
33
34
35
@discussion
TODO
- Hardware Cursor support with NSCursor instead of Carbon
- Keyboard repeat/mouse speed adjust (if needed)
- Multiple monitor support (currently only main display)
- Accelerated blitting support
Oct 5, 2002
Oct 5, 2002
36
37
- Fix white OpenGL window on minimize (fixed) (update: broken again on 10.2)
- Find out what events should be sent/ignored if window is minimized
Jun 1, 2002
Jun 1, 2002
38
- Find a way to deal with external resolution/depth switch while app is running
Oct 5, 2002
Oct 5, 2002
39
- Resizeable windows (done)
Jan 22, 2002
Jan 22, 2002
40
- Check accuracy of QZ_SetGamma()
41
42
43
Problems:
- OGL not working in full screen with software renderer
- SetColors sets palette correctly but clears framebuffer
Jun 1, 2002
Jun 1, 2002
44
- Crash in CG after several mode switches (I think this has been fixed)
Jan 22, 2002
Jan 22, 2002
45
- Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
Oct 5, 2002
Oct 5, 2002
46
- Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
Jan 22, 2002
Jan 22, 2002
47
48
- Warping cursor delays mouse events for a fraction of a second,
there is a hack around this that helps a bit
49
50
51
*/
#include <Cocoa/Cocoa.h>
Jan 22, 2002
Jan 22, 2002
52
#include <OpenGL/OpenGL.h>
53
#include <Carbon/Carbon.h>
Jun 1, 2002
Jun 1, 2002
54
#include <QuickTime/QuickTime.h>
Dec 15, 2002
Dec 15, 2002
55
#include <IOKit/IOKitLib.h> /* For powersave handling */
Feb 1, 2003
Feb 1, 2003
56
#include <pthread.h>
Feb 1, 2003
Feb 1, 2003
58
#include "SDL_thread.h"
59
60
#include "SDL_video.h"
#include "SDL_error.h"
Jan 22, 2002
Jan 22, 2002
61
#include "SDL_timer.h"
62
63
64
65
66
#include "SDL_syswm.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
Aug 12, 2002
Aug 12, 2002
67
/*
Oct 5, 2002
Oct 5, 2002
68
69
70
71
72
Add methods to get at private members of NSScreen.
Since there is a bug in Apple's screen switching code
that does not update this variable when switching
to fullscreen, we'll set it manually (but only for the
main screen).
Aug 12, 2002
Aug 12, 2002
73
74
75
76
77
78
79
80
81
82
83
84
*/
@interface NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
@end
@implementation NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
{
_frame = frame;
}
@end
Oct 5, 2002
Oct 5, 2002
85
86
87
88
/*
This is a workaround to directly access NSOpenGLContext's CGL context
We need this to check for errors NSOpenGLContext doesn't support
*/
89
90
91
92
93
94
95
96
97
98
99
@interface NSOpenGLContext (CGLContextAccess)
- (CGLContextObj) cglContext;
@end
@implementation NSOpenGLContext (CGLContextAccess)
- (CGLContextObj) cglContext;
{
return _contextAuxiliary;
}
@end
Oct 5, 2002
Oct 5, 2002
100
101
102
103
/*
Structure for rez switch gamma fades
We can hide the monitor flicker by setting the gamma tables to 0
*/
Jan 22, 2002
Jan 22, 2002
104
105
106
107
108
109
110
111
112
113
114
#define QZ_GAMMA_TABLE_SIZE 256
typedef struct {
CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
CGGammaValue green[QZ_GAMMA_TABLE_SIZE];
CGGammaValue blue[QZ_GAMMA_TABLE_SIZE];
} SDL_QuartzGammaTable;
/* Main driver structure to store required state information */
115
116
typedef struct SDL_PrivateVideoData {
Jan 22, 2002
Jan 22, 2002
117
118
119
120
121
CGDirectDisplayID display; /* 0 == main display (only support single display) */
CFDictionaryRef mode; /* current mode of the display */
CFDictionaryRef save_mode; /* original mode of the display */
CFArrayRef mode_list; /* list of available fullscreen modes */
CGDirectPaletteRef palette; /* palette of an 8-bit display */
Oct 5, 2002
Oct 5, 2002
122
NSOpenGLContext *gl_context; /* OpenGL rendering context */
Jan 22, 2002
Jan 22, 2002
123
Uint32 width, height, bpp; /* frequently used data about the display */
Oct 5, 2002
Oct 5, 2002
124
Uint32 flags; /* flags for current mode, for teardown purposes */
Jan 22, 2002
Jan 22, 2002
125
126
127
128
Uint32 video_set; /* boolean; indicates if video was set correctly */
Uint32 warp_flag; /* boolean; notify to event loop that a warp just occured */
Uint32 warp_ticks; /* timestamp when the warp occured */
NSWindow *window; /* Cocoa window to implement the SDL window */
Oct 5, 2002
Oct 5, 2002
129
130
131
132
133
134
135
136
NSQuickDrawView *view; /* the window's view; draw 2D and OpenGL into this view */
SDL_Surface *resize_icon; /* icon for the resize badge, we have to draw it by hand */
SDL_GrabMode current_grab_mode; /* default value is SDL_GRAB_OFF */
BOOL in_foreground; /* boolean; indicate if app is in foreground or not */
SDL_Rect **client_mode_list; /* resolution list to pass back to client */
SDLKey keymap[256]; /* Mac OS X to SDL key mapping */
Uint32 current_mods; /* current keyboard modifiers, to track modifier state */
Uint32 last_virtual_button;/* last virtual mouse button pressed */
Dec 27, 2002
Dec 27, 2002
137
138
139
140
io_connect_t power_connection; /* used with IOKit to detect wake from sleep */
Uint8 expect_mouse_up; /* used to determine when to send mouse up events */
Uint8 grab_state; /* used to manage grab behavior */
NSPoint cursor_loc; /* saved cursor coords, for activate/deactivate when grabbed */
Apr 20, 2003
Apr 20, 2003
141
142
BOOL cursor_visible; /* tells if cursor was instructed to be hidden or not (SDL_ShowCursor) */
BOOL cursor_hidden; /* tells if cursor is *actually* hidden or not */
Feb 1, 2003
Feb 1, 2003
143
144
145
146
147
Uint8* sw_buffers[2]; /* pointers to the two software buffers for double-buffer emulation */
SDL_Thread *thread; /* thread for async updates to the screen */
SDL_sem *sem1, *sem2; /* synchronization for async screen updates */
Uint8 *current_buffer; /* the buffer being copied to the screen */
BOOL quit_thread; /* used to quit the async blitting thread */
Dec 27, 2002
Dec 27, 2002
148
Jun 1, 2002
Jun 1, 2002
149
150
151
152
153
154
155
156
ImageDescriptionHandle yuv_idh;
MatrixRecordPtr yuv_matrix;
DecompressorComponent yuv_codec;
ImageSequence yuv_seq;
PlanarPixmapInfoYUV420 *yuv_pixmap;
Sint16 yuv_width, yuv_height;
CGrafPtr yuv_port;
157
158
} SDL_PrivateVideoData ;
Jun 1, 2002
Jun 1, 2002
159
#define _THIS SDL_VideoDevice *this
160
161
162
163
164
165
166
167
168
169
#define display_id (this->hidden->display)
#define mode (this->hidden->mode)
#define save_mode (this->hidden->save_mode)
#define mode_list (this->hidden->mode_list)
#define palette (this->hidden->palette)
#define gl_context (this->hidden->gl_context)
#define device_width (this->hidden->width)
#define device_height (this->hidden->height)
#define device_bpp (this->hidden->bpp)
#define mode_flags (this->hidden->flags)
Aug 21, 2001
Aug 21, 2001
170
#define qz_window (this->hidden->window)
Jan 22, 2002
Jan 22, 2002
171
172
173
174
#define window_view (this->hidden->view)
#define video_set (this->hidden->video_set)
#define warp_ticks (this->hidden->warp_ticks)
#define warp_flag (this->hidden->warp_flag)
Oct 5, 2002
Oct 5, 2002
175
176
177
178
179
180
181
#define resize_icon (this->hidden->resize_icon)
#define current_grab_mode (this->hidden->current_grab_mode)
#define in_foreground (this->hidden->in_foreground)
#define client_mode_list (this->hidden->client_mode_list)
#define keymap (this->hidden->keymap)
#define current_mods (this->hidden->current_mods)
#define last_virtual_button (this->hidden->last_virtual_button)
Dec 27, 2002
Dec 27, 2002
182
183
184
185
186
#define power_connection (this->hidden->power_connection)
#define expect_mouse_up (this->hidden->expect_mouse_up)
#define grab_state (this->hidden->grab_state)
#define cursor_loc (this->hidden->cursor_loc)
#define cursor_visible (this->hidden->cursor_visible)
Apr 20, 2003
Apr 20, 2003
187
#define cursor_hidden (this->hidden->cursor_hidden)
Feb 1, 2003
Feb 1, 2003
188
189
190
191
192
193
#define sw_buffers (this->hidden->sw_buffers)
#define thread (this->hidden->thread)
#define sem1 (this->hidden->sem1)
#define sem2 (this->hidden->sem2)
#define current_buffer (this->hidden->current_buffer)
#define quit_thread (this->hidden->quit_thread)
Oct 5, 2002
Oct 5, 2002
194
Jun 1, 2002
Jun 1, 2002
195
196
197
198
199
200
201
202
203
#define yuv_idh (this->hidden->yuv_idh)
#define yuv_matrix (this->hidden->yuv_matrix)
#define yuv_codec (this->hidden->yuv_codec)
#define yuv_seq (this->hidden->yuv_seq)
#define yuv_pixmap (this->hidden->yuv_pixmap)
#define yuv_data (this->hidden->yuv_data)
#define yuv_width (this->hidden->yuv_width)
#define yuv_height (this->hidden->yuv_height)
#define yuv_port (this->hidden->yuv_port)
Jan 22, 2002
Jan 22, 2002
204
Dec 27, 2002
Dec 27, 2002
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* grab states - the input is in one of these states */
enum {
QZ_UNGRABBED = 0,
QZ_VISIBLE_GRAB,
QZ_INVISIBLE_GRAB
};
/* grab actions - these can change the grabbed state */
enum {
QZ_ENABLE_GRAB = 0,
QZ_DISABLE_GRAB,
QZ_HIDECURSOR,
QZ_SHOWCURSOR
};
Oct 5, 2002
Oct 5, 2002
221
222
223
224
225
226
227
/*
Obscuring code: maximum number of windows above ours (inclusive)
Note: this doesn't work too well in practice and should be
phased out when we add OpenGL 2D acceleration. It was never
enabled in the first place, so this shouldn't be a problem ;-)
*/
Jan 22, 2002
Jan 22, 2002
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#define kMaxWindows 256
/* Some of the Core Graphics Server API for obscuring code */
#define kCGSWindowLevelTop 2147483632
#define kCGSWindowLevelDockIconDrag 500
#define kCGSWindowLevelDockMenu 101
#define kCGSWindowLevelMenuIgnore 21
#define kCGSWindowLevelMenu 20
#define kCGSWindowLevelDockLabel 12
#define kCGSWindowLevelDockIcon 11
#define kCGSWindowLevelDock 10
#define kCGSWindowLevelUtility 3
#define kCGSWindowLevelNormal 0
Oct 5, 2002
Oct 5, 2002
242
243
244
245
246
/*
For completeness; We never use these window levels, they are always below us
#define kCGSWindowLevelMBarShadow -20
#define kCGSWindowLevelDesktopPicture -2147483647
#define kCGSWindowLevelDesktop -2147483648
Jan 22, 2002
Jan 22, 2002
247
*/
Jan 22, 2002
Jan 22, 2002
249
typedef CGError CGSError;
Jun 1, 2002
Jun 1, 2002
250
251
252
typedef long CGSWindowCount;
typedef void * CGSConnectionID;
typedef int CGSWindowID;
Jan 22, 2002
Jan 22, 2002
253
254
255
256
257
258
typedef CGSWindowID* CGSWindowIDList;
typedef CGWindowLevel CGSWindowLevel;
typedef NSRect CGSRect;
extern CGSConnectionID _CGSDefaultConnection ();
Jun 1, 2002
Jun 1, 2002
259
extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
Jan 22, 2002
Jan 22, 2002
260
261
262
263
264
265
266
267
268
269
270
271
CGSConnectionID owner,
CGSWindowCount listCapacity,
CGSWindowIDList list,
CGSWindowCount *listCount);
extern CGSError CGSGetScreenRectForWindow (CGSConnectionID cid,
CGSWindowID wid,
CGSRect *rect);
extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
CGSWindowID wid,
CGSWindowLevel *level);
Jun 1, 2002
Jun 1, 2002
272
273
274
extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y,
unsigned int w, unsigned int h, unsigned int color);
Jan 22, 2002
Jan 22, 2002
275
276
277
278
extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
Feb 1, 2003
Feb 1, 2003
280
281
int CGSDisplayHWSync (CGDirectDisplayID id);
282
283
284
285
286
287
288
289
/* Bootstrap functions */
static int QZ_Available ();
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
static void QZ_DeleteDevice (SDL_VideoDevice *device);
/* Initialization, Query, Setup, and Redrawing functions */
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format);
Jun 1, 2002
Jun 1, 2002
290
291
static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format,
Uint32 flags);
292
293
static void QZ_UnsetVideoMode (_THIS);
Jun 1, 2002
Jun 1, 2002
294
295
296
static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current,
int width, int height, int bpp,
Uint32 flags);
297
static int QZ_ToggleFullScreen (_THIS, int on);
Jun 1, 2002
Jun 1, 2002
298
299
static int QZ_SetColors (_THIS, int first_color,
int num_colors, SDL_Color *colors);
Feb 1, 2003
Feb 1, 2003
300
301
302
303
304
305
306
static int QZ_LockDoubleBuffer (_THIS, SDL_Surface *surface);
static void QZ_UnlockDoubleBuffer (_THIS, SDL_Surface *surface);
static int QZ_ThreadFlip (_THIS);
static int QZ_FlipDoubleBuffer (_THIS, SDL_Surface *surface);
static void QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);
307
static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects);
Oct 5, 2002
Oct 5, 2002
308
static int QZ_LockWindow (_THIS, SDL_Surface *surface);
Sep 16, 2002
Sep 16, 2002
309
static void QZ_UnlockWindow (_THIS, SDL_Surface *surface);
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
static void QZ_UpdateRects (_THIS, int num_rects, SDL_Rect *rects);
static void QZ_VideoQuit (_THIS);
/* Hardware surface functions (for fullscreen mode only) */
static int QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
static int QZ_LockHWSurface(_THIS, SDL_Surface *surface);
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
/* static int QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
/* Gamma Functions */
static int QZ_SetGamma (_THIS, float red, float green, float blue);
static int QZ_GetGamma (_THIS, float *red, float *green, float *blue);
static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
/* OpenGL functions */
Oct 5, 2002
Oct 5, 2002
327
328
static int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
static void QZ_TearDownOpenGL (_THIS);
329
330
331
332
333
334
335
static void* QZ_GL_GetProcAddress (_THIS, const char *proc);
static int QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int* value);
static int QZ_GL_MakeCurrent (_THIS);
static void QZ_GL_SwapBuffers (_THIS);
static int QZ_GL_LoadLibrary (_THIS, const char *location);
/* Private function to warp the cursor (used internally) */
Jan 22, 2002
Jan 22, 2002
336
static void QZ_PrivateWarpCursor (_THIS, int x, int y);
337
338
339
/* Cursor and Mouse functions */
static void QZ_FreeWMCursor (_THIS, WMcursor *cursor);
Jun 1, 2002
Jun 1, 2002
340
341
static WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask,
int w, int h, int hot_x, int hot_y);
342
343
344
345
346
347
348
349
350
351
static int QZ_ShowWMCursor (_THIS, WMcursor *cursor);
static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y);
static void QZ_MoveWMCursor (_THIS, int x, int y);
static void QZ_CheckMouseMode (_THIS);
/* Event functions */
static void QZ_InitOSKeymap (_THIS);
static void QZ_PumpEvents (_THIS);
/* Window Manager functions */
Oct 5, 2002
Oct 5, 2002
352
353
354
static void QZ_SetCaption (_THIS, const char *title, const char *icon);
static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask);
static int QZ_IconifyWindow (_THIS);
355
356
static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
/*static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/
Jan 22, 2002
Jan 22, 2002
357
Jun 1, 2002
Jun 1, 2002
358
359
/* YUV functions */
static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
Dec 15, 2002
Dec 15, 2002
360
Uint32 format, SDL_Surface *display);