2 * Copyright © 2006 Keith Packard
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.
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
28 #include "xf86Rename.h"
30 #include "xf86Modes.h"
31 #include "xf86Cursor.h"
33 #include "picturestr.h"
35 /* Compat definitions for older X Servers. */
37 #define M_T_PREFERRED 0x08
40 #define M_T_DRIVER 0x40
42 #ifndef HARDWARE_CURSOR_ARGB
43 #define HARDWARE_CURSOR_ARGB 0x00004000
46 typedef struct _xf86Crtc xf86CrtcRec
, *xf86CrtcPtr
;
47 typedef struct _xf86Output xf86OutputRec
, *xf86OutputPtr
;
49 /* define a standard for connector types */
50 typedef enum _xf86ConnectorType
{
56 XF86ConnectorComposite
,
58 XF86ConnectorComponent
,
60 XF86ConnectorProprietary
,
63 typedef enum _xf86OutputStatus
{
64 XF86OutputStatusConnected
,
65 XF86OutputStatusDisconnected
,
66 XF86OutputStatusUnknown
,
69 typedef struct _xf86CrtcFuncs
{
71 * Turns the crtc on/off, or sets intermediate power levels if available.
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.
78 (*dpms
)(xf86CrtcPtr crtc
,
82 * Saves the crtc's state for restoration on VT switch.
85 (*save
)(xf86CrtcPtr crtc
);
88 * Restore's the crtc's state at VT switch.
91 (*restore
)(xf86CrtcPtr crtc
);
94 * Lock CRTC prior to mode setting, mostly for DRI.
95 * Returns whether unlock is needed
98 (*lock
) (xf86CrtcPtr crtc
);
101 * Unlock CRTC after mode setting, mostly for DRI
104 (*unlock
) (xf86CrtcPtr crtc
);
107 * Callback to adjust the mode to be set in the CRTC.
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.
114 (*mode_fixup
)(xf86CrtcPtr crtc
,
116 DisplayModePtr adjusted_mode
);
119 * Prepare CRTC for an upcoming mode set.
122 (*prepare
)(xf86CrtcPtr crtc
);
125 * Callback for setting up a video mode after fixups have been made.
128 (*mode_set
)(xf86CrtcPtr crtc
,
130 DisplayModePtr adjusted_mode
,
134 * Commit mode changes to a CRTC
137 (*commit
)(xf86CrtcPtr crtc
);
139 /* Set the color ramps for the CRTC to the given values. */
141 (*gamma_set
)(xf86CrtcPtr crtc
, CARD16
*red
, CARD16
*green
, CARD16
*blue
,
145 * Allocate the shadow area, delay the pixmap creation until needed
148 (*shadow_allocate
) (xf86CrtcPtr crtc
, int width
, int height
);
151 * Create shadow pixmap for rotation support
154 (*shadow_create
) (xf86CrtcPtr crtc
, void *data
, int width
, int height
);
157 * Destroy shadow pixmap
160 (*shadow_destroy
) (xf86CrtcPtr crtc
, PixmapPtr pPixmap
, void *data
);
166 (*set_cursor_colors
) (xf86CrtcPtr crtc
, int bg
, int fg
);
169 * Set cursor position
172 (*set_cursor_position
) (xf86CrtcPtr crtc
, int x
, int y
);
178 (*show_cursor
) (xf86CrtcPtr crtc
);
184 (*hide_cursor
) (xf86CrtcPtr crtc
);
187 * Load monochrome image
190 (*load_cursor_image
) (xf86CrtcPtr crtc
, CARD8
*image
);
196 (*load_cursor_argb
) (xf86CrtcPtr crtc
, CARD32
*image
);
199 * Clean up driver-specific bits of the crtc
202 (*destroy
) (xf86CrtcPtr crtc
);
203 } xf86CrtcFuncsRec
, *xf86CrtcFuncsPtr
;
207 * Associated ScrnInfo
212 * Active state of this CRTC
214 * Set when this CRTC is driving one or more outputs
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
227 PixmapPtr rotatedPixmap
;
233 * Locates this CRTC within the frame buffer
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
245 DisplayModeRec desiredMode
;
246 Rotation desiredRotation
;
247 int desiredX
, desiredY
;
249 /** crtc-specific functions */
250 const xf86CrtcFuncsRec
*funcs
;
255 * Holds driver-private information
257 void *driver_private
;
259 #ifdef RANDR_12_INTERFACE
263 * When RandR 1.2 is available, this
264 * points at the associated crtc object
266 RRCrtcPtr randr_crtc
;
272 * Current cursor is ARGB
276 * Track whether cursor is within CRTC range
278 Bool cursor_in_range
;
280 * Track state of cursor associated with this CRTC
285 * Current transformation matrix
287 PictTransform crtc_to_framebuffer
;
288 PictTransform framebuffer_to_crtc
;
289 Bool transform_in_use
;
291 * Bounding box in screen space
296 typedef struct _xf86OutputFuncs
{
298 * Called to allow the output a chance to create properties after the
299 * RandR objects have been created.
302 (*create_resources
)(xf86OutputPtr output
);
305 * Turns the output on/off, or sets intermediate power levels if available.
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.
312 (*dpms
)(xf86OutputPtr output
,
316 * Saves the output's state for restoration on VT switch.
319 (*save
)(xf86OutputPtr output
);
322 * Restore's the output's state at VT switch.
325 (*restore
)(xf86OutputPtr output
);
328 * Callback for testing a video mode for a given output.
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.
333 * \return MODE_OK if the mode is valid, or another MODE_* otherwise.
336 (*mode_valid
)(xf86OutputPtr output
,
337 DisplayModePtr pMode
);
340 * Callback to adjust the mode to be set in the CRTC.
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.
347 (*mode_fixup
)(xf86OutputPtr output
,
349 DisplayModePtr adjusted_mode
);
352 * Callback for preparing mode changes on an output
355 (*prepare
)(xf86OutputPtr output
);
358 * Callback for committing mode changes on an output
361 (*commit
)(xf86OutputPtr output
);
364 * Callback for setting up a video mode after fixups have been made.
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.
371 (*mode_set
)(xf86OutputPtr output
,
373 DisplayModePtr adjusted_mode
);
376 * Probe for a connected output, and return detect_status.
379 (*detect
)(xf86OutputPtr output
);
382 * Query the device for the modes it provides.
384 * This function may also update MonInfo, mm_width, and mm_height.
386 * \return singly-linked list of modes or NULL if no modes found.
389 (*get_modes
)(xf86OutputPtr output
);
391 #ifdef RANDR_12_INTERFACE
393 * Callback when an output's property has changed.
396 (*set_property
)(xf86OutputPtr output
,
398 RRPropertyValuePtr value
);
401 * Clean up driver-specific bits of the output
404 (*destroy
) (xf86OutputPtr output
);
405 } xf86OutputFuncsRec
, *xf86OutputFuncsPtr
;
409 * Associated ScrnInfo
414 * Currently connected crtc (if any)
416 * If this output is not in use, this field will be NULL.
421 * Possible CRTCs for this output as a mask of crtc indices
423 CARD32 possible_crtcs
;
426 * Possible outputs to share the same CRTC as a mask of output indices
428 CARD32 possible_clones
;
431 * Whether this output can support interlaced modes
433 Bool interlaceAllowed
;
436 * Whether this output can support double scan modes
438 Bool doubleScanAllowed
;
441 * List of available modes on this output.
443 * This should be the list from get_modes(), plus perhaps additional
444 * compatible modes added later.
446 DisplayModePtr probed_modes
;
449 * Options parsed from the related monitor section
451 OptionInfoPtr options
;
454 * Configured monitor section
456 XF86ConfMonitorPtr conf_monitor
;
459 * Desired initial position
461 int initial_x
, initial_y
;
464 * Desired initial rotation
466 Rotation initial_rotation
;
469 * Current connection status
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
474 xf86OutputStatus status
;
476 /** EDID monitor information */
479 /** subpixel order */
482 /** Physical size of the currently attached output device. */
483 int mm_width
, mm_height
;
488 /** output-specific functions */
489 const xf86OutputFuncsRec
*funcs
;
491 /** driver private information */
492 void *driver_private
;
494 /** Whether to use the old per-screen Monitor config section */
495 Bool use_screen_monitor
;
497 #ifdef RANDR_12_INTERFACE
499 * RandR 1.2 output structure.
501 * When RandR 1.2 is available, this points at the associated
502 * RandR output structure and is created when this output is created
504 RROutputPtr randr_output
;
510 typedef struct _xf86CrtcConfigFuncs
{
512 * Requests that the driver resize the screen.
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.
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.
524 (*resize
)(ScrnInfoPtr scrn
,
527 } xf86CrtcConfigFuncsRec
, *xf86CrtcConfigFuncsPtr
;
529 typedef struct _xf86CrtcConfig
{
531 xf86OutputPtr
*output
;
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.
543 int minWidth
, minHeight
;
544 int maxWidth
, maxHeight
;
546 /* For crtc-based rotation */
547 DamagePtr rotation_damage
;
548 Bool rotation_damage_registered
;
551 unsigned int dga_flags
;
552 unsigned long dga_address
;
553 DGAModePtr dga_modes
;
555 int dga_width
, dga_height
, dga_stride
;
556 DisplayModePtr dga_save_mode
;
558 const xf86CrtcConfigFuncsRec
*funcs
;
560 CreateScreenResourcesProcPtr CreateScreenResources
;
562 CloseScreenProcPtr CloseScreen
;
564 /* Cursor information */
565 xf86CursorInfoPtr cursor_info
;
569 CARD32 cursor_fg
, cursor_bg
;
572 * Options parsed from the related device section
574 OptionInfoPtr options
;
578 /* wrap screen BlockHandler for rotation */
579 ScreenBlockHandlerProcPtr BlockHandler
;
581 } xf86CrtcConfigRec
, *xf86CrtcConfigPtr
;
583 extern int xf86CrtcConfigPrivateIndex
;
585 #define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
588 * Initialize xf86CrtcConfig structure
592 xf86CrtcConfigInit (ScrnInfoPtr scrn
,
593 const xf86CrtcConfigFuncsRec
*funcs
);
596 xf86CrtcSetSizeRange (ScrnInfoPtr scrn
,
597 int minWidth
, int minHeight
,
598 int maxWidth
, int maxHeight
);
604 xf86CrtcCreate (ScrnInfoPtr scrn
,
605 const xf86CrtcFuncsRec
*funcs
);
608 xf86CrtcDestroy (xf86CrtcPtr crtc
);
612 * Sets the given video mode on the given crtc
615 xf86CrtcSetMode (xf86CrtcPtr crtc
, DisplayModePtr mode
, Rotation rotation
,
619 * Assign crtc rotation during mode set
622 xf86CrtcRotate (xf86CrtcPtr crtc
, DisplayModePtr mode
, Rotation rotation
);
625 * Clean up rotation during CloseScreen
628 xf86RotateCloseScreen (ScreenPtr pScreen
);
631 * Return whether any output is assigned to the crtc
634 xf86CrtcInUse (xf86CrtcPtr crtc
);
640 xf86OutputCreate (ScrnInfoPtr scrn
,
641 const xf86OutputFuncsRec
*funcs
,
645 xf86OutputUseScreenMonitor (xf86OutputPtr output
, Bool use_screen_monitor
);
648 xf86OutputRename (xf86OutputPtr output
, const char *name
);
651 xf86OutputDestroy (xf86OutputPtr output
);
654 xf86ProbeOutputModes (ScrnInfoPtr pScrn
, int maxX
, int maxY
);
657 xf86SetScrnInfoModes (ScrnInfoPtr pScrn
);
660 xf86CrtcScreenInit (ScreenPtr pScreen
);
663 xf86InitialConfiguration (ScrnInfoPtr pScrn
, Bool canGrow
);
666 xf86DPMSSet(ScrnInfoPtr pScrn
, int PowerManagementMode
, int flags
);
669 xf86SaveScreen(ScreenPtr pScreen
, int mode
);
672 xf86DisableUnusedFunctions(ScrnInfoPtr pScrn
);
675 xf86OutputFindClosestMode (xf86OutputPtr output
, DisplayModePtr desired
);
678 xf86SetSingleMode (ScrnInfoPtr pScrn
, DisplayModePtr desired
, Rotation rotation
);
681 * Set the EDID information for the specified output
684 xf86OutputSetEDID (xf86OutputPtr output
, xf86MonPtr edid_mon
);
687 * Return the list of modes supported by the EDID information
691 xf86OutputGetEDIDModes (xf86OutputPtr output
);
694 xf86OutputGetEDID (xf86OutputPtr output
, I2CBusPtr pDDCBus
);
697 * Initialize dga for this screen
701 xf86DiDGAInit (ScreenPtr pScreen
, unsigned long dga_address
);
704 * Re-initialize dga for this screen (as when the set of modes changes)
708 xf86DiDGAReInit (ScreenPtr pScreen
);
711 * Set the subpixel order reported for the screen using
712 * the information from the outputs
716 xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen
);
719 * Get a standard string name for a connector type
722 xf86ConnectorGetName(xf86ConnectorType connector
);
725 * Using the desired mode information in each crtc, set
726 * modes (used in EnterVT functions, or at server startup)
730 xf86SetDesiredModes (ScrnInfoPtr pScrn
);
733 * Initialize the CRTC-based cursor code. CRTC function vectors must
734 * contain relevant cursor setting functions.
736 * Driver should call this from ScreenInit function
739 xf86_cursors_init (ScreenPtr screen
, int max_width
, int max_height
, int flags
);
742 * Called when anything on the screen is reconfigured.
744 * Reloads cursor images as needed, then adjusts cursor positions.
746 * Driver should call this from crtc commit function.
749 xf86_reload_cursors (ScreenPtr screen
);
752 * Called from EnterVT to turn the cursors back on
755 xf86_show_cursors (ScrnInfoPtr scrn
);
758 * Called by the driver to turn cursors off
761 xf86_hide_cursors (ScrnInfoPtr scrn
);
764 * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
767 xf86_cursors_fini (ScreenPtr screen
);
770 * For overlay video, compute the relevant CRTC and
771 * clip video to that.
772 * wraps xf86XVClipVideoHelper()
776 xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn
,
777 xf86CrtcPtr
*crtc_ret
,
778 xf86CrtcPtr desired_crtc
,
788 #endif /* _XF86CRTC_H_ */