1/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2011 Aaron Plattner
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission.  The copyright holders make no representations
12 * about the suitability of this software for any purpose.  It is provided "as
13 * is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23#ifndef _XF86CRTC_H_
24#define _XF86CRTC_H_
25
26#include <edid.h>
27#include "randrstr.h"
28#include "xf86Modes.h"
29#include "xf86Cursor.h"
30#include "xf86i2c.h"
31#include "damage.h"
32#include "picturestr.h"
33
34/* Compat definitions for older X Servers. */
35#ifndef M_T_PREFERRED
36#define M_T_PREFERRED	0x08
37#endif
38#ifndef M_T_DRIVER
39#define M_T_DRIVER	0x40
40#endif
41#ifndef M_T_USERPREF
42#define M_T_USERPREF	0x80
43#endif
44#ifndef HARDWARE_CURSOR_ARGB
45#define HARDWARE_CURSOR_ARGB				0x00004000
46#endif
47
48typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
49typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
50typedef struct _xf86Lease xf86LeaseRec, *xf86LeasePtr;
51
52/* define a standard for connector types */
53typedef enum _xf86ConnectorType {
54    XF86ConnectorNone,
55    XF86ConnectorVGA,
56    XF86ConnectorDVI_I,
57    XF86ConnectorDVI_D,
58    XF86ConnectorDVI_A,
59    XF86ConnectorComposite,
60    XF86ConnectorSvideo,
61    XF86ConnectorComponent,
62    XF86ConnectorLFP,
63    XF86ConnectorProprietary,
64    XF86ConnectorHDMI,
65    XF86ConnectorDisplayPort,
66} xf86ConnectorType;
67
68typedef enum _xf86OutputStatus {
69    XF86OutputStatusConnected,
70    XF86OutputStatusDisconnected,
71    XF86OutputStatusUnknown
72} xf86OutputStatus;
73
74typedef enum _xf86DriverTransforms {
75    XF86DriverTransformNone = 0,
76    XF86DriverTransformOutput = 1 << 0,
77    XF86DriverTransformCursorImage = 1 << 1,
78    XF86DriverTransformCursorPosition = 1 << 2,
79} xf86DriverTransforms;
80
81
82struct xf86CrtcTileInfo {
83    uint32_t group_id;
84    uint32_t flags;
85    uint32_t num_h_tile;
86    uint32_t num_v_tile;
87    uint32_t tile_h_loc;
88    uint32_t tile_v_loc;
89    uint32_t tile_h_size;
90    uint32_t tile_v_size;
91};
92
93typedef struct _xf86CrtcFuncs {
94   /**
95    * Turns the crtc on/off, or sets intermediate power levels if available.
96    *
97    * Unsupported intermediate modes drop to the lower power setting.  If the
98    * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to
99    * be safe to call mode_set.
100    */
101    void
102     (*dpms) (xf86CrtcPtr crtc, int mode);
103
104   /**
105    * Saves the crtc's state for restoration on VT switch.
106    */
107    void
108     (*save) (xf86CrtcPtr crtc);
109
110   /**
111    * Restore's the crtc's state at VT switch.
112    */
113    void
114     (*restore) (xf86CrtcPtr crtc);
115
116    /**
117     * Lock CRTC prior to mode setting, mostly for DRI.
118     * Returns whether unlock is needed
119     */
120    Bool
121     (*lock) (xf86CrtcPtr crtc);
122
123    /**
124     * Unlock CRTC after mode setting, mostly for DRI
125     */
126    void
127     (*unlock) (xf86CrtcPtr crtc);
128
129    /**
130     * Callback to adjust the mode to be set in the CRTC.
131     *
132     * This allows a CRTC to adjust the clock or even the entire set of
133     * timings, which is used for panels with fixed timings or for
134     * buses with clock limitations.
135     */
136    Bool
137     (*mode_fixup) (xf86CrtcPtr crtc,
138                    DisplayModePtr mode, DisplayModePtr adjusted_mode);
139
140    /**
141     * Prepare CRTC for an upcoming mode set.
142     */
143    void
144     (*prepare) (xf86CrtcPtr crtc);
145
146    /**
147     * Callback for setting up a video mode after fixups have been made.
148     */
149    void
150     (*mode_set) (xf86CrtcPtr crtc,
151                  DisplayModePtr mode,
152                  DisplayModePtr adjusted_mode, int x, int y);
153
154    /**
155     * Commit mode changes to a CRTC
156     */
157    void
158     (*commit) (xf86CrtcPtr crtc);
159
160    /* Set the color ramps for the CRTC to the given values. */
161    void
162     (*gamma_set) (xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
163                   int size);
164
165    /**
166     * Allocate the shadow area, delay the pixmap creation until needed
167     */
168    void *(*shadow_allocate) (xf86CrtcPtr crtc, int width, int height);
169
170    /**
171     * Create shadow pixmap for rotation support
172     */
173    PixmapPtr
174     (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height);
175
176    /**
177     * Destroy shadow pixmap
178     */
179    void
180     (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
181
182    /**
183     * Set cursor colors
184     */
185    void
186     (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg);
187
188    /**
189     * Set cursor position
190     */
191    void
192     (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y);
193
194    /**
195     * Show cursor
196     */
197    void
198     (*show_cursor) (xf86CrtcPtr crtc);
199    Bool
200     (*show_cursor_check) (xf86CrtcPtr crtc);
201
202    /**
203     * Hide cursor
204     */
205    void
206     (*hide_cursor) (xf86CrtcPtr crtc);
207
208    /**
209     * Load monochrome image
210     */
211    void
212     (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image);
213    Bool
214     (*load_cursor_image_check) (xf86CrtcPtr crtc, CARD8 *image);
215
216    /**
217     * Load ARGB image
218     */
219    void
220     (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image);
221    Bool
222     (*load_cursor_argb_check) (xf86CrtcPtr crtc, CARD32 *image);
223
224    /**
225     * Clean up driver-specific bits of the crtc
226     */
227    void
228     (*destroy) (xf86CrtcPtr crtc);
229
230    /**
231     * Less fine-grained mode setting entry point for kernel modesetting
232     */
233    Bool
234     (*set_mode_major) (xf86CrtcPtr crtc, DisplayModePtr mode,
235                        Rotation rotation, int x, int y);
236
237    /**
238     * Callback for panning. Doesn't change the mode.
239     * Added in ABI version 2
240     */
241    void
242     (*set_origin) (xf86CrtcPtr crtc, int x, int y);
243
244    /**
245     */
246    Bool
247    (*set_scanout_pixmap)(xf86CrtcPtr crtc, PixmapPtr pixmap);
248
249} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
250
251#define XF86_CRTC_VERSION 8
252
253struct _xf86Crtc {
254    /**
255     * ABI versioning
256     */
257    int version;
258
259    /**
260     * Associated ScrnInfo
261     */
262    ScrnInfoPtr scrn;
263
264    /**
265     * Desired state of this CRTC
266     *
267     * Set when this CRTC should be driving one or more outputs
268     */
269    Bool enabled;
270
271    /**
272     * Active mode
273     *
274     * This reflects the mode as set in the CRTC currently
275     * It will be cleared when the VT is not active or
276     * during server startup
277     */
278    DisplayModeRec mode;
279    Rotation rotation;
280    PixmapPtr rotatedPixmap;
281    void *rotatedData;
282
283    /**
284     * Position on screen
285     *
286     * Locates this CRTC within the frame buffer
287     */
288    int x, y;
289
290    /**
291     * Desired mode
292     *
293     * This is set to the requested mode, independent of
294     * whether the VT is active. In particular, it receives
295     * the startup configured mode and saves the active mode
296     * on VT switch.
297     */
298    DisplayModeRec desiredMode;
299    Rotation desiredRotation;
300    int desiredX, desiredY;
301
302    /** crtc-specific functions */
303    const xf86CrtcFuncsRec *funcs;
304
305    /**
306     * Driver private
307     *
308     * Holds driver-private information
309     */
310    void *driver_private;
311
312#ifdef RANDR_12_INTERFACE
313    /**
314     * RandR crtc
315     *
316     * When RandR 1.2 is available, this
317     * points at the associated crtc object
318     */
319    RRCrtcPtr randr_crtc;
320#else
321    void *randr_crtc;
322#endif
323
324    /**
325     * Current cursor is ARGB
326     */
327    Bool cursor_argb;
328    /**
329     * Track whether cursor is within CRTC range
330     */
331    Bool cursor_in_range;
332    /**
333     * Track state of cursor associated with this CRTC
334     */
335    Bool cursor_shown;
336
337    /**
338     * Current transformation matrix
339     */
340    PictTransform crtc_to_framebuffer;
341    /* framebuffer_to_crtc was removed in ABI 2 */
342    struct pict_f_transform f_crtc_to_framebuffer;      /* ABI 2 */
343    struct pict_f_transform f_framebuffer_to_crtc;      /* ABI 2 */
344    PictFilterPtr filter;       /* ABI 2 */
345    xFixed *params;             /* ABI 2 */
346    int nparams;                /* ABI 2 */
347    int filter_width;           /* ABI 2 */
348    int filter_height;          /* ABI 2 */
349    Bool transform_in_use;
350    RRTransformRec transform;   /* ABI 2 */
351    Bool transformPresent;      /* ABI 2 */
352    RRTransformRec desiredTransform;    /* ABI 2 */
353    Bool desiredTransformPresent;       /* ABI 2 */
354    /**
355     * Bounding box in screen space
356     */
357    BoxRec bounds;
358    /**
359     * Panning:
360     * TotalArea: total panning area, larger than CRTC's size
361     * TrackingArea: Area of the pointer for which the CRTC is panned
362     * border: Borders of the displayed CRTC area which induces panning if the pointer reaches them
363     * Added in ABI version 2
364     */
365    BoxRec panningTotalArea;
366    BoxRec panningTrackingArea;
367    INT16 panningBorder[4];
368
369    /**
370     * Current gamma, especially useful after initial config.
371     * Added in ABI version 3
372     */
373    CARD16 *gamma_red;
374    CARD16 *gamma_green;
375    CARD16 *gamma_blue;
376    int gamma_size;
377
378    /**
379     * Actual state of this CRTC
380     *
381     * Set to TRUE after modesetting, set to FALSE if no outputs are connected
382     * Added in ABI version 3
383     */
384    Bool active;
385    /**
386     * Clear the shadow
387     */
388    Bool shadowClear;
389
390    /**
391     * Indicates that the driver is handling some or all transforms:
392     *
393     * XF86DriverTransformOutput: The driver handles the output transform, so
394     * the shadow surface should be disabled.  The driver writes this field
395     * before calling xf86CrtcRotate to indicate that it is handling the
396     * transform (including rotation and reflection).
397     *
398     * XF86DriverTransformCursorImage: Setting this flag causes the server to
399     * pass the untransformed cursor image to the driver hook.
400     *
401     * XF86DriverTransformCursorPosition: Setting this flag causes the server
402     * to pass the untransformed cursor position to the driver hook.
403     *
404     * Added in ABI version 4, changed to xf86DriverTransforms in ABI version 7
405     */
406    xf86DriverTransforms driverIsPerformingTransform;
407
408    /* Added in ABI version 5
409     */
410    PixmapPtr current_scanout;
411
412    /* Added in ABI version 6
413     */
414    PixmapPtr current_scanout_back;
415};
416
417typedef struct _xf86OutputFuncs {
418    /**
419     * Called to allow the output a chance to create properties after the
420     * RandR objects have been created.
421     */
422    void
423     (*create_resources) (xf86OutputPtr output);
424
425    /**
426     * Turns the output on/off, or sets intermediate power levels if available.
427     *
428     * Unsupported intermediate modes drop to the lower power setting.  If the
429     * mode is DPMSModeOff, the output must be disabled, as the DPLL may be
430     * disabled afterwards.
431     */
432    void
433     (*dpms) (xf86OutputPtr output, int mode);
434
435    /**
436     * Saves the output's state for restoration on VT switch.
437     */
438    void
439     (*save) (xf86OutputPtr output);
440
441    /**
442     * Restore's the output's state at VT switch.
443     */
444    void
445     (*restore) (xf86OutputPtr output);
446
447    /**
448     * Callback for testing a video mode for a given output.
449     *
450     * This function should only check for cases where a mode can't be supported
451     * on the output specifically, and not represent generic CRTC limitations.
452     *
453     * \return MODE_OK if the mode is valid, or another MODE_* otherwise.
454     */
455    int
456     (*mode_valid) (xf86OutputPtr output, DisplayModePtr pMode);
457
458    /**
459     * Callback to adjust the mode to be set in the CRTC.
460     *
461     * This allows an output to adjust the clock or even the entire set of
462     * timings, which is used for panels with fixed timings or for
463     * buses with clock limitations.
464     */
465    Bool
466     (*mode_fixup) (xf86OutputPtr output,
467                    DisplayModePtr mode, DisplayModePtr adjusted_mode);
468
469    /**
470     * Callback for preparing mode changes on an output
471     */
472    void
473     (*prepare) (xf86OutputPtr output);
474
475    /**
476     * Callback for committing mode changes on an output
477     */
478    void
479     (*commit) (xf86OutputPtr output);
480
481    /**
482     * Callback for setting up a video mode after fixups have been made.
483     *
484     * This is only called while the output is disabled.  The dpms callback
485     * must be all that's necessary for the output, to turn the output on
486     * after this function is called.
487     */
488    void
489     (*mode_set) (xf86OutputPtr output,
490                  DisplayModePtr mode, DisplayModePtr adjusted_mode);
491
492    /**
493     * Probe for a connected output, and return detect_status.
494     */
495     xf86OutputStatus(*detect) (xf86OutputPtr output);
496
497    /**
498     * Query the device for the modes it provides.
499     *
500     * This function may also update MonInfo, mm_width, and mm_height.
501     *
502     * \return singly-linked list of modes or NULL if no modes found.
503     */
504     DisplayModePtr(*get_modes) (xf86OutputPtr output);
505
506#ifdef RANDR_12_INTERFACE
507    /**
508     * Callback when an output's property has changed.
509     */
510    Bool
511     (*set_property) (xf86OutputPtr output,
512                      Atom property, RRPropertyValuePtr value);
513#endif
514#ifdef RANDR_13_INTERFACE
515    /**
516     * Callback to get an updated property value
517     */
518    Bool
519     (*get_property) (xf86OutputPtr output, Atom property);
520#endif
521#ifdef RANDR_GET_CRTC_INTERFACE
522    /**
523     * Callback to get current CRTC for a given output
524     */
525     xf86CrtcPtr(*get_crtc) (xf86OutputPtr output);
526#endif
527    /**
528     * Clean up driver-specific bits of the output
529     */
530    void
531     (*destroy) (xf86OutputPtr output);
532} xf86OutputFuncsRec, *xf86OutputFuncsPtr;
533
534#define XF86_OUTPUT_VERSION 3
535
536struct _xf86Output {
537    /**
538     * ABI versioning
539     */
540    int version;
541
542    /**
543     * Associated ScrnInfo
544     */
545    ScrnInfoPtr scrn;
546
547    /**
548     * Currently connected crtc (if any)
549     *
550     * If this output is not in use, this field will be NULL.
551     */
552    xf86CrtcPtr crtc;
553
554    /**
555     * Possible CRTCs for this output as a mask of crtc indices
556     */
557    CARD32 possible_crtcs;
558
559    /**
560     * Possible outputs to share the same CRTC as a mask of output indices
561     */
562    CARD32 possible_clones;
563
564    /**
565     * Whether this output can support interlaced modes
566     */
567    Bool interlaceAllowed;
568
569    /**
570     * Whether this output can support double scan modes
571     */
572    Bool doubleScanAllowed;
573
574    /**
575     * List of available modes on this output.
576     *
577     * This should be the list from get_modes(), plus perhaps additional
578     * compatible modes added later.
579     */
580    DisplayModePtr probed_modes;
581
582    /**
583     * Options parsed from the related monitor section
584     */
585    OptionInfoPtr options;
586
587    /**
588     * Configured monitor section
589     */
590    XF86ConfMonitorPtr conf_monitor;
591
592    /**
593     * Desired initial position
594     */
595    int initial_x, initial_y;
596
597    /**
598     * Desired initial rotation
599     */
600    Rotation initial_rotation;
601
602    /**
603     * Current connection status
604     *
605     * This indicates whether a monitor is known to be connected
606     * to this output or not, or whether there is no way to tell
607     */
608    xf86OutputStatus status;
609
610    /** EDID monitor information */
611    xf86MonPtr MonInfo;
612
613    /** subpixel order */
614    int subpixel_order;
615
616    /** Physical size of the currently attached output device. */
617    int mm_width, mm_height;
618
619    /** Output name */
620    char *name;
621
622    /** output-specific functions */
623    const xf86OutputFuncsRec *funcs;
624
625    /** driver private information */
626    void *driver_private;
627
628    /** Whether to use the old per-screen Monitor config section */
629    Bool use_screen_monitor;
630
631    /** For pre-init, whether the output should be excluded from the
632     * desktop when there are other viable outputs to use
633     */
634    Bool non_desktop;
635
636#ifdef RANDR_12_INTERFACE
637    /**
638     * RandR 1.2 output structure.
639     *
640     * When RandR 1.2 is available, this points at the associated
641     * RandR output structure and is created when this output is created
642     */
643    RROutputPtr randr_output;
644#else
645    void *randr_output;
646#endif
647    /**
648     * Desired initial panning
649     * Added in ABI version 2
650     */
651    BoxRec initialTotalArea;
652    BoxRec initialTrackingArea;
653    INT16 initialBorder[4];
654
655    struct xf86CrtcTileInfo tile_info;
656};
657
658typedef struct _xf86ProviderFuncs {
659    /**
660     * Called to allow the provider a chance to create properties after the
661     * RandR objects have been created.
662     */
663    void
664    (*create_resources) (ScrnInfoPtr scrn);
665
666    /**
667     * Callback when an provider's property has changed.
668     */
669    Bool
670    (*set_property) (ScrnInfoPtr scrn,
671                     Atom property, RRPropertyValuePtr value);
672
673    /**
674     * Callback to get an updated property value
675     */
676    Bool
677    (*get_property) (ScrnInfoPtr provider, Atom property);
678
679} xf86ProviderFuncsRec, *xf86ProviderFuncsPtr;
680
681#define XF86_LEASE_VERSION      1
682
683struct _xf86Lease {
684    /**
685     * ABI versioning
686     */
687    int version;
688
689    /**
690     * Associated ScrnInfo
691     */
692    ScrnInfoPtr scrn;
693
694    /**
695     * Driver private
696     */
697    void *driver_private;
698
699    /**
700     * RandR lease
701     */
702    RRLeasePtr randr_lease;
703
704    /*
705     * Contents of the lease
706     */
707
708    /**
709     * Number of leased CRTCs
710     */
711    int num_crtc;
712
713    /**
714     * Number of leased outputs
715     */
716    int num_output;
717
718    /**
719     * Array of pointers to leased CRTCs
720     */
721    RRCrtcPtr *crtcs;
722
723    /**
724     * Array of pointers to leased outputs
725     */
726    RROutputPtr *outputs;
727};
728
729typedef struct _xf86CrtcConfigFuncs {
730    /**
731     * Requests that the driver resize the screen.
732     *
733     * The driver is responsible for updating scrn->virtualX and scrn->virtualY.
734     * If the requested size cannot be set, the driver should leave those values
735     * alone and return FALSE.
736     *
737     * A naive driver that cannot reallocate the screen may simply change
738     * virtual[XY].  A more advanced driver will want to also change the
739     * devPrivate.ptr and devKind of the screen pixmap, update any offscreen
740     * pixmaps it may have moved, and change pScrn->displayWidth.
741     */
742    Bool
743     (*resize) (ScrnInfoPtr scrn, int width, int height);
744
745    /**
746     * Requests that the driver create a lease
747     */
748    int (*create_lease)(RRLeasePtr lease, int *fd);
749
750    /**
751     * Ask the driver to terminate a lease, freeing all
752     * driver resources
753     */
754    void (*terminate_lease)(RRLeasePtr lease);
755} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
756
757/*
758 * The driver calls this when it detects that a lease
759 * has been terminated
760 */
761extern _X_EXPORT void
762xf86CrtcLeaseTerminated(RRLeasePtr lease);
763
764extern _X_EXPORT void
765xf86CrtcLeaseStarted(RRLeasePtr lease);
766
767typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
768
769typedef struct _xf86CrtcConfig {
770    int num_output;
771    xf86OutputPtr *output;
772    /**
773     * compat_output is used whenever we deal
774     * with legacy code that only understands a single
775     * output. pScrn->modes will be loaded from this output,
776     * adjust frame will whack this output, etc.
777     */
778    int compat_output;
779
780    int num_crtc;
781    xf86CrtcPtr *crtc;
782
783    int minWidth, minHeight;
784    int maxWidth, maxHeight;
785
786    /* For crtc-based rotation */
787    DamagePtr rotation_damage;
788    Bool rotation_damage_registered;
789
790    /* DGA */
791    unsigned int dga_flags;
792    unsigned long dga_address;
793    DGAModePtr dga_modes;
794    int dga_nmode;
795    int dga_width, dga_height, dga_stride;
796    DisplayModePtr dga_save_mode;
797
798    const xf86CrtcConfigFuncsRec *funcs;
799
800    CreateScreenResourcesProcPtr CreateScreenResources;
801
802    CloseScreenProcPtr CloseScreen;
803
804    /* Cursor information */
805    xf86CursorInfoPtr cursor_info;
806    CursorPtr cursor;
807    CARD8 *cursor_image;
808    Bool cursor_on;
809    CARD32 cursor_fg, cursor_bg;
810
811    /**
812     * Options parsed from the related device section
813     */
814    OptionInfoPtr options;
815
816    Bool debug_modes;
817
818    /* wrap screen BlockHandler for rotation */
819    ScreenBlockHandlerProcPtr BlockHandler;
820
821    /* callback when crtc configuration changes */
822    xf86_crtc_notify_proc_ptr xf86_crtc_notify;
823
824    char *name;
825    const xf86ProviderFuncsRec *provider_funcs;
826#ifdef RANDR_12_INTERFACE
827    RRProviderPtr randr_provider;
828#else
829    void *randr_provider;
830#endif
831} xf86CrtcConfigRec, *xf86CrtcConfigPtr;
832
833extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
834
835#define XF86_CRTC_CONFIG_PTR(p)	((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
836
837static _X_INLINE xf86OutputPtr
838xf86CompatOutput(ScrnInfoPtr pScrn)
839{
840    xf86CrtcConfigPtr config;
841
842    if (xf86CrtcConfigPrivateIndex == -1)
843        return NULL;
844    config = XF86_CRTC_CONFIG_PTR(pScrn);
845    if (config->compat_output < 0)
846        return NULL;
847    return config->output[config->compat_output];
848}
849
850static _X_INLINE xf86CrtcPtr
851xf86CompatCrtc(ScrnInfoPtr pScrn)
852{
853    xf86OutputPtr compat_output = xf86CompatOutput(pScrn);
854
855    if (!compat_output)
856        return NULL;
857    return compat_output->crtc;
858}
859
860static _X_INLINE RRCrtcPtr
861xf86CompatRRCrtc(ScrnInfoPtr pScrn)
862{
863    xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn);
864
865    if (!compat_crtc)
866        return NULL;
867    return compat_crtc->randr_crtc;
868}
869
870/*
871 * Initialize xf86CrtcConfig structure
872 */
873
874extern _X_EXPORT void
875 xf86CrtcConfigInit(ScrnInfoPtr scrn, const xf86CrtcConfigFuncsRec * funcs);
876
877extern _X_EXPORT void
878
879xf86CrtcSetSizeRange(ScrnInfoPtr scrn,
880                     int minWidth, int minHeight, int maxWidth, int maxHeight);
881
882/*
883 * Crtc functions
884 */
885extern _X_EXPORT xf86CrtcPtr
886xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs);
887
888extern _X_EXPORT void
889 xf86CrtcDestroy(xf86CrtcPtr crtc);
890
891/**
892 * Sets the given video mode on the given crtc
893 */
894
895extern _X_EXPORT Bool
896
897xf86CrtcSetModeTransform(xf86CrtcPtr crtc, DisplayModePtr mode,
898                         Rotation rotation, RRTransformPtr transform, int x,
899                         int y);
900
901extern _X_EXPORT Bool
902
903xf86CrtcSetMode(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
904                int x, int y);
905
906extern _X_EXPORT void
907 xf86CrtcSetOrigin(xf86CrtcPtr crtc, int x, int y);
908
909/*
910 * Assign crtc rotation during mode set
911 */
912extern _X_EXPORT Bool
913 xf86CrtcRotate(xf86CrtcPtr crtc);
914
915/*
916 * Clean up any rotation data, used when a crtc is turned off
917 * as well as when rotation is disabled.
918 */
919extern _X_EXPORT void
920 xf86RotateDestroy(xf86CrtcPtr crtc);
921
922/*
923 * free shadow memory allocated for all crtcs
924 */
925extern _X_EXPORT void
926 xf86RotateFreeShadow(ScrnInfoPtr pScrn);
927
928/*
929 * Clean up rotation during CloseScreen
930 */
931extern _X_EXPORT void
932 xf86RotateCloseScreen(ScreenPtr pScreen);
933
934/**
935 * Return whether any output is assigned to the crtc
936 */
937extern _X_EXPORT Bool
938 xf86CrtcInUse(xf86CrtcPtr crtc);
939
940/*
941 * Output functions
942 */
943extern _X_EXPORT xf86OutputPtr
944xf86OutputCreate(ScrnInfoPtr scrn,
945                 const xf86OutputFuncsRec * funcs, const char *name);
946
947extern _X_EXPORT void
948 xf86OutputUseScreenMonitor(xf86OutputPtr output, Bool use_screen_monitor);
949
950extern _X_EXPORT Bool
951 xf86OutputRename(xf86OutputPtr output, const char *name);
952
953extern _X_EXPORT void
954 xf86OutputDestroy(xf86OutputPtr output);
955
956extern _X_EXPORT void
957 xf86ProbeOutputModes(ScrnInfoPtr pScrn, int maxX, int maxY);
958
959extern _X_EXPORT void
960 xf86SetScrnInfoModes(ScrnInfoPtr pScrn);
961
962#ifdef RANDR_13_INTERFACE
963#define ScreenInitRetType	int
964#else
965#define ScreenInitRetType	Bool
966#endif
967
968extern _X_EXPORT ScreenInitRetType xf86CrtcScreenInit(ScreenPtr pScreen);
969
970extern _X_EXPORT void
971xf86AssignNoOutputInitialSize(ScrnInfoPtr scrn, const OptionInfoRec *options,
972                              int *no_output_width, int *no_output_height);
973
974extern _X_EXPORT Bool
975 xf86InitialConfiguration(ScrnInfoPtr pScrn, Bool canGrow);
976
977extern _X_EXPORT void
978 xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
979
980extern _X_EXPORT Bool
981 xf86SaveScreen(ScreenPtr pScreen, int mode);
982
983extern _X_EXPORT void
984 xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
985
986extern _X_EXPORT DisplayModePtr
987xf86OutputFindClosestMode(xf86OutputPtr output, DisplayModePtr desired);
988
989extern _X_EXPORT Bool
990
991xf86SetSingleMode(ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
992
993/**
994 * Set the EDID information for the specified output
995 */
996extern _X_EXPORT void
997 xf86OutputSetEDID(xf86OutputPtr output, xf86MonPtr edid_mon);
998
999/**
1000 * Set the TILE information for the specified output
1001 */
1002extern _X_EXPORT void
1003xf86OutputSetTile(xf86OutputPtr output, struct xf86CrtcTileInfo *tile_info);
1004
1005extern _X_EXPORT Bool
1006xf86OutputParseKMSTile(const char *tile_data, int tile_length, struct xf86CrtcTileInfo *tile_info);
1007
1008/**
1009 * Return the list of modes supported by the EDID information
1010 * stored in 'output'
1011 */
1012extern _X_EXPORT DisplayModePtr xf86OutputGetEDIDModes(xf86OutputPtr output);
1013
1014extern _X_EXPORT xf86MonPtr
1015xf86OutputGetEDID(xf86OutputPtr output, I2CBusPtr pDDCBus);
1016
1017/**
1018 * Initialize dga for this screen
1019 */
1020
1021#ifdef XFreeXDGA
1022extern _X_EXPORT Bool
1023 xf86DiDGAInit(ScreenPtr pScreen, unsigned long dga_address);
1024
1025/* this is the real function, used only internally */
1026_X_INTERNAL Bool
1027 _xf86_di_dga_init_internal(ScreenPtr pScreen);
1028
1029/**
1030 * Re-initialize dga for this screen (as when the set of modes changes)
1031 */
1032
1033extern _X_EXPORT Bool
1034 xf86DiDGAReInit(ScreenPtr pScreen);
1035#endif
1036
1037/* This is the real function, used only internally */
1038_X_INTERNAL Bool
1039 _xf86_di_dga_reinit_internal(ScreenPtr pScreen);
1040
1041/*
1042 * Set the subpixel order reported for the screen using
1043 * the information from the outputs
1044 */
1045
1046extern _X_EXPORT void
1047 xf86CrtcSetScreenSubpixelOrder(ScreenPtr pScreen);
1048
1049/*
1050 * Get a standard string name for a connector type
1051 */
1052extern _X_EXPORT const char *xf86ConnectorGetName(xf86ConnectorType connector);
1053
1054/*
1055 * Using the desired mode information in each crtc, set
1056 * modes (used in EnterVT functions, or at server startup)
1057 */
1058
1059extern _X_EXPORT Bool
1060 xf86SetDesiredModes(ScrnInfoPtr pScrn);
1061
1062/**
1063 * Initialize the CRTC-based cursor code. CRTC function vectors must
1064 * contain relevant cursor setting functions.
1065 *
1066 * Driver should call this from ScreenInit function
1067 */
1068extern _X_EXPORT Bool
1069 xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags);
1070
1071/**
1072 * Superseded by xf86CursorResetCursor, which is getting called
1073 * automatically when necessary.
1074 */
1075static _X_INLINE _X_DEPRECATED void xf86_reload_cursors(ScreenPtr screen) {}
1076
1077/**
1078 * Called from EnterVT to turn the cursors back on
1079 */
1080extern _X_EXPORT Bool
1081 xf86_show_cursors(ScrnInfoPtr scrn);
1082
1083/**
1084 * Called by the driver to turn a single crtc's cursor off
1085 */
1086extern _X_EXPORT void
1087xf86_crtc_hide_cursor(xf86CrtcPtr crtc);
1088
1089/**
1090 * Called by the driver to turn a single crtc's cursor on
1091 */
1092extern _X_EXPORT Bool
1093xf86_crtc_show_cursor(xf86CrtcPtr crtc);
1094
1095/**
1096 * Called by the driver to turn cursors off
1097 */
1098extern _X_EXPORT void
1099 xf86_hide_cursors(ScrnInfoPtr scrn);
1100
1101/**
1102 * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
1103 */
1104extern _X_EXPORT void
1105 xf86_cursors_fini(ScreenPtr screen);
1106
1107#ifdef XV
1108/*
1109 * For overlay video, compute the relevant CRTC and
1110 * clip video to that.
1111 * wraps xf86XVClipVideoHelper()
1112 */
1113
1114extern _X_EXPORT Bool
1115
1116xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
1117                            xf86CrtcPtr * crtc_ret,
1118                            xf86CrtcPtr desired_crtc,
1119                            BoxPtr dst,
1120                            INT32 *xa,
1121                            INT32 *xb,
1122                            INT32 *ya,
1123                            INT32 *yb,
1124                            RegionPtr reg, INT32 width, INT32 height);
1125#endif
1126
1127extern _X_EXPORT xf86_crtc_notify_proc_ptr
1128xf86_wrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new);
1129
1130extern _X_EXPORT void
1131 xf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old);
1132
1133extern _X_EXPORT void
1134 xf86_crtc_notify(ScreenPtr pScreen);
1135
1136/**
1137 * Gamma
1138 */
1139
1140extern _X_EXPORT Bool
1141 xf86_crtc_supports_gamma(ScrnInfoPtr pScrn);
1142
1143extern _X_EXPORT void
1144xf86ProviderSetup(ScrnInfoPtr scrn,
1145                  const xf86ProviderFuncsRec * funcs, const char *name);
1146
1147extern _X_EXPORT void
1148xf86DetachAllCrtc(ScrnInfoPtr scrn);
1149
1150Bool xf86OutputForceEnabled(xf86OutputPtr output);
1151#endif                          /* _XF86CRTC_H_ */
1152