First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / modes / xf86Crtc.h
blob9693e12bbfb7233b2910bbe790668a80b880d216
1 /*
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
20 * OF THIS SOFTWARE.
22 #ifndef _XF86CRTC_H_
23 #define _XF86CRTC_H_
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"
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
46 typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
47 typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
49 /* define a standard for connector types */
50 typedef 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;
63 typedef enum _xf86OutputStatus {
64 XF86OutputStatusConnected,
65 XF86OutputStatusDisconnected,
66 XF86OutputStatusUnknown,
67 } xf86OutputStatus;
69 typedef struct _xf86CrtcFuncs {
70 /**
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.
77 void
78 (*dpms)(xf86CrtcPtr crtc,
79 int mode);
81 /**
82 * Saves the crtc's state for restoration on VT switch.
84 void
85 (*save)(xf86CrtcPtr crtc);
87 /**
88 * Restore's the crtc's state at VT switch.
90 void
91 (*restore)(xf86CrtcPtr crtc);
93 /**
94 * Lock CRTC prior to mode setting, mostly for DRI.
95 * Returns whether unlock is needed
97 Bool
98 (*lock) (xf86CrtcPtr crtc);
101 * Unlock CRTC after mode setting, mostly for DRI
103 void
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.
113 Bool
114 (*mode_fixup)(xf86CrtcPtr crtc,
115 DisplayModePtr mode,
116 DisplayModePtr adjusted_mode);
119 * Prepare CRTC for an upcoming mode set.
121 void
122 (*prepare)(xf86CrtcPtr crtc);
125 * Callback for setting up a video mode after fixups have been made.
127 void
128 (*mode_set)(xf86CrtcPtr crtc,
129 DisplayModePtr mode,
130 DisplayModePtr adjusted_mode,
131 int x, int y);
134 * Commit mode changes to a CRTC
136 void
137 (*commit)(xf86CrtcPtr crtc);
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);
145 * Allocate the shadow area, delay the pixmap creation until needed
147 void *
148 (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height);
151 * Create shadow pixmap for rotation support
153 PixmapPtr
154 (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height);
157 * Destroy shadow pixmap
159 void
160 (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
163 * Set cursor colors
165 void
166 (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg);
169 * Set cursor position
171 void
172 (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y);
175 * Show cursor
177 void
178 (*show_cursor) (xf86CrtcPtr crtc);
181 * Hide cursor
183 void
184 (*hide_cursor) (xf86CrtcPtr crtc);
187 * Load monochrome image
189 void
190 (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image);
193 * Load ARGB image
195 void
196 (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image);
199 * Clean up driver-specific bits of the crtc
201 void
202 (*destroy) (xf86CrtcPtr crtc);
203 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
205 struct _xf86Crtc {
207 * Associated ScrnInfo
209 ScrnInfoPtr scrn;
212 * Active state of this CRTC
214 * Set when this CRTC is driving one or more outputs
216 Bool enabled;
219 * Active mode
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
225 DisplayModeRec mode;
226 Rotation rotation;
227 PixmapPtr rotatedPixmap;
228 void *rotatedData;
231 * Position on screen
233 * Locates this CRTC within the frame buffer
235 int x, y;
238 * Desired mode
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.
245 DisplayModeRec desiredMode;
246 Rotation desiredRotation;
247 int desiredX, desiredY;
249 /** crtc-specific functions */
250 const xf86CrtcFuncsRec *funcs;
253 * Driver private
255 * Holds driver-private information
257 void *driver_private;
259 #ifdef RANDR_12_INTERFACE
261 * RandR crtc
263 * When RandR 1.2 is available, this
264 * points at the associated crtc object
266 RRCrtcPtr randr_crtc;
267 #else
268 void *randr_crtc;
269 #endif
272 * Current cursor is ARGB
274 Bool cursor_argb;
276 * Track whether cursor is within CRTC range
278 Bool cursor_in_range;
280 * Track state of cursor associated with this CRTC
282 Bool cursor_shown;
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
293 BoxRec bounds;
296 typedef struct _xf86OutputFuncs {
298 * Called to allow the output a chance to create properties after the
299 * RandR objects have been created.
301 void
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.
311 void
312 (*dpms)(xf86OutputPtr output,
313 int mode);
316 * Saves the output's state for restoration on VT switch.
318 void
319 (*save)(xf86OutputPtr output);
322 * Restore's the output's state at VT switch.
324 void
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.
346 Bool
347 (*mode_fixup)(xf86OutputPtr output,
348 DisplayModePtr mode,
349 DisplayModePtr adjusted_mode);
352 * Callback for preparing mode changes on an output
354 void
355 (*prepare)(xf86OutputPtr output);
358 * Callback for committing mode changes on an output
360 void
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.
370 void
371 (*mode_set)(xf86OutputPtr output,
372 DisplayModePtr mode,
373 DisplayModePtr adjusted_mode);
376 * Probe for a connected output, and return detect_status.
378 xf86OutputStatus
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.
388 DisplayModePtr
389 (*get_modes)(xf86OutputPtr output);
391 #ifdef RANDR_12_INTERFACE
393 * Callback when an output's property has changed.
395 Bool
396 (*set_property)(xf86OutputPtr output,
397 Atom property,
398 RRPropertyValuePtr value);
399 #endif
401 * Clean up driver-specific bits of the output
403 void
404 (*destroy) (xf86OutputPtr output);
405 } xf86OutputFuncsRec, *xf86OutputFuncsPtr;
407 struct _xf86Output {
409 * Associated ScrnInfo
411 ScrnInfoPtr scrn;
414 * Currently connected crtc (if any)
416 * If this output is not in use, this field will be NULL.
418 xf86CrtcPtr crtc;
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 */
477 xf86MonPtr MonInfo;
479 /** subpixel order */
480 int subpixel_order;
482 /** Physical size of the currently attached output device. */
483 int mm_width, mm_height;
485 /** Output name */
486 char *name;
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;
505 #else
506 void *randr_output;
507 #endif
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.
523 Bool
524 (*resize)(ScrnInfoPtr scrn,
525 int width,
526 int height);
527 } xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
529 typedef struct _xf86CrtcConfig {
530 int num_output;
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.
538 int compat_output;
540 int num_crtc;
541 xf86CrtcPtr *crtc;
543 int minWidth, minHeight;
544 int maxWidth, maxHeight;
546 /* For crtc-based rotation */
547 DamagePtr rotation_damage;
548 Bool rotation_damage_registered;
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;
558 const xf86CrtcConfigFuncsRec *funcs;
560 CreateScreenResourcesProcPtr CreateScreenResources;
562 CloseScreenProcPtr CloseScreen;
564 /* Cursor information */
565 xf86CursorInfoPtr cursor_info;
566 CursorPtr cursor;
567 CARD8 *cursor_image;
568 Bool cursor_on;
569 CARD32 cursor_fg, cursor_bg;
572 * Options parsed from the related device section
574 OptionInfoPtr options;
576 Bool debug_modes;
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
591 void
592 xf86CrtcConfigInit (ScrnInfoPtr scrn,
593 const xf86CrtcConfigFuncsRec *funcs);
595 void
596 xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
597 int minWidth, int minHeight,
598 int maxWidth, int maxHeight);
601 * Crtc functions
603 xf86CrtcPtr
604 xf86CrtcCreate (ScrnInfoPtr scrn,
605 const xf86CrtcFuncsRec *funcs);
607 void
608 xf86CrtcDestroy (xf86CrtcPtr crtc);
612 * Sets the given video mode on the given crtc
614 Bool
615 xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
616 int x, int y);
619 * Assign crtc rotation during mode set
621 Bool
622 xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation);
625 * Clean up rotation during CloseScreen
627 void
628 xf86RotateCloseScreen (ScreenPtr pScreen);
631 * Return whether any output is assigned to the crtc
633 Bool
634 xf86CrtcInUse (xf86CrtcPtr crtc);
637 * Output functions
639 xf86OutputPtr
640 xf86OutputCreate (ScrnInfoPtr scrn,
641 const xf86OutputFuncsRec *funcs,
642 const char *name);
644 void
645 xf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor);
647 Bool
648 xf86OutputRename (xf86OutputPtr output, const char *name);
650 void
651 xf86OutputDestroy (xf86OutputPtr output);
653 void
654 xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY);
656 void
657 xf86SetScrnInfoModes (ScrnInfoPtr pScrn);
659 Bool
660 xf86CrtcScreenInit (ScreenPtr pScreen);
662 Bool
663 xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow);
665 void
666 xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
668 Bool
669 xf86SaveScreen(ScreenPtr pScreen, int mode);
671 void
672 xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
674 DisplayModePtr
675 xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired);
677 Bool
678 xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
681 * Set the EDID information for the specified output
683 void
684 xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon);
687 * Return the list of modes supported by the EDID information
688 * stored in 'output'
690 DisplayModePtr
691 xf86OutputGetEDIDModes (xf86OutputPtr output);
693 xf86MonPtr
694 xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus);
697 * Initialize dga for this screen
700 Bool
701 xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address);
704 * Re-initialize dga for this screen (as when the set of modes changes)
707 Bool
708 xf86DiDGAReInit (ScreenPtr pScreen);
711 * Set the subpixel order reported for the screen using
712 * the information from the outputs
715 void
716 xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen);
719 * Get a standard string name for a connector type
721 char *
722 xf86ConnectorGetName(xf86ConnectorType connector);
725 * Using the desired mode information in each crtc, set
726 * modes (used in EnterVT functions, or at server startup)
729 Bool
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
738 Bool
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.
748 void
749 xf86_reload_cursors (ScreenPtr screen);
752 * Called from EnterVT to turn the cursors back on
754 void
755 xf86_show_cursors (ScrnInfoPtr scrn);
758 * Called by the driver to turn cursors off
760 void
761 xf86_hide_cursors (ScrnInfoPtr scrn);
764 * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
766 void
767 xf86_cursors_fini (ScreenPtr screen);
770 * For overlay video, compute the relevant CRTC and
771 * clip video to that.
772 * wraps xf86XVClipVideoHelper()
775 Bool
776 xf86_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);
788 #endif /* _XF86CRTC_H_ */