Skip to content

Latest commit

 

History

History
228 lines (202 loc) · 10.5 KB

SDL_QuartzVideo.h

File metadata and controls

228 lines (202 loc) · 10.5 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 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
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Jun 1, 2002
Jun 1, 2002
24
/*
25
@file SDL_QuartzVideo.h
Oct 5, 2002
Oct 5, 2002
26
@author Darrell Walisser, Max Horn, et al.
Oct 5, 2002
Oct 5, 2002
28
@abstract SDL video driver for Mac OS X.
29
30
31
32
33
34
35
36
@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
37
38
- 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
39
- Find a way to deal with external resolution/depth switch while app is running
Jan 22, 2002
Jan 22, 2002
40
- Check accuracy of QZ_SetGamma()
41
42
Problems:
- OGL not working in full screen with software renderer
Sep 14, 2011
Sep 14, 2011
43
- 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
Mar 8, 2006
Mar 8, 2006
51
52
53
/* Needs to be first, so QuickTime.h doesn't include glext.h (10.4) */
#include "SDL_opengl.h"
54
55
#include <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
Sep 24, 2006
Sep 24, 2006
56
#include <OpenGL/OpenGL.h> /* For CGL functions and types */
Apr 22, 2006
Apr 22, 2006
57
#include <IOKit/IOKitLib.h> /* For powersave handling */
Feb 1, 2003
Feb 1, 2003
58
#include <pthread.h>
Feb 1, 2003
Feb 1, 2003
60
#include "SDL_thread.h"
61
62
#include "SDL_video.h"
#include "SDL_error.h"
Jan 22, 2002
Jan 22, 2002
63
#include "SDL_timer.h"
Nov 23, 2005
Nov 23, 2005
64
#include "SDL_loadso.h"
Feb 16, 2006
Feb 16, 2006
65
66
67
68
#include "SDL_syswm.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Sep 21, 2009
Sep 21, 2009
70
71
#ifdef __powerpc__
Jan 4, 2004
Jan 4, 2004
72
73
74
/*
This is a workaround to directly access NSOpenGLContext's CGL context
We need this to check for errors NSOpenGLContext doesn't support
Sep 21, 2009
Sep 21, 2009
75
76
Please note this is only used on PowerPC (Intel Macs are guaranteed to
have a better API for this, since it showed up in Mac OS X 10.3).
Jan 4, 2004
Jan 4, 2004
77
78
79
80
*/
@interface NSOpenGLContext (CGLContextAccess)
- (CGLContextObj) cglContext;
@end
Sep 21, 2009
Sep 21, 2009
81
82
83
84
#endif
/* use this to get the CGLContext; it handles Cocoa interface changes. */
CGLContextObj QZ_GetCGLContextObj(NSOpenGLContext *nsctx);
Jan 4, 2004
Jan 4, 2004
85
86
Jan 22, 2002
Jan 22, 2002
87
/* Main driver structure to store required state information */
88
typedef struct SDL_PrivateVideoData {
Sep 16, 2011
Sep 16, 2011
89
BOOL use_new_mode_apis; /* 1 == >= 10.6 APIs available */
Apr 6, 2007
Apr 6, 2007
90
BOOL allow_screensaver; /* 0 == disable screensaver */
Jan 22, 2002
Jan 22, 2002
91
CGDirectDisplayID display; /* 0 == main display (only support single display) */
Aug 22, 2011
Aug 22, 2011
92
93
const void *mode; /* current mode of the display */
const void *save_mode; /* original mode of the display */
Oct 5, 2002
Oct 5, 2002
94
NSOpenGLContext *gl_context; /* OpenGL rendering context */
Jan 3, 2012
Jan 3, 2012
95
NSGraphicsContext *nsgfx_context; /* Cocoa graphics context */
Jan 22, 2002
Jan 22, 2002
96
Uint32 width, height, bpp; /* frequently used data about the display */
Oct 5, 2002
Oct 5, 2002
97
Uint32 flags; /* flags for current mode, for teardown purposes */
Jan 22, 2002
Jan 22, 2002
98
99
100
101
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 */
Sep 21, 2009
Sep 21, 2009
102
103
NSView *view; /* the window's view; draw 2D and OpenGL into this view */
CGContextRef cg_context; /* CoreGraphics rendering context */
Oct 5, 2002
Oct 5, 2002
104
105
106
107
108
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 */
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 */
Jul 11, 2007
Jul 11, 2007
109
NSText *field_edit; /* a field editor for keyboard composition processing */
Oct 5, 2002
Oct 5, 2002
110
Uint32 last_virtual_button;/* last virtual mouse button pressed */
Dec 27, 2002
Dec 27, 2002
111
112
113
114
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 */
Jan 4, 2004
Jan 4, 2004
115
116
BOOL cursor_should_be_visible; /* tells if cursor is supposed to be visible (SDL_ShowCursor) */
BOOL cursor_visible; /* tells if cursor is *actually* visible or not */
Feb 1, 2003
Feb 1, 2003
117
118
119
120
121
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 */
Mar 22, 2004
Mar 22, 2004
122
SInt32 system_version; /* used to dis-/enable workarounds depending on the system version */
Jun 1, 2002
Jun 1, 2002
123
Nov 23, 2005
Nov 23, 2005
124
void *opengl_library; /* dynamically loaded OpenGL library. */
Jan 4, 2004
Jan 4, 2004
125
} SDL_PrivateVideoData;
Jun 1, 2002
Jun 1, 2002
127
#define _THIS SDL_VideoDevice *this
128
129
130
#define display_id (this->hidden->display)
#define mode (this->hidden->mode)
#define save_mode (this->hidden->save_mode)
Sep 16, 2011
Sep 16, 2011
131
#define use_new_mode_apis (this->hidden->use_new_mode_apis)
Apr 6, 2007
Apr 6, 2007
132
#define allow_screensaver (this->hidden->allow_screensaver)
Sep 14, 2011
Sep 14, 2011
133
#define palette (this->hidden->palette)
134
#define gl_context (this->hidden->gl_context)
Jan 3, 2012
Jan 3, 2012
135
#define nsgfx_context (this->hidden->nsgfx_context)
136
137
138
139
#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
140
#define qz_window (this->hidden->window)
Jan 22, 2002
Jan 22, 2002
141
#define window_view (this->hidden->view)
Sep 21, 2009
Sep 21, 2009
142
#define cg_context (this->hidden->cg_context)
Jan 22, 2002
Jan 22, 2002
143
144
145
#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
146
147
148
149
150
#define resize_icon (this->hidden->resize_icon)
#define current_grab_mode (this->hidden->current_grab_mode)
#define client_mode_list (this->hidden->client_mode_list)
#define keymap (this->hidden->keymap)
#define current_mods (this->hidden->current_mods)
Jul 11, 2007
Jul 11, 2007
151
#define field_edit (this->hidden->field_edit)
Oct 5, 2002
Oct 5, 2002
152
#define last_virtual_button (this->hidden->last_virtual_button)
Dec 27, 2002
Dec 27, 2002
153
154
155
156
#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)
Jan 4, 2004
Jan 4, 2004
157
#define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
Dec 27, 2002
Dec 27, 2002
158
#define cursor_visible (this->hidden->cursor_visible)
Feb 1, 2003
Feb 1, 2003
159
#define sw_buffers (this->hidden->sw_buffers)
Sep 21, 2009
Sep 21, 2009
160
#define sw_contexts (this->hidden->sw_contexts)
Feb 1, 2003
Feb 1, 2003
161
162
163
164
165
#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)
Mar 22, 2004
Mar 22, 2004
166
#define system_version (this->hidden->system_version)
Nov 23, 2005
Nov 23, 2005
167
#define opengl_library (this->hidden->opengl_library)
Oct 5, 2002
Oct 5, 2002
168
Dec 27, 2002
Dec 27, 2002
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* 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
};
184
/* Gamma Functions */
Jan 4, 2004
Jan 4, 2004
185
186
187
188
int QZ_SetGamma (_THIS, float red, float green, float blue);
int QZ_GetGamma (_THIS, float *red, float *green, float *blue);
int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
189
190
/* OpenGL functions */
Jan 4, 2004
Jan 4, 2004
191
192
193
194
195
196
197
int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
void QZ_TearDownOpenGL (_THIS);
void* QZ_GL_GetProcAddress (_THIS, const char *proc);
int QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int* value);
int QZ_GL_MakeCurrent (_THIS);
void QZ_GL_SwapBuffers (_THIS);
int QZ_GL_LoadLibrary (_THIS, const char *location);
198
199
/* Cursor and Mouse functions */
Jan 4, 2004
Jan 4, 2004
200
201
202
203
204
205
206
void QZ_FreeWMCursor (_THIS, WMcursor *cursor);
WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask,
int w, int h, int hot_x, int hot_y);
int QZ_ShowWMCursor (_THIS, WMcursor *cursor);
void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y);
void QZ_MoveWMCursor (_THIS, int x, int y);
void QZ_CheckMouseMode (_THIS);
Jan 2, 2006
Jan 2, 2006
207
void QZ_UpdateMouse (_THIS);
208
209
/* Event functions */
Jan 4, 2004
Jan 4, 2004
210
211
void QZ_InitOSKeymap (_THIS);
void QZ_PumpEvents (_THIS);
212
213
/* Window Manager functions */
Jan 4, 2004
Jan 4, 2004
214
215
216
217
218
void QZ_SetCaption (_THIS, const char *title, const char *icon);
void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask);
int QZ_IconifyWindow (_THIS);
SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
/*int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/
Jan 22, 2002
Jan 22, 2002
219
Jan 4, 2004
Jan 4, 2004
220
221
222
223
224
225
/* Private functions (used internally) */
void QZ_PrivateWarpCursor (_THIS, int x, int y);
void QZ_ChangeGrabState (_THIS, int action);
void QZ_RegisterForSleepNotifications (_THIS);
void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p);
void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p);
Jan 7, 2004
Jan 7, 2004
226
BOOL QZ_IsMouseInWindow (_THIS);
Apr 13, 2006
Apr 13, 2006
227
228
void QZ_DoActivate (_THIS);
void QZ_DoDeactivate (_THIS);