Mercurial > sdl-ios-xcode
annotate src/video/macdsp/SDL_dspvideo.c @ 1558:b46bb79cc197
Fixed bug #113:
Date: Sat, 16 Apr 2005 08:39:22 +1000
From: "Eric Mangold"
Subject: [SDL] Window manager does not show SDL window titles
Hello,
I have an issue with SDL-using applications and the sawfish window manager.
The problem is that SDL windows do not show the window caption. My gnome
panel *does* show the window name, but the actual sawfish window frame
shows no caption at all. All other non-SDL applications that I use work
fine.
I tried a couple other window managers, and they *were* able to show the
SDL window captions correctly. Though there many be other WMs that can't.
I believe the problem is that SDL is using the UTF8_STRING type for the
window's WM_NAME and WM_ICON properties. In fact, WM_NAME and WM_ICON are
supposed to set to a TEXT type, usually STRING (ISO 8859-1).
The property names _NET_WM_NAME and _NET_WM_ICON_NAME should be used to
store the UTF8_STRING versions of the window title and icon name.
You can see the properties I refer to with a command like this:
xprop|grep -e "WM.*NAME"
Please note the freedesktop.org standard:
http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html#id2506954
This page talks a little bit about the history of these properties. Just
search down the page for "WM_NAME".
http://www.cl.cam.ac.uk/~mgk25/unicode.html
Please let me know if I can be of any assistance in resolving this issue.
Thanks,
Eric Mangold
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Mar 2006 07:31:36 +0000 |
parents | 8d9bb0cf2c2a |
children | e49147870aac e6de7e5fd451 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1135
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* | |
25 Written by Darrell Walisser <dwaliss1@purdue.edu> | |
26 | |
27 Implementation notes ---------------------------------------------------------------------- | |
28 | |
29 A bit on GWorlds in VRAM from technote 1182: | |
30 | |
31 There are two important things to note about GWorld's allocated in | |
32 VRAM. First, the base address retrieved through GetPixBaseAddr or | |
33 read directly from the PixMap structure can become invalid anytime | |
34 memory is allocated in VRAM. This can occur either by explicit | |
35 allocations, such as calls to NewGWorld, or by implicit ones, such as | |
36 those associated with the internal texture allocation of OpenGL. The | |
37 stored pixel images themselves will still be valid but may have been | |
38 moved in VRAM, thus rendering any stored base addresses invalid. | |
39 You should never store an image's base address for longer than is | |
40 necessary and especially never across calls to NewGWorld or | |
41 texture-creation routines. | |
42 | |
43 Secondly, an offscreen pixel image allocated in VRAM can be | |
44 purged at system task time by the display driver. This means any | |
45 time your application yields time such by calling WaitNextEvent or | |
46 SystemTask you can lose your VRAM GWorld contents. While this | |
47 happens infrequently, usually associated with display resolution or | |
48 pixel depth changes you must code for this eventuality. This purge | |
49 can occur whether or not the GWorld is locked or not. A return value | |
50 of false from LockPixels, a NULL return value from GetPixBaseAddr | |
51 or NULL in the baseAddr field of the PixMap mean that the pixel | |
52 image has been purged. To reallocate it you can either call | |
53 UpdateGWorld or Dispose your current GWorld through | |
54 DisposeGWorld and reallocate it via NewGWorld. Either way you must | |
55 then rebuild the pixel image. | |
56 | |
57 ------------------------------------------------------------------------------------ | |
58 | |
59 Currently, I don't account for (1). In my testing, NewGWorld never invalidated | |
60 other existing GWorlds in VRAM. However, I do have protection for (2). | |
61 Namely, I am using GetOSEvent() instead of WaitNextEvent() so that there are no | |
62 context switches (the app hogs the CPU). Eventually a book-keeping system should | |
63 be coded to take care of (1) and (2). | |
64 | |
65 ------------------------------------------------------------------------------------ | |
66 | |
67 System requirements (* denotes optional): | |
68 | |
69 1. DrawSprocket 1.7.3 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
70 2. *MacOS 9 or later (but *not* Mac OS X) for hardware accelerated blit / fill |
0 | 71 3. *May also require certain graphics hardware for (2). I trust that all Apple OEM |
72 hardware will work. Third party accelerators may work if they have QuickDraw | |
73 acceleration in the drivers and the drivers have been updated for OS 9. The current | |
74 Voodoo 3 drivers (1.0b12) do not work. | |
75 | |
76 Coding suggestions: | |
77 | |
78 1. Use SDL_UpdateRects ! | |
79 | |
80 If no QuickDraw acceleration is present, double-buffered surfaces will use a back buffer | |
81 in System memory. I recommend you use SDL_UpdateRects with double-buffered surfaces | |
82 for best performance on these cards, since the overhead is nearly zero for VRAM back buffer. | |
83 | |
84 2. Load most-resident surfaces first. | |
85 | |
86 If you fill up VRAM or AGP memory, there is no contingency for purging to make room for the next one. | |
87 Therefore, you should load the surfaces you plan to use the most frequently first. | |
88 Sooner or later, I will code LRU replacement to help this. | |
89 | |
90 TODO: | |
91 Some kind of posterized mode for resolutions < 640x480. | |
92 Window support / fullscreen toggle. | |
93 Figure out how much VRAM is available. Put in video->info->video_mem. | |
94 Track VRAM usage. | |
95 | |
96 BUGS: | |
97 I can't create a hardware surface the same size as the screen?! How to fix? | |
98 | |
99 | |
100 | |
101 COMPILE OPTIONS: | |
102 | |
103 DSP_TRY_CC_AND_AA - Define if you want to try HWA color-key and alpha blitters | |
104 HW color-key blitting gives substantial improvements, | |
105 but hw alpha is neck-and-neck with SDL's soft bitter. | |
106 | |
107 DSP_NO_SYNC_VBL - Define for HWA double-buffered surfaces: don't sync | |
108 pseudo-flip to monitor redraw. | |
109 | |
110 DSP_NO_SYNC_OPENGL - Define for OpenGL surfaces: don't sync buffer swap. Synching buffer | |
111 swap may result in reduced performance, but can eliminate some | |
112 tearing artifacts. | |
113 CHANGELOG: | |
114 09/17/00 Lots of little tweaks. Build modelist in reverse order so largest contexts | |
115 list first. Compared various methods with ROM methods and fixed rez switch | |
116 crashing bug in GL Tron. (Woohoo!) | |
117 */ | |
118 | |
119 #define DSP_TRY_CC_AND_AA | |
120 | |
121 /* #define DSP_NO_SYNC_VBL */ | |
122 | |
123 #define DSP_NO_SYNC_OPENGL | |
124 | |
125 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
126 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
127 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
128 #include <DrawSprocket/DrawSprocket.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
129 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 130 #include <Carbon.h> |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
131 #include <DrawSprocket.h> |
0 | 132 #else |
133 #include <LowMem.h> | |
134 #include <Gestalt.h> | |
135 #include <Devices.h> | |
136 #include <DiskInit.h> | |
137 #include <QDOffscreen.h> | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
138 #include <DrawSprocket.h> |
0 | 139 #endif |
140 | |
141 #include "SDL_video.h" | |
142 #include "SDL_syswm.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
143 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
144 #include "../SDL_blit.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
145 #include "../SDL_pixels_c.h" |
0 | 146 #include "SDL_dspvideo.h" |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
147 #include "../maccommon/SDL_macgl_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
148 #include "../maccommon/SDL_macwm_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
149 #include "../maccommon/SDL_macmouse_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
150 #include "../maccommon/SDL_macevents_c.h" |
0 | 151 |
152 /* Initialization/Query functions */ | |
153 static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
154 static SDL_Rect **DSp_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
155 static SDL_Surface *DSp_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
156 static int DSp_SetColors(_THIS, int firstcolor, int ncolors, | |
157 SDL_Color *colors); | |
158 static int DSp_CreatePalette(_THIS); | |
159 static int DSp_DestroyPalette(_THIS); | |
160 static void DSp_VideoQuit(_THIS); | |
161 | |
162 static int DSp_GetMainDevice (_THIS, GDHandle *device); | |
163 static void DSp_IsHWAvailable (_THIS, SDL_PixelFormat *vformat); | |
164 static void DSp_DSpUpdate(_THIS, int numrects, SDL_Rect *sdl_rects); | |
165 static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *sdl_rects); | |
166 | |
167 /* Hardware surface functions */ | |
168 static int DSp_SetHWAlpha(_THIS, SDL_Surface *surface, UInt8 alpha); | |
169 static int DSp_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key); | |
170 static int DSp_NewHWSurface(_THIS, CGrafPtr *port, int depth, int width, int height); | |
171 static int DSp_AllocHWSurface(_THIS, SDL_Surface *surface); | |
172 static int DSp_LockHWSurface(_THIS, SDL_Surface *surface); | |
173 static void DSp_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
174 static void DSp_FreeHWSurface(_THIS, SDL_Surface *surface); | |
175 static int DSp_FlipHWSurface(_THIS, SDL_Surface *surface); | |
176 static int DSp_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dest); | |
177 static int DSp_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
178 SDL_Surface *dst, SDL_Rect *dstrect); | |
179 static int DSp_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color); | |
180 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
181 #if SDL_VIDEO_OPENGL |
0 | 182 static void DSp_GL_SwapBuffers (_THIS); |
183 #endif | |
184 | |
185 #if ! TARGET_API_MAC_CARBON | |
186 | |
187 #define GetPortPixRowBytes(x) ( (*(x->portPixMap))->rowBytes ) | |
188 #define GetGDevPixMap(x) ((**(x)).gdPMap) | |
189 #define GetPortPixMap(x) ((*(x)).portPixMap) | |
190 | |
191 #define GetPixDepth(y) ((**(y)).pixelSize) | |
192 //#define GetPixRowBytes(y) ((**(y)).rowBytes) | |
193 //#define GetPixBaseAddr(y) ((**(y)).baseAddr) | |
194 #define GetPixCTab(y) ((**(y)).pmTable) | |
195 #define GetPortBitMapForCopyBits(x) (&(((GrafPtr)(x))->portBits)) | |
196 | |
197 #else | |
198 #define GetPortPixRowBytes(x) (GetPixRowBytes(GetPortPixMap(x)) ) | |
199 #define GetGDevPixMap(x) ((**(x)).gdPMap) | |
200 | |
201 #endif | |
202 | |
203 typedef struct private_hwdata { | |
204 | |
205 GWorldPtr offscreen; // offscreen gworld in VRAM or AGP | |
206 | |
207 #ifdef DSP_TRY_CC_AND_AA | |
208 GWorldPtr mask; // transparent mask | |
209 RGBColor alpha; // alpha color | |
210 RGBColor trans; // transparent color | |
211 #endif | |
212 | |
213 } private_hwdata; | |
214 | |
215 typedef private_hwdata private_swdata ; /* have same fields */ | |
216 | |
217 /* Macintosh toolbox driver bootstrap functions */ | |
218 | |
219 static int DSp_Available(void) | |
220 { | |
221 /* Check for DrawSprocket */ | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
222 #if ! TARGET_API_MAC_OSX |
0 | 223 /* This check is only meaningful if you weak-link DrawSprocketLib */ |
224 return ((Ptr)DSpStartup != (Ptr)kUnresolvedCFragSymbolAddress); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
225 #else |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
226 return 1; // DrawSprocket.framework doesn't have it all, but it's there |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
227 #endif |
0 | 228 } |
229 | |
230 static void DSp_DeleteDevice(SDL_VideoDevice *device) | |
231 { | |
232 /* -dw- taking no chances with null pointers */ | |
233 if (device) { | |
234 | |
235 if (device->hidden) { | |
236 | |
237 if (device->hidden->dspinfo) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
238 SDL_free(device->hidden->dspinfo); |
0 | 239 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
240 SDL_free(device->hidden); |
0 | 241 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
242 SDL_free(device); |
0 | 243 } |
244 } | |
245 | |
246 static SDL_VideoDevice *DSp_CreateDevice(int devindex) | |
247 { | |
248 SDL_VideoDevice *device; | |
249 | |
250 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
251 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 252 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
253 SDL_memset(device, 0, sizeof (*device)); |
0 | 254 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
255 SDL_malloc((sizeof *device->hidden)); |
0 | 256 if (device->hidden) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
257 SDL_memset(device->hidden, 0, sizeof ( *(device->hidden) ) ); |
0 | 258 } |
259 if ( (device == NULL) || (device->hidden == NULL) ) { | |
260 SDL_OutOfMemory(); | |
261 | |
262 if ( device ) { | |
263 | |
264 if (device->hidden) | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
265 SDL_free(device->hidden); |
0 | 266 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
267 SDL_free(device); |
0 | 268 } |
269 | |
270 return(NULL); | |
271 } | |
272 | |
273 /* Allocate DrawSprocket information */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
274 device->hidden->dspinfo = (struct DSpInfo *)SDL_malloc( |
0 | 275 (sizeof *device->hidden->dspinfo)); |
276 if ( device->hidden->dspinfo == NULL ) { | |
277 SDL_OutOfMemory(); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
278 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
279 SDL_free(device); |
0 | 280 return(0); |
281 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
282 SDL_memset(device->hidden->dspinfo, 0, (sizeof *device->hidden->dspinfo)); |
0 | 283 |
284 /* Set the function pointers */ | |
285 device->VideoInit = DSp_VideoInit; | |
286 device->ListModes = DSp_ListModes; | |
287 device->SetVideoMode = DSp_SetVideoMode; | |
288 device->SetColors = DSp_SetColors; | |
289 device->UpdateRects = NULL; | |
290 device->VideoQuit = DSp_VideoQuit; | |
291 device->AllocHWSurface = DSp_AllocHWSurface; | |
292 device->CheckHWBlit = NULL; | |
293 device->FillHWRect = NULL; | |
294 device->SetHWColorKey = NULL; | |
295 device->SetHWAlpha = NULL; | |
296 device->LockHWSurface = DSp_LockHWSurface; | |
297 device->UnlockHWSurface = DSp_UnlockHWSurface; | |
298 device->FlipHWSurface = DSp_FlipHWSurface; | |
299 device->FreeHWSurface = DSp_FreeHWSurface; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
300 #if SDL_VIDEO_OPENGL |
0 | 301 device->GL_MakeCurrent = Mac_GL_MakeCurrent; |
302 device->GL_SwapBuffers = DSp_GL_SwapBuffers; | |
1032
c1c2efca4548
Date: Mon, 24 Jan 2005 21:37:56 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
303 device->GL_LoadLibrary = Mac_GL_LoadLibrary; |
c1c2efca4548
Date: Mon, 24 Jan 2005 21:37:56 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
304 device->GL_GetProcAddress = Mac_GL_GetProcAddress; |
0 | 305 #endif |
306 device->SetCaption = NULL; | |
307 device->SetIcon = NULL; | |
308 device->IconifyWindow = NULL; | |
309 device->GrabInput = NULL; | |
310 device->GetWMInfo = NULL; | |
311 device->FreeWMCursor = Mac_FreeWMCursor; | |
312 device->CreateWMCursor = Mac_CreateWMCursor; | |
313 device->ShowWMCursor = Mac_ShowWMCursor; | |
314 device->WarpWMCursor = Mac_WarpWMCursor; | |
315 device->InitOSKeymap = Mac_InitOSKeymap; | |
316 device->PumpEvents = Mac_PumpEvents; | |
317 | |
318 device->GrabInput = NULL; | |
319 device->CheckMouseMode = NULL; | |
320 | |
321 device->free = DSp_DeleteDevice; | |
322 | |
323 return device; | |
324 } | |
325 | |
326 VideoBootStrap DSp_bootstrap = { | |
327 "DSp", "MacOS DrawSprocket", | |
328 DSp_Available, DSp_CreateDevice | |
329 }; | |
330 | |
331 /* Use DSp/Display Manager to build mode list for given screen */ | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
332 static SDL_Rect** DSp_BuildModeList (const GDHandle gDevice, int *displayWidth, int *displayHeight) |
0 | 333 { |
334 DSpContextAttributes attributes; | |
335 DSpContextReference context; | |
336 DisplayIDType displayID; | |
337 SDL_Rect temp_list [16]; | |
338 SDL_Rect **mode_list; | |
339 int width, height, i, j; | |
340 | |
341 #if TARGET_API_MAC_OSX | |
342 | |
343 displayID = 0; | |
344 | |
345 #else | |
346 /* Ask Display Manager for integer id of screen device */ | |
347 if ( DMGetDisplayIDByGDevice (gDevice, &displayID, SDL_TRUE) != noErr ) { | |
348 return NULL; | |
349 } | |
350 #endif | |
351 /* Get the first possible DSp context on this device */ | |
352 if ( DSpGetFirstContext (displayID, &context) != noErr ) { | |
353 return NULL; | |
354 } | |
355 | |
356 if ( DSpContext_GetAttributes (context, &attributes) != noErr ) | |
357 return NULL; | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
358 |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
359 *displayWidth = attributes.displayWidth; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
360 *displayHeight = attributes.displayHeight; |
0 | 361 |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
362 for ( i = 0; i < SDL_arraysize(temp_list); i++ ) { |
0 | 363 width = attributes.displayWidth; |
364 height = attributes.displayHeight; | |
365 | |
366 temp_list [i].x = 0 | attributes.displayBestDepth; | |
367 temp_list [i].y = 0; | |
368 temp_list [i].w = width; | |
369 temp_list [i].h = height; | |
370 | |
371 /* DSp will report many different contexts with the same width and height. */ | |
372 /* They will differ in bit depth and refresh rate. */ | |
373 /* We will ignore them until we reach one with a different width/height */ | |
374 /* When there are no more contexts to look at, we will quit building the list*/ | |
375 while ( width == attributes.displayWidth && height == attributes.displayHeight ) { | |
376 | |
377 OSStatus err = DSpGetNextContext (context, &context); | |
378 if (err != noErr) | |
379 if (err == kDSpContextNotFoundErr) | |
380 goto done; | |
381 else | |
382 return NULL; | |
383 | |
384 if ( DSpContext_GetAttributes (context, &attributes) != noErr ) | |
385 return NULL; | |
386 | |
387 temp_list [i].x |= attributes.displayBestDepth; | |
388 } | |
389 } | |
390 done: | |
391 i++; /* i was not incremented before kicking out of the loop */ | |
392 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
393 mode_list = (SDL_Rect**) SDL_malloc (sizeof (SDL_Rect*) * (i+1)); |
0 | 394 if (mode_list) { |
395 | |
396 /* -dw- new stuff: build in reverse order so largest sizes list first */ | |
397 for (j = i-1; j >= 0; j--) { | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
398 mode_list [j] = (SDL_Rect*) SDL_malloc (sizeof (SDL_Rect)); |
0 | 399 if (mode_list [j]) |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
400 SDL_memcpy (mode_list [j], &(temp_list [j]), sizeof (SDL_Rect)); |
0 | 401 else { |
402 SDL_OutOfMemory (); | |
403 return NULL; | |
404 } | |
405 } | |
406 mode_list [i] = NULL; /* append null to the end */ | |
407 } | |
408 else { | |
409 SDL_OutOfMemory (); | |
410 return NULL; | |
411 } | |
412 | |
413 return mode_list; | |
414 } | |
415 | |
416 static void DSp_IsHWAvailable (_THIS, SDL_PixelFormat *vformat) | |
417 { | |
418 /* | |
419 VRAM GWorlds are only available on OS 9 or later. | |
420 Even with OS 9, some display drivers won't support it, | |
421 so we create a test GWorld and check for errors. | |
422 */ | |
423 | |
424 long versionSystem; | |
425 | |
426 dsp_vram_available = SDL_FALSE; | |
427 dsp_agp_available = SDL_FALSE; | |
428 | |
429 Gestalt ('sysv', &versionSystem); | |
430 if (0x00000860 < (versionSystem & 0x0000FFFF)) { | |
431 | |
432 GWorldPtr offscreen; | |
433 OSStatus err; | |
434 Rect bounds; | |
435 | |
436 SetRect (&bounds, 0, 0, 320, 240); | |
437 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
438 #if useDistantHdwrMem && useLocalHdwrMem |
0 | 439 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useDistantHdwrMem | noNewDevice); |
440 if (err == noErr) { | |
441 dsp_vram_available = SDL_TRUE; | |
442 DisposeGWorld (offscreen); | |
443 } | |
444 | |
445 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useLocalHdwrMem | noNewDevice); | |
446 if (err == noErr) { | |
447 DisposeGWorld (offscreen); | |
448 dsp_agp_available = SDL_TRUE; | |
449 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
450 #endif |
0 | 451 } |
452 } | |
453 | |
454 static int DSp_GetMainDevice (_THIS, GDHandle *device) | |
455 { | |
456 | |
457 #if TARGET_API_MAC_OSX | |
458 /* DSpUserSelectContext not available on OS X */ | |
459 *device = GetMainDevice(); | |
460 return 0; | |
461 #else | |
462 | |
463 DSpContextAttributes attrib; | |
464 DSpContextReference context; | |
465 DisplayIDType display_id; | |
466 GDHandle main_device; | |
467 GDHandle device_list; | |
468 | |
469 device_list = GetDeviceList (); | |
470 main_device = GetMainDevice (); | |
471 | |
472 /* Quick check to avoid slower method when only one display exists */ | |
473 if ( (**device_list).gdNextGD == NULL ) { | |
474 *device = main_device; | |
475 return 0; | |
476 } | |
477 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
478 SDL_memset (&attrib, 0, sizeof (DSpContextAttributes)); |
0 | 479 |
480 /* These attributes are hopefully supported on all devices...*/ | |
481 attrib.displayWidth = 640; | |
482 attrib.displayHeight = 480; | |
483 attrib.displayBestDepth = 8; | |
484 attrib.backBufferBestDepth = 8; | |
485 attrib.displayDepthMask = kDSpDepthMask_All; | |
486 attrib.backBufferDepthMask = kDSpDepthMask_All; | |
487 attrib.colorNeeds = kDSpColorNeeds_Require; | |
488 attrib.pageCount = 1; | |
489 | |
490 if (noErr != DMGetDisplayIDByGDevice (main_device, &display_id, SDL_FALSE)) { | |
491 SDL_SetError ("Display Manager couldn't associate GDevice with a Display ID"); | |
492 return (-1); | |
493 } | |
494 | |
495 /* Put up dialog on main display to select which display to use */ | |
496 if (noErr != DSpUserSelectContext (&attrib, display_id, NULL, &context)) { | |
497 SDL_SetError ("DrawSprocket couldn't create a context"); | |
498 return (-1); | |
499 } | |
500 | |
501 if (noErr != DSpContext_GetDisplayID (context, &display_id)) { | |
502 SDL_SetError ("DrawSprocket couldn't get display ID"); | |
503 return (-1); | |
504 } | |
505 | |
506 if (noErr != DMGetGDeviceByDisplayID (display_id, &main_device, SDL_FALSE)) { | |
507 SDL_SetError ("Display Manager couldn't associate Display ID with GDevice"); | |
508 return (-1); | |
509 } | |
510 | |
511 *device = main_device; | |
512 return (0); | |
513 #endif | |
514 } | |
515 | |
516 static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
517 { | |
1135
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
518 NumVersion dsp_version = { 0x01, 0x00, 0x00, 0x00 }; |
0 | 519 |
1135
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
520 #if UNIVERSAL_INTERFACES_VERSION > 0x0320 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
521 dsp_version = DSpGetVersion (); |
1135
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
522 #endif |
0 | 523 |
524 if ( (dsp_version.majorRev == 1 && dsp_version.minorAndBugRev < 0x73) || | |
525 (dsp_version.majorRev < 1) ) { | |
526 | |
527 /* StandardAlert (kAlertStopAlert, "\pError!", | |
528 "\pI need DrawSprocket 1.7.3 or later!\n" | |
529 "You can find a newer version at http://www.apple.com/swupdates.", | |
530 NULL, NULL); | |
531 */ | |
532 SDL_SetError ("DrawSprocket version is too old. Need 1.7.3 or later."); | |
533 return (-1); | |
534 } | |
535 | |
536 if ( DSpStartup () != noErr ) { | |
537 SDL_SetError ("DrawSprocket couldn't startup"); | |
538 return(-1); | |
539 } | |
540 | |
541 /* Start DSpintosh events */ | |
542 Mac_InitEvents(this); | |
543 | |
544 /* Get a handle to the main monitor, or choose one on multiple monitor setups */ | |
545 if ( DSp_GetMainDevice(this, &SDL_Display) < 0) | |
546 return (-1); | |
547 | |
548 /* Determine pixel format */ | |
549 vformat->BitsPerPixel = GetPixDepth ( (**SDL_Display).gdPMap ); | |
550 dsp_old_depth = vformat->BitsPerPixel; | |
551 | |
552 switch (vformat->BitsPerPixel) { | |
553 case 16: | |
554 vformat->Rmask = 0x00007c00; | |
555 vformat->Gmask = 0x000003e0; | |
556 vformat->Bmask = 0x0000001f; | |
557 break; | |
558 default: | |
559 break; | |
560 } | |
561 | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
562 if ( DSp_CreatePalette (this) < 0 ) { |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
563 SDL_SetError ("Could not create palette"); |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
564 return (-1); |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
565 } |
0 | 566 |
567 /* Get a list of available fullscreen modes */ | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
568 SDL_modelist = DSp_BuildModeList (SDL_Display, |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
569 &this->info.current_w, &this->info.current_h); |
0 | 570 if (SDL_modelist == NULL) { |
571 SDL_SetError ("DrawSprocket could not build a mode list"); | |
572 return (-1); | |
573 } | |
574 | |
575 /* Check for VRAM and AGP GWorlds for HW Blitting */ | |
576 DSp_IsHWAvailable (this, vformat); | |
577 | |
578 this->info.wm_available = 0; | |
579 | |
580 if (dsp_vram_available || dsp_agp_available) { | |
581 | |
582 this->info.hw_available = SDL_TRUE; | |
583 | |
584 this->CheckHWBlit = DSp_CheckHWBlit; | |
585 this->info.blit_hw = SDL_TRUE; | |
586 | |
587 this->FillHWRect = DSp_FillHWRect; | |
588 this->info.blit_fill = SDL_TRUE; | |
589 | |
590 #ifdef DSP_TRY_CC_AND_AA | |
591 this->SetHWColorKey = DSp_SetHWColorKey; | |
592 this->info.blit_hw_CC = SDL_TRUE; | |
593 | |
594 this->SetHWAlpha = DSp_SetHWAlpha; | |
595 this->info.blit_hw_A = SDL_TRUE; | |
596 #endif | |
597 | |
598 } | |
599 | |
600 return(0); | |
601 } | |
602 | |
603 static SDL_Rect **DSp_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
604 { | |
605 static SDL_Rect *dsp_modes[16]; | |
606 int i = 0, j = 0; | |
607 | |
608 if ( format->BitsPerPixel == 0 ) | |
609 return ( (SDL_Rect**) NULL ); | |
610 | |
611 while (SDL_modelist[i] != NULL) { | |
612 | |
613 if (SDL_modelist[i]->x & format->BitsPerPixel) { | |
614 dsp_modes[j] = SDL_modelist[i]; | |
615 j++; | |
616 } | |
617 i++; | |
618 } | |
619 | |
620 dsp_modes[j] = NULL; | |
621 | |
622 return dsp_modes; | |
623 } | |
624 | |
625 /* Various screen update functions available */ | |
626 static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
627 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
628 #if ! TARGET_API_MAC_OSX |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
629 |
0 | 630 static volatile unsigned int retrace_count = 0; /* -dw- need volatile because it updates asychronously */ |
631 | |
632 Boolean DSp_VBLProc ( DSpContextReference context, void *ref_con ) | |
633 { | |
634 retrace_count++; | |
635 | |
636 return 1; /* Darrell, is this right? */ | |
637 } | |
638 | |
639 static void DSp_SetHWError (OSStatus err, int is_agp) | |
640 { | |
641 char message[1024]; | |
642 const char *fmt, *mem; | |
643 | |
644 if ( is_agp ) { | |
645 mem = "AGP Memory"; | |
646 } else { | |
647 mem = "VRAM"; | |
648 } | |
649 switch(err) { | |
650 case memFullErr: | |
651 fmt = "Hardware surface possible but not enough %s available"; | |
652 break; | |
653 case cDepthErr: | |
654 fmt = "Hardware surface possible but invalid color depth"; | |
655 break; | |
656 default: | |
657 fmt = "Hardware surface could not be allocated in %s - unknown error"; | |
658 break; | |
659 } | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
660 SDL_snprintf(message, SDL_arraysize(message), fmt, mem); |
0 | 661 SDL_SetError(message); |
662 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
663 #endif // TARGET_API_MAC_OSX |
0 | 664 |
665 /* put up a dialog to verify display change */ | |
666 static int DSp_ConfirmSwitch () { | |
667 | |
668 /* resource id's for dialog */ | |
669 const int rDialog = 1002; | |
670 const int bCancel = 1; | |
671 const int bOK = 2; | |
672 | |
673 DialogPtr dialog; | |
674 OSStatus err; | |
675 SInt32 response; | |
676 DialogItemIndex item = 0; | |
677 GrafPtr savePort; | |
678 | |
679 GetPort (&savePort); | |
680 | |
681 dialog = GetNewDialog (rDialog, NULL, (WindowPtr) -1); | |
682 if (dialog == NULL) | |
683 return (0); | |
684 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
685 #if TARGET_API_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
686 SetPort (GetDialogPort(dialog)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
687 #else |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
688 SetPort ((WindowPtr) dialog); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
689 #endif |
0 | 690 |
691 SetDialogDefaultItem (dialog, bCancel); | |
692 SetDialogCancelItem (dialog, bCancel); | |
693 | |
694 SetEventMask (everyEvent); | |
695 FlushEvents (everyEvent, 0); | |
696 | |
697 /* On MacOS 8.5 or later, we can make the dialog go away after 15 seconds */ | |
698 /* This is good since it's possible user can't even see the dialog! */ | |
699 /* Requires linking to DialogsLib */ | |
700 err = Gestalt(gestaltSystemVersion,&response); | |
701 if (err == noErr && response >= 0x00000850) { | |
702 SetDialogTimeout(dialog, bCancel, 15); | |
703 } | |
704 | |
705 do { | |
706 | |
707 ModalDialog ( NULL, &item ); | |
708 | |
709 } while ( item != bCancel && item != bOK && err != noErr); | |
710 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
711 |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
712 DisposeDialog (dialog); |
0 | 713 SetPort (savePort); |
714 | |
715 SetEventMask(everyEvent - autoKeyMask); | |
716 FlushEvents(everyEvent, 0); | |
717 | |
718 return (item - 1); | |
719 } | |
720 | |
721 static void DSp_UnsetVideoMode(_THIS, SDL_Surface *current) | |
722 { | |
723 | |
724 | |
725 if ( current->flags & SDL_OPENGL ) { | |
726 Mac_GL_Quit (this); | |
727 } | |
728 | |
729 if (dsp_context != NULL) { | |
730 | |
731 GWorldPtr front; | |
732 DSpContext_GetFrontBuffer (dsp_context, &front); | |
733 | |
734 if (front != dsp_back_buffer) | |
735 DisposeGWorld (dsp_back_buffer); | |
736 | |
737 if (current->hwdata) | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
738 SDL_free(current->hwdata); |
0 | 739 |
740 DSpContext_SetState (dsp_context, kDSpContextState_Inactive ); | |
741 DSpContext_Release (dsp_context); | |
742 | |
743 dsp_context = NULL; | |
744 } | |
745 | |
746 if (SDL_Window != NULL) { | |
747 DisposeWindow (SDL_Window); | |
748 SDL_Window = NULL; | |
749 } | |
750 | |
751 current->pixels = NULL; | |
752 current->flags = 0; | |
753 } | |
754 | |
755 static SDL_Surface *DSp_SetVideoMode(_THIS, | |
756 SDL_Surface *current, int width, int height, int bpp, Uint32 flags) | |
757 { | |
758 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
759 #if !TARGET_API_MAC_OSX |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
760 DisplayIDType display_id; |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
761 Fixed freq; |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
762 #endif |
0 | 763 DSpContextAttributes attrib; |
764 OSStatus err; | |
765 UInt32 rmask = 0, gmask = 0, bmask = 0; | |
766 | |
767 int page_count; | |
768 int double_buf; | |
769 int hw_surface; | |
770 int use_dsp_back_buffer; | |
771 | |
772 DSp_UnsetVideoMode (this, current); | |
773 | |
774 if (bpp != dsp_old_depth) | |
775 DSp_DestroyPalette (this); | |
776 | |
777 double_buf = (flags & SDL_DOUBLEBUF) != 0; | |
778 hw_surface = (flags & SDL_HWSURFACE) != 0; | |
779 use_dsp_back_buffer = !dsp_vram_available || !hw_surface ; | |
780 | |
781 current->flags |= SDL_FULLSCREEN; | |
782 | |
783 rebuild: | |
784 | |
785 if ( double_buf && use_dsp_back_buffer ) { | |
786 page_count = 2; | |
787 } else { | |
788 page_count = 1; | |
789 } | |
790 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
791 SDL_memset (&attrib, 0, sizeof (DSpContextAttributes)); |
0 | 792 attrib.displayWidth = width; |
793 attrib.displayHeight = height; | |
794 attrib.displayBestDepth = bpp; | |
795 attrib.backBufferBestDepth = bpp; | |
796 attrib.displayDepthMask = kDSpDepthMask_All; | |
797 attrib.backBufferDepthMask = kDSpDepthMask_All; | |
798 attrib.colorNeeds = kDSpColorNeeds_Require; | |
799 attrib.colorTable = 0; | |
800 attrib.pageCount = page_count; | |
1135
cf6133247d34
Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents:
1133
diff
changeset
|
801 #if TARGET_API_MAC_OSX || UNIVERSAL_INTERFACES_VERSION == 0x0320 |
0 | 802 |
803 if ( DSpFindBestContext (&attrib, &dsp_context) != noErr ) { | |
804 SDL_SetError ("DrawSprocket couldn't find a context"); | |
805 return NULL; | |
806 } | |
807 | |
808 #else | |
809 if ( noErr != DMGetDisplayIDByGDevice (SDL_Display, &display_id, SDL_FALSE) ) { | |
810 SDL_SetError ("Display Manager couldn't associate GDevice with display_id"); | |
811 return NULL; | |
812 } | |
1032
c1c2efca4548
Date: Mon, 24 Jan 2005 21:37:56 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
813 if ( DSpFindBestContextOnDisplayID(&attrib, &dsp_context, display_id) != noErr ) { |
0 | 814 SDL_SetError ("DrawSprocket couldn't find a suitable context on given display"); |
815 return NULL; | |
816 } | |
817 | |
818 #endif | |
819 if ( DSpContext_Reserve (dsp_context, &attrib) != noErr ) { | |
820 SDL_SetError ("DrawSprocket couldn't get the needed resources to build the display"); | |
821 return NULL; | |
822 } | |
823 | |
824 if ( (err = DSpContext_SetState (dsp_context, kDSpContextState_Active)) != noErr ) { | |
825 | |
826 if (err == kDSpConfirmSwitchWarning) { | |
827 | |
828 if ( ! DSp_ConfirmSwitch () ) { | |
829 | |
830 DSpContext_Release (dsp_context); | |
831 dsp_context = NULL; | |
832 SDL_SetError ("User cancelled display switch"); | |
833 return NULL; | |
834 } | |
835 else | |
836 /* Have to reactivate context. Why? */ | |
837 DSpContext_SetState (dsp_context, kDSpContextState_Active); | |
838 | |
839 } | |
840 else { | |
841 SDL_SetError ("DrawSprocket couldn't activate the context"); | |
842 return NULL; | |
843 } | |
844 } | |
845 | |
846 | |
847 if (bpp != dsp_old_depth) { | |
848 | |
849 DSp_CreatePalette (this); | |
850 | |
851 /* update format if display depth changed */ | |
852 if (bpp == 16) { | |
853 | |
854 rmask = 0x00007c00; | |
855 gmask = 0x000003e0; | |
856 bmask = 0x0000001f; | |
857 } | |
858 if ( ! SDL_ReallocFormat (current, bpp, rmask, gmask, bmask, 0 ) ) { | |
859 | |
860 SDL_SetError ("Could not reallocate video format."); | |
861 return(NULL); | |
862 } | |
863 } | |
864 | |
865 if (!double_buf) { | |
866 | |
867 /* single-buffer context */ | |
868 DSpContext_GetFrontBuffer (dsp_context, &dsp_back_buffer); | |
869 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
870 current->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata)); |
0 | 871 if (current ->hwdata == NULL) { |
872 SDL_OutOfMemory (); | |
873 return NULL; | |
874 } | |
875 current->hwdata->offscreen = dsp_back_buffer; | |
876 current->flags |= SDL_HWSURFACE; | |
877 this->UpdateRects = DSp_DirectUpdate; | |
878 } | |
879 else if ( use_dsp_back_buffer ) { | |
880 | |
881 DSpContext_GetBackBuffer (dsp_context, kDSpBufferKind_Normal, &dsp_back_buffer); | |
882 | |
883 current->flags |= SDL_DOUBLEBUF | SDL_SWSURFACE; /* only front buffer is in VRAM */ | |
884 this->UpdateRects = DSp_DSpUpdate; | |
885 } | |
886 else if ( DSp_NewHWSurface(this, &dsp_back_buffer, bpp, width-1, height-1) == 0 ) { | |
887 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
888 current->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata)); |
0 | 889 if (current ->hwdata == NULL) { |
890 SDL_OutOfMemory (); | |
891 return NULL; | |
892 } | |
893 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
894 SDL_memset (current->hwdata, 0, sizeof (private_hwdata)); |
0 | 895 current->hwdata->offscreen = dsp_back_buffer; |
896 current->flags |= SDL_DOUBLEBUF | SDL_HWSURFACE; | |
897 this->UpdateRects = DSp_DirectUpdate; /* hardware doesn't do update rects, must be page-flipped */ | |
898 } | |
899 else { | |
900 | |
901 DSpContext_Release (dsp_context); | |
902 use_dsp_back_buffer = SDL_TRUE; | |
903 goto rebuild; | |
904 } | |
905 | |
906 current->pitch = GetPortPixRowBytes(dsp_back_buffer) & 0x3FFF; | |
907 current->pixels = GetPixBaseAddr(GetPortPixMap(dsp_back_buffer)); | |
908 | |
909 current->w = width; | |
910 current->h = height; | |
911 | |
912 #if ! TARGET_API_MAC_OSX | |
913 | |
914 if (use_dsp_back_buffer) { | |
915 | |
916 DSpContext_GetMonitorFrequency (dsp_context, &freq); | |
917 DSpContext_SetMaxFrameRate (dsp_context, freq >> 16); | |
918 } | |
919 | |
920 | |
921 if ( (current->flags & SDL_HWSURFACE) || (current->flags & SDL_OPENGL) ) | |
922 DSpContext_SetVBLProc (dsp_context, DSp_VBLProc, NULL); | |
923 #endif | |
924 | |
925 if (bpp == 8) | |
926 current->flags |= SDL_HWPALETTE; | |
927 | |
928 if (flags & SDL_OPENGL) { | |
929 | |
930 Rect rect; | |
931 RGBColor rgb = { 0.0, 0.0, 0.0 }; | |
932 GrafPtr save_port; | |
933 | |
934 SetRect (&rect, 0, 0, width, height); | |
935 SDL_Window = NewCWindow(nil, &( (**SDL_Display).gdRect), "\p", SDL_TRUE, plainDBox, (WindowPtr)-1, SDL_FALSE, 0); | |
936 | |
937 if (SDL_Window == NULL) { | |
938 | |
939 SDL_SetError ("DSp_SetVideoMode : OpenGL window could not be created."); | |
940 return NULL; | |
941 } | |
942 | |
943 /* Set window color to black to avoid white flash*/ | |
944 GetPort (&save_port); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
945 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
946 SetPort (GetWindowPort(SDL_Window)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
947 #else |
0 | 948 SetPort (SDL_Window); |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
949 #endif |
0 | 950 RGBForeColor (&rgb); |
951 PaintRect (&rect); | |
952 SetPort (save_port); | |
953 | |
954 SetPortWindowPort (SDL_Window); | |
955 SelectWindow (SDL_Window); | |
956 | |
957 if ( Mac_GL_Init (this) < 0 ) { | |
958 | |
959 SDL_SetError ("DSp_SetVideoMode : could not create OpenGL context."); | |
960 return NULL; | |
961 } | |
962 | |
963 current->flags |= SDL_OPENGL; | |
964 } | |
965 | |
966 return current; | |
967 } | |
968 | |
969 #ifdef DSP_TRY_CC_AND_AA | |
970 | |
971 static int DSp_MakeHWMask (_THIS, SDL_Surface *surface) | |
972 { | |
973 GDHandle save_device; | |
974 CGrafPtr save_port; | |
975 GWorldPtr temp; | |
976 RGBColor black = { 0, 0, 0 }; | |
977 RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF }; | |
978 Rect rect; | |
979 | |
980 Uint32 depth = GetPixDepth ( GetGDevPixMap (SDL_Display) ); | |
981 | |
982 SetRect (&rect, 0, 0, surface->w, surface->h); | |
983 | |
984 if ( noErr != NewGWorld (&(surface->hwdata->mask), depth, &rect, 0, SDL_Display, 0 ) < 0 ) { | |
985 | |
986 SDL_OutOfMemory (); | |
987 return (-1); | |
988 } | |
989 | |
990 if ( noErr != NewGWorld (&temp, depth, &rect, 0 , SDL_Display, 0 ) ) { | |
991 | |
992 SDL_OutOfMemory (); | |
993 return (-1); | |
994 } | |
995 | |
996 | |
997 GetGWorld (&save_port, &save_device); | |
998 SetGWorld (surface->hwdata->mask, SDL_Display); | |
999 | |
1000 RGBForeColor (&white); | |
1001 PaintRect (&rect); | |
1002 | |
1003 RGBBackColor (&(surface->hwdata->trans)); | |
1004 | |
1005 CopyBits ( GetPortBitMapForCopyBits(surface->hwdata->offscreen), | |
1006 GetPortBitMapForCopyBits(surface->hwdata->mask), | |
1007 &rect, &rect, transparent, NULL ); | |
1008 | |
1009 SetGWorld (surface->hwdata->mask, SDL_Display); | |
1010 SetGWorld (save_port, save_device); | |
1011 return (0); | |
1012 } | |
1013 | |
1014 static int DSp_SetHWAlpha(_THIS, SDL_Surface *surface, UInt8 alpha) | |
1015 { | |
1016 surface->hwdata->alpha.red = (alpha / 255.0) * 65535; | |
1017 surface->hwdata->alpha.blue = (alpha / 255.0) * 65535; | |
1018 surface->hwdata->alpha.green = (alpha / 255.0) * 65535; | |
1019 | |
1020 surface->flags |= SDL_SRCALPHA; | |
1021 | |
1022 if (surface->flags & SDL_SRCCOLORKEY) { | |
1023 return(DSp_MakeHWMask (this, surface)); | |
1024 } | |
1025 return(0); | |
1026 } | |
1027 | |
1028 static int DSp_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
1029 { | |
1030 CGrafPtr save_port; | |
1031 GDHandle save_device; | |
1032 | |
1033 GetGWorld (&save_port, &save_device); | |
1034 SetGWorld (surface->hwdata->offscreen, NULL); | |
1035 | |
1036 Index2Color (key, &(surface->hwdata->trans)); | |
1037 surface->flags |= SDL_SRCCOLORKEY; | |
1038 | |
1039 SetGWorld (save_port, save_device); | |
1040 | |
1041 if ( surface->flags & SDL_SRCALPHA ) { | |
1042 return(DSp_MakeHWMask (this, surface)); | |
1043 } | |
1044 return(0); | |
1045 } | |
1046 | |
1047 #endif /* DSP_TRY_CC_AND_AA */ | |
1048 | |
1049 static int DSp_NewHWSurface(_THIS, CGrafPtr *port, int depth, int width, int height) { | |
1050 | |
1051 OSStatus err; | |
1052 Rect bounds; | |
1053 | |
1054 SetRect (&bounds, 0, 0, width, height); | |
1055 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
1056 #if useDistantHdwrMem && useLocalHdwrMem |
0 | 1057 if (dsp_vram_available) { |
1058 /* try VRAM */ | |
1059 err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useDistantHdwrMem | noNewDevice ); | |
1060 if (err != noErr) | |
1061 DSp_SetHWError (err, SDL_FALSE); | |
1062 else | |
1063 return (0); | |
1064 } | |
1065 | |
1066 if (dsp_agp_available) { | |
1067 /* try AGP */ | |
1068 err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useLocalHdwrMem | noNewDevice ); | |
1069 | |
1070 if (err != noErr) | |
1071 DSp_SetHWError (err, SDL_TRUE); | |
1072 else | |
1073 return (0); | |
1074 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
1075 #endif |
0 | 1076 |
1077 return (-1); | |
1078 } | |
1079 | |
1080 static int DSp_AllocHWSurface(_THIS, SDL_Surface *surface) | |
1081 { | |
1082 GWorldPtr temp; | |
1083 | |
1084 if ( DSp_NewHWSurface (this, &temp, surface->format->BitsPerPixel, surface->w, surface->h) < 0 ) | |
1085 return (-1); | |
1086 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
1087 surface->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata)); |
0 | 1088 if (surface->hwdata == NULL) { |
1089 SDL_OutOfMemory (); | |
1090 return -1; | |
1091 } | |
1092 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
1093 SDL_memset (surface->hwdata, 0, sizeof(private_hwdata)); |
0 | 1094 surface->hwdata->offscreen = temp; |
1095 surface->pitch = GetPixRowBytes (GetPortPixMap (temp)) & 0x3FFF; | |
1096 surface->pixels = GetPixBaseAddr (GetPortPixMap (temp)); | |
1097 surface->flags |= SDL_HWSURFACE; | |
1098 #ifdef DSP_TRY_CC_AND_AA | |
1099 surface->flags |= SDL_HWACCEL; | |
1100 #endif | |
1101 return 0; | |
1102 } | |
1103 | |
1104 static void DSp_FreeHWSurface(_THIS, SDL_Surface *surface) | |
1105 { | |
1106 if (surface->hwdata->offscreen != NULL) | |
1107 DisposeGWorld (surface->hwdata->offscreen); | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
1108 SDL_free(surface->hwdata); |
0 | 1109 |
1110 surface->pixels = NULL; | |
1111 } | |
1112 | |
1113 static int DSp_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dest) | |
1114 { | |
1115 int accelerated; | |
1116 | |
1117 /* Set initial acceleration on */ | |
1118 src->flags |= SDL_HWACCEL; | |
1119 | |
1120 /* Set the surface attributes */ | |
1121 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
1122 if ( ! this->info.blit_hw_A ) { | |
1123 src->flags &= ~SDL_HWACCEL; | |
1124 } | |
1125 } | |
1126 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
1127 if ( ! this->info.blit_hw_CC ) { | |
1128 src->flags &= ~SDL_HWACCEL; | |
1129 } | |
1130 } | |
1131 | |
1132 /* Check to see if final surface blit is accelerated */ | |
1133 accelerated = !!(src->flags & SDL_HWACCEL); | |
1134 if ( accelerated ) { | |
1135 src->map->hw_blit = DSp_HWAccelBlit; | |
1136 } | |
1137 return(accelerated); | |
1138 } | |
1139 | |
1140 static int DSp_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
1141 SDL_Surface *dst, SDL_Rect *dstrect) | |
1142 { | |
1143 CGrafPtr save_port; | |
1144 GDHandle save_device; | |
1145 Rect src_rect, dst_rect; | |
1146 RGBColor black = { 0, 0, 0 }; | |
1147 RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF }; | |
1148 | |
1149 #ifdef DSP_TRY_CC_AND_AA | |
1150 UInt32 mode; | |
1151 #endif | |
1152 | |
1153 SetRect (&src_rect, srcrect->x, srcrect->y, srcrect->x + srcrect->w, srcrect->y + srcrect->h); | |
1154 SetRect (&dst_rect, dstrect->x, dstrect->y, dstrect->x + dstrect->w, dstrect->y + dstrect->h); | |
1155 | |
1156 GetGWorld (&save_port, &save_device); | |
1157 SetGWorld (dst->hwdata->offscreen, NULL); | |
1158 | |
1159 RGBForeColor (&black); | |
1160 RGBBackColor (&white); | |
1161 | |
1162 #ifdef DSP_TRY_CC_AND_AA | |
1163 | |
1164 if ( (src->flags & SDL_SRCCOLORKEY) && | |
1165 (src->flags & SDL_SRCALPHA) ) { | |
1166 | |
1167 OpColor (&(src->hwdata->alpha)); | |
1168 | |
1169 CopyDeepMask ( GetPortBitMapForCopyBits(src->hwdata->offscreen), | |
1170 GetPortBitMapForCopyBits(src->hwdata->mask), | |
1171 GetPortBitMapForCopyBits(dst->hwdata->offscreen), | |
1172 &src_rect, &src_rect, &dst_rect, | |
1173 blend, | |
1174 NULL ); | |
1175 } | |
1176 else { | |
1177 | |
1178 if ( src->flags & SDL_SRCCOLORKEY) { | |
1179 RGBBackColor (&(src->hwdata->trans) ); | |
1180 mode = transparent; | |
1181 } | |
1182 else if (src->flags & SDL_SRCALPHA) { | |
1183 | |
1184 OpColor (&(src->hwdata->alpha)); | |
1185 mode = blend; | |
1186 } | |
1187 else { | |
1188 | |
1189 mode = srcCopy; | |
1190 } | |
1191 | |
1192 CopyBits ( GetPortBitMapForCopyBits(src->hwdata->offscreen), | |
1193 GetPortBitMapForCopyBits(dst->hwdata->offscreen), | |
1194 &src_rect, &dst_rect, mode, NULL ); | |
1195 } | |
1196 #else | |
1197 | |
1198 CopyBits ( &(((GrafPtr)(src->hwdata->offscreen))->portBits), | |
1199 &(((GrafPtr)(dst->hwdata->offscreen))->portBits), | |
1200 &src_rect, &dst_rect, srcCopy, NULL ); | |
1201 | |
1202 #endif /* DSP_TRY_CC_AND_AA */ | |
1203 | |
1204 SetGWorld (save_port, save_device); | |
1205 | |
1206 return(0); | |
1207 } | |
1208 | |
1209 static int DSp_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
1210 { | |
1211 CGrafPtr save_port; | |
1212 GDHandle save_device; | |
1213 Rect fill_rect; | |
1214 RGBColor rgb; | |
1215 | |
1216 SetRect (&fill_rect, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); | |
1217 | |
1218 GetGWorld (&save_port, &save_device); | |
1219 SetGWorld (dst->hwdata->offscreen, NULL); | |
1220 | |
1221 Index2Color (color, &rgb); | |
1222 | |
1223 RGBForeColor (&rgb); | |
1224 PaintRect (&fill_rect); | |
1225 | |
1226 SetGWorld (save_port, save_device); | |
1227 | |
1228 return(0); | |
1229 } | |
1230 | |
1231 static int DSp_FlipHWSurface(_THIS, SDL_Surface *surface) | |
1232 { | |
1233 if ( (surface->flags & SDL_HWSURFACE) ) { | |
1234 CGrafPtr dsp_front_buffer, save_port; | |
1235 Rect rect; | |
1236 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
1237 #if ! TARGET_API_MAC_OSX |
0 | 1238 unsigned int old_count; |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
1239 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
1240 |
0 | 1241 /* pseudo page flipping for VRAM back buffer*/ |
1242 DSpContext_GetFrontBuffer (dsp_context, &dsp_front_buffer); | |
1243 SetRect (&rect, 0, 0, surface->w-1, surface->h-1); | |
1244 | |
1245 GetPort ((GrafPtr *)&save_port); | |
1246 SetPort ((GrafPtr)dsp_front_buffer); | |
1247 | |
1248 /* wait for retrace */ | |
1249 /* I have tried doing the swap in interrupt routine (VBL Proc) to do */ | |
1250 /* it asynchronously, but apparently CopyBits isn't interrupt safe */ | |
1251 | |
1252 #if ! TARGET_API_MAC_OSX | |
1253 #ifndef DSP_NO_SYNC_VBL | |
1254 old_count = retrace_count; | |
1255 while (old_count == retrace_count) | |
1256 ; | |
1257 #endif | |
1258 #endif | |
1259 | |
1260 CopyBits ( GetPortBitMapForCopyBits(dsp_back_buffer), | |
1261 GetPortBitMapForCopyBits(dsp_front_buffer), | |
1262 &rect, &rect, srcCopy, NULL ); | |
1263 | |
1264 SetPort ((GrafPtr)save_port); | |
1265 | |
1266 } else { | |
1267 /* not really page flipping at all: DSp just blits the dirty rectangles from DSp_UpdateRects */ | |
1268 Boolean busy_flag; | |
1269 DSpContext_SwapBuffers (dsp_context, NULL, &busy_flag); /* this waits for VBL */ | |
1270 DSpContext_GetBackBuffer (dsp_context, kDSpBufferKind_Normal, &dsp_back_buffer); | |
1271 surface->pixels = GetPixBaseAddr( GetPortPixMap(dsp_back_buffer) ); | |
1272 } | |
1273 return(0); | |
1274 } | |
1275 | |
1276 static int DSp_LockHWSurface(_THIS, SDL_Surface *surface) | |
1277 { | |
1278 if ( LockPixels (GetGWorldPixMap (surface->hwdata->offscreen)) ) | |
1279 return 0; | |
1280 else | |
1281 return -1; | |
1282 } | |
1283 | |
1284 static void DSp_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
1285 { | |
1286 UnlockPixels (GetGWorldPixMap (surface->hwdata->offscreen)); | |
1287 } | |
1288 | |
1289 static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *sdl_rects) | |
1290 { | |
1291 return; | |
1292 } | |
1293 | |
1294 static void DSp_DSpUpdate(_THIS, int numrects, SDL_Rect *sdl_rects) | |
1295 { | |
1296 #if ! TARGET_API_MAC_OSX /* Unsupported DSp in here */ | |
1297 int i; | |
1298 Rect rect; | |
1299 | |
1300 for (i = 0; i < numrects; i++) { | |
1301 | |
1302 rect.top = sdl_rects[i].y; | |
1303 rect.left = sdl_rects[i].x; | |
1304 rect.bottom = sdl_rects[i].h + sdl_rects[i].y; | |
1305 rect.right = sdl_rects[i].w + sdl_rects[i].x; | |
1306 | |
1307 DSpContext_InvalBackBufferRect (dsp_context, &rect); | |
1308 } | |
1309 #endif | |
1310 } | |
1311 | |
1312 static int DSp_CreatePalette(_THIS) { | |
1313 | |
1314 | |
1315 /* Create our palette */ | |
1316 SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8); | |
1317 if ( SDL_CTab == nil ) { | |
1318 SDL_OutOfMemory(); | |
1319 return(-1); | |
1320 } | |
1321 (**SDL_CTab).ctSeed = GetCTSeed(); | |
1322 (**SDL_CTab).ctFlags = 0; | |
1323 (**SDL_CTab).ctSize = 255; | |
1324 CTabChanged(SDL_CTab); | |
1325 SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0); | |
1326 | |
1327 return 0; | |
1328 } | |
1329 | |
1330 static int DSp_DestroyPalette(_THIS) { | |
1331 | |
1332 /* Free palette and restore original one */ | |
1333 if ( SDL_CTab != nil ) { | |
1334 DisposeHandle((Handle)SDL_CTab); | |
1335 SDL_CTab = nil; | |
1336 } | |
1337 if ( SDL_CPal != nil ) { | |
1338 DisposePalette(SDL_CPal); | |
1339 SDL_CPal = nil; | |
1340 } | |
1341 RestoreDeviceClut(SDL_Display); | |
1342 | |
1343 return (0); | |
1344 } | |
1345 | |
1346 static int DSp_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
1347 { | |
1348 CTabHandle cTab; | |
1349 | |
1350 int i; | |
1351 | |
1352 cTab = SDL_CTab; | |
1353 | |
1354 /* Verify the range of colors */ | |
1355 if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) { | |
1356 return(0); | |
1357 } | |
1358 | |
1359 /* Set the screen palette and update the display */ | |
1360 for(i = 0; i < ncolors; i++) { | |
1361 int j = firstcolor + i; | |
1362 (**cTab).ctTable[j].value = j; | |
1363 (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r; | |
1364 (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g; | |
1365 (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b; | |
1366 } | |
1367 | |
1368 SetGDevice(SDL_Display); | |
1369 SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); | |
1370 | |
1371 return(1); | |
1372 } | |
1373 | |
1374 void DSp_VideoQuit(_THIS) | |
1375 { | |
1376 int i; | |
1377 | |
1378 /* Free current video mode */ | |
1379 DSp_UnsetVideoMode(this, this->screen); | |
1380 | |
1381 /* Free Palette and restore original */ | |
1382 DSp_DestroyPalette (this); | |
1383 | |
1384 /* Free list of video modes */ | |
1385 if ( SDL_modelist != NULL ) { | |
1386 for ( i=0; SDL_modelist[i]; i++ ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1387 SDL_free(SDL_modelist[i]); |
0 | 1388 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1389 SDL_free(SDL_modelist); |
0 | 1390 SDL_modelist = NULL; |
1391 } | |
1392 | |
1393 /* Unload DrawSprocket */ | |
1394 DSpShutdown (); | |
1395 } | |
1396 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
1397 #if SDL_VIDEO_OPENGL |
0 | 1398 |
1399 /* swap buffers with v-sync */ | |
1400 static void DSp_GL_SwapBuffers (_THIS) { | |
1401 | |
1402 #ifndef DSP_NO_SYNC_OPENGL | |
1403 | |
1404 unsigned int old_count; | |
1405 | |
1406 old_count = retrace_count; | |
1407 while (old_count == retrace_count) | |
1408 ; | |
1409 #endif | |
1410 | |
1411 aglSwapBuffers (glContext); | |
1412 } | |
1413 | |
1414 #endif |