Commit fff61690 authored by Sam Lantinga's avatar Sam Lantinga

Fixed gamma ramps in DirectX windowed and OpenGL modes

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40339
parent 808d714d
...@@ -67,9 +67,6 @@ extern void (*WIN_RealizePalette)(_THIS); ...@@ -67,9 +67,6 @@ extern void (*WIN_RealizePalette)(_THIS);
/* Called by windows message loop when the system palette changes */ /* Called by windows message loop when the system palette changes */
extern void (*WIN_PaletteChanged)(_THIS, HWND window); extern void (*WIN_PaletteChanged)(_THIS, HWND window);
/* Called by windows message loop when losing or gaining gamma focus */
extern void (*WIN_SwapGamma)(_THIS);
/* Called by windows message loop when a portion of the screen needs update */ /* Called by windows message loop when a portion of the screen needs update */
extern void (*WIN_WinPAINT)(_THIS, HDC hdc); extern void (*WIN_WinPAINT)(_THIS, HDC hdc);
...@@ -93,6 +90,9 @@ extern int mouse_relative; ...@@ -93,6 +90,9 @@ extern int mouse_relative;
extern DEVMODE SDL_fullscreen_mode; extern DEVMODE SDL_fullscreen_mode;
#endif #endif
/* The system gamma ramp for GDI modes */
extern WORD *gamma_saved;
/* This is really from SDL_dx5audio.c */ /* This is really from SDL_dx5audio.c */
extern void DX5_SoundFocus(HWND window); extern void DX5_SoundFocus(HWND window);
......
...@@ -60,6 +60,7 @@ int posted = 0; ...@@ -60,6 +60,7 @@ int posted = 0;
#ifndef NO_CHANGEDISPLAYSETTINGS #ifndef NO_CHANGEDISPLAYSETTINGS
DEVMODE SDL_fullscreen_mode; DEVMODE SDL_fullscreen_mode;
#endif #endif
WORD *gamma_saved = NULL;
/* Functions called by the message processing function */ /* Functions called by the message processing function */
...@@ -67,8 +68,8 @@ LONG ...@@ -67,8 +68,8 @@ LONG
(*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL; (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
void (*WIN_RealizePalette)(_THIS); void (*WIN_RealizePalette)(_THIS);
void (*WIN_PaletteChanged)(_THIS, HWND window); void (*WIN_PaletteChanged)(_THIS, HWND window);
void (*WIN_SwapGamma)(_THIS);
void (*WIN_WinPAINT)(_THIS, HDC hdc); void (*WIN_WinPAINT)(_THIS, HDC hdc);
extern void DIB_SwapGamma(_THIS);
static void SDL_RestoreGameMode(void) static void SDL_RestoreGameMode(void)
{ {
...@@ -198,7 +199,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -198,7 +199,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WIN_GrabInput(this, SDL_GRAB_ON); WIN_GrabInput(this, SDL_GRAB_ON);
} }
if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) { if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
WIN_SwapGamma(this); if ( ! DDRAW_FULLSCREEN() ) {
DIB_SwapGamma(this);
}
if ( WINDIB_FULLSCREEN() ) { if ( WINDIB_FULLSCREEN() ) {
SDL_RestoreGameMode(); SDL_RestoreGameMode();
} }
...@@ -215,7 +218,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -215,7 +218,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WIN_GrabInput(this, SDL_GRAB_OFF); WIN_GrabInput(this, SDL_GRAB_OFF);
} }
if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
WIN_SwapGamma(this); if ( ! DDRAW_FULLSCREEN() ) {
DIB_SwapGamma(this);
}
if ( WINDIB_FULLSCREEN() ) { if ( WINDIB_FULLSCREEN() ) {
SDL_RestoreDesktopMode(); SDL_RestoreDesktopMode();
} }
......
...@@ -61,12 +61,10 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height ...@@ -61,12 +61,10 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height
static int DIB_SetColors(_THIS, int firstcolor, int ncolors, static int DIB_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors); SDL_Color *colors);
static void DIB_CheckGamma(_THIS); static void DIB_CheckGamma(_THIS);
static void DIB_SwapGamma(_THIS); void DIB_SwapGamma(_THIS);
static void DIB_QuitGamma(_THIS); void DIB_QuitGamma(_THIS);
#ifndef NO_GAMMA_SUPPORT int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
static int DIB_SetGammaRamp(_THIS, Uint16 *ramp); int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
static int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
#endif
static void DIB_VideoQuit(_THIS); static void DIB_VideoQuit(_THIS);
/* Hardware surface functions */ /* Hardware surface functions */
...@@ -142,10 +140,8 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex) ...@@ -142,10 +140,8 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
device->UnlockHWSurface = DIB_UnlockHWSurface; device->UnlockHWSurface = DIB_UnlockHWSurface;
device->FlipHWSurface = NULL; device->FlipHWSurface = NULL;
device->FreeHWSurface = DIB_FreeHWSurface; device->FreeHWSurface = DIB_FreeHWSurface;
#ifndef NO_GAMMA_SUPPORT
device->SetGammaRamp = DIB_SetGammaRamp; device->SetGammaRamp = DIB_SetGammaRamp;
device->GetGammaRamp = DIB_GetGammaRamp; device->GetGammaRamp = DIB_GetGammaRamp;
#endif
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress; device->GL_GetProcAddress = WIN_GL_GetProcAddress;
...@@ -169,7 +165,6 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex) ...@@ -169,7 +165,6 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
/* Set up the windows message handling functions */ /* Set up the windows message handling functions */
WIN_RealizePalette = DIB_RealizePalette; WIN_RealizePalette = DIB_RealizePalette;
WIN_PaletteChanged = DIB_PaletteChanged; WIN_PaletteChanged = DIB_PaletteChanged;
WIN_SwapGamma = DIB_SwapGamma;
WIN_WinPAINT = DIB_WinPAINT; WIN_WinPAINT = DIB_WinPAINT;
HandleMessage = DIB_HandleMessage; HandleMessage = DIB_HandleMessage;
...@@ -807,7 +802,7 @@ static void DIB_CheckGamma(_THIS) ...@@ -807,7 +802,7 @@ static void DIB_CheckGamma(_THIS)
ReleaseDC(SDL_Window, hdc); ReleaseDC(SDL_Window, hdc);
#endif /* !NO_GAMMA_SUPPORT */ #endif /* !NO_GAMMA_SUPPORT */
} }
static void DIB_SwapGamma(_THIS) void DIB_SwapGamma(_THIS)
{ {
#ifndef NO_GAMMA_SUPPORT #ifndef NO_GAMMA_SUPPORT
HDC hdc; HDC hdc;
...@@ -826,7 +821,7 @@ static void DIB_SwapGamma(_THIS) ...@@ -826,7 +821,7 @@ static void DIB_SwapGamma(_THIS)
} }
#endif /* !NO_GAMMA_SUPPORT */ #endif /* !NO_GAMMA_SUPPORT */
} }
static void DIB_QuitGamma(_THIS) void DIB_QuitGamma(_THIS)
{ {
#ifndef NO_GAMMA_SUPPORT #ifndef NO_GAMMA_SUPPORT
if ( gamma_saved ) { if ( gamma_saved ) {
...@@ -846,10 +841,12 @@ static void DIB_QuitGamma(_THIS) ...@@ -846,10 +841,12 @@ static void DIB_QuitGamma(_THIS)
#endif /* !NO_GAMMA_SUPPORT */ #endif /* !NO_GAMMA_SUPPORT */
} }
#ifndef NO_GAMMA_SUPPORT int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
static int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
{ {
#ifdef NO_GAMMA_SUPPORT
SDL_SetError("SDL compiled without gamma ramp support");
return -1;
#else
HDC hdc; HDC hdc;
BOOL succeeded; BOOL succeeded;
...@@ -872,10 +869,15 @@ static int DIB_SetGammaRamp(_THIS, Uint16 *ramp) ...@@ -872,10 +869,15 @@ static int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
succeeded = TRUE; succeeded = TRUE;
} }
return succeeded ? 0 : -1; return succeeded ? 0 : -1;
#endif /* !NO_GAMMA_SUPPORT */
} }
static int DIB_GetGammaRamp(_THIS, Uint16 *ramp) int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
{ {
#ifdef NO_GAMMA_SUPPORT
SDL_SetError("SDL compiled without gamma ramp support");
return -1;
#else
HDC hdc; HDC hdc;
BOOL succeeded; BOOL succeeded;
...@@ -884,9 +886,8 @@ static int DIB_GetGammaRamp(_THIS, Uint16 *ramp) ...@@ -884,9 +886,8 @@ static int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
succeeded = GetDeviceGammaRamp(hdc, ramp); succeeded = GetDeviceGammaRamp(hdc, ramp);
ReleaseDC(SDL_Window, hdc); ReleaseDC(SDL_Window, hdc);
return succeeded ? 0 : -1; return succeeded ? 0 : -1;
}
#endif /* !NO_GAMMA_SUPPORT */ #endif /* !NO_GAMMA_SUPPORT */
}
void DIB_VideoQuit(_THIS) void DIB_VideoQuit(_THIS)
{ {
......
...@@ -38,14 +38,11 @@ struct SDL_PrivateVideoData { ...@@ -38,14 +38,11 @@ struct SDL_PrivateVideoData {
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ #define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS]; int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS]; SDL_Rect **SDL_modelist[NUM_MODELISTS];
WORD *gamma_saved;
}; };
/* Old variable names */ /* Old variable names */
#define screen_bmp (this->hidden->screen_bmp) #define screen_bmp (this->hidden->screen_bmp)
#define screen_pal (this->hidden->screen_pal) #define screen_pal (this->hidden->screen_pal)
#define SDL_nummodes (this->hidden->SDL_nummodes) #define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist) #define SDL_modelist (this->hidden->SDL_modelist)
#define gamma_saved (this->hidden->gamma_saved)
#endif /* _SDL_dibvideo_h */ #endif /* _SDL_dibvideo_h */
...@@ -404,11 +404,8 @@ static SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); ...@@ -404,11 +404,8 @@ static SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); static SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int DX5_SetColors(_THIS, int firstcolor, int ncolors, static int DX5_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors); SDL_Color *colors);
static void DX5_SwapGamma(_THIS);
#ifdef IDirectDrawGammaControl_SetGammaRamp
static int DX5_SetGammaRamp(_THIS, Uint16 *ramp); static int DX5_SetGammaRamp(_THIS, Uint16 *ramp);
static int DX5_GetGammaRamp(_THIS, Uint16 *ramp); static int DX5_GetGammaRamp(_THIS, Uint16 *ramp);
#endif
static void DX5_VideoQuit(_THIS); static void DX5_VideoQuit(_THIS);
/* Hardware surface functions */ /* Hardware surface functions */
...@@ -430,6 +427,11 @@ static void DX5_RealizePalette(_THIS); ...@@ -430,6 +427,11 @@ static void DX5_RealizePalette(_THIS);
static void DX5_PaletteChanged(_THIS, HWND window); static void DX5_PaletteChanged(_THIS, HWND window);
static void DX5_WinPAINT(_THIS, HDC hdc); static void DX5_WinPAINT(_THIS, HDC hdc);
/* WinDIB driver functions for manipulating gamma ramps */
extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
extern void DIB_QuitGamma(_THIS);
/* DX5 driver bootstrap functions */ /* DX5 driver bootstrap functions */
static int DX5_Available(void) static int DX5_Available(void)
...@@ -591,10 +593,8 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex) ...@@ -591,10 +593,8 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex)
device->UnlockHWSurface = DX5_UnlockHWSurface; device->UnlockHWSurface = DX5_UnlockHWSurface;
device->FlipHWSurface = DX5_FlipHWSurface; device->FlipHWSurface = DX5_FlipHWSurface;
device->FreeHWSurface = DX5_FreeHWSurface; device->FreeHWSurface = DX5_FreeHWSurface;
#ifdef IDirectDrawGammaControl_SetGammaRamp
device->SetGammaRamp = DX5_SetGammaRamp; device->SetGammaRamp = DX5_SetGammaRamp;
device->GetGammaRamp = DX5_GetGammaRamp; device->GetGammaRamp = DX5_GetGammaRamp;
#endif
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress; device->GL_GetProcAddress = WIN_GL_GetProcAddress;
...@@ -618,7 +618,6 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex) ...@@ -618,7 +618,6 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex)
/* Set up the windows message handling functions */ /* Set up the windows message handling functions */
WIN_RealizePalette = DX5_RealizePalette; WIN_RealizePalette = DX5_RealizePalette;
WIN_PaletteChanged = DX5_PaletteChanged; WIN_PaletteChanged = DX5_PaletteChanged;
WIN_SwapGamma = DX5_SwapGamma;
WIN_WinPAINT = DX5_WinPAINT; WIN_WinPAINT = DX5_WinPAINT;
HandleMessage = DX5_HandleMessage; HandleMessage = DX5_HandleMessage;
...@@ -2112,20 +2111,24 @@ int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) ...@@ -2112,20 +2111,24 @@ int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
return(alloct_all); return(alloct_all);
} }
static void DX5_SwapGamma(_THIS)
{
return;
}
/* Gamma code is only available on DirectX 7 and newer */ /* Gamma code is only available on DirectX 7 and newer */
#ifdef IDirectDrawGammaControl_SetGammaRamp
static int DX5_SetGammaRamp(_THIS, Uint16 *ramp) static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
{ {
#ifdef IDirectDrawGammaControl_SetGammaRamp
LPDIRECTDRAWGAMMACONTROL gamma; LPDIRECTDRAWGAMMACONTROL gamma;
DDGAMMARAMP gamma_ramp; DDGAMMARAMP gamma_ramp;
HRESULT result; HRESULT result;
#endif
/* In windowed or OpenGL mode, use windib gamma code */
if ( ! DDRAW_FULLSCREEN() ) {
return DIB_SetGammaRamp(this, ramp);
}
#ifndef IDirectDrawGammaControl_SetGammaRamp
SDL_SetError("SDL compiled without DirectX gamma ramp support");
return -1;
#else
/* Check for a video mode! */ /* Check for a video mode! */
if ( ! SDL_primary ) { if ( ! SDL_primary ) {
SDL_SetError("A video mode must be set for gamma correction"); SDL_SetError("A video mode must be set for gamma correction");
...@@ -2152,14 +2155,26 @@ static int DX5_SetGammaRamp(_THIS, Uint16 *ramp) ...@@ -2152,14 +2155,26 @@ static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
/* Release the interface and return */ /* Release the interface and return */
IDirectDrawGammaControl_Release(gamma); IDirectDrawGammaControl_Release(gamma);
return (result == DD_OK) ? 0 : -1; return (result == DD_OK) ? 0 : -1;
#endif /* !IDirectDrawGammaControl_SetGammaRamp */
} }
static int DX5_GetGammaRamp(_THIS, Uint16 *ramp) static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
{ {
#ifdef IDirectDrawGammaControl_SetGammaRamp
LPDIRECTDRAWGAMMACONTROL gamma; LPDIRECTDRAWGAMMACONTROL gamma;
DDGAMMARAMP gamma_ramp; DDGAMMARAMP gamma_ramp;
HRESULT result; HRESULT result;
#endif
/* In windowed or OpenGL mode, use windib gamma code */
if ( ! DDRAW_FULLSCREEN() ) {
return DIB_GetGammaRamp(this, ramp);
}
#ifndef IDirectDrawGammaControl_SetGammaRamp
SDL_SetError("SDL compiled without DirectX gamma ramp support");
return -1;
#else
/* Check for a video mode! */ /* Check for a video mode! */
if ( ! SDL_primary ) { if ( ! SDL_primary ) {
SDL_SetError("A video mode must be set for gamma correction"); SDL_SetError("A video mode must be set for gamma correction");
...@@ -2187,10 +2202,9 @@ static int DX5_GetGammaRamp(_THIS, Uint16 *ramp) ...@@ -2187,10 +2202,9 @@ static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
/* Release the interface and return */ /* Release the interface and return */
IDirectDrawGammaControl_Release(gamma); IDirectDrawGammaControl_Release(gamma);
return (result == DD_OK) ? 0 : -1; return (result == DD_OK) ? 0 : -1;
#endif /* !IDirectDrawGammaControl_SetGammaRamp */
} }
#endif /* IDirectDrawGammaControl_SetGammaRamp */
void DX5_VideoQuit(_THIS) void DX5_VideoQuit(_THIS)
{ {
int i, j; int i, j;
...@@ -2228,6 +2242,7 @@ void DX5_VideoQuit(_THIS) ...@@ -2228,6 +2242,7 @@ void DX5_VideoQuit(_THIS)
} }
/* Free the window */ /* Free the window */
DIB_QuitGamma(this);
if ( SDL_Window ) { if ( SDL_Window ) {
DX5_DestroyWindow(this); DX5_DestroyWindow(this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment