xf86Crtc.h revision 05b261ec
1/* 2 * Copyright © 2006 Keith Packard 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that copyright 7 * notice and this permission notice appear in supporting documentation, and 8 * that the name of the copyright holders not be used in advertising or 9 * publicity pertaining to distribution of the software without specific, 10 * written prior permission. The copyright holders make no representations 11 * about the suitability of this software for any purpose. It is provided "as 12 * is" without express or implied warranty. 13 * 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20 * OF THIS SOFTWARE. 21 */ 22#ifndef _XF86CRTC_H_ 23#define _XF86CRTC_H_ 24 25#include <edid.h> 26#include "randrstr.h" 27#if XF86_MODES_RENAME 28#include "xf86Rename.h" 29#endif 30#include "xf86Modes.h" 31#include "xf86Cursor.h" 32#include "damage.h" 33#include "picturestr.h" 34 35/* Compat definitions for older X Servers. */ 36#ifndef M_T_PREFERRED 37#define M_T_PREFERRED 0x08 38#endif 39#ifndef M_T_DRIVER 40#define M_T_DRIVER 0x40 41#endif 42#ifndef HARDWARE_CURSOR_ARGB 43#define HARDWARE_CURSOR_ARGB 0x00004000 44#endif 45 46typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr; 47typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr; 48 49/* define a standard for connector types */ 50typedef enum _xf86ConnectorType { 51 XF86ConnectorNone, 52 XF86ConnectorVGA, 53 XF86ConnectorDVI_I, 54 XF86ConnectorDVI_D, 55 XF86ConnectorDVI_A, 56 XF86ConnectorComposite, 57 XF86ConnectorSvideo, 58 XF86ConnectorComponent, 59 XF86ConnectorLFP, 60 XF86ConnectorProprietary, 61} xf86ConnectorType; 62 63typedef enum _xf86OutputStatus { 64 XF86OutputStatusConnected, 65 XF86OutputStatusDisconnected, 66 XF86OutputStatusUnknown, 67} xf86OutputStatus; 68 69typedef struct _xf86CrtcFuncs { 70 /** 71 * Turns the crtc on/off, or sets intermediate power levels if available. 72 * 73 * Unsupported intermediate modes drop to the lower power setting. If the 74 * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to 75 * be safe to call mode_set. 76 */ 77 void 78 (*dpms)(xf86CrtcPtr crtc, 79 int mode); 80 81 /** 82 * Saves the crtc's state for restoration on VT switch. 83 */ 84 void 85 (*save)(xf86CrtcPtr crtc); 86 87 /** 88 * Restore's the crtc's state at VT switch. 89 */ 90 void 91 (*restore)(xf86CrtcPtr crtc); 92 93 /** 94 * Lock CRTC prior to mode setting, mostly for DRI. 95 * Returns whether unlock is needed 96 */ 97 Bool 98 (*lock) (xf86CrtcPtr crtc); 99 100 /** 101 * Unlock CRTC after mode setting, mostly for DRI 102 */ 103 void 104 (*unlock) (xf86CrtcPtr crtc); 105 106 /** 107 * Callback to adjust the mode to be set in the CRTC. 108 * 109 * This allows a CRTC to adjust the clock or even the entire set of 110 * timings, which is used for panels with fixed timings or for 111 * buses with clock limitations. 112 */ 113 Bool 114 (*mode_fixup)(xf86CrtcPtr crtc, 115 DisplayModePtr mode, 116 DisplayModePtr adjusted_mode); 117 118 /** 119 * Prepare CRTC for an upcoming mode set. 120 */ 121 void 122 (*prepare)(xf86CrtcPtr crtc); 123 124 /** 125 * Callback for setting up a video mode after fixups have been made. 126 */ 127 void 128 (*mode_set)(xf86CrtcPtr crtc, 129 DisplayModePtr mode, 130 DisplayModePtr adjusted_mode, 131 int x, int y); 132 133 /** 134 * Commit mode changes to a CRTC 135 */ 136 void 137 (*commit)(xf86CrtcPtr crtc); 138 139 /* Set the color ramps for the CRTC to the given values. */ 140 void 141 (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue, 142 int size); 143 144 /** 145 * Allocate the shadow area, delay the pixmap creation until needed 146 */ 147 void * 148 (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height); 149 150 /** 151 * Create shadow pixmap for rotation support 152 */ 153 PixmapPtr 154 (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height); 155 156 /** 157 * Destroy shadow pixmap 158 */ 159 void 160 (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data); 161 162 /** 163 * Set cursor colors 164 */ 165 void 166 (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg); 167 168 /** 169 * Set cursor position 170 */ 171 void 172 (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y); 173 174 /** 175 * Show cursor 176 */ 177 void 178 (*show_cursor) (xf86CrtcPtr crtc); 179 180 /** 181 * Hide cursor 182 */ 183 void 184 (*hide_cursor) (xf86CrtcPtr crtc); 185 186 /** 187 * Load monochrome image 188 */ 189 void 190 (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image); 191 192 /** 193 * Load ARGB image 194 */ 195 void 196 (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image); 197 198 /** 199 * Clean up driver-specific bits of the crtc 200 */ 201 void 202 (*destroy) (xf86CrtcPtr crtc); 203} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr; 204 205struct _xf86Crtc { 206 /** 207 * Associated ScrnInfo 208 */ 209 ScrnInfoPtr scrn; 210 211 /** 212 * Active state of this CRTC 213 * 214 * Set when this CRTC is driving one or more outputs 215 */ 216 Bool enabled; 217 218 /** 219 * Active mode 220 * 221 * This reflects the mode as set in the CRTC currently 222 * It will be cleared when the VT is not active or 223 * during server startup 224 */ 225 DisplayModeRec mode; 226 Rotation rotation; 227 PixmapPtr rotatedPixmap; 228 void *rotatedData; 229 230 /** 231 * Position on screen 232 * 233 * Locates this CRTC within the frame buffer 234 */ 235 int x, y; 236 237 /** 238 * Desired mode 239 * 240 * This is set to the requested mode, independent of 241 * whether the VT is active. In particular, it receives 242 * the startup configured mode and saves the active mode 243 * on VT switch. 244 */ 245 DisplayModeRec desiredMode; 246 Rotation desiredRotation; 247 int desiredX, desiredY; 248 249 /** crtc-specific functions */ 250 const xf86CrtcFuncsRec *funcs; 251 252 /** 253 * Driver private 254 * 255 * Holds driver-private information 256 */ 257 void *driver_private; 258 259#ifdef RANDR_12_INTERFACE 260 /** 261 * RandR crtc 262 * 263 * When RandR 1.2 is available, this 264 * points at the associated crtc object 265 */ 266 RRCrtcPtr randr_crtc; 267#else 268 void *randr_crtc; 269#endif 270 271 /** 272 * Current cursor is ARGB 273 */ 274 Bool cursor_argb; 275 /** 276 * Track whether cursor is within CRTC range 277 */ 278 Bool cursor_in_range; 279 /** 280 * Track state of cursor associated with this CRTC 281 */ 282 Bool cursor_shown; 283 284 /** 285 * Current transformation matrix 286 */ 287 PictTransform crtc_to_framebuffer; 288 PictTransform framebuffer_to_crtc; 289 Bool transform_in_use; 290 /** 291 * Bounding box in screen space 292 */ 293 BoxRec bounds; 294}; 295 296typedef struct _xf86OutputFuncs { 297 /** 298 * Called to allow the output a chance to create properties after the 299 * RandR objects have been created. 300 */ 301 void 302 (*create_resources)(xf86OutputPtr output); 303 304 /** 305 * Turns the output on/off, or sets intermediate power levels if available. 306 * 307 * Unsupported intermediate modes drop to the lower power setting. If the 308 * mode is DPMSModeOff, the output must be disabled, as the DPLL may be 309 * disabled afterwards. 310 */ 311 void 312 (*dpms)(xf86OutputPtr output, 313 int mode); 314 315 /** 316 * Saves the output's state for restoration on VT switch. 317 */ 318 void 319 (*save)(xf86OutputPtr output); 320 321 /** 322 * Restore's the output's state at VT switch. 323 */ 324 void 325 (*restore)(xf86OutputPtr output); 326 327 /** 328 * Callback for testing a video mode for a given output. 329 * 330 * This function should only check for cases where a mode can't be supported 331 * on the output specifically, and not represent generic CRTC limitations. 332 * 333 * \return MODE_OK if the mode is valid, or another MODE_* otherwise. 334 */ 335 int 336 (*mode_valid)(xf86OutputPtr output, 337 DisplayModePtr pMode); 338 339 /** 340 * Callback to adjust the mode to be set in the CRTC. 341 * 342 * This allows an output to adjust the clock or even the entire set of 343 * timings, which is used for panels with fixed timings or for 344 * buses with clock limitations. 345 */ 346 Bool 347 (*mode_fixup)(xf86OutputPtr output, 348 DisplayModePtr mode, 349 DisplayModePtr adjusted_mode); 350 351 /** 352 * Callback for preparing mode changes on an output 353 */ 354 void 355 (*prepare)(xf86OutputPtr output); 356 357 /** 358 * Callback for committing mode changes on an output 359 */ 360 void 361 (*commit)(xf86OutputPtr output); 362 363 /** 364 * Callback for setting up a video mode after fixups have been made. 365 * 366 * This is only called while the output is disabled. The dpms callback 367 * must be all that's necessary for the output, to turn the output on 368 * after this function is called. 369 */ 370 void 371 (*mode_set)(xf86OutputPtr output, 372 DisplayModePtr mode, 373 DisplayModePtr adjusted_mode); 374 375 /** 376 * Probe for a connected output, and return detect_status. 377 */ 378 xf86OutputStatus 379 (*detect)(xf86OutputPtr output); 380 381 /** 382 * Query the device for the modes it provides. 383 * 384 * This function may also update MonInfo, mm_width, and mm_height. 385 * 386 * \return singly-linked list of modes or NULL if no modes found. 387 */ 388 DisplayModePtr 389 (*get_modes)(xf86OutputPtr output); 390 391#ifdef RANDR_12_INTERFACE 392 /** 393 * Callback when an output's property has changed. 394 */ 395 Bool 396 (*set_property)(xf86OutputPtr output, 397 Atom property, 398 RRPropertyValuePtr value); 399#endif 400 /** 401 * Clean up driver-specific bits of the output 402 */ 403 void 404 (*destroy) (xf86OutputPtr output); 405} xf86OutputFuncsRec, *xf86OutputFuncsPtr; 406 407struct _xf86Output { 408 /** 409 * Associated ScrnInfo 410 */ 411 ScrnInfoPtr scrn; 412 413 /** 414 * Currently connected crtc (if any) 415 * 416 * If this output is not in use, this field will be NULL. 417 */ 418 xf86CrtcPtr crtc; 419 420 /** 421 * Possible CRTCs for this output as a mask of crtc indices 422 */ 423 CARD32 possible_crtcs; 424 425 /** 426 * Possible outputs to share the same CRTC as a mask of output indices 427 */ 428 CARD32 possible_clones; 429 430 /** 431 * Whether this output can support interlaced modes 432 */ 433 Bool interlaceAllowed; 434 435 /** 436 * Whether this output can support double scan modes 437 */ 438 Bool doubleScanAllowed; 439 440 /** 441 * List of available modes on this output. 442 * 443 * This should be the list from get_modes(), plus perhaps additional 444 * compatible modes added later. 445 */ 446 DisplayModePtr probed_modes; 447 448 /** 449 * Options parsed from the related monitor section 450 */ 451 OptionInfoPtr options; 452 453 /** 454 * Configured monitor section 455 */ 456 XF86ConfMonitorPtr conf_monitor; 457 458 /** 459 * Desired initial position 460 */ 461 int initial_x, initial_y; 462 463 /** 464 * Desired initial rotation 465 */ 466 Rotation initial_rotation; 467 468 /** 469 * Current connection status 470 * 471 * This indicates whether a monitor is known to be connected 472 * to this output or not, or whether there is no way to tell 473 */ 474 xf86OutputStatus status; 475 476 /** EDID monitor information */ 477 xf86MonPtr MonInfo; 478 479 /** subpixel order */ 480 int subpixel_order; 481 482 /** Physical size of the currently attached output device. */ 483 int mm_width, mm_height; 484 485 /** Output name */ 486 char *name; 487 488 /** output-specific functions */ 489 const xf86OutputFuncsRec *funcs; 490 491 /** driver private information */ 492 void *driver_private; 493 494 /** Whether to use the old per-screen Monitor config section */ 495 Bool use_screen_monitor; 496 497#ifdef RANDR_12_INTERFACE 498 /** 499 * RandR 1.2 output structure. 500 * 501 * When RandR 1.2 is available, this points at the associated 502 * RandR output structure and is created when this output is created 503 */ 504 RROutputPtr randr_output; 505#else 506 void *randr_output; 507#endif 508}; 509 510typedef struct _xf86CrtcConfigFuncs { 511 /** 512 * Requests that the driver resize the screen. 513 * 514 * The driver is responsible for updating scrn->virtualX and scrn->virtualY. 515 * If the requested size cannot be set, the driver should leave those values 516 * alone and return FALSE. 517 * 518 * A naive driver that cannot reallocate the screen may simply change 519 * virtual[XY]. A more advanced driver will want to also change the 520 * devPrivate.ptr and devKind of the screen pixmap, update any offscreen 521 * pixmaps it may have moved, and change pScrn->displayWidth. 522 */ 523 Bool 524 (*resize)(ScrnInfoPtr scrn, 525 int width, 526 int height); 527} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr; 528 529typedef struct _xf86CrtcConfig { 530 int num_output; 531 xf86OutputPtr *output; 532 /** 533 * compat_output is used whenever we deal 534 * with legacy code that only understands a single 535 * output. pScrn->modes will be loaded from this output, 536 * adjust frame will whack this output, etc. 537 */ 538 int compat_output; 539 540 int num_crtc; 541 xf86CrtcPtr *crtc; 542 543 int minWidth, minHeight; 544 int maxWidth, maxHeight; 545 546 /* For crtc-based rotation */ 547 DamagePtr rotation_damage; 548 Bool rotation_damage_registered; 549 550 /* DGA */ 551 unsigned int dga_flags; 552 unsigned long dga_address; 553 DGAModePtr dga_modes; 554 int dga_nmode; 555 int dga_width, dga_height, dga_stride; 556 DisplayModePtr dga_save_mode; 557 558 const xf86CrtcConfigFuncsRec *funcs; 559 560 CreateScreenResourcesProcPtr CreateScreenResources; 561 562 CloseScreenProcPtr CloseScreen; 563 564 /* Cursor information */ 565 xf86CursorInfoPtr cursor_info; 566 CursorPtr cursor; 567 CARD8 *cursor_image; 568 Bool cursor_on; 569 CARD32 cursor_fg, cursor_bg; 570 571 /** 572 * Options parsed from the related device section 573 */ 574 OptionInfoPtr options; 575 576 Bool debug_modes; 577 578 /* wrap screen BlockHandler for rotation */ 579 ScreenBlockHandlerProcPtr BlockHandler; 580 581} xf86CrtcConfigRec, *xf86CrtcConfigPtr; 582 583extern int xf86CrtcConfigPrivateIndex; 584 585#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr)) 586 587/* 588 * Initialize xf86CrtcConfig structure 589 */ 590 591void 592xf86CrtcConfigInit (ScrnInfoPtr scrn, 593 const xf86CrtcConfigFuncsRec *funcs); 594 595void 596xf86CrtcSetSizeRange (ScrnInfoPtr scrn, 597 int minWidth, int minHeight, 598 int maxWidth, int maxHeight); 599 600/* 601 * Crtc functions 602 */ 603xf86CrtcPtr 604xf86CrtcCreate (ScrnInfoPtr scrn, 605 const xf86CrtcFuncsRec *funcs); 606 607void 608xf86CrtcDestroy (xf86CrtcPtr crtc); 609 610 611/** 612 * Sets the given video mode on the given crtc 613 */ 614Bool 615xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, 616 int x, int y); 617 618/* 619 * Assign crtc rotation during mode set 620 */ 621Bool 622xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation); 623 624/* 625 * Clean up rotation during CloseScreen 626 */ 627void 628xf86RotateCloseScreen (ScreenPtr pScreen); 629 630/** 631 * Return whether any output is assigned to the crtc 632 */ 633Bool 634xf86CrtcInUse (xf86CrtcPtr crtc); 635 636/* 637 * Output functions 638 */ 639xf86OutputPtr 640xf86OutputCreate (ScrnInfoPtr scrn, 641 const xf86OutputFuncsRec *funcs, 642 const char *name); 643 644void 645xf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor); 646 647Bool 648xf86OutputRename (xf86OutputPtr output, const char *name); 649 650void 651xf86OutputDestroy (xf86OutputPtr output); 652 653void 654xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY); 655 656void 657xf86SetScrnInfoModes (ScrnInfoPtr pScrn); 658 659Bool 660xf86CrtcScreenInit (ScreenPtr pScreen); 661 662Bool 663xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow); 664 665void 666xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags); 667 668Bool 669xf86SaveScreen(ScreenPtr pScreen, int mode); 670 671void 672xf86DisableUnusedFunctions(ScrnInfoPtr pScrn); 673 674DisplayModePtr 675xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired); 676 677Bool 678xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation); 679 680/** 681 * Set the EDID information for the specified output 682 */ 683void 684xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon); 685 686/** 687 * Return the list of modes supported by the EDID information 688 * stored in 'output' 689 */ 690DisplayModePtr 691xf86OutputGetEDIDModes (xf86OutputPtr output); 692 693xf86MonPtr 694xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus); 695 696/** 697 * Initialize dga for this screen 698 */ 699 700Bool 701xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address); 702 703/** 704 * Re-initialize dga for this screen (as when the set of modes changes) 705 */ 706 707Bool 708xf86DiDGAReInit (ScreenPtr pScreen); 709 710/* 711 * Set the subpixel order reported for the screen using 712 * the information from the outputs 713 */ 714 715void 716xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen); 717 718/* 719 * Get a standard string name for a connector type 720 */ 721char * 722xf86ConnectorGetName(xf86ConnectorType connector); 723 724/* 725 * Using the desired mode information in each crtc, set 726 * modes (used in EnterVT functions, or at server startup) 727 */ 728 729Bool 730xf86SetDesiredModes (ScrnInfoPtr pScrn); 731 732/** 733 * Initialize the CRTC-based cursor code. CRTC function vectors must 734 * contain relevant cursor setting functions. 735 * 736 * Driver should call this from ScreenInit function 737 */ 738Bool 739xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags); 740 741/** 742 * Called when anything on the screen is reconfigured. 743 * 744 * Reloads cursor images as needed, then adjusts cursor positions. 745 * 746 * Driver should call this from crtc commit function. 747 */ 748void 749xf86_reload_cursors (ScreenPtr screen); 750 751/** 752 * Called from EnterVT to turn the cursors back on 753 */ 754void 755xf86_show_cursors (ScrnInfoPtr scrn); 756 757/** 758 * Called by the driver to turn cursors off 759 */ 760void 761xf86_hide_cursors (ScrnInfoPtr scrn); 762 763/** 764 * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time. 765 */ 766void 767xf86_cursors_fini (ScreenPtr screen); 768 769/* 770 * For overlay video, compute the relevant CRTC and 771 * clip video to that. 772 * wraps xf86XVClipVideoHelper() 773 */ 774 775Bool 776xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn, 777 xf86CrtcPtr *crtc_ret, 778 xf86CrtcPtr desired_crtc, 779 BoxPtr dst, 780 INT32 *xa, 781 INT32 *xb, 782 INT32 *ya, 783 INT32 *yb, 784 RegionPtr reg, 785 INT32 width, 786 INT32 height); 787 788#endif /* _XF86CRTC_H_ */ 789