Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Work in progress on multi-display support:
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
slouken committed Dec 1, 2009
1 parent a04f7fe commit 7ada394
Show file tree
Hide file tree
Showing 29 changed files with 431 additions and 470 deletions.
17 changes: 10 additions & 7 deletions include/SDL_video.h
Expand Up @@ -50,7 +50,8 @@ extern "C" {
* \sa SDL_GetDesktopDisplayMode()
* \sa SDL_GetCurrentDisplayMode()
* \sa SDL_GetClosestDisplayMode()
* \sa SDL_SetDisplayMode()
* \sa SDL_SetWindowDisplayMode()
* \sa SDL_GetWindowDisplayMode()
*/
typedef struct
{
Expand Down Expand Up @@ -427,23 +428,25 @@ extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const

/**
* \brief Set the display mode used when a fullscreen window is visible
* on the currently selected display.
* on the currently selected display. By default the window's
* dimensions and the desktop format and refresh rate are used.
*
* \param mode The mode to use, or NULL for the desktop mode.
* \param mode The mode to use, or NULL for the default mode.
*
* \return 0 on success, or -1 if setting the display mode failed.
*
* \sa SDL_SetWindowFullscreen()
*/
extern DECLSPEC int SDLCALL SDL_SetFullscreenDisplayMode(const SDL_DisplayMode
extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_WindowID windowID,
const SDL_DisplayMode
* mode);

/**
* \brief Fill in information about the display mode used when a fullscreen
* window is visible on the currently selected display.
*/
extern DECLSPEC int SDLCALL SDL_GetFullscreenDisplayMode(SDL_DisplayMode *
mode);
extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_WindowID windowID,
SDL_DisplayMode * mode);

/**
* \brief Set the palette entries for indexed display modes.
Expand Down Expand Up @@ -680,7 +683,7 @@ extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_WindowID windowID);
*
* \return 0 on success, or -1 if setting the display mode failed.
*
* \sa SDL_SetFullscreenDisplayMode()
* \sa SDL_WindowDisplayMode()
*/
extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_WindowID windowID,
int fullscreen);
Expand Down
14 changes: 6 additions & 8 deletions src/SDL_compat.c
Expand Up @@ -482,7 +482,6 @@ SDL_Surface *
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
SDL_DisplayMode desktop_mode;
SDL_DisplayMode mode;
int window_x = SDL_WINDOWPOS_UNDEFINED;
int window_y = SDL_WINDOWPOS_UNDEFINED;
Uint32 window_flags;
Expand Down Expand Up @@ -552,7 +551,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
window_flags |= SDL_WINDOW_BORDERLESS;
}
GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
SDL_SetFullscreenDisplayMode(NULL);
SDL_VideoWindow =
SDL_CreateWindow(wm_title, window_x, window_y, width, height,
window_flags);
Expand Down Expand Up @@ -611,14 +609,14 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
return NULL;
}
}
mode.format = desired_format;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;

/* Set the desired display mode */
/* Set up the desired display mode */
if (flags & SDL_FULLSCREEN) {
if (SDL_SetFullscreenDisplayMode(&mode) < 0) {
SDL_DisplayMode mode;

SDL_zero(mode);
mode.format = desired_format;
if (SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode) < 0) {
return NULL;
}
}
Expand Down
90 changes: 61 additions & 29 deletions src/video/SDL_gamma.c
Expand Up @@ -113,38 +113,47 @@ SDL_GetGamma(float *red, float *green, float *blue)
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 */
succeeded = -1;
if (_this && _this->SetDisplayGammaRamp) {
if (SDL_GetFocusWindow()) {
succeeded =
_this->SetDisplayGammaRamp(_this, SDL_CurrentDisplay.gamma);
_this->SetDisplayGammaRamp(_this, display, display->gamma);
} else {
succeeded = 0;
}
Expand All @@ -155,50 +164,73 @@ SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green,
}

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: */
32 changes: 21 additions & 11 deletions src/video/SDL_sysvideo.h
Expand Up @@ -139,6 +139,8 @@ struct SDL_Window
int display;
SDL_Renderer *renderer;

SDL_DisplayMode fullscreen_mode;

void *userdata;
void *driverdata;
};
Expand All @@ -158,7 +160,6 @@ struct SDL_VideoDisplay
SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode;
SDL_DisplayMode current_mode;
SDL_DisplayMode fullscreen_mode;
SDL_Palette *palette;

Uint16 *gamma;
Expand Down Expand Up @@ -213,27 +214,27 @@ struct SDL_VideoDevice
* Get a list of the available display modes. e.g.
* SDL_AddDisplayMode(_this->current_display, mode)
*/
void (*GetDisplayModes) (_THIS);
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);

/*
* Setting the display mode is independent of creating windows, so
* when the display mode is changed, all existing windows should have
* their data updated accordingly, including the display surfaces
* associated with them.
*/
int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);

/* Set the color entries of the display palette */
int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
int (*SetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);

/* Get the color entries of the display palette */
int (*GetDisplayPalette) (_THIS, SDL_Palette * palette);
int (*GetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);

/* Set the gamma ramp */
int (*SetDisplayGammaRamp) (_THIS, Uint16 * ramp);
int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);

/* Get the gamma ramp */
int (*GetDisplayGammaRamp) (_THIS, Uint16 * ramp);
int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);

/* * * */
/*
Expand Down Expand Up @@ -405,10 +406,19 @@ extern VideoBootStrap PND_bootstrap;
extern SDL_VideoDevice *SDL_GetVideoDevice();
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
extern SDL_bool
SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode);
extern void
SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
extern int SDL_SetDisplayPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors);
extern int SDL_GetDisplayPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors);
extern void SDL_AddRenderDriver(SDL_VideoDisplay *display, const SDL_RenderDriver * driver);

extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue);
extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue);

extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
Expand Down

0 comments on commit 7ada394

Please sign in to comment.