Commit f1867eeb authored by Patrice Mandin's avatar Patrice Mandin

[PATCH] SDL_GetVideoMode() do not find the best video mode

The current GetVideoMode() function stops at the first mode which has any
dimensions smaller than the one asked, and gives the previous in the list.

If I ask 336x224 with this list:
768x480 768x240 640x400 640x200 384x480 384x240 320x400 320x200
SDL will give me 640x400, because 640x200 as height smaller than what I
asked.

However the best mode is the smaller which has both dimensions bigger
than the one asked (384x240 in my example).

This patch fixes this, plus it does not rely on a sorted video mode list.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401077
parent 7dc6f6ec
...@@ -462,33 +462,29 @@ static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags) ...@@ -462,33 +462,29 @@ static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags)
SDL_closest_depths[table][0] = *BitsPerPixel; SDL_closest_depths[table][0] = *BitsPerPixel;
SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
int best;
format.BitsPerPixel = SDL_closest_depths[table][b]; format.BitsPerPixel = SDL_closest_depths[table][b];
sizes = SDL_ListModes(&format, flags); sizes = SDL_ListModes(&format, flags);
if ( sizes == (SDL_Rect **)0 ) { if ( sizes == (SDL_Rect **)0 ) {
/* No sizes supported at this bit-depth */ /* No sizes supported at this bit-depth */
continue; continue;
} }
best=0;
for ( i=0; sizes[i]; ++i ) { for ( i=0; sizes[i]; ++i ) {
if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) { /* Mode with both dimensions bigger or equal than asked ? */
if ( i > 0 ) { if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) {
--i; /* Mode with any dimension smaller or equal than current best ? */
*w = sizes[i]->w; if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) {
*h = sizes[i]->h; best=i;
*BitsPerPixel = SDL_closest_depths[table][b];
supported = 1; supported = 1;
} else {
/* Largest mode too small... */;
} }
break;
} }
} }
if ( (i > 0) && ! sizes[i] ) { if (supported) {
/* The smallest mode was larger than requested, OK */ *w=sizes[best]->w;
--i; *h=sizes[best]->h;
*w = sizes[i]->w;
*h = sizes[i]->h;
*BitsPerPixel = SDL_closest_depths[table][b]; *BitsPerPixel = SDL_closest_depths[table][b];
supported = 1;
} }
} }
if ( ! supported ) { if ( ! supported ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment