Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Implemented Win32 video mode support

  • Loading branch information
slouken committed Jul 7, 2006
1 parent 0d18b5a commit 42a8e3b47df14951d4cbbbcb6079e5521f02d0b2
@@ -75,6 +75,7 @@ typedef struct
int w; /**< width */
int h; /**< height */
int refresh_rate; /**< refresh rate (or zero for unspecified) */
void *driverdata; /**< driver-specific data, initialize to 0 */
} SDL_DisplayMode;

/**
@@ -131,6 +131,7 @@ struct SDL_Window
*/
struct SDL_VideoDisplay
{
int max_display_modes;
int num_display_modes;
SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode;
@@ -178,7 +179,7 @@ struct SDL_VideoDevice
* should have their data updated accordingly, including the
* display surfaces associated with them.
*/
int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);

/* Sets the color entries of the display palette to those in 'colors'.
The return value is 0 if all entries could be set properly or -1
@@ -410,8 +411,8 @@ extern VideoBootStrap glSDL_bootstrap;
extern SDL_VideoDevice *SDL_GetVideoDevice();
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
extern void SDL_AddDisplayMode(int displayIndex,
const SDL_DisplayMode * mode);
extern SDL_bool SDL_AddDisplayMode(int displayIndex,
const SDL_DisplayMode * mode);
extern void SDL_AddRenderDriver(int displayIndex,
const SDL_RenderDriver * driver);

@@ -362,7 +362,7 @@ SDL_SelectVideoDisplay(int index)
return _this->current_display;
}

void
SDL_bool
SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
{
SDL_VideoDisplay *display = &_this->displays[displayIndex];
@@ -372,19 +372,27 @@ SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
/* Make sure we don't already have the mode in the list */
modes = display->display_modes;
nmodes = display->num_display_modes;
for (i = 0; i < nmodes; ++i) {
for (i = nmodes; i--;) {
if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
return;
return SDL_FALSE;
}
}

/* Go ahead and add the new mode */
modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode));
if (modes) {
if (nmodes == display->max_display_modes) {
modes =
SDL_realloc(modes,
(display->max_display_modes + 32) * sizeof(*modes));
if (!modes) {
return SDL_FALSE;
}
display->display_modes = modes;
modes[nmodes] = *mode;
display->num_display_modes++;
display->max_display_modes += 32;
}
modes[nmodes] = *mode;
display->num_display_modes++;

return SDL_TRUE;
}

int
@@ -501,6 +509,8 @@ SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
} else {
closest->refresh_rate = mode->refresh_rate;
}
closest->driverdata = match->driverdata;

/* Pick some reasonable defaults if the app and driver don't care */
if (!closest->format) {
closest->format = SDL_PixelFormat_RGB888;
@@ -521,7 +531,7 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
{
SDL_VideoDisplay *display;
SDL_DisplayMode display_mode;
int ncolors;
int i, ncolors;

if (!_this) {
SDL_SetError("Video subsystem has not been initialized");
@@ -562,6 +572,12 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
return 0;
}

/* Actually change the display mode */
if (_this->SetDisplayMode(_this, &display_mode) < 0) {
return -1;
}
display->current_mode = display_mode;

/* Set up a palette, if necessary */
if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
@@ -584,7 +600,17 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
}
}

return _this->SetDisplayMode(_this, &display_mode);
/* Move any fullscreen windows into position */
for (i = 0; i < display->num_windows; ++i) {
SDL_Window *window = &display->windows[i];
if (window->flags & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowPosition(window->id,
((display_mode.w - window->w) / 2),
((display_mode.h - window->h) / 2));
}
}

return 0;
}

int
@@ -662,8 +688,14 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_zero(window);
window.id = _this->next_object_id++;
window.title = title ? SDL_strdup(title) : NULL;
window.x = x;
window.y = y;
if (flags & SDL_WINDOW_FULLSCREEN) {
const SDL_DisplayMode *mode = &SDL_CurrentDisplay.current_mode;
window.x = (mode->w - w) / 2;
window.y = (mode->h - h) / 2;
} else {
window.x = x;
window.y = y;
}
window.w = w;
window.h = h;
window.flags = (flags & allowed_flags);
@@ -1813,14 +1845,34 @@ SDL_VideoQuit(void)
SDL_free(display->windows);
display->windows = NULL;
}
display->num_windows = 0;
}
_this->VideoQuit(_this);

for (i = _this->num_displays; i--;) {
SDL_VideoDisplay *display = &_this->displays[i];
for (j = display->num_display_modes; j--;) {
if (display->display_modes[j].driverdata) {
SDL_free(display->display_modes[j].driverdata);
display->display_modes[j].driverdata = NULL;
}
}
if (display->display_modes) {
SDL_free(display->display_modes);
display->display_modes = NULL;
}
if (display->desktop_mode.driverdata) {
SDL_free(display->desktop_mode.driverdata);
display->desktop_mode.driverdata = NULL;
}
if (display->palette) {
SDL_FreePalette(display->palette);
display->palette = NULL;
}
}
_this->VideoQuit(_this);
if (_this->displays) {
SDL_free(_this->displays);
_this->displays = NULL;
}
_this->free(_this);
_this = NULL;
@@ -50,7 +50,7 @@

/* Initialization/Query functions */
static int DUMMY_VideoInit(_THIS);
static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
static int DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
static void DUMMY_VideoQuit(_THIS);

/* DUMMY driver bootstrap functions */
@@ -120,9 +120,8 @@ DUMMY_VideoInit(_THIS)
}

static int
DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
{
SDL_CurrentDisplay.current_mode = *mode;
return 0;
}

@@ -26,7 +26,7 @@
#include "../../events/SDL_keyboard_c.h"

void
WIN_AddKeyboard(_THIS)
WIN_InitKeyboard(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_Keyboard keyboard;
@@ -36,7 +36,7 @@ WIN_AddKeyboard(_THIS)
}

void
WIN_DelKeyboard(_THIS)
WIN_QuitKeyboard(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

@@ -24,8 +24,8 @@
#ifndef _SDL_win32keyboard_h
#define _SDL_win32keyboard_h

extern void WIN_AddKeyboard(_THIS);
extern void WIN_DelKeyboard(_THIS);
extern void WIN_InitKeyboard(_THIS);
extern void WIN_QuitKeyboard(_THIS);

#endif /* _SDL_win32keyboard_h */

0 comments on commit 42a8e3b

Please sign in to comment.