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