xf86Crtc.c 83.9 KB
Newer Older
1 2
/*
 * Copyright © 2006 Keith Packard
3
 * Copyright © 2008 Red Hat, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of the copyright holders not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no representations
 * about the suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 */

#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
26 27 28 29
#else
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
30 31 32 33 34 35 36 37 38 39
#endif

#include <stddef.h>
#include <string.h>
#include <stdio.h>

#include "xf86.h"
#include "xf86DDC.h"
#include "xf86Crtc.h"
#include "xf86Modes.h"
40
#include "xf86Priv.h"
41 42
#include "xf86RandR12.h"
#include "X11/extensions/render.h"
Peter Hutterer's avatar
Peter Hutterer committed
43
#include "X11/extensions/dpmsconst.h"
44
#include "X11/Xatom.h"
45
#include "picturestr.h"
46

47 48
#include "xf86xv.h"

49 50
#define NO_OUTPUT_DEFAULT_WIDTH 1024
#define NO_OUTPUT_DEFAULT_HEIGHT 768
51 52 53 54
/*
 * Initialize xf86CrtcConfig structure
 */

55
int xf86CrtcConfigPrivateIndex = -1;
56

57
void
58 59
xf86CrtcConfigInit (ScrnInfoPtr scrn,
		    const xf86CrtcConfigFuncsRec *funcs)
60 61 62 63 64 65
{
    xf86CrtcConfigPtr	config;
    
    if (xf86CrtcConfigPrivateIndex == -1)
	xf86CrtcConfigPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
    config = xnfcalloc (1, sizeof (xf86CrtcConfigRec));
66 67 68

    config->funcs = funcs;

69 70 71
    scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config;
}
 
72
void
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
		      int minWidth, int minHeight,
		      int maxWidth, int maxHeight)
{
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);

    config->minWidth = minWidth;
    config->minHeight = minHeight;
    config->maxWidth = maxWidth;
    config->maxHeight = maxHeight;
}

/*
 * Crtc functions
 */
88
xf86CrtcPtr
89 90 91 92 93 94
xf86CrtcCreate (ScrnInfoPtr		scrn,
		const xf86CrtcFuncsRec	*funcs)
{
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
    xf86CrtcPtr		crtc, *crtcs;

95
    crtc = calloc(sizeof (xf86CrtcRec), 1);
96 97
    if (!crtc)
	return NULL;
98
    crtc->version = XF86_CRTC_VERSION;
99 100 101 102 103 104 105
    crtc->scrn = scrn;
    crtc->funcs = funcs;
#ifdef RANDR_12_INTERFACE
    crtc->randr_crtc = NULL;
#endif
    crtc->rotation = RR_Rotate_0;
    crtc->desiredRotation = RR_Rotate_0;
106 107 108
    pixman_transform_init_identity (&crtc->crtc_to_framebuffer);
    pixman_f_transform_init_identity (&crtc->f_crtc_to_framebuffer);
    pixman_f_transform_init_identity (&crtc->f_framebuffer_to_crtc);
109 110 111 112 113 114
    crtc->filter = NULL;
    crtc->params = NULL;
    crtc->nparams = 0;
    crtc->filter_width = 0;
    crtc->filter_height = 0;
    crtc->transform_in_use = FALSE;
115 116
    crtc->transformPresent = FALSE;
    crtc->desiredTransformPresent = FALSE;
117 118
    memset (&crtc->bounds, '\0', sizeof (crtc->bounds));

119 120 121
    /* Preallocate gamma at a sensible size. */
    crtc->gamma_size = 256;
    crtc->gamma_red = malloc(3 * crtc->gamma_size * sizeof (CARD16));
122
    if (!crtc->gamma_red) {
123
	free(crtc);
124 125
	return NULL;
    }
126 127 128
    crtc->gamma_green = crtc->gamma_red + crtc->gamma_size;
    crtc->gamma_blue = crtc->gamma_green + crtc->gamma_size;

129
    if (xf86_config->crtc)
130
	crtcs = realloc(xf86_config->crtc,
131 132
			  (xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
    else
133
	crtcs = malloc((xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
134 135
    if (!crtcs)
    {
136
	free(crtc);
137 138 139 140 141 142 143
	return NULL;
    }
    xf86_config->crtc = crtcs;
    xf86_config->crtc[xf86_config->num_crtc++] = crtc;
    return crtc;
}

144
void
145 146 147 148 149 150 151 152 153 154 155
xf86CrtcDestroy (xf86CrtcPtr crtc)
{
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
    int			c;
    
    (*crtc->funcs->destroy) (crtc);
    for (c = 0; c < xf86_config->num_crtc; c++)
	if (xf86_config->crtc[c] == crtc)
	{
	    memmove (&xf86_config->crtc[c],
		     &xf86_config->crtc[c+1],
156
		     ((xf86_config->num_crtc - (c + 1)) * sizeof(void*)));
157 158 159
	    xf86_config->num_crtc--;
	    break;
	}
160
    free(crtc->params);
161
    free(crtc->gamma_red);
162
    free(crtc);
163 164 165 166 167 168 169
}


/**
 * Return whether any outputs are connected to the specified pipe
 */

170
Bool
171 172 173 174 175 176 177 178 179 180 181 182
xf86CrtcInUse (xf86CrtcPtr crtc)
{
    ScrnInfoPtr		pScrn = crtc->scrn;
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
    int			o;
    
    for (o = 0; o < xf86_config->num_output; o++)
	if (xf86_config->output[o]->crtc == crtc)
	    return TRUE;
    return FALSE;
}

183
void
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen)
{
    int			subpixel_order = SubPixelUnknown;
    Bool		has_none = FALSE;
    ScrnInfoPtr		scrn = xf86Screens[pScreen->myNum];
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
    int			c, o;

    for (c = 0; c < xf86_config->num_crtc; c++)
    {
	xf86CrtcPtr crtc = xf86_config->crtc[c];
	
	for (o = 0; o < xf86_config->num_output; o++)
	{
	    xf86OutputPtr   output = xf86_config->output[o];

	    if (output->crtc == crtc)
	    {
		switch (output->subpixel_order) {
		case SubPixelNone:
		    has_none = TRUE;
		    break;
		case SubPixelUnknown:
		    break;
		default:
		    subpixel_order = output->subpixel_order;
		    break;
		}
	    }
	    if (subpixel_order != SubPixelUnknown)
		break;
	}
	if (subpixel_order != SubPixelUnknown)
	{
	    static const int circle[4] = {
		SubPixelHorizontalRGB,
		SubPixelVerticalRGB,
		SubPixelHorizontalBGR,
		SubPixelVerticalBGR,
	    };
	    int	rotate;
	    int c;
	    for (rotate = 0; rotate < 4; rotate++)
		if (crtc->rotation & (1 << rotate))
		    break;
	    for (c = 0; c < 4; c++)
		if (circle[c] == subpixel_order)
		    break;
	    c = (c + rotate) & 0x3;
	    if ((crtc->rotation & RR_Reflect_X) && !(c & 1))
		c ^= 2;
	    if ((crtc->rotation & RR_Reflect_Y) && (c & 1))
		c ^= 2;
	    subpixel_order = circle[c];
	    break;
	}
    }
    if (subpixel_order == SubPixelUnknown && has_none)
	subpixel_order = SubPixelNone;
    PictureSetSubpixelOrder (pScreen, subpixel_order);
}

246 247 248
/**
 * Sets the given video mode on the given crtc
 */
249
Bool
250
xf86CrtcSet(xf86CrtcPtr crtc, xf86CrtcSetRec *set)
251 252 253 254 255 256
{
    ScrnInfoPtr		scrn = crtc->scrn;
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
    int			i;
    Bool		ret = FALSE;
    Bool		didLock = FALSE;
257
    DisplayModePtr	adjusted_mode = NULL;
258 259 260
    DisplayModeRec	saved_mode;
    int			saved_x, saved_y;
    Rotation		saved_rotation;
261 262
    RRTransformRec	saved_transform;
    Bool		saved_transform_present;
263 264

    crtc->enabled = xf86CrtcInUse (crtc);
265

266
    /* We only hit this if someone explicitly sends a "disabled" modeset. */
267 268
    if (!crtc->enabled)
    {
269 270
	/* Check everything for stuff that should be off. */
	xf86DisableUnusedFunctions(scrn);
271 272 273
	return TRUE;
    }

274 275 276
    /* See if nothing has changed */
    if (!set->flags)
	return TRUE;
277 278 279 280 281

    saved_mode = crtc->mode;
    saved_x = crtc->x;
    saved_y = crtc->y;
    saved_rotation = crtc->rotation;
282 283 284 285
    if (crtc->transformPresent) {
	RRTransformInit (&saved_transform);
	RRTransformCopy (&saved_transform, &crtc->transform);
    }
286 287
    saved_transform_present = crtc->transformPresent;

288 289 290
    /* Update crtc values up front so the driver can rely on them for mode
     * setting.
     */
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
    if (set->flags & XF86CrtcSetMode)
	crtc->mode = *set->mode;
    if (set->flags & XF86CrtcSetOrigin) {
	crtc->x = set->x;
	crtc->y = set->y;
    }
    if (set->flags & XF86CrtcSetRotation)
	crtc->rotation = set->rotation;

    if (set->flags & XF86CrtcSetTransform) {
	if (set->transform) {
	    RRTransformCopy (&crtc->transform, set->transform);
	    crtc->transformPresent = TRUE;
	} else
	    crtc->transformPresent = FALSE;
    }

    if (crtc->funcs->set) {
	ret = crtc->funcs->set(crtc, set->flags);
	goto done;
    }

    if (set->flags == XF86CrtcSetOrigin && crtc->funcs->set_origin) {
	ret = xf86CrtcRotate(crtc);
	if (ret)
	    crtc->funcs->set_origin(crtc, crtc->x, crtc->y);
	goto done;
    }
319

320
    if (crtc->funcs->set_mode_major) {
321 322 323
	ret = crtc->funcs->set_mode_major(crtc, &crtc->mode,
					  crtc->rotation,
					  crtc->x, crtc->y);
324 325 326
	goto done;
    }

327 328
    adjusted_mode = xf86DuplicateMode(&crtc->mode);

329
    didLock = crtc->funcs->lock (crtc);
330 331 332 333 334 335 336 337 338 339
    /* Pass our mode to the outputs and the CRTC to give them a chance to
     * adjust it according to limitations or output properties, and also
     * a chance to reject the mode entirely.
     */
    for (i = 0; i < xf86_config->num_output; i++) {
	xf86OutputPtr output = xf86_config->output[i];

	if (output->crtc != crtc)
	    continue;

340
	if (!output->funcs->mode_fixup(output, &crtc->mode, adjusted_mode)) {
341 342 343 344
	    goto done;
	}
    }

345
    if (!crtc->funcs->mode_fixup(crtc, &crtc->mode, adjusted_mode)) {
346 347 348
	goto done;
    }

349
    if (!xf86CrtcRotate (crtc))
350 351
	goto done;

Dave Airlie's avatar
Dave Airlie committed
352
    /* Prepare the outputs and CRTCs before setting the mode. */
353 354 355 356 357 358 359
    for (i = 0; i < xf86_config->num_output; i++) {
	xf86OutputPtr output = xf86_config->output[i];

	if (output->crtc != crtc)
	    continue;

	/* Disable the output as the first thing we do. */
Dave Airlie's avatar
Dave Airlie committed
360
	output->funcs->prepare(output);
361 362
    }

Dave Airlie's avatar
Dave Airlie committed
363
    crtc->funcs->prepare(crtc);
364 365 366 367

    /* Set up the DPLL and any output state that needs to adjust or depend
     * on the DPLL.
     */
368
    crtc->funcs->mode_set(crtc, &crtc->mode, adjusted_mode, crtc->x, crtc->y);
369 370 371 372
    for (i = 0; i < xf86_config->num_output; i++) 
    {
	xf86OutputPtr output = xf86_config->output[i];
	if (output->crtc == crtc)
373
	    output->funcs->mode_set(output, &crtc->mode, adjusted_mode);
374 375
    }

376
    /* Only upload when needed, to avoid unneeded delays. */
377
    if (!crtc->active && crtc->funcs->gamma_set)
378 379 380
	crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
                                            crtc->gamma_blue, crtc->gamma_size);

381
    /* Now, enable the clocks, plane, pipe, and outputs that we set up. */
Dave Airlie's avatar
Dave Airlie committed
382
    crtc->funcs->commit(crtc);
383 384 385 386
    for (i = 0; i < xf86_config->num_output; i++) 
    {
	xf86OutputPtr output = xf86_config->output[i];
	if (output->crtc == crtc)
Dave Airlie's avatar
Dave Airlie committed
387
	    output->funcs->commit(output);
388 389 390
    }

    ret = TRUE;
391

392
done:
393 394 395 396
    if (ret) {
	crtc->active = TRUE;
	if (scrn->pScreen)
	    xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
397 398
	if (scrn->ModeSet)
	    scrn->ModeSet(scrn);
399
    } else {
400 401 402 403
	crtc->x = saved_x;
	crtc->y = saved_y;
	crtc->rotation = saved_rotation;
	crtc->mode = saved_mode;
404 405
	if (saved_transform_present)
	    RRTransformCopy (&crtc->transform, &saved_transform);
406
	crtc->transformPresent = saved_transform_present;
407 408
    }

409 410 411 412
    if (adjusted_mode) {
	free(adjusted_mode->name);
	free(adjusted_mode);
    }
413

414 415 416 417 418 419
    if (didLock)
	crtc->funcs->unlock (crtc);

    return ret;
}

Matthias Hopf's avatar
Matthias Hopf committed
420 421 422
/**
 * Pans the screen, does not change the mode
 */
423
void
424
xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y)
Matthias Hopf's avatar
Matthias Hopf committed
425
{
426 427 428 429 430 431 432
    xf86CrtcSetRec	set;

    if (x != crtc->x || y != crtc->y) {
	set.x = x;
	set.y = y;
	set.flags = XF86CrtcSetOrigin;
	(void) xf86CrtcSet(crtc, &set);
433
    }
Matthias Hopf's avatar
Matthias Hopf committed
434 435
}

436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
/*
 * Output functions
 */

extern XF86ConfigPtr xf86configptr;

typedef enum {
    OPTION_PREFERRED_MODE,
    OPTION_POSITION,
    OPTION_BELOW,
    OPTION_RIGHT_OF,
    OPTION_ABOVE,
    OPTION_LEFT_OF,
    OPTION_ENABLE,
    OPTION_DISABLE,
    OPTION_MIN_CLOCK,
    OPTION_MAX_CLOCK,
    OPTION_IGNORE,
454
    OPTION_ROTATE,
455
    OPTION_PANNING,
456
    OPTION_PRIMARY,
457
    OPTION_DEFAULT_MODES,
458 459 460 461 462 463 464 465 466 467 468 469 470 471
} OutputOpts;

static OptionInfoRec xf86OutputOptions[] = {
    {OPTION_PREFERRED_MODE, "PreferredMode",	OPTV_STRING,  {0}, FALSE },
    {OPTION_POSITION,	    "Position",		OPTV_STRING,  {0}, FALSE },
    {OPTION_BELOW,	    "Below",		OPTV_STRING,  {0}, FALSE },
    {OPTION_RIGHT_OF,	    "RightOf",		OPTV_STRING,  {0}, FALSE },
    {OPTION_ABOVE,	    "Above",		OPTV_STRING,  {0}, FALSE },
    {OPTION_LEFT_OF,	    "LeftOf",		OPTV_STRING,  {0}, FALSE },
    {OPTION_ENABLE,	    "Enable",		OPTV_BOOLEAN, {0}, FALSE },
    {OPTION_DISABLE,	    "Disable",		OPTV_BOOLEAN, {0}, FALSE },
    {OPTION_MIN_CLOCK,	    "MinClock",		OPTV_FREQ,    {0}, FALSE },
    {OPTION_MAX_CLOCK,	    "MaxClock",		OPTV_FREQ,    {0}, FALSE },
    {OPTION_IGNORE,	    "Ignore",		OPTV_BOOLEAN, {0}, FALSE },
472
    {OPTION_ROTATE,	    "Rotate",		OPTV_STRING,  {0}, FALSE },
473
    {OPTION_PANNING,	    "Panning",		OPTV_STRING,  {0}, FALSE },
474
    {OPTION_PRIMARY,	    "Primary",		OPTV_BOOLEAN, {0}, FALSE },
475
    {OPTION_DEFAULT_MODES,  "DefaultModes",	OPTV_BOOLEAN, {0}, FALSE },
476 477 478
    {-1,		    NULL,		OPTV_NONE,    {0}, FALSE },
};

479 480 481 482 483
enum {
    OPTION_MODEDEBUG,
};

static OptionInfoRec xf86DeviceOptions[] = {
484
    {OPTION_MODEDEBUG,	    "ModeDebug",	OPTV_BOOLEAN,  {0}, FALSE },
485 486 487
    {-1,		    NULL,		OPTV_NONE,    {0}, FALSE },
};

488 489 490 491 492 493 494 495 496
static void
xf86OutputSetMonitor (xf86OutputPtr output)
{
    char    *option_name;
    char    *monitor;

    if (!output->name)
	return;

497
    free(output->options);
498 499 500

    output->options = xnfalloc (sizeof (xf86OutputOptions));
    memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions));
501 502

    XNFasprintf(&option_name, "monitor-%s", output->name);
503 504 505 506 507
    monitor = xf86findOptionValue (output->scrn->options, option_name);
    if (!monitor)
	monitor = output->name;
    else
	xf86MarkOptionUsedByName (output->scrn->options, option_name);
508
    free(option_name);
509 510
    output->conf_monitor = xf86findMonitor (monitor,
					    xf86configptr->conf_monitor_lst);
511 512 513 514 515 516
    /*
     * Find the monitor section of the screen and use that
     */
    if (!output->conf_monitor && output->use_screen_monitor)
	output->conf_monitor = xf86findMonitor (output->scrn->monitor->id,
						xf86configptr->conf_monitor_lst);
517
    if (output->conf_monitor)
518 519 520 521
    {
	xf86DrvMsg (output->scrn->scrnIndex, X_INFO,
		    "Output %s using monitor section %s\n",
		    output->name, output->conf_monitor->mon_identifier);
522 523 524
	xf86ProcessOptions (output->scrn->scrnIndex,
			    output->conf_monitor->mon_option_lst,
			    output->options);
525 526 527 528 529
    }
    else
	xf86DrvMsg (output->scrn->scrnIndex, X_INFO,
		    "Output %s has no monitor section\n",
		    output->name);
530 531 532
}

static Bool
533
xf86OutputEnabled (xf86OutputPtr output, Bool strict)
534
{
535 536 537 538 539 540 541 542 543 544 545
    Bool    enable, disable;

    /* check to see if this output was enabled in the config file */
    if (xf86GetOptValBool (output->options, OPTION_ENABLE, &enable) && enable)
    {
	xf86DrvMsg (output->scrn->scrnIndex, X_INFO,
		    "Output %s enabled by config file\n", output->name);
	return TRUE;
    }
    /* or if this output was disabled in the config file */
    if (xf86GetOptValBool (output->options, OPTION_DISABLE, &disable) && disable)
546
    {
547 548
	xf86DrvMsg (output->scrn->scrnIndex, X_INFO,
		    "Output %s disabled by config file\n", output->name);
549 550
	return FALSE;
    }
551 552 553 554 555 556 557 558 559 560

    /* 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;
    }

561 562 563
    xf86DrvMsg (output->scrn->scrnIndex, X_INFO,
    	    "Output %s %sconnected\n", output->name, enable ? "" : "dis");
    return enable;
564 565 566 567 568 569 570 571
}

static Bool
xf86OutputIgnored (xf86OutputPtr    output)
{
    return xf86ReturnOptValBool (output->options, OPTION_IGNORE, FALSE);
}

572 573 574 575 576 577 578 579 580 581 582 583 584 585
static char *direction[4] = {
    "normal", 
    "left", 
    "inverted", 
    "right"
};

static Rotation
xf86OutputInitialRotation (xf86OutputPtr output)
{
    char    *rotate_name = xf86GetOptValString (output->options, 
						OPTION_ROTATE);
    int	    i;

586 587 588
    if (!rotate_name) {
	if (output->initial_rotation)
	    return output->initial_rotation;
589
	return RR_Rotate_0;
590
    }
591 592 593
    
    for (i = 0; i < 4; i++)
	if (xf86nameCompare (direction[i], rotate_name) == 0)
594
	    return 1 << i;
595 596 597
    return RR_Rotate_0;
}

598
xf86OutputPtr
599
xf86OutputCreate (ScrnInfoPtr		    scrn,
600
		  const xf86OutputFuncsRec  *funcs,
601 602 603 604 605
		  const char		    *name)
{
    xf86OutputPtr	output, *outputs;
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
    int			len;
606
    Bool		primary;
607 608 609 610 611 612

    if (name)
	len = strlen (name) + 1;
    else
	len = 0;

613
    output = calloc(sizeof (xf86OutputRec) + len, 1);
614 615 616 617 618 619 620 621 622 623
    if (!output)
	return NULL;
    output->scrn = scrn;
    output->funcs = funcs;
    if (name)
    {
	output->name = (char *) (output + 1);
	strcpy (output->name, name);
    }
    output->subpixel_order = SubPixelUnknown;
624 625 626 627
    /*
     * Use the old per-screen monitor section for the first output
     */
    output->use_screen_monitor = (xf86_config->num_output == 0);
628 629 630 631 632 633 634 635
#ifdef RANDR_12_INTERFACE
    output->randr_output = NULL;
#endif
    if (name)
    {
	xf86OutputSetMonitor (output);
	if (xf86OutputIgnored (output))
	{
636
	    free(output);
637 638 639 640 641 642
	    return FALSE;
	}
    }
    
    
    if (xf86_config->output)
643
	outputs = realloc(xf86_config->output,
644 645
			  (xf86_config->num_output + 1) * sizeof (xf86OutputPtr));
    else
646
	outputs = malloc((xf86_config->num_output + 1) * sizeof (xf86OutputPtr));
647 648
    if (!outputs)
    {
649
	free(output);
650 651
	return NULL;
    }
652

653
    xf86_config->output = outputs;
654 655 656 657 658 659 660 661 662 663 664 665 666 667

    if (xf86GetOptValBool (output->options, OPTION_PRIMARY, &primary) && primary)
    {
	memmove(xf86_config->output + 1, xf86_config->output,
		xf86_config->num_output * sizeof (xf86OutputPtr));
	xf86_config->output[0] = output;
    }
    else
    {
	xf86_config->output[xf86_config->num_output] = output;
    }

    xf86_config->num_output++;

668 669 670
    return output;
}

671
Bool
672 673
xf86OutputRename (xf86OutputPtr output, const char *name)
{
674
    char    *newname = strdup(name);
675 676 677 678 679
    
    if (!newname)
	return FALSE;	/* so sorry... */
    
    if (output->name && output->name != (char *) (output + 1))
680
	free(output->name);
681 682 683 684 685 686 687
    output->name = newname;
    xf86OutputSetMonitor (output);
    if (xf86OutputIgnored (output))
	return FALSE;
    return TRUE;
}

688
void
689 690 691 692 693 694 695 696 697
xf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor)
{
    if (use_screen_monitor != output->use_screen_monitor)
    {
	output->use_screen_monitor = use_screen_monitor;
	xf86OutputSetMonitor (output);
    }
}

698
void
699 700 701 702 703 704 705 706 707 708 709 710 711 712
xf86OutputDestroy (xf86OutputPtr output)
{
    ScrnInfoPtr		scrn = output->scrn;
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
    int			o;
    
    (*output->funcs->destroy) (output);
    while (output->probed_modes)
	xf86DeleteMode (&output->probed_modes, output->probed_modes);
    for (o = 0; o < xf86_config->num_output; o++)
	if (xf86_config->output[o] == output)
	{
	    memmove (&xf86_config->output[o],
		     &xf86_config->output[o+1],
713
		     ((xf86_config->num_output - (o + 1)) * sizeof(void*)));
714 715 716 717
	    xf86_config->num_output--;
	    break;
	}
    if (output->name && output->name != (char *) (output + 1))
718 719
	free(output->name);
    free(output);
720 721
}

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
/*
 * Called during CreateScreenResources to hook up RandR
 */
static Bool
xf86CrtcCreateScreenResources (ScreenPtr screen)
{
    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);

    screen->CreateScreenResources = config->CreateScreenResources;
    
    if (!(*screen->CreateScreenResources)(screen))
	return FALSE;

    if (!xf86RandR12CreateScreenResources (screen))
	return FALSE;

    return TRUE;
}

742 743 744 745 746 747 748 749
/*
 * Clean up config on server reset
 */
static Bool
xf86CrtcCloseScreen (int index, ScreenPtr screen)
{
    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
750
    int			o, c;
751 752 753 754 755
    
    screen->CloseScreen = config->CloseScreen;

    xf86RotateCloseScreen (screen);

756 757 758 759 760 761 762 763 764 765 766 767
    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr	output = config->output[o];

	output->randr_output = NULL;
    }
    for (c = 0; c < config->num_crtc; c++)
    {
	xf86CrtcPtr	crtc = config->crtc[c];

	crtc->randr_crtc = NULL;
    }
768 769
    xf86RandR12CloseScreen (screen);

770 771 772
    return screen->CloseScreen (index, screen);
}

773 774 775
/*
 * Called at ScreenInit time to set up
 */
776 777 778 779 780
#ifdef RANDR_13_INTERFACE
int
#else
Bool
#endif
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
xf86CrtcScreenInit (ScreenPtr screen)
{
    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
    int			c;

    /* Rotation */
    xf86DrvMsg(scrn->scrnIndex, X_INFO, "RandR 1.2 enabled, ignore the following RandR disabled message.\n");
    xf86DisableRandR(); /* Disable old RandR extension support */
    xf86RandR12Init (screen);

    /* support all rotations if every crtc has the shadow alloc funcs */
    for (c = 0; c < config->num_crtc; c++)
    {
	xf86CrtcPtr crtc = config->crtc[c];
	if (!crtc->funcs->shadow_allocate || !crtc->funcs->shadow_create)
	    break;
    }
    if (c == config->num_crtc)
800
    {
801
	xf86RandR12SetRotations (screen, RR_Rotate_0 | RR_Rotate_90 |
Keith Packard's avatar
Keith Packard committed
802 803
				 RR_Rotate_180 | RR_Rotate_270 |
				 RR_Reflect_X | RR_Reflect_Y);
804
	xf86RandR12SetTransformSupport (screen, TRUE);
805
    }
806
    else
807
    {
808
	xf86RandR12SetRotations (screen, RR_Rotate_0);
809
	xf86RandR12SetTransformSupport (screen, FALSE);
810
    }
811 812 813 814
    
    /* Wrap CreateScreenResources so we can initialize the RandR code */
    config->CreateScreenResources = screen->CreateScreenResources;
    screen->CreateScreenResources = xf86CrtcCreateScreenResources;
815 816 817 818

    config->CloseScreen = screen->CloseScreen;
    screen->CloseScreen = xf86CrtcCloseScreen;
    
819
#ifdef XFreeXDGA
Keith Packard's avatar
Keith Packard committed
820
    _xf86_di_dga_init_internal(screen);
821
#endif
822 823 824
#ifdef RANDR_13_INTERFACE
    return RANDR_INTERFACE_VERSION;
#else
825
    return TRUE;
826
#endif
827 828
}

829 830 831 832 833 834 835 836 837 838 839
static DisplayModePtr
xf86DefaultMode (xf86OutputPtr output, int width, int height)
{
    DisplayModePtr  target_mode = NULL;
    DisplayModePtr  mode;
    int		    target_diff = 0;
    int		    target_preferred = 0;
    int		    mm_height;
    
    mm_height = output->mm_height;
    if (!mm_height)
840
	mm_height = (768 * 25.4) / DEFAULT_DPI;
841
    /*
842
     * Pick a mode closest to DEFAULT_DPI
843 844 845 846
     */
    for (mode = output->probed_modes; mode; mode = mode->next)
    {
	int	    dpi;
847 848
	int	    preferred = (((mode->type & M_T_PREFERRED) != 0) +
				 ((mode->type & M_T_USERPREF) != 0));
849 850
	int	    diff;

851 852 853 854 855 856
	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
	    xf86ModeHeight (mode, output->initial_rotation) > height)
	    continue;
	
	/* yes, use VDisplay here, not xf86ModeHeight */
	dpi = (mode->VDisplay * 254) / (mm_height * 10);
857
	diff = dpi - DEFAULT_DPI;
858 859 860 861 862 863 864 865 866 867 868 869 870
	diff = diff < 0 ? -diff : diff;
	if (target_mode == NULL || (preferred > target_preferred) ||
	    (preferred == target_preferred && diff < target_diff))
	{
	    target_mode = mode;
	    target_diff = diff;
	    target_preferred = preferred;
	}
    }
    return target_mode;
}

static DisplayModePtr
871 872
xf86ClosestMode (xf86OutputPtr output, 
		 DisplayModePtr match, Rotation match_rotation,
873 874 875 876 877 878 879 880 881 882 883 884 885 886
		 int width, int height)
{
    DisplayModePtr  target_mode = NULL;
    DisplayModePtr  mode;
    int		    target_diff = 0;
    
    /*
     * Pick a mode closest to the specified mode
     */
    for (mode = output->probed_modes; mode; mode = mode->next)
    {
	int	    dx, dy;
	int	    diff;

887 888 889
	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
	    xf86ModeHeight (mode, output->initial_rotation) > height)
	    continue;
890 891
	
	/* exact matches are preferred */
892 893
	if (output->initial_rotation == match_rotation &&
	    xf86ModesEqual (mode, match))
894 895
	    return mode;
	
896 897
	dx = xf86ModeWidth (match, match_rotation) - xf86ModeWidth (mode, output->initial_rotation);
	dy = xf86ModeHeight (match, match_rotation) - xf86ModeHeight (mode, output->initial_rotation);
898 899 900 901 902 903 904 905 906 907
	diff = dx * dx + dy * dy;
	if (target_mode == NULL || diff < target_diff)
	{
	    target_mode = mode;
	    target_diff = diff;
	}
    }
    return target_mode;
}

908
static DisplayModePtr
909 910 911 912 913 914
xf86OutputHasPreferredMode (xf86OutputPtr output, int width, int height)
{
    DisplayModePtr  mode;

    for (mode = output->probed_modes; mode; mode = mode->next)
    {
915 916 917 918
	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
	    xf86ModeHeight (mode, output->initial_rotation) > height)
	    continue;

919
	if (mode->type & M_T_PREFERRED)
920
	    return mode;
921
    }
922 923 924 925 926 927 928 929 930 931 932 933 934
    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;
935 936 937 938 939 940 941 942 943 944 945
}

static int
xf86PickCrtcs (ScrnInfoPtr	scrn,
	       xf86CrtcPtr	*best_crtcs,
	       DisplayModePtr	*modes,
	       int		n,
	       int		width,
	       int		height)
{
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
946
    int		    c, o;
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
    xf86OutputPtr   output;
    xf86CrtcPtr	    crtc;
    xf86CrtcPtr	    *crtcs;
    xf86CrtcPtr	    best_crtc;
    int		    best_score;
    int		    score;
    int		    my_score;
    
    if (n == config->num_output)
	return 0;
    output = config->output[n];
    
    /*
     * Compute score with this output disabled
     */
    best_crtcs[n] = NULL;
    best_crtc = NULL;
    best_score = xf86PickCrtcs (scrn, best_crtcs, modes, n+1, width, height);
    if (modes[n] == NULL)
	return best_score;
    
968
    crtcs = malloc(config->num_output * sizeof (xf86CrtcPtr));
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
    if (!crtcs)
	return best_score;

    my_score = 1;
    /* Score outputs that are known to be connected higher */
    if (output->status == XF86OutputStatusConnected)
	my_score++;
    /* Score outputs with preferred modes higher */
    if (xf86OutputHasPreferredMode (output, width, height))
	my_score++;
    /*
     * Select a crtc for this output and
     * then attempt to configure the remaining
     * outputs
     */
    for (c = 0; c < config->num_crtc; c++)
    {
	if ((output->possible_crtcs & (1 << c)) == 0)
	    continue;
	
	crtc = config->crtc[c];
	/*
	 * Check to see if some other output is
	 * using this crtc
	 */
	for (o = 0; o < n; o++)
	    if (best_crtcs[o] == crtc)
		break;
	if (o < n)
	{
	    /*
	     * If the two outputs desire the same mode,
	     * see if they can be cloned
	     */
	    if (xf86ModesEqual (modes[o], modes[n]) &&
Cooper Yuan's avatar
Cooper Yuan committed
1004
		config->output[o]->initial_rotation == config->output[n]->initial_rotation &&
1005 1006 1007
		config->output[o]->initial_x == config->output[n]->initial_x &&
		config->output[o]->initial_y == config->output[n]->initial_y)
	    {
1008
		if ((output->possible_clones & (1 << o)) == 0)
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
		    continue;		/* nope, try next CRTC */
	    }
	    else
		continue;		/* different modes, can't clone */
	}
	crtcs[n] = crtc;
	memcpy (crtcs, best_crtcs, n * sizeof (xf86CrtcPtr));
	score = my_score + xf86PickCrtcs (scrn, crtcs, modes, n+1, width, height);
	if (score > best_score)
	{
	    best_crtc = crtc;
	    best_score = score;
	    memcpy (best_crtcs, crtcs, config->num_output * sizeof (xf86CrtcPtr));
	}
    }
1024
    free(crtcs);
1025 1026 1027 1028 1029 1030
    return best_score;
}


/*
 * Compute the virtual size necessary to place all of the available
1031 1032 1033 1034 1035
 * crtcs in the specified configuration.
 *
 * canGrow indicates that the driver can make the screen larger than its initial
 * configuration.  If FALSE, this function will enlarge the screen to include
 * the largest available mode.
1036 1037 1038
 */

static void
1039 1040
xf86DefaultScreenLimits (ScrnInfoPtr scrn, int *widthp, int *heightp,
			 Bool canGrow)
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
{
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
    int	    width = 0, height = 0;
    int	    o;
    int	    c;
    int	    s;

    for (c = 0; c < config->num_crtc; c++)
    {
	int	    crtc_width = 0, crtc_height = 0;
	xf86CrtcPtr crtc = config->crtc[c];

	if (crtc->enabled)
	{
1055 1056
	    crtc_width = crtc->desiredX + xf86ModeWidth (&crtc->desiredMode, crtc->desiredRotation);
	    crtc_height = crtc->desiredY + xf86ModeHeight (&crtc->desiredMode, crtc->desiredRotation);
1057
	}
1058 1059 1060 1061
	if (!canGrow) {
	    for (o = 0; o < config->num_output; o++)
	    {
		xf86OutputPtr   output = config->output[o];
1062

1063 1064
		for (s = 0; s < config->num_crtc; s++)
		    if (output->possible_crtcs & (1 << s))
1065
		    {
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
			DisplayModePtr  mode;
			for (mode = output->probed_modes; mode; mode = mode->next)
			{
			    if (mode->HDisplay > crtc_width)
				crtc_width = mode->HDisplay;
			    if (mode->VDisplay > crtc_width)
				crtc_width = mode->VDisplay;
			    if (mode->VDisplay > crtc_height)
				crtc_height = mode->VDisplay;
			    if (mode->HDisplay > crtc_height)
				crtc_height = mode->HDisplay;
			}
1078
		    }
1079
	    }
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
	}
	if (crtc_width > width)
	    width = crtc_width;
	if (crtc_height > height)
	    height = crtc_height;
    }
    if (config->maxWidth && width > config->maxWidth) width = config->maxWidth;
    if (config->maxHeight && height > config->maxHeight) height = config->maxHeight;
    if (config->minWidth && width < config->minWidth) width = config->minWidth;
    if (config->minHeight && height < config->minHeight) height = config->minHeight;
    *widthp = width;
    *heightp = height;
}

#define POSITION_UNSET	-100000

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
/*
 * check if the user configured any outputs at all 
 * with either a position or a relative setting or a mode.
 */
static Bool
xf86UserConfiguredOutputs(ScrnInfoPtr scrn, DisplayModePtr *modes)
{
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
    int o;
    Bool user_conf = FALSE;

    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr output = config->output[o];
	char	    *position;
	char	    *relative_name;
	OutputOpts	    relation;
	int r;
	static const OutputOpts	relations[] = {
	    OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF
	};

	position = xf86GetOptValString (output->options,
					OPTION_POSITION);
	if (position)
	    user_conf = TRUE;

	relation = 0;
	relative_name = NULL;
	for (r = 0; r < 4; r++)
	{
	    relation = relations[r];
	    relative_name = xf86GetOptValString (output->options,
						     relation);
	    if (relative_name)
		break;
	}
	if (relative_name)
	    user_conf = TRUE;

	modes[o] = xf86OutputHasUserPreferredMode(output);
	if (modes[o])
	    user_conf = TRUE;
    }

    return user_conf;
}

1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
static Bool
xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes)
{
    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
    int			o;
    int			min_x, min_y;
    
    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr	output = config->output[o];

	output->initial_x = output->initial_y = POSITION_UNSET;
    }
    
    /*
     * Loop until all outputs are set
     */
    for (;;)
    {
	Bool	any_set = FALSE;
	Bool	keep_going = FALSE;

	for (o = 0; o < config->num_output; o++)	
	{
	    static const OutputOpts	relations[] = {
		OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF
	    };
	    xf86OutputPtr   output = config->output[o];
	    xf86OutputPtr   relative;
	    char	    *relative_name;
	    char	    *position;
	    OutputOpts	    relation;
	    int		    r;

	    if (output->initial_x != POSITION_UNSET)
		continue;
	    position = xf86GetOptValString (output->options,
					    OPTION_POSITION);
	    /*
	     * Absolute position wins
	     */
	    if (position)
	    {
		int		    x, y;
		if (sscanf (position, "%d %d", &x, &y) == 2)
		{
		    output->initial_x = x;
		    output->initial_y = y;
		}
		else
		{
		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
				"Output %s position not of form \"x y\"\n",
				output->name);
		    output->initial_x = output->initial_y = 0;
		}
		any_set = TRUE;
		continue;
	    }
	    /*
	     * Next comes relative positions
	     */
	    relation = 0;
	    relative_name = NULL;
	    for (r = 0; r < 4; r++)
	    {
		relation = relations[r];
		relative_name = xf86GetOptValString (output->options,
						     relation);
		if (relative_name)
		    break;
	    }
	    if (relative_name)
	    {
		int or;
		relative = NULL;
		for (or = 0; or < config->num_output; or++)
		{
		    xf86OutputPtr	out_rel = config->output[or];
		    XF86ConfMonitorPtr	rel_mon = out_rel->conf_monitor;

		    if (rel_mon)
1226 1227 1228 1229 1230 1231 1232 1233 1234
		    {
			if (xf86nameCompare (rel_mon->mon_identifier,
					      relative_name) == 0)
			{
			    relative = config->output[or];
			    break;
			}
		    }
		    if (strcmp (out_rel->name, relative_name) == 0)
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
		    {
			relative = config->output[or];
			break;
		    }
		}
		if (!relative)
		{
		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
				"Cannot position output %s relative to unknown output %s\n",
				output->name, relative_name);
		    output->initial_x = 0;
		    output->initial_y = 0;
		    any_set = TRUE;
		    continue;
		}
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
		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;
		}
1260 1261 1262 1263 1264 1265 1266 1267 1268
		if (relative->initial_x == POSITION_UNSET)
		{
		    keep_going = TRUE;
		    continue;
		}
		output->initial_x = relative->initial_x;
		output->initial_y = relative->initial_y;
		switch (relation) {
		case OPTION_BELOW:
1269
		    output->initial_y += xf86ModeHeight (modes[or], relative->initial_rotation);
1270 1271
		    break;
		case OPTION_RIGHT_OF:
1272
		    output->initial_x += xf86ModeWidth (modes[or], relative->initial_rotation);
1273 1274
		    break;
		case OPTION_ABOVE:
1275 1276
		    if (modes[o])
			output->initial_y -= xf86ModeHeight (modes[o], output->initial_rotation);
1277 1278
		    break;
		case OPTION_LEFT_OF:
1279 1280
		    if (modes[o])
			output->initial_x -= xf86ModeWidth (modes[o], output->initial_rotation);
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
		    break;
		default:
		    break;
		}
		any_set = TRUE;
		continue;
	    }
	    
	    /* Nothing set, just stick them at 0,0 */
	    output->initial_x = 0;
	    output->initial_y = 0;
	    any_set = TRUE;
	}
	if (!keep_going)
	    break;
	if (!any_set) 
	{
	    for (o = 0; o < config->num_output; o++)
	    {
		xf86OutputPtr   output = config->output[o];
		if (output->initial_x == POSITION_UNSET)
		{
		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
				"Output position loop. Moving %s to 0,0\n",
				output->name);
		    output->initial_x = output->initial_y = 0;
		    break;
		}
	    }
	}
    }

    /*
     * normalize positions
     */
    min_x = 1000000;
    min_y = 1000000;
    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr	output = config->output[o];

	if (output->initial_x < min_x)
	    min_x = output->initial_x;
	if (output->initial_y < min_y)
	    min_y = output->initial_y;
    }
    
    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr	output = config->output[o];

	output->initial_x -= min_x;
	output->initial_y -= min_y;
    }
    return TRUE;
}

1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355