comparison src/video/windx5/SDL_dx5video.c @ 1855:5ff2c01e475e

Moved DirectInput joystick code to 1.3 branch
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 May 2006 17:26:40 +0000
parents 2280e314a978
children 339d733e3699
comparison
equal deleted inserted replaced
1854:2280e314a978 1855:5ff2c01e475e
434 /* WinDIB driver functions for manipulating gamma ramps */ 434 /* WinDIB driver functions for manipulating gamma ramps */
435 extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp); 435 extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
436 extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp); 436 extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
437 extern void DIB_QuitGamma(_THIS); 437 extern void DIB_QuitGamma(_THIS);
438 438
439 /* DX5 driver bootstrap functions */
440
441 static int DX5_Available(void)
442 {
443 HINSTANCE DInputDLL;
444 HINSTANCE DDrawDLL;
445 int dinput_ok;
446 int ddraw_ok;
447
448 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
449 dinput_ok = 0;
450 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
451 if ( DInputDLL != NULL ) {
452 dinput_ok = 1;
453 FreeLibrary(DInputDLL);
454 }
455 ddraw_ok = 0;
456 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
457 if ( DDrawDLL != NULL ) {
458 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
459 LPDIRECTDRAW DDraw;
460
461 /* Try to create a valid DirectDraw object */
462 DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
463 if ( (DDrawCreate != NULL)
464 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
465 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
466 NULL, DDSCL_NORMAL)) ) {
467 DDSURFACEDESC desc;
468 LPDIRECTDRAWSURFACE DDrawSurf;
469 LPDIRECTDRAWSURFACE3 DDrawSurf3;
470
471 /* Try to create a DirectDrawSurface3 object */
472 SDL_memset(&desc, 0, sizeof(desc));
473 desc.dwSize = sizeof(desc);
474 desc.dwFlags = DDSD_CAPS;
475 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
476 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
477 &DDrawSurf, NULL)) ) {
478 if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
479 &IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
480 /* Yay! */
481 ddraw_ok = 1;
482
483 /* Clean up.. */
484 IDirectDrawSurface3_Release(DDrawSurf3);
485 }
486 IDirectDrawSurface_Release(DDrawSurf);
487 }
488 }
489 IDirectDraw_Release(DDraw);
490 }
491 FreeLibrary(DDrawDLL);
492 }
493 return(dinput_ok && ddraw_ok);
494 }
495
439 /* Functions for loading the DirectX functions dynamically */ 496 /* Functions for loading the DirectX functions dynamically */
440 static int DX5_loaded = 0;
441 static HINSTANCE DDrawDLL = NULL; 497 static HINSTANCE DDrawDLL = NULL;
442 static HINSTANCE DInputDLL = NULL; 498 static HINSTANCE DInputDLL = NULL;
443 499
444 void DX5_Unload(void) 500 static void DX5_Unload(void)
445 { 501 {
446 if ( --DX5_loaded == 0 ) { 502 if ( DDrawDLL != NULL ) {
447 if ( DDrawDLL != NULL ) { 503 FreeLibrary(DDrawDLL);
448 FreeLibrary(DDrawDLL); 504 DDrawCreate = NULL;
449 DDrawCreate = NULL; 505 DDrawDLL = NULL;
450 DDrawDLL = NULL; 506 }
451 } 507 if ( DInputDLL != NULL ) {
452 if ( DInputDLL != NULL ) { 508 FreeLibrary(DInputDLL);
453 FreeLibrary(DInputDLL); 509 DInputCreate = NULL;
454 DInputCreate = NULL; 510 DInputDLL = NULL;
455 DInputDLL = NULL; 511 }
456 } 512 }
457 } 513 static int DX5_Load(void)
458 } 514 {
459 int DX5_Load(void) 515 int status;
460 { 516
461 int status = 0; 517 DX5_Unload();
462 518 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
463 if ( ++DX5_loaded == 1 ) { 519 if ( DDrawDLL != NULL ) {
464 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL")); 520 DDrawCreate = (void *)GetProcAddress(DDrawDLL,
465 if ( DDrawDLL != NULL ) { 521 TEXT("DirectDrawCreate"));
466 DDrawCreate = (void *)GetProcAddress(DDrawDLL, 522 }
467 TEXT("DirectDrawCreate")); 523 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
468 } 524 if ( DInputDLL != NULL ) {
469 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL")); 525 DInputCreate = (void *)GetProcAddress(DInputDLL,
470 if ( DInputDLL != NULL ) { 526 TEXT("DirectInputCreateA"));
471 DInputCreate = (void *)GetProcAddress(DInputDLL, 527 }
472 TEXT("DirectInputCreateA")); 528 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
473 } 529 status = 0;
474 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) { 530 } else {
475 status = 0; 531 DX5_Unload();
476 } else { 532 status = -1;
477 DX5_Unload();
478 status = -1;
479 }
480 } 533 }
481 return status; 534 return status;
482 }
483
484 /* DX5 driver bootstrap functions */
485
486 static int DX5_Available(void)
487 {
488 int ddraw_ok = 0;
489 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
490 LPDIRECTDRAW DDraw;
491
492 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
493 if ( DX5_Load() < 0 ) {
494 return -1;
495 }
496
497 /* Try to create a valid DirectDraw object */
498 DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
499 if ( (DDrawCreate != NULL)
500 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
501 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
502 NULL, DDSCL_NORMAL)) ) {
503 DDSURFACEDESC desc;
504 LPDIRECTDRAWSURFACE DDrawSurf;
505 LPDIRECTDRAWSURFACE3 DDrawSurf3;
506
507 /* Try to create a DirectDrawSurface3 object */
508 SDL_memset(&desc, 0, sizeof(desc));
509 desc.dwSize = sizeof(desc);
510 desc.dwFlags = DDSD_CAPS;
511 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
512 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
513 &DDrawSurf, NULL)) ) {
514 if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
515 &IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
516 /* Yay! */
517 ddraw_ok = 1;
518
519 /* Clean up.. */
520 IDirectDrawSurface3_Release(DDrawSurf3);
521 }
522 IDirectDrawSurface_Release(DDrawSurf);
523 }
524 }
525 IDirectDraw_Release(DDraw);
526 }
527
528 DX5_Unload();
529
530 return ddraw_ok;
531 } 535 }
532 536
533 static void DX5_DeleteDevice(SDL_VideoDevice *this) 537 static void DX5_DeleteDevice(SDL_VideoDevice *this)
534 { 538 {
535 /* Free DirectDraw object */ 539 /* Free DirectDraw object */
536 if ( ddraw2 != NULL ) { 540 if ( ddraw2 != NULL ) {
537 IDirectDraw2_Release(ddraw2); 541 IDirectDraw2_Release(ddraw2);
538 } 542 }
539 DX5_Unload(); 543 DX5_Unload();
540
541 if ( this ) { 544 if ( this ) {
542 if ( this->hidden ) { 545 if ( this->hidden ) {
543 SDL_free(this->hidden); 546 SDL_free(this->hidden);
544 } 547 }
545 if ( this->gl_data ) { 548 if ( this->gl_data ) {