comparison src/video/macdsp/SDL_dspvideo.c @ 1668:4da1ee79c9af SDL-1.3

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