src/video/SDL_video.c
changeset 1076 8d3b95ece376
parent 1052 68f607298ca9
child 1133 609c060fd2a2
     1.1 --- a/src/video/SDL_video.c	Tue Jun 07 13:30:06 2005 +0000
     1.2 +++ b/src/video/SDL_video.c	Sun Jun 12 16:12:55 2005 +0000
     1.3 @@ -462,33 +462,29 @@
     1.4  	SDL_closest_depths[table][0] = *BitsPerPixel;
     1.5  	SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
     1.6  	for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
     1.7 +		int best;
     1.8 +
     1.9  		format.BitsPerPixel = SDL_closest_depths[table][b];
    1.10  		sizes = SDL_ListModes(&format, flags);
    1.11  		if ( sizes == (SDL_Rect **)0 ) {
    1.12  			/* No sizes supported at this bit-depth */
    1.13  			continue;
    1.14  		}
    1.15 +		best=0;
    1.16  		for ( i=0; sizes[i]; ++i ) {
    1.17 -			if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) {
    1.18 -				if ( i > 0 ) {
    1.19 -					--i;
    1.20 -					*w = sizes[i]->w;
    1.21 -					*h = sizes[i]->h;
    1.22 -					*BitsPerPixel = SDL_closest_depths[table][b];
    1.23 +			/* Mode with both dimensions bigger or equal than asked ? */
    1.24 +			if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) {
    1.25 +				/* Mode with any dimension smaller or equal than current best ? */
    1.26 +				if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) {
    1.27 +					best=i;
    1.28  					supported = 1;
    1.29 -				} else {
    1.30 -					/* Largest mode too small... */;
    1.31  				}
    1.32 -				break;
    1.33  			}
    1.34  		}
    1.35 -		if ( (i > 0) && ! sizes[i] ) {
    1.36 -			/* The smallest mode was larger than requested, OK */
    1.37 -			--i;
    1.38 -			*w = sizes[i]->w;
    1.39 -			*h = sizes[i]->h;
    1.40 +		if (supported) {
    1.41 +			*w=sizes[best]->w;
    1.42 +			*h=sizes[best]->h;
    1.43  			*BitsPerPixel = SDL_closest_depths[table][b];
    1.44 -			supported = 1;
    1.45  		}
    1.46  	}
    1.47  	if ( ! supported ) {