Skip to content

Commit

Permalink
Fixed gamma ramps in DirectX windowed and OpenGL modes
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Apr 11, 2002
1 parent 5fd81ce commit 37cf260
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/video/wincommon/SDL_lowvideo.h
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
11 changes: 8 additions & 3 deletions src/video/wincommon/SDL_sysevents.c
Expand Up @@ -60,15 +60,16 @@ int posted = 0;
#ifndef NO_CHANGEDISPLAYSETTINGS
DEVMODE SDL_fullscreen_mode;
#endif
WORD *gamma_saved = NULL;


/* Functions called by the message processing function */
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)
{
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
35 changes: 18 additions & 17 deletions src/video/windib/SDL_dibvideo.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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 ) {
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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)
{
Expand Down
3 changes: 0 additions & 3 deletions src/video/windib/SDL_dibvideo.h
Expand Up @@ -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 */
45 changes: 30 additions & 15 deletions src/video/windx5/SDL_dx5video.c
Expand Up @@ -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 */
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2228,6 +2242,7 @@ void DX5_VideoQuit(_THIS)
}

/* Free the window */
DIB_QuitGamma(this);
if ( SDL_Window ) {
DX5_DestroyWindow(this);
}
Expand Down

0 comments on commit 37cf260

Please sign in to comment.