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);
/* Called by windows message loop when the system palette changes */
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 */
extern void (*WIN_WinPAINT)(_THIS, HDC hdc);
......@@ -93,6 +90,9 @@ extern int mouse_relative;
extern DEVMODE SDL_fullscreen_mode;
#endif
/* The system gamma ramp for GDI modes */
extern WORD *gamma_saved;
/* This is really from SDL_dx5audio.c */
extern void DX5_SoundFocus(HWND window);
......
......@@ -60,6 +60,7 @@ int posted = 0;
#ifndef NO_CHANGEDISPLAYSETTINGS
DEVMODE SDL_fullscreen_mode;
#endif
WORD *gamma_saved = NULL;
/* Functions called by the message processing function */
......@@ -67,8 +68,8 @@ LONG
(*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
void (*WIN_RealizePalette)(_THIS);
void (*WIN_PaletteChanged)(_THIS, HWND window);
void (*WIN_SwapGamma)(_THIS);
void (*WIN_WinPAINT)(_THIS, HDC hdc);
extern void DIB_SwapGamma(_THIS);
static void SDL_RestoreGameMode(void)
{
......@@ -198,7 +199,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WIN_GrabInput(this, SDL_GRAB_ON);
}
if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
WIN_SwapGamma(this);
if ( ! DDRAW_FULLSCREEN() ) {
DIB_SwapGamma(this);
}
if ( WINDIB_FULLSCREEN() ) {
SDL_RestoreGameMode();
}
......@@ -215,7 +218,9 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WIN_GrabInput(this, SDL_GRAB_OFF);
}
if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
WIN_SwapGamma(this);
if ( ! DDRAW_FULLSCREEN() ) {
DIB_SwapGamma(this);
}
if ( WINDIB_FULLSCREEN() ) {
SDL_RestoreDesktopMode();
}
......
......@@ -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,
SDL_Color *colors);
static void DIB_CheckGamma(_THIS);
static void DIB_SwapGamma(_THIS);
static void DIB_QuitGamma(_THIS);
#ifndef NO_GAMMA_SUPPORT
static int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
static int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
#endif
void DIB_SwapGamma(_THIS);
void DIB_QuitGamma(_THIS);
int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
static void DIB_VideoQuit(_THIS);
/* Hardware surface functions */
......@@ -142,10 +140,8 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
device->UnlockHWSurface = DIB_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = DIB_FreeHWSurface;
#ifndef NO_GAMMA_SUPPORT
device->SetGammaRamp = DIB_SetGammaRamp;
device->GetGammaRamp = DIB_GetGammaRamp;
#endif
#ifdef HAVE_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress;
......@@ -169,7 +165,6 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
/* Set up the windows message handling functions */
WIN_RealizePalette = DIB_RealizePalette;
WIN_PaletteChanged = DIB_PaletteChanged;
WIN_SwapGamma = DIB_SwapGamma;
WIN_WinPAINT = DIB_WinPAINT;
HandleMessage = DIB_HandleMessage;
......@@ -807,7 +802,7 @@ static void DIB_CheckGamma(_THIS)
ReleaseDC(SDL_Window, hdc);
#endif /* !NO_GAMMA_SUPPORT */
}
static void DIB_SwapGamma(_THIS)
void DIB_SwapGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
HDC hdc;
......@@ -826,7 +821,7 @@ static void DIB_SwapGamma(_THIS)
}
#endif /* !NO_GAMMA_SUPPORT */
}
static void DIB_QuitGamma(_THIS)
void DIB_QuitGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
if ( gamma_saved ) {
......@@ -846,10 +841,12 @@ static void DIB_QuitGamma(_THIS)
#endif /* !NO_GAMMA_SUPPORT */
}
#ifndef NO_GAMMA_SUPPORT
static int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef NO_GAMMA_SUPPORT
SDL_SetError("SDL compiled without gamma ramp support");
return -1;
#else
HDC hdc;
BOOL succeeded;
......@@ -872,10 +869,15 @@ static int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
succeeded = TRUE;
}
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;
BOOL succeeded;
......@@ -884,9 +886,8 @@ static int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
succeeded = GetDeviceGammaRamp(hdc, ramp);
ReleaseDC(SDL_Window, hdc);
return succeeded ? 0 : -1;
}
#endif /* !NO_GAMMA_SUPPORT */
}
void DIB_VideoQuit(_THIS)
{
......
......@@ -38,14 +38,11 @@ struct SDL_PrivateVideoData {
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
WORD *gamma_saved;
};
/* Old variable names */
#define screen_bmp (this->hidden->screen_bmp)
#define screen_pal (this->hidden->screen_pal)
#define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist)
#define gamma_saved (this->hidden->gamma_saved)
#endif /* _SDL_dibvideo_h */
......@@ -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 int DX5_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors);
static void DX5_SwapGamma(_THIS);
#ifdef IDirectDrawGammaControl_SetGammaRamp
static int DX5_SetGammaRamp(_THIS, Uint16 *ramp);
static int DX5_GetGammaRamp(_THIS, Uint16 *ramp);
#endif
static void DX5_VideoQuit(_THIS);
/* Hardware surface functions */
......@@ -430,6 +427,11 @@ static void DX5_RealizePalette(_THIS);
static void DX5_PaletteChanged(_THIS, HWND window);
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 */
static int DX5_Available(void)
......@@ -591,10 +593,8 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex)
device->UnlockHWSurface = DX5_UnlockHWSurface;
device->FlipHWSurface = DX5_FlipHWSurface;
device->FreeHWSurface = DX5_FreeHWSurface;
#ifdef IDirectDrawGammaControl_SetGammaRamp
device->SetGammaRamp = DX5_SetGammaRamp;
device->GetGammaRamp = DX5_GetGammaRamp;
#endif
#ifdef HAVE_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress;
......@@ -618,7 +618,6 @@ static SDL_VideoDevice *DX5_CreateDevice(int devindex)
/* Set up the windows message handling functions */
WIN_RealizePalette = DX5_RealizePalette;
WIN_PaletteChanged = DX5_PaletteChanged;
WIN_SwapGamma = DX5_SwapGamma;
WIN_WinPAINT = DX5_WinPAINT;
HandleMessage = DX5_HandleMessage;
......@@ -2112,20 +2111,24 @@ int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
return(alloct_all);
}
static void DX5_SwapGamma(_THIS)
{
return;
}
/* Gamma code is only available on DirectX 7 and newer */
#ifdef IDirectDrawGammaControl_SetGammaRamp
static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef IDirectDrawGammaControl_SetGammaRamp
LPDIRECTDRAWGAMMACONTROL gamma;
DDGAMMARAMP gamma_ramp;
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! */
if ( ! SDL_primary ) {
SDL_SetError("A video mode must be set for gamma correction");
......@@ -2152,14 +2155,26 @@ static int DX5_SetGammaRamp(_THIS, Uint16 *ramp)
/* Release the interface and return */
IDirectDrawGammaControl_Release(gamma);
return (result == DD_OK) ? 0 : -1;
#endif /* !IDirectDrawGammaControl_SetGammaRamp */
}
static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef IDirectDrawGammaControl_SetGammaRamp
LPDIRECTDRAWGAMMACONTROL gamma;
DDGAMMARAMP gamma_ramp;
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! */
if ( ! SDL_primary ) {
SDL_SetError("A video mode must be set for gamma correction");
......@@ -2187,10 +2202,9 @@ static int DX5_GetGammaRamp(_THIS, Uint16 *ramp)
/* Release the interface and return */
IDirectDrawGammaControl_Release(gamma);
return (result == DD_OK) ? 0 : -1;
#endif /* !IDirectDrawGammaControl_SetGammaRamp */
}
#endif /* IDirectDrawGammaControl_SetGammaRamp */
void DX5_VideoQuit(_THIS)
{
int i, j;
......@@ -2228,6 +2242,7 @@ void DX5_VideoQuit(_THIS)
}
/* Free the window */
DIB_QuitGamma(this);
if ( SDL_Window ) {
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