Fixed gamma ramps in DirectX windowed and OpenGL modes
authorSam Lantinga <slouken@libsdl.org>
Thu, 11 Apr 2002 15:23:07 +0000
changeset 338518ffd98a8f6
parent 337 9154ec9ca3d2
child 339 eed579d059ef
Fixed gamma ramps in DirectX windowed and OpenGL modes
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/windib/SDL_dibvideo.c
src/video/windib/SDL_dibvideo.h
src/video/windx5/SDL_dx5video.c
     1.1 --- a/src/video/wincommon/SDL_lowvideo.h	Thu Apr 11 14:35:16 2002 +0000
     1.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Thu Apr 11 15:23:07 2002 +0000
     1.3 @@ -67,9 +67,6 @@
     1.4  /* Called by windows message loop when the system palette changes */
     1.5  extern void (*WIN_PaletteChanged)(_THIS, HWND window);
     1.6  
     1.7 -/* Called by windows message loop when losing or gaining gamma focus */
     1.8 -extern void (*WIN_SwapGamma)(_THIS);
     1.9 -
    1.10  /* Called by windows message loop when a portion of the screen needs update */
    1.11  extern void (*WIN_WinPAINT)(_THIS, HDC hdc);
    1.12  
    1.13 @@ -93,6 +90,9 @@
    1.14  extern DEVMODE SDL_fullscreen_mode;
    1.15  #endif
    1.16  
    1.17 +/* The system gamma ramp for GDI modes */
    1.18 +extern WORD *gamma_saved;
    1.19 +
    1.20  /* This is really from SDL_dx5audio.c */
    1.21  extern void DX5_SoundFocus(HWND window);
    1.22  
     2.1 --- a/src/video/wincommon/SDL_sysevents.c	Thu Apr 11 14:35:16 2002 +0000
     2.2 +++ b/src/video/wincommon/SDL_sysevents.c	Thu Apr 11 15:23:07 2002 +0000
     2.3 @@ -60,6 +60,7 @@
     2.4  #ifndef NO_CHANGEDISPLAYSETTINGS
     2.5  DEVMODE SDL_fullscreen_mode;
     2.6  #endif
     2.7 +WORD *gamma_saved = NULL;
     2.8  
     2.9  
    2.10  /* Functions called by the message processing function */
    2.11 @@ -67,8 +68,8 @@
    2.12  (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
    2.13  void (*WIN_RealizePalette)(_THIS);
    2.14  void (*WIN_PaletteChanged)(_THIS, HWND window);
    2.15 -void (*WIN_SwapGamma)(_THIS);
    2.16  void (*WIN_WinPAINT)(_THIS, HDC hdc);
    2.17 +extern void DIB_SwapGamma(_THIS);
    2.18  
    2.19  static void SDL_RestoreGameMode(void)
    2.20  {
    2.21 @@ -198,7 +199,9 @@
    2.22  					WIN_GrabInput(this, SDL_GRAB_ON);
    2.23  				}
    2.24  				if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
    2.25 -					WIN_SwapGamma(this);
    2.26 +					if ( ! DDRAW_FULLSCREEN() ) {
    2.27 +						DIB_SwapGamma(this);
    2.28 +					}
    2.29  					if ( WINDIB_FULLSCREEN() ) {
    2.30  						SDL_RestoreGameMode();
    2.31  					}
    2.32 @@ -215,7 +218,9 @@
    2.33  					WIN_GrabInput(this, SDL_GRAB_OFF);
    2.34  				}
    2.35  				if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
    2.36 -					WIN_SwapGamma(this);
    2.37 +					if ( ! DDRAW_FULLSCREEN() ) {
    2.38 +						DIB_SwapGamma(this);
    2.39 +					}
    2.40  					if ( WINDIB_FULLSCREEN() ) {
    2.41  						SDL_RestoreDesktopMode();
    2.42  					}
     3.1 --- a/src/video/windib/SDL_dibvideo.c	Thu Apr 11 14:35:16 2002 +0000
     3.2 +++ b/src/video/windib/SDL_dibvideo.c	Thu Apr 11 15:23:07 2002 +0000
     3.3 @@ -61,12 +61,10 @@
     3.4  static int DIB_SetColors(_THIS, int firstcolor, int ncolors,
     3.5  			 SDL_Color *colors);
     3.6  static void DIB_CheckGamma(_THIS);
     3.7 -static void DIB_SwapGamma(_THIS);
     3.8 -static void DIB_QuitGamma(_THIS);
     3.9 -#ifndef NO_GAMMA_SUPPORT
    3.10 -static int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
    3.11 -static int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
    3.12 -#endif
    3.13 +void DIB_SwapGamma(_THIS);
    3.14 +void DIB_QuitGamma(_THIS);
    3.15 +int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
    3.16 +int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
    3.17  static void DIB_VideoQuit(_THIS);
    3.18  
    3.19  /* Hardware surface functions */
    3.20 @@ -142,10 +140,8 @@
    3.21  	device->UnlockHWSurface = DIB_UnlockHWSurface;
    3.22  	device->FlipHWSurface = NULL;
    3.23  	device->FreeHWSurface = DIB_FreeHWSurface;
    3.24 -#ifndef NO_GAMMA_SUPPORT
    3.25  	device->SetGammaRamp = DIB_SetGammaRamp;
    3.26  	device->GetGammaRamp = DIB_GetGammaRamp;
    3.27 -#endif
    3.28  #ifdef HAVE_OPENGL
    3.29          device->GL_LoadLibrary = WIN_GL_LoadLibrary;
    3.30          device->GL_GetProcAddress = WIN_GL_GetProcAddress;
    3.31 @@ -169,7 +165,6 @@
    3.32  	/* Set up the windows message handling functions */
    3.33  	WIN_RealizePalette = DIB_RealizePalette;
    3.34  	WIN_PaletteChanged = DIB_PaletteChanged;
    3.35 -	WIN_SwapGamma = DIB_SwapGamma;
    3.36  	WIN_WinPAINT = DIB_WinPAINT;
    3.37  	HandleMessage = DIB_HandleMessage;
    3.38  
    3.39 @@ -807,7 +802,7 @@
    3.40  	ReleaseDC(SDL_Window, hdc);
    3.41  #endif /* !NO_GAMMA_SUPPORT */
    3.42  }
    3.43 -static void DIB_SwapGamma(_THIS)
    3.44 +void DIB_SwapGamma(_THIS)
    3.45  {
    3.46  #ifndef NO_GAMMA_SUPPORT
    3.47  	HDC hdc;
    3.48 @@ -826,7 +821,7 @@
    3.49  	}
    3.50  #endif /* !NO_GAMMA_SUPPORT */
    3.51  }
    3.52 -static void DIB_QuitGamma(_THIS)
    3.53 +void DIB_QuitGamma(_THIS)
    3.54  {
    3.55  #ifndef NO_GAMMA_SUPPORT
    3.56  	if ( gamma_saved ) {
    3.57 @@ -846,10 +841,12 @@
    3.58  #endif /* !NO_GAMMA_SUPPORT */
    3.59  }
    3.60  
    3.61 -#ifndef NO_GAMMA_SUPPORT
    3.62 -
    3.63 -static int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
    3.64 +int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
    3.65  {
    3.66 +#ifdef NO_GAMMA_SUPPORT
    3.67 +	SDL_SetError("SDL compiled without gamma ramp support");
    3.68 +	return -1;
    3.69 +#else
    3.70  	HDC hdc;
    3.71  	BOOL succeeded;
    3.72  
    3.73 @@ -872,10 +869,15 @@
    3.74  		succeeded = TRUE;
    3.75  	}
    3.76  	return succeeded ? 0 : -1;
    3.77 +#endif /* !NO_GAMMA_SUPPORT */
    3.78  }
    3.79  
    3.80 -static int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
    3.81 +int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
    3.82  {
    3.83 +#ifdef NO_GAMMA_SUPPORT
    3.84 +	SDL_SetError("SDL compiled without gamma ramp support");
    3.85 +	return -1;
    3.86 +#else
    3.87  	HDC hdc;
    3.88  	BOOL succeeded;
    3.89  
    3.90 @@ -884,10 +886,9 @@
    3.91  	succeeded = GetDeviceGammaRamp(hdc, ramp);
    3.92  	ReleaseDC(SDL_Window, hdc);
    3.93  	return succeeded ? 0 : -1;
    3.94 +#endif /* !NO_GAMMA_SUPPORT */
    3.95  }
    3.96  
    3.97 -#endif /* !NO_GAMMA_SUPPORT */
    3.98 -
    3.99  void DIB_VideoQuit(_THIS)
   3.100  {
   3.101  	/* Destroy the window and everything associated with it */
     4.1 --- a/src/video/windib/SDL_dibvideo.h	Thu Apr 11 14:35:16 2002 +0000
     4.2 +++ b/src/video/windib/SDL_dibvideo.h	Thu Apr 11 15:23:07 2002 +0000
     4.3 @@ -38,14 +38,11 @@
     4.4  #define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
     4.5      int SDL_nummodes[NUM_MODELISTS];
     4.6      SDL_Rect **SDL_modelist[NUM_MODELISTS];
     4.7 -
     4.8 -    WORD *gamma_saved;
     4.9  };
    4.10  /* Old variable names */
    4.11  #define screen_bmp		(this->hidden->screen_bmp)
    4.12  #define screen_pal		(this->hidden->screen_pal)
    4.13  #define SDL_nummodes		(this->hidden->SDL_nummodes)
    4.14  #define SDL_modelist		(this->hidden->SDL_modelist)
    4.15 -#define gamma_saved		(this->hidden->gamma_saved)
    4.16  
    4.17  #endif /* _SDL_dibvideo_h */
     5.1 --- a/src/video/windx5/SDL_dx5video.c	Thu Apr 11 14:35:16 2002 +0000
     5.2 +++ b/src/video/windx5/SDL_dx5video.c	Thu Apr 11 15:23:07 2002 +0000
     5.3 @@ -404,11 +404,8 @@
     5.4  static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
     5.5  static int DX5_SetColors(_THIS, int firstcolor, int ncolors,
     5.6  			 SDL_Color *colors);
     5.7 -static void DX5_SwapGamma(_THIS);
     5.8 -#ifdef IDirectDrawGammaControl_SetGammaRamp
     5.9  static int DX5_SetGammaRamp(_THIS, Uint16 *ramp);
    5.10  static int DX5_GetGammaRamp(_THIS, Uint16 *ramp);
    5.11 -#endif
    5.12  static void DX5_VideoQuit(_THIS);
    5.13  
    5.14  /* Hardware surface functions */
    5.15 @@ -430,6 +427,11 @@
    5.16  static void DX5_PaletteChanged(_THIS, HWND window);
    5.17  static void DX5_WinPAINT(_THIS, HDC hdc);
    5.18  
    5.19 +/* WinDIB driver functions for manipulating gamma ramps */
    5.20 +extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
    5.21 +extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
    5.22 +extern void DIB_QuitGamma(_THIS);
    5.23 +
    5.24  /* DX5 driver bootstrap functions */
    5.25  
    5.26  static int DX5_Available(void)
    5.27 @@ -591,10 +593,8 @@
    5.28  	device->UnlockHWSurface = DX5_UnlockHWSurface;
    5.29  	device->FlipHWSurface = DX5_FlipHWSurface;
    5.30  	device->FreeHWSurface = DX5_FreeHWSurface;
    5.31 -#ifdef IDirectDrawGammaControl_SetGammaRamp
    5.32  	device->SetGammaRamp = DX5_SetGammaRamp;
    5.33  	device->GetGammaRamp = DX5_GetGammaRamp;
    5.34 -#endif
    5.35  #ifdef HAVE_OPENGL
    5.36          device->GL_LoadLibrary = WIN_GL_LoadLibrary;
    5.37          device->GL_GetProcAddress = WIN_GL_GetProcAddress;
    5.38 @@ -618,7 +618,6 @@
    5.39  	/* Set up the windows message handling functions */
    5.40  	WIN_RealizePalette = DX5_RealizePalette;
    5.41  	WIN_PaletteChanged = DX5_PaletteChanged;
    5.42 -	WIN_SwapGamma = DX5_SwapGamma;
    5.43  	WIN_WinPAINT = DX5_WinPAINT;
    5.44  	HandleMessage = DX5_HandleMessage;
    5.45  
    5.46 @@ -2112,20 +2111,24 @@
    5.47  	return(alloct_all);
    5.48  }
    5.49  
    5.50 -static void DX5_SwapGamma(_THIS)
    5.51 -{
    5.52 -	return;
    5.53 -}
    5.54 -
    5.55  /* Gamma code is only available on DirectX 7 and newer */
    5.56 -#ifdef IDirectDrawGammaControl_SetGammaRamp
    5.57 -
    5.58  static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
    5.59  {
    5.60 +#ifdef IDirectDrawGammaControl_SetGammaRamp
    5.61  	LPDIRECTDRAWGAMMACONTROL gamma;
    5.62  	DDGAMMARAMP gamma_ramp;
    5.63  	HRESULT result;
    5.64 +#endif
    5.65  
    5.66 +	/* In windowed or OpenGL mode, use windib gamma code */
    5.67 +	if ( ! DDRAW_FULLSCREEN() ) {
    5.68 +		return DIB_SetGammaRamp(this, ramp);
    5.69 +	}
    5.70 +
    5.71 +#ifndef IDirectDrawGammaControl_SetGammaRamp
    5.72 +	SDL_SetError("SDL compiled without DirectX gamma ramp support");
    5.73 +	return -1;
    5.74 +#else
    5.75  	/* Check for a video mode! */
    5.76  	if ( ! SDL_primary ) {
    5.77  		SDL_SetError("A video mode must be set for gamma correction");
    5.78 @@ -2152,14 +2155,26 @@
    5.79  	/* Release the interface and return */
    5.80  	IDirectDrawGammaControl_Release(gamma);
    5.81  	return (result == DD_OK) ? 0 : -1;
    5.82 +#endif /* !IDirectDrawGammaControl_SetGammaRamp */
    5.83  }
    5.84  
    5.85  static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
    5.86  {
    5.87 +#ifdef IDirectDrawGammaControl_SetGammaRamp
    5.88  	LPDIRECTDRAWGAMMACONTROL gamma;
    5.89  	DDGAMMARAMP gamma_ramp;
    5.90  	HRESULT result;
    5.91 +#endif
    5.92  
    5.93 +	/* In windowed or OpenGL mode, use windib gamma code */
    5.94 +	if ( ! DDRAW_FULLSCREEN() ) {
    5.95 +		return DIB_GetGammaRamp(this, ramp);
    5.96 +	}
    5.97 +
    5.98 +#ifndef IDirectDrawGammaControl_SetGammaRamp
    5.99 +	SDL_SetError("SDL compiled without DirectX gamma ramp support");
   5.100 +	return -1;
   5.101 +#else
   5.102  	/* Check for a video mode! */
   5.103  	if ( ! SDL_primary ) {
   5.104  		SDL_SetError("A video mode must be set for gamma correction");
   5.105 @@ -2187,10 +2202,9 @@
   5.106  	/* Release the interface and return */
   5.107  	IDirectDrawGammaControl_Release(gamma);
   5.108  	return (result == DD_OK) ? 0 : -1;
   5.109 +#endif /* !IDirectDrawGammaControl_SetGammaRamp */
   5.110  }
   5.111  
   5.112 -#endif /* IDirectDrawGammaControl_SetGammaRamp */
   5.113 -
   5.114  void DX5_VideoQuit(_THIS)
   5.115  {
   5.116  	int i, j;
   5.117 @@ -2228,6 +2242,7 @@
   5.118  	}
   5.119  
   5.120  	/* Free the window */
   5.121 +	DIB_QuitGamma(this);
   5.122  	if ( SDL_Window ) {
   5.123  		DX5_DestroyWindow(this);
   5.124  	}