Mercurial > sdl-ios-xcode
diff src/video/SDL_gamma.c @ 3500:4b594623401b
Work in progress on multi-display support:
* Added display parameter to many internal functions so video modes can be set on displays that aren't the public current one.
* The fullscreen mode is associated with fullscreen windows - not displays, so different windows more naturally have a mode associated with them based on their width and height. It's no longer necessary to specify a fullscreen mode, a default one will be picked automatically for fullscreen windows.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Dec 2009 05:57:15 +0000 |
parents | 62d4992e5a92 |
children | 64ce267332c6 |
line wrap: on
line diff
--- a/src/video/SDL_gamma.c Mon Nov 30 21:04:25 2009 +0000 +++ b/src/video/SDL_gamma.c Tue Dec 01 05:57:15 2009 +0000 @@ -113,30 +113,39 @@ return succeeded; } +static void +SDL_UninitializedVideo() +{ + SDL_SetError("Video subsystem has not been initialized"); +} + int -SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, - const Uint16 * blue) +SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); int succeeded; + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + /* Lazily allocate the gamma tables */ - if (!SDL_CurrentDisplay.gamma) { - SDL_GetGammaRamp(NULL, NULL, NULL); + if (!display->gamma) { + if (SDL_GetGammaRampForDisplay(display, NULL, NULL, NULL) < 0) { + return -1; + } } /* Fill the gamma table with the new values */ if (red) { - SDL_memcpy(&SDL_CurrentDisplay.gamma[0 * 256], red, - 256 * sizeof(*SDL_CurrentDisplay.gamma)); + SDL_memcpy(&display->gamma[0 * 256], red, 256 * sizeof(*display->gamma)); } if (green) { - SDL_memcpy(&SDL_CurrentDisplay.gamma[1 * 256], green, - 256 * sizeof(*SDL_CurrentDisplay.gamma)); + SDL_memcpy(&display->gamma[1 * 256], green, 256 * sizeof(*display->gamma)); } if (blue) { - SDL_memcpy(&SDL_CurrentDisplay.gamma[2 * 256], blue, - 256 * sizeof(*SDL_CurrentDisplay.gamma)); + SDL_memcpy(&display->gamma[2 * 256], blue, 256 * sizeof(*display->gamma)); } /* Try to set the gamma ramp in the driver */ @@ -144,7 +153,7 @@ if (_this && _this->SetDisplayGammaRamp) { if (SDL_GetFocusWindow()) { succeeded = - _this->SetDisplayGammaRamp(_this, SDL_CurrentDisplay.gamma); + _this->SetDisplayGammaRamp(_this, display, display->gamma); } else { succeeded = 0; } @@ -155,50 +164,73 @@ } int -SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) +SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_SetGammaRampForDisplay(&SDL_CurrentDisplay, red, green, blue); +} + +int +SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + /* Lazily allocate the gamma table */ - if (!SDL_CurrentDisplay.gamma) { - size_t rampsize = (3 * 256 * sizeof(*SDL_CurrentDisplay.gamma)); + if (!display->gamma) { + size_t rampsize = (3 * 256 * sizeof(*display->gamma)); - SDL_CurrentDisplay.gamma = SDL_malloc(rampsize * 2); - if (!SDL_CurrentDisplay.gamma) { + display->gamma = SDL_malloc(rampsize * 2); + if (!display->gamma) { SDL_OutOfMemory(); return -1; } if (_this && _this->GetDisplayGammaRamp) { /* Get the real hardware gamma */ - _this->GetDisplayGammaRamp(_this, SDL_CurrentDisplay.gamma); + _this->GetDisplayGammaRamp(_this, display, display->gamma); } else { /* Assume an identity gamma */ int i; for (i = 0; i < 256; ++i) { - SDL_CurrentDisplay.gamma[0 * 256 + i] = (i << 8) | i; - SDL_CurrentDisplay.gamma[1 * 256 + i] = (i << 8) | i; - SDL_CurrentDisplay.gamma[2 * 256 + i] = (i << 8) | i; + display->gamma[0 * 256 + i] = (i << 8) | i; + display->gamma[1 * 256 + i] = (i << 8) | i; + display->gamma[2 * 256 + i] = (i << 8) | i; } } - SDL_CurrentDisplay.saved_gamma = SDL_CurrentDisplay.gamma + (3 * 256); - SDL_memcpy(SDL_CurrentDisplay.saved_gamma, SDL_CurrentDisplay.gamma, - rampsize); + display->saved_gamma = display->gamma + (3 * 256); + SDL_memcpy(display->saved_gamma, display->gamma, rampsize); } /* Just copy from our internal table */ if (red) { - SDL_memcpy(red, &SDL_CurrentDisplay.gamma[0 * 256], - 256 * sizeof(*red)); + SDL_memcpy(red, &display->gamma[0 * 256], 256 * sizeof(*red)); } if (green) { - SDL_memcpy(green, &SDL_CurrentDisplay.gamma[1 * 256], - 256 * sizeof(*green)); + SDL_memcpy(green, &display->gamma[1 * 256], 256 * sizeof(*green)); } if (blue) { - SDL_memcpy(blue, &SDL_CurrentDisplay.gamma[2 * 256], - 256 * sizeof(*blue)); + SDL_memcpy(blue, &display->gamma[2 * 256], 256 * sizeof(*blue)); } return 0; } +int +SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_GetGammaRampForDisplay(&SDL_CurrentDisplay, red, green, blue); +} + /* vi: set ts=4 sw=4 expandtab: */