[PATCH v2] DDX/modes: Add a sanity check when using screen sizes from EDID

Egbert Eich eich at freedesktop.org
Fri Oct 4 23:02:28 PDT 2013


EDID sometimes lies about screen sizes. Since the screen size is used
by clients to determine the DPI a wrong ration will lead to terrible
looking fonts.
Add a sanity check for the h/v ratio cutting off at 2.4. This would
still accept the cinemascope aspect ratio as valid.
Also add message suggesting to add a quirk table entry.

Signed-off-by: Egbert Eich <eich at freedesktop.org>
---
 v2: Avoid division in ratio calculation.                                     
     Pointed out by Keith Packard <keithp at keithp.com>                         

 hw/xfree86/modes/xf86Crtc.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 35845e8..2a02c85 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -3045,10 +3045,22 @@ handle_detailed_physical_size(struct detailed_monitor_section
     if (det_mon->type == DT &&
         det_mon->section.d_timings.h_size != 0 &&
         det_mon->section.d_timings.v_size != 0) {
-
-        p->output->mm_width = det_mon->section.d_timings.h_size;
-        p->output->mm_height = det_mon->section.d_timings.v_size;
-        p->ret = TRUE;
+        /* some sanity checking for aspect ratio:
+           assume any h / v (or v / h) > 2.4 to be bogus.
+           This would even include cinemascope */
+        if (((det_mon->section.d_timings.h_size * 5) <
+             (det_mon->section.d_timings.v_size * 12)) &&
+            ((det_mon->section.d_timings.v_size * 5) <
+             (det_mon->section.d_timings.h_size * 12))) {
+            p->output->mm_width = det_mon->section.d_timings.h_size;
+            p->output->mm_height = det_mon->section.d_timings.v_size;
+            p->ret = TRUE;
+        } else
+            xf86DrvMsg(p->output->scrn->scrnIndex, X_WARNING,
+                       "Output %s: Strange aspect ratio (%i/%i), "
+                       "consider adding a quirk\n", p->output->name,
+                       det_mon->section.d_timings.h_size,
+                       det_mon->section.d_timings.v_size);
     }
 }
 
-- 
1.8.1.4



More information about the xorg-devel mailing list