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