From d199f85d708e8fd3cd89eb06376a06a06ab5457f Mon Sep 17 00:00:00 2001 From: macallan Date: Tue, 12 Oct 2010 16:18:19 +0000 Subject: fix off-by-one error which happened when the first mode with matching size is also the best match by refresh rate --- sys/dev/videomode/pickmode.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/videomode/pickmode.c b/sys/dev/videomode/pickmode.c index 86cc10cb461..072bcc24790 100644 --- a/sys/dev/videomode/pickmode.c +++ b/sys/dev/videomode/pickmode.c @@ -1,4 +1,4 @@ -/* $NetBSD: pickmode.c,v 1.1 2010/05/04 21:17:10 macallan Exp $ */ +/* $NetBSD: pickmode.c,v 1.2 2010/10/12 16:18:19 macallan Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pickmode.c,v 1.1 2010/05/04 21:17:10 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pickmode.c,v 1.2 2010/10/12 16:18:19 macallan Exp $"); #include #include @@ -81,9 +81,9 @@ pick_mode_by_ref(int width, int height, int refresh) this = &videomode_list[i]; mref = this->dot_clock * 1000 / (this->htotal * this->vtotal); diff = abs(mref - refresh); - if ((this->hdisplay != width) || (this->vdisplay != height) || - (diff > closest)) + if ((this->hdisplay != width) || (this->vdisplay != height)) continue; + DPRINTF("%s in %d hz, diff %d\n", this->name, mref, diff); if (best != NULL) { if (diff < closest) { @@ -91,11 +91,13 @@ pick_mode_by_ref(int width, int height, int refresh) best = this; closest = diff; } - } else + } else { best = this; + closest = diff; + } } if (best!= NULL) - DPRINTF("found %s\n", best->name); + DPRINTF("found %s %d\n", best->name, best->dot_clock); return best; } -- cgit