Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.

SDL_SetVideoMode() now accepts 0 for width or height and will use the current video mode (or the desktop mode if no mode has been set.)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401549
This commit is contained in:
Sam Lantinga 2006-03-15 17:46:41 +00:00
parent 5ab1844363
commit ab022a8987
33 changed files with 140 additions and 37 deletions

View File

@ -4,7 +4,15 @@ This is a list of API changes in SDL's version history.
Version 1.0:
1.2.10:
Added current_w and current_h to the SDL_VideoInfo structure,
which is set to the desktop resolution during video intialization,
and then set to the current resolution when a video mode is set.
SDL_SetVideoMode() now accepts 0 for width or height and will use
the current video mode (or the desktop mode if no mode has been set.)
Added SDL_GetKeyRepeat()
Added SDL_config.h, with defaults for various build environments.
1.2.7:

View File

@ -161,6 +161,8 @@ typedef struct SDL_VideoInfo {
Uint32 UnusedBits3 :16;
Uint32 video_mem; /* The total amount of video memory (in K) */
SDL_PixelFormat *vfmt; /* Value: The format of the video surface */
int current_w; /* Value: The current video mode width */
int current_h; /* Value: The current video mode height */
} SDL_VideoInfo;

View File

@ -587,6 +587,13 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
}
this = video = current_video;
/* Default to the current width and height */
if ( width == 0 ) {
width = video->info.current_w;
}
if ( height == 0 ) {
height = video->info.current_h;
}
/* Default to the current video bpp */
if ( bpp == 0 ) {
flags |= SDL_ANYFORMAT;
@ -889,6 +896,8 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
SDL_PublicSurface = SDL_VideoSurface;
}
video->info.vfmt = SDL_VideoSurface->format;
video->info.current_w = SDL_VideoSurface->w;
video->info.current_h = SDL_VideoSurface->h;
/* We're done! */
return(SDL_PublicSurface);

View File

@ -275,6 +275,8 @@ int BE_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Save the current display mode */
bscreen.GetMode(&saved_mode);
_this->info.current_w = saved_mode.virtual_width;
_this->info.current_h = saved_mode.virtual_height;
/* Determine the screen depth */
vformat->BitsPerPixel = ColorSpaceToBitsPerPixel(bscreen.ColorSpace());

View File

@ -463,6 +463,8 @@ static int CGX_VideoInit(_THIS, SDL_PixelFormat *vformat)
SDL_SetError("Couldn't lock the display");
return(-1);
}
this->info.current_w = SDL_Display->Width;
this->info.current_h = SDL_Display->Height;
D(bug("Checking if we are using a CGX native display...\n"));
@ -834,8 +836,6 @@ int CGX_CreateWindow(_THIS, SDL_Surface *screen,
if( !SDL_windowid ) {
CGX_SetSizeHints(this, w, h, flags);
current_w = w;
current_h = h;
}
/* Set our colormaps when not setting a GL mode */
@ -885,8 +885,6 @@ int CGX_ResizeWindow(_THIS,
if ( ! SDL_windowid ) {
/* Resize the window manager window */
CGX_SetSizeHints(this, w, h, flags);
current_w = w;
current_h = h;
ChangeWindowBox(SDL_Window,SDL_Window->LeftEdge,SDL_Window->TopEdge, w+SDL_Window->BorderLeft+SDL_Window->BorderRight,
h+SDL_Window->BorderTop+SDL_Window->BorderBottom);

View File

@ -67,10 +67,6 @@ struct SDL_PrivateVideoData {
Uint8 *Ximage; /* The X image for our window */
int swap_pixels; /* Flag: true if display is swapped endian */
/* The current width and height of the fullscreen mode */
int current_w;
int current_h;
/* Support for internal mouse warping */
struct {
int x;
@ -132,8 +128,6 @@ struct SDL_PrivateVideoData {
#define SDL_Ximage (this->hidden->Ximage)
#define SDL_GC (this->hidden->gc)
#define swap_pixels (this->hidden->swap_pixels)
#define current_w (this->hidden->current_w)
#define current_h (this->hidden->current_h)
#define mouse_last (this->hidden->mouse_last)
#define mouse_accel (this->hidden->mouse_accel)
#define mouse_relative (this->hidden->mouse_relative)

View File

@ -349,6 +349,10 @@ static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
DGA_event_base = event_base;
/* Determine the current screen size */
this->info.current_w = DisplayWidth(DGA_Display, DGA_Screen);
this->info.current_h = DisplayHeight(DGA_Display, DGA_Screen);
/* Determine the current screen depth */
visual = DefaultVisual(DGA_Display, DGA_Screen);
{

View File

@ -291,6 +291,9 @@ int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
#endif /* __WINS__ */
_this->info.current_w = Private->EPOC_ScreenSize.iWidth;
_this->info.current_h = Private->EPOC_ScreenSize.iHeight;
/* The "best" video format should be returned to caller. */
vformat->BitsPerPixel = /*!!GetBpp(displayMode) */ 8;

View File

@ -636,6 +636,8 @@ static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
/* Fill in our hardware acceleration capabilities */
this->info.current_w = current_w;
this->info.current_h = current_h;
this->info.wm_available = 0;
this->info.hw_available = 1;
this->info.video_mem = finfo.smem_len/1024;

View File

@ -529,6 +529,10 @@ int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);
}
/* Determine the current screen size */
this->info.current_w = gapi->gxProperties.cxWidth;
this->info.current_h = gapi->gxProperties.cyHeight;
/* Sort the mode lists */
for ( i=0; i<NUM_MODELISTS; ++i ) {
if ( gapi->SDL_nummodes[i] > 0 ) {

View File

@ -430,9 +430,9 @@ int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Setup destination mfdb */
VDI_dst_mfdb.fd_addr = NULL;
/* Update hardware info */
this->info.hw_available = 0;
this->info.video_mem = 0;
/* Determine the current screen size */
this->info.current_w = VDI_w;
this->info.current_h = VDI_h;
/* Determine the screen depth */
/* we change this during the SDL_SetVideoMode implementation... */

View File

@ -197,6 +197,10 @@ int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat)
GGI_VideoQuit(NULL);
}
/* Determine the current screen size */
this->info.current_w = mode.virt.x;
this->info.current_h = mode.virt.y;
/* Set a palette for palletized modes */
if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
{

View File

@ -287,6 +287,10 @@ static int iPod_VideoInit (_THIS, SDL_PixelFormat *vformat)
fcntl (kbfd, F_SETFL, O_RDWR | O_NONBLOCK);
/* Determine the current screen size */
this->info.current_w = lcd_width;
this->info.current_h = lcd_height;
if ((generation >= 60000) && (generation < 70000)) {
vformat->BitsPerPixel = 16;
vformat->Rmask = 0xF800;

View File

@ -329,7 +329,7 @@ VideoBootStrap DSp_bootstrap = {
};
/* Use DSp/Display Manager to build mode list for given screen */
static SDL_Rect** DSp_BuildModeList (const GDHandle gDevice)
static SDL_Rect** DSp_BuildModeList (const GDHandle gDevice, int *displayWidth, int *displayHeight)
{
DSpContextAttributes attributes;
DSpContextReference context;
@ -355,6 +355,9 @@ static SDL_Rect** DSp_BuildModeList (const GDHandle gDevice)
if ( DSpContext_GetAttributes (context, &attributes) != noErr )
return NULL;
*displayWidth = attributes.displayWidth;
*displayHeight = attributes.displayHeight;
for ( i = 0; i < SDL_arraysize(temp_list); i++ ) {
width = attributes.displayWidth;
@ -556,14 +559,14 @@ static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat)
break;
}
if ( DSp_CreatePalette (this) < 0 ) {
SDL_SetError ("Could not create palette");
return (-1);
}
if ( DSp_CreatePalette (this) < 0 ) {
SDL_SetError ("Could not create palette");
return (-1);
}
/* Get a list of available fullscreen modes */
SDL_modelist = DSp_BuildModeList (SDL_Display);
SDL_modelist = DSp_BuildModeList (SDL_Display,
&this->info.current_w, &this->info.current_h);
if (SDL_modelist == NULL) {
SDL_SetError ("DrawSprocket could not build a mode list");
return (-1);

View File

@ -203,6 +203,10 @@ static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Get a handle to the main monitor */
SDL_Display = GetMainDevice();
/* Determine the current screen size */
this->info.current_w = (**SDL_Display).gdRect.right;
this->info.current_h = (**SDL_Display).gdRect.bottom;
/* Determine pixel format */
vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize;
switch (vformat->BitsPerPixel) {

View File

@ -209,6 +209,10 @@ int NX_VideoInit (_THIS, SDL_PixelFormat * vformat)
GrGetScreenInfo (& si) ;
SDL_Visual.bpp = si.bpp ;
/* Determine the current screen size */
this->info.current_w = si.cols ;
this->info.current_h = si.rows ;
// GetVideoMode
SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ;
if (SDL_modelist) {

View File

@ -2724,6 +2724,10 @@ static int os2fslib_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
/* Determine the current screen size */
_this->info.current_w = 0; // FIXME!
_this->info.current_h = 0; // FIXME!
/* Determine the screen depth */
vformat->BitsPerPixel = pDesktopMode->uiBPP;
vformat->BytesPerPixel = (vformat->BitsPerPixel+7)/8;

View File

@ -400,6 +400,10 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat)
return -1;
}
/* Determine the current screen size */
this->info.current_w = desktop_mode.width;
this->info.current_h = desktop_mode.height;
/* We need to return BytesPerPixel as it in used by CreateRGBsurface */
vformat->BitsPerPixel = desktop_mode.bits_per_pixel;
vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width;

View File

@ -166,6 +166,10 @@ int PG_VideoInit(_THIS, SDL_PixelFormat *vformat)
PG_InitEvents(this);
/* Determine the current screen size */
this->info.current_w = this->hidden->mi.lxres;
this->info.current_h = this->hidden->mi.lyres;
/* Determine the screen depth.
* We change this during the SDL_SetVideoMode implementation...
* Round up to the nearest Bytes per pixel

View File

@ -298,7 +298,6 @@ static int GS_VideoInit(_THIS, SDL_PixelFormat *vformat)
return(-1);
}
/* Determine the current screen depth */
if ( ioctl(console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0 ) {
close(memory_fd);
close(console_fd);
@ -306,6 +305,12 @@ static int GS_VideoInit(_THIS, SDL_PixelFormat *vformat)
SDL_SetError("Couldn't get console pixel format");
return(-1);
}
/* Determine the current screen size */
this->info.current_w = vinfo.w;
this->info.current_h = vinfo.h;
/* Determine the current screen depth */
switch (vinfo.psm) {
/* Supported pixel formats */
case PS2_GS_PSMCT32:

View File

@ -226,6 +226,10 @@ extern "C" {
QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1,
desktop_size.height(), desktop_size.width());
/* Determine the current screen size */
this->info.current_w = desktop_size.width();
this->info.current_h = desktop_size.height();
/* Create the window / widget */
SDL_Win = new SDL_QWin(QSize(QT_HIDDEN_SIZE, QT_HIDDEN_SIZE));
((QPEApplication*)qApp)->showMainWidget(SDL_Win);

View File

@ -200,6 +200,11 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayHeight),
kCFNumberSInt32Type, &device_height);
/* Determine the current screen size */
this->info.current_w = device_width;
this->info.current_h = device_height;
/* Determine the default screen depth */
video_format->BitsPerPixel = device_bpp;
/* Set misc globals */

View File

@ -175,6 +175,10 @@ int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
_kernel_swi(OS_ReadModeVariable, &regs, &regs);
vformat->BitsPerPixel = (1 << regs.r[2]);
/* Determine the current screen size */
this->info.current_w = 0; /* FIXME! */
this->info.current_h = 0; /* FIXME! */
/* Minimum bpp for SDL is 8 */
if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8;

View File

@ -257,6 +257,10 @@ int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
keyboard_seteventhandler(SVGA_keyboardcallback);
/* Determine the current screen size */
this->info.current_w = 0;
this->info.current_h = 0;
/* Determine the screen depth (use default 8-bit depth) */
vformat->BitsPerPixel = 8;

View File

@ -257,6 +257,12 @@ int VGL_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
/* Determine the current screen size */
if (VGLCurMode != NULL) {
this->info.current_w = VGLCurMode->ModeInfo.Xsize;
this->info.current_h = VGLCurMode->ModeInfo.Ysize;
}
/* Determine the screen depth */
if (VGLCurMode != NULL)
vformat->BitsPerPixel = VGLCurMode->Depth;

View File

@ -334,6 +334,8 @@ int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat)
#endif
/* Query for the desktop resolution */
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
this->info.current_w = SDL_desktop_mode.dmPelsWidth;
this->info.current_h = SDL_desktop_mode.dmPelsHeight;
/* Query for the list of available video modes */
for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) {

View File

@ -930,6 +930,8 @@ int DX5_VideoInit(_THIS, SDL_PixelFormat *vformat)
#ifndef NO_CHANGEDISPLAYSETTINGS
/* Query for the desktop resolution */
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
this->info.current_w = SDL_desktop_mode.dmPelsWidth;
this->info.current_h = SDL_desktop_mode.dmPelsHeight;
#endif
/* Enumerate the available fullscreen modes */

View File

@ -300,6 +300,9 @@ int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat)
height = private->info.height;
}
this->info.current_w = width;
this->info.current_h = height;
if (private->shadowFB) {
private->shadowmem = (Uint8 *)SDL_malloc(len);
if (private->shadowmem == NULL) {

View File

@ -652,21 +652,21 @@ int X11_ResizeFullScreen(_THIS)
if ( currently_fullscreen ) {
/* Switch resolution and cover it with the FSwindow */
move_cursor_to(this, x, y);
set_best_resolution(this, current_w, current_h);
set_best_resolution(this, window_w, window_h);
move_cursor_to(this, x, y);
get_real_resolution(this, &real_w, &real_h);
if ( current_w > real_w ) {
if ( window_w > real_w ) {
real_w = MAX(real_w, screen_w);
}
if ( current_h > real_h ) {
if ( window_h > real_h ) {
real_h = MAX(real_h, screen_h);
}
pXMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
move_cursor_to(this, real_w/2, real_h/2);
/* Center and reparent the drawing window */
x = (real_w - current_w)/2;
y = (real_h - current_h)/2;
x = (real_w - window_w)/2;
y = (real_h - window_h)/2;
pXReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
/* FIXME: move the mouse to the old relative location */
pXSync(SDL_Display, True); /* Flush spurious mode change events */
@ -706,10 +706,10 @@ int X11_EnterFullScreen(_THIS)
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
get_real_resolution(this, &real_w, &real_h);
if ( current_w > real_w ) {
if ( window_w > real_w ) {
real_w = MAX(real_w, screen_w);
}
if ( current_h > real_h ) {
if ( window_h > real_h ) {
real_h = MAX(real_h, screen_h);
}
pXMoveResizeWindow(SDL_Display, FSwindow,

View File

@ -508,6 +508,10 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
if(X11_GetVideoModes(this) < 0)
return -1;
/* Determine the current screen size */
this->info.current_w = DisplayWidth(SDL_Display, SDL_Screen);
this->info.current_h = DisplayHeight(SDL_Display, SDL_Screen);
/* Determine the default screen depth:
Use the default visual (or at least one with the same depth) */
SDL_DisplayColormap = DefaultColormap(SDL_Display, SDL_Screen);
@ -863,8 +867,8 @@ static int X11_CreateWindow(_THIS, SDL_Surface *screen,
/* resize the (possibly new) window manager window */
if( !SDL_windowid ) {
X11_SetSizeHints(this, w, h, flags);
current_w = w;
current_h = h;
window_w = w;
window_h = h;
pXResizeWindow(SDL_Display, WMwindow, w, h);
}
@ -985,8 +989,8 @@ static int X11_ResizeWindow(_THIS,
if ( ! SDL_windowid ) {
/* Resize the window manager window */
X11_SetSizeHints(this, w, h, flags);
current_w = w;
current_h = h;
window_w = w;
window_h = h;
pXResizeWindow(SDL_Display, WMwindow, w, h);
/* Resize the fullscreen and display windows */

View File

@ -76,8 +76,8 @@ struct SDL_PrivateVideoData {
GC gc; /* The graphic context for drawing */
/* The current width and height of the fullscreen mode */
int current_w;
int current_h;
int window_w;
int window_h;
/* Support for internal mouse warping */
struct {
@ -159,8 +159,8 @@ struct SDL_PrivateVideoData {
#define shminfo (this->hidden->shminfo)
#define SDL_Ximage (this->hidden->Ximage)
#define SDL_GC (this->hidden->gc)
#define current_w (this->hidden->current_w)
#define current_h (this->hidden->current_h)
#define window_w (this->hidden->window_w)
#define window_h (this->hidden->window_h)
#define mouse_last (this->hidden->mouse_last)
#define mouse_accel (this->hidden->mouse_accel)
#define mouse_relative (this->hidden->mouse_relative)

View File

@ -416,6 +416,12 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
break;
}
/* Determine the current screen size */
if ( XBIOS_nummodes > 0 ) {
this->info.current_w = XBIOS_modelist[0].width;
this->info.current_h = XBIOS_modelist[0].height;
}
current_mode = XBIOS_modelist;
j8 = j16 = 0;
for (i=0; i<XBIOS_nummodes; i++, current_mode++) {

View File

@ -400,7 +400,8 @@ int main(int argc, char *argv[])
}
info = SDL_GetVideoInfo();
printf(
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
"Current display: %dx%d, %d bits-per-pixel\n",
info->current_w, info->current_h, info->vfmt->BitsPerPixel);
if ( info->vfmt->palette == NULL ) {
printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);