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