Skip to content

Commit

Permalink
fbdev: make the best-fit section of fb_find_mode return the closest m…
Browse files Browse the repository at this point in the history
…atching mode

Currently, if a perfect match in terms of resolution is not found,
fb_find_mode() only looks for a best-fit mode among modes with a higher
resolution than the one requested.  Thus, if the user requests a resolution
higher than the largest supported one, they are dropped to the default mode
(usually a low resolution one).

Change this behaviour so that all valid video modes are considered when
looking for a best-fit mode, while still preferring modes with a higher
resolution.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
Cc: Krzysztof Helt <krzysztof.h1@poczta.fm>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Michal Januszewski authored and Linus Torvalds committed Apr 28, 2008
1 parent 169b6a7 commit 6b745b6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions drivers/video/modedb.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ int fb_find_mode(struct fb_var_screeninfo *var,
int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
u32 best, diff;
u32 best, diff, tdiff;

for (i = namelen-1; i >= 0; i--) {
switch (name[i]) {
Expand Down Expand Up @@ -651,19 +651,27 @@ int fb_find_mode(struct fb_var_screeninfo *var,
return (refresh_specified) ? 2 : 1;
}

diff = xres + yres;
diff = 2 * (xres + yres);
best = -1;
DPRINTK("Trying best-fit modes\n");
for (i = 0; i < dbsize; i++) {
if (xres <= db[i].xres && yres <= db[i].yres) {
DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
if (!fb_try_mode(var, info, &db[i], bpp)) {
if (diff > (db[i].xres - xres) + (db[i].yres - yres)) {
diff = (db[i].xres - xres) + (db[i].yres - yres);
best = i;
}
tdiff = abs(db[i].xres - xres) +
abs(db[i].yres - yres);

/*
* Penalize modes with resolutions smaller
* than requested.
*/
if (xres > db[i].xres || yres > db[i].yres)
tdiff += xres + yres;

if (diff > tdiff) {
diff = tdiff;
best = i;
}
}
}
}
if (best != -1) {
fb_try_mode(var, info, &db[best], bpp);
Expand Down

0 comments on commit 6b745b6

Please sign in to comment.