diff options
Diffstat (limited to 'driver/xf86-video-nv/compat')
-rw-r--r-- | driver/xf86-video-nv/compat/Makefile.am | 1 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/Makefile.in | 6 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Crtc.c | 676 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Crtc.h | 15 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Cursors.c | 10 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86EdidModes.c | 446 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Modes.c | 132 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Modes.h | 12 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86RandR12.c | 128 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86Rotate.c | 7 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/modes/xf86cvt.c | 9 | ||||
-rw-r--r-- | driver/xf86-video-nv/compat/parser/xf86Parser.h | 2 |
12 files changed, 1117 insertions, 327 deletions
diff --git a/driver/xf86-video-nv/compat/Makefile.am b/driver/xf86-video-nv/compat/Makefile.am index f5f8d936d..de17f9332 100644 --- a/driver/xf86-video-nv/compat/Makefile.am +++ b/driver/xf86-video-nv/compat/Makefile.am @@ -7,6 +7,7 @@ EXTRA_DIST = \ modes/xf86cvt.c \ modes/xf86DiDGA.c \ modes/xf86EdidModes.c \ + modes/xf86gtf.c \ modes/xf86Modes.c \ modes/xf86Modes.h \ modes/xf86RandR12.c \ diff --git a/driver/xf86-video-nv/compat/Makefile.in b/driver/xf86-video-nv/compat/Makefile.in index 858efc555..6b95d3103 100644 --- a/driver/xf86-video-nv/compat/Makefile.in +++ b/driver/xf86-video-nv/compat/Makefile.in @@ -77,6 +77,7 @@ DEPDIR = @DEPDIR@ DRIVER_MAN_DIR = @DRIVER_MAN_DIR@ DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@ DRIVER_NAME = @DRIVER_NAME@ +DSYMUTIL = @DSYMUTIL@ ECHO = @ECHO@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ @@ -105,6 +106,7 @@ MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ MAKEINFO = @MAKEINFO@ MISC_MAN_DIR = @MISC_MAN_DIR@ MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@ +NMEDIT = @NMEDIT@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ @@ -117,6 +119,7 @@ PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@ PCIACCESS_LIBS = @PCIACCESS_LIBS@ PKG_CONFIG = @PKG_CONFIG@ RANLIB = @RANLIB@ +SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ @@ -127,7 +130,9 @@ XORG_LIBS = @XORG_LIBS@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DSYMUTIL = @ac_ct_DSYMUTIL@ ac_ct_F77 = @ac_ct_F77@ +ac_ct_NMEDIT = @ac_ct_NMEDIT@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@ @@ -180,6 +185,7 @@ EXTRA_DIST = \ modes/xf86cvt.c \ modes/xf86DiDGA.c \ modes/xf86EdidModes.c \ + modes/xf86gtf.c \ modes/xf86Modes.c \ modes/xf86Modes.h \ modes/xf86RandR12.c \ diff --git a/driver/xf86-video-nv/compat/modes/xf86Crtc.c b/driver/xf86-video-nv/compat/modes/xf86Crtc.c index d375da897..855d646da 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Crtc.c +++ b/driver/xf86-video-nv/compat/modes/xf86Crtc.c @@ -1,5 +1,6 @@ /* * Copyright © 2006 Keith Packard + * Copyright © 2008 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -36,6 +37,7 @@ #include "xf86DDC.h" #include "xf86Crtc.h" #include "xf86Modes.h" +#include "xf86Priv.h" #include "xf86RandR12.h" #include "X11/extensions/render.h" #define DPMS_SERVER @@ -235,6 +237,9 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, int saved_x, saved_y; Rotation saved_rotation; + if (crtc->funcs->set_mode_major) + return crtc->funcs->set_mode_major(crtc, mode, rotation, x, y); + crtc->enabled = xf86CrtcInUse (crtc); if (!crtc->enabled) @@ -259,6 +264,30 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, crtc->y = y; crtc->rotation = rotation; + /* Shift offsets that move us out of virtual size */ + if (x + mode->HDisplay > xf86_config->maxWidth || + y + mode->VDisplay > xf86_config->maxHeight) + { + if (x + mode->HDisplay > xf86_config->maxWidth) + crtc->x = xf86_config->maxWidth - mode->HDisplay; + if (y + mode->VDisplay > xf86_config->maxHeight) + crtc->y = xf86_config->maxHeight - mode->VDisplay; + if (crtc->x < 0 || crtc->y < 0) + { + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Mode %dx%d does not fit virtual size %dx%d - " + "internal error\n", mode->HDisplay, mode->VDisplay, + xf86_config->maxWidth, xf86_config->maxHeight); + goto done; + } + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Mode %dx%d+%d+%d does not fit virtual size %dx%d - " + "offset updated to +%d+%d\n", + mode->HDisplay, mode->VDisplay, x, y, + xf86_config->maxWidth, xf86_config->maxHeight, + crtc->x, crtc->y); + } + /* XXX short-circuit changes to base location only */ /* Pass our mode to the outputs and the CRTC to give them a chance to @@ -300,7 +329,7 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, /* Set up the DPLL and any output state that needs to adjust or depend * on the DPLL. */ - crtc->funcs->mode_set(crtc, mode, adjusted_mode, x, y); + crtc->funcs->mode_set(crtc, mode, adjusted_mode, crtc->x, crtc->y); for (i = 0; i < xf86_config->num_output; i++) { xf86OutputPtr output = xf86_config->output[i]; @@ -438,7 +467,7 @@ xf86OutputSetMonitor (xf86OutputPtr output) } static Bool -xf86OutputEnabled (xf86OutputPtr output) +xf86OutputEnabled (xf86OutputPtr output, Bool strict) { Bool enable, disable; @@ -456,8 +485,16 @@ xf86OutputEnabled (xf86OutputPtr output) "Output %s disabled by config file\n", output->name); return FALSE; } - /* otherwise, enable if it is not disconnected */ - enable = output->status != XF86OutputStatusDisconnected; + + /* If not, try to only light up the ones we know are connected */ + if (strict) { + enable = output->status == XF86OutputStatusConnected; + } + /* But if that fails, try to light up even outputs we're unsure of */ + else { + enable = output->status != XF86OutputStatusDisconnected; + } + xf86DrvMsg (output->scrn->scrnIndex, X_INFO, "Output %s %sconnected\n", output->name, enable ? "" : "dis"); return enable; @@ -704,14 +741,15 @@ xf86DefaultMode (xf86OutputPtr output, int width, int height) mm_height = output->mm_height; if (!mm_height) - mm_height = 203; /* 768 pixels at 96dpi */ + mm_height = (768 * 25.4) / DEFAULT_DPI; /* - * Pick a mode closest to 96dpi + * Pick a mode closest to DEFAULT_DPI */ for (mode = output->probed_modes; mode; mode = mode->next) { int dpi; - int preferred = (mode->type & M_T_PREFERRED) != 0; + int preferred = (((mode->type & M_T_PREFERRED) != 0) + + ((mode->type & M_T_USERPREF) != 0)); int diff; if (xf86ModeWidth (mode, output->initial_rotation) > width || @@ -720,7 +758,7 @@ xf86DefaultMode (xf86OutputPtr output, int width, int height) /* yes, use VDisplay here, not xf86ModeHeight */ dpi = (mode->VDisplay * 254) / (mm_height * 10); - diff = dpi - 96; + diff = dpi - DEFAULT_DPI; diff = diff < 0 ? -diff : diff; if (target_mode == NULL || (preferred > target_preferred) || (preferred == target_preferred && diff < target_diff)) @@ -771,7 +809,7 @@ xf86ClosestMode (xf86OutputPtr output, return target_mode; } -static Bool +static DisplayModePtr xf86OutputHasPreferredMode (xf86OutputPtr output, int width, int height) { DisplayModePtr mode; @@ -783,9 +821,21 @@ xf86OutputHasPreferredMode (xf86OutputPtr output, int width, int height) continue; if (mode->type & M_T_PREFERRED) - return TRUE; + return mode; } - return FALSE; + return NULL; +} + +static DisplayModePtr +xf86OutputHasUserPreferredMode (xf86OutputPtr output) +{ + DisplayModePtr mode, first = output->probed_modes; + + for (mode = first; mode && mode->next != first; mode = mode->next) + if (mode->type & M_T_USERPREF) + return mode; + + return NULL; } static int @@ -1053,6 +1103,16 @@ xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes) any_set = TRUE; continue; } + if (!modes[or]) + { + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Cannot position output %s relative to output %s without modes\n", + output->name, relative_name); + output->initial_x = 0; + output->initial_y = 0; + any_set = TRUE; + continue; + } if (relative->initial_x == POSITION_UNSET) { keep_going = TRUE; @@ -1068,10 +1128,10 @@ xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes) output->initial_x += xf86ModeWidth (modes[or], relative->initial_rotation); break; case OPTION_ABOVE: - output->initial_y -= xf86ModeHeight (modes[or], relative->initial_rotation); + output->initial_y -= xf86ModeHeight (modes[o], relative->initial_rotation); break; case OPTION_LEFT_OF: - output->initial_x -= xf86ModeWidth (modes[or], relative->initial_rotation); + output->initial_x -= xf86ModeWidth (modes[o], relative->initial_rotation); break; default: break; @@ -1214,6 +1274,67 @@ xf86SortModes (DisplayModePtr input) return output; } +static char * +preferredMode(ScrnInfoPtr pScrn, xf86OutputPtr output) +{ + char *preferred_mode = NULL; + + /* Check for a configured preference for a particular mode */ + preferred_mode = xf86GetOptValString (output->options, + OPTION_PREFERRED_MODE); + if (preferred_mode) + return preferred_mode; + + if (pScrn->display->modes && *pScrn->display->modes) + preferred_mode = *pScrn->display->modes; + + return preferred_mode; +} + +static void +GuessRangeFromModes(MonPtr mon, DisplayModePtr mode) +{ + if (!mon || !mode) + return; + + mon->nHsync = 1; + mon->hsync[0].lo = 1024.0; + mon->hsync[0].hi = 0.0; + + mon->nVrefresh = 1; + mon->vrefresh[0].lo = 1024.0; + mon->vrefresh[0].hi = 0.0; + + while (mode) { + if (!mode->HSync) + mode->HSync = ((float) mode->Clock ) / ((float) mode->HTotal); + + if (!mode->VRefresh) + mode->VRefresh = (1000.0 * ((float) mode->Clock)) / + ((float) (mode->HTotal * mode->VTotal)); + + if (mode->HSync < mon->hsync[0].lo) + mon->hsync[0].lo = mode->HSync; + + if (mode->HSync > mon->hsync[0].hi) + mon->hsync[0].hi = mode->HSync; + + if (mode->VRefresh < mon->vrefresh[0].lo) + mon->vrefresh[0].lo = mode->VRefresh; + + if (mode->VRefresh > mon->vrefresh[0].hi) + mon->vrefresh[0].hi = mode->VRefresh; + + mode = mode->next; + } + + /* stretch out the bottom to fit 640x480@60 */ + if (mon->hsync[0].lo > 31.0) + mon->hsync[0].lo = 31.0; + if (mon->vrefresh[0].lo > 58.0) + mon->vrefresh[0].lo = 58.0; +} + _X_EXPORT void xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) { @@ -1318,8 +1439,8 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) if (sync_source == sync_default) sync_source = sync_edid; } - if (ranges->max_clock > max_clock) - max_clock = ranges->max_clock; + if (ranges->max_clock * 1000 > max_clock) + max_clock = ranges->max_clock * 1000; } } } @@ -1331,6 +1452,10 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) OPTUNITS_KHZ, &clock)) max_clock = (int) clock; + /* If we still don't have a sync range, guess wildly */ + if (!mon_rec.nHsync || !mon_rec.nVrefresh) + GuessRangeFromModes(&mon_rec, output_modes); + /* * These limits will end up setting a 1024x768@60Hz mode by default, * which seems like a fairly good mode to use when nothing else is @@ -1350,7 +1475,14 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) } default_modes = xf86GetDefaultModes (output->interlaceAllowed, output->doubleScanAllowed); - + + /* + * If this is not an RB monitor, remove RB modes from the default + * pool. RB modes from the config or the monitor itself are fine. + */ + if (!mon_rec.reducedblanking) + xf86ValidateModesReducedBlanking (scrn, default_modes); + if (sync_source == sync_config) { /* @@ -1366,9 +1498,12 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) /* * Check default modes against monitor max clock */ - if (max_clock) + if (max_clock) { xf86ValidateModesClocks(scrn, default_modes, &min_clock, &max_clock, 1); + xf86ValidateModesClocks(scrn, output_modes, + &min_clock, &max_clock, 1); + } output->probed_modes = NULL; output->probed_modes = xf86ModesAdd (output->probed_modes, config_modes); @@ -1395,8 +1530,7 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) output->probed_modes = xf86SortModes (output->probed_modes); /* Check for a configured preference for a particular mode */ - preferred_mode = xf86GetOptValString (output->options, - OPTION_PREFERRED_MODE); + preferred_mode = preferredMode(scrn, output); if (preferred_mode) { @@ -1415,10 +1549,9 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) mode->prev = NULL; output->probed_modes = mode; } - mode->type |= M_T_PREFERRED; + mode->type |= (M_T_PREFERRED|M_T_USERPREF); + break; } - else - mode->type &= ~M_T_PREFERRED; } } @@ -1458,7 +1591,98 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) _X_EXPORT void xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr scrn, int *x, int *y); -_X_EXPORT void +static DisplayModePtr +biggestMode(DisplayModePtr a, DisplayModePtr b) +{ + int A, B; + + if (!a) + return b; + if (!b) + return a; + + A = a->HDisplay * a->VDisplay; + B = b->HDisplay * b->VDisplay; + + if (A > B) + return a; + + return b; +} + +static xf86OutputPtr +SetCompatOutput(xf86CrtcConfigPtr config) +{ + xf86OutputPtr output = NULL, test = NULL; + DisplayModePtr maxmode = NULL, testmode, mode; + int o, compat = -1, count, mincount = 0; + + /* Look for one that's definitely connected */ + for (o = 0; o < config->num_output; o++) + { + test = config->output[o]; + if (!test->crtc) + continue; + if (test->status != XF86OutputStatusConnected) + continue; + if (!test->probed_modes) + continue; + + testmode = mode = test->probed_modes; + for (count = 0; mode; mode = mode->next, count++) + testmode = biggestMode(testmode, mode); + + if (!output) { + output = test; + compat = o; + maxmode = testmode; + mincount = count; + } else if (maxmode == biggestMode(maxmode, testmode)) { + output = test; + compat = o; + maxmode = testmode; + mincount = count; + } else if ((maxmode->HDisplay == testmode->HDisplay) && + (maxmode->VDisplay == testmode->VDisplay) && + count <= mincount) { + output = test; + compat = o; + maxmode = testmode; + mincount = count; + } + } + + /* If we didn't find one, take anything we can get */ + if (!output) + { + for (o = 0; o < config->num_output; o++) + { + test = config->output[o]; + if (!test->crtc) + continue; + if (!test->probed_modes) + continue; + + if (!output) { + output = test; + compat = o; + } else if (test->probed_modes->HDisplay < output->probed_modes->HDisplay) { + output = test; + compat = o; + } + } + } + + if (compat >= 0) { + config->compat_output = compat; + } else { + /* Don't change the compat output when no valid outputs found */ + output = config->output[config->compat_output]; + } + + return output; +} + xf86SetScrnInfoModes (ScrnInfoPtr scrn) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); @@ -1466,23 +1690,11 @@ xf86SetScrnInfoModes (ScrnInfoPtr scrn) xf86CrtcPtr crtc; DisplayModePtr last, mode; - output = config->output[config->compat_output]; - if (!output->crtc) - { - int o; + output = SetCompatOutput(config); + + if (!output) + return; /* punt */ - output = NULL; - for (o = 0; o < config->num_output; o++) - if (config->output[o]->crtc) - { - config->compat_output = o; - output = config->output[o]; - break; - } - /* no outputs are active, punt and leave things as they are */ - if (!output) - return; - } crtc = output->crtc; /* Clear any existing modes from scrn->modes */ @@ -1512,6 +1724,271 @@ xf86SetScrnInfoModes (ScrnInfoPtr scrn) scrn->currentMode = scrn->modes; } +static void +xf86EnableOutputs(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, Bool *enabled) +{ + Bool any_enabled = FALSE; + int o; + + for (o = 0; o < config->num_output; o++) + any_enabled |= enabled[o] = xf86OutputEnabled(config->output[o], TRUE); + + if (!any_enabled) { + xf86DrvMsg(scrn->scrnIndex, X_WARNING, + "No outputs definitely connected, trying again...\n"); + + for (o = 0; o < config->num_output; o++) + enabled[o] = xf86OutputEnabled(config->output[o], FALSE); + } +} + +static Bool +nextEnabledOutput(xf86CrtcConfigPtr config, Bool *enabled, int *index) +{ + int o = *index; + + for (o++; o < config->num_output; o++) { + if (enabled[o]) { + *index = o; + return TRUE; + } + } + + return FALSE; +} + +static Bool +xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, + DisplayModePtr *modes, Bool *enabled, + int width, int height) +{ + int o, p; + int max_pref_width = 0, max_pref_height = 0; + DisplayModePtr *preferred, *preferred_match; + Bool ret = FALSE; + + preferred = xnfcalloc(config->num_output, sizeof(DisplayModePtr)); + preferred_match = xnfcalloc(config->num_output, sizeof(DisplayModePtr)); + + /* Check if the preferred mode is available on all outputs */ + for (p = -1; nextEnabledOutput(config, enabled, &p); ) { + Rotation r = config->output[p]->initial_rotation; + DisplayModePtr mode; + if ((preferred[p] = xf86OutputHasPreferredMode(config->output[p], + width, height))) { + int pref_width = xf86ModeWidth(preferred[p], r); + int pref_height = xf86ModeHeight(preferred[p], r); + Bool all_match = TRUE; + + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + Bool match = FALSE; + xf86OutputPtr output = config->output[o]; + if (o == p) + continue; + + for (mode = output->probed_modes; mode; mode = mode->next) { + Rotation r = output->initial_rotation; + if (xf86ModeWidth(mode, r) == pref_width && + xf86ModeHeight(mode, r) == pref_height) { + preferred[o] = mode; + match = TRUE; + } + } + + all_match &= match; + } + + if (all_match && + (pref_width*pref_height > max_pref_width*max_pref_height)) { + for (o = -1; nextEnabledOutput(config, enabled, &o); ) + preferred_match[o] = preferred[o]; + max_pref_width = pref_width; + max_pref_height = pref_height; + ret = TRUE; + } + } + } + + if (ret) { + /* oh good, there is a match. stash the selected modes and return. */ + memcpy(modes, preferred_match, + config->num_output * sizeof(DisplayModePtr)); + } + + xfree(preferred); + xfree(preferred_match); + return ret; +} + +static Bool +aspectMatch(float a, float b) +{ + return fabs(1 - (a / b)) < 0.05; +} + +static DisplayModePtr +nextAspectMode(xf86OutputPtr o, DisplayModePtr last, float aspect) +{ + DisplayModePtr m = NULL; + + if (!o) + return NULL; + + if (!last) + m = o->probed_modes; + else + m = last->next; + + for (; m; m = m->next) + if (aspectMatch(aspect, (float)m->HDisplay / (float)m->VDisplay)) + return m; + + return NULL; +} + +static DisplayModePtr +bestModeForAspect(xf86CrtcConfigPtr config, Bool *enabled, float aspect) +{ + int o = -1, p; + DisplayModePtr mode = NULL, test = NULL, match = NULL; + + nextEnabledOutput(config, enabled, &o); + while ((mode = nextAspectMode(config->output[o], mode, aspect))) { + for (p = o; nextEnabledOutput(config, enabled, &p); ) { + test = xf86OutputFindClosestMode(config->output[p], mode); + if (!test) + break; + if (test->HDisplay != mode->HDisplay || + test->VDisplay != mode->VDisplay) { + test = NULL; + break; + } + } + + /* if we didn't match it on all outputs, try the next one */ + if (!test) + continue; + + /* if it's bigger than the last one, save it */ + if (!match || (test->HDisplay > match->HDisplay)) + match = test; + } + + /* return the biggest one found */ + return match; +} + +static Bool +xf86TargetAspect(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, + DisplayModePtr *modes, Bool *enabled, + int width, int height) +{ + int o; + float aspect = 0.0, *aspects; + xf86OutputPtr output; + Bool ret = FALSE; + DisplayModePtr guess = NULL, aspect_guess = NULL, base_guess = NULL; + + aspects = xnfcalloc(config->num_output, sizeof(float)); + + /* collect the aspect ratios */ + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + output = config->output[o]; + if (output->mm_height) + aspects[o] = (float)output->mm_width / (float)output->mm_height; + else + aspects[o] = 4.0 / 3.0; + } + + /* check that they're all the same */ + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + output = config->output[o]; + if (!aspect) { + aspect = aspects[o]; + } else if (!aspectMatch(aspect, aspects[o])) { + goto no_aspect_match; + } + } + + /* if they're all 4:3, just skip ahead and save effort */ + if (!aspectMatch(aspect, 4.0/3.0)) + aspect_guess = bestModeForAspect(config, enabled, aspect); + +no_aspect_match: + base_guess = bestModeForAspect(config, enabled, 4.0/3.0); + + guess = biggestMode(base_guess, aspect_guess); + + if (!guess) + goto out; + + /* found a mode that works everywhere, now apply it */ + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + modes[o] = xf86OutputFindClosestMode(config->output[o], guess); + } + ret = TRUE; + +out: + xfree(aspects); + return ret; +} + +static Bool +xf86TargetFallback(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, + DisplayModePtr *modes, Bool *enabled, + int width, int height) +{ + DisplayModePtr target_mode = NULL; + Rotation target_rotation = RR_Rotate_0; + DisplayModePtr default_mode; + int default_preferred, target_preferred = 0, o; + + /* User preferred > preferred > other modes */ + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + default_mode = xf86DefaultMode (config->output[o], width, height); + if (!default_mode) + continue; + + default_preferred = (((default_mode->type & M_T_PREFERRED) != 0) + + ((default_mode->type & M_T_USERPREF) != 0)); + + if (default_preferred > target_preferred || !target_mode) { + target_mode = default_mode; + target_preferred = default_preferred; + target_rotation = config->output[o]->initial_rotation; + config->compat_output = o; + } + } + + if (target_mode) + modes[config->compat_output] = target_mode; + + /* Fill in other output modes */ + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + if (!modes[o]) + modes[o] = xf86ClosestMode(config->output[o], target_mode, + target_rotation, width, height); + } + + return (target_mode != NULL); +} + +static Bool +xf86TargetUserpref(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, + DisplayModePtr *modes, Bool *enabled, + int width, int height) +{ + int o; + + for (o = -1; nextEnabledOutput(config, enabled, &o); ) + if (xf86OutputHasUserPreferredMode(config->output[o])) + return + xf86TargetFallback(scrn, config, modes, enabled, width, height); + + return FALSE; +} + + /** * Construct default screen configuration * @@ -1531,13 +2008,11 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); int o, c; - DisplayModePtr target_mode = NULL; - Rotation target_rotation = RR_Rotate_0; xf86CrtcPtr *crtcs; DisplayModePtr *modes; Bool *enabled; - int width; - int height; + int width, height; + int i = scrn->scrnIndex; /* Set up the device options */ config->options = xnfalloc (sizeof (xf86DeviceOptions)); @@ -1563,70 +2038,28 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow) modes = xnfcalloc (config->num_output, sizeof (DisplayModePtr)); enabled = xnfcalloc (config->num_output, sizeof (Bool)); - for (o = 0; o < config->num_output; o++) - { - xf86OutputPtr output = config->output[o]; - - modes[o] = NULL; - enabled[o] = xf86OutputEnabled (output); - } - - /* - * Let outputs with preferred modes drive screen size - */ - for (o = 0; o < config->num_output; o++) - { - xf86OutputPtr output = config->output[o]; + xf86EnableOutputs(scrn, config, enabled); + + if (xf86TargetUserpref(scrn, config, modes, enabled, width, height)) + xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n"); + else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height)) + xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n"); + else if (xf86TargetAspect(scrn, config, modes, enabled, width, height)) + xf86DrvMsg(i, X_INFO, "Using fuzzy aspect match for initial modes\n"); + else if (xf86TargetFallback(scrn, config, modes, enabled, width, height)) + xf86DrvMsg(i, X_INFO, "Using sloppy heuristic for initial modes\n"); + else + xf86DrvMsg(i, X_WARNING, "Unable to find initial modes\n"); - if (enabled[o] && - xf86OutputHasPreferredMode (output, width, height)) - { - target_mode = xf86DefaultMode (output, width, height); - target_rotation = output->initial_rotation; - if (target_mode) - { - modes[o] = target_mode; - config->compat_output = o; - break; - } - } - } - if (!target_mode) - { - for (o = 0; o < config->num_output; o++) - { - xf86OutputPtr output = config->output[o]; - if (enabled[o]) - { - target_mode = xf86DefaultMode (output, width, height); - target_rotation = output->initial_rotation; - if (target_mode) - { - modes[o] = target_mode; - config->compat_output = o; - break; - } - } - } - } - for (o = 0; o < config->num_output; o++) - { - xf86OutputPtr output = config->output[o]; - - if (enabled[o]) - { - if (!modes[o]) - modes[o] = xf86ClosestMode (output, target_mode, - target_rotation, width, height); - if (!modes[o]) - xf86DrvMsg (scrn->scrnIndex, X_ERROR, - "Output %s enabled but has no modes\n", - output->name); - else - xf86DrvMsg (scrn->scrnIndex, X_INFO, - "Output %s using initial mode %s\n", - output->name, modes[o]->name); - } + for (o = -1; nextEnabledOutput(config, enabled, &o); ) { + if (!modes[o]) + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Output %s enabled but has no modes\n", + config->output[o]->name); + else + xf86DrvMsg (scrn->scrnIndex, X_INFO, + "Output %s using initial mode %s\n", + config->output[o]->name, modes[o]->name); } /* @@ -1681,6 +2114,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow) crtc->x = output->initial_x; crtc->y = output->initial_y; output->crtc = crtc; + } else { + output->crtc = NULL; } } @@ -1760,6 +2195,10 @@ xf86SetDesiredModes (ScrnInfoPtr scrn) xf86OutputPtr output = NULL; int o; + /* Skip disabled CRTCs */ + if (!crtc->enabled) + continue; + if (config->output[config->compat_output]->crtc == crtc) output = config->output[config->compat_output]; else @@ -1771,9 +2210,7 @@ xf86SetDesiredModes (ScrnInfoPtr scrn) break; } } - /* - * Skip disabled crtcs - */ + /* paranoia */ if (!output) continue; @@ -2134,13 +2571,21 @@ _X_EXPORT xf86MonPtr xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus) { ScrnInfoPtr scrn = output->scrn; + xf86MonPtr mon; + + mon = xf86DoEDID_DDC2 (scrn->scrnIndex, pDDCBus); + if (mon) + xf86DDCApplyQuirks (scrn->scrnIndex, mon); - return xf86DoEDID_DDC2 (scrn->scrnIndex, pDDCBus); + return mon; } -static char *_xf86ConnectorNames[] = { "None", "VGA", "DVI-I", "DVI-D", - "DVI-A", "Composite", "S-Video", - "Component", "LFP", "Proprietary" }; +static char *_xf86ConnectorNames[] = { + "None", "VGA", "DVI-I", "DVI-D", + "DVI-A", "Composite", "S-Video", + "Component", "LFP", "Proprietary", + "HDMI", "DisplayPort", + }; _X_EXPORT char * xf86ConnectorGetName(xf86ConnectorType connector) { @@ -2220,7 +2665,10 @@ xf86_covering_crtc(ScrnInfoPtr pScrn, /* * For overlay video, compute the relevant CRTC and - * clip video to that + * clip video to that. + * + * returning FALSE means there was a memory failure of some kind, + * not that the video shouldn't be displayed */ _X_EXPORT Bool diff --git a/driver/xf86-video-nv/compat/modes/xf86Crtc.h b/driver/xf86-video-nv/compat/modes/xf86Crtc.h index 9693e12bb..cc045b229 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Crtc.h +++ b/driver/xf86-video-nv/compat/modes/xf86Crtc.h @@ -29,6 +29,7 @@ #endif #include "xf86Modes.h" #include "xf86Cursor.h" +#include "xf86i2c.h" #include "damage.h" #include "picturestr.h" @@ -39,6 +40,9 @@ #ifndef M_T_DRIVER #define M_T_DRIVER 0x40 #endif +#ifndef M_T_USERPREF +#define M_T_USERPREF 0x80 +#endif #ifndef HARDWARE_CURSOR_ARGB #define HARDWARE_CURSOR_ARGB 0x00004000 #endif @@ -58,12 +62,14 @@ typedef enum _xf86ConnectorType { XF86ConnectorComponent, XF86ConnectorLFP, XF86ConnectorProprietary, + XF86ConnectorHDMI, + XF86ConnectorDisplayPort, } xf86ConnectorType; typedef enum _xf86OutputStatus { XF86OutputStatusConnected, XF86OutputStatusDisconnected, - XF86OutputStatusUnknown, + XF86OutputStatusUnknown } xf86OutputStatus; typedef struct _xf86CrtcFuncs { @@ -200,6 +206,13 @@ typedef struct _xf86CrtcFuncs { */ void (*destroy) (xf86CrtcPtr crtc); + + /** + * Less fine-grained mode setting entry point for kernel modesetting + */ + Bool + (*set_mode_major)(xf86CrtcPtr crtc, DisplayModePtr mode, + Rotation rotation, int x, int y); } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr; struct _xf86Crtc { diff --git a/driver/xf86-video-nv/compat/modes/xf86Cursors.c b/driver/xf86-video-nv/compat/modes/xf86Cursors.c index b5101642b..cb93dc6ba 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Cursors.c +++ b/driver/xf86-video-nv/compat/modes/xf86Cursors.c @@ -137,7 +137,8 @@ cursor_bitpos (int flags, int x, Bool mask) mask = !mask; if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED) x = (x & ~3) | (3 - (x & 3)); - if (flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) + if (((flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) == 0) == + (X_BYTE_ORDER == X_BIG_ENDIAN)) x = (x & ~7) | (7 - (x & 7)); if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1) x = (x << 1) + mask; @@ -226,7 +227,8 @@ xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg) xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); CursorPtr cursor = xf86_config->cursor; int c; - CARD8 *bits = cursor ? cursor->devPriv[screen->myNum] : NULL; + CARD8 *bits = cursor ? dixLookupPrivate(&cursor->devPrivates, + screen) : NULL; /* Save ARGB versions of these colors */ xf86_config->cursor_fg = (CARD32) fg | 0xff000000; @@ -399,7 +401,7 @@ xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src) int flags = cursor_info->Flags; cursor_image = xf86_config->cursor_image; - memset(cursor_image, 0, cursor_info->MaxWidth * stride); + memset(cursor_image, 0, cursor_info->MaxHeight * stride); for (y = 0; y < cursor_info->MaxHeight; y++) for (x = 0; x < cursor_info->MaxWidth; x++) @@ -612,7 +614,7 @@ xf86_reload_cursors (ScreenPtr screen) else #endif (*cursor_info->LoadCursorImage)(cursor_info->pScrn, - cursor->devPriv[screen->myNum]); + dixLookupPrivate(&cursor->devPrivates, screen)); (*cursor_info->SetCursorPosition)(cursor_info->pScrn, x, y); (*cursor_info->ShowCursor)(cursor_info->pScrn); diff --git a/driver/xf86-video-nv/compat/modes/xf86EdidModes.c b/driver/xf86-video-nv/compat/modes/xf86EdidModes.c index 8b5e69d9a..bf0ea3f64 100644 --- a/driver/xf86-video-nv/compat/modes/xf86EdidModes.c +++ b/driver/xf86-video-nv/compat/modes/xf86EdidModes.c @@ -54,13 +54,28 @@ typedef enum { DDC_QUIRK_PREFER_LARGE_60 = 1 << 0, /* 135MHz clock is too high, drop a bit */ DDC_QUIRK_135_CLOCK_TOO_HIGH = 1 << 1, + /* Prefer the largest mode at 75 Hz */ + DDC_QUIRK_PREFER_LARGE_75 = 1 << 2, + /* Convert detailed timing's horizontal from units of cm to mm */ + DDC_QUIRK_DETAILED_H_IN_CM = 1 << 3, + /* Convert detailed timing's vertical from units of cm to mm */ + DDC_QUIRK_DETAILED_V_IN_CM = 1 << 4, + /* Detailed timing descriptors have bogus size values, so just take the + * maximum size and use that. + */ + DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE = 1 << 5, + /* Monitor forgot to set the first detailed is preferred bit. */ + DDC_QUIRK_FIRST_DETAILED_PREFERRED = 1 << 6, + /* use +hsync +vsync for detailed mode */ + DDC_QUIRK_DETAILED_SYNC_PP = 1 << 7, } ddc_quirk_t; static Bool quirk_prefer_large_60 (int scrnIndex, xf86MonPtr DDC) { /* Belinea 10 15 55 */ if (memcmp (DDC->vendor.name, "MAX", 4) == 0 && - DDC->vendor.prod_id == 1516) + ((DDC->vendor.prod_id == 1516) || + (DDC->vendor.prod_id == 0x77e))) return TRUE; /* Acer AL1706 */ @@ -78,6 +93,52 @@ static Bool quirk_prefer_large_60 (int scrnIndex, xf86MonPtr DDC) DDC->vendor.prod_id == 638) return TRUE; + /* Acer F51 */ + if (memcmp (DDC->vendor.name, "API", 4) == 0 && + DDC->vendor.prod_id == 0x7602) + return TRUE; + + + return FALSE; +} + +static Bool quirk_prefer_large_75 (int scrnIndex, xf86MonPtr DDC) +{ + /* Bug #11603: Funai Electronics PM36B */ + if (memcmp (DDC->vendor.name, "FCM", 4) == 0 && + DDC->vendor.prod_id == 13600) + return TRUE; + + return FALSE; +} + +static Bool quirk_detailed_h_in_cm (int scrnIndex, xf86MonPtr DDC) +{ + /* Bug #11603: Funai Electronics PM36B */ + if (memcmp (DDC->vendor.name, "FCM", 4) == 0 && + DDC->vendor.prod_id == 13600) + return TRUE; + + return FALSE; +} + +static Bool quirk_detailed_v_in_cm (int scrnIndex, xf86MonPtr DDC) +{ + /* Bug #11603: Funai Electronics PM36B */ + if (memcmp (DDC->vendor.name, "FCM", 4) == 0 && + DDC->vendor.prod_id == 13600) + return TRUE; + + return FALSE; +} + +static Bool quirk_detailed_use_maximum_size (int scrnIndex, xf86MonPtr DDC) +{ + /* Bug #10304: LGPhilipsLCD LP154W01-A5 */ + if (memcmp (DDC->vendor.name, "LPL", 4) == 0 && + (DDC->vendor.prod_id == 0 || DDC->vendor.prod_id == 0x2a00)) + return TRUE; + return FALSE; } @@ -91,6 +152,35 @@ static Bool quirk_135_clock_too_high (int scrnIndex, xf86MonPtr DDC) return FALSE; } +static Bool quirk_first_detailed_preferred (int scrnIndex, xf86MonPtr DDC) +{ + /* Philips 107p5 CRT. Reported on xorg@ with pastebin. */ + if (memcmp (DDC->vendor.name, "PHL", 4) == 0 && + DDC->vendor.prod_id == 57364) + return TRUE; + + /* Proview AY765C 17" LCD. See bug #15160*/ + if (memcmp (DDC->vendor.name, "PTS", 4) == 0 && + DDC->vendor.prod_id == 765) + return TRUE; + + /* ACR of some sort RH #284231 */ + if (memcmp (DDC->vendor.name, "ACR", 4) == 0 && + DDC->vendor.prod_id == 2423) + return TRUE; + + return FALSE; +} + +static Bool quirk_detailed_sync_pp(int scrnIndex, xf86MonPtr DDC) +{ + /* Bug #12439: Samsung SyncMaster 205BW */ + if (memcmp (DDC->vendor.name, "SAM", 4) == 0 && + DDC->vendor.prod_id == 541) + return TRUE; + return FALSE; +} + typedef struct { Bool (*detect) (int scrnIndex, xf86MonPtr DDC); ddc_quirk_t quirk; @@ -106,6 +196,30 @@ static const ddc_quirk_map_t ddc_quirks[] = { quirk_135_clock_too_high, DDC_QUIRK_135_CLOCK_TOO_HIGH, "Recommended 135MHz pixel clock is too high" }, + { + quirk_prefer_large_75, DDC_QUIRK_PREFER_LARGE_75, + "Detailed timing is not preferred, use largest mode at 75Hz" + }, + { + quirk_detailed_h_in_cm, DDC_QUIRK_DETAILED_H_IN_CM, + "Detailed timings give horizontal size in cm." + }, + { + quirk_detailed_v_in_cm, DDC_QUIRK_DETAILED_V_IN_CM, + "Detailed timings give vertical size in cm." + }, + { + quirk_detailed_use_maximum_size, DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE, + "Detailed timings give sizes in cm." + }, + { + quirk_first_detailed_preferred, DDC_QUIRK_FIRST_DETAILED_PREFERRED, + "First detailed timing was not marked as preferred." + }, + { + quirk_detailed_sync_pp, DDC_QUIRK_DETAILED_SYNC_PP, + "Use +hsync +vsync for detailed timing." + }, { NULL, DDC_QUIRK_NONE, "No known quirks" @@ -116,27 +230,27 @@ static const ddc_quirk_map_t ddc_quirks[] = { * TODO: * - for those with access to the VESA DMT standard; review please. */ -#define MODEPREFIX(name) NULL, NULL, name, 0,M_T_DRIVER -#define MODESUFFIX 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0 - -static DisplayModeRec DDCEstablishedModes[17] = { - { MODEPREFIX("800x600"), 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@60Hz */ - { MODEPREFIX("800x600"), 36000, 800, 824, 896, 1024, 0, 600, 601, 603, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@56Hz */ - { MODEPREFIX("640x480"), 31500, 640, 656, 720, 840, 0, 480, 481, 484, 500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@75Hz */ - { MODEPREFIX("640x480"), 31500, 640, 664, 704, 832, 0, 480, 489, 491, 520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@72Hz */ - { MODEPREFIX("640x480"), 30240, 640, 704, 768, 864, 0, 480, 483, 486, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@67Hz */ - { MODEPREFIX("640x480"), 25200, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@60Hz */ - { MODEPREFIX("720x400"), 35500, 720, 738, 846, 900, 0, 400, 421, 423, 449, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 720x400@88Hz */ - { MODEPREFIX("720x400"), 28320, 720, 738, 846, 900, 0, 400, 412, 414, 449, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 720x400@70Hz */ - { MODEPREFIX("1280x1024"), 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1280x1024@75Hz */ - { MODEPREFIX("1024x768"), 78800, 1024, 1040, 1136, 1312, 0, 768, 769, 772, 800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1024x768@75Hz */ - { MODEPREFIX("1024x768"), 75000, 1024, 1048, 1184, 1328, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@70Hz */ - { MODEPREFIX("1024x768"), 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@60Hz */ - { MODEPREFIX("1024x768"), 44900, 1024, 1032, 1208, 1264, 0, 768, 768, 776, 817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX }, /* 1024x768@43Hz */ - { MODEPREFIX("832x624"), 57284, 832, 864, 928, 1152, 0, 624, 625, 628, 667, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 832x624@75Hz */ - { MODEPREFIX("800x600"), 49500, 800, 816, 896, 1056, 0, 600, 601, 604, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@75Hz */ - { MODEPREFIX("800x600"), 50000, 800, 856, 976, 1040, 0, 600, 637, 643, 666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@72Hz */ - { MODEPREFIX("1152x864"), 108000, 1152, 1216, 1344, 1600, 0, 864, 865, 868, 900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1152x864@75Hz */ +#define MODEPREFIX NULL, NULL, NULL, 0, M_T_DRIVER +#define MODESUFFIX 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0 + +static const DisplayModeRec DDCEstablishedModes[17] = { + { MODEPREFIX, 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@60Hz */ + { MODEPREFIX, 36000, 800, 824, 896, 1024, 0, 600, 601, 603, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@56Hz */ + { MODEPREFIX, 31500, 640, 656, 720, 840, 0, 480, 481, 484, 500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@75Hz */ + { MODEPREFIX, 31500, 640, 664, 704, 832, 0, 480, 489, 491, 520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@72Hz */ + { MODEPREFIX, 30240, 640, 704, 768, 864, 0, 480, 483, 486, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@67Hz */ + { MODEPREFIX, 25200, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@60Hz */ + { MODEPREFIX, 35500, 720, 738, 846, 900, 0, 400, 421, 423, 449, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 720x400@88Hz */ + { MODEPREFIX, 28320, 720, 738, 846, 900, 0, 400, 412, 414, 449, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 720x400@70Hz */ + { MODEPREFIX, 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1280x1024@75Hz */ + { MODEPREFIX, 78800, 1024, 1040, 1136, 1312, 0, 768, 769, 772, 800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1024x768@75Hz */ + { MODEPREFIX, 75000, 1024, 1048, 1184, 1328, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@70Hz */ + { MODEPREFIX, 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@60Hz */ + { MODEPREFIX, 44900, 1024, 1032, 1208, 1264, 0, 768, 768, 776, 817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX }, /* 1024x768@43Hz */ + { MODEPREFIX, 57284, 832, 864, 928, 1152, 0, 624, 625, 628, 667, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 832x624@75Hz */ + { MODEPREFIX, 49500, 800, 816, 896, 1056, 0, 600, 601, 604, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@75Hz */ + { MODEPREFIX, 50000, 800, 856, 976, 1040, 0, 600, 637, 643, 666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@72Hz */ + { MODEPREFIX, 108000, 1152, 1216, 1344, 1600, 0, 864, 865, 868, 900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1152x864@75Hz */ }; static DisplayModePtr @@ -158,20 +272,57 @@ DDCModesFromEstablished(int scrnIndex, struct established_timings *timing, return Modes; } +#define LEVEL_DMT 0 +#define LEVEL_GTF 1 +#define LEVEL_CVT 2 + +static int +MonitorStandardTimingLevel(xf86MonPtr DDC) +{ + if (DDC->ver.revision >= 2) { + if (DDC->ver.revision >= 4 && CVT_SUPPORTED(DDC->features.msc)) { + return LEVEL_CVT; + } + return LEVEL_GTF; + } + return LEVEL_DMT; +} + /* + * This is not really correct. Appendix B of the EDID 1.4 spec defines + * the right thing to do here. If the timing given here matches a mode + * defined in the VESA DMT standard, we _must_ use that. If the device + * supports CVT modes, then we should generate a CVT timing. If both + * of the above fail, use GTF. + * + * There are some wrinkles here. EDID 1.1 and 1.0 sinks can't really + * "support" GTF, since it wasn't a standard yet; so if they ask for a + * timing in this section that isn't defined in DMT, returning a GTF mode + * may not actually be valid. EDID 1.3 sinks often report support for + * some CVT modes, but they are not required to support CVT timings for + * modes in the standard timing descriptor, so we should _not_ treat them + * as CVT-compliant (unless specified in an extension block I suppose). * + * EDID 1.4 requires that all sink devices support both GTF and CVT timings + * for modes in this section, but does say that CVT is preferred. */ static DisplayModePtr -DDCModesFromStandardTiming(int scrnIndex, struct std_timings *timing, - ddc_quirk_t quirks) +DDCModesFromStandardTiming(struct std_timings *timing, ddc_quirk_t quirks, + int timing_level) { DisplayModePtr Modes = NULL, Mode = NULL; int i; for (i = 0; i < STD_TIMINGS; i++) { if (timing[i].hsize && timing[i].vsize && timing[i].refresh) { - Mode = xf86CVTMode(timing[i].hsize, timing[i].vsize, - timing[i].refresh, FALSE, FALSE); + /* XXX check for DMT first, else... */ + if (timing_level == LEVEL_CVT) + Mode = xf86CVTMode(timing[i].hsize, timing[i].vsize, + timing[i].refresh, FALSE, FALSE); + else + Mode = xf86GTFMode(timing[i].hsize, timing[i].vsize, + timing[i].refresh, FALSE, FALSE); + Mode->type = M_T_DRIVER; Modes = xf86ModesAdd(Modes, Mode); } @@ -185,7 +336,7 @@ DDCModesFromStandardTiming(int scrnIndex, struct std_timings *timing, */ static DisplayModePtr DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, - int preferred, ddc_quirk_t quirks) + Bool preferred, ddc_quirk_t quirks) { DisplayModePtr Mode; @@ -216,8 +367,7 @@ DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, " sync.\n", __func__, timing->h_active, timing->v_active); } - Mode = xnfalloc(sizeof(DisplayModeRec)); - memset(Mode, 0, sizeof(DisplayModeRec)); + Mode = xnfcalloc(1, sizeof(DisplayModeRec)); Mode->type = M_T_DRIVER; if (preferred) @@ -239,6 +389,12 @@ DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, Mode->VSyncEnd = Mode->VSyncStart + timing->v_sync_width; Mode->VTotal = timing->v_active + timing->v_blanking; + /* perform basic check on the detail timing */ + if (Mode->HSyncEnd > Mode->HTotal || Mode->VSyncEnd > Mode->VTotal) { + xfree(Mode); + return NULL; + } + xf86SetModeDefaultName(Mode); /* We ignore h/v_size and h/v_border for now. */ @@ -246,21 +402,59 @@ DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, if (timing->interlaced) Mode->Flags |= V_INTERLACE; - if (timing->misc & 0x02) - Mode->Flags |= V_PVSYNC; - else - Mode->Flags |= V_NVSYNC; - - if (timing->misc & 0x01) - Mode->Flags |= V_PHSYNC; - else - Mode->Flags |= V_NHSYNC; + if (quirks & DDC_QUIRK_DETAILED_SYNC_PP) + Mode->Flags |= V_PVSYNC | V_PHSYNC; + else { + if (timing->misc & 0x02) + Mode->Flags |= V_PVSYNC; + else + Mode->Flags |= V_NVSYNC; + + if (timing->misc & 0x01) + Mode->Flags |= V_PHSYNC; + else + Mode->Flags |= V_NHSYNC; + } return Mode; } +static DisplayModePtr +DDCModesFromCVT(int scrnIndex, struct cvt_timings *t) +{ + DisplayModePtr modes = NULL; + int i; + + for (i = 0; i < 4; i++) { + if (t[i].height) { + if (t[i].rates & 0x10) + modes = xf86ModesAdd(modes, + xf86CVTMode(t[i].width, t[i].height, 50, 0, 0)); + if (t[i].rates & 0x08) + modes = xf86ModesAdd(modes, + xf86CVTMode(t[i].width, t[i].height, 60, 0, 0)); + if (t[i].rates & 0x04) + modes = xf86ModesAdd(modes, + xf86CVTMode(t[i].width, t[i].height, 75, 0, 0)); + if (t[i].rates & 0x02) + modes = xf86ModesAdd(modes, + xf86CVTMode(t[i].width, t[i].height, 85, 0, 0)); + if (t[i].rates & 0x01) + modes = xf86ModesAdd(modes, + xf86CVTMode(t[i].width, t[i].height, 60, 1, 0)); + } else break; + } + + return modes; +} + + /* - * + * This is only valid when the sink claims to be continuous-frequency + * but does not supply a detailed range descriptor. Such sinks are + * arguably broken. Currently the mode validation code isn't aware of + * this; the non-RANDR code even punts the decision of optional sync + * range checking to the driver. Loss. */ static void DDCGuessRangesFromModes(int scrnIndex, MonPtr Monitor, DisplayModePtr Modes) @@ -303,27 +497,121 @@ DDCGuessRangesFromModes(int scrnIndex, MonPtr Monitor, DisplayModePtr Modes) } } +static ddc_quirk_t +xf86DDCDetectQuirks(int scrnIndex, xf86MonPtr DDC, Bool verbose) +{ + ddc_quirk_t quirks; + int i; + + quirks = DDC_QUIRK_NONE; + for (i = 0; ddc_quirks[i].detect; i++) { + if (ddc_quirks[i].detect (scrnIndex, DDC)) { + if (verbose) { + xf86DrvMsg (scrnIndex, X_INFO, " EDID quirk: %s\n", + ddc_quirks[i].description); + } + quirks |= ddc_quirks[i].quirk; + } + } + + return quirks; +} + +/** + * Applies monitor-specific quirks to the decoded EDID information. + * + * Note that some quirks applying to the mode list are still implemented in + * xf86DDCGetModes. + */ +void +xf86DDCApplyQuirks(int scrnIndex, xf86MonPtr DDC) +{ + ddc_quirk_t quirks = xf86DDCDetectQuirks (scrnIndex, DDC, FALSE); + int i; + + for (i = 0; i < DET_TIMINGS; i++) { + struct detailed_monitor_section *det_mon = &DDC->det_mon[i]; + + if (det_mon->type != DT) + continue; + + if (quirks & DDC_QUIRK_DETAILED_H_IN_CM) + det_mon->section.d_timings.h_size *= 10; + + if (quirks & DDC_QUIRK_DETAILED_V_IN_CM) + det_mon->section.d_timings.v_size *= 10; + + if (quirks & DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE) { + det_mon->section.d_timings.h_size = 10 * DDC->features.hsize; + det_mon->section.d_timings.v_size = 10 * DDC->features.vsize; + } + } +} + +/** + * Walks the modes list, finding the mode with the largest area which is + * closest to the target refresh rate, and marks it as the only preferred mode. +*/ +static void +xf86DDCSetPreferredRefresh(int scrnIndex, DisplayModePtr modes, + float target_refresh) +{ + DisplayModePtr mode, best = modes; + + for (mode = modes; mode; mode = mode->next) + { + mode->type &= ~M_T_PREFERRED; + + if (mode == best) continue; + + if (mode->HDisplay * mode->VDisplay > + best->HDisplay * best->VDisplay) + { + best = mode; + continue; + } + if (mode->HDisplay * mode->VDisplay == + best->HDisplay * best->VDisplay) + { + double mode_refresh = xf86ModeVRefresh (mode); + double best_refresh = xf86ModeVRefresh (best); + double mode_dist = fabs(mode_refresh - target_refresh); + double best_dist = fabs(best_refresh - target_refresh); + + if (mode_dist < best_dist) + { + best = mode; + continue; + } + } + } + if (best) + best->type |= M_T_PREFERRED; +} + _X_EXPORT DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC) { - int preferred, i; + int i; DisplayModePtr Modes = NULL, Mode; ddc_quirk_t quirks; + Bool preferred; + int timing_level; xf86DrvMsg (scrnIndex, X_INFO, "EDID vendor \"%s\", prod id %d\n", DDC->vendor.name, DDC->vendor.prod_id); - quirks = DDC_QUIRK_NONE; - for (i = 0; ddc_quirks[i].detect; i++) - if (ddc_quirks[i].detect (scrnIndex, DDC)) - { - xf86DrvMsg (scrnIndex, X_INFO, " EDID quirk: %s\n", - ddc_quirks[i].description); - quirks |= ddc_quirks[i].quirk; - } - + + quirks = xf86DDCDetectQuirks(scrnIndex, DDC, TRUE); + preferred = PREFERRED_TIMING_MODE(DDC->features.msc); - if (quirks & DDC_QUIRK_PREFER_LARGE_60) - preferred = 0; + if (DDC->ver.revision >= 4) + preferred = TRUE; + if (quirks & DDC_QUIRK_FIRST_DETAILED_PREFERRED) + preferred = TRUE; + if (quirks & (DDC_QUIRK_PREFER_LARGE_60 | DDC_QUIRK_PREFER_LARGE_75)) + preferred = FALSE; + + timing_level = MonitorStandardTimingLevel(DDC); for (i = 0; i < DET_TIMINGS; i++) { struct detailed_monitor_section *det_mon = &DDC->det_mon[i]; @@ -334,15 +622,18 @@ xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC) &det_mon->section.d_timings, preferred, quirks); - preferred = 0; + preferred = FALSE; Modes = xf86ModesAdd(Modes, Mode); break; case DS_STD_TIMINGS: - Mode = DDCModesFromStandardTiming(scrnIndex, - det_mon->section.std_t, - quirks); + Mode = DDCModesFromStandardTiming(det_mon->section.std_t, + quirks, timing_level); Modes = xf86ModesAdd(Modes, Mode); break; + case DS_CVT: + Mode = DDCModesFromCVT(scrnIndex, det_mon->section.cvt); + Modes = xf86ModesAdd(Modes, Mode); + break; default: break; } @@ -353,36 +644,15 @@ xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC) Modes = xf86ModesAdd(Modes, Mode); /* Add standard timings */ - Mode = DDCModesFromStandardTiming(scrnIndex, DDC->timings2, quirks); + Mode = DDCModesFromStandardTiming(DDC->timings2, quirks, timing_level); Modes = xf86ModesAdd(Modes, Mode); if (quirks & DDC_QUIRK_PREFER_LARGE_60) - { - DisplayModePtr best = Modes; - for (Mode = Modes; Mode; Mode = Mode->next) - { - if (Mode == best) continue; - if (Mode->HDisplay * Mode->VDisplay > best->HDisplay * best->VDisplay) - { - best = Mode; - continue; - } - if (Mode->HDisplay * Mode->VDisplay == best->HDisplay * best->VDisplay) - { - double mode_refresh = xf86ModeVRefresh (Mode); - double best_refresh = xf86ModeVRefresh (best); - double mode_dist = fabs(mode_refresh - 60.0); - double best_dist = fabs(best_refresh - 60.0); - if (mode_dist < best_dist) - { - best = Mode; - continue; - } - } - } - if (best) - best->type |= M_T_PREFERRED; - } + xf86DDCSetPreferredRefresh(scrnIndex, Modes, 60); + + if (quirks & DDC_QUIRK_PREFER_LARGE_75) + xf86DDCSetPreferredRefresh(scrnIndex, Modes, 75); + return Modes; } @@ -401,13 +671,17 @@ xf86DDCMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC) Monitor->DDC = DDC; - Monitor->widthmm = 10 * DDC->features.hsize; - Monitor->heightmm = 10 * DDC->features.vsize; + if (Monitor->widthmm <= 0 && Monitor->heightmm <= 0) { + Monitor->widthmm = 10 * DDC->features.hsize; + Monitor->heightmm = 10 * DDC->features.vsize; + } - /* If this is a digital display, then we can use reduced blanking */ + /* + * If this is a digital display, then we can use reduced blanking. + * XXX This is a 1.3 heuristic. 1.4 explicitly defines rb support. + */ if (DDC->features.input_type) Monitor->reducedblanking = TRUE; - /* Allow the user to also enable this through config */ Modes = xf86DDCGetModes(scrnIndex, DDC); diff --git a/driver/xf86-video-nv/compat/modes/xf86Modes.c b/driver/xf86-video-nv/compat/modes/xf86Modes.c index f49c2921c..ea398ad81 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Modes.c +++ b/driver/xf86-video-nv/compat/modes/xf86Modes.c @@ -38,12 +38,14 @@ extern XF86ConfigPtr xf86configptr; -/** - * @file this file contains symbols from xf86Mode.c and friends that are static - * there but we still want to use. We need to come up with better API here. +/* + * This is the version number where we epoched. These files get copied + * into drivers that want to use this setup infrastructure on pre-1.3 + * servers, so when that happens they need to define these symbols + * themselves. However, _in_ the server, we basically always define them now. */ - #if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,2,99,2,0) + /** * Calculates the horizontal sync rate of a mode. * @@ -116,6 +118,24 @@ xf86ModeHeight (DisplayModePtr mode, Rotation rotation) } } +/** Calculates the memory bandwidth (in MiB/sec) of a mode. */ +_X_EXPORT unsigned int +xf86ModeBandwidth(DisplayModePtr mode, int depth) +{ + float a_active, a_total, active_percent, pixels_per_second; + int bytes_per_pixel = (depth + 7) / 8; + + if (!mode->HTotal || !mode->VTotal || !mode->Clock) + return 0; + + a_active = mode->HDisplay * mode->VDisplay; + a_total = mode->HTotal * mode->VTotal; + active_percent = a_active / a_total; + pixels_per_second = active_percent * mode->Clock * 1000.0; + + return (unsigned int)(pixels_per_second * bytes_per_pixel / (1024 * 1024)); +} + /** Sets a default mode name of <width>x<height> on a mode. */ _X_EXPORT void xf86SetModeDefaultName(DisplayModePtr mode) @@ -194,11 +214,11 @@ xf86DuplicateMode(DisplayModePtr pMode) *pNew = *pMode; pNew->next = NULL; pNew->prev = NULL; - if (pNew->name == NULL) { - xf86SetModeDefaultName(pMode); - } else { + + if (pMode->name == NULL) + xf86SetModeDefaultName(pNew); + else pNew->name = xnfstrdup(pMode->name); - } return pNew; } @@ -320,12 +340,10 @@ xf86PrintModeline(int scrnIndex,DisplayModePtr mode) /** * Marks as bad any modes with unsupported flags. * - * \param modeList doubly-linked or circular list of modes. + * \param modeList doubly-linked list of modes. * \param flags flags supported by the driver. * * \bug only V_INTERLACE and V_DBLSCAN are supported. Is that enough? - * - * This is not in xf86Modes.c, but would be part of the proposed new API. */ _X_EXPORT void xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, @@ -344,9 +362,7 @@ xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, /** * Marks as bad any modes extending beyond the given max X, Y, or pitch. * - * \param modeList doubly-linked or circular list of modes. - * - * This is not in xf86Modes.c, but would be part of the proposed new API. + * \param modeList doubly-linked list of modes. */ _X_EXPORT void xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, @@ -373,9 +389,7 @@ xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, * Marks as bad any modes that aren't supported by the given monitor's * hsync and vrefresh ranges. * - * \param modeList doubly-linked or circular list of modes. - * - * This is not in xf86Modes.c, but would be part of the proposed new API. + * \param modeList doubly-linked list of modes. */ _X_EXPORT void xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, @@ -389,8 +403,8 @@ xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, bad = TRUE; for (i = 0; i < mon->nHsync; i++) { - if (xf86ModeHSync(mode) >= mon->hsync[i].lo && - xf86ModeHSync(mode) <= mon->hsync[i].hi) + if (xf86ModeHSync(mode) >= mon->hsync[i].lo * (1-SYNC_TOLERANCE) && + xf86ModeHSync(mode) <= mon->hsync[i].hi * (1+SYNC_TOLERANCE)) { bad = FALSE; } @@ -400,8 +414,8 @@ xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, bad = TRUE; for (i = 0; i < mon->nVrefresh; i++) { - if (xf86ModeVRefresh(mode) >= mon->vrefresh[i].lo && - xf86ModeVRefresh(mode) <= mon->vrefresh[i].hi) + if (xf86ModeVRefresh(mode) >= mon->vrefresh[i].lo * (1-SYNC_TOLERANCE) && + xf86ModeVRefresh(mode) <= mon->vrefresh[i].hi * (1+SYNC_TOLERANCE)) { bad = FALSE; } @@ -417,12 +431,10 @@ xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, /** * Marks as bad any modes extending beyond outside of the given clock ranges. * - * \param modeList doubly-linked or circular list of modes. + * \param modeList doubly-linked list of modes. * \param min pointer to minimums of clock ranges * \param max pointer to maximums of clock ranges * \param n_ranges number of ranges. - * - * This is not in xf86Modes.c, but would be part of the proposed new API. */ _X_EXPORT void xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, @@ -434,7 +446,8 @@ xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, for (mode = modeList; mode != NULL; mode = mode->next) { Bool good = FALSE; for (i = 0; i < n_ranges; i++) { - if (mode->Clock >= min[i] && mode->Clock <= max[i]) { + if (mode->Clock >= min[i] * (1-SYNC_TOLERANCE) && + mode->Clock <= max[i] * (1+SYNC_TOLERANCE)) { good = TRUE; break; } @@ -454,9 +467,7 @@ xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, * * MODE_BAD is used as the rejection flag, for lack of a better flag. * - * \param modeList doubly-linked or circular list of modes. - * - * This is not in xf86Modes.c, but would be part of the proposed new API. + * \param modeList doubly-linked list of modes. */ _X_EXPORT void xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList) @@ -484,13 +495,52 @@ xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList) /** + * Marks as bad any modes exceeding the given bandwidth. + * + * \param modeList doubly-linked list of modes. + * \param bandwidth bandwidth in MHz. + * \param depth color depth. + */ +_X_EXPORT void +xf86ValidateModesBandwidth(ScrnInfoPtr pScrn, DisplayModePtr modeList, + unsigned int bandwidth, int depth) +{ + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + if (xf86ModeBandwidth(mode, depth) > bandwidth) + mode->status = MODE_BANDWIDTH; + } +} + +/** + * Marks as bad any reduced-blanking modes. + * + * \param modeList doubly-linked list of modes. + */ +_X_EXPORT void +xf86ValidateModesReducedBlanking(ScrnInfoPtr pScrn, DisplayModePtr modeList) +{ + Bool mode_is_reduced = FALSE; + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + /* gratuitous duplication from pre-randr validation code */ + if ((((mode->HDisplay * 5 / 4) & ~0x07) > mode->HTotal) && + ((mode->HTotal - mode->HDisplay) == 160) && + ((mode->HSyncEnd - mode->HDisplay) == 80) && + ((mode->HSyncEnd - mode->HSyncStart) == 32) && + ((mode->VSyncStart - mode->VDisplay) == 3)) + mode->status = MODE_NO_REDUCED; + } +} + +/** * Frees any modes from the list with a status other than MODE_OK. * * \param modeList pointer to a doubly-linked or circular list of modes. * \param verbose determines whether the reason for mode invalidation is * printed. - * - * This is not in xf86Modes.c, but would be part of the proposed new API. */ _X_EXPORT void xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList, @@ -630,7 +680,7 @@ xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed) DisplayModePtr head = NULL, prev = NULL, mode; int i; - for (i = 0; xf86DefaultModes[i].name != NULL; i++) + for (i = 0; i < xf86NumDefaultModes; i++) { DisplayModePtr defMode = &xf86DefaultModes[i]; @@ -639,23 +689,9 @@ xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed) if (!doubleScanAllowed && (defMode->Flags & V_DBLSCAN)) continue; - mode = xalloc(sizeof(DisplayModeRec)); - if (!mode) - continue; - memcpy(mode,&xf86DefaultModes[i],sizeof(DisplayModeRec)); - mode->name = xstrdup(xf86DefaultModes[i].name); - if (!mode->name) - { - xfree (mode); - continue; - } - mode->prev = prev; - mode->next = NULL; - if (prev) - prev->next = mode; - else - head = mode; - prev = mode; + mode = xf86DuplicateMode(defMode); + + head = xf86ModesAdd(head, mode); } return head; } diff --git a/driver/xf86-video-nv/compat/modes/xf86Modes.h b/driver/xf86-video-nv/compat/modes/xf86Modes.h index 2bd4edeba..acdea65d8 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Modes.h +++ b/driver/xf86-video-nv/compat/modes/xf86Modes.h @@ -42,6 +42,7 @@ double xf86ModeHSync(DisplayModePtr mode); double xf86ModeVRefresh(DisplayModePtr mode); +unsigned int xf86ModeBandwidth(DisplayModePtr mode, int depth); int xf86ModeWidth (DisplayModePtr mode, Rotation rotation); @@ -61,6 +62,7 @@ DisplayModePtr xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new); DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC); DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, Bool Interlaced); +DisplayModePtr xf86GTFMode(int h_pixels, int v_lines, float freq, int interlaced, int margins); void xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, @@ -79,6 +81,13 @@ xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, MonPtr mon); void +xf86ValidateModesBandwidth(ScrnInfoPtr pScrn, DisplayModePtr modeList, + unsigned int bandwidth, int depth); + +void +xf86ValidateModesReducedBlanking(ScrnInfoPtr pScrn, DisplayModePtr modeList); + +void xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList, Bool verbose); @@ -95,4 +104,7 @@ xf86GetMonitorModes (ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor); DisplayModePtr xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed); +void +xf86DDCApplyQuirks(int scrnIndex, xf86MonPtr DDC); + #endif /* _XF86MODES_H_ */ diff --git a/driver/xf86-video-nv/compat/modes/xf86RandR12.c b/driver/xf86-video-nv/compat/modes/xf86RandR12.c index 38435c924..6f8ccdf84 100644 --- a/driver/xf86-video-nv/compat/modes/xf86RandR12.c +++ b/driver/xf86-video-nv/compat/modes/xf86RandR12.c @@ -59,11 +59,11 @@ static Bool xf86RandR12Init12 (ScreenPtr pScreen); static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen); #endif -static int xf86RandR12Index; -static int xf86RandR12Generation; +static int xf86RandR12Generation; +static DevPrivateKey xf86RandR12Key; -#define XF86RANDRINFO(p) \ - ((XF86RandRInfoPtr)(p)->devPrivates[xf86RandR12Index].ptr) +#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \ + dixLookupPrivate(&(p)->devPrivates, xf86RandR12Key)) static int xf86RandR12ModeRefresh (DisplayModePtr mode) @@ -119,9 +119,7 @@ xf86RandR12GetInfo (ScreenPtr pScreen, Rotation *rotations) return FALSE; RRRegisterRate (pScreen, pSize, refresh); - if (xf86ModesEqual(mode, scrp->currentMode) && - mode->HDisplay == scrp->virtualX && - mode->VDisplay == scrp->virtualY) + if (xf86ModesEqual(mode, scrp->currentMode)) { RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize); } @@ -135,23 +133,6 @@ xf86RandR12GetInfo (ScreenPtr pScreen, Rotation *rotations) randrp->maxY = maxY; } - if (scrp->currentMode->HDisplay != randrp->virtualX || - scrp->currentMode->VDisplay != randrp->virtualY) - { - pSize = RRRegisterSize (pScreen, - randrp->virtualX, randrp->virtualY, - randrp->mmWidth, - randrp->mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate (pScreen, pSize, refresh0); - if (scrp->virtualX == randrp->virtualX && - scrp->virtualY == randrp->virtualY) - { - RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize); - } - } - return TRUE; } @@ -340,10 +321,12 @@ xf86RandR12ScreenSetSize (ScreenPtr pScreen, PixmapPtr pScrnPix = (*pScreen->GetScreenPixmap)(pScreen); Bool ret = FALSE; - if (randrp->virtualX == -1 || randrp->virtualY == -1) - { - randrp->virtualX = pScrn->virtualX; - randrp->virtualY = pScrn->virtualY; + if (xf86RandR12Key) { + if (randrp->virtualX == -1 || randrp->virtualY == -1) + { + randrp->virtualX = pScrn->virtualX; + randrp->virtualY = pScrn->virtualY; + } } if (pRoot && pScrn->vtSema) (*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE); @@ -356,8 +339,8 @@ xf86RandR12ScreenSetSize (ScreenPtr pScreen, pScreen->width = pScrnPix->drawable.width = width; pScreen->height = pScrnPix->drawable.height = height; - pScreen->mmWidth = mmWidth; - pScreen->mmHeight = mmHeight; + randrp->mmWidth = pScreen->mmWidth = mmWidth; + randrp->mmHeight = pScreen->mmHeight = mmHeight; xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1); xf86SetViewport (pScreen, 0, 0); @@ -366,7 +349,7 @@ finish: if (pRoot && pScrn->vtSema) (*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE); #if RANDR_12_INTERFACE - if (WindowTable[pScreen->myNum] && ret) + if (xf86RandR12Key && WindowTable[pScreen->myNum] && ret) RRScreenSizeNotify (pScreen); #endif return ret; @@ -426,8 +409,18 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen) xf86OutputPtr output = config->output[config->compat_output]; xf86CrtcPtr crtc = output->crtc; - if (crtc && crtc->mode.HDisplay && - output->mm_width && output->mm_height) + if (output->conf_monitor && + (output->conf_monitor->mon_width > 0 && + output->conf_monitor->mon_height > 0)) + { + /* + * Prefer user configured DisplaySize + */ + mmWidth = output->conf_monitor->mon_width; + mmHeight = output->conf_monitor->mon_height; + } + else if (crtc && crtc->mode.HDisplay && + output->mm_width && output->mm_height) { /* * If the output has a mode and a declared size, use that @@ -440,10 +433,10 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen) else { /* - * Otherwise, just set the screen to 96dpi + * Otherwise, just set the screen to DEFAULT_DPI */ - mmWidth = width * 25.4 / 96; - mmHeight = height * 25.4 / 96; + mmWidth = width * 25.4 / DEFAULT_DPI; + mmHeight = height * 25.4 / DEFAULT_DPI; } } xf86DrvMsg(pScrn->scrnIndex, X_INFO, @@ -456,6 +449,9 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen) mmHeight); } + if (xf86RandR12Key == NULL) + return TRUE; + if (randrp->virtualX == -1 || randrp->virtualY == -1) { randrp->virtualX = pScrn->virtualX; @@ -481,11 +477,11 @@ xf86RandR12Init (ScreenPtr pScreen) if (!noPanoramiXExtension) return TRUE; #endif + if (xf86RandR12Generation != serverGeneration) - { - xf86RandR12Index = AllocateScreenPrivateIndex(); xf86RandR12Generation = serverGeneration; - } + + xf86RandR12Key = &xf86RandR12Key; randrp = xalloc (sizeof (XF86RandRInfoRec)); if (!randrp) @@ -511,7 +507,7 @@ xf86RandR12Init (ScreenPtr pScreen) randrp->maxX = randrp->maxY = 0; - pScreen->devPrivates[xf86RandR12Index].ptr = randrp; + dixSetPrivate(&pScreen->devPrivates, xf86RandR12Key, randrp); #if RANDR_12_INTERFACE if (!xf86RandR12Init12 (pScreen)) @@ -523,12 +519,18 @@ xf86RandR12Init (ScreenPtr pScreen) _X_EXPORT void xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotations) { - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + XF86RandRInfoPtr randrp; #if RANDR_12_INTERFACE ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; int c; xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); +#endif + + if (xf86RandR12Key == NULL) + return; + randrp = XF86RANDRINFO(pScreen); +#if RANDR_12_INTERFACE for (c = 0; c < config->num_crtc; c++) { xf86CrtcPtr crtc = config->crtc[c]; @@ -626,7 +628,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr randr_crtc) DisplayModePtr mode = &crtc->mode; Bool ret; - randr_outputs = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr)); + randr_outputs = xalloc(config->num_output * sizeof (RROutputPtr)); if (!randr_outputs) return FALSE; x = crtc->x; @@ -661,7 +663,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr randr_crtc) } ret = RRCrtcNotify (randr_crtc, randr_mode, x, y, rotation, numOutputs, randr_outputs); - DEALLOCATE_LOCAL(randr_outputs); + xfree(randr_outputs); return ret; } @@ -673,11 +675,8 @@ xf86RandRModeConvert (ScrnInfoPtr scrn, RRModePtr randr_mode, DisplayModePtr mode) { - mode->prev = NULL; - mode->next = NULL; - mode->name = NULL; + memset(mode, 0, sizeof(DisplayModeRec)); mode->status = MODE_OK; - mode->type = 0; mode->Clock = randr_mode->mode.dotClock / 1000; @@ -716,7 +715,10 @@ xf86RandR12CrtcSet (ScreenPtr pScreen, xf86CrtcPtr *save_crtcs; Bool save_enabled = crtc->enabled; - save_crtcs = ALLOCATE_LOCAL(config->num_output * sizeof (xf86CrtcPtr)); + if (!crtc->scrn->vtSema) + return FALSE; + + save_crtcs = xalloc(config->num_output * sizeof (xf86CrtcPtr)); if ((randr_mode != NULL) != crtc->enabled) changed = TRUE; else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode)) @@ -772,7 +774,7 @@ xf86RandR12CrtcSet (ScreenPtr pScreen, xf86OutputPtr output = config->output[o]; output->crtc = save_crtcs[o]; } - DEALLOCATE_LOCAL(save_crtcs); + xfree(save_crtcs); return FALSE; } /* @@ -785,7 +787,7 @@ xf86RandR12CrtcSet (ScreenPtr pScreen, } xf86DisableUnusedFunctions (pScrn); } - DEALLOCATE_LOCAL(save_crtcs); + xfree(save_crtcs); return xf86RandR12CrtcNotify (randr_crtc); } @@ -928,8 +930,8 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen) RRCrtcPtr randr_crtc; int nclone; - clones = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr)); - crtcs = ALLOCATE_LOCAL (config->num_crtc * sizeof (RRCrtcPtr)); + clones = xalloc(config->num_output * sizeof (RROutputPtr)); + crtcs = xalloc (config->num_crtc * sizeof (RRCrtcPtr)); for (o = 0; o < config->num_output; o++) { xf86OutputPtr output = config->output[o]; @@ -946,8 +948,8 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen) if (!RROutputSetCrtcs (output->randr_output, crtcs, ncrtc)) { - DEALLOCATE_LOCAL (crtcs); - DEALLOCATE_LOCAL (clones); + xfree (crtcs); + xfree (clones); return FALSE; } @@ -983,13 +985,13 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen) } if (!RROutputSetClones (output->randr_output, clones, nclone)) { - DEALLOCATE_LOCAL (crtcs); - DEALLOCATE_LOCAL (clones); + xfree (crtcs); + xfree (clones); return FALSE; } } - DEALLOCATE_LOCAL (crtcs); - DEALLOCATE_LOCAL (clones); + xfree (crtcs); + xfree (clones); return TRUE; } @@ -1058,9 +1060,11 @@ xf86RandR12CreateScreenResources12 (ScreenPtr pScreen) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + if (xf86RandR12Key == NULL) + return TRUE; + for (c = 0; c < config->num_crtc; c++) - xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc); - + xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc); RRScreenSetSizeRange (pScreen, config->minWidth, config->minHeight, config->maxWidth, config->maxHeight); @@ -1077,11 +1081,11 @@ xf86RandR12TellChanged (ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); int c; - if (!randrp) + if (xf86RandR12Key == NULL) return; + xf86RandR12SetInfo12 (pScreen); for (c = 0; c < config->num_crtc; c++) xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc); diff --git a/driver/xf86-video-nv/compat/modes/xf86Rotate.c b/driver/xf86-video-nv/compat/modes/xf86Rotate.c index 380478f7f..e2d6295b9 100644 --- a/driver/xf86-video-nv/compat/modes/xf86Rotate.c +++ b/driver/xf86-video-nv/compat/modes/xf86Rotate.c @@ -494,7 +494,8 @@ xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation) { ScrnInfoPtr pScrn = crtc->scrn; xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; + /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */ + ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex]; PictTransform crtc_to_fb, fb_to_crtc; PictureTransformIdentity (&crtc_to_fb); @@ -579,9 +580,9 @@ xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation) } else { - PictureTransformTranslate (&crtc_to_fb, &fb_to_crtc, crtc->x, crtc->y); + PictureTransformTranslate (&crtc_to_fb, &fb_to_crtc, F(crtc->x), F(crtc->y)); PictureTransformIsInverse ("offset", &crtc_to_fb, &fb_to_crtc); - + /* * these are the size of the shadow pixmap, which * matches the mode, not the pre-rotated copy in the diff --git a/driver/xf86-video-nv/compat/modes/xf86cvt.c b/driver/xf86-video-nv/compat/modes/xf86cvt.c index 69ccc4259..e9c74aa62 100644 --- a/driver/xf86-video-nv/compat/modes/xf86cvt.c +++ b/driver/xf86-video-nv/compat/modes/xf86cvt.c @@ -20,11 +20,6 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @file This is a copy of xf86cvt.c from the X Server, for compatibility with - * old servers (pre-1.2). - */ - /* * The reason for having this function in a file of its own is * so that ../utils/cvt/cvt can link to it, and that xf86CVTMode @@ -72,7 +67,7 @@ _X_EXPORT DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, Bool Interlaced) { - DisplayModeRec *Mode = xnfalloc(sizeof(DisplayModeRec)); + DisplayModeRec *Mode = xnfcalloc(1, sizeof(DisplayModeRec)); /* 1) top/bottom margin size (% of height) - default: 1.8 */ #define CVT_MARGIN_PERCENTAGE 1.8 @@ -95,8 +90,6 @@ xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, int VDisplayRnd, VMargin, VSync; float Interlace; /* Please rename this */ - memset(Mode, 0, sizeof(DisplayModeRec)); - /* CVT default is 60.0Hz */ if (!VRefresh) VRefresh = 60.0; diff --git a/driver/xf86-video-nv/compat/parser/xf86Parser.h b/driver/xf86-video-nv/compat/parser/xf86Parser.h index dc30823cc..fd6cc530b 100644 --- a/driver/xf86-video-nv/compat/parser/xf86Parser.h +++ b/driver/xf86-video-nv/compat/parser/xf86Parser.h @@ -71,7 +71,6 @@ typedef struct { char *file_logfile; - char *file_rgbpath; char *file_modulepath; char *file_inputdevs; char *file_fontpath; @@ -308,6 +307,7 @@ typedef struct XF86ConfDisplayPtr scrn_display_lst; XF86OptionPtr scrn_option_lst; char *scrn_comment; + int scrn_virtualX, scrn_virtualY; } XF86ConfScreenRec, *XF86ConfScreenPtr; |