Mercurial > sdl-ios-xcode
comparison src/video/windx5/SDL_dx5video.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 | fc731a7d83ed |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
54 #define PC_NOCOLLAPSE 0 | 54 #define PC_NOCOLLAPSE 0 |
55 #endif | 55 #endif |
56 | 56 |
57 | 57 |
58 /* DirectX function pointers for video and events */ | 58 /* DirectX function pointers for video and events */ |
59 HRESULT (WINAPI * DDrawCreate) (GUID FAR * lpGUID, LPDIRECTDRAW FAR * lplpDD, | 59 HRESULT(WINAPI * DDrawCreate) (GUID FAR * lpGUID, LPDIRECTDRAW FAR * lplpDD, |
60 IUnknown FAR * pUnkOuter); | 60 IUnknown FAR * pUnkOuter); |
61 HRESULT (WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, | 61 HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, |
62 LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); | 62 LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); |
63 | 63 |
64 /* This is the rect EnumModes2 uses */ | 64 /* This is the rect EnumModes2 uses */ |
65 struct DX5EnumRect | 65 struct DX5EnumRect |
66 { | 66 { |
67 SDL_Rect r; | 67 SDL_Rect r; |
404 | 404 |
405 const DIDATAFORMAT c_dfDIJoystick = { 24, 16, 0x00000001, 80, 44, JOY_fmt }; | 405 const DIDATAFORMAT c_dfDIJoystick = { 24, 16, 0x00000001, 80, 44, JOY_fmt }; |
406 | 406 |
407 | 407 |
408 /* Initialization/Query functions */ | 408 /* Initialization/Query functions */ |
409 static int DX5_VideoInit (_THIS, SDL_PixelFormat * vformat); | 409 static int DX5_VideoInit(_THIS, SDL_PixelFormat * vformat); |
410 static SDL_Rect **DX5_ListModes (_THIS, SDL_PixelFormat * format, | 410 static SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat * format, |
411 Uint32 flags); | 411 Uint32 flags); |
412 static SDL_Surface *DX5_SetVideoMode (_THIS, SDL_Surface * current, int width, | 412 static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface * current, int width, |
413 int height, int bpp, Uint32 flags); | 413 int height, int bpp, Uint32 flags); |
414 static int DX5_SetColors (_THIS, int firstcolor, int ncolors, | 414 static int DX5_SetColors(_THIS, int firstcolor, int ncolors, |
415 SDL_Color * colors); | 415 SDL_Color * colors); |
416 static int DX5_SetGammaRamp (_THIS, Uint16 * ramp); | 416 static int DX5_SetGammaRamp(_THIS, Uint16 * ramp); |
417 static int DX5_GetGammaRamp (_THIS, Uint16 * ramp); | 417 static int DX5_GetGammaRamp(_THIS, Uint16 * ramp); |
418 static void DX5_VideoQuit (_THIS); | 418 static void DX5_VideoQuit(_THIS); |
419 | 419 |
420 /* Hardware surface functions */ | 420 /* Hardware surface functions */ |
421 static int DX5_AllocHWSurface (_THIS, SDL_Surface * surface); | 421 static int DX5_AllocHWSurface(_THIS, SDL_Surface * surface); |
422 static int DX5_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst); | 422 static int DX5_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst); |
423 static int DX5_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, | 423 static int DX5_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect, |
424 Uint32 color); | 424 Uint32 color); |
425 static int DX5_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key); | 425 static int DX5_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key); |
426 static int DX5_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha); | 426 static int DX5_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha); |
427 static int DX5_LockHWSurface (_THIS, SDL_Surface * surface); | 427 static int DX5_LockHWSurface(_THIS, SDL_Surface * surface); |
428 static void DX5_UnlockHWSurface (_THIS, SDL_Surface * surface); | 428 static void DX5_UnlockHWSurface(_THIS, SDL_Surface * surface); |
429 static int DX5_FlipHWSurface (_THIS, SDL_Surface * surface); | 429 static int DX5_FlipHWSurface(_THIS, SDL_Surface * surface); |
430 static void DX5_FreeHWSurface (_THIS, SDL_Surface * surface); | 430 static void DX5_FreeHWSurface(_THIS, SDL_Surface * surface); |
431 | 431 |
432 static int DX5_AllocDDSurface (_THIS, SDL_Surface * surface, | 432 static int DX5_AllocDDSurface(_THIS, SDL_Surface * surface, |
433 LPDIRECTDRAWSURFACE3 requested, Uint32 flag); | 433 LPDIRECTDRAWSURFACE3 requested, Uint32 flag); |
434 | 434 |
435 /* Windows message handling functions */ | 435 /* Windows message handling functions */ |
436 static void DX5_RealizePalette (_THIS); | 436 static void DX5_RealizePalette(_THIS); |
437 static void DX5_PaletteChanged (_THIS, HWND window); | 437 static void DX5_PaletteChanged(_THIS, HWND window); |
438 static void DX5_WinPAINT (_THIS, HDC hdc); | 438 static void DX5_WinPAINT(_THIS, HDC hdc); |
439 | 439 |
440 /* WinDIB driver functions for manipulating gamma ramps */ | 440 /* WinDIB driver functions for manipulating gamma ramps */ |
441 extern int DIB_SetGammaRamp (_THIS, Uint16 * ramp); | 441 extern int DIB_SetGammaRamp(_THIS, Uint16 * ramp); |
442 extern int DIB_GetGammaRamp (_THIS, Uint16 * ramp); | 442 extern int DIB_GetGammaRamp(_THIS, Uint16 * ramp); |
443 extern void DIB_QuitGamma (_THIS); | 443 extern void DIB_QuitGamma(_THIS); |
444 | 444 |
445 /* Functions for loading the DirectX functions dynamically */ | 445 /* Functions for loading the DirectX functions dynamically */ |
446 static int DX5_loaded = 0; | 446 static int DX5_loaded = 0; |
447 static HINSTANCE DDrawDLL = NULL; | 447 static HINSTANCE DDrawDLL = NULL; |
448 static HINSTANCE DInputDLL = NULL; | 448 static HINSTANCE DInputDLL = NULL; |
449 | 449 |
450 void | 450 void |
451 DX5_Unload (void) | 451 DX5_Unload(void) |
452 { | 452 { |
453 if (--DX5_loaded == 0) { | 453 if (--DX5_loaded == 0) { |
454 if (DDrawDLL != NULL) { | 454 if (DDrawDLL != NULL) { |
455 FreeLibrary (DDrawDLL); | 455 FreeLibrary(DDrawDLL); |
456 DDrawCreate = NULL; | 456 DDrawCreate = NULL; |
457 DDrawDLL = NULL; | 457 DDrawDLL = NULL; |
458 } | 458 } |
459 if (DInputDLL != NULL) { | 459 if (DInputDLL != NULL) { |
460 FreeLibrary (DInputDLL); | 460 FreeLibrary(DInputDLL); |
461 DInputCreate = NULL; | 461 DInputCreate = NULL; |
462 DInputDLL = NULL; | 462 DInputDLL = NULL; |
463 } | 463 } |
464 } | 464 } |
465 } | 465 } |
466 int | 466 int |
467 DX5_Load (void) | 467 DX5_Load(void) |
468 { | 468 { |
469 int status = 0; | 469 int status = 0; |
470 | 470 |
471 if (++DX5_loaded == 1) { | 471 if (++DX5_loaded == 1) { |
472 DDrawDLL = LoadLibrary (TEXT ("DDRAW.DLL")); | 472 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL")); |
473 if (DDrawDLL != NULL) { | 473 if (DDrawDLL != NULL) { |
474 DDrawCreate = (void *) GetProcAddress (DDrawDLL, | 474 DDrawCreate = (void *) GetProcAddress(DDrawDLL, |
475 TEXT ("DirectDrawCreate")); | 475 TEXT("DirectDrawCreate")); |
476 } | 476 } |
477 DInputDLL = LoadLibrary (TEXT ("DINPUT.DLL")); | 477 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL")); |
478 if (DInputDLL != NULL) { | 478 if (DInputDLL != NULL) { |
479 DInputCreate = (void *) GetProcAddress (DInputDLL, | 479 DInputCreate = (void *) GetProcAddress(DInputDLL, |
480 TEXT | 480 TEXT |
481 ("DirectInputCreateA")); | 481 ("DirectInputCreateA")); |
482 } | 482 } |
483 if (DDrawDLL && DDrawCreate && DInputDLL && DInputCreate) { | 483 if (DDrawDLL && DDrawCreate && DInputDLL && DInputCreate) { |
484 status = 0; | 484 status = 0; |
485 } else { | 485 } else { |
486 DX5_Unload (); | 486 DX5_Unload(); |
487 status = -1; | 487 status = -1; |
488 } | 488 } |
489 } | 489 } |
490 return status; | 490 return status; |
491 } | 491 } |
492 | 492 |
493 /* DX5 driver bootstrap functions */ | 493 /* DX5 driver bootstrap functions */ |
494 | 494 |
495 static int | 495 static int |
496 DX5_Available (void) | 496 DX5_Available(void) |
497 { | 497 { |
498 int ddraw_ok = 0; | 498 int ddraw_ok = 0; |
499 HRESULT (WINAPI * DDrawCreate) (GUID *, LPDIRECTDRAW *, IUnknown *); | 499 HRESULT(WINAPI * DDrawCreate) (GUID *, LPDIRECTDRAW *, IUnknown *); |
500 LPDIRECTDRAW DDraw; | 500 LPDIRECTDRAW DDraw; |
501 | 501 |
502 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */ | 502 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */ |
503 if (DX5_Load () < 0) { | 503 if (DX5_Load() < 0) { |
504 return -1; | 504 return -1; |
505 } | 505 } |
506 | 506 |
507 /* Try to create a valid DirectDraw object */ | 507 /* Try to create a valid DirectDraw object */ |
508 DDrawCreate = | 508 DDrawCreate = (void *) GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate")); |
509 (void *) GetProcAddress (DDrawDLL, TEXT ("DirectDrawCreate")); | 509 if ((DDrawCreate != NULL) && !FAILED(DDrawCreate(NULL, &DDraw, NULL))) { |
510 if ((DDrawCreate != NULL) && !FAILED (DDrawCreate (NULL, &DDraw, NULL))) { | 510 if (!FAILED(IDirectDraw_SetCooperativeLevel(DDraw, |
511 if (!FAILED (IDirectDraw_SetCooperativeLevel (DDraw, | 511 NULL, DDSCL_NORMAL))) { |
512 NULL, DDSCL_NORMAL))) { | |
513 DDSURFACEDESC desc; | 512 DDSURFACEDESC desc; |
514 LPDIRECTDRAWSURFACE DDrawSurf; | 513 LPDIRECTDRAWSURFACE DDrawSurf; |
515 LPDIRECTDRAWSURFACE3 DDrawSurf3; | 514 LPDIRECTDRAWSURFACE3 DDrawSurf3; |
516 | 515 |
517 /* Try to create a DirectDrawSurface3 object */ | 516 /* Try to create a DirectDrawSurface3 object */ |
518 SDL_memset (&desc, 0, sizeof (desc)); | 517 SDL_memset(&desc, 0, sizeof(desc)); |
519 desc.dwSize = sizeof (desc); | 518 desc.dwSize = sizeof(desc); |
520 desc.dwFlags = DDSD_CAPS; | 519 desc.dwFlags = DDSD_CAPS; |
521 desc.ddsCaps.dwCaps = | 520 desc.ddsCaps.dwCaps = |
522 DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY; | 521 DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY; |
523 if (!FAILED | 522 if (!FAILED |
524 (IDirectDraw_CreateSurface | 523 (IDirectDraw_CreateSurface(DDraw, &desc, &DDrawSurf, NULL))) { |
525 (DDraw, &desc, &DDrawSurf, NULL))) { | |
526 if (!FAILED | 524 if (!FAILED |
527 (IDirectDrawSurface_QueryInterface | 525 (IDirectDrawSurface_QueryInterface |
528 (DDrawSurf, &IID_IDirectDrawSurface3, | 526 (DDrawSurf, &IID_IDirectDrawSurface3, |
529 (LPVOID *) & DDrawSurf3))) { | 527 (LPVOID *) & DDrawSurf3))) { |
530 /* Yay! */ | 528 /* Yay! */ |
531 ddraw_ok = 1; | 529 ddraw_ok = 1; |
532 | 530 |
533 /* Clean up.. */ | 531 /* Clean up.. */ |
534 IDirectDrawSurface3_Release (DDrawSurf3); | 532 IDirectDrawSurface3_Release(DDrawSurf3); |
535 } | 533 } |
536 IDirectDrawSurface_Release (DDrawSurf); | 534 IDirectDrawSurface_Release(DDrawSurf); |
537 } | 535 } |
538 } | 536 } |
539 IDirectDraw_Release (DDraw); | 537 IDirectDraw_Release(DDraw); |
540 } | 538 } |
541 | 539 |
542 DX5_Unload (); | 540 DX5_Unload(); |
543 | 541 |
544 return ddraw_ok; | 542 return ddraw_ok; |
545 } | 543 } |
546 | 544 |
547 static void | 545 static void |
548 DX5_DeleteDevice (SDL_VideoDevice * this) | 546 DX5_DeleteDevice(SDL_VideoDevice * this) |
549 { | 547 { |
550 /* Free DirectDraw object */ | 548 /* Free DirectDraw object */ |
551 if (ddraw2 != NULL) { | 549 if (ddraw2 != NULL) { |
552 IDirectDraw2_Release (ddraw2); | 550 IDirectDraw2_Release(ddraw2); |
553 } | 551 } |
554 DX5_Unload (); | 552 DX5_Unload(); |
555 | 553 |
556 if (this) { | 554 if (this) { |
557 if (this->hidden) { | 555 if (this->hidden) { |
558 SDL_free (this->hidden); | 556 SDL_free(this->hidden); |
559 } | 557 } |
560 if (this->gl_data) { | 558 if (this->gl_data) { |
561 SDL_free (this->gl_data); | 559 SDL_free(this->gl_data); |
562 } | 560 } |
563 SDL_free (this); | 561 SDL_free(this); |
564 } | 562 } |
565 } | 563 } |
566 | 564 |
567 static SDL_VideoDevice * | 565 static SDL_VideoDevice * |
568 DX5_CreateDevice (int devindex) | 566 DX5_CreateDevice(int devindex) |
569 { | 567 { |
570 SDL_VideoDevice *device; | 568 SDL_VideoDevice *device; |
571 | 569 |
572 /* Load DirectX */ | 570 /* Load DirectX */ |
573 if (DX5_Load () < 0) { | 571 if (DX5_Load() < 0) { |
574 return (NULL); | 572 return (NULL); |
575 } | 573 } |
576 | 574 |
577 /* Initialize all variables that we clean on shutdown */ | 575 /* Initialize all variables that we clean on shutdown */ |
578 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 576 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
579 if (device) { | 577 if (device) { |
580 SDL_memset (device, 0, (sizeof *device)); | 578 SDL_memset(device, 0, (sizeof *device)); |
581 device->hidden = (struct SDL_PrivateVideoData *) | 579 device->hidden = (struct SDL_PrivateVideoData *) |
582 SDL_malloc ((sizeof *device->hidden)); | 580 SDL_malloc((sizeof *device->hidden)); |
583 device->gl_data = (struct SDL_PrivateGLData *) | 581 device->gl_data = (struct SDL_PrivateGLData *) |
584 SDL_malloc ((sizeof *device->gl_data)); | 582 SDL_malloc((sizeof *device->gl_data)); |
585 } | 583 } |
586 if ((device == NULL) || (device->hidden == NULL) || | 584 if ((device == NULL) || (device->hidden == NULL) || |
587 (device->gl_data == NULL)) { | 585 (device->gl_data == NULL)) { |
588 SDL_OutOfMemory (); | 586 SDL_OutOfMemory(); |
589 DX5_DeleteDevice (device); | 587 DX5_DeleteDevice(device); |
590 return (NULL); | 588 return (NULL); |
591 } | 589 } |
592 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); | 590 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
593 SDL_memset (device->gl_data, 0, (sizeof *device->gl_data)); | 591 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); |
594 | 592 |
595 /* Set the function pointers */ | 593 /* Set the function pointers */ |
596 device->VideoInit = DX5_VideoInit; | 594 device->VideoInit = DX5_VideoInit; |
597 device->ListModes = DX5_ListModes; | 595 device->ListModes = DX5_ListModes; |
598 device->SetVideoMode = DX5_SetVideoMode; | 596 device->SetVideoMode = DX5_SetVideoMode; |
648 "directx", "Win95/98/2000 DirectX", | 646 "directx", "Win95/98/2000 DirectX", |
649 DX5_Available, DX5_CreateDevice | 647 DX5_Available, DX5_CreateDevice |
650 }; | 648 }; |
651 | 649 |
652 static int | 650 static int |
653 cmpmodes (const void *va, const void *vb) | 651 cmpmodes(const void *va, const void *vb) |
654 { | 652 { |
655 SDL_Rect *a = *(SDL_Rect **) va; | 653 SDL_Rect *a = *(SDL_Rect **) va; |
656 SDL_Rect *b = *(SDL_Rect **) vb; | 654 SDL_Rect *b = *(SDL_Rect **) vb; |
657 if (a->w == b->w) | 655 if (a->w == b->w) |
658 return b->h - a->h; | 656 return b->h - a->h; |
659 else | 657 else |
660 return b->w - a->w; | 658 return b->w - a->w; |
661 } | 659 } |
662 | 660 |
663 static HRESULT WINAPI | 661 static HRESULT WINAPI |
664 EnumModes2 (DDSURFACEDESC * desc, VOID * udata) | 662 EnumModes2(DDSURFACEDESC * desc, VOID * udata) |
665 { | 663 { |
666 SDL_VideoDevice *this = (SDL_VideoDevice *) udata; | 664 SDL_VideoDevice *this = (SDL_VideoDevice *) udata; |
667 struct DX5EnumRect *enumrect; | 665 struct DX5EnumRect *enumrect; |
668 #if defined(NONAMELESSUNION) | 666 #if defined(NONAMELESSUNION) |
669 int bpp = desc->ddpfPixelFormat.u1.dwRGBBitCount; | 667 int bpp = desc->ddpfPixelFormat.u1.dwRGBBitCount; |
693 enumlists[bpp]->r.h == (Uint16) desc->dwHeight) { | 691 enumlists[bpp]->r.h == (Uint16) desc->dwHeight) { |
694 if (refreshRate > enumlists[bpp]->refreshRate && | 692 if (refreshRate > enumlists[bpp]->refreshRate && |
695 refreshRate <= maxRefreshRate) { | 693 refreshRate <= maxRefreshRate) { |
696 enumlists[bpp]->refreshRate = refreshRate; | 694 enumlists[bpp]->refreshRate = refreshRate; |
697 #ifdef DDRAW_DEBUG | 695 #ifdef DDRAW_DEBUG |
698 fprintf (stderr, | 696 fprintf(stderr, |
699 "New refresh rate for %d bpp: %dx%d at %d Hz\n", | 697 "New refresh rate for %d bpp: %dx%d at %d Hz\n", |
700 (bpp + 1) * 8, (int) desc->dwWidth, | 698 (bpp + 1) * 8, (int) desc->dwWidth, |
701 (int) desc->dwHeight, refreshRate); | 699 (int) desc->dwHeight, refreshRate); |
702 #endif | 700 #endif |
703 } | 701 } |
704 break; | 702 break; |
705 } | 703 } |
706 ++SDL_nummodes[bpp]; | 704 ++SDL_nummodes[bpp]; |
707 enumrect = | 705 enumrect = |
708 (struct DX5EnumRect *) SDL_malloc (sizeof (struct DX5EnumRect)); | 706 (struct DX5EnumRect *) SDL_malloc(sizeof(struct DX5EnumRect)); |
709 if (!enumrect) { | 707 if (!enumrect) { |
710 SDL_OutOfMemory (); | 708 SDL_OutOfMemory(); |
711 return (DDENUMRET_CANCEL); | 709 return (DDENUMRET_CANCEL); |
712 } | 710 } |
713 enumrect->refreshRate = refreshRate; | 711 enumrect->refreshRate = refreshRate; |
714 enumrect->r.x = 0; | 712 enumrect->r.x = 0; |
715 enumrect->r.y = 0; | 713 enumrect->r.y = 0; |
716 enumrect->r.w = (Uint16) desc->dwWidth; | 714 enumrect->r.w = (Uint16) desc->dwWidth; |
717 enumrect->r.h = (Uint16) desc->dwHeight; | 715 enumrect->r.h = (Uint16) desc->dwHeight; |
718 enumrect->next = enumlists[bpp]; | 716 enumrect->next = enumlists[bpp]; |
719 enumlists[bpp] = enumrect; | 717 enumlists[bpp] = enumrect; |
720 #ifdef DDRAW_DEBUG | 718 #ifdef DDRAW_DEBUG |
721 fprintf (stderr, "New mode for %d bpp: %dx%d at %d Hz\n", | 719 fprintf(stderr, "New mode for %d bpp: %dx%d at %d Hz\n", |
722 (bpp + 1) * 8, (int) desc->dwWidth, (int) desc->dwHeight, | 720 (bpp + 1) * 8, (int) desc->dwWidth, (int) desc->dwHeight, |
723 refreshRate); | 721 refreshRate); |
724 #endif | 722 #endif |
725 break; | 723 break; |
726 } | 724 } |
727 | 725 |
728 return (DDENUMRET_OK); | 726 return (DDENUMRET_OK); |
729 } | 727 } |
730 | 728 |
731 void | 729 void |
732 SetDDerror (const char *function, int code) | 730 SetDDerror(const char *function, int code) |
733 { | 731 { |
734 static char *error; | 732 static char *error; |
735 static char errbuf[1024]; | 733 static char errbuf[1024]; |
736 | 734 |
737 errbuf[0] = 0; | 735 errbuf[0] = 0; |
837 break; | 835 break; |
838 case E_NOINTERFACE: | 836 case E_NOINTERFACE: |
839 error = "Interface not present"; | 837 error = "Interface not present"; |
840 break; | 838 break; |
841 default: | 839 default: |
842 SDL_snprintf (errbuf, SDL_arraysize (errbuf), | 840 SDL_snprintf(errbuf, SDL_arraysize(errbuf), |
843 "%s: Unknown DirectDraw error: 0x%x", function, code); | 841 "%s: Unknown DirectDraw error: 0x%x", function, code); |
844 break; | 842 break; |
845 } | 843 } |
846 if (!errbuf[0]) { | 844 if (!errbuf[0]) { |
847 SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function, | 845 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, |
848 error); | 846 error); |
849 } | 847 } |
850 SDL_SetError ("%s", errbuf); | 848 SDL_SetError("%s", errbuf); |
851 return; | 849 return; |
852 } | 850 } |
853 | 851 |
854 | 852 |
855 static int | 853 static int |
856 DX5_UpdateVideoInfo (_THIS) | 854 DX5_UpdateVideoInfo(_THIS) |
857 { | 855 { |
858 /* This needs to be DDCAPS_DX5 for the DirectDraw2 interface */ | 856 /* This needs to be DDCAPS_DX5 for the DirectDraw2 interface */ |
859 #if DIRECTDRAW_VERSION <= 0x300 | 857 #if DIRECTDRAW_VERSION <= 0x300 |
860 #error Your version of DirectX must be greater than or equal to 5.0 | 858 #error Your version of DirectX must be greater than or equal to 5.0 |
861 #endif | 859 #endif |
866 DDCAPS_DX5 DDCaps; | 864 DDCAPS_DX5 DDCaps; |
867 #endif | 865 #endif |
868 HRESULT result; | 866 HRESULT result; |
869 | 867 |
870 /* Fill in our hardware acceleration capabilities */ | 868 /* Fill in our hardware acceleration capabilities */ |
871 SDL_memset (&DDCaps, 0, sizeof (DDCaps)); | 869 SDL_memset(&DDCaps, 0, sizeof(DDCaps)); |
872 DDCaps.dwSize = sizeof (DDCaps); | 870 DDCaps.dwSize = sizeof(DDCaps); |
873 result = IDirectDraw2_GetCaps (ddraw2, (DDCAPS *) & DDCaps, NULL); | 871 result = IDirectDraw2_GetCaps(ddraw2, (DDCAPS *) & DDCaps, NULL); |
874 if (result != DD_OK) { | 872 if (result != DD_OK) { |
875 SetDDerror ("DirectDraw2::GetCaps", result); | 873 SetDDerror("DirectDraw2::GetCaps", result); |
876 return (-1); | 874 return (-1); |
877 } | 875 } |
878 this->info.hw_available = 1; | 876 this->info.hw_available = 1; |
879 if ((DDCaps.dwCaps & DDCAPS_BLT) == DDCAPS_BLT) { | 877 if ((DDCaps.dwCaps & DDCAPS_BLT) == DDCAPS_BLT) { |
880 this->info.blit_hw = 1; | 878 this->info.blit_hw = 1; |
902 /* Find out how much video memory is available */ | 900 /* Find out how much video memory is available */ |
903 { | 901 { |
904 DDSCAPS ddsCaps; | 902 DDSCAPS ddsCaps; |
905 DWORD total_mem; | 903 DWORD total_mem; |
906 ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; | 904 ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; |
907 result = IDirectDraw2_GetAvailableVidMem (ddraw2, | 905 result = IDirectDraw2_GetAvailableVidMem(ddraw2, |
908 &ddsCaps, &total_mem, NULL); | 906 &ddsCaps, &total_mem, NULL); |
909 if (result != DD_OK) { | 907 if (result != DD_OK) { |
910 total_mem = DDCaps.dwVidMemTotal; | 908 total_mem = DDCaps.dwVidMemTotal; |
911 } | 909 } |
912 this->info.video_mem = total_mem / 1024; | 910 this->info.video_mem = total_mem / 1024; |
913 } | 911 } |
914 return (0); | 912 return (0); |
915 } | 913 } |
916 | 914 |
917 int | 915 int |
918 DX5_VideoInit (_THIS, SDL_PixelFormat * vformat) | 916 DX5_VideoInit(_THIS, SDL_PixelFormat * vformat) |
919 { | 917 { |
920 HRESULT result; | 918 HRESULT result; |
921 LPDIRECTDRAW ddraw; | 919 LPDIRECTDRAW ddraw; |
922 int i, j; | 920 int i, j; |
923 HDC hdc; | 921 HDC hdc; |
933 SDL_modeindex[i] = 0; | 931 SDL_modeindex[i] = 0; |
934 } | 932 } |
935 colorchange_expected = 0; | 933 colorchange_expected = 0; |
936 | 934 |
937 /* Create the window */ | 935 /* Create the window */ |
938 if (DX5_CreateWindow (this) < 0) { | 936 if (DX5_CreateWindow(this) < 0) { |
939 return (-1); | 937 return (-1); |
940 } | 938 } |
941 #if !SDL_AUDIO_DISABLED | 939 #if !SDL_AUDIO_DISABLED |
942 DX5_SoundFocus (SDL_Window); | 940 DX5_SoundFocus(SDL_Window); |
943 #endif | 941 #endif |
944 | 942 |
945 /* Create the DirectDraw object */ | 943 /* Create the DirectDraw object */ |
946 result = DDrawCreate (NULL, &ddraw, NULL); | 944 result = DDrawCreate(NULL, &ddraw, NULL); |
947 if (result != DD_OK) { | 945 if (result != DD_OK) { |
948 SetDDerror ("DirectDrawCreate", result); | 946 SetDDerror("DirectDrawCreate", result); |
949 return (-1); | 947 return (-1); |
950 } | 948 } |
951 result = IDirectDraw_QueryInterface (ddraw, &IID_IDirectDraw2, | 949 result = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw2, |
952 (LPVOID *) & ddraw2); | 950 (LPVOID *) & ddraw2); |
953 IDirectDraw_Release (ddraw); | 951 IDirectDraw_Release(ddraw); |
954 if (result != DD_OK) { | 952 if (result != DD_OK) { |
955 SetDDerror ("DirectDraw::QueryInterface", result); | 953 SetDDerror("DirectDraw::QueryInterface", result); |
956 return (-1); | 954 return (-1); |
957 } | 955 } |
958 | 956 |
959 /* Determine the screen depth */ | 957 /* Determine the screen depth */ |
960 hdc = GetDC (SDL_Window); | 958 hdc = GetDC(SDL_Window); |
961 vformat->BitsPerPixel = GetDeviceCaps (hdc, PLANES) * | 959 vformat->BitsPerPixel = GetDeviceCaps(hdc, PLANES) * |
962 GetDeviceCaps (hdc, BITSPIXEL); | 960 GetDeviceCaps(hdc, BITSPIXEL); |
963 ReleaseDC (SDL_Window, hdc); | 961 ReleaseDC(SDL_Window, hdc); |
964 | 962 |
965 #ifndef NO_CHANGEDISPLAYSETTINGS | 963 #ifndef NO_CHANGEDISPLAYSETTINGS |
966 /* Query for the desktop resolution */ | 964 /* Query for the desktop resolution */ |
967 EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); | 965 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); |
968 this->info.current_w = SDL_desktop_mode.dmPelsWidth; | 966 this->info.current_w = SDL_desktop_mode.dmPelsWidth; |
969 this->info.current_h = SDL_desktop_mode.dmPelsHeight; | 967 this->info.current_h = SDL_desktop_mode.dmPelsHeight; |
970 #endif | 968 #endif |
971 | 969 |
972 /* Enumerate the available fullscreen modes */ | 970 /* Enumerate the available fullscreen modes */ |
973 for (i = 0; i < NUM_MODELISTS; ++i) | 971 for (i = 0; i < NUM_MODELISTS; ++i) |
974 enumlists[i] = NULL; | 972 enumlists[i] = NULL; |
975 | 973 |
976 result = | 974 result = |
977 IDirectDraw2_EnumDisplayModes (ddraw2, DDEDM_REFRESHRATES, NULL, this, | 975 IDirectDraw2_EnumDisplayModes(ddraw2, DDEDM_REFRESHRATES, NULL, this, |
978 EnumModes2); | 976 EnumModes2); |
979 if (result != DD_OK) { | 977 if (result != DD_OK) { |
980 SetDDerror ("DirectDraw2::EnumDisplayModes", result); | 978 SetDDerror("DirectDraw2::EnumDisplayModes", result); |
981 return (-1); | 979 return (-1); |
982 } | 980 } |
983 for (i = 0; i < NUM_MODELISTS; ++i) { | 981 for (i = 0; i < NUM_MODELISTS; ++i) { |
984 struct DX5EnumRect *rect; | 982 struct DX5EnumRect *rect; |
985 SDL_modelist[i] = (SDL_Rect **) | 983 SDL_modelist[i] = (SDL_Rect **) |
986 SDL_malloc ((SDL_nummodes[i] + 1) * sizeof (SDL_Rect *)); | 984 SDL_malloc((SDL_nummodes[i] + 1) * sizeof(SDL_Rect *)); |
987 if (SDL_modelist[i] == NULL) { | 985 if (SDL_modelist[i] == NULL) { |
988 SDL_OutOfMemory (); | 986 SDL_OutOfMemory(); |
989 return (-1); | 987 return (-1); |
990 } | 988 } |
991 for (j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next) { | 989 for (j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next) { |
992 SDL_modelist[i][j] = &rect->r; | 990 SDL_modelist[i][j] = &rect->r; |
993 } | 991 } |
994 SDL_modelist[i][j] = NULL; | 992 SDL_modelist[i][j] = NULL; |
995 | 993 |
996 if (SDL_nummodes[i] > 0) { | 994 if (SDL_nummodes[i] > 0) { |
997 SDL_qsort (SDL_modelist[i], SDL_nummodes[i], | 995 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], |
998 sizeof *SDL_modelist[i], cmpmodes); | 996 sizeof *SDL_modelist[i], cmpmodes); |
999 } | 997 } |
1000 } | 998 } |
1001 | 999 |
1002 /* Fill in some window manager capabilities */ | 1000 /* Fill in some window manager capabilities */ |
1003 this->info.wm_available = 1; | 1001 this->info.wm_available = 1; |
1004 | 1002 |
1005 /* Fill in the video hardware capabilities */ | 1003 /* Fill in the video hardware capabilities */ |
1006 DX5_UpdateVideoInfo (this); | 1004 DX5_UpdateVideoInfo(this); |
1007 | 1005 |
1008 return (0); | 1006 return (0); |
1009 } | 1007 } |
1010 | 1008 |
1011 SDL_Rect ** | 1009 SDL_Rect ** |
1012 DX5_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 1010 DX5_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
1013 { | 1011 { |
1014 int bpp; | 1012 int bpp; |
1015 | 1013 |
1016 bpp = format->BitsPerPixel; | 1014 bpp = format->BitsPerPixel; |
1017 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 1015 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
1036 } | 1034 } |
1037 } | 1035 } |
1038 } | 1036 } |
1039 | 1037 |
1040 /* Various screen update functions available */ | 1038 /* Various screen update functions available */ |
1041 static void DX5_WindowUpdate (_THIS, int numrects, SDL_Rect * rects); | 1039 static void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect * rects); |
1042 static void DX5_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); | 1040 static void DX5_DirectUpdate(_THIS, int numrects, SDL_Rect * rects); |
1043 | 1041 |
1044 SDL_Surface * | 1042 SDL_Surface * |
1045 DX5_SetVideoMode (_THIS, SDL_Surface * current, | 1043 DX5_SetVideoMode(_THIS, SDL_Surface * current, |
1046 int width, int height, int bpp, Uint32 flags) | 1044 int width, int height, int bpp, Uint32 flags) |
1047 { | 1045 { |
1048 SDL_Surface *video; | 1046 SDL_Surface *video; |
1049 HRESULT result; | 1047 HRESULT result; |
1050 DWORD sharemode; | 1048 DWORD sharemode; |
1051 DWORD style; | 1049 DWORD style; |
1057 LPDIRECTDRAWSURFACE dd_surface1; | 1055 LPDIRECTDRAWSURFACE dd_surface1; |
1058 LPDIRECTDRAWSURFACE3 dd_surface3; | 1056 LPDIRECTDRAWSURFACE3 dd_surface3; |
1059 | 1057 |
1060 SDL_resizing = 1; | 1058 SDL_resizing = 1; |
1061 #ifdef DDRAW_DEBUG | 1059 #ifdef DDRAW_DEBUG |
1062 fprintf (stderr, "Setting %dx%dx%d video mode\n", width, height, bpp); | 1060 fprintf(stderr, "Setting %dx%dx%d video mode\n", width, height, bpp); |
1063 #endif | 1061 #endif |
1064 /* Clean up any previous DirectDraw surfaces */ | 1062 /* Clean up any previous DirectDraw surfaces */ |
1065 if (current->hwdata) { | 1063 if (current->hwdata) { |
1066 this->FreeHWSurface (this, current); | 1064 this->FreeHWSurface(this, current); |
1067 current->hwdata = NULL; | 1065 current->hwdata = NULL; |
1068 } | 1066 } |
1069 if (SDL_primary != NULL) { | 1067 if (SDL_primary != NULL) { |
1070 IDirectDrawSurface3_Release (SDL_primary); | 1068 IDirectDrawSurface3_Release(SDL_primary); |
1071 SDL_primary = NULL; | 1069 SDL_primary = NULL; |
1072 } | 1070 } |
1073 #ifndef NO_CHANGEDISPLAYSETTINGS | 1071 #ifndef NO_CHANGEDISPLAYSETTINGS |
1074 /* Unset any previous OpenGL fullscreen mode */ | 1072 /* Unset any previous OpenGL fullscreen mode */ |
1075 if ((current->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) == | 1073 if ((current->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) == |
1076 (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) { | 1074 (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) { |
1077 ChangeDisplaySettings (NULL, 0); | 1075 ChangeDisplaySettings(NULL, 0); |
1078 } | 1076 } |
1079 #endif | 1077 #endif |
1080 | 1078 |
1081 /* Clean up any GL context that may be hanging around */ | 1079 /* Clean up any GL context that may be hanging around */ |
1082 if (current->flags & SDL_INTERNALOPENGL) { | 1080 if (current->flags & SDL_INTERNALOPENGL) { |
1083 WIN_GL_ShutDown (this); | 1081 WIN_GL_ShutDown(this); |
1084 } | 1082 } |
1085 | 1083 |
1086 /* If we are setting a GL mode, use GDI, not DirectX (yuck) */ | 1084 /* If we are setting a GL mode, use GDI, not DirectX (yuck) */ |
1087 if (flags & SDL_INTERNALOPENGL) { | 1085 if (flags & SDL_INTERNALOPENGL) { |
1088 Uint32 Rmask, Gmask, Bmask; | 1086 Uint32 Rmask, Gmask, Bmask; |
1117 Rmask = 0x00000000; | 1115 Rmask = 0x00000000; |
1118 Gmask = 0x00000000; | 1116 Gmask = 0x00000000; |
1119 Bmask = 0x00000000; | 1117 Bmask = 0x00000000; |
1120 break; | 1118 break; |
1121 } | 1119 } |
1122 video = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, bpp, | 1120 video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, |
1123 Rmask, Gmask, Bmask, 0); | 1121 Rmask, Gmask, Bmask, 0); |
1124 if (video == NULL) { | 1122 if (video == NULL) { |
1125 SDL_OutOfMemory (); | 1123 SDL_OutOfMemory(); |
1126 return (NULL); | 1124 return (NULL); |
1127 } | 1125 } |
1128 } | 1126 } |
1129 | 1127 |
1130 /* Fill in part of the video surface */ | 1128 /* Fill in part of the video surface */ |
1131 video->flags = 0; /* Clear flags */ | 1129 video->flags = 0; /* Clear flags */ |
1132 video->w = width; | 1130 video->w = width; |
1133 video->h = height; | 1131 video->h = height; |
1134 video->pitch = SDL_CalculatePitch (video); | 1132 video->pitch = SDL_CalculatePitch(video); |
1135 | 1133 |
1136 #ifndef NO_CHANGEDISPLAYSETTINGS | 1134 #ifndef NO_CHANGEDISPLAYSETTINGS |
1137 /* Set fullscreen mode if appropriate. | 1135 /* Set fullscreen mode if appropriate. |
1138 Ugh, since our list of valid video modes comes from | 1136 Ugh, since our list of valid video modes comes from |
1139 the DirectX driver, we may not actually be able to | 1137 the DirectX driver, we may not actually be able to |
1142 */ | 1140 */ |
1143 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 1141 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
1144 DEVMODE settings; | 1142 DEVMODE settings; |
1145 BOOL changed; | 1143 BOOL changed; |
1146 | 1144 |
1147 SDL_memset (&settings, 0, sizeof (DEVMODE)); | 1145 SDL_memset(&settings, 0, sizeof(DEVMODE)); |
1148 settings.dmSize = sizeof (DEVMODE); | 1146 settings.dmSize = sizeof(DEVMODE); |
1149 settings.dmBitsPerPel = video->format->BitsPerPixel; | 1147 settings.dmBitsPerPel = video->format->BitsPerPixel; |
1150 settings.dmPelsWidth = width; | 1148 settings.dmPelsWidth = width; |
1151 settings.dmPelsHeight = height; | 1149 settings.dmPelsHeight = height; |
1152 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | 1150 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; |
1153 if (width <= (int) SDL_desktop_mode.dmPelsWidth | 1151 if (width <= (int) SDL_desktop_mode.dmPelsWidth |
1155 settings.dmDisplayFrequency = | 1153 settings.dmDisplayFrequency = |
1156 SDL_desktop_mode.dmDisplayFrequency; | 1154 SDL_desktop_mode.dmDisplayFrequency; |
1157 settings.dmFields |= DM_DISPLAYFREQUENCY; | 1155 settings.dmFields |= DM_DISPLAYFREQUENCY; |
1158 } | 1156 } |
1159 changed = | 1157 changed = |
1160 (ChangeDisplaySettings (&settings, CDS_FULLSCREEN) == | 1158 (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == |
1161 DISP_CHANGE_SUCCESSFUL); | 1159 DISP_CHANGE_SUCCESSFUL); |
1162 if (!changed && (settings.dmFields & DM_DISPLAYFREQUENCY)) { | 1160 if (!changed && (settings.dmFields & DM_DISPLAYFREQUENCY)) { |
1163 settings.dmFields &= ~DM_DISPLAYFREQUENCY; | 1161 settings.dmFields &= ~DM_DISPLAYFREQUENCY; |
1164 changed = (ChangeDisplaySettings (&settings, CDS_FULLSCREEN) | 1162 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) |
1165 == DISP_CHANGE_SUCCESSFUL); | 1163 == DISP_CHANGE_SUCCESSFUL); |
1166 } | 1164 } |
1167 if (changed) { | 1165 if (changed) { |
1168 video->flags |= SDL_FULLSCREEN; | 1166 video->flags |= SDL_FULLSCREEN; |
1169 SDL_fullscreen_mode = settings; | 1167 SDL_fullscreen_mode = settings; |
1170 } | 1168 } |
1171 } | 1169 } |
1172 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | 1170 #endif /* !NO_CHANGEDISPLAYSETTINGS */ |
1173 | 1171 |
1174 style = GetWindowLong (SDL_Window, GWL_STYLE); | 1172 style = GetWindowLong(SDL_Window, GWL_STYLE); |
1175 style &= ~(resizestyle | WS_MAXIMIZE); | 1173 style &= ~(resizestyle | WS_MAXIMIZE); |
1176 if (video->flags & SDL_FULLSCREEN) { | 1174 if (video->flags & SDL_FULLSCREEN) { |
1177 style &= ~windowstyle; | 1175 style &= ~windowstyle; |
1178 style |= directstyle; | 1176 style |= directstyle; |
1179 } else { | 1177 } else { |
1188 style |= resizestyle; | 1186 style |= resizestyle; |
1189 video->flags |= SDL_RESIZABLE; | 1187 video->flags |= SDL_RESIZABLE; |
1190 } | 1188 } |
1191 } | 1189 } |
1192 #if WS_MAXIMIZE | 1190 #if WS_MAXIMIZE |
1193 if (IsZoomed (SDL_Window)) | 1191 if (IsZoomed(SDL_Window)) |
1194 style |= WS_MAXIMIZE; | 1192 style |= WS_MAXIMIZE; |
1195 #endif | 1193 #endif |
1196 } | 1194 } |
1197 | 1195 |
1198 /* DJM: Don't piss of anyone who has setup his own window */ | 1196 /* DJM: Don't piss of anyone who has setup his own window */ |
1199 if (!SDL_windowid) | 1197 if (!SDL_windowid) |
1200 SetWindowLong (SDL_Window, GWL_STYLE, style); | 1198 SetWindowLong(SDL_Window, GWL_STYLE, style); |
1201 | 1199 |
1202 /* Resize the window (copied from SDL WinDIB driver) */ | 1200 /* Resize the window (copied from SDL WinDIB driver) */ |
1203 if (!SDL_windowid && !IsZoomed (SDL_Window)) { | 1201 if (!SDL_windowid && !IsZoomed(SDL_Window)) { |
1204 RECT bounds; | 1202 RECT bounds; |
1205 int x, y; | 1203 int x, y; |
1206 HWND top; | 1204 HWND top; |
1207 UINT swp_flags; | 1205 UINT swp_flags; |
1208 const char *window = NULL; | 1206 const char *window = NULL; |
1209 const char *center = NULL; | 1207 const char *center = NULL; |
1210 | 1208 |
1211 if (!SDL_windowX && !SDL_windowY) { | 1209 if (!SDL_windowX && !SDL_windowY) { |
1212 window = SDL_getenv ("SDL_VIDEO_WINDOW_POS"); | 1210 window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); |
1213 center = SDL_getenv ("SDL_VIDEO_CENTERED"); | 1211 center = SDL_getenv("SDL_VIDEO_CENTERED"); |
1214 if (window) { | 1212 if (window) { |
1215 if (SDL_sscanf (window, "%d,%d", &x, &y) == 2) { | 1213 if (SDL_sscanf(window, "%d,%d", &x, &y) == 2) { |
1216 SDL_windowX = x; | 1214 SDL_windowX = x; |
1217 SDL_windowY = y; | 1215 SDL_windowY = y; |
1218 } | 1216 } |
1219 if (SDL_strcmp (window, "center") == 0) { | 1217 if (SDL_strcmp(window, "center") == 0) { |
1220 center = window; | 1218 center = window; |
1221 } | 1219 } |
1222 } | 1220 } |
1223 } | 1221 } |
1224 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); | 1222 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); |
1225 | 1223 |
1226 bounds.left = SDL_windowX; | 1224 bounds.left = SDL_windowX; |
1227 bounds.top = SDL_windowY; | 1225 bounds.top = SDL_windowY; |
1228 bounds.right = SDL_windowX + video->w; | 1226 bounds.right = SDL_windowX + video->w; |
1229 bounds.bottom = SDL_windowY + video->h; | 1227 bounds.bottom = SDL_windowY + video->h; |
1230 AdjustWindowRectEx (&bounds, | 1228 AdjustWindowRectEx(&bounds, |
1231 GetWindowLong (SDL_Window, GWL_STYLE), | 1229 GetWindowLong(SDL_Window, GWL_STYLE), |
1232 FALSE, 0); | 1230 FALSE, 0); |
1233 width = bounds.right - bounds.left; | 1231 width = bounds.right - bounds.left; |
1234 height = bounds.bottom - bounds.top; | 1232 height = bounds.bottom - bounds.top; |
1235 if ((flags & SDL_FULLSCREEN)) { | 1233 if ((flags & SDL_FULLSCREEN)) { |
1236 x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2; | 1234 x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; |
1237 y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2; | 1235 y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; |
1238 } else if (center) { | 1236 } else if (center) { |
1239 x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2; | 1237 x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; |
1240 y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2; | 1238 y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; |
1241 } else if (SDL_windowX || SDL_windowY || window) { | 1239 } else if (SDL_windowX || SDL_windowY || window) { |
1242 x = bounds.left; | 1240 x = bounds.left; |
1243 y = bounds.top; | 1241 y = bounds.top; |
1244 } else { | 1242 } else { |
1245 x = y = -1; | 1243 x = y = -1; |
1248 if (flags & SDL_FULLSCREEN) { | 1246 if (flags & SDL_FULLSCREEN) { |
1249 top = HWND_TOPMOST; | 1247 top = HWND_TOPMOST; |
1250 } else { | 1248 } else { |
1251 top = HWND_NOTOPMOST; | 1249 top = HWND_NOTOPMOST; |
1252 } | 1250 } |
1253 SetWindowPos (SDL_Window, top, x, y, width, height, swp_flags); | 1251 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); |
1254 if (!(flags & SDL_FULLSCREEN)) { | 1252 if (!(flags & SDL_FULLSCREEN)) { |
1255 SDL_windowX = SDL_bounds.left; | 1253 SDL_windowX = SDL_bounds.left; |
1256 SDL_windowY = SDL_bounds.top; | 1254 SDL_windowY = SDL_bounds.top; |
1257 } | 1255 } |
1258 SetForegroundWindow (SDL_Window); | 1256 SetForegroundWindow(SDL_Window); |
1259 } | 1257 } |
1260 SDL_resizing = 0; | 1258 SDL_resizing = 0; |
1261 | 1259 |
1262 /* Set up for OpenGL */ | 1260 /* Set up for OpenGL */ |
1263 if (WIN_GL_SetupWindow (this) < 0) { | 1261 if (WIN_GL_SetupWindow(this) < 0) { |
1264 return (NULL); | 1262 return (NULL); |
1265 } | 1263 } |
1266 video->flags |= SDL_INTERNALOPENGL; | 1264 video->flags |= SDL_INTERNALOPENGL; |
1267 return (video); | 1265 return (video); |
1268 } | 1266 } |
1269 | 1267 |
1270 /* Set the appropriate window style */ | 1268 /* Set the appropriate window style */ |
1271 style = GetWindowLong (SDL_Window, GWL_STYLE); | 1269 style = GetWindowLong(SDL_Window, GWL_STYLE); |
1272 style &= ~(resizestyle | WS_MAXIMIZE); | 1270 style &= ~(resizestyle | WS_MAXIMIZE); |
1273 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 1271 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
1274 style &= ~windowstyle; | 1272 style &= ~windowstyle; |
1275 style |= directstyle; | 1273 style |= directstyle; |
1276 } else { | 1274 } else { |
1283 if (flags & SDL_RESIZABLE) { | 1281 if (flags & SDL_RESIZABLE) { |
1284 style |= resizestyle; | 1282 style |= resizestyle; |
1285 } | 1283 } |
1286 } | 1284 } |
1287 #if WS_MAXIMIZE | 1285 #if WS_MAXIMIZE |
1288 if (IsZoomed (SDL_Window)) | 1286 if (IsZoomed(SDL_Window)) |
1289 style |= WS_MAXIMIZE; | 1287 style |= WS_MAXIMIZE; |
1290 #endif | 1288 #endif |
1291 } | 1289 } |
1292 /* DJM: Don't piss of anyone who has setup his own window */ | 1290 /* DJM: Don't piss of anyone who has setup his own window */ |
1293 if (!SDL_windowid) | 1291 if (!SDL_windowid) |
1294 SetWindowLong (SDL_Window, GWL_STYLE, style); | 1292 SetWindowLong(SDL_Window, GWL_STYLE, style); |
1295 | 1293 |
1296 /* Set DirectDraw sharing mode.. exclusive when fullscreen */ | 1294 /* Set DirectDraw sharing mode.. exclusive when fullscreen */ |
1297 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 1295 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
1298 sharemode = DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; | 1296 sharemode = DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; |
1299 } else { | 1297 } else { |
1300 sharemode = DDSCL_NORMAL; | 1298 sharemode = DDSCL_NORMAL; |
1301 } | 1299 } |
1302 result = IDirectDraw2_SetCooperativeLevel (ddraw2, SDL_Window, sharemode); | 1300 result = IDirectDraw2_SetCooperativeLevel(ddraw2, SDL_Window, sharemode); |
1303 if (result != DD_OK) { | 1301 if (result != DD_OK) { |
1304 SetDDerror ("DirectDraw2::SetCooperativeLevel", result); | 1302 SetDDerror("DirectDraw2::SetCooperativeLevel", result); |
1305 return (NULL); | 1303 return (NULL); |
1306 } | 1304 } |
1307 | 1305 |
1308 /* Set the display mode, if we are in fullscreen mode */ | 1306 /* Set the display mode, if we are in fullscreen mode */ |
1309 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 1307 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
1312 int maxRefreshRate; | 1310 int maxRefreshRate; |
1313 | 1311 |
1314 /* Cover up desktop during mode change */ | 1312 /* Cover up desktop during mode change */ |
1315 bounds.left = 0; | 1313 bounds.left = 0; |
1316 bounds.top = 0; | 1314 bounds.top = 0; |
1317 bounds.right = GetSystemMetrics (SM_CXSCREEN); | 1315 bounds.right = GetSystemMetrics(SM_CXSCREEN); |
1318 bounds.bottom = GetSystemMetrics (SM_CYSCREEN); | 1316 bounds.bottom = GetSystemMetrics(SM_CYSCREEN); |
1319 AdjustWindowRectEx (&bounds, GetWindowLong (SDL_Window, GWL_STYLE), | 1317 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), |
1320 FALSE, 0); | 1318 FALSE, 0); |
1321 SetWindowPos (SDL_Window, HWND_TOPMOST, bounds.left, bounds.top, | 1319 SetWindowPos(SDL_Window, HWND_TOPMOST, bounds.left, bounds.top, |
1322 bounds.right - bounds.left, | 1320 bounds.right - bounds.left, |
1323 bounds.bottom - bounds.top, SWP_NOCOPYBITS); | 1321 bounds.bottom - bounds.top, SWP_NOCOPYBITS); |
1324 ShowWindow (SDL_Window, SW_SHOW); | 1322 ShowWindow(SDL_Window, SW_SHOW); |
1325 while (GetForegroundWindow () != SDL_Window) { | 1323 while (GetForegroundWindow() != SDL_Window) { |
1326 SetForegroundWindow (SDL_Window); | 1324 SetForegroundWindow(SDL_Window); |
1327 SDL_Delay (100); | 1325 SDL_Delay(100); |
1328 } | 1326 } |
1329 | 1327 |
1330 /* find maximum monitor refresh rate for this resolution */ | 1328 /* find maximum monitor refresh rate for this resolution */ |
1331 /* Dmitry Yakimov ftech@tula.net */ | 1329 /* Dmitry Yakimov ftech@tula.net */ |
1332 maxRefreshRate = 0; /* system default */ | 1330 maxRefreshRate = 0; /* system default */ |
1335 maxRefreshRate = rect->refreshRate; | 1333 maxRefreshRate = rect->refreshRate; |
1336 break; | 1334 break; |
1337 } | 1335 } |
1338 } | 1336 } |
1339 #ifdef DDRAW_DEBUG | 1337 #ifdef DDRAW_DEBUG |
1340 fprintf (stderr, "refresh rate = %d Hz\n", maxRefreshRate); | 1338 fprintf(stderr, "refresh rate = %d Hz\n", maxRefreshRate); |
1341 #endif | 1339 #endif |
1342 | 1340 |
1343 result = | 1341 result = |
1344 IDirectDraw2_SetDisplayMode (ddraw2, width, height, bpp, | 1342 IDirectDraw2_SetDisplayMode(ddraw2, width, height, bpp, |
1345 maxRefreshRate, 0); | 1343 maxRefreshRate, 0); |
1346 if (result != DD_OK) { | 1344 if (result != DD_OK) { |
1347 result = | 1345 result = |
1348 IDirectDraw2_SetDisplayMode (ddraw2, width, height, bpp, | 1346 IDirectDraw2_SetDisplayMode(ddraw2, width, height, bpp, 0, 0); |
1349 0, 0); | |
1350 if (result != DD_OK) { | 1347 if (result != DD_OK) { |
1351 /* We couldn't set fullscreen mode, try window */ | 1348 /* We couldn't set fullscreen mode, try window */ |
1352 return (DX5_SetVideoMode | 1349 return (DX5_SetVideoMode |
1353 (this, current, width, height, bpp, | 1350 (this, current, width, height, bpp, |
1354 flags & ~SDL_FULLSCREEN)); | 1351 flags & ~SDL_FULLSCREEN)); |
1355 } | 1352 } |
1356 } | 1353 } |
1357 DX5_DInputReset (this, 1); | 1354 DX5_DInputReset(this, 1); |
1358 } else { | 1355 } else { |
1359 DX5_DInputReset (this, 0); | 1356 DX5_DInputReset(this, 0); |
1360 } | 1357 } |
1361 DX5_UpdateVideoInfo (this); | 1358 DX5_UpdateVideoInfo(this); |
1362 | 1359 |
1363 /* Create a primary DirectDraw surface */ | 1360 /* Create a primary DirectDraw surface */ |
1364 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 1361 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
1365 ddsd.dwSize = sizeof (ddsd); | 1362 ddsd.dwSize = sizeof(ddsd); |
1366 ddsd.dwFlags = DDSD_CAPS; | 1363 ddsd.dwFlags = DDSD_CAPS; |
1367 ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY); | 1364 ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY); |
1368 if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { | 1365 if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { |
1369 /* There's no windowed double-buffering */ | 1366 /* There's no windowed double-buffering */ |
1370 flags &= ~SDL_DOUBLEBUF; | 1367 flags &= ~SDL_DOUBLEBUF; |
1372 if ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { | 1369 if ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
1373 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; | 1370 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; |
1374 ddsd.ddsCaps.dwCaps |= (DDSCAPS_COMPLEX | DDSCAPS_FLIP); | 1371 ddsd.ddsCaps.dwCaps |= (DDSCAPS_COMPLEX | DDSCAPS_FLIP); |
1375 ddsd.dwBackBufferCount = 1; | 1372 ddsd.dwBackBufferCount = 1; |
1376 } | 1373 } |
1377 result = IDirectDraw2_CreateSurface (ddraw2, &ddsd, &dd_surface1, NULL); | 1374 result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL); |
1378 if ((result != DD_OK) && ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)) { | 1375 if ((result != DD_OK) && ((flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)) { |
1379 ddsd.dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 1376 ddsd.dwFlags &= ~DDSD_BACKBUFFERCOUNT; |
1380 ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX | DDSCAPS_FLIP); | 1377 ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX | DDSCAPS_FLIP); |
1381 ddsd.dwBackBufferCount = 0; | 1378 ddsd.dwBackBufferCount = 0; |
1382 result = IDirectDraw2_CreateSurface (ddraw2, | 1379 result = IDirectDraw2_CreateSurface(ddraw2, |
1383 &ddsd, &dd_surface1, NULL); | 1380 &ddsd, &dd_surface1, NULL); |
1384 } | 1381 } |
1385 if (result != DD_OK) { | 1382 if (result != DD_OK) { |
1386 SetDDerror ("DirectDraw2::CreateSurface(PRIMARY)", result); | 1383 SetDDerror("DirectDraw2::CreateSurface(PRIMARY)", result); |
1387 return (NULL); | 1384 return (NULL); |
1388 } | 1385 } |
1389 result = IDirectDrawSurface_QueryInterface (dd_surface1, | 1386 result = IDirectDrawSurface_QueryInterface(dd_surface1, |
1390 &IID_IDirectDrawSurface3, | 1387 &IID_IDirectDrawSurface3, |
1391 (LPVOID *) & SDL_primary); | 1388 (LPVOID *) & SDL_primary); |
1392 if (result != DD_OK) { | 1389 if (result != DD_OK) { |
1393 SetDDerror ("DirectDrawSurface::QueryInterface", result); | 1390 SetDDerror("DirectDrawSurface::QueryInterface", result); |
1394 return (NULL); | 1391 return (NULL); |
1395 } | 1392 } |
1396 IDirectDrawSurface_Release (dd_surface1); | 1393 IDirectDrawSurface_Release(dd_surface1); |
1397 | 1394 |
1398 /* Get the format of the primary DirectDraw surface */ | 1395 /* Get the format of the primary DirectDraw surface */ |
1399 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 1396 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
1400 ddsd.dwSize = sizeof (ddsd); | 1397 ddsd.dwSize = sizeof(ddsd); |
1401 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS; | 1398 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS; |
1402 result = IDirectDrawSurface3_GetSurfaceDesc (SDL_primary, &ddsd); | 1399 result = IDirectDrawSurface3_GetSurfaceDesc(SDL_primary, &ddsd); |
1403 if (result != DD_OK) { | 1400 if (result != DD_OK) { |
1404 SetDDerror ("DirectDrawSurface::GetSurfaceDesc", result); | 1401 SetDDerror("DirectDrawSurface::GetSurfaceDesc", result); |
1405 return (NULL); | 1402 return (NULL); |
1406 } | 1403 } |
1407 if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)) { | 1404 if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)) { |
1408 SDL_SetError ("Primary DDRAW surface is not RGB format"); | 1405 SDL_SetError("Primary DDRAW surface is not RGB format"); |
1409 return (NULL); | 1406 return (NULL); |
1410 } | 1407 } |
1411 | 1408 |
1412 /* Free old palette and create a new one if we're in 8-bit mode */ | 1409 /* Free old palette and create a new one if we're in 8-bit mode */ |
1413 if (SDL_palette != NULL) { | 1410 if (SDL_palette != NULL) { |
1414 IDirectDrawPalette_Release (SDL_palette); | 1411 IDirectDrawPalette_Release(SDL_palette); |
1415 SDL_palette = NULL; | 1412 SDL_palette = NULL; |
1416 } | 1413 } |
1417 #if defined(NONAMELESSUNION) | 1414 #if defined(NONAMELESSUNION) |
1418 if (ddsd.ddpfPixelFormat.u1.dwRGBBitCount == 8) { | 1415 if (ddsd.ddpfPixelFormat.u1.dwRGBBitCount == 8) { |
1419 #else | 1416 #else |
1449 SDL_colors[i].peRed = i; | 1446 SDL_colors[i].peRed = i; |
1450 SDL_colors[i].peGreen = 0; | 1447 SDL_colors[i].peGreen = 0; |
1451 SDL_colors[i].peBlue = 0; | 1448 SDL_colors[i].peBlue = 0; |
1452 } | 1449 } |
1453 } | 1450 } |
1454 result = IDirectDraw2_CreatePalette (ddraw2, | 1451 result = IDirectDraw2_CreatePalette(ddraw2, |
1455 (DDPCAPS_8BIT | | 1452 (DDPCAPS_8BIT | |
1456 DDPCAPS_ALLOW256), SDL_colors, | 1453 DDPCAPS_ALLOW256), SDL_colors, |
1457 &SDL_palette, NULL); | 1454 &SDL_palette, NULL); |
1458 if (result != DD_OK) { | 1455 if (result != DD_OK) { |
1459 SetDDerror ("DirectDraw2::CreatePalette", result); | 1456 SetDDerror("DirectDraw2::CreatePalette", result); |
1460 return (NULL); | 1457 return (NULL); |
1461 } | 1458 } |
1462 result = IDirectDrawSurface3_SetPalette (SDL_primary, SDL_palette); | 1459 result = IDirectDrawSurface3_SetPalette(SDL_primary, SDL_palette); |
1463 if (result != DD_OK) { | 1460 if (result != DD_OK) { |
1464 SetDDerror ("DirectDrawSurface3::SetPalette", result); | 1461 SetDDerror("DirectDrawSurface3::SetPalette", result); |
1465 return (NULL); | 1462 return (NULL); |
1466 } | 1463 } |
1467 } | 1464 } |
1468 | 1465 |
1469 /* Create our video surface using the same pixel format */ | 1466 /* Create our video surface using the same pixel format */ |
1473 #if defined(NONAMELESSUNION) | 1470 #if defined(NONAMELESSUNION) |
1474 ddsd.ddpfPixelFormat.u1.dwRGBBitCount)) { | 1471 ddsd.ddpfPixelFormat.u1.dwRGBBitCount)) { |
1475 #else | 1472 #else |
1476 ddsd.ddpfPixelFormat.dwRGBBitCount)) { | 1473 ddsd.ddpfPixelFormat.dwRGBBitCount)) { |
1477 #endif | 1474 #endif |
1478 SDL_FreeSurface (video); | 1475 SDL_FreeSurface(video); |
1479 video = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, | 1476 video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, |
1480 #if defined(NONAMELESSUNION) | 1477 #if defined(NONAMELESSUNION) |
1481 ddsd.ddpfPixelFormat.u1.dwRGBBitCount, | 1478 ddsd.ddpfPixelFormat.u1.dwRGBBitCount, |
1482 ddsd.ddpfPixelFormat.u2.dwRBitMask, | 1479 ddsd.ddpfPixelFormat.u2.dwRBitMask, |
1483 ddsd.ddpfPixelFormat.u3.dwGBitMask, | 1480 ddsd.ddpfPixelFormat.u3.dwGBitMask, |
1484 ddsd.ddpfPixelFormat.u4.dwBBitMask, | 1481 ddsd.ddpfPixelFormat.u4.dwBBitMask, |
1485 #else | 1482 #else |
1486 ddsd.ddpfPixelFormat.dwRGBBitCount, | 1483 ddsd.ddpfPixelFormat.dwRGBBitCount, |
1487 ddsd.ddpfPixelFormat.dwRBitMask, | 1484 ddsd.ddpfPixelFormat.dwRBitMask, |
1488 ddsd.ddpfPixelFormat.dwGBitMask, | 1485 ddsd.ddpfPixelFormat.dwGBitMask, |
1489 ddsd.ddpfPixelFormat.dwBBitMask, | 1486 ddsd.ddpfPixelFormat.dwBBitMask, |
1490 #endif | 1487 #endif |
1491 0); | 1488 0); |
1492 if (video == NULL) { | 1489 if (video == NULL) { |
1493 SDL_OutOfMemory (); | 1490 SDL_OutOfMemory(); |
1494 return (NULL); | 1491 return (NULL); |
1495 } | 1492 } |
1496 video->w = width; | 1493 video->w = width; |
1497 video->h = height; | 1494 video->h = height; |
1498 video->pitch = 0; | 1495 video->pitch = 0; |
1518 /* Necessary if we're going from fullscreen to window */ | 1515 /* Necessary if we're going from fullscreen to window */ |
1519 if (video->pixels == NULL) { | 1516 if (video->pixels == NULL) { |
1520 video->pitch = (width * video->format->BytesPerPixel); | 1517 video->pitch = (width * video->format->BytesPerPixel); |
1521 /* Pitch needs to be QWORD (8-byte) aligned */ | 1518 /* Pitch needs to be QWORD (8-byte) aligned */ |
1522 video->pitch = (video->pitch + 7) & ~7; | 1519 video->pitch = (video->pitch + 7) & ~7; |
1523 video->pixels = (void *) SDL_malloc (video->h * video->pitch); | 1520 video->pixels = (void *) SDL_malloc(video->h * video->pitch); |
1524 if (video->pixels == NULL) { | 1521 if (video->pixels == NULL) { |
1525 if (video != current) { | 1522 if (video != current) { |
1526 SDL_FreeSurface (video); | 1523 SDL_FreeSurface(video); |
1527 } | 1524 } |
1528 SDL_OutOfMemory (); | 1525 SDL_OutOfMemory(); |
1529 return (NULL); | 1526 return (NULL); |
1530 } | 1527 } |
1531 } | 1528 } |
1532 dd_surface3 = NULL; | 1529 dd_surface3 = NULL; |
1533 #if 0 /* FIXME: enable this when SDL consistently reports lost surfaces */ | 1530 #if 0 /* FIXME: enable this when SDL consistently reports lost surfaces */ |
1546 video->flags |= SDL_NOFRAME; | 1543 video->flags |= SDL_NOFRAME; |
1547 } | 1544 } |
1548 } else { | 1545 } else { |
1549 /* Necessary if we're going from window to fullscreen */ | 1546 /* Necessary if we're going from window to fullscreen */ |
1550 if (video->pixels != NULL) { | 1547 if (video->pixels != NULL) { |
1551 SDL_free (video->pixels); | 1548 SDL_free(video->pixels); |
1552 video->pixels = NULL; | 1549 video->pixels = NULL; |
1553 } | 1550 } |
1554 dd_surface3 = SDL_primary; | 1551 dd_surface3 = SDL_primary; |
1555 video->flags |= SDL_HWSURFACE; | 1552 video->flags |= SDL_HWSURFACE; |
1556 } | 1553 } |
1559 if ((ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP) == DDSCAPS_FLIP) { | 1556 if ((ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP) == DDSCAPS_FLIP) { |
1560 video->flags |= SDL_DOUBLEBUF; | 1557 video->flags |= SDL_DOUBLEBUF; |
1561 } | 1558 } |
1562 | 1559 |
1563 /* Allocate the SDL surface associated with the primary surface */ | 1560 /* Allocate the SDL surface associated with the primary surface */ |
1564 if (DX5_AllocDDSurface (this, video, dd_surface3, | 1561 if (DX5_AllocDDSurface(this, video, dd_surface3, |
1565 video->flags & SDL_HWSURFACE) < 0) { | 1562 video->flags & SDL_HWSURFACE) < 0) { |
1566 if (video != current) { | 1563 if (video != current) { |
1567 SDL_FreeSurface (video); | 1564 SDL_FreeSurface(video); |
1568 } | 1565 } |
1569 return (NULL); | 1566 return (NULL); |
1570 } | 1567 } |
1571 | 1568 |
1572 /* Use the appropriate blitting function */ | 1569 /* Use the appropriate blitting function */ |
1582 | 1579 |
1583 /* Make our window the proper size, set the clipper, then show it */ | 1580 /* Make our window the proper size, set the clipper, then show it */ |
1584 if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { | 1581 if ((flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { |
1585 /* Create and set a clipper on our primary surface */ | 1582 /* Create and set a clipper on our primary surface */ |
1586 if (SDL_clipper == NULL) { | 1583 if (SDL_clipper == NULL) { |
1587 result = IDirectDraw2_CreateClipper (ddraw2, | 1584 result = IDirectDraw2_CreateClipper(ddraw2, |
1588 0, &SDL_clipper, NULL); | 1585 0, &SDL_clipper, NULL); |
1589 if (result != DD_OK) { | 1586 if (result != DD_OK) { |
1590 if (video != current) { | 1587 if (video != current) { |
1591 SDL_FreeSurface (video); | 1588 SDL_FreeSurface(video); |
1592 } | 1589 } |
1593 SetDDerror ("DirectDraw2::CreateClipper", result); | 1590 SetDDerror("DirectDraw2::CreateClipper", result); |
1594 return (NULL); | 1591 return (NULL); |
1595 } | 1592 } |
1596 } | 1593 } |
1597 result = IDirectDrawClipper_SetHWnd (SDL_clipper, 0, SDL_Window); | 1594 result = IDirectDrawClipper_SetHWnd(SDL_clipper, 0, SDL_Window); |
1598 if (result != DD_OK) { | 1595 if (result != DD_OK) { |
1599 if (video != current) { | 1596 if (video != current) { |
1600 SDL_FreeSurface (video); | 1597 SDL_FreeSurface(video); |
1601 } | 1598 } |
1602 SetDDerror ("DirectDrawClipper::SetHWnd", result); | 1599 SetDDerror("DirectDrawClipper::SetHWnd", result); |
1603 return (NULL); | 1600 return (NULL); |
1604 } | 1601 } |
1605 result = IDirectDrawSurface3_SetClipper (SDL_primary, SDL_clipper); | 1602 result = IDirectDrawSurface3_SetClipper(SDL_primary, SDL_clipper); |
1606 if (result != DD_OK) { | 1603 if (result != DD_OK) { |
1607 if (video != current) { | 1604 if (video != current) { |
1608 SDL_FreeSurface (video); | 1605 SDL_FreeSurface(video); |
1609 } | 1606 } |
1610 SetDDerror ("DirectDrawSurface3::SetClipper", result); | 1607 SetDDerror("DirectDrawSurface3::SetClipper", result); |
1611 return (NULL); | 1608 return (NULL); |
1612 } | 1609 } |
1613 | 1610 |
1614 /* Resize the window (copied from SDL WinDIB driver) */ | 1611 /* Resize the window (copied from SDL WinDIB driver) */ |
1615 if (!SDL_windowid && !IsZoomed (SDL_Window)) { | 1612 if (!SDL_windowid && !IsZoomed(SDL_Window)) { |
1616 RECT bounds; | 1613 RECT bounds; |
1617 int x, y; | 1614 int x, y; |
1618 UINT swp_flags; | 1615 UINT swp_flags; |
1619 const char *window = NULL; | 1616 const char *window = NULL; |
1620 const char *center = NULL; | 1617 const char *center = NULL; |
1621 | 1618 |
1622 if (!SDL_windowX && !SDL_windowY) { | 1619 if (!SDL_windowX && !SDL_windowY) { |
1623 window = SDL_getenv ("SDL_VIDEO_WINDOW_POS"); | 1620 window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); |
1624 center = SDL_getenv ("SDL_VIDEO_CENTERED"); | 1621 center = SDL_getenv("SDL_VIDEO_CENTERED"); |
1625 if (window) { | 1622 if (window) { |
1626 if (SDL_sscanf (window, "%d,%d", &x, &y) == 2) { | 1623 if (SDL_sscanf(window, "%d,%d", &x, &y) == 2) { |
1627 SDL_windowX = x; | 1624 SDL_windowX = x; |
1628 SDL_windowY = y; | 1625 SDL_windowY = y; |
1629 } | 1626 } |
1630 if (SDL_strcmp (window, "center") == 0) { | 1627 if (SDL_strcmp(window, "center") == 0) { |
1631 center = window; | 1628 center = window; |
1632 } | 1629 } |
1633 } | 1630 } |
1634 } | 1631 } |
1635 swp_flags = SWP_NOCOPYBITS; | 1632 swp_flags = SWP_NOCOPYBITS; |
1636 | 1633 |
1637 bounds.left = SDL_windowX; | 1634 bounds.left = SDL_windowX; |
1638 bounds.top = SDL_windowY; | 1635 bounds.top = SDL_windowY; |
1639 bounds.right = SDL_windowX + video->w; | 1636 bounds.right = SDL_windowX + video->w; |
1640 bounds.bottom = SDL_windowY + video->h; | 1637 bounds.bottom = SDL_windowY + video->h; |
1641 AdjustWindowRectEx (&bounds, | 1638 AdjustWindowRectEx(&bounds, |
1642 GetWindowLong (SDL_Window, GWL_STYLE), | 1639 GetWindowLong(SDL_Window, GWL_STYLE), |
1643 FALSE, 0); | 1640 FALSE, 0); |
1644 width = bounds.right - bounds.left; | 1641 width = bounds.right - bounds.left; |
1645 height = bounds.bottom - bounds.top; | 1642 height = bounds.bottom - bounds.top; |
1646 if (center) { | 1643 if (center) { |
1647 x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2; | 1644 x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; |
1648 y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2; | 1645 y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; |
1649 } else if (SDL_windowX || SDL_windowY || window) { | 1646 } else if (SDL_windowX || SDL_windowY || window) { |
1650 x = bounds.left; | 1647 x = bounds.left; |
1651 y = bounds.top; | 1648 y = bounds.top; |
1652 } else { | 1649 } else { |
1653 x = y = -1; | 1650 x = y = -1; |
1654 swp_flags |= SWP_NOMOVE; | 1651 swp_flags |= SWP_NOMOVE; |
1655 } | 1652 } |
1656 SetWindowPos (SDL_Window, HWND_NOTOPMOST, x, y, width, height, | 1653 SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, |
1657 swp_flags); | 1654 swp_flags); |
1658 SDL_windowX = SDL_bounds.left; | 1655 SDL_windowX = SDL_bounds.left; |
1659 SDL_windowY = SDL_bounds.top; | 1656 SDL_windowY = SDL_bounds.top; |
1660 } | 1657 } |
1661 | 1658 |
1662 } | 1659 } |
1663 ShowWindow (SDL_Window, SW_SHOW); | 1660 ShowWindow(SDL_Window, SW_SHOW); |
1664 SetForegroundWindow (SDL_Window); | 1661 SetForegroundWindow(SDL_Window); |
1665 SDL_resizing = 0; | 1662 SDL_resizing = 0; |
1666 | 1663 |
1667 /* JC 14 Mar 2006 | 1664 /* JC 14 Mar 2006 |
1668 Flush the message loop or this can cause big problems later | 1665 Flush the message loop or this can cause big problems later |
1669 Especially if the user decides to use dialog boxes or assert()! | 1666 Especially if the user decides to use dialog boxes or assert()! |
1670 */ | 1667 */ |
1671 WIN_FlushMessageQueue (); | 1668 WIN_FlushMessageQueue(); |
1672 | 1669 |
1673 /* We're live! */ | 1670 /* We're live! */ |
1674 return (video); | 1671 return (video); |
1675 } | 1672 } |
1676 | 1673 |
1679 LPDIRECTDRAWSURFACE3 dd_surface; | 1676 LPDIRECTDRAWSURFACE3 dd_surface; |
1680 LPDIRECTDRAWSURFACE3 dd_writebuf; | 1677 LPDIRECTDRAWSURFACE3 dd_writebuf; |
1681 }; | 1678 }; |
1682 | 1679 |
1683 static int | 1680 static int |
1684 DX5_AllocDDSurface (_THIS, SDL_Surface * surface, | 1681 DX5_AllocDDSurface(_THIS, SDL_Surface * surface, |
1685 LPDIRECTDRAWSURFACE3 requested, Uint32 flag) | 1682 LPDIRECTDRAWSURFACE3 requested, Uint32 flag) |
1686 { | 1683 { |
1687 LPDIRECTDRAWSURFACE dd_surface1; | 1684 LPDIRECTDRAWSURFACE dd_surface1; |
1688 LPDIRECTDRAWSURFACE3 dd_surface3; | 1685 LPDIRECTDRAWSURFACE3 dd_surface3; |
1689 DDSURFACEDESC ddsd; | 1686 DDSURFACEDESC ddsd; |
1690 HRESULT result; | 1687 HRESULT result; |
1692 /* Clear the hardware flag, in case we fail */ | 1689 /* Clear the hardware flag, in case we fail */ |
1693 surface->flags &= ~flag; | 1690 surface->flags &= ~flag; |
1694 | 1691 |
1695 /* Allocate the hardware acceleration data */ | 1692 /* Allocate the hardware acceleration data */ |
1696 surface->hwdata = (struct private_hwdata *) | 1693 surface->hwdata = (struct private_hwdata *) |
1697 SDL_malloc (sizeof (*surface->hwdata)); | 1694 SDL_malloc(sizeof(*surface->hwdata)); |
1698 if (surface->hwdata == NULL) { | 1695 if (surface->hwdata == NULL) { |
1699 SDL_OutOfMemory (); | 1696 SDL_OutOfMemory(); |
1700 return (-1); | 1697 return (-1); |
1701 } | 1698 } |
1702 dd_surface3 = NULL; | 1699 dd_surface3 = NULL; |
1703 | 1700 |
1704 /* Set up the surface description */ | 1701 /* Set up the surface description */ |
1705 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 1702 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
1706 ddsd.dwSize = sizeof (ddsd); | 1703 ddsd.dwSize = sizeof(ddsd); |
1707 ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | | 1704 ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | |
1708 DDSD_PITCH | DDSD_PIXELFORMAT); | 1705 DDSD_PITCH | DDSD_PIXELFORMAT); |
1709 ddsd.dwWidth = surface->w; | 1706 ddsd.dwWidth = surface->w; |
1710 ddsd.dwHeight = surface->h; | 1707 ddsd.dwHeight = surface->h; |
1711 #if defined(NONAMELESSUNION) | 1708 #if defined(NONAMELESSUNION) |
1716 if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) { | 1713 if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) { |
1717 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY); | 1714 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY); |
1718 } else { | 1715 } else { |
1719 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY); | 1716 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY); |
1720 } | 1717 } |
1721 ddsd.ddpfPixelFormat.dwSize = sizeof (ddsd.ddpfPixelFormat); | 1718 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); |
1722 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; | 1719 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; |
1723 if (surface->format->palette) { | 1720 if (surface->format->palette) { |
1724 ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8; | 1721 ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8; |
1725 } | 1722 } |
1726 #if defined(NONAMELESSUNION) | 1723 #if defined(NONAMELESSUNION) |
1737 | 1734 |
1738 /* Create the DirectDraw video surface */ | 1735 /* Create the DirectDraw video surface */ |
1739 if (requested != NULL) { | 1736 if (requested != NULL) { |
1740 dd_surface3 = requested; | 1737 dd_surface3 = requested; |
1741 } else { | 1738 } else { |
1742 result = IDirectDraw2_CreateSurface (ddraw2, | 1739 result = IDirectDraw2_CreateSurface(ddraw2, |
1743 &ddsd, &dd_surface1, NULL); | 1740 &ddsd, &dd_surface1, NULL); |
1744 if (result != DD_OK) { | 1741 if (result != DD_OK) { |
1745 SetDDerror ("DirectDraw2::CreateSurface", result); | 1742 SetDDerror("DirectDraw2::CreateSurface", result); |
1746 goto error_end; | 1743 goto error_end; |
1747 } | 1744 } |
1748 result = IDirectDrawSurface_QueryInterface (dd_surface1, | 1745 result = IDirectDrawSurface_QueryInterface(dd_surface1, |
1749 &IID_IDirectDrawSurface3, | 1746 &IID_IDirectDrawSurface3, |
1750 (LPVOID *) & dd_surface3); | 1747 (LPVOID *) & dd_surface3); |
1751 IDirectDrawSurface_Release (dd_surface1); | 1748 IDirectDrawSurface_Release(dd_surface1); |
1752 if (result != DD_OK) { | 1749 if (result != DD_OK) { |
1753 SetDDerror ("DirectDrawSurface::QueryInterface", result); | 1750 SetDDerror("DirectDrawSurface::QueryInterface", result); |
1754 goto error_end; | 1751 goto error_end; |
1755 } | 1752 } |
1756 } | 1753 } |
1757 | 1754 |
1758 if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) { | 1755 if ((flag & SDL_HWSURFACE) == SDL_HWSURFACE) { |
1759 /* Check to see whether the surface actually ended up | 1756 /* Check to see whether the surface actually ended up |
1760 in video memory, and fail if not. We expect the | 1757 in video memory, and fail if not. We expect the |
1761 surfaces we create here to actually be in hardware! | 1758 surfaces we create here to actually be in hardware! |
1762 */ | 1759 */ |
1763 result = IDirectDrawSurface3_GetCaps (dd_surface3, &ddsd.ddsCaps); | 1760 result = IDirectDrawSurface3_GetCaps(dd_surface3, &ddsd.ddsCaps); |
1764 if (result != DD_OK) { | 1761 if (result != DD_OK) { |
1765 SetDDerror ("DirectDrawSurface3::GetCaps", result); | 1762 SetDDerror("DirectDrawSurface3::GetCaps", result); |
1766 goto error_end; | 1763 goto error_end; |
1767 } | 1764 } |
1768 if ((ddsd.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) != | 1765 if ((ddsd.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) != |
1769 DDSCAPS_VIDEOMEMORY) { | 1766 DDSCAPS_VIDEOMEMORY) { |
1770 SDL_SetError ("No room in video memory"); | 1767 SDL_SetError("No room in video memory"); |
1771 goto error_end; | 1768 goto error_end; |
1772 } | 1769 } |
1773 } else { | 1770 } else { |
1774 /* Try to hook our surface memory */ | 1771 /* Try to hook our surface memory */ |
1775 ddsd.dwFlags = DDSD_LPSURFACE; | 1772 ddsd.dwFlags = DDSD_LPSURFACE; |
1776 ddsd.lpSurface = surface->pixels; | 1773 ddsd.lpSurface = surface->pixels; |
1777 result = IDirectDrawSurface3_SetSurfaceDesc (dd_surface3, &ddsd, 0); | 1774 result = IDirectDrawSurface3_SetSurfaceDesc(dd_surface3, &ddsd, 0); |
1778 if (result != DD_OK) { | 1775 if (result != DD_OK) { |
1779 SetDDerror ("DirectDraw2::SetSurfaceDesc", result); | 1776 SetDDerror("DirectDraw2::SetSurfaceDesc", result); |
1780 goto error_end; | 1777 goto error_end; |
1781 } | 1778 } |
1782 | 1779 |
1783 } | 1780 } |
1784 | 1781 |
1785 /* Make sure the surface format was set properly */ | 1782 /* Make sure the surface format was set properly */ |
1786 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 1783 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
1787 ddsd.dwSize = sizeof (ddsd); | 1784 ddsd.dwSize = sizeof(ddsd); |
1788 result = IDirectDrawSurface3_Lock (dd_surface3, NULL, | 1785 result = IDirectDrawSurface3_Lock(dd_surface3, NULL, |
1789 &ddsd, | 1786 &ddsd, |
1790 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), | 1787 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), NULL); |
1791 NULL); | |
1792 if (result != DD_OK) { | 1788 if (result != DD_OK) { |
1793 SetDDerror ("DirectDrawSurface3::Lock", result); | 1789 SetDDerror("DirectDrawSurface3::Lock", result); |
1794 goto error_end; | 1790 goto error_end; |
1795 } | 1791 } |
1796 IDirectDrawSurface3_Unlock (dd_surface3, NULL); | 1792 IDirectDrawSurface3_Unlock(dd_surface3, NULL); |
1797 | 1793 |
1798 if ((flag & SDL_HWSURFACE) == SDL_SWSURFACE) { | 1794 if ((flag & SDL_HWSURFACE) == SDL_SWSURFACE) { |
1799 if (ddsd.lpSurface != surface->pixels) { | 1795 if (ddsd.lpSurface != surface->pixels) { |
1800 SDL_SetError ("DDraw didn't use SDL surface memory"); | 1796 SDL_SetError("DDraw didn't use SDL surface memory"); |
1801 goto error_end; | 1797 goto error_end; |
1802 } | 1798 } |
1803 if ( | 1799 if ( |
1804 #if defined(NONAMELESSUNION) | 1800 #if defined(NONAMELESSUNION) |
1805 ddsd.u1.lPitch | 1801 ddsd.u1.lPitch |
1806 #else | 1802 #else |
1807 ddsd.lPitch | 1803 ddsd.lPitch |
1808 #endif | 1804 #endif |
1809 != (LONG) surface->pitch) { | 1805 != (LONG) surface->pitch) { |
1810 SDL_SetError ("DDraw created surface with wrong pitch"); | 1806 SDL_SetError("DDraw created surface with wrong pitch"); |
1811 goto error_end; | 1807 goto error_end; |
1812 } | 1808 } |
1813 } else { | 1809 } else { |
1814 #if defined(NONAMELESSUNION) | 1810 #if defined(NONAMELESSUNION) |
1815 surface->pitch = (Uint16) ddsd.u1.lPitch; | 1811 surface->pitch = (Uint16) ddsd.u1.lPitch; |
1828 surface->format->BitsPerPixel) || | 1824 surface->format->BitsPerPixel) || |
1829 (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) || | 1825 (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) || |
1830 (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) || | 1826 (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) || |
1831 (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask)) { | 1827 (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask)) { |
1832 #endif | 1828 #endif |
1833 SDL_SetError ("DDraw didn't use SDL surface description"); | 1829 SDL_SetError("DDraw didn't use SDL surface description"); |
1834 goto error_end; | 1830 goto error_end; |
1835 } | 1831 } |
1836 if ((ddsd.dwWidth != (DWORD) surface->w) || | 1832 if ((ddsd.dwWidth != (DWORD) surface->w) || |
1837 (ddsd.dwHeight != (DWORD) surface->h)) { | 1833 (ddsd.dwHeight != (DWORD) surface->h)) { |
1838 SDL_SetError ("DDraw created surface with wrong size"); | 1834 SDL_SetError("DDraw created surface with wrong size"); |
1839 goto error_end; | 1835 goto error_end; |
1840 } | 1836 } |
1841 | 1837 |
1842 /* Set the surface private data */ | 1838 /* Set the surface private data */ |
1843 surface->flags |= flag; | 1839 surface->flags |= flag; |
1844 surface->hwdata->dd_surface = dd_surface3; | 1840 surface->hwdata->dd_surface = dd_surface3; |
1845 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { | 1841 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
1846 LPDIRECTDRAWSURFACE3 dd_writebuf; | 1842 LPDIRECTDRAWSURFACE3 dd_writebuf; |
1847 | 1843 |
1848 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; | 1844 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; |
1849 result = IDirectDrawSurface3_GetAttachedSurface (dd_surface3, | 1845 result = IDirectDrawSurface3_GetAttachedSurface(dd_surface3, |
1850 &ddsd.ddsCaps, | 1846 &ddsd.ddsCaps, |
1851 &dd_writebuf); | 1847 &dd_writebuf); |
1852 if (result != DD_OK) { | 1848 if (result != DD_OK) { |
1853 SetDDerror ("DirectDrawSurface3::GetAttachedSurface", result); | 1849 SetDDerror("DirectDrawSurface3::GetAttachedSurface", result); |
1854 } else { | 1850 } else { |
1855 dd_surface3 = dd_writebuf; | 1851 dd_surface3 = dd_writebuf; |
1856 } | 1852 } |
1857 } | 1853 } |
1858 surface->hwdata->dd_writebuf = dd_surface3; | 1854 surface->hwdata->dd_writebuf = dd_surface3; |
1865 every single case. Is there a better way, other than deeply | 1861 every single case. Is there a better way, other than deeply |
1866 nesting the code? | 1862 nesting the code? |
1867 */ | 1863 */ |
1868 error_end: | 1864 error_end: |
1869 if ((dd_surface3 != NULL) && (dd_surface3 != requested)) { | 1865 if ((dd_surface3 != NULL) && (dd_surface3 != requested)) { |
1870 IDirectDrawSurface_Release (dd_surface3); | 1866 IDirectDrawSurface_Release(dd_surface3); |
1871 } | 1867 } |
1872 SDL_free (surface->hwdata); | 1868 SDL_free(surface->hwdata); |
1873 surface->hwdata = NULL; | 1869 surface->hwdata = NULL; |
1874 return (-1); | 1870 return (-1); |
1875 } | 1871 } |
1876 | 1872 |
1877 static int | 1873 static int |
1878 DX5_AllocHWSurface (_THIS, SDL_Surface * surface) | 1874 DX5_AllocHWSurface(_THIS, SDL_Surface * surface) |
1879 { | 1875 { |
1880 /* DDraw limitation -- you need to set cooperative level first */ | 1876 /* DDraw limitation -- you need to set cooperative level first */ |
1881 if (SDL_primary == NULL) { | 1877 if (SDL_primary == NULL) { |
1882 SDL_SetError ("You must set a non-GL video mode first"); | 1878 SDL_SetError("You must set a non-GL video mode first"); |
1883 return (-1); | 1879 return (-1); |
1884 } | 1880 } |
1885 return (DX5_AllocDDSurface (this, surface, NULL, SDL_HWSURFACE)); | 1881 return (DX5_AllocDDSurface(this, surface, NULL, SDL_HWSURFACE)); |
1886 } | 1882 } |
1887 | 1883 |
1888 #ifdef DDRAW_DEBUG | 1884 #ifdef DDRAW_DEBUG |
1889 void | 1885 void |
1890 PrintSurface (char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags) | 1886 PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags) |
1891 { | 1887 { |
1892 DDSURFACEDESC ddsd; | 1888 DDSURFACEDESC ddsd; |
1893 | 1889 |
1894 /* Lock and load! */ | 1890 /* Lock and load! */ |
1895 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 1891 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
1896 ddsd.dwSize = sizeof (ddsd); | 1892 ddsd.dwSize = sizeof(ddsd); |
1897 if (IDirectDrawSurface3_Lock (surface, NULL, &ddsd, | 1893 if (IDirectDrawSurface3_Lock(surface, NULL, &ddsd, |
1898 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), | 1894 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), |
1899 NULL) != DD_OK) { | 1895 NULL) != DD_OK) { |
1900 return; | 1896 return; |
1901 } | 1897 } |
1902 IDirectDrawSurface3_Unlock (surface, NULL); | 1898 IDirectDrawSurface3_Unlock(surface, NULL); |
1903 | 1899 |
1904 fprintf (stderr, "%s:\n", title); | 1900 fprintf(stderr, "%s:\n", title); |
1905 fprintf (stderr, "\tSize: %dx%d in %s at %ld bpp (pitch = %ld)\n", | 1901 fprintf(stderr, "\tSize: %dx%d in %s at %ld bpp (pitch = %ld)\n", |
1906 ddsd.dwWidth, ddsd.dwHeight, | 1902 ddsd.dwWidth, ddsd.dwHeight, |
1907 (flags & SDL_HWSURFACE) ? "hardware" : "software", | 1903 (flags & SDL_HWSURFACE) ? "hardware" : "software", |
1908 #if defined(NONAMELESSUNION) | 1904 #if defined(NONAMELESSUNION) |
1909 ddsd.ddpfPixelFormat.u1.dwRGBBitCount, ddsd.u1.lPitch); | 1905 ddsd.ddpfPixelFormat.u1.dwRGBBitCount, ddsd.u1.lPitch); |
1910 #else | 1906 #else |
1911 ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.lPitch); | 1907 ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.lPitch); |
1912 #endif | 1908 #endif |
1913 fprintf (stderr, "\tR = 0x%X, G = 0x%X, B = 0x%X\n", | 1909 fprintf(stderr, "\tR = 0x%X, G = 0x%X, B = 0x%X\n", |
1914 #if defined(NONAMELESSUNION) | 1910 #if defined(NONAMELESSUNION) |
1915 ddsd.ddpfPixelFormat.u2.dwRBitMask, | 1911 ddsd.ddpfPixelFormat.u2.dwRBitMask, |
1916 ddsd.ddpfPixelFormat.u3.dwGBitMask, | 1912 ddsd.ddpfPixelFormat.u3.dwGBitMask, |
1917 ddsd.ddpfPixelFormat.u4.dwBBitMask); | 1913 ddsd.ddpfPixelFormat.u4.dwBBitMask); |
1918 #else | 1914 #else |
1919 ddsd.ddpfPixelFormat.dwRBitMask, | 1915 ddsd.ddpfPixelFormat.dwRBitMask, |
1920 ddsd.ddpfPixelFormat.dwGBitMask, | 1916 ddsd.ddpfPixelFormat.dwGBitMask, ddsd.ddpfPixelFormat.dwBBitMask); |
1921 ddsd.ddpfPixelFormat.dwBBitMask); | |
1922 #endif | 1917 #endif |
1923 } | 1918 } |
1924 #endif /* DDRAW_DEBUG */ | 1919 #endif /* DDRAW_DEBUG */ |
1925 | 1920 |
1926 static int | 1921 static int |
1927 DX5_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, | 1922 DX5_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect, |
1928 SDL_Surface * dst, SDL_Rect * dstrect) | 1923 SDL_Surface * dst, SDL_Rect * dstrect) |
1929 { | 1924 { |
1930 LPDIRECTDRAWSURFACE3 src_surface; | 1925 LPDIRECTDRAWSURFACE3 src_surface; |
1931 LPDIRECTDRAWSURFACE3 dst_surface; | 1926 LPDIRECTDRAWSURFACE3 dst_surface; |
1932 DWORD flags; | 1927 DWORD flags; |
1933 RECT rect; | 1928 RECT rect; |
1948 but it will affect the return values of locks and flips. | 1943 but it will affect the return values of locks and flips. |
1949 */ | 1944 */ |
1950 flags |= DDBLTFAST_WAIT; | 1945 flags |= DDBLTFAST_WAIT; |
1951 | 1946 |
1952 /* Do the blit! */ | 1947 /* Do the blit! */ |
1953 result = IDirectDrawSurface3_BltFast (dst_surface, | 1948 result = IDirectDrawSurface3_BltFast(dst_surface, |
1954 dstrect->x, dstrect->y, src_surface, | 1949 dstrect->x, dstrect->y, src_surface, |
1955 &rect, flags); | 1950 &rect, flags); |
1956 if (result != DD_OK) { | 1951 if (result != DD_OK) { |
1957 if (result == DDERR_SURFACELOST) { | 1952 if (result == DDERR_SURFACELOST) { |
1958 result = IDirectDrawSurface3_Restore (src_surface); | 1953 result = IDirectDrawSurface3_Restore(src_surface); |
1959 result = IDirectDrawSurface3_Restore (dst_surface); | 1954 result = IDirectDrawSurface3_Restore(dst_surface); |
1960 /* The surfaces need to be reloaded with artwork */ | 1955 /* The surfaces need to be reloaded with artwork */ |
1961 SDL_SetError ("Blit surfaces were lost, reload them"); | 1956 SDL_SetError("Blit surfaces were lost, reload them"); |
1962 return (-2); | 1957 return (-2); |
1963 } | 1958 } |
1964 SetDDerror ("IDirectDrawSurface3::BltFast", result); | 1959 SetDDerror("IDirectDrawSurface3::BltFast", result); |
1965 #ifdef DDRAW_DEBUG | 1960 #ifdef DDRAW_DEBUG |
1966 fprintf (stderr, "Original dest rect: %dx%d at %d,%d\n", dstrect->w, | 1961 fprintf(stderr, "Original dest rect: %dx%d at %d,%d\n", dstrect->w, |
1967 dstrect->h, dstrect->x, dstrect->y); | 1962 dstrect->h, dstrect->x, dstrect->y); |
1968 fprintf (stderr, | 1963 fprintf(stderr, |
1969 "HW accelerated %sblit to from 0x%p to 0x%p at (%d,%d)\n", | 1964 "HW accelerated %sblit to from 0x%p to 0x%p at (%d,%d)\n", |
1970 (src->flags & SDL_SRCCOLORKEY) ? "colorkey " : "", src, | 1965 (src->flags & SDL_SRCCOLORKEY) ? "colorkey " : "", src, |
1971 dst, dstrect->x, dstrect->y); | 1966 dst, dstrect->x, dstrect->y); |
1972 PrintSurface ("SRC", src_surface, src->flags); | 1967 PrintSurface("SRC", src_surface, src->flags); |
1973 PrintSurface ("DST", dst_surface, dst->flags); | 1968 PrintSurface("DST", dst_surface, dst->flags); |
1974 fprintf (stderr, "Source rectangle: (%d,%d) - (%d,%d)\n", | 1969 fprintf(stderr, "Source rectangle: (%d,%d) - (%d,%d)\n", |
1975 rect.left, rect.top, rect.right, rect.bottom); | 1970 rect.left, rect.top, rect.right, rect.bottom); |
1976 #endif | 1971 #endif |
1977 /* Unexpected error, fall back to software blit */ | 1972 /* Unexpected error, fall back to software blit */ |
1978 return (src->map->sw_blit (src, srcrect, dst, dstrect)); | 1973 return (src->map->sw_blit(src, srcrect, dst, dstrect)); |
1979 } | 1974 } |
1980 return (0); | 1975 return (0); |
1981 } | 1976 } |
1982 | 1977 |
1983 static int | 1978 static int |
1984 DX5_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst) | 1979 DX5_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst) |
1985 { | 1980 { |
1986 int accelerated; | 1981 int accelerated; |
1987 | 1982 |
1988 /* We need to have a DDraw surface for HW blits */ | 1983 /* We need to have a DDraw surface for HW blits */ |
1989 if ((src->flags & SDL_HWSURFACE) == SDL_SWSURFACE) { | 1984 if ((src->flags & SDL_HWSURFACE) == SDL_SWSURFACE) { |
1990 /* Allocate a DDraw surface for the blit */ | 1985 /* Allocate a DDraw surface for the blit */ |
1991 if (src->hwdata == NULL) { | 1986 if (src->hwdata == NULL) { |
1992 DX5_AllocDDSurface (this, src, NULL, SDL_SWSURFACE); | 1987 DX5_AllocDDSurface(this, src, NULL, SDL_SWSURFACE); |
1993 } | 1988 } |
1994 } | 1989 } |
1995 if (src->hwdata == NULL) { | 1990 if (src->hwdata == NULL) { |
1996 return (0); | 1991 return (0); |
1997 } | 1992 } |
1999 /* Set initial acceleration on */ | 1994 /* Set initial acceleration on */ |
2000 src->flags |= SDL_HWACCEL; | 1995 src->flags |= SDL_HWACCEL; |
2001 | 1996 |
2002 /* Set the surface attributes */ | 1997 /* Set the surface attributes */ |
2003 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { | 1998 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { |
2004 if (DX5_SetHWColorKey (this, src, src->format->colorkey) < 0) { | 1999 if (DX5_SetHWColorKey(this, src, src->format->colorkey) < 0) { |
2005 src->flags &= ~SDL_HWACCEL; | 2000 src->flags &= ~SDL_HWACCEL; |
2006 } | 2001 } |
2007 } | 2002 } |
2008 if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) { | 2003 if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) { |
2009 if (DX5_SetHWAlpha (this, src, src->format->alpha) < 0) { | 2004 if (DX5_SetHWAlpha(this, src, src->format->alpha) < 0) { |
2010 src->flags &= ~SDL_HWACCEL; | 2005 src->flags &= ~SDL_HWACCEL; |
2011 } | 2006 } |
2012 } | 2007 } |
2013 | 2008 |
2014 /* Check to see if final surface blit is accelerated */ | 2009 /* Check to see if final surface blit is accelerated */ |
2015 accelerated = !!(src->flags & SDL_HWACCEL); | 2010 accelerated = !!(src->flags & SDL_HWACCEL); |
2016 if (accelerated) { | 2011 if (accelerated) { |
2017 #ifdef DDRAW_DEBUG | 2012 #ifdef DDRAW_DEBUG |
2018 fprintf (stderr, "Setting accelerated blit on 0x%p\n", src); | 2013 fprintf(stderr, "Setting accelerated blit on 0x%p\n", src); |
2019 #endif | 2014 #endif |
2020 src->map->hw_blit = DX5_HWAccelBlit; | 2015 src->map->hw_blit = DX5_HWAccelBlit; |
2021 } | 2016 } |
2022 return (accelerated); | 2017 return (accelerated); |
2023 } | 2018 } |
2024 | 2019 |
2025 static int | 2020 static int |
2026 DX5_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) | 2021 DX5_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) |
2027 { | 2022 { |
2028 LPDIRECTDRAWSURFACE3 dst_surface; | 2023 LPDIRECTDRAWSURFACE3 dst_surface; |
2029 RECT area; | 2024 RECT area; |
2030 DDBLTFX bltfx; | 2025 DDBLTFX bltfx; |
2031 HRESULT result; | 2026 HRESULT result; |
2032 | 2027 |
2033 #ifdef DDRAW_DEBUG | 2028 #ifdef DDRAW_DEBUG |
2034 fprintf (stderr, "HW accelerated fill at (%d,%d)\n", dstrect->x, | 2029 fprintf(stderr, "HW accelerated fill at (%d,%d)\n", dstrect->x, |
2035 dstrect->y); | 2030 dstrect->y); |
2036 #endif | 2031 #endif |
2037 dst_surface = dst->hwdata->dd_writebuf; | 2032 dst_surface = dst->hwdata->dd_writebuf; |
2038 area.top = (LONG) dstrect->y; | 2033 area.top = (LONG) dstrect->y; |
2039 area.bottom = (LONG) dstrect->y + dstrect->h; | 2034 area.bottom = (LONG) dstrect->y + dstrect->h; |
2040 area.left = (LONG) dstrect->x; | 2035 area.left = (LONG) dstrect->x; |
2041 area.right = (LONG) dstrect->x + dstrect->w; | 2036 area.right = (LONG) dstrect->x + dstrect->w; |
2042 bltfx.dwSize = sizeof (bltfx); | 2037 bltfx.dwSize = sizeof(bltfx); |
2043 #if defined(NONAMELESSUNION) | 2038 #if defined(NONAMELESSUNION) |
2044 bltfx.u5.dwFillColor = color; | 2039 bltfx.u5.dwFillColor = color; |
2045 #else | 2040 #else |
2046 bltfx.dwFillColor = color; | 2041 bltfx.dwFillColor = color; |
2047 #endif | 2042 #endif |
2048 result = IDirectDrawSurface3_Blt (dst_surface, | 2043 result = IDirectDrawSurface3_Blt(dst_surface, |
2049 &area, NULL, NULL, | 2044 &area, NULL, NULL, |
2050 DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); | 2045 DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); |
2051 if (result == DDERR_SURFACELOST) { | 2046 if (result == DDERR_SURFACELOST) { |
2052 IDirectDrawSurface3_Restore (dst_surface); | 2047 IDirectDrawSurface3_Restore(dst_surface); |
2053 result = IDirectDrawSurface3_Blt (dst_surface, | 2048 result = IDirectDrawSurface3_Blt(dst_surface, |
2054 &area, NULL, NULL, | 2049 &area, NULL, NULL, |
2055 DDBLT_COLORFILL | DDBLT_WAIT, | 2050 DDBLT_COLORFILL | DDBLT_WAIT, |
2056 &bltfx); | 2051 &bltfx); |
2057 } | 2052 } |
2058 if (result != DD_OK) { | 2053 if (result != DD_OK) { |
2059 SetDDerror ("IDirectDrawSurface3::Blt", result); | 2054 SetDDerror("IDirectDrawSurface3::Blt", result); |
2060 return (-1); | 2055 return (-1); |
2061 } | 2056 } |
2062 return (0); | 2057 return (0); |
2063 } | 2058 } |
2064 | 2059 |
2065 static int | 2060 static int |
2066 DX5_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key) | 2061 DX5_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key) |
2067 { | 2062 { |
2068 DDCOLORKEY colorkey; | 2063 DDCOLORKEY colorkey; |
2069 HRESULT result; | 2064 HRESULT result; |
2070 | 2065 |
2071 /* Set the surface colorkey */ | 2066 /* Set the surface colorkey */ |
2072 colorkey.dwColorSpaceLowValue = key; | 2067 colorkey.dwColorSpaceLowValue = key; |
2073 colorkey.dwColorSpaceHighValue = key; | 2068 colorkey.dwColorSpaceHighValue = key; |
2074 result = | 2069 result = |
2075 IDirectDrawSurface3_SetColorKey (surface->hwdata->dd_surface, | 2070 IDirectDrawSurface3_SetColorKey(surface->hwdata->dd_surface, |
2076 DDCKEY_SRCBLT, &colorkey); | 2071 DDCKEY_SRCBLT, &colorkey); |
2077 if (result != DD_OK) { | 2072 if (result != DD_OK) { |
2078 SetDDerror ("IDirectDrawSurface3::SetColorKey", result); | 2073 SetDDerror("IDirectDrawSurface3::SetColorKey", result); |
2079 return (-1); | 2074 return (-1); |
2080 } | 2075 } |
2081 return (0); | 2076 return (0); |
2082 } | 2077 } |
2083 static int | 2078 static int |
2084 DX5_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha) | 2079 DX5_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha) |
2085 { | 2080 { |
2086 return (-1); | 2081 return (-1); |
2087 } | 2082 } |
2088 | 2083 |
2089 static int | 2084 static int |
2090 DX5_LockHWSurface (_THIS, SDL_Surface * surface) | 2085 DX5_LockHWSurface(_THIS, SDL_Surface * surface) |
2091 { | 2086 { |
2092 HRESULT result; | 2087 HRESULT result; |
2093 LPDIRECTDRAWSURFACE3 dd_surface; | 2088 LPDIRECTDRAWSURFACE3 dd_surface; |
2094 DDSURFACEDESC ddsd; | 2089 DDSURFACEDESC ddsd; |
2095 | 2090 |
2096 /* Lock and load! */ | 2091 /* Lock and load! */ |
2097 dd_surface = surface->hwdata->dd_writebuf; | 2092 dd_surface = surface->hwdata->dd_writebuf; |
2098 SDL_memset (&ddsd, 0, sizeof (ddsd)); | 2093 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
2099 ddsd.dwSize = sizeof (ddsd); | 2094 ddsd.dwSize = sizeof(ddsd); |
2100 result = IDirectDrawSurface3_Lock (dd_surface, NULL, &ddsd, | 2095 result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd, |
2101 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), | 2096 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), NULL); |
2102 NULL); | |
2103 if (result == DDERR_SURFACELOST) { | 2097 if (result == DDERR_SURFACELOST) { |
2104 result = IDirectDrawSurface3_Restore (surface->hwdata->dd_surface); | 2098 result = IDirectDrawSurface3_Restore(surface->hwdata->dd_surface); |
2105 result = IDirectDrawSurface3_Lock (dd_surface, NULL, &ddsd, | 2099 result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd, |
2106 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), | 2100 (DDLOCK_NOSYSLOCK | DDLOCK_WAIT), |
2107 NULL); | 2101 NULL); |
2108 } | 2102 } |
2109 if (result != DD_OK) { | 2103 if (result != DD_OK) { |
2110 SetDDerror ("DirectDrawSurface3::Lock", result); | 2104 SetDDerror("DirectDrawSurface3::Lock", result); |
2111 return (-1); | 2105 return (-1); |
2112 } | 2106 } |
2113 /* Pitch might have changed -- recalculate pitch and offset */ | 2107 /* Pitch might have changed -- recalculate pitch and offset */ |
2114 #if defined(NONAMELESSUNION) | 2108 #if defined(NONAMELESSUNION) |
2115 if (surface->pitch != ddsd.u1.lPitch) { | 2109 if (surface->pitch != ddsd.u1.lPitch) { |
2126 surface->pixels = ddsd.lpSurface; | 2120 surface->pixels = ddsd.lpSurface; |
2127 return (0); | 2121 return (0); |
2128 } | 2122 } |
2129 | 2123 |
2130 static void | 2124 static void |
2131 DX5_UnlockHWSurface (_THIS, SDL_Surface * surface) | 2125 DX5_UnlockHWSurface(_THIS, SDL_Surface * surface) |
2132 { | 2126 { |
2133 IDirectDrawSurface3_Unlock (surface->hwdata->dd_writebuf, NULL); | 2127 IDirectDrawSurface3_Unlock(surface->hwdata->dd_writebuf, NULL); |
2134 surface->pixels = NULL; | 2128 surface->pixels = NULL; |
2135 } | 2129 } |
2136 | 2130 |
2137 static int | 2131 static int |
2138 DX5_FlipHWSurface (_THIS, SDL_Surface * surface) | 2132 DX5_FlipHWSurface(_THIS, SDL_Surface * surface) |
2139 { | 2133 { |
2140 HRESULT result; | 2134 HRESULT result; |
2141 LPDIRECTDRAWSURFACE3 dd_surface; | 2135 LPDIRECTDRAWSURFACE3 dd_surface; |
2142 | 2136 |
2143 dd_surface = surface->hwdata->dd_surface; | 2137 dd_surface = surface->hwdata->dd_surface; |
2144 | 2138 |
2145 /* to prevent big slowdown on fast computers, wait here instead of driver ring 0 code */ | 2139 /* to prevent big slowdown on fast computers, wait here instead of driver ring 0 code */ |
2146 /* Dmitry Yakimov (ftech@tula.net) */ | 2140 /* Dmitry Yakimov (ftech@tula.net) */ |
2147 while (IDirectDrawSurface3_GetFlipStatus (dd_surface, DDGBS_ISBLTDONE) == | 2141 while (IDirectDrawSurface3_GetFlipStatus(dd_surface, DDGBS_ISBLTDONE) == |
2148 DDERR_WASSTILLDRAWING); | 2142 DDERR_WASSTILLDRAWING); |
2149 | 2143 |
2150 result = IDirectDrawSurface3_Flip (dd_surface, NULL, DDFLIP_WAIT); | 2144 result = IDirectDrawSurface3_Flip(dd_surface, NULL, DDFLIP_WAIT); |
2151 if (result == DDERR_SURFACELOST) { | 2145 if (result == DDERR_SURFACELOST) { |
2152 result = IDirectDrawSurface3_Restore (surface->hwdata->dd_surface); | 2146 result = IDirectDrawSurface3_Restore(surface->hwdata->dd_surface); |
2153 while (IDirectDrawSurface3_GetFlipStatus | 2147 while (IDirectDrawSurface3_GetFlipStatus |
2154 (dd_surface, DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING); | 2148 (dd_surface, DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING); |
2155 result = IDirectDrawSurface3_Flip (dd_surface, NULL, DDFLIP_WAIT); | 2149 result = IDirectDrawSurface3_Flip(dd_surface, NULL, DDFLIP_WAIT); |
2156 } | 2150 } |
2157 if (result != DD_OK) { | 2151 if (result != DD_OK) { |
2158 SetDDerror ("DirectDrawSurface3::Flip", result); | 2152 SetDDerror("DirectDrawSurface3::Flip", result); |
2159 return (-1); | 2153 return (-1); |
2160 } | 2154 } |
2161 return (0); | 2155 return (0); |
2162 } | 2156 } |
2163 | 2157 |
2164 static void | 2158 static void |
2165 DX5_FreeHWSurface (_THIS, SDL_Surface * surface) | 2159 DX5_FreeHWSurface(_THIS, SDL_Surface * surface) |
2166 { | 2160 { |
2167 if (surface->hwdata) { | 2161 if (surface->hwdata) { |
2168 if (surface->hwdata->dd_surface != SDL_primary) { | 2162 if (surface->hwdata->dd_surface != SDL_primary) { |
2169 IDirectDrawSurface3_Release (surface->hwdata->dd_surface); | 2163 IDirectDrawSurface3_Release(surface->hwdata->dd_surface); |
2170 } | 2164 } |
2171 SDL_free (surface->hwdata); | 2165 SDL_free(surface->hwdata); |
2172 surface->hwdata = NULL; | 2166 surface->hwdata = NULL; |
2173 } | 2167 } |
2174 } | 2168 } |
2175 | 2169 |
2176 void | 2170 void |
2177 DX5_WindowUpdate (_THIS, int numrects, SDL_Rect * rects) | 2171 DX5_WindowUpdate(_THIS, int numrects, SDL_Rect * rects) |
2178 { | 2172 { |
2179 HRESULT result; | 2173 HRESULT result; |
2180 int i; | 2174 int i; |
2181 RECT src, dst; | 2175 RECT src, dst; |
2182 | 2176 |
2187 src.right = (LONG) rects[i].x + rects[i].w; | 2181 src.right = (LONG) rects[i].x + rects[i].w; |
2188 dst.top = SDL_bounds.top + src.top; | 2182 dst.top = SDL_bounds.top + src.top; |
2189 dst.left = SDL_bounds.left + src.left; | 2183 dst.left = SDL_bounds.left + src.left; |
2190 dst.bottom = SDL_bounds.top + src.bottom; | 2184 dst.bottom = SDL_bounds.top + src.bottom; |
2191 dst.right = SDL_bounds.left + src.right; | 2185 dst.right = SDL_bounds.left + src.right; |
2192 result = IDirectDrawSurface3_Blt (SDL_primary, &dst, | 2186 result = IDirectDrawSurface3_Blt(SDL_primary, &dst, |
2193 this->screen->hwdata->dd_surface, | 2187 this->screen->hwdata->dd_surface, |
2194 &src, DDBLT_WAIT, NULL); | 2188 &src, DDBLT_WAIT, NULL); |
2195 /* Doh! Check for lost surface and restore it */ | 2189 /* Doh! Check for lost surface and restore it */ |
2196 if (result == DDERR_SURFACELOST) { | 2190 if (result == DDERR_SURFACELOST) { |
2197 IDirectDrawSurface3_Restore (SDL_primary); | 2191 IDirectDrawSurface3_Restore(SDL_primary); |
2198 IDirectDrawSurface3_Blt (SDL_primary, &dst, | 2192 IDirectDrawSurface3_Blt(SDL_primary, &dst, |
2199 this->screen->hwdata->dd_surface, | 2193 this->screen->hwdata->dd_surface, |
2200 &src, DDBLT_WAIT, NULL); | 2194 &src, DDBLT_WAIT, NULL); |
2201 } | 2195 } |
2202 } | 2196 } |
2203 } | 2197 } |
2204 | 2198 |
2205 void | 2199 void |
2206 DX5_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) | 2200 DX5_DirectUpdate(_THIS, int numrects, SDL_Rect * rects) |
2207 { | 2201 { |
2208 } | 2202 } |
2209 | 2203 |
2210 /* Compress a full palette into the limited number of colors given to us | 2204 /* Compress a full palette into the limited number of colors given to us |
2211 by windows. | 2205 by windows. |
2232 int g = (A.g - B.g); \ | 2226 int g = (A.g - B.g); \ |
2233 int b = (A.b - B.b); \ | 2227 int b = (A.b - B.b); \ |
2234 (r*r + g*g + b*b); \ | 2228 (r*r + g*g + b*b); \ |
2235 }) | 2229 }) |
2236 static void | 2230 static void |
2237 DX5_CompressPalette (_THIS, SDL_Color * colors, int ncolors, int maxcolors) | 2231 DX5_CompressPalette(_THIS, SDL_Color * colors, int ncolors, int maxcolors) |
2238 { | 2232 { |
2239 #ifdef SIMPLE_COMPRESSION | 2233 #ifdef SIMPLE_COMPRESSION |
2240 int i, j; | 2234 int i, j; |
2241 #else | 2235 #else |
2242 static SDL_Color zero = { 0, 0, 0, 0 }; | 2236 static SDL_Color zero = { 0, 0, 0, 0 }; |
2258 SDL_colors[j].peGreen = colors[i].g; | 2252 SDL_colors[j].peGreen = colors[i].g; |
2259 SDL_colors[j].peBlue = colors[i].b; | 2253 SDL_colors[j].peBlue = colors[i].b; |
2260 } | 2254 } |
2261 #else | 2255 #else |
2262 /* Allocate memory for the arrays we use */ | 2256 /* Allocate memory for the arrays we use */ |
2263 pool = SDL_stack_alloc (int, 2 * ncolors); | 2257 pool = SDL_stack_alloc(int, 2 * ncolors); |
2264 if (pool == NULL) { | 2258 if (pool == NULL) { |
2265 /* No worries, just return */ ; | 2259 /* No worries, just return */ ; |
2266 return; | 2260 return; |
2267 } | 2261 } |
2268 seen = pool; | 2262 seen = pool; |
2269 SDL_memset (seen, 0, ncolors * sizeof (int)); | 2263 SDL_memset(seen, 0, ncolors * sizeof(int)); |
2270 order = pool + ncolors; | 2264 order = pool + ncolors; |
2271 | 2265 |
2272 /* Start with the brightest color */ | 2266 /* Start with the brightest color */ |
2273 max = 0; | 2267 max = 0; |
2274 for (i = 0; i < ncolors; ++i) { | 2268 for (i = 0; i < ncolors; ++i) { |
2275 dist = CS_CS_DIST (zero, colors[i]); | 2269 dist = CS_CS_DIST(zero, colors[i]); |
2276 if (dist >= max) { | 2270 if (dist >= max) { |
2277 max = dist; | 2271 max = dist; |
2278 next = i; | 2272 next = i; |
2279 } | 2273 } |
2280 } | 2274 } |
2288 max = 0; | 2282 max = 0; |
2289 for (i = 0; i < ncolors; ++i) { | 2283 for (i = 0; i < ncolors; ++i) { |
2290 if (seen[i]) { | 2284 if (seen[i]) { |
2291 continue; | 2285 continue; |
2292 } | 2286 } |
2293 dist = CS_CS_DIST (colors[i], colors[prev]); | 2287 dist = CS_CS_DIST(colors[i], colors[prev]); |
2294 if (dist >= max) { | 2288 if (dist >= max) { |
2295 max = dist; | 2289 max = dist; |
2296 next = i; | 2290 next = i; |
2297 } | 2291 } |
2298 } | 2292 } |
2305 for (j = 10, i = 0; i < maxcolors; ++i, ++j) { | 2299 for (j = 10, i = 0; i < maxcolors; ++i, ++j) { |
2306 SDL_colors[j].peRed = colors[order[i]].r; | 2300 SDL_colors[j].peRed = colors[order[i]].r; |
2307 SDL_colors[j].peGreen = colors[order[i]].g; | 2301 SDL_colors[j].peGreen = colors[order[i]].g; |
2308 SDL_colors[j].peBlue = colors[order[i]].b; | 2302 SDL_colors[j].peBlue = colors[order[i]].b; |
2309 } | 2303 } |
2310 SDL_stack_free (pool); | 2304 SDL_stack_free(pool); |
2311 #endif /* SIMPLE_COMPRESSION */ | 2305 #endif /* SIMPLE_COMPRESSION */ |
2312 } | 2306 } |
2313 | 2307 |
2314 /* Set the system colormap in both fullscreen and windowed modes */ | 2308 /* Set the system colormap in both fullscreen and windowed modes */ |
2315 int | 2309 int |
2316 DX5_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 2310 DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
2317 { | 2311 { |
2318 int i; | 2312 int i; |
2319 int alloct_all; | 2313 int alloct_all; |
2320 | 2314 |
2321 /* Copy palette colors into display palette */ | 2315 /* Copy palette colors into display palette */ |
2327 int j = firstcolor + i; | 2321 int j = firstcolor + i; |
2328 SDL_colors[j].peRed = colors[i].r; | 2322 SDL_colors[j].peRed = colors[i].r; |
2329 SDL_colors[j].peGreen = colors[i].g; | 2323 SDL_colors[j].peGreen = colors[i].g; |
2330 SDL_colors[j].peBlue = colors[i].b; | 2324 SDL_colors[j].peBlue = colors[i].b; |
2331 } | 2325 } |
2332 IDirectDrawPalette_SetEntries (SDL_palette, 0, | 2326 IDirectDrawPalette_SetEntries(SDL_palette, 0, |
2333 firstcolor, ncolors, | 2327 firstcolor, ncolors, |
2334 &SDL_colors[firstcolor]); | 2328 &SDL_colors[firstcolor]); |
2335 alloct_all = 1; | 2329 alloct_all = 1; |
2336 } else { | 2330 } else { |
2337 /* Grab the 236 most diverse colors in the palette */ | 2331 /* Grab the 236 most diverse colors in the palette */ |
2338 DX5_CompressPalette (this, colors, ncolors, 236); | 2332 DX5_CompressPalette(this, colors, ncolors, 236); |
2339 /* This sends an WM_PALETTECHANGED message to us */ | 2333 /* This sends an WM_PALETTECHANGED message to us */ |
2340 colorchange_expected = 1; | 2334 colorchange_expected = 1; |
2341 IDirectDrawPalette_SetEntries (SDL_palette, 0, | 2335 IDirectDrawPalette_SetEntries(SDL_palette, 0, 0, 256, SDL_colors); |
2342 0, 256, SDL_colors); | |
2343 } | 2336 } |
2344 } | 2337 } |
2345 return (alloct_all); | 2338 return (alloct_all); |
2346 } | 2339 } |
2347 | 2340 |
2348 /* Gamma code is only available on DirectX 7 and newer */ | 2341 /* Gamma code is only available on DirectX 7 and newer */ |
2349 static int | 2342 static int |
2350 DX5_SetGammaRamp (_THIS, Uint16 * ramp) | 2343 DX5_SetGammaRamp(_THIS, Uint16 * ramp) |
2351 { | 2344 { |
2352 #ifdef IDirectDrawGammaControl_SetGammaRamp | 2345 #ifdef IDirectDrawGammaControl_SetGammaRamp |
2353 LPDIRECTDRAWGAMMACONTROL gamma; | 2346 LPDIRECTDRAWGAMMACONTROL gamma; |
2354 DDGAMMARAMP gamma_ramp; | 2347 DDGAMMARAMP gamma_ramp; |
2355 HRESULT result; | 2348 HRESULT result; |
2356 #endif | 2349 #endif |
2357 | 2350 |
2358 /* In windowed or OpenGL mode, use windib gamma code */ | 2351 /* In windowed or OpenGL mode, use windib gamma code */ |
2359 if (!DDRAW_FULLSCREEN ()) { | 2352 if (!DDRAW_FULLSCREEN()) { |
2360 return DIB_SetGammaRamp (this, ramp); | 2353 return DIB_SetGammaRamp(this, ramp); |
2361 } | 2354 } |
2362 #ifndef IDirectDrawGammaControl_SetGammaRamp | 2355 #ifndef IDirectDrawGammaControl_SetGammaRamp |
2363 SDL_SetError ("SDL compiled without DirectX gamma ramp support"); | 2356 SDL_SetError("SDL compiled without DirectX gamma ramp support"); |
2364 return -1; | 2357 return -1; |
2365 #else | 2358 #else |
2366 /* Check for a video mode! */ | 2359 /* Check for a video mode! */ |
2367 if (!SDL_primary) { | 2360 if (!SDL_primary) { |
2368 SDL_SetError ("A video mode must be set for gamma correction"); | 2361 SDL_SetError("A video mode must be set for gamma correction"); |
2369 return (-1); | 2362 return (-1); |
2370 } | 2363 } |
2371 | 2364 |
2372 /* Get the gamma control object */ | 2365 /* Get the gamma control object */ |
2373 result = IDirectDrawSurface3_QueryInterface (SDL_primary, | 2366 result = IDirectDrawSurface3_QueryInterface(SDL_primary, |
2374 &IID_IDirectDrawGammaControl, | 2367 &IID_IDirectDrawGammaControl, |
2375 (LPVOID *) & gamma); | 2368 (LPVOID *) & gamma); |
2376 if (result != DD_OK) { | 2369 if (result != DD_OK) { |
2377 SetDDerror ("DirectDrawSurface3::QueryInterface(GAMMA)", result); | 2370 SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result); |
2378 return (-1); | 2371 return (-1); |
2379 } | 2372 } |
2380 | 2373 |
2381 /* Set up the gamma ramp */ | 2374 /* Set up the gamma ramp */ |
2382 SDL_memcpy (gamma_ramp.red, &ramp[0 * 256], 256 * sizeof (*ramp)); | 2375 SDL_memcpy(gamma_ramp.red, &ramp[0 * 256], 256 * sizeof(*ramp)); |
2383 SDL_memcpy (gamma_ramp.green, &ramp[1 * 256], 256 * sizeof (*ramp)); | 2376 SDL_memcpy(gamma_ramp.green, &ramp[1 * 256], 256 * sizeof(*ramp)); |
2384 SDL_memcpy (gamma_ramp.blue, &ramp[2 * 256], 256 * sizeof (*ramp)); | 2377 SDL_memcpy(gamma_ramp.blue, &ramp[2 * 256], 256 * sizeof(*ramp)); |
2385 result = IDirectDrawGammaControl_SetGammaRamp (gamma, 0, &gamma_ramp); | 2378 result = IDirectDrawGammaControl_SetGammaRamp(gamma, 0, &gamma_ramp); |
2386 if (result != DD_OK) { | 2379 if (result != DD_OK) { |
2387 SetDDerror ("DirectDrawGammaControl::SetGammaRamp()", result); | 2380 SetDDerror("DirectDrawGammaControl::SetGammaRamp()", result); |
2388 } | 2381 } |
2389 | 2382 |
2390 /* Release the interface and return */ | 2383 /* Release the interface and return */ |
2391 IDirectDrawGammaControl_Release (gamma); | 2384 IDirectDrawGammaControl_Release(gamma); |
2392 return (result == DD_OK) ? 0 : -1; | 2385 return (result == DD_OK) ? 0 : -1; |
2393 #endif /* !IDirectDrawGammaControl_SetGammaRamp */ | 2386 #endif /* !IDirectDrawGammaControl_SetGammaRamp */ |
2394 } | 2387 } |
2395 | 2388 |
2396 static int | 2389 static int |
2397 DX5_GetGammaRamp (_THIS, Uint16 * ramp) | 2390 DX5_GetGammaRamp(_THIS, Uint16 * ramp) |
2398 { | 2391 { |
2399 #ifdef IDirectDrawGammaControl_SetGammaRamp | 2392 #ifdef IDirectDrawGammaControl_SetGammaRamp |
2400 LPDIRECTDRAWGAMMACONTROL gamma; | 2393 LPDIRECTDRAWGAMMACONTROL gamma; |
2401 DDGAMMARAMP gamma_ramp; | 2394 DDGAMMARAMP gamma_ramp; |
2402 HRESULT result; | 2395 HRESULT result; |
2403 #endif | 2396 #endif |
2404 | 2397 |
2405 /* In windowed or OpenGL mode, use windib gamma code */ | 2398 /* In windowed or OpenGL mode, use windib gamma code */ |
2406 if (!DDRAW_FULLSCREEN ()) { | 2399 if (!DDRAW_FULLSCREEN()) { |
2407 return DIB_GetGammaRamp (this, ramp); | 2400 return DIB_GetGammaRamp(this, ramp); |
2408 } | 2401 } |
2409 #ifndef IDirectDrawGammaControl_SetGammaRamp | 2402 #ifndef IDirectDrawGammaControl_SetGammaRamp |
2410 SDL_SetError ("SDL compiled without DirectX gamma ramp support"); | 2403 SDL_SetError("SDL compiled without DirectX gamma ramp support"); |
2411 return -1; | 2404 return -1; |
2412 #else | 2405 #else |
2413 /* Check for a video mode! */ | 2406 /* Check for a video mode! */ |
2414 if (!SDL_primary) { | 2407 if (!SDL_primary) { |
2415 SDL_SetError ("A video mode must be set for gamma correction"); | 2408 SDL_SetError("A video mode must be set for gamma correction"); |
2416 return (-1); | 2409 return (-1); |
2417 } | 2410 } |
2418 | 2411 |
2419 /* Get the gamma control object */ | 2412 /* Get the gamma control object */ |
2420 result = IDirectDrawSurface3_QueryInterface (SDL_primary, | 2413 result = IDirectDrawSurface3_QueryInterface(SDL_primary, |
2421 &IID_IDirectDrawGammaControl, | 2414 &IID_IDirectDrawGammaControl, |
2422 (LPVOID *) & gamma); | 2415 (LPVOID *) & gamma); |
2423 if (result != DD_OK) { | 2416 if (result != DD_OK) { |
2424 SetDDerror ("DirectDrawSurface3::QueryInterface(GAMMA)", result); | 2417 SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result); |
2425 return (-1); | 2418 return (-1); |
2426 } | 2419 } |
2427 | 2420 |
2428 /* Set up the gamma ramp */ | 2421 /* Set up the gamma ramp */ |
2429 result = IDirectDrawGammaControl_GetGammaRamp (gamma, 0, &gamma_ramp); | 2422 result = IDirectDrawGammaControl_GetGammaRamp(gamma, 0, &gamma_ramp); |
2430 if (result == DD_OK) { | 2423 if (result == DD_OK) { |
2431 SDL_memcpy (&ramp[0 * 256], gamma_ramp.red, 256 * sizeof (*ramp)); | 2424 SDL_memcpy(&ramp[0 * 256], gamma_ramp.red, 256 * sizeof(*ramp)); |
2432 SDL_memcpy (&ramp[1 * 256], gamma_ramp.green, 256 * sizeof (*ramp)); | 2425 SDL_memcpy(&ramp[1 * 256], gamma_ramp.green, 256 * sizeof(*ramp)); |
2433 SDL_memcpy (&ramp[2 * 256], gamma_ramp.blue, 256 * sizeof (*ramp)); | 2426 SDL_memcpy(&ramp[2 * 256], gamma_ramp.blue, 256 * sizeof(*ramp)); |
2434 } else { | 2427 } else { |
2435 SetDDerror ("DirectDrawGammaControl::GetGammaRamp()", result); | 2428 SetDDerror("DirectDrawGammaControl::GetGammaRamp()", result); |
2436 } | 2429 } |
2437 | 2430 |
2438 /* Release the interface and return */ | 2431 /* Release the interface and return */ |
2439 IDirectDrawGammaControl_Release (gamma); | 2432 IDirectDrawGammaControl_Release(gamma); |
2440 return (result == DD_OK) ? 0 : -1; | 2433 return (result == DD_OK) ? 0 : -1; |
2441 #endif /* !IDirectDrawGammaControl_SetGammaRamp */ | 2434 #endif /* !IDirectDrawGammaControl_SetGammaRamp */ |
2442 } | 2435 } |
2443 | 2436 |
2444 void | 2437 void |
2445 DX5_VideoQuit (_THIS) | 2438 DX5_VideoQuit(_THIS) |
2446 { | 2439 { |
2447 int i, j; | 2440 int i, j; |
2448 | 2441 |
2449 /* If we're fullscreen GL, we need to reset the display */ | 2442 /* If we're fullscreen GL, we need to reset the display */ |
2450 if (this->screen != NULL) { | 2443 if (this->screen != NULL) { |
2451 #ifndef NO_CHANGEDISPLAYSETTINGS | 2444 #ifndef NO_CHANGEDISPLAYSETTINGS |
2452 if ((this->screen->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) == | 2445 if ((this->screen->flags & (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) == |
2453 (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) { | 2446 (SDL_INTERNALOPENGL | SDL_FULLSCREEN)) { |
2454 ChangeDisplaySettings (NULL, 0); | 2447 ChangeDisplaySettings(NULL, 0); |
2455 ShowWindow (SDL_Window, SW_HIDE); | 2448 ShowWindow(SDL_Window, SW_HIDE); |
2456 } | 2449 } |
2457 #endif | 2450 #endif |
2458 if (this->screen->flags & SDL_INTERNALOPENGL) { | 2451 if (this->screen->flags & SDL_INTERNALOPENGL) { |
2459 WIN_GL_ShutDown (this); | 2452 WIN_GL_ShutDown(this); |
2460 } | 2453 } |
2461 } | 2454 } |
2462 | 2455 |
2463 /* Free any palettes we used */ | 2456 /* Free any palettes we used */ |
2464 if (SDL_palette != NULL) { | 2457 if (SDL_palette != NULL) { |
2465 IDirectDrawPalette_Release (SDL_palette); | 2458 IDirectDrawPalette_Release(SDL_palette); |
2466 SDL_palette = NULL; | 2459 SDL_palette = NULL; |
2467 } | 2460 } |
2468 | 2461 |
2469 /* Allow the primary surface to be freed */ | 2462 /* Allow the primary surface to be freed */ |
2470 if (SDL_primary != NULL) { | 2463 if (SDL_primary != NULL) { |
2473 | 2466 |
2474 /* Free video mode lists */ | 2467 /* Free video mode lists */ |
2475 for (i = 0; i < NUM_MODELISTS; ++i) { | 2468 for (i = 0; i < NUM_MODELISTS; ++i) { |
2476 if (SDL_modelist[i] != NULL) { | 2469 if (SDL_modelist[i] != NULL) { |
2477 for (j = 0; SDL_modelist[i][j]; ++j) | 2470 for (j = 0; SDL_modelist[i][j]; ++j) |
2478 SDL_free (SDL_modelist[i][j]); | 2471 SDL_free(SDL_modelist[i][j]); |
2479 SDL_free (SDL_modelist[i]); | 2472 SDL_free(SDL_modelist[i]); |
2480 SDL_modelist[i] = NULL; | 2473 SDL_modelist[i] = NULL; |
2481 } | 2474 } |
2482 } | 2475 } |
2483 | 2476 |
2484 /* Free the window */ | 2477 /* Free the window */ |
2485 DIB_QuitGamma (this); | 2478 DIB_QuitGamma(this); |
2486 if (SDL_Window) { | 2479 if (SDL_Window) { |
2487 DX5_DestroyWindow (this); | 2480 DX5_DestroyWindow(this); |
2488 } | 2481 } |
2489 | 2482 |
2490 /* Free our window icon */ | 2483 /* Free our window icon */ |
2491 if (screen_icn) { | 2484 if (screen_icn) { |
2492 DestroyIcon (screen_icn); | 2485 DestroyIcon(screen_icn); |
2493 screen_icn = NULL; | 2486 screen_icn = NULL; |
2494 } | 2487 } |
2495 } | 2488 } |
2496 | 2489 |
2497 /* Exported for the windows message loop only */ | 2490 /* Exported for the windows message loop only */ |
2498 void | 2491 void |
2499 DX5_RealizePalette (_THIS) | 2492 DX5_RealizePalette(_THIS) |
2500 { | 2493 { |
2501 if (SDL_palette) { | 2494 if (SDL_palette) { |
2502 IDirectDrawSurface3_SetPalette (SDL_primary, SDL_palette); | 2495 IDirectDrawSurface3_SetPalette(SDL_primary, SDL_palette); |
2503 } | 2496 } |
2504 } | 2497 } |
2505 static void | 2498 static void |
2506 DX5_Recolor8Bit (_THIS, SDL_Surface * surface, Uint8 * mapping) | 2499 DX5_Recolor8Bit(_THIS, SDL_Surface * surface, Uint8 * mapping) |
2507 { | 2500 { |
2508 int row, col; | 2501 int row, col; |
2509 Uint8 *pixels; | 2502 Uint8 *pixels; |
2510 | 2503 |
2511 if (surface->w && surface->h) { | 2504 if (surface->w && surface->h) { |
2512 if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { | 2505 if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
2513 if (this->LockHWSurface (this, surface) < 0) { | 2506 if (this->LockHWSurface(this, surface) < 0) { |
2514 return; | 2507 return; |
2515 } | 2508 } |
2516 } | 2509 } |
2517 for (row = 0; row < surface->h; ++row) { | 2510 for (row = 0; row < surface->h; ++row) { |
2518 pixels = (Uint8 *) surface->pixels + row * surface->pitch; | 2511 pixels = (Uint8 *) surface->pixels + row * surface->pitch; |
2519 for (col = 0; col < surface->w; ++col, ++pixels) { | 2512 for (col = 0; col < surface->w; ++col, ++pixels) { |
2520 *pixels = mapping[*pixels]; | 2513 *pixels = mapping[*pixels]; |
2521 } | 2514 } |
2522 } | 2515 } |
2523 if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { | 2516 if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
2524 this->UnlockHWSurface (this, surface); | 2517 this->UnlockHWSurface(this, surface); |
2525 } | 2518 } |
2526 SDL_UpdateRect (surface, 0, 0, 0, 0); | 2519 SDL_UpdateRect(surface, 0, 0, 0, 0); |
2527 } | 2520 } |
2528 } | 2521 } |
2529 void | 2522 void |
2530 DX5_PaletteChanged (_THIS, HWND window) | 2523 DX5_PaletteChanged(_THIS, HWND window) |
2531 { | 2524 { |
2532 SDL_Palette *palette; | 2525 SDL_Palette *palette; |
2533 SDL_Color *saved = NULL; | 2526 SDL_Color *saved = NULL; |
2534 HDC hdc; | 2527 HDC hdc; |
2535 int i; | 2528 int i; |
2544 if (!palette) | 2537 if (!palette) |
2545 palette = SDL_VideoSurface->format->palette; | 2538 palette = SDL_VideoSurface->format->palette; |
2546 if (palette == NULL) { /* Sometimes we don't have a palette */ | 2539 if (palette == NULL) { /* Sometimes we don't have a palette */ |
2547 return; | 2540 return; |
2548 } | 2541 } |
2549 entries = SDL_stack_alloc (PALETTEENTRY, palette->ncolors); | 2542 entries = SDL_stack_alloc(PALETTEENTRY, palette->ncolors); |
2550 hdc = GetDC (window); | 2543 hdc = GetDC(window); |
2551 GetSystemPaletteEntries (hdc, 0, palette->ncolors, entries); | 2544 GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries); |
2552 ReleaseDC (window, hdc); | 2545 ReleaseDC(window, hdc); |
2553 if (!colorchange_expected) { | 2546 if (!colorchange_expected) { |
2554 saved = SDL_stack_alloc (SDL_Color, palette->ncolors); | 2547 saved = SDL_stack_alloc(SDL_Color, palette->ncolors); |
2555 SDL_memcpy (saved, palette->colors, | 2548 SDL_memcpy(saved, palette->colors, |
2556 palette->ncolors * sizeof (SDL_Color)); | 2549 palette->ncolors * sizeof(SDL_Color)); |
2557 } | 2550 } |
2558 for (i = 0; i < palette->ncolors; ++i) { | 2551 for (i = 0; i < palette->ncolors; ++i) { |
2559 palette->colors[i].r = entries[i].peRed; | 2552 palette->colors[i].r = entries[i].peRed; |
2560 palette->colors[i].g = entries[i].peGreen; | 2553 palette->colors[i].g = entries[i].peGreen; |
2561 palette->colors[i].b = entries[i].peBlue; | 2554 palette->colors[i].b = entries[i].peBlue; |
2562 } | 2555 } |
2563 SDL_stack_free (entries); | 2556 SDL_stack_free(entries); |
2564 if (!colorchange_expected) { | 2557 if (!colorchange_expected) { |
2565 Uint8 mapping[256]; | 2558 Uint8 mapping[256]; |
2566 | 2559 |
2567 SDL_memset (mapping, 0, sizeof (mapping)); | 2560 SDL_memset(mapping, 0, sizeof(mapping)); |
2568 for (i = 0; i < palette->ncolors; ++i) { | 2561 for (i = 0; i < palette->ncolors; ++i) { |
2569 mapping[i] = SDL_FindColor (palette, | 2562 mapping[i] = SDL_FindColor(palette, |
2570 saved[i].r, saved[i].g, saved[i].b); | 2563 saved[i].r, saved[i].g, saved[i].b); |
2571 } | 2564 } |
2572 DX5_Recolor8Bit (this, SDL_VideoSurface, mapping); | 2565 DX5_Recolor8Bit(this, SDL_VideoSurface, mapping); |
2573 SDL_stack_free (saved); | 2566 SDL_stack_free(saved); |
2574 } | 2567 } |
2575 colorchange_expected = 0; | 2568 colorchange_expected = 0; |
2576 | 2569 |
2577 /* Notify all mapped surfaces of the change */ | 2570 /* Notify all mapped surfaces of the change */ |
2578 SDL_FormatChanged (SDL_VideoSurface); | 2571 SDL_FormatChanged(SDL_VideoSurface); |
2579 } | 2572 } |
2580 | 2573 |
2581 /* Exported for the windows message loop only */ | 2574 /* Exported for the windows message loop only */ |
2582 void | 2575 void |
2583 DX5_WinPAINT (_THIS, HDC hdc) | 2576 DX5_WinPAINT(_THIS, HDC hdc) |
2584 { | 2577 { |
2585 SDL_UpdateRect (SDL_PublicSurface, 0, 0, 0, 0); | 2578 SDL_UpdateRect(SDL_PublicSurface, 0, 0, 0, 0); |
2586 } | 2579 } |
2587 | 2580 |
2588 /* vi: set ts=4 sw=4 expandtab: */ | 2581 /* vi: set ts=4 sw=4 expandtab: */ |